diff --git a/commons/src/main/java/io/github/martinwitt/laughing_train/domain/entity/AnalyzerStatus.java b/commons/src/main/java/io/github/martinwitt/laughing_train/domain/entity/AnalyzerStatus.java index 734e39927..fe6f0bd47 100644 --- a/commons/src/main/java/io/github/martinwitt/laughing_train/domain/entity/AnalyzerStatus.java +++ b/commons/src/main/java/io/github/martinwitt/laughing_train/domain/entity/AnalyzerStatus.java @@ -11,6 +11,10 @@ public class AnalyzerStatus implements Serializable { private String commitHash; private LocalDateTime localDateTime; + public AnalyzerStatus() { + // for JPA + } + AnalyzerStatus( String analyzerName, Status status, int numberOfIssues, String commitHash, LocalDateTime localDateTime) { this.analyzerName = analyzerName; diff --git a/commons/src/main/java/io/github/martinwitt/laughing_train/domain/entity/GitHubCommit.java b/commons/src/main/java/io/github/martinwitt/laughing_train/domain/entity/GitHubCommit.java index bc494fb71..64e4d44f0 100644 --- a/commons/src/main/java/io/github/martinwitt/laughing_train/domain/entity/GitHubCommit.java +++ b/commons/src/main/java/io/github/martinwitt/laughing_train/domain/entity/GitHubCommit.java @@ -8,9 +8,11 @@ public class GitHubCommit implements Serializable { private String commitHash; private List analyzerStatuses; + public GitHubCommit() { + // for JPA + } /** * @param commitHash - * @param localDateTime * @param analyzerStatuses */ public GitHubCommit(String commitHash, List analyzerStatuses) { diff --git a/github-bot/src/main/java/io/github/martinwitt/laughing_train/mining/AnalyzerResultsPersistence.java b/github-bot/src/main/java/io/github/martinwitt/laughing_train/mining/AnalyzerResultsPersistence.java index 7b28e7ed8..153924684 100644 --- a/github-bot/src/main/java/io/github/martinwitt/laughing_train/mining/AnalyzerResultsPersistence.java +++ b/github-bot/src/main/java/io/github/martinwitt/laughing_train/mining/AnalyzerResultsPersistence.java @@ -63,10 +63,15 @@ private void addOrUpdateCommitHash(Project project, CodeAnalyzerResult spoonResu RemoteProject newProject = new RemoteProject(name, project.url()); newProject.addCommitHash(commitHash); List commits = newProject.getCommits(); - commits.stream() + var selectedCommit = commits.stream() .filter(v -> v.getCommitHash().equals(commitHash)) - .findFirst() - .ifPresent(v -> v.addAnalyzerStatus(analyzerStatus)); + .findFirst(); + if (selectedCommit.isPresent()) { + selectedCommit.get().addAnalyzerStatus(analyzerStatus); + logger.atInfo().log( + "Adding new commit hash for %s with status %s for analyzer %s", + name, analyzerStatus.getStatus(), analyzerStatus.getAnalyzerName()); + } projectRepository.create(newProject); } else { logger.atInfo().log("Updating commit hash for %s", name); diff --git a/github-bot/src/main/java/io/github/martinwitt/laughing_train/persistence/DataBaseMigration.java b/github-bot/src/main/java/io/github/martinwitt/laughing_train/persistence/DataBaseMigration.java index f3e3ab5cc..059022220 100644 --- a/github-bot/src/main/java/io/github/martinwitt/laughing_train/persistence/DataBaseMigration.java +++ b/github-bot/src/main/java/io/github/martinwitt/laughing_train/persistence/DataBaseMigration.java @@ -3,8 +3,6 @@ import com.google.common.flogger.FluentLogger; import com.mongodb.client.model.Filters; import com.mongodb.client.result.DeleteResult; -import io.github.martinwitt.laughing_train.domain.entity.AnalyzerStatus; -import io.github.martinwitt.laughing_train.domain.entity.GitHubCommit; import io.github.martinwitt.laughing_train.domain.entity.ProjectConfig; import io.github.martinwitt.laughing_train.domain.entity.RemoteProject; import io.github.martinwitt.laughing_train.persistence.impl.MongoBadSmellRepository; @@ -78,7 +76,6 @@ private void migrateDataBase(Promise promise) { removeDuplicatedProjects(); removeRuleIdsWithSpaces(); removeBadSmellsWithWrongFolder(); - removeAnalyzerStatusWithoutLocalDataTime(); logger.atInfo().log("Finished migrating database"); promise.complete(); } @@ -149,23 +146,4 @@ private void removeBadSmellsWithWrongFolder() { .deleteMany(Filters.and(Filters.regex("filePath", ".*/tmp/.*"), Filters.eq("analyzer", "Spoon"))); logger.atInfo().log("Removed %d bad smells with ruleId containing spaces", deleteMany.getDeletedCount()); } - - private void removeAnalyzerStatusWithoutLocalDataTime() { - logger.atInfo().log("Removing analyzer status without local data"); - for (RemoteProject remoteProject : projectRepository.getAll()) { - for (GitHubCommit commits : remoteProject.getCommits()) { - List list = new ArrayList<>(); - for (AnalyzerStatus analyzerStatus : commits.getAnalyzerStatuses()) { - if (analyzerStatus.getLocalDateTime() != null) { - list.add(analyzerStatus); - } - } - if (list.size() != commits.getAnalyzerStatuses().size()) { - commits.setAnalyzerStatuses(list); - projectRepository.deleteByProjectUrl(remoteProject.getProjectUrl()); - projectRepository.save(remoteProject); - } - } - } - } } diff --git a/github-bot/src/main/java/io/github/martinwitt/laughing_train/persistence/converter/ProjectDaoConverter.java b/github-bot/src/main/java/io/github/martinwitt/laughing_train/persistence/converter/ProjectDaoConverter.java index 29438d2a0..2aeb6efdf 100644 --- a/github-bot/src/main/java/io/github/martinwitt/laughing_train/persistence/converter/ProjectDaoConverter.java +++ b/github-bot/src/main/java/io/github/martinwitt/laughing_train/persistence/converter/ProjectDaoConverter.java @@ -11,6 +11,7 @@ public ProjectDao convertToDao(RemoteProject entity) { dao.setProjectName(entity.getProjectName()); dao.setProjectUrl(entity.getProjectUrl()); dao.setCommitHashes(entity.getCommitHashes()); + dao.setCommits(entity.getCommits()); return dao; } @@ -18,6 +19,7 @@ public ProjectDao convertToDao(RemoteProject entity) { public RemoteProject convertToEntity(ProjectDao dao) { var project = new RemoteProject(dao.getProjectName(), dao.getProjectUrl()); dao.getCommitHashes().forEach(project::addCommitHash); + dao.getCommits().forEach(project::addCommitHash); return project; } } diff --git a/github-bot/src/main/java/io/github/martinwitt/laughing_train/persistence/dao/ProjectDao.java b/github-bot/src/main/java/io/github/martinwitt/laughing_train/persistence/dao/ProjectDao.java index 2b18b9082..5119c081d 100644 --- a/github-bot/src/main/java/io/github/martinwitt/laughing_train/persistence/dao/ProjectDao.java +++ b/github-bot/src/main/java/io/github/martinwitt/laughing_train/persistence/dao/ProjectDao.java @@ -1,5 +1,6 @@ package io.github.martinwitt.laughing_train.persistence.dao; +import io.github.martinwitt.laughing_train.domain.entity.GitHubCommit; import io.quarkus.mongodb.panache.PanacheMongoEntity; import io.quarkus.mongodb.panache.common.MongoEntity; import java.util.List; @@ -10,6 +11,7 @@ public class ProjectDao extends PanacheMongoEntity { private String projectName; private String projectUrl; private List commitHashes; + private List commits; public ProjectDao() { // for JPA @@ -57,6 +59,19 @@ public void setCommitHashes(List commitHashes) { this.commitHashes = commitHashes; } + /** + * @return the commits + */ + public List getCommits() { + return commits; + } + /** + * @param commits the commits to set + */ + public void setCommits(List commits) { + this.commits = commits; + } + @Override public String toString() { return "{" + " projectName='"