Combine処理を変更

This commit is contained in:
r-ca 2024-01-28 14:13:17 +09:00
parent 0210bcaeb6
commit 671718ba83
No known key found for this signature in database
GPG Key ID: 6A72911AC73464A9

View File

@ -8,6 +8,7 @@ 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.Collections;
import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Objects; import java.util.Objects;
import java.util.UUID; import java.util.UUID;
@ -301,32 +302,50 @@ public class LacertaLibraryImpl implements LacertaLibrary {
} }
@Override @Override
public CompletableFuture<Void> combineDocument(String parentId, String childId) { public CompletableFuture<Void> combineDocument(String targetId1, String tagetId2) {
return CompletableFuture.supplyAsync(() -> { return CompletableFuture.supplyAsync(() -> {
DocumentEntity parentDocumentEntity = database.documentDao().findById(parentId); DocumentEntity target1DocumentEntity = database.documentDao().findById(targetId1);
DocumentEntity childDocumentEntity = database.documentDao().findById(childId); DocumentEntity target2DocumentEntity = database.documentDao().findById(tagetId2);
if (parentDocumentEntity == null || childDocumentEntity == null) { if (target1DocumentEntity == null || target2DocumentEntity == null) {
logger.warn("LacertaLibraryImpl", "DocumentEntity is not found."); logger.warn("LacertaLibraryImpl", "DocumentEntity is not found.");
return null; return null;
} }
parentDocumentEntity.isCombineParent = true; target1DocumentEntity.isCombineChild = true;
childDocumentEntity.isCombineChild = true; target2DocumentEntity.isCombineChild = true;
database.documentDao().update(parentDocumentEntity); database.documentDao().update(target1DocumentEntity);
database.documentDao().update(childDocumentEntity); database.documentDao().update(target2DocumentEntity);
logger.debug("LacertaLibraryImpl", "Database Query: Updated DocumentEntity"); logger.debug("LacertaLibraryImpl", "Database Query: Updated DocumentEntity");
ToxiDocumentEntity toxiDocumentEntity = new ToxiDocumentEntity(); DocumentEntity parentDocumentEntity = new DocumentEntity();
toxiDocumentEntity.parentDocumentId = parentId; parentDocumentEntity.id = UUID.randomUUID().toString();
toxiDocumentEntity.childDocumentId = childId; parentDocumentEntity.title = target1DocumentEntity.title + "(Combined)";
toxiDocumentEntity.order = 0; // TODO-rca: 並び順の概念をもたせる parentDocumentEntity.parentId = target1DocumentEntity.parentId;
toxiDocumentEntity.isActive = true; // TODO-rca: タブから非表示にできるようにする parentDocumentEntity.author = target1DocumentEntity.author; // TODO-rca: Target1とTarget2の作者が異なる場合の処理
toxiDocumentEntity.titleCache = childDocumentEntity.title; // CombinedなDocumentはいま作成された と考える
database.toxiDocumentDao().insert(toxiDocumentEntity); parentDocumentEntity.createdAt = new Date();
logger.debug("LacertaLibraryImpl", "Database Query: Inserted ToxiDocumentEntity"); parentDocumentEntity.updatedAt = new Date();
parentDocumentEntity.isCombineParent = true;
parentDocumentEntity.isCombineChild = false;
database.documentDao().insert(parentDocumentEntity);
logger.debug("LacertaLibraryImpl", "Database Query: Inserted DocumentEntity");
insertCombineDocumentToxi(parentDocumentEntity.id, target1DocumentEntity.id, target1DocumentEntity.title);
insertCombineDocumentToxi(parentDocumentEntity.id, target2DocumentEntity.id, target2DocumentEntity.title);
return null; return null;
}); });
} }
private void insertCombineDocumentToxi(String parentId, String childId, String titleCache) {
ToxiDocumentEntity toxiDocumentEntity = new ToxiDocumentEntity();
toxiDocumentEntity.parentDocumentId = parentId;
toxiDocumentEntity.childDocumentId = childId;
toxiDocumentEntity.order = 0; // TODO-rca: 並び順の概念をもたせる
toxiDocumentEntity.isActive = true; // TODO-rca: タブから非表示にできるようにする
toxiDocumentEntity.titleCache = titleCache;
database.toxiDocumentDao().insert(toxiDocumentEntity);
logger.debug("LacertaLibraryImpl", "Database Query: Inserted ToxiDocumentEntity");
}
@Override @Override
public CompletableFuture<Void> uncombineDocument(String parentId, String childId) { public CompletableFuture<Void> uncombineDocument(String parentId, String childId) {
return CompletableFuture.supplyAsync(() -> { return CompletableFuture.supplyAsync(() -> {