From aeab50cfb8ebb025d58d0f7a49e071f7bf68b885 Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Wed, 15 Feb 2023 18:28:39 +0400 Subject: [PATCH] #89 -- Create a valid class hierarchy --- .../gitrepository/service/GitApi.java | 4 ++ .../gitrepository/service/GitAtheneApi.java | 16 ++++++ .../gitrepository/service/IndexService.java | 2 +- .../ts/creator/db/AuthorsCommitTS.java | 14 +++-- .../ts/creator/{scheduled => db}/ClassTS.java | 23 +++----- .../extractor/ts/creator/db/CommitsTS.java | 14 +++-- .../ts/creator/db/DBTimeSeriesCreator.java | 11 ++-- .../{scheduled => db}/DependenceTS.java | 23 +++----- .../creator/{scheduled => db}/EntityTS.java | 24 +++----- .../ulstu/extractor/ts/creator/db/FileTS.java | 14 +++-- .../{scheduled => db}/InterfaceTS.java | 23 +++----- .../creator/{scheduled => db}/ProcessTS.java | 22 +++----- .../ts/creator/scheduled/AuthorTS.java | 55 +++---------------- .../scheduled/AuthorsCompletedIssueTS.java | 53 ------------------ .../ts/creator/scheduled/AuthorsIssueTS.java | 53 ------------------ 15 files changed, 98 insertions(+), 253 deletions(-) rename src/main/java/ru/ulstu/extractor/ts/creator/{scheduled => db}/ClassTS.java (56%) rename src/main/java/ru/ulstu/extractor/ts/creator/{scheduled => db}/DependenceTS.java (56%) rename src/main/java/ru/ulstu/extractor/ts/creator/{scheduled => db}/EntityTS.java (71%) rename src/main/java/ru/ulstu/extractor/ts/creator/{scheduled => db}/InterfaceTS.java (56%) rename src/main/java/ru/ulstu/extractor/ts/creator/{scheduled => db}/ProcessTS.java (58%) delete mode 100644 src/main/java/ru/ulstu/extractor/ts/creator/scheduled/AuthorsCompletedIssueTS.java delete mode 100644 src/main/java/ru/ulstu/extractor/ts/creator/scheduled/AuthorsIssueTS.java diff --git a/src/main/java/ru/ulstu/extractor/gitrepository/service/GitApi.java b/src/main/java/ru/ulstu/extractor/gitrepository/service/GitApi.java index 3aa4e59..1267a15 100644 --- a/src/main/java/ru/ulstu/extractor/gitrepository/service/GitApi.java +++ b/src/main/java/ru/ulstu/extractor/gitrepository/service/GitApi.java @@ -10,4 +10,8 @@ public interface GitApi { Integer getOpenIssuesCount(Branch branch); String getFormattedUrl(String gitRepositoryUrl, String template); + + Integer getAuthorsCompletedIssues(Branch branch); + + Integer getAuthorsCount(Branch branch); } diff --git a/src/main/java/ru/ulstu/extractor/gitrepository/service/GitAtheneApi.java b/src/main/java/ru/ulstu/extractor/gitrepository/service/GitAtheneApi.java index a8853dc..eb79ab5 100644 --- a/src/main/java/ru/ulstu/extractor/gitrepository/service/GitAtheneApi.java +++ b/src/main/java/ru/ulstu/extractor/gitrepository/service/GitAtheneApi.java @@ -10,6 +10,8 @@ public class GitAtheneApi implements GitApi { private static final String BRANCHES_COUNT_URL = "%s/api/v1/repos/%s/%s/branches"; private static final String STARS_COUNT_URL = "%s/api/v1/repos/%s/%s"; private static final String OPEN_ISSUES_URL = "%s/api/v1/repos/%s/%s/issues?state=open"; + private static final String AUTHOR_COMPLETED_ISSUES_URL = "%s/api/v1/repos/%s/%s/issues?state=open"; + private static final String AUTHORS_COUNT_URL = "%s/api/v1/repos/%s/%s/branches"; public GitAtheneApi(HttpService httpService) { this.httpService = httpService; @@ -42,4 +44,18 @@ public class GitAtheneApi implements GitApi { String[] urlParts = gitRepositoryUrl.split("/"); return String.format(template, urlParts[0] + "/" + urlParts[1] + "/" + urlParts[2], urlParts[3], urlParts[4]); } + + @Override + public Integer getAuthorsCompletedIssues(Branch branch) { + return httpService + .get(getFormattedUrl(branch.getGitRepository().getUrl(), AUTHOR_COMPLETED_ISSUES_URL)) + .length(); + } + + @Override + public Integer getAuthorsCount(Branch branch) { + return httpService + .get(getFormattedUrl(branch.getGitRepository().getUrl(), AUTHORS_COUNT_URL)) + .length(); + } } diff --git a/src/main/java/ru/ulstu/extractor/gitrepository/service/IndexService.java b/src/main/java/ru/ulstu/extractor/gitrepository/service/IndexService.java index 088aa22..7921c21 100644 --- a/src/main/java/ru/ulstu/extractor/gitrepository/service/IndexService.java +++ b/src/main/java/ru/ulstu/extractor/gitrepository/service/IndexService.java @@ -79,7 +79,7 @@ public class IndexService { commits = gitRepositoryService.getCommits(gitRepository.getUrl(), branch.getName(), commitsFrom, commitsTo, false); } final Branch branchForSave = branch; - timeSeriesCreators.forEach(tsCreator -> tsCreator.addTimeSeries(gitRepository, branchForSave)); + timeSeriesCreators.forEach(tsCreator -> tsCreator.addTimeSeries(branchForSave)); branchService.updateStatus(branch, IndexingStatus.FINISHED); LOG.debug("Complete indexing {} branch", branch.getName()); } diff --git a/src/main/java/ru/ulstu/extractor/ts/creator/db/AuthorsCommitTS.java b/src/main/java/ru/ulstu/extractor/ts/creator/db/AuthorsCommitTS.java index dc95528..dd1b7c8 100644 --- a/src/main/java/ru/ulstu/extractor/ts/creator/db/AuthorsCommitTS.java +++ b/src/main/java/ru/ulstu/extractor/ts/creator/db/AuthorsCommitTS.java @@ -3,10 +3,10 @@ package ru.ulstu.extractor.ts.creator.db; import org.springframework.stereotype.Component; import ru.ulstu.extractor.author.model.Author; import ru.ulstu.extractor.author.service.AuthorService; +import ru.ulstu.extractor.branch.model.Branch; import ru.ulstu.extractor.branch.service.BranchService; import ru.ulstu.extractor.commit.model.Commit; import ru.ulstu.extractor.commit.service.CommitService; -import ru.ulstu.extractor.gitrepository.model.GitRepository; import ru.ulstu.extractor.ts.model.TimeSeries; import ru.ulstu.extractor.ts.model.TimeSeriesType; import ru.ulstu.extractor.ts.model.TimeSeriesValue; @@ -38,18 +38,20 @@ public class AuthorsCommitTS extends DBTimeSeriesCreator { } @Override - public List getTimeSeries(GitRepository gitRepository, String branchName) { + public List getTimeSeries(Branch branch) { List timeSeriesResult = new ArrayList<>(); List authors = authorService.findAll(); - List commits = new ArrayList<>(commitService.findByRepositoryIdAndName(gitRepository.getId(), branchName)); + List commits = new ArrayList<>(commitService.findByRepositoryIdAndName(branch.getGitRepository().getId(), + branch.getName())); for (Author author : authors) { TimeSeries timeSeries = new TimeSeries( String.format("%s %s %s %s", - gitRepository.getName(), - branchName, + branch.getGitRepository().getName(), + branch.getName(), author.getName(), getTimeSeriesType().getDescription()), - branchService.findByRepositoryAndName(gitRepository, branchName), + branchService.findByRepositoryAndName(branch.getGitRepository(), + branch.getName()), getTimeSeriesType()); for (Commit commit : commits) { if (commit.getAuthor().equals(author)) { diff --git a/src/main/java/ru/ulstu/extractor/ts/creator/scheduled/ClassTS.java b/src/main/java/ru/ulstu/extractor/ts/creator/db/ClassTS.java similarity index 56% rename from src/main/java/ru/ulstu/extractor/ts/creator/scheduled/ClassTS.java rename to src/main/java/ru/ulstu/extractor/ts/creator/db/ClassTS.java index 6062fc0..904238c 100644 --- a/src/main/java/ru/ulstu/extractor/ts/creator/scheduled/ClassTS.java +++ b/src/main/java/ru/ulstu/extractor/ts/creator/db/ClassTS.java @@ -1,10 +1,8 @@ -package ru.ulstu.extractor.ts.creator.scheduled; +package ru.ulstu.extractor.ts.creator.db; import org.springframework.stereotype.Component; +import ru.ulstu.extractor.branch.model.Branch; import ru.ulstu.extractor.branch.service.BranchService; -import ru.ulstu.extractor.gitrepository.model.GitRepository; -import ru.ulstu.extractor.gitrepository.service.GitRepositoryService; -import ru.ulstu.extractor.ts.creator.AbstractTimeSeriesCreator; import ru.ulstu.extractor.ts.model.TimeSeries; import ru.ulstu.extractor.ts.model.TimeSeriesType; import ru.ulstu.extractor.ts.service.TimeSeriesService; @@ -14,30 +12,25 @@ import java.util.Collections; import java.util.List; @Component -public class ClassTS extends AbstractTimeSeriesCreator { +public class ClassTS extends DBTimeSeriesCreator { private final TimeSeriesService timeSeriesService; private final BranchService branchService; - private final GitRepositoryService gitRepositoryService; - public ClassTS(TimeSeriesService timeSeriesService, - BranchService branchService, - GitRepositoryService gitRepositoryService) { + BranchService branchService) { this.timeSeriesService = timeSeriesService; this.branchService = branchService; - this.gitRepositoryService = gitRepositoryService; } @Override - public List getTimeSeries(Integer repositoryId, String branchName) { - GitRepository gitRepository = gitRepositoryService.findById(repositoryId); + public List getTimeSeries(Branch branch) { return Collections.singletonList( new TimeSeries( String.format("%s %s %s", - gitRepository.getName(), - branchName, + branch.getGitRepository().getName(), + branch.getName(), getTimeSeriesType().getDescription()), - branchService.findByRepositoryAndName(gitRepository, branchName), + branchService.findByRepositoryAndName(branch.getGitRepository(), branch.getName()), getTimeSeriesType(), Dummy.getDefaultTimeSeries())); } diff --git a/src/main/java/ru/ulstu/extractor/ts/creator/db/CommitsTS.java b/src/main/java/ru/ulstu/extractor/ts/creator/db/CommitsTS.java index 523ff76..a8982c1 100644 --- a/src/main/java/ru/ulstu/extractor/ts/creator/db/CommitsTS.java +++ b/src/main/java/ru/ulstu/extractor/ts/creator/db/CommitsTS.java @@ -1,9 +1,9 @@ package ru.ulstu.extractor.ts.creator.db; import org.springframework.stereotype.Component; +import ru.ulstu.extractor.branch.model.Branch; import ru.ulstu.extractor.branch.service.BranchService; import ru.ulstu.extractor.commit.service.CommitService; -import ru.ulstu.extractor.gitrepository.model.GitRepository; import ru.ulstu.extractor.ts.model.TimeSeries; import ru.ulstu.extractor.ts.model.TimeSeriesType; import ru.ulstu.extractor.ts.model.TimeSeriesValue; @@ -28,17 +28,19 @@ public class CommitsTS extends DBTimeSeriesCreator { } @Override - public List getTimeSeries(GitRepository gitRepository, String branchName) { + public List getTimeSeries(Branch branch) { //TODO: добавить постраничное чтение return Collections.singletonList( new TimeSeries( String.format("%s %s %s", - gitRepository.getName(), - branchName, + branch.getGitRepository().getName(), + branch.getName(), getTimeSeriesType().getDescription()), - branchService.findByRepositoryAndName(gitRepository, branchName), + branchService.findByRepositoryAndName(branch.getGitRepository(), + branch.getName()), getTimeSeriesType(), - commitService.findByRepositoryIdAndName(gitRepository.getId(), branchName) + commitService.findByRepositoryIdAndName(branch.getGitRepository().getId(), + branch.getName()) .stream() .map(c -> new TimeSeriesValue(c.getDate(), 1.0)) .collect(Collectors.toList()))); diff --git a/src/main/java/ru/ulstu/extractor/ts/creator/db/DBTimeSeriesCreator.java b/src/main/java/ru/ulstu/extractor/ts/creator/db/DBTimeSeriesCreator.java index 7de98b7..214aa32 100644 --- a/src/main/java/ru/ulstu/extractor/ts/creator/db/DBTimeSeriesCreator.java +++ b/src/main/java/ru/ulstu/extractor/ts/creator/db/DBTimeSeriesCreator.java @@ -1,7 +1,6 @@ package ru.ulstu.extractor.ts.creator.db; import ru.ulstu.extractor.branch.model.Branch; -import ru.ulstu.extractor.gitrepository.model.GitRepository; import ru.ulstu.extractor.ts.creator.AbstractTimeSeriesCreator; import ru.ulstu.extractor.ts.model.TimeSeries; import ru.ulstu.extractor.ts.model.TimeSeriesValue; @@ -15,21 +14,19 @@ public abstract class DBTimeSeriesCreator extends AbstractTimeSeriesCreator { /** * Извлечь список точек временных рядов * - * @param gitRepository - * @param branchName + * @param branch * @return */ - public abstract List getTimeSeries(GitRepository gitRepository, String branchName); + public abstract List getTimeSeries(Branch branch); /** * Сохранить извлеченные временные ряды * - * @param gitRepository * @param branch */ - public void addTimeSeries(GitRepository gitRepository, Branch branch) { + public void addTimeSeries(Branch branch) { // извлеченные временных рядов - List timeSeries = getTimeSeries(gitRepository, branch.getName()); + List timeSeries = getTimeSeries(branch); // сгруппированные по временным интервалам точки временных рядов timeSeries.forEach(ts -> ts.setValues(mapTimeSeriesToInterval(getTimeSeriesService().getTimeSeriesInterval(), ts.getValues()))); diff --git a/src/main/java/ru/ulstu/extractor/ts/creator/scheduled/DependenceTS.java b/src/main/java/ru/ulstu/extractor/ts/creator/db/DependenceTS.java similarity index 56% rename from src/main/java/ru/ulstu/extractor/ts/creator/scheduled/DependenceTS.java rename to src/main/java/ru/ulstu/extractor/ts/creator/db/DependenceTS.java index d53c5b6..385f2a0 100644 --- a/src/main/java/ru/ulstu/extractor/ts/creator/scheduled/DependenceTS.java +++ b/src/main/java/ru/ulstu/extractor/ts/creator/db/DependenceTS.java @@ -1,10 +1,8 @@ -package ru.ulstu.extractor.ts.creator.scheduled; +package ru.ulstu.extractor.ts.creator.db; import org.springframework.stereotype.Component; +import ru.ulstu.extractor.branch.model.Branch; import ru.ulstu.extractor.branch.service.BranchService; -import ru.ulstu.extractor.gitrepository.model.GitRepository; -import ru.ulstu.extractor.gitrepository.service.GitRepositoryService; -import ru.ulstu.extractor.ts.creator.AbstractTimeSeriesCreator; import ru.ulstu.extractor.ts.model.TimeSeries; import ru.ulstu.extractor.ts.model.TimeSeriesType; import ru.ulstu.extractor.ts.service.TimeSeriesService; @@ -14,30 +12,25 @@ import java.util.Collections; import java.util.List; @Component -public class DependenceTS extends AbstractTimeSeriesCreator { +public class DependenceTS extends DBTimeSeriesCreator { private final TimeSeriesService timeSeriesService; private final BranchService branchService; - private final GitRepositoryService gitRepositoryService; - public DependenceTS(TimeSeriesService timeSeriesService, - BranchService branchService, - GitRepositoryService gitRepositoryService) { + BranchService branchService) { this.timeSeriesService = timeSeriesService; this.branchService = branchService; - this.gitRepositoryService = gitRepositoryService; } @Override - public List getTimeSeries(Integer repositoryId, String branchName) { - GitRepository gitRepository = gitRepositoryService.findById(repositoryId); + public List getTimeSeries(Branch branch) { return Collections.singletonList( new TimeSeries( String.format("%s %s %s", - gitRepository.getName(), - branchName, + branch.getGitRepository().getName(), + branch.getName(), getTimeSeriesType().getDescription()), - branchService.findByRepositoryAndName(gitRepository, branchName), + branchService.findByRepositoryAndName(branch.getGitRepository(), branch.getName()), getTimeSeriesType(), Dummy.getDefaultTimeSeries())); } diff --git a/src/main/java/ru/ulstu/extractor/ts/creator/scheduled/EntityTS.java b/src/main/java/ru/ulstu/extractor/ts/creator/db/EntityTS.java similarity index 71% rename from src/main/java/ru/ulstu/extractor/ts/creator/scheduled/EntityTS.java rename to src/main/java/ru/ulstu/extractor/ts/creator/db/EntityTS.java index 3666d6b..aed07b3 100644 --- a/src/main/java/ru/ulstu/extractor/ts/creator/scheduled/EntityTS.java +++ b/src/main/java/ru/ulstu/extractor/ts/creator/db/EntityTS.java @@ -1,13 +1,11 @@ -package ru.ulstu.extractor.ts.creator.scheduled; +package ru.ulstu.extractor.ts.creator.db; import org.springframework.stereotype.Component; +import ru.ulstu.extractor.branch.model.Branch; import ru.ulstu.extractor.branch.service.BranchService; import ru.ulstu.extractor.commit.model.Commit; import ru.ulstu.extractor.commit.service.CommitService; import ru.ulstu.extractor.gitrepository.model.FileChange; -import ru.ulstu.extractor.gitrepository.model.GitRepository; -import ru.ulstu.extractor.gitrepository.service.GitRepositoryService; -import ru.ulstu.extractor.ts.creator.AbstractTimeSeriesCreator; import ru.ulstu.extractor.ts.model.TimeSeries; import ru.ulstu.extractor.ts.model.TimeSeriesType; import ru.ulstu.extractor.ts.model.TimeSeriesValue; @@ -19,36 +17,32 @@ import java.util.List; import java.util.stream.Collectors; @Component -public class EntityTS extends AbstractTimeSeriesCreator { +public class EntityTS extends DBTimeSeriesCreator { private final TimeSeriesService timeSeriesService; private final CommitService commitService; - private final GitRepositoryService gitRepositoryService; private final BranchService branchService; public EntityTS(TimeSeriesService timeSeriesService, CommitService commitService, - GitRepositoryService gitRepositoryService, BranchService branchService) { this.timeSeriesService = timeSeriesService; this.commitService = commitService; - this.gitRepositoryService = gitRepositoryService; this.branchService = branchService; } @Override - public List getTimeSeries(Integer repositoryId, String branchName) { - GitRepository gitRepository = gitRepositoryService.findById(repositoryId); + public List getTimeSeries(Branch branch) { return Collections.singletonList( new TimeSeries( String.format("%s %s %s", - gitRepository.getName(), - branchName, + branch.getGitRepository().getName(), + branch.getName(), getTimeSeriesType().getDescription()), - branchService.findByRepositoryAndName(gitRepository, branchName), + branchService.findByRepositoryAndName(branch.getGitRepository(), branch.getName()), getTimeSeriesType(), - commitService.findByRepositoryIdAndName(repositoryId, branchName) + commitService.findByRepositoryIdAndName(branch.getGitRepository().getId(), branch.getName()) .stream() - .map(c -> new TimeSeriesValue(c.getDate(), findEntity(repositoryId, branchName))) + .map(c -> new TimeSeriesValue(c.getDate(), findEntity(branch.getGitRepository().getId(), branch.getName()))) .collect(Collectors.toList()))); } diff --git a/src/main/java/ru/ulstu/extractor/ts/creator/db/FileTS.java b/src/main/java/ru/ulstu/extractor/ts/creator/db/FileTS.java index dd845f6..3d4b62d 100644 --- a/src/main/java/ru/ulstu/extractor/ts/creator/db/FileTS.java +++ b/src/main/java/ru/ulstu/extractor/ts/creator/db/FileTS.java @@ -1,11 +1,11 @@ package ru.ulstu.extractor.ts.creator.db; import org.springframework.stereotype.Component; +import ru.ulstu.extractor.branch.model.Branch; import ru.ulstu.extractor.branch.service.BranchService; import ru.ulstu.extractor.commit.model.Commit; import ru.ulstu.extractor.commit.service.CommitService; import ru.ulstu.extractor.gitrepository.model.FileChange; -import ru.ulstu.extractor.gitrepository.model.GitRepository; import ru.ulstu.extractor.ts.model.TimeSeries; import ru.ulstu.extractor.ts.model.TimeSeriesType; import ru.ulstu.extractor.ts.model.TimeSeriesValue; @@ -29,16 +29,18 @@ public class FileTS extends DBTimeSeriesCreator { } @Override - public List getTimeSeries(GitRepository gitRepository, String branchName) { + public List getTimeSeries(Branch branch) { List timeSeriesResult = new ArrayList<>(); - List commits = new ArrayList<>(commitService.findByRepositoryIdAndName(gitRepository.getId(), branchName)); + List commits = new ArrayList<>(commitService.findByRepositoryIdAndName(branch.getGitRepository().getId(), + branch.getName())); double value = 0; TimeSeries timeSeries = new TimeSeries( String.format("%s %s %s", - gitRepository.getName(), - branchName, + branch.getGitRepository().getName(), + branch.getName(), getTimeSeriesType().getDescription()), - branchService.findByRepositoryAndName(gitRepository, branchName), + branchService.findByRepositoryAndName(branch.getGitRepository(), + branch.getName()), getTimeSeriesType()); for (Commit commit : commits) { for (FileChange fileChange : commit.getFileChanges()) { diff --git a/src/main/java/ru/ulstu/extractor/ts/creator/scheduled/InterfaceTS.java b/src/main/java/ru/ulstu/extractor/ts/creator/db/InterfaceTS.java similarity index 56% rename from src/main/java/ru/ulstu/extractor/ts/creator/scheduled/InterfaceTS.java rename to src/main/java/ru/ulstu/extractor/ts/creator/db/InterfaceTS.java index efc1827..08d8cda 100644 --- a/src/main/java/ru/ulstu/extractor/ts/creator/scheduled/InterfaceTS.java +++ b/src/main/java/ru/ulstu/extractor/ts/creator/db/InterfaceTS.java @@ -1,10 +1,8 @@ -package ru.ulstu.extractor.ts.creator.scheduled; +package ru.ulstu.extractor.ts.creator.db; import org.springframework.stereotype.Component; +import ru.ulstu.extractor.branch.model.Branch; import ru.ulstu.extractor.branch.service.BranchService; -import ru.ulstu.extractor.gitrepository.model.GitRepository; -import ru.ulstu.extractor.gitrepository.service.GitRepositoryService; -import ru.ulstu.extractor.ts.creator.AbstractTimeSeriesCreator; import ru.ulstu.extractor.ts.model.TimeSeries; import ru.ulstu.extractor.ts.model.TimeSeriesType; import ru.ulstu.extractor.ts.service.TimeSeriesService; @@ -14,30 +12,25 @@ import java.util.Collections; import java.util.List; @Component -public class InterfaceTS extends AbstractTimeSeriesCreator { +public class InterfaceTS extends DBTimeSeriesCreator { private final TimeSeriesService timeSeriesService; private final BranchService branchService; - private final GitRepositoryService gitRepositoryService; - public InterfaceTS(TimeSeriesService timeSeriesService, - BranchService branchService, - GitRepositoryService gitRepositoryService) { + BranchService branchService) { this.timeSeriesService = timeSeriesService; this.branchService = branchService; - this.gitRepositoryService = gitRepositoryService; } @Override - public List getTimeSeries(Integer repositoryId, String branchName) { - GitRepository gitRepository = gitRepositoryService.findById(repositoryId); + public List getTimeSeries(Branch branch) { return Collections.singletonList( new TimeSeries( String.format("%s %s %s", - gitRepository.getName(), - branchName, + branch.getGitRepository().getName(), + branch.getName(), getTimeSeriesType().getDescription()), - branchService.findByRepositoryAndName(gitRepository, branchName), + branchService.findByRepositoryAndName(branch.getGitRepository(), branch.getName()), getTimeSeriesType(), Dummy.getDefaultTimeSeries())); } diff --git a/src/main/java/ru/ulstu/extractor/ts/creator/scheduled/ProcessTS.java b/src/main/java/ru/ulstu/extractor/ts/creator/db/ProcessTS.java similarity index 58% rename from src/main/java/ru/ulstu/extractor/ts/creator/scheduled/ProcessTS.java rename to src/main/java/ru/ulstu/extractor/ts/creator/db/ProcessTS.java index 1dd4675..c900678 100644 --- a/src/main/java/ru/ulstu/extractor/ts/creator/scheduled/ProcessTS.java +++ b/src/main/java/ru/ulstu/extractor/ts/creator/db/ProcessTS.java @@ -1,9 +1,8 @@ -package ru.ulstu.extractor.ts.creator.scheduled; +package ru.ulstu.extractor.ts.creator.db; import org.springframework.stereotype.Component; +import ru.ulstu.extractor.branch.model.Branch; import ru.ulstu.extractor.branch.service.BranchService; -import ru.ulstu.extractor.gitrepository.model.GitRepository; -import ru.ulstu.extractor.gitrepository.service.GitRepositoryService; import ru.ulstu.extractor.ts.model.TimeSeries; import ru.ulstu.extractor.ts.model.TimeSeriesType; import ru.ulstu.extractor.ts.service.TimeSeriesService; @@ -13,30 +12,25 @@ import java.util.Collections; import java.util.List; @Component -public class ProcessTS extends ScheduledTimeSeriesCreator { +public class ProcessTS extends DBTimeSeriesCreator { private final TimeSeriesService timeSeriesService; private final BranchService branchService; - private final GitRepositoryService gitRepositoryService; - public ProcessTS(TimeSeriesService timeSeriesService, - BranchService branchService, - GitRepositoryService gitRepositoryService) { + BranchService branchService) { this.timeSeriesService = timeSeriesService; this.branchService = branchService; - this.gitRepositoryService = gitRepositoryService; } @Override - public List getTimeSeries(Integer repositoryId, String branchName) { - GitRepository gitRepository = gitRepositoryService.findById(repositoryId); + public List getTimeSeries(Branch branch) { return Collections.singletonList( new TimeSeries( String.format("%s %s %s", - gitRepository.getName(), - branchName, + branch.getGitRepository().getName(), + branch.getName(), getTimeSeriesType().getDescription()), - branchService.findByRepositoryAndName(gitRepository, branchName), + branchService.findByRepositoryAndName(branch.getGitRepository(), branch.getName()), getTimeSeriesType(), Dummy.getDefaultTimeSeries())); } diff --git a/src/main/java/ru/ulstu/extractor/ts/creator/scheduled/AuthorTS.java b/src/main/java/ru/ulstu/extractor/ts/creator/scheduled/AuthorTS.java index 3caec78..768f16f 100644 --- a/src/main/java/ru/ulstu/extractor/ts/creator/scheduled/AuthorTS.java +++ b/src/main/java/ru/ulstu/extractor/ts/creator/scheduled/AuthorTS.java @@ -1,38 +1,20 @@ package ru.ulstu.extractor.ts.creator.scheduled; import org.springframework.stereotype.Component; -import ru.ulstu.extractor.author.model.Author; -import ru.ulstu.extractor.author.service.AuthorService; -import ru.ulstu.extractor.branch.service.BranchService; -import ru.ulstu.extractor.commit.model.Commit; -import ru.ulstu.extractor.commit.service.CommitService; -import ru.ulstu.extractor.gitrepository.model.GitRepository; -import ru.ulstu.extractor.gitrepository.service.GitRepositoryService; -import ru.ulstu.extractor.ts.creator.db.DBTimeSeriesCreator; -import ru.ulstu.extractor.ts.model.TimeSeries; +import ru.ulstu.extractor.branch.model.Branch; +import ru.ulstu.extractor.gitrepository.service.GitApi; import ru.ulstu.extractor.ts.model.TimeSeriesType; import ru.ulstu.extractor.ts.model.TimeSeriesValue; import ru.ulstu.extractor.ts.service.TimeSeriesService; -import java.util.ArrayList; -import java.util.List; - @Component -public class AuthorTS extends DBTimeSeriesCreator { +public class AuthorTS extends ScheduledTimeSeriesCreator { private final TimeSeriesService timeSeriesService; - private final CommitService commitService; - private final AuthorService authorService; - private final BranchService branchService; + private final GitApi gitApi; - public AuthorTS(TimeSeriesService timeSeriesService, - CommitService commitService, - AuthorService authorService, - GitRepositoryService gitRepositoryService, - BranchService branchService) { + public AuthorTS(TimeSeriesService timeSeriesService, GitApi gitApi) { this.timeSeriesService = timeSeriesService; - this.commitService = commitService; - this.authorService = authorService; - this.branchService = branchService; + this.gitApi = gitApi; } @Override @@ -41,29 +23,8 @@ public class AuthorTS extends DBTimeSeriesCreator { } @Override - public List getTimeSeries(GitRepository gitRepository, String branchName) { - List timeSeriesResult = new ArrayList<>(); - List authors = authorService.findAll(); - List commits = new ArrayList<>(commitService.findByRepositoryIdAndName(gitRepository.getId(), branchName)); - for (Author author : authors) { - TimeSeries timeSeries = new TimeSeries( - String.format("%s %s %s %s", - gitRepository.getName(), - branchName, - author.getName(), - getTimeSeriesType().getDescription()), - branchService.findByRepositoryAndName(gitRepository, branchName), - getTimeSeriesType()); - for (Commit commit : commits) { - if (commit.getAuthor().equals(author)) { - timeSeries.getValues().add(new TimeSeriesValue(commit.getDate(), 1.0)); - } - } - if (!timeSeries.getValues().isEmpty()) { - timeSeriesResult.add(timeSeries); - } - } - return timeSeriesResult; + public TimeSeriesValue getNewTimeSeriesValue(Branch branch) { + return new TimeSeriesValue(gitApi.getAuthorsCount(branch)); } @Override diff --git a/src/main/java/ru/ulstu/extractor/ts/creator/scheduled/AuthorsCompletedIssueTS.java b/src/main/java/ru/ulstu/extractor/ts/creator/scheduled/AuthorsCompletedIssueTS.java deleted file mode 100644 index 9eeb72d..0000000 --- a/src/main/java/ru/ulstu/extractor/ts/creator/scheduled/AuthorsCompletedIssueTS.java +++ /dev/null @@ -1,53 +0,0 @@ -package ru.ulstu.extractor.ts.creator.scheduled; - -import org.springframework.stereotype.Component; -import ru.ulstu.extractor.branch.service.BranchService; -import ru.ulstu.extractor.gitrepository.model.GitRepository; -import ru.ulstu.extractor.gitrepository.service.GitRepositoryService; -import ru.ulstu.extractor.ts.model.TimeSeries; -import ru.ulstu.extractor.ts.model.TimeSeriesType; -import ru.ulstu.extractor.ts.service.TimeSeriesService; -import ru.ulstu.extractor.ts.util.Dummy; - -import java.util.Collections; -import java.util.List; - -@Component -public class AuthorsCompletedIssueTS extends ScheduledTimeSeriesCreator { - private final TimeSeriesService timeSeriesService; - private final BranchService branchService; - - private final GitRepositoryService gitRepositoryService; - - public AuthorsCompletedIssueTS(TimeSeriesService timeSeriesService, - BranchService branchService, - GitRepositoryService gitRepositoryService) { - this.timeSeriesService = timeSeriesService; - this.branchService = branchService; - this.gitRepositoryService = gitRepositoryService; - } - - @Override - public List getTimeSeries(GitRepository gitRepository, String branchName) { - //TODO: добавить постраничное чтение - return Collections.singletonList( - new TimeSeries( - String.format("%s %s %s", - gitRepository.getName(), - branchName, - getTimeSeriesType().getDescription()), - branchService.findByRepositoryAndName(gitRepository, branchName), - getTimeSeriesType(), - Dummy.getDefaultTimeSeries())); - } - - @Override - public TimeSeriesService getTimeSeriesService() { - return timeSeriesService; - } - - @Override - public TimeSeriesType getTimeSeriesType() { - return TimeSeriesType.AUTHOR_COMPLETED_ISSUES; - } -} diff --git a/src/main/java/ru/ulstu/extractor/ts/creator/scheduled/AuthorsIssueTS.java b/src/main/java/ru/ulstu/extractor/ts/creator/scheduled/AuthorsIssueTS.java deleted file mode 100644 index 9407869..0000000 --- a/src/main/java/ru/ulstu/extractor/ts/creator/scheduled/AuthorsIssueTS.java +++ /dev/null @@ -1,53 +0,0 @@ -package ru.ulstu.extractor.ts.creator.scheduled; - -import org.springframework.stereotype.Component; -import ru.ulstu.extractor.branch.service.BranchService; -import ru.ulstu.extractor.gitrepository.model.GitRepository; -import ru.ulstu.extractor.gitrepository.service.GitRepositoryService; -import ru.ulstu.extractor.ts.model.TimeSeries; -import ru.ulstu.extractor.ts.model.TimeSeriesType; -import ru.ulstu.extractor.ts.service.TimeSeriesService; -import ru.ulstu.extractor.ts.util.Dummy; - -import java.util.Collections; -import java.util.List; - -@Component -public class AuthorsIssueTS extends ScheduledTimeSeriesCreator { - private final TimeSeriesService timeSeriesService; - private final BranchService branchService; - - private final GitRepositoryService gitRepositoryService; - - public AuthorsIssueTS(TimeSeriesService timeSeriesService, - BranchService branchService, - GitRepositoryService gitRepositoryService) { - this.timeSeriesService = timeSeriesService; - this.branchService = branchService; - this.gitRepositoryService = gitRepositoryService; - } - - @Override - public List getTimeSeries(Integer repositoryId, String branchName) { - GitRepository gitRepository = gitRepositoryService.findById(repositoryId); - return Collections.singletonList( - new TimeSeries( - String.format("%s %s %s", - gitRepository.getName(), - branchName, - getTimeSeriesType().getDescription()), - branchService.findByRepositoryAndName(gitRepository, branchName), - getTimeSeriesType(), - Dummy.getDefaultTimeSeries())); - } - - @Override - public TimeSeriesService getTimeSeriesService() { - return timeSeriesService; - } - - @Override - public TimeSeriesType getTimeSeriesType() { - return TimeSeriesType.AUTHOR_ISSUES; - } -}