From f7d07b0ec313af84a6208d3f5b9b0949678f4865 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=82=8D=E3=82=80=E3=81=AD=E3=81=93?= Date: Mon, 22 Jan 2024 20:21:01 +0900 Subject: [PATCH] =?UTF-8?q?=E3=83=91=E3=82=B9=E8=A7=A3=E6=B1=BA=E3=83=A1?= =?UTF-8?q?=E3=82=BD=E3=83=83=E3=83=89=E3=82=92=E4=BD=9C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lacerta/data/impl/LacertaLibraryImpl.java | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/data/src/main/java/one/nem/lacerta/data/impl/LacertaLibraryImpl.java b/data/src/main/java/one/nem/lacerta/data/impl/LacertaLibraryImpl.java index 797306c1..46b8dc23 100644 --- a/data/src/main/java/one/nem/lacerta/data/impl/LacertaLibraryImpl.java +++ b/data/src/main/java/one/nem/lacerta/data/impl/LacertaLibraryImpl.java @@ -4,6 +4,7 @@ import java.text.DateFormat; import java.time.format.DateTimeFormatter; import java.util.ArrayList; import java.util.Collection; +import java.util.Collections; import java.util.List; import java.util.UUID; import java.util.concurrent.CompletableFuture; @@ -140,4 +141,55 @@ public class LacertaLibraryImpl implements LacertaLibrary { return folderEntity.id; }); } + + @Override + public CompletableFuture getPublicPath(String itemId, ListItemType itemType) { + return CompletableFuture.supplyAsync(() -> { + if (itemType == ListItemType.ITEM_TYPE_DOCUMENT) { + DocumentEntity documentEntity = database.documentDao().findById(itemId); + if (documentEntity == null) { + return null; + } + return new PublicPath().resolve(documentEntity.publicPath); + } else if (itemType == ListItemType.ITEM_TYPE_FOLDER) { + FolderEntity folderEntity = database.folderDao().findById(itemId); + if (folderEntity == null) { + return null; + } + return new PublicPath().resolve(folderEntity.publicPath); + } else { + return null; + } + }); + } + + /** + * 再帰的にパスを解決する + * + * @param folderId + * @return + */ + private PublicPath recursiveResolve(String folderId) { + String current = folderId; + boolean continueFlag = true; + ArrayList folderNames = new ArrayList<>(); + while (continueFlag) { + FolderEntity folderEntity = database.folderDao().findById(current); + if (folderEntity == null) { // 存在しないフォルダIDが指定された場合 + continueFlag = false; + } else { + folderNames.add(folderEntity.name); + current = folderEntity.parentId; + if (current == null) { // ルートフォルダに到達した場合 + continueFlag = false; + } + } + } + + // フォルダ名を逆順にしてListに変換 + Collections.reverse(folderNames); + List folderNamesReversed = new ArrayList<>(folderNames); + + return new PublicPath(folderNamesReversed); + } }