From d832438f8f1fcf6f14689631b9556a4bd87b5e52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=82=8D=E3=82=80=E3=81=AD=E3=81=93?= Date: Wed, 17 Jan 2024 10:46:31 +0900 Subject: [PATCH] =?UTF-8?q?Vcs=E5=AE=9F=E8=A3=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/one/nem/lacerta/vcs/LacertaVcs.java | 2 + .../nem/lacerta/vcs/impl/LacertaVcsImpl.java | 58 ++++++++++++++++++- 2 files changed, 59 insertions(+), 1 deletion(-) diff --git a/vcs/src/main/java/one/nem/lacerta/vcs/LacertaVcs.java b/vcs/src/main/java/one/nem/lacerta/vcs/LacertaVcs.java index 46640d37..3a47e45a 100644 --- a/vcs/src/main/java/one/nem/lacerta/vcs/LacertaVcs.java +++ b/vcs/src/main/java/one/nem/lacerta/vcs/LacertaVcs.java @@ -11,6 +11,8 @@ public interface LacertaVcs { public void createDocument(String documentId); + public void generateRevisionAtCurrent(String message); + // debug public void printLog(); diff --git a/vcs/src/main/java/one/nem/lacerta/vcs/impl/LacertaVcsImpl.java b/vcs/src/main/java/one/nem/lacerta/vcs/impl/LacertaVcsImpl.java index 15e343da..cea5728b 100644 --- a/vcs/src/main/java/one/nem/lacerta/vcs/impl/LacertaVcsImpl.java +++ b/vcs/src/main/java/one/nem/lacerta/vcs/impl/LacertaVcsImpl.java @@ -1,5 +1,7 @@ package one.nem.lacerta.vcs.impl; +import java.util.ArrayList; +import java.util.List; import java.util.UUID; import javax.inject.Inject; @@ -8,6 +10,7 @@ import dagger.assisted.Assisted; import dagger.assisted.AssistedInject; import one.nem.lacerta.source.database.LacertaDatabase; import one.nem.lacerta.source.database.entity.VcsLogEntity; +import one.nem.lacerta.source.database.entity.VcsRevEntity; import one.nem.lacerta.utils.LacertaLogger; import one.nem.lacerta.vcs.LacertaVcs; @@ -26,7 +29,9 @@ public class LacertaVcsImpl implements LacertaVcs { public LacertaVcsImpl(LacertaLogger logger, LacertaDatabase database, @Assisted String documentId) { this.logger = logger; this.database = database; - this.documentId = documentId; + if (documentId != null) { + this.documentId = documentId; + } logger.debug(TAG, "LacertaVcsImpl constructor"); } @@ -54,7 +59,58 @@ public class LacertaVcsImpl implements LacertaVcs { @Override public void createDocument(String documentId) { + logger.debug(TAG, "createDocument"); + VcsLogEntity vcsLogEntity = new VcsLogEntity(); + vcsLogEntity.id = UUID.randomUUID().toString(); + vcsLogEntity.documentId = documentId; + vcsLogEntity.branchName = "master"; + vcsLogEntity.createdAt = new java.util.Date(); + vcsLogEntity.action = "placeholder"; + database.vcsLogDao().insert(vcsLogEntity); + } + // Internal + private ArrayList getNonIncludedVcsLogEntities() { + return new ArrayList<>(database.vcsLogDao().findByDocumentIdAndIncluded(documentId, false)); + } + + private ArrayList getNonIncludedVcsLogEntities(String branchName) { + return new ArrayList<>(database.vcsLogDao().findByDocumentIdAndBranchNameAndIncluded(documentId, branchName, false)); + } + + private void setIncludedVcsLogEntities(ArrayList vcsLogEntities) { + vcsLogEntities.forEach(vcsLogEntity -> { + vcsLogEntity.isIncluded = true; + database.vcsLogDao().update(vcsLogEntity); + }); + + logger.debug(TAG, "setIncludedVcsLogEntities updated: " + vcsLogEntities.size() + " entities"); + } + + @Override + public void generateRevisionAtCurrent(String message) { + logger.debug(TAG, "generateRevisionAtCurrent"); + + ArrayList vcsLogEntities = getNonIncludedVcsLogEntities(); + + ArrayList logIds = new ArrayList<>(); + vcsLogEntities.forEach(vcsLogEntity -> { + logIds.add(vcsLogEntity.id); + }); + + VcsRevEntity vcsRevEntity = new VcsRevEntity(); + vcsRevEntity.id = UUID.randomUUID().toString(); + vcsRevEntity.documentId = documentId; + vcsRevEntity.branchName = "master"; + vcsRevEntity.createdAt = new java.util.Date(); + vcsRevEntity.commitMessage = message; + vcsRevEntity.logIds = logIds; + + database.vcsRevDao().insert(vcsRevEntity); + + setIncludedVcsLogEntities(vcsLogEntities); + + logger.debug(TAG, "generateRevisionAtCurrent finished"); } @Override