Vcs実装

This commit is contained in:
ろむねこ 2024-01-17 10:46:31 +09:00
parent 0487553f3b
commit d832438f8f
No known key found for this signature in database
GPG Key ID: FA1F39A1BA37D168
2 changed files with 59 additions and 1 deletions

View File

@ -11,6 +11,8 @@ public interface LacertaVcs {
public void createDocument(String documentId); public void createDocument(String documentId);
public void generateRevisionAtCurrent(String message);
// debug // debug
public void printLog(); public void printLog();

View File

@ -1,5 +1,7 @@
package one.nem.lacerta.vcs.impl; package one.nem.lacerta.vcs.impl;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID; import java.util.UUID;
import javax.inject.Inject; import javax.inject.Inject;
@ -8,6 +10,7 @@ import dagger.assisted.Assisted;
import dagger.assisted.AssistedInject; import dagger.assisted.AssistedInject;
import one.nem.lacerta.source.database.LacertaDatabase; import one.nem.lacerta.source.database.LacertaDatabase;
import one.nem.lacerta.source.database.entity.VcsLogEntity; 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.utils.LacertaLogger;
import one.nem.lacerta.vcs.LacertaVcs; import one.nem.lacerta.vcs.LacertaVcs;
@ -26,7 +29,9 @@ public class LacertaVcsImpl implements LacertaVcs {
public LacertaVcsImpl(LacertaLogger logger, LacertaDatabase database, @Assisted String documentId) { public LacertaVcsImpl(LacertaLogger logger, LacertaDatabase database, @Assisted String documentId) {
this.logger = logger; this.logger = logger;
this.database = database; this.database = database;
if (documentId != null) {
this.documentId = documentId; this.documentId = documentId;
}
logger.debug(TAG, "LacertaVcsImpl constructor"); logger.debug(TAG, "LacertaVcsImpl constructor");
} }
@ -54,7 +59,58 @@ public class LacertaVcsImpl implements LacertaVcs {
@Override @Override
public void createDocument(String documentId) { 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<VcsLogEntity> getNonIncludedVcsLogEntities() {
return new ArrayList<>(database.vcsLogDao().findByDocumentIdAndIncluded(documentId, false));
}
private ArrayList<VcsLogEntity> getNonIncludedVcsLogEntities(String branchName) {
return new ArrayList<>(database.vcsLogDao().findByDocumentIdAndBranchNameAndIncluded(documentId, branchName, false));
}
private void setIncludedVcsLogEntities(ArrayList<VcsLogEntity> 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<VcsLogEntity> vcsLogEntities = getNonIncludedVcsLogEntities();
ArrayList<String> 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 @Override