パス解決メソッドを作成

This commit is contained in:
ろむねこ 2024-01-22 20:21:01 +09:00
parent 7f71e818a8
commit f7d07b0ec3
No known key found for this signature in database
GPG Key ID: FA1F39A1BA37D168

View File

@ -4,6 +4,7 @@ import java.text.DateFormat;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
@ -140,4 +141,55 @@ public class LacertaLibraryImpl implements LacertaLibrary {
return folderEntity.id; return folderEntity.id;
}); });
} }
@Override
public CompletableFuture<PublicPath> 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<String> 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<String> folderNamesReversed = new ArrayList<>(folderNames);
return new PublicPath(folderNamesReversed);
}
} }