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,30 +302,48 @@ 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");
DocumentEntity parentDocumentEntity = new DocumentEntity();
parentDocumentEntity.id = UUID.randomUUID().toString();
parentDocumentEntity.title = target1DocumentEntity.title + "(Combined)";
parentDocumentEntity.parentId = target1DocumentEntity.parentId;
parentDocumentEntity.author = target1DocumentEntity.author; // TODO-rca: Target1とTarget2の作者が異なる場合の処理
// CombinedなDocumentはいま作成された と考える
parentDocumentEntity.createdAt = new Date();
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;
});
}
private void insertCombineDocumentToxi(String parentId, String childId, String titleCache) {
ToxiDocumentEntity toxiDocumentEntity = new ToxiDocumentEntity(); ToxiDocumentEntity toxiDocumentEntity = new ToxiDocumentEntity();
toxiDocumentEntity.parentDocumentId = parentId; toxiDocumentEntity.parentDocumentId = parentId;
toxiDocumentEntity.childDocumentId = childId; toxiDocumentEntity.childDocumentId = childId;
toxiDocumentEntity.order = 0; // TODO-rca: 並び順の概念をもたせる toxiDocumentEntity.order = 0; // TODO-rca: 並び順の概念をもたせる
toxiDocumentEntity.isActive = true; // TODO-rca: タブから非表示にできるようにする toxiDocumentEntity.isActive = true; // TODO-rca: タブから非表示にできるようにする
toxiDocumentEntity.titleCache = childDocumentEntity.title; toxiDocumentEntity.titleCache = titleCache;
database.toxiDocumentDao().insert(toxiDocumentEntity); database.toxiDocumentDao().insert(toxiDocumentEntity);
logger.debug("LacertaLibraryImpl", "Database Query: Inserted ToxiDocumentEntity"); logger.debug("LacertaLibraryImpl", "Database Query: Inserted ToxiDocumentEntity");
return null;
});
} }
@Override @Override