mirror of
https://github.com/lacerta-doc/Lacerta.git
synced 2024-11-22 16:03:15 +00:00
Vcs実装
This commit is contained in:
parent
0487553f3b
commit
d832438f8f
|
@ -11,6 +11,8 @@ public interface LacertaVcs {
|
|||
|
||||
public void createDocument(String documentId);
|
||||
|
||||
public void generateRevisionAtCurrent(String message);
|
||||
|
||||
// debug
|
||||
public void printLog();
|
||||
|
||||
|
|
|
@ -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;
|
||||
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<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
|
||||
|
|
Loading…
Reference in New Issue
Block a user