From 0d43bf8ccd71cb79d5ad824217c3d84c62fbdbe0 Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Wed, 15 Feb 2023 00:55:06 +0400 Subject: [PATCH 1/5] #89 -- Use git service api to create time series --- .../gitrepository/service/GitApi.java | 13 +++++ .../gitrepository/service/GitAtheneApi.java | 45 ++++++++++++++++ .../gitrepository/service/IndexService.java | 9 ++-- .../ru/ulstu/extractor/http/HttpService.java | 23 ++++++++ .../ts/creator/AbstractTimeSeriesCreator.java | 39 -------------- .../ulstu/extractor/ts/creator/BranchTS.java | 53 ------------------- .../ulstu/extractor/ts/creator/IssuesTS.java | 53 ------------------- .../ru/ulstu/extractor/ts/creator/StarTS.java | 53 ------------------- .../ts/creator/{ => db}/AuthorsCommitTS.java | 13 ++--- .../ts/creator/{ => db}/CommitsTS.java | 13 ++--- .../ts/creator/db/DBTimeSeriesCreator.java | 45 ++++++++++++++++ .../extractor/ts/creator/{ => db}/FileTS.java | 13 ++--- .../ts/creator/{ => scheduled}/AuthorTS.java | 12 ++--- .../AuthorsCompletedIssueTS.java | 7 ++- .../{ => scheduled}/AuthorsIssueTS.java | 4 +- .../ts/creator/scheduled/BranchTS.java | 35 ++++++++++++ .../ts/creator/{ => scheduled}/ClassTS.java | 3 +- .../creator/{ => scheduled}/DependenceTS.java | 3 +- .../ts/creator/{ => scheduled}/EntityTS.java | 3 +- .../creator/{ => scheduled}/InterfaceTS.java | 3 +- .../ts/creator/scheduled/IssuesTS.java | 35 ++++++++++++ .../ts/creator/{ => scheduled}/ProcessTS.java | 4 +- .../scheduled/ScheduledTimeSeriesCreator.java | 20 +++++++ .../ts/creator/scheduled/StarTS.java | 34 ++++++++++++ .../ulstu/extractor/ts/model/TimeSeries.java | 7 +++ .../extractor/ts/model/TimeSeriesValue.java | 5 ++ .../ts/repository/TimeSeriesRepository.java | 4 ++ .../service/ScheduledTimeSeriesService.java | 34 ++++++++++++ .../ts/service/TimeSeriesService.java | 11 +++- 29 files changed, 346 insertions(+), 250 deletions(-) create mode 100644 src/main/java/ru/ulstu/extractor/gitrepository/service/GitApi.java create mode 100644 src/main/java/ru/ulstu/extractor/gitrepository/service/GitAtheneApi.java delete mode 100644 src/main/java/ru/ulstu/extractor/ts/creator/BranchTS.java delete mode 100644 src/main/java/ru/ulstu/extractor/ts/creator/IssuesTS.java delete mode 100644 src/main/java/ru/ulstu/extractor/ts/creator/StarTS.java rename src/main/java/ru/ulstu/extractor/ts/creator/{ => db}/AuthorsCommitTS.java (81%) rename src/main/java/ru/ulstu/extractor/ts/creator/{ => db}/CommitsTS.java (78%) create mode 100644 src/main/java/ru/ulstu/extractor/ts/creator/db/DBTimeSeriesCreator.java rename src/main/java/ru/ulstu/extractor/ts/creator/{ => db}/FileTS.java (81%) rename src/main/java/ru/ulstu/extractor/ts/creator/{ => scheduled}/AuthorTS.java (85%) rename src/main/java/ru/ulstu/extractor/ts/creator/{ => scheduled}/AuthorsCompletedIssueTS.java (86%) rename src/main/java/ru/ulstu/extractor/ts/creator/{ => scheduled}/AuthorsIssueTS.java (94%) create mode 100644 src/main/java/ru/ulstu/extractor/ts/creator/scheduled/BranchTS.java rename src/main/java/ru/ulstu/extractor/ts/creator/{ => scheduled}/ClassTS.java (94%) rename src/main/java/ru/ulstu/extractor/ts/creator/{ => scheduled}/DependenceTS.java (94%) rename src/main/java/ru/ulstu/extractor/ts/creator/{ => scheduled}/EntityTS.java (96%) rename src/main/java/ru/ulstu/extractor/ts/creator/{ => scheduled}/InterfaceTS.java (94%) create mode 100644 src/main/java/ru/ulstu/extractor/ts/creator/scheduled/IssuesTS.java rename src/main/java/ru/ulstu/extractor/ts/creator/{ => scheduled}/ProcessTS.java (94%) create mode 100644 src/main/java/ru/ulstu/extractor/ts/creator/scheduled/ScheduledTimeSeriesCreator.java create mode 100644 src/main/java/ru/ulstu/extractor/ts/creator/scheduled/StarTS.java create mode 100644 src/main/java/ru/ulstu/extractor/ts/service/ScheduledTimeSeriesService.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 new file mode 100644 index 0000000..3aa4e59 --- /dev/null +++ b/src/main/java/ru/ulstu/extractor/gitrepository/service/GitApi.java @@ -0,0 +1,13 @@ +package ru.ulstu.extractor.gitrepository.service; + +import ru.ulstu.extractor.branch.model.Branch; + +public interface GitApi { + Integer getBranchesCount(Branch branch); + + Integer getStarsCount(Branch branch); + + Integer getOpenIssuesCount(Branch branch); + + String getFormattedUrl(String gitRepositoryUrl, String template); +} diff --git a/src/main/java/ru/ulstu/extractor/gitrepository/service/GitAtheneApi.java b/src/main/java/ru/ulstu/extractor/gitrepository/service/GitAtheneApi.java new file mode 100644 index 0000000..a8853dc --- /dev/null +++ b/src/main/java/ru/ulstu/extractor/gitrepository/service/GitAtheneApi.java @@ -0,0 +1,45 @@ +package ru.ulstu.extractor.gitrepository.service; + +import org.springframework.stereotype.Service; +import ru.ulstu.extractor.branch.model.Branch; +import ru.ulstu.extractor.http.HttpService; + +@Service +public class GitAtheneApi implements GitApi { + private final HttpService httpService; + 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"; + + public GitAtheneApi(HttpService httpService) { + this.httpService = httpService; + } + + @Override + public Integer getBranchesCount(Branch branch) { + return httpService + .get(getFormattedUrl(branch.getGitRepository().getUrl(), BRANCHES_COUNT_URL)) + .length(); + } + + @Override + public Integer getStarsCount(Branch branch) { + return httpService + .get(getFormattedUrl(branch.getGitRepository().getUrl(), STARS_COUNT_URL)) + .getJSONObject(0) + .getInt("stars_count"); + } + + @Override + public Integer getOpenIssuesCount(Branch branch) { + return httpService + .get(getFormattedUrl(branch.getGitRepository().getUrl(), OPEN_ISSUES_URL)) + .length(); + } + + @Override + public String getFormattedUrl(String gitRepositoryUrl, String template) { + String[] urlParts = gitRepositoryUrl.split("/"); + return String.format(template, urlParts[0] + "/" + urlParts[1] + "/" + urlParts[2], urlParts[3], urlParts[4]); + } +} 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 7c3b4bb..088aa22 100644 --- a/src/main/java/ru/ulstu/extractor/gitrepository/service/IndexService.java +++ b/src/main/java/ru/ulstu/extractor/gitrepository/service/IndexService.java @@ -18,7 +18,7 @@ import ru.ulstu.extractor.branch.service.BranchService; import ru.ulstu.extractor.commit.model.Commit; import ru.ulstu.extractor.gitrepository.model.GitRepository; import ru.ulstu.extractor.gitrepository.repository.GitRepositoryRepository; -import ru.ulstu.extractor.ts.creator.AbstractTimeSeriesCreator; +import ru.ulstu.extractor.ts.creator.db.DBTimeSeriesCreator; import java.io.IOException; import java.util.Collections; @@ -33,13 +33,13 @@ public class IndexService { private final GitRepositoryService gitRepositoryService; private final GitRepositoryRepository gitRepositoryRepository; private final BranchService branchService; - private final List timeSeriesCreators; + private final List timeSeriesCreators; private final static ExecutorService EXECUTOR = Executors.newFixedThreadPool(10); public IndexService(GitRepositoryService gitRepositoryService, GitRepositoryRepository gitRepositoryRepository, BranchService branchService, - List timeSeriesCreators) { + List timeSeriesCreators) { this.gitRepositoryService = gitRepositoryService; this.gitRepositoryRepository = gitRepositoryRepository; this.branchService = branchService; @@ -78,9 +78,8 @@ public class IndexService { commitsTo += COMMITS_PAGE_SIZE; commits = gitRepositoryService.getCommits(gitRepository.getUrl(), branch.getName(), commitsFrom, commitsTo, false); } - Integer repositoryId = gitRepository.getId(); final Branch branchForSave = branch; - timeSeriesCreators.forEach(tsCreator -> tsCreator.addTimeSeries(repositoryId, branchForSave)); + timeSeriesCreators.forEach(tsCreator -> tsCreator.addTimeSeries(gitRepository, branchForSave)); branchService.updateStatus(branch, IndexingStatus.FINISHED); LOG.debug("Complete indexing {} branch", branch.getName()); } diff --git a/src/main/java/ru/ulstu/extractor/http/HttpService.java b/src/main/java/ru/ulstu/extractor/http/HttpService.java index 6d79315..cc1884e 100644 --- a/src/main/java/ru/ulstu/extractor/http/HttpService.java +++ b/src/main/java/ru/ulstu/extractor/http/HttpService.java @@ -1,5 +1,6 @@ package ru.ulstu.extractor.http; +import org.json.JSONArray; import org.json.JSONObject; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -38,4 +39,26 @@ public class HttpService { log.debug("Service response: {}", response); return response; } + + public JSONArray get(String url) { + log.debug("Service call: {}", url); + try { + String response = client + .get() + .uri(url) + .accept(MediaType.APPLICATION_JSON) + .retrieve() + .bodyToMono(String.class) + .toFuture().get(); + if (response.startsWith("[")) { + return new JSONArray(response); + } else { + JSONArray jsonArray = new JSONArray(); + jsonArray.put(0, new JSONObject(response)); + return jsonArray; + } + } catch (Exception e) { + return new JSONArray("[{response:\"empty\"}]"); + } + } } diff --git a/src/main/java/ru/ulstu/extractor/ts/creator/AbstractTimeSeriesCreator.java b/src/main/java/ru/ulstu/extractor/ts/creator/AbstractTimeSeriesCreator.java index cad3156..c6a2f2b 100644 --- a/src/main/java/ru/ulstu/extractor/ts/creator/AbstractTimeSeriesCreator.java +++ b/src/main/java/ru/ulstu/extractor/ts/creator/AbstractTimeSeriesCreator.java @@ -1,49 +1,10 @@ package ru.ulstu.extractor.ts.creator; -import ru.ulstu.extractor.branch.model.Branch; -import ru.ulstu.extractor.ts.model.TimeSeries; import ru.ulstu.extractor.ts.model.TimeSeriesType; -import ru.ulstu.extractor.ts.model.TimeSeriesValue; import ru.ulstu.extractor.ts.service.TimeSeriesService; -import java.util.Comparator; -import java.util.List; - -import static ru.ulstu.extractor.ts.util.TimeSeriesDateMapper.mapTimeSeriesToInterval; - public abstract class AbstractTimeSeriesCreator { public abstract TimeSeriesType getTimeSeriesType(); - /** - * Извлечь список точек временных рядов - * - * @param repositoryId - * @param branchName - * @return - */ - public abstract List getTimeSeries(Integer repositoryId, String branchName); - public abstract TimeSeriesService getTimeSeriesService(); - - /** - * Сохранить извлеченные временные ряды - * - * @param repositoryId - * @param branch - */ - public void addTimeSeries(Integer repositoryId, Branch branch) { - // извлеченные временных рядов - List timeSeries = getTimeSeries(repositoryId, branch.getName()); - - // сгруппированные по временным интервалам точки временных рядов - timeSeries.forEach(ts -> ts.setValues(mapTimeSeriesToInterval(getTimeSeriesService().getTimeSeriesInterval(), ts.getValues()))); - getTimeSeriesService().save(sortTimeSeries(timeSeries), branch); - } - - private List sortTimeSeries(List timeSeries) { - for (TimeSeries ts : timeSeries) { - ts.getValues().sort(Comparator.comparing(TimeSeriesValue::getDate)); - } - return timeSeries; - } } diff --git a/src/main/java/ru/ulstu/extractor/ts/creator/BranchTS.java b/src/main/java/ru/ulstu/extractor/ts/creator/BranchTS.java deleted file mode 100644 index a6d99f0..0000000 --- a/src/main/java/ru/ulstu/extractor/ts/creator/BranchTS.java +++ /dev/null @@ -1,53 +0,0 @@ -package ru.ulstu.extractor.ts.creator; - -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 BranchTS extends AbstractTimeSeriesCreator { - private final TimeSeriesService timeSeriesService; - private final BranchService branchService; - - private final GitRepositoryService gitRepositoryService; - - public BranchTS(TimeSeriesService timeSeriesService, - BranchService branchService, - GitRepositoryService gitRepositoryService) { - this.timeSeriesService = timeSeriesService; - this.branchService = branchService; - this.gitRepositoryService = gitRepositoryService; - } - - @Override - public TimeSeriesType getTimeSeriesType() { - return TimeSeriesType.BRANCHES; - } - - @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; - } -} diff --git a/src/main/java/ru/ulstu/extractor/ts/creator/IssuesTS.java b/src/main/java/ru/ulstu/extractor/ts/creator/IssuesTS.java deleted file mode 100644 index af43b83..0000000 --- a/src/main/java/ru/ulstu/extractor/ts/creator/IssuesTS.java +++ /dev/null @@ -1,53 +0,0 @@ -package ru.ulstu.extractor.ts.creator; - -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 IssuesTS extends AbstractTimeSeriesCreator { - private final TimeSeriesService timeSeriesService; - private final BranchService branchService; - - private final GitRepositoryService gitRepositoryService; - - public IssuesTS(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.ISSUES; - } -} diff --git a/src/main/java/ru/ulstu/extractor/ts/creator/StarTS.java b/src/main/java/ru/ulstu/extractor/ts/creator/StarTS.java deleted file mode 100644 index 0bbcf93..0000000 --- a/src/main/java/ru/ulstu/extractor/ts/creator/StarTS.java +++ /dev/null @@ -1,53 +0,0 @@ -package ru.ulstu.extractor.ts.creator; - -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 StarTS extends AbstractTimeSeriesCreator { - private final TimeSeriesService timeSeriesService; - private final BranchService branchService; - - private final GitRepositoryService gitRepositoryService; - - public StarTS(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.STARS; - } -} diff --git a/src/main/java/ru/ulstu/extractor/ts/creator/AuthorsCommitTS.java b/src/main/java/ru/ulstu/extractor/ts/creator/db/AuthorsCommitTS.java similarity index 81% rename from src/main/java/ru/ulstu/extractor/ts/creator/AuthorsCommitTS.java rename to src/main/java/ru/ulstu/extractor/ts/creator/db/AuthorsCommitTS.java index 86ec31d..dc95528 100644 --- a/src/main/java/ru/ulstu/extractor/ts/creator/AuthorsCommitTS.java +++ b/src/main/java/ru/ulstu/extractor/ts/creator/db/AuthorsCommitTS.java @@ -1,4 +1,4 @@ -package ru.ulstu.extractor.ts.creator; +package ru.ulstu.extractor.ts.creator.db; import org.springframework.stereotype.Component; import ru.ulstu.extractor.author.model.Author; @@ -7,7 +7,6 @@ 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.model.TimeSeries; import ru.ulstu.extractor.ts.model.TimeSeriesType; import ru.ulstu.extractor.ts.model.TimeSeriesValue; @@ -17,22 +16,19 @@ import java.util.ArrayList; import java.util.List; @Component -public class AuthorsCommitTS extends AbstractTimeSeriesCreator { +public class AuthorsCommitTS extends DBTimeSeriesCreator { private final TimeSeriesService timeSeriesService; private final CommitService commitService; private final AuthorService authorService; - private final GitRepositoryService gitRepositoryService; private final BranchService branchService; public AuthorsCommitTS(TimeSeriesService timeSeriesService, CommitService commitService, AuthorService authorService, - GitRepositoryService gitRepositoryService, BranchService branchService) { this.timeSeriesService = timeSeriesService; this.commitService = commitService; this.authorService = authorService; - this.gitRepositoryService = gitRepositoryService; this.branchService = branchService; } @@ -42,11 +38,10 @@ public class AuthorsCommitTS extends AbstractTimeSeriesCreator { } @Override - public List getTimeSeries(Integer repositoryId, String branchName) { + public List getTimeSeries(GitRepository gitRepository, String branchName) { List timeSeriesResult = new ArrayList<>(); List authors = authorService.findAll(); - GitRepository gitRepository = gitRepositoryService.findById(repositoryId); - List commits = new ArrayList<>(commitService.findByRepositoryIdAndName(repositoryId, branchName)); + List commits = new ArrayList<>(commitService.findByRepositoryIdAndName(gitRepository.getId(), branchName)); for (Author author : authors) { TimeSeries timeSeries = new TimeSeries( String.format("%s %s %s %s", diff --git a/src/main/java/ru/ulstu/extractor/ts/creator/CommitsTS.java b/src/main/java/ru/ulstu/extractor/ts/creator/db/CommitsTS.java similarity index 78% rename from src/main/java/ru/ulstu/extractor/ts/creator/CommitsTS.java rename to src/main/java/ru/ulstu/extractor/ts/creator/db/CommitsTS.java index 0b7ed9d..523ff76 100644 --- a/src/main/java/ru/ulstu/extractor/ts/creator/CommitsTS.java +++ b/src/main/java/ru/ulstu/extractor/ts/creator/db/CommitsTS.java @@ -1,10 +1,9 @@ -package ru.ulstu.extractor.ts.creator; +package ru.ulstu.extractor.ts.creator.db; import org.springframework.stereotype.Component; 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.gitrepository.service.GitRepositoryService; import ru.ulstu.extractor.ts.model.TimeSeries; import ru.ulstu.extractor.ts.model.TimeSeriesType; import ru.ulstu.extractor.ts.model.TimeSeriesValue; @@ -15,25 +14,21 @@ import java.util.List; import java.util.stream.Collectors; @Component -public class CommitsTS extends AbstractTimeSeriesCreator { +public class CommitsTS extends DBTimeSeriesCreator { private final TimeSeriesService timeSeriesService; private final CommitService commitService; - private final GitRepositoryService gitRepositoryService; private final BranchService branchService; public CommitsTS(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(GitRepository gitRepository, String branchName) { //TODO: добавить постраничное чтение return Collections.singletonList( new TimeSeries( @@ -43,7 +38,7 @@ public class CommitsTS extends AbstractTimeSeriesCreator { getTimeSeriesType().getDescription()), branchService.findByRepositoryAndName(gitRepository, branchName), getTimeSeriesType(), - commitService.findByRepositoryIdAndName(repositoryId, branchName) + commitService.findByRepositoryIdAndName(gitRepository.getId(), branchName) .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 new file mode 100644 index 0000000..7de98b7 --- /dev/null +++ b/src/main/java/ru/ulstu/extractor/ts/creator/db/DBTimeSeriesCreator.java @@ -0,0 +1,45 @@ +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; + +import java.util.Comparator; +import java.util.List; + +import static ru.ulstu.extractor.ts.util.TimeSeriesDateMapper.mapTimeSeriesToInterval; + +public abstract class DBTimeSeriesCreator extends AbstractTimeSeriesCreator { + /** + * Извлечь список точек временных рядов + * + * @param gitRepository + * @param branchName + * @return + */ + public abstract List getTimeSeries(GitRepository gitRepository, String branchName); + + /** + * Сохранить извлеченные временные ряды + * + * @param gitRepository + * @param branch + */ + public void addTimeSeries(GitRepository gitRepository, Branch branch) { + // извлеченные временных рядов + List timeSeries = getTimeSeries(gitRepository, branch.getName()); + + // сгруппированные по временным интервалам точки временных рядов + timeSeries.forEach(ts -> ts.setValues(mapTimeSeriesToInterval(getTimeSeriesService().getTimeSeriesInterval(), ts.getValues()))); + getTimeSeriesService().save(sortTimeSeries(timeSeries), branch); + } + + private List sortTimeSeries(List timeSeries) { + for (TimeSeries ts : timeSeries) { + ts.getValues().sort(Comparator.comparing(TimeSeriesValue::getDate)); + } + return timeSeries; + } +} diff --git a/src/main/java/ru/ulstu/extractor/ts/creator/FileTS.java b/src/main/java/ru/ulstu/extractor/ts/creator/db/FileTS.java similarity index 81% rename from src/main/java/ru/ulstu/extractor/ts/creator/FileTS.java rename to src/main/java/ru/ulstu/extractor/ts/creator/db/FileTS.java index 5d5f21a..dd845f6 100644 --- a/src/main/java/ru/ulstu/extractor/ts/creator/FileTS.java +++ b/src/main/java/ru/ulstu/extractor/ts/creator/db/FileTS.java @@ -1,4 +1,4 @@ -package ru.ulstu.extractor.ts.creator; +package ru.ulstu.extractor.ts.creator.db; import org.springframework.stereotype.Component; import ru.ulstu.extractor.branch.service.BranchService; @@ -6,7 +6,6 @@ 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.model.TimeSeries; import ru.ulstu.extractor.ts.model.TimeSeriesType; import ru.ulstu.extractor.ts.model.TimeSeriesValue; @@ -16,27 +15,23 @@ import java.util.ArrayList; import java.util.List; @Component -public class FileTS extends AbstractTimeSeriesCreator { +public class FileTS extends DBTimeSeriesCreator { private final TimeSeriesService timeSeriesService; - private final GitRepositoryService gitRepositoryService; private final CommitService commitService; private final BranchService branchService; public FileTS(TimeSeriesService timeSeriesService, - GitRepositoryService gitRepositoryService, CommitService commitService, BranchService branchService) { this.timeSeriesService = timeSeriesService; - this.gitRepositoryService = gitRepositoryService; this.commitService = commitService; this.branchService = branchService; } @Override - public List getTimeSeries(Integer repositoryId, String branchName) { - GitRepository gitRepository = gitRepositoryService.findById(repositoryId); + public List getTimeSeries(GitRepository gitRepository, String branchName) { List timeSeriesResult = new ArrayList<>(); - List commits = new ArrayList<>(commitService.findByRepositoryIdAndName(repositoryId, branchName)); + List commits = new ArrayList<>(commitService.findByRepositoryIdAndName(gitRepository.getId(), branchName)); double value = 0; TimeSeries timeSeries = new TimeSeries( String.format("%s %s %s", diff --git a/src/main/java/ru/ulstu/extractor/ts/creator/AuthorTS.java b/src/main/java/ru/ulstu/extractor/ts/creator/scheduled/AuthorTS.java similarity index 85% rename from src/main/java/ru/ulstu/extractor/ts/creator/AuthorTS.java rename to src/main/java/ru/ulstu/extractor/ts/creator/scheduled/AuthorTS.java index f2fd7cf..3caec78 100644 --- a/src/main/java/ru/ulstu/extractor/ts/creator/AuthorTS.java +++ b/src/main/java/ru/ulstu/extractor/ts/creator/scheduled/AuthorTS.java @@ -1,4 +1,4 @@ -package ru.ulstu.extractor.ts.creator; +package ru.ulstu.extractor.ts.creator.scheduled; import org.springframework.stereotype.Component; import ru.ulstu.extractor.author.model.Author; @@ -8,6 +8,7 @@ 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.ts.model.TimeSeriesType; import ru.ulstu.extractor.ts.model.TimeSeriesValue; @@ -17,11 +18,10 @@ import java.util.ArrayList; import java.util.List; @Component -public class AuthorTS extends AbstractTimeSeriesCreator { +public class AuthorTS extends DBTimeSeriesCreator { private final TimeSeriesService timeSeriesService; private final CommitService commitService; private final AuthorService authorService; - private final GitRepositoryService gitRepositoryService; private final BranchService branchService; public AuthorTS(TimeSeriesService timeSeriesService, @@ -32,7 +32,6 @@ public class AuthorTS extends AbstractTimeSeriesCreator { this.timeSeriesService = timeSeriesService; this.commitService = commitService; this.authorService = authorService; - this.gitRepositoryService = gitRepositoryService; this.branchService = branchService; } @@ -42,11 +41,10 @@ public class AuthorTS extends AbstractTimeSeriesCreator { } @Override - public List getTimeSeries(Integer repositoryId, String branchName) { + public List getTimeSeries(GitRepository gitRepository, String branchName) { List timeSeriesResult = new ArrayList<>(); List authors = authorService.findAll(); - GitRepository gitRepository = gitRepositoryService.findById(repositoryId); - List commits = new ArrayList<>(commitService.findByRepositoryIdAndName(repositoryId, branchName)); + List commits = new ArrayList<>(commitService.findByRepositoryIdAndName(gitRepository.getId(), branchName)); for (Author author : authors) { TimeSeries timeSeries = new TimeSeries( String.format("%s %s %s %s", diff --git a/src/main/java/ru/ulstu/extractor/ts/creator/AuthorsCompletedIssueTS.java b/src/main/java/ru/ulstu/extractor/ts/creator/scheduled/AuthorsCompletedIssueTS.java similarity index 86% rename from src/main/java/ru/ulstu/extractor/ts/creator/AuthorsCompletedIssueTS.java rename to src/main/java/ru/ulstu/extractor/ts/creator/scheduled/AuthorsCompletedIssueTS.java index 700b6cb..9eeb72d 100644 --- a/src/main/java/ru/ulstu/extractor/ts/creator/AuthorsCompletedIssueTS.java +++ b/src/main/java/ru/ulstu/extractor/ts/creator/scheduled/AuthorsCompletedIssueTS.java @@ -1,4 +1,4 @@ -package ru.ulstu.extractor.ts.creator; +package ru.ulstu.extractor.ts.creator.scheduled; import org.springframework.stereotype.Component; import ru.ulstu.extractor.branch.service.BranchService; @@ -13,7 +13,7 @@ import java.util.Collections; import java.util.List; @Component -public class AuthorsCompletedIssueTS extends AbstractTimeSeriesCreator { +public class AuthorsCompletedIssueTS extends ScheduledTimeSeriesCreator { private final TimeSeriesService timeSeriesService; private final BranchService branchService; @@ -28,8 +28,7 @@ public class AuthorsCompletedIssueTS extends AbstractTimeSeriesCreator { } @Override - public List getTimeSeries(Integer repositoryId, String branchName) { - GitRepository gitRepository = gitRepositoryService.findById(repositoryId); + public List getTimeSeries(GitRepository gitRepository, String branchName) { //TODO: добавить постраничное чтение return Collections.singletonList( new TimeSeries( diff --git a/src/main/java/ru/ulstu/extractor/ts/creator/AuthorsIssueTS.java b/src/main/java/ru/ulstu/extractor/ts/creator/scheduled/AuthorsIssueTS.java similarity index 94% rename from src/main/java/ru/ulstu/extractor/ts/creator/AuthorsIssueTS.java rename to src/main/java/ru/ulstu/extractor/ts/creator/scheduled/AuthorsIssueTS.java index c4fa9ea..9407869 100644 --- a/src/main/java/ru/ulstu/extractor/ts/creator/AuthorsIssueTS.java +++ b/src/main/java/ru/ulstu/extractor/ts/creator/scheduled/AuthorsIssueTS.java @@ -1,4 +1,4 @@ -package ru.ulstu.extractor.ts.creator; +package ru.ulstu.extractor.ts.creator.scheduled; import org.springframework.stereotype.Component; import ru.ulstu.extractor.branch.service.BranchService; @@ -13,7 +13,7 @@ import java.util.Collections; import java.util.List; @Component -public class AuthorsIssueTS extends AbstractTimeSeriesCreator { +public class AuthorsIssueTS extends ScheduledTimeSeriesCreator { private final TimeSeriesService timeSeriesService; private final BranchService branchService; diff --git a/src/main/java/ru/ulstu/extractor/ts/creator/scheduled/BranchTS.java b/src/main/java/ru/ulstu/extractor/ts/creator/scheduled/BranchTS.java new file mode 100644 index 0000000..4ef0042 --- /dev/null +++ b/src/main/java/ru/ulstu/extractor/ts/creator/scheduled/BranchTS.java @@ -0,0 +1,35 @@ +package ru.ulstu.extractor.ts.creator.scheduled; + +import org.springframework.stereotype.Component; +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; + +@Component +public class BranchTS extends ScheduledTimeSeriesCreator { + private final TimeSeriesService timeSeriesService; + private final GitApi gitApi; + + public BranchTS(TimeSeriesService timeSeriesService, + GitApi gitApi) { + this.timeSeriesService = timeSeriesService; + this.gitApi = gitApi; + } + + @Override + public TimeSeriesType getTimeSeriesType() { + return TimeSeriesType.BRANCHES; + } + + @Override + public TimeSeriesService getTimeSeriesService() { + return timeSeriesService; + } + + @Override + public TimeSeriesValue getNewTimeSeriesValue(Branch branch) { + return new TimeSeriesValue(gitApi.getBranchesCount(branch)); + } +} diff --git a/src/main/java/ru/ulstu/extractor/ts/creator/ClassTS.java b/src/main/java/ru/ulstu/extractor/ts/creator/scheduled/ClassTS.java similarity index 94% rename from src/main/java/ru/ulstu/extractor/ts/creator/ClassTS.java rename to src/main/java/ru/ulstu/extractor/ts/creator/scheduled/ClassTS.java index f284e90..6062fc0 100644 --- a/src/main/java/ru/ulstu/extractor/ts/creator/ClassTS.java +++ b/src/main/java/ru/ulstu/extractor/ts/creator/scheduled/ClassTS.java @@ -1,9 +1,10 @@ -package ru.ulstu.extractor.ts.creator; +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.creator.AbstractTimeSeriesCreator; import ru.ulstu.extractor.ts.model.TimeSeries; import ru.ulstu.extractor.ts.model.TimeSeriesType; import ru.ulstu.extractor.ts.service.TimeSeriesService; diff --git a/src/main/java/ru/ulstu/extractor/ts/creator/DependenceTS.java b/src/main/java/ru/ulstu/extractor/ts/creator/scheduled/DependenceTS.java similarity index 94% rename from src/main/java/ru/ulstu/extractor/ts/creator/DependenceTS.java rename to src/main/java/ru/ulstu/extractor/ts/creator/scheduled/DependenceTS.java index d89b5e8..d53c5b6 100644 --- a/src/main/java/ru/ulstu/extractor/ts/creator/DependenceTS.java +++ b/src/main/java/ru/ulstu/extractor/ts/creator/scheduled/DependenceTS.java @@ -1,9 +1,10 @@ -package ru.ulstu.extractor.ts.creator; +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.creator.AbstractTimeSeriesCreator; import ru.ulstu.extractor.ts.model.TimeSeries; import ru.ulstu.extractor.ts.model.TimeSeriesType; import ru.ulstu.extractor.ts.service.TimeSeriesService; diff --git a/src/main/java/ru/ulstu/extractor/ts/creator/EntityTS.java b/src/main/java/ru/ulstu/extractor/ts/creator/scheduled/EntityTS.java similarity index 96% rename from src/main/java/ru/ulstu/extractor/ts/creator/EntityTS.java rename to src/main/java/ru/ulstu/extractor/ts/creator/scheduled/EntityTS.java index b20dabd..3666d6b 100644 --- a/src/main/java/ru/ulstu/extractor/ts/creator/EntityTS.java +++ b/src/main/java/ru/ulstu/extractor/ts/creator/scheduled/EntityTS.java @@ -1,4 +1,4 @@ -package ru.ulstu.extractor.ts.creator; +package ru.ulstu.extractor.ts.creator.scheduled; import org.springframework.stereotype.Component; import ru.ulstu.extractor.branch.service.BranchService; @@ -7,6 +7,7 @@ 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; diff --git a/src/main/java/ru/ulstu/extractor/ts/creator/InterfaceTS.java b/src/main/java/ru/ulstu/extractor/ts/creator/scheduled/InterfaceTS.java similarity index 94% rename from src/main/java/ru/ulstu/extractor/ts/creator/InterfaceTS.java rename to src/main/java/ru/ulstu/extractor/ts/creator/scheduled/InterfaceTS.java index 4c00620..efc1827 100644 --- a/src/main/java/ru/ulstu/extractor/ts/creator/InterfaceTS.java +++ b/src/main/java/ru/ulstu/extractor/ts/creator/scheduled/InterfaceTS.java @@ -1,9 +1,10 @@ -package ru.ulstu.extractor.ts.creator; +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.creator.AbstractTimeSeriesCreator; import ru.ulstu.extractor.ts.model.TimeSeries; import ru.ulstu.extractor.ts.model.TimeSeriesType; import ru.ulstu.extractor.ts.service.TimeSeriesService; diff --git a/src/main/java/ru/ulstu/extractor/ts/creator/scheduled/IssuesTS.java b/src/main/java/ru/ulstu/extractor/ts/creator/scheduled/IssuesTS.java new file mode 100644 index 0000000..69907c6 --- /dev/null +++ b/src/main/java/ru/ulstu/extractor/ts/creator/scheduled/IssuesTS.java @@ -0,0 +1,35 @@ +package ru.ulstu.extractor.ts.creator.scheduled; + +import org.springframework.stereotype.Component; +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; + +@Component +public class IssuesTS extends ScheduledTimeSeriesCreator { + private final TimeSeriesService timeSeriesService; + private final GitApi gitApi; + + public IssuesTS(TimeSeriesService timeSeriesService, + GitApi gitApi) { + this.timeSeriesService = timeSeriesService; + this.gitApi = gitApi; + } + + @Override + public TimeSeriesValue getNewTimeSeriesValue(Branch branch) { + return new TimeSeriesValue(gitApi.getOpenIssuesCount(branch)); + } + + @Override + public TimeSeriesService getTimeSeriesService() { + return timeSeriesService; + } + + @Override + public TimeSeriesType getTimeSeriesType() { + return TimeSeriesType.ISSUES; + } +} diff --git a/src/main/java/ru/ulstu/extractor/ts/creator/ProcessTS.java b/src/main/java/ru/ulstu/extractor/ts/creator/scheduled/ProcessTS.java similarity index 94% rename from src/main/java/ru/ulstu/extractor/ts/creator/ProcessTS.java rename to src/main/java/ru/ulstu/extractor/ts/creator/scheduled/ProcessTS.java index c172063..1dd4675 100644 --- a/src/main/java/ru/ulstu/extractor/ts/creator/ProcessTS.java +++ b/src/main/java/ru/ulstu/extractor/ts/creator/scheduled/ProcessTS.java @@ -1,4 +1,4 @@ -package ru.ulstu.extractor.ts.creator; +package ru.ulstu.extractor.ts.creator.scheduled; import org.springframework.stereotype.Component; import ru.ulstu.extractor.branch.service.BranchService; @@ -13,7 +13,7 @@ import java.util.Collections; import java.util.List; @Component -public class ProcessTS extends AbstractTimeSeriesCreator { +public class ProcessTS extends ScheduledTimeSeriesCreator { private final TimeSeriesService timeSeriesService; private final BranchService branchService; diff --git a/src/main/java/ru/ulstu/extractor/ts/creator/scheduled/ScheduledTimeSeriesCreator.java b/src/main/java/ru/ulstu/extractor/ts/creator/scheduled/ScheduledTimeSeriesCreator.java new file mode 100644 index 0000000..1be6322 --- /dev/null +++ b/src/main/java/ru/ulstu/extractor/ts/creator/scheduled/ScheduledTimeSeriesCreator.java @@ -0,0 +1,20 @@ +package ru.ulstu.extractor.ts.creator.scheduled; + +import org.springframework.transaction.annotation.Transactional; +import ru.ulstu.extractor.branch.model.Branch; +import ru.ulstu.extractor.ts.creator.AbstractTimeSeriesCreator; +import ru.ulstu.extractor.ts.model.TimeSeries; +import ru.ulstu.extractor.ts.model.TimeSeriesValue; + +import java.util.Collections; + +public abstract class ScheduledTimeSeriesCreator extends AbstractTimeSeriesCreator { + @Transactional + public void addTimeSeriesValue(Branch branch) { + TimeSeries timeSeries = getTimeSeriesService().findByBranchAndTypeOrCreate(branch, getTimeSeriesType()); + timeSeries.getValues().add(getNewTimeSeriesValue(branch)); + getTimeSeriesService().save(Collections.singletonList(timeSeries), branch); + } + + public abstract TimeSeriesValue getNewTimeSeriesValue(Branch branch); +} diff --git a/src/main/java/ru/ulstu/extractor/ts/creator/scheduled/StarTS.java b/src/main/java/ru/ulstu/extractor/ts/creator/scheduled/StarTS.java new file mode 100644 index 0000000..6422822 --- /dev/null +++ b/src/main/java/ru/ulstu/extractor/ts/creator/scheduled/StarTS.java @@ -0,0 +1,34 @@ +package ru.ulstu.extractor.ts.creator.scheduled; + +import org.springframework.stereotype.Component; +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; + +@Component +public class StarTS extends ScheduledTimeSeriesCreator { + private final TimeSeriesService timeSeriesService; + private final GitApi gitApi; + + public StarTS(TimeSeriesService timeSeriesService, GitApi gitApi) { + this.timeSeriesService = timeSeriesService; + this.gitApi = gitApi; + } + + @Override + public TimeSeriesService getTimeSeriesService() { + return timeSeriesService; + } + + @Override + public TimeSeriesType getTimeSeriesType() { + return TimeSeriesType.STARS; + } + + @Override + public TimeSeriesValue getNewTimeSeriesValue(Branch branch) { + return new TimeSeriesValue(gitApi.getStarsCount(branch)); + } +} diff --git a/src/main/java/ru/ulstu/extractor/ts/model/TimeSeries.java b/src/main/java/ru/ulstu/extractor/ts/model/TimeSeries.java index 5e302fa..76abf70 100644 --- a/src/main/java/ru/ulstu/extractor/ts/model/TimeSeries.java +++ b/src/main/java/ru/ulstu/extractor/ts/model/TimeSeries.java @@ -33,6 +33,13 @@ public class TimeSeries extends BaseEntity { public TimeSeries() { } + public TimeSeries(Branch branch, TimeSeriesType timeSeriesType) { + this(String.format("%s %s %s", + branch.getGitRepository().getName(), + branch.getName(), + timeSeriesType.getDescription()), branch, timeSeriesType); + } + public TimeSeries(String name, Branch branch, TimeSeriesType timeSeriesType) { this(name, branch, timeSeriesType, new ArrayList<>()); } diff --git a/src/main/java/ru/ulstu/extractor/ts/model/TimeSeriesValue.java b/src/main/java/ru/ulstu/extractor/ts/model/TimeSeriesValue.java index 112b4c5..9b77f2a 100644 --- a/src/main/java/ru/ulstu/extractor/ts/model/TimeSeriesValue.java +++ b/src/main/java/ru/ulstu/extractor/ts/model/TimeSeriesValue.java @@ -18,6 +18,11 @@ public class TimeSeriesValue extends BaseEntity { this.value = value; } + public TimeSeriesValue(Integer value) { + this.date = new Date(); + this.value = Double.valueOf(value); + } + public TimeSeriesValue(TimeSeries timeSeries, Date date, Double value) { this.date = date; this.value = value; diff --git a/src/main/java/ru/ulstu/extractor/ts/repository/TimeSeriesRepository.java b/src/main/java/ru/ulstu/extractor/ts/repository/TimeSeriesRepository.java index 7346519..583582c 100644 --- a/src/main/java/ru/ulstu/extractor/ts/repository/TimeSeriesRepository.java +++ b/src/main/java/ru/ulstu/extractor/ts/repository/TimeSeriesRepository.java @@ -1,7 +1,9 @@ package ru.ulstu.extractor.ts.repository; import org.springframework.data.jpa.repository.JpaRepository; +import ru.ulstu.extractor.branch.model.Branch; import ru.ulstu.extractor.ts.model.TimeSeries; +import ru.ulstu.extractor.ts.model.TimeSeriesType; import java.util.List; import java.util.Optional; @@ -10,4 +12,6 @@ public interface TimeSeriesRepository extends JpaRepository Optional findByName(String name); List getTimeSeriesByBranchId(Integer branchId); + + Optional getTimeSeriesByBranchAndTimeSeriesType(Branch branch, TimeSeriesType timeSeriesType); } diff --git a/src/main/java/ru/ulstu/extractor/ts/service/ScheduledTimeSeriesService.java b/src/main/java/ru/ulstu/extractor/ts/service/ScheduledTimeSeriesService.java new file mode 100644 index 0000000..4dc636e --- /dev/null +++ b/src/main/java/ru/ulstu/extractor/ts/service/ScheduledTimeSeriesService.java @@ -0,0 +1,34 @@ +package ru.ulstu.extractor.ts.service; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.scheduling.annotation.Scheduled; +import org.springframework.stereotype.Service; +import ru.ulstu.extractor.branch.model.Branch; +import ru.ulstu.extractor.branch.service.BranchService; +import ru.ulstu.extractor.ts.creator.scheduled.ScheduledTimeSeriesCreator; + +import java.util.List; + +@Service +public class ScheduledTimeSeriesService { + private final Logger log = LoggerFactory.getLogger(ScheduledTimeSeriesService.class); + private final List scheduledTimeSeriesCreators; + private final BranchService branchService; + + public ScheduledTimeSeriesService(List scheduledTimeSeriesCreators, + BranchService branchService) { + this.scheduledTimeSeriesCreators = scheduledTimeSeriesCreators; + this.branchService = branchService; + } + + @Scheduled(cron = "0 */5 * * * *", zone = "Europe/Samara") + public void addTimeSeriesPoints() { + log.debug("ConferenceScheduler.checkDeadlineBeforeWeek started"); + List branches = branchService.findAll(); + branches.forEach(branch -> { + scheduledTimeSeriesCreators.forEach(creator -> creator.addTimeSeriesValue(branch)); + }); + log.debug("ConferenceScheduler.checkDeadlineBeforeWeek finished"); + } +} diff --git a/src/main/java/ru/ulstu/extractor/ts/service/TimeSeriesService.java b/src/main/java/ru/ulstu/extractor/ts/service/TimeSeriesService.java index 4cc2de9..3989f2e 100644 --- a/src/main/java/ru/ulstu/extractor/ts/service/TimeSeriesService.java +++ b/src/main/java/ru/ulstu/extractor/ts/service/TimeSeriesService.java @@ -59,7 +59,7 @@ public class TimeSeriesService { return savedTimeSeries; } - public TimeSeries findOrCreate(String timeSeriesName, Branch branch, TimeSeriesType timeSeriesType) { + private TimeSeries findOrCreate(String timeSeriesName, Branch branch, TimeSeriesType timeSeriesType) { Optional maybeTimeSeries = timeSeriesRepository.findByName(timeSeriesName); if (maybeTimeSeries.isPresent()) { LOG.debug("TimeSeries {} exists.", maybeTimeSeries.get().getName()); @@ -68,6 +68,15 @@ public class TimeSeriesService { return timeSeriesRepository.save(new TimeSeries(timeSeriesName, branch, timeSeriesType)); } + public TimeSeries findByBranchAndTypeOrCreate(Branch branch, TimeSeriesType timeSeriesType) { + Optional maybeTimeSeries = timeSeriesRepository.getTimeSeriesByBranchAndTimeSeriesType(branch, timeSeriesType); + if (maybeTimeSeries.isPresent()) { + LOG.debug("TimeSeries {} exists.", maybeTimeSeries.get().getName()); + return maybeTimeSeries.get(); + } + return timeSeriesRepository.save(new TimeSeries(branch, timeSeriesType)); + } + /** * Сохранить список временных рядов * -- 2.34.1 From aeab50cfb8ebb025d58d0f7a49e071f7bf68b885 Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Wed, 15 Feb 2023 18:28:39 +0400 Subject: [PATCH 2/5] #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; - } -} -- 2.34.1 From 3de664abb1e1829d70c630a277383e4258899f33 Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Thu, 16 Feb 2023 00:39:13 +0400 Subject: [PATCH 3/5] #89 -- Divide git api services --- .../gitrepository/service/GithubApi.java | 61 +++++++++++++++++++ .../gitrepository/service/GitlabApi.java | 61 +++++++++++++++++++ .../ru/ulstu/extractor/http/HttpService.java | 2 +- .../ts/creator/scheduled/AuthorTS.java | 12 ++-- .../ts/creator/scheduled/BranchTS.java | 11 ++-- .../ts/creator/scheduled/IssuesTS.java | 11 ++-- .../scheduled/ScheduledTimeSeriesCreator.java | 15 +++++ .../ts/creator/scheduled/StarTS.java | 12 ++-- .../ru/ulstu/extractor/util/StringUtils.java | 6 ++ 9 files changed, 170 insertions(+), 21 deletions(-) create mode 100644 src/main/java/ru/ulstu/extractor/gitrepository/service/GithubApi.java create mode 100644 src/main/java/ru/ulstu/extractor/gitrepository/service/GitlabApi.java diff --git a/src/main/java/ru/ulstu/extractor/gitrepository/service/GithubApi.java b/src/main/java/ru/ulstu/extractor/gitrepository/service/GithubApi.java new file mode 100644 index 0000000..11145ca --- /dev/null +++ b/src/main/java/ru/ulstu/extractor/gitrepository/service/GithubApi.java @@ -0,0 +1,61 @@ +package ru.ulstu.extractor.gitrepository.service; + +import org.springframework.stereotype.Service; +import ru.ulstu.extractor.branch.model.Branch; +import ru.ulstu.extractor.http.HttpService; + +@Service +public class GithubApi implements GitApi { + private final HttpService httpService; + 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 GithubApi(HttpService httpService) { + this.httpService = httpService; + } + + @Override + public Integer getBranchesCount(Branch branch) { + return httpService + .get(getFormattedUrl(branch.getGitRepository().getUrl(), BRANCHES_COUNT_URL)) + .length(); + } + + @Override + public Integer getStarsCount(Branch branch) { + return httpService + .get(getFormattedUrl(branch.getGitRepository().getUrl(), STARS_COUNT_URL)) + .getJSONObject(0) + .getInt("stars_count"); + } + + @Override + public Integer getOpenIssuesCount(Branch branch) { + return httpService + .get(getFormattedUrl(branch.getGitRepository().getUrl(), OPEN_ISSUES_URL)) + .length(); + } + + @Override + public String getFormattedUrl(String gitRepositoryUrl, String template) { + 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/GitlabApi.java b/src/main/java/ru/ulstu/extractor/gitrepository/service/GitlabApi.java new file mode 100644 index 0000000..975e0f8 --- /dev/null +++ b/src/main/java/ru/ulstu/extractor/gitrepository/service/GitlabApi.java @@ -0,0 +1,61 @@ +package ru.ulstu.extractor.gitrepository.service; + +import org.springframework.stereotype.Service; +import ru.ulstu.extractor.branch.model.Branch; +import ru.ulstu.extractor.http.HttpService; + +@Service +public class GitlabApi implements GitApi { + private final HttpService httpService; + 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 GitlabApi(HttpService httpService) { + this.httpService = httpService; + } + + @Override + public Integer getBranchesCount(Branch branch) { + return httpService + .get(getFormattedUrl(branch.getGitRepository().getUrl(), BRANCHES_COUNT_URL)) + .length(); + } + + @Override + public Integer getStarsCount(Branch branch) { + return httpService + .get(getFormattedUrl(branch.getGitRepository().getUrl(), STARS_COUNT_URL)) + .getJSONObject(0) + .getInt("stars_count"); + } + + @Override + public Integer getOpenIssuesCount(Branch branch) { + return httpService + .get(getFormattedUrl(branch.getGitRepository().getUrl(), OPEN_ISSUES_URL)) + .length(); + } + + @Override + public String getFormattedUrl(String gitRepositoryUrl, String template) { + 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/http/HttpService.java b/src/main/java/ru/ulstu/extractor/http/HttpService.java index cc1884e..2c24f1f 100644 --- a/src/main/java/ru/ulstu/extractor/http/HttpService.java +++ b/src/main/java/ru/ulstu/extractor/http/HttpService.java @@ -58,7 +58,7 @@ public class HttpService { return jsonArray; } } catch (Exception e) { - return new JSONArray("[{response:\"empty\"}]"); + throw new RuntimeException(e); } } } 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 768f16f..a07007c 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,8 +1,8 @@ package ru.ulstu.extractor.ts.creator.scheduled; +import org.springframework.context.ApplicationContext; import org.springframework.stereotype.Component; 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; @@ -10,11 +10,12 @@ import ru.ulstu.extractor.ts.service.TimeSeriesService; @Component public class AuthorTS extends ScheduledTimeSeriesCreator { private final TimeSeriesService timeSeriesService; - private final GitApi gitApi; + private final ApplicationContext applicationContext; - public AuthorTS(TimeSeriesService timeSeriesService, GitApi gitApi) { + public AuthorTS(TimeSeriesService timeSeriesService, + ApplicationContext applicationContext) { this.timeSeriesService = timeSeriesService; - this.gitApi = gitApi; + this.applicationContext = applicationContext; } @Override @@ -24,7 +25,8 @@ public class AuthorTS extends ScheduledTimeSeriesCreator { @Override public TimeSeriesValue getNewTimeSeriesValue(Branch branch) { - return new TimeSeriesValue(gitApi.getAuthorsCount(branch)); + return new TimeSeriesValue(applicationContext.getBean(getGitApiServiceClass(branch)) + .getAuthorsCount(branch)); } @Override diff --git a/src/main/java/ru/ulstu/extractor/ts/creator/scheduled/BranchTS.java b/src/main/java/ru/ulstu/extractor/ts/creator/scheduled/BranchTS.java index 4ef0042..81289db 100644 --- a/src/main/java/ru/ulstu/extractor/ts/creator/scheduled/BranchTS.java +++ b/src/main/java/ru/ulstu/extractor/ts/creator/scheduled/BranchTS.java @@ -1,8 +1,8 @@ package ru.ulstu.extractor.ts.creator.scheduled; +import org.springframework.context.ApplicationContext; import org.springframework.stereotype.Component; 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; @@ -10,12 +10,12 @@ import ru.ulstu.extractor.ts.service.TimeSeriesService; @Component public class BranchTS extends ScheduledTimeSeriesCreator { private final TimeSeriesService timeSeriesService; - private final GitApi gitApi; + private final ApplicationContext applicationContext; public BranchTS(TimeSeriesService timeSeriesService, - GitApi gitApi) { + ApplicationContext applicationContext) { this.timeSeriesService = timeSeriesService; - this.gitApi = gitApi; + this.applicationContext = applicationContext; } @Override @@ -30,6 +30,7 @@ public class BranchTS extends ScheduledTimeSeriesCreator { @Override public TimeSeriesValue getNewTimeSeriesValue(Branch branch) { - return new TimeSeriesValue(gitApi.getBranchesCount(branch)); + return new TimeSeriesValue(applicationContext.getBean(getGitApiServiceClass(branch)) + .getBranchesCount(branch)); } } diff --git a/src/main/java/ru/ulstu/extractor/ts/creator/scheduled/IssuesTS.java b/src/main/java/ru/ulstu/extractor/ts/creator/scheduled/IssuesTS.java index 69907c6..8d26648 100644 --- a/src/main/java/ru/ulstu/extractor/ts/creator/scheduled/IssuesTS.java +++ b/src/main/java/ru/ulstu/extractor/ts/creator/scheduled/IssuesTS.java @@ -1,8 +1,8 @@ package ru.ulstu.extractor.ts.creator.scheduled; +import org.springframework.context.ApplicationContext; import org.springframework.stereotype.Component; 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; @@ -10,17 +10,18 @@ import ru.ulstu.extractor.ts.service.TimeSeriesService; @Component public class IssuesTS extends ScheduledTimeSeriesCreator { private final TimeSeriesService timeSeriesService; - private final GitApi gitApi; + private final ApplicationContext applicationContext; public IssuesTS(TimeSeriesService timeSeriesService, - GitApi gitApi) { + ApplicationContext applicationContext) { this.timeSeriesService = timeSeriesService; - this.gitApi = gitApi; + this.applicationContext = applicationContext; } @Override public TimeSeriesValue getNewTimeSeriesValue(Branch branch) { - return new TimeSeriesValue(gitApi.getOpenIssuesCount(branch)); + return new TimeSeriesValue(applicationContext.getBean(getGitApiServiceClass(branch)) + .getOpenIssuesCount(branch)); } @Override diff --git a/src/main/java/ru/ulstu/extractor/ts/creator/scheduled/ScheduledTimeSeriesCreator.java b/src/main/java/ru/ulstu/extractor/ts/creator/scheduled/ScheduledTimeSeriesCreator.java index 1be6322..0bb3786 100644 --- a/src/main/java/ru/ulstu/extractor/ts/creator/scheduled/ScheduledTimeSeriesCreator.java +++ b/src/main/java/ru/ulstu/extractor/ts/creator/scheduled/ScheduledTimeSeriesCreator.java @@ -2,13 +2,24 @@ package ru.ulstu.extractor.ts.creator.scheduled; import org.springframework.transaction.annotation.Transactional; import ru.ulstu.extractor.branch.model.Branch; +import ru.ulstu.extractor.gitrepository.service.GitApi; +import ru.ulstu.extractor.gitrepository.service.GitAtheneApi; +import ru.ulstu.extractor.gitrepository.service.GithubApi; +import ru.ulstu.extractor.gitrepository.service.GitlabApi; import ru.ulstu.extractor.ts.creator.AbstractTimeSeriesCreator; import ru.ulstu.extractor.ts.model.TimeSeries; import ru.ulstu.extractor.ts.model.TimeSeriesValue; +import ru.ulstu.extractor.util.StringUtils; import java.util.Collections; +import java.util.Map; public abstract class ScheduledTimeSeriesCreator extends AbstractTimeSeriesCreator { + private final Map> gitApiServiceHolder = Map.of( + "git.athene.tech", GitAtheneApi.class, + "github.com", GithubApi.class, + "gitlab.com", GitlabApi.class); + @Transactional public void addTimeSeriesValue(Branch branch) { TimeSeries timeSeries = getTimeSeriesService().findByBranchAndTypeOrCreate(branch, getTimeSeriesType()); @@ -17,4 +28,8 @@ public abstract class ScheduledTimeSeriesCreator extends AbstractTimeSeriesCreat } public abstract TimeSeriesValue getNewTimeSeriesValue(Branch branch); + + public Class getGitApiServiceClass(Branch branch) { + return gitApiServiceHolder.get(StringUtils.getServerDomain(branch.getGitRepository().getUrl())); + } } diff --git a/src/main/java/ru/ulstu/extractor/ts/creator/scheduled/StarTS.java b/src/main/java/ru/ulstu/extractor/ts/creator/scheduled/StarTS.java index 6422822..27becfa 100644 --- a/src/main/java/ru/ulstu/extractor/ts/creator/scheduled/StarTS.java +++ b/src/main/java/ru/ulstu/extractor/ts/creator/scheduled/StarTS.java @@ -1,8 +1,8 @@ package ru.ulstu.extractor.ts.creator.scheduled; +import org.springframework.context.ApplicationContext; import org.springframework.stereotype.Component; 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; @@ -10,11 +10,12 @@ import ru.ulstu.extractor.ts.service.TimeSeriesService; @Component public class StarTS extends ScheduledTimeSeriesCreator { private final TimeSeriesService timeSeriesService; - private final GitApi gitApi; + private final ApplicationContext applicationContext; - public StarTS(TimeSeriesService timeSeriesService, GitApi gitApi) { + public StarTS(TimeSeriesService timeSeriesService, + ApplicationContext applicationContext) { this.timeSeriesService = timeSeriesService; - this.gitApi = gitApi; + this.applicationContext = applicationContext; } @Override @@ -29,6 +30,7 @@ public class StarTS extends ScheduledTimeSeriesCreator { @Override public TimeSeriesValue getNewTimeSeriesValue(Branch branch) { - return new TimeSeriesValue(gitApi.getStarsCount(branch)); + return new TimeSeriesValue(applicationContext.getBean(getGitApiServiceClass(branch)) + .getStarsCount(branch)); } } diff --git a/src/main/java/ru/ulstu/extractor/util/StringUtils.java b/src/main/java/ru/ulstu/extractor/util/StringUtils.java index ec448bc..9d137e5 100644 --- a/src/main/java/ru/ulstu/extractor/util/StringUtils.java +++ b/src/main/java/ru/ulstu/extractor/util/StringUtils.java @@ -9,6 +9,7 @@ import java.nio.file.FileSystems; public class StringUtils { public final static String EMPTY_STRING = ""; + public final static String SERVER_DOMAIN_PATTERN = "%s"; private final static String PATH_SEPARATOR = FileSystems.getDefault().getSeparator(); public static String addPathSeparator(String path) { @@ -25,4 +26,9 @@ public class StringUtils { public static boolean fileInSubdirectory(String filePath, String projectPath, String subDirectory) { return filePath.startsWith(projectPath + PATH_SEPARATOR + subDirectory); } + + public static String getServerDomain(String url) { + String[] urlParts = url.split("/"); + return urlParts[2]; + } } -- 2.34.1 From 78016741cf3938fce731f217f6eecee2ab40bb51 Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Sun, 19 Feb 2023 23:59:30 +0400 Subject: [PATCH 4/5] #89 -- Fix scheduled time series --- .../gitrepository/model/GitRepository.java | 8 +++- .../gitrepository/service/GitApi.java | 4 +- .../gitrepository/service/GitAtheneApi.java | 22 +++------ .../gitrepository/service/GithubApi.java | 32 +++++-------- .../gitrepository/service/GitlabApi.java | 46 +++++++++++-------- .../ru/ulstu/extractor/http/HttpService.java | 2 + .../ts/creator/scheduled/AuthorTS.java | 36 --------------- 7 files changed, 56 insertions(+), 94 deletions(-) delete mode 100644 src/main/java/ru/ulstu/extractor/ts/creator/scheduled/AuthorTS.java diff --git a/src/main/java/ru/ulstu/extractor/gitrepository/model/GitRepository.java b/src/main/java/ru/ulstu/extractor/gitrepository/model/GitRepository.java index f2b8276..da94301 100644 --- a/src/main/java/ru/ulstu/extractor/gitrepository/model/GitRepository.java +++ b/src/main/java/ru/ulstu/extractor/gitrepository/model/GitRepository.java @@ -26,7 +26,11 @@ public class GitRepository extends BaseEntity { public String getName() { int lastDelimiterIndex = url.lastIndexOf("/"); return (lastDelimiterIndex > 0 && lastDelimiterIndex < url.length()) - ? url.substring(lastDelimiterIndex + 1) - : url; + ? removeDotGit(url.substring(lastDelimiterIndex + 1)) + : removeDotGit(url); + } + + private String removeDotGit(String prevName) { + return prevName.substring(0, prevName.lastIndexOf(".git")); } } 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 1267a15..4be8736 100644 --- a/src/main/java/ru/ulstu/extractor/gitrepository/service/GitApi.java +++ b/src/main/java/ru/ulstu/extractor/gitrepository/service/GitApi.java @@ -9,9 +9,7 @@ public interface GitApi { Integer getOpenIssuesCount(Branch branch); - String getFormattedUrl(String gitRepositoryUrl, String template); + String getFormattedUrl(Branch branch, 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 eb79ab5..d6644e1 100644 --- a/src/main/java/ru/ulstu/extractor/gitrepository/service/GitAtheneApi.java +++ b/src/main/java/ru/ulstu/extractor/gitrepository/service/GitAtheneApi.java @@ -10,8 +10,7 @@ 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"; + private static final String COMPLETED_ISSUES_URL = "%s/api/v1/repos/%s/%s/issues?state=closed"; public GitAtheneApi(HttpService httpService) { this.httpService = httpService; @@ -20,14 +19,14 @@ public class GitAtheneApi implements GitApi { @Override public Integer getBranchesCount(Branch branch) { return httpService - .get(getFormattedUrl(branch.getGitRepository().getUrl(), BRANCHES_COUNT_URL)) + .get(getFormattedUrl(branch, BRANCHES_COUNT_URL)) .length(); } @Override public Integer getStarsCount(Branch branch) { return httpService - .get(getFormattedUrl(branch.getGitRepository().getUrl(), STARS_COUNT_URL)) + .get(getFormattedUrl(branch, STARS_COUNT_URL)) .getJSONObject(0) .getInt("stars_count"); } @@ -35,27 +34,20 @@ public class GitAtheneApi implements GitApi { @Override public Integer getOpenIssuesCount(Branch branch) { return httpService - .get(getFormattedUrl(branch.getGitRepository().getUrl(), OPEN_ISSUES_URL)) + .get(getFormattedUrl(branch, OPEN_ISSUES_URL)) .length(); } @Override - public String getFormattedUrl(String gitRepositoryUrl, String template) { - String[] urlParts = gitRepositoryUrl.split("/"); + public String getFormattedUrl(Branch branch, String template) { + String[] urlParts = branch.getGitRepository().getUrl().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)) + .get(getFormattedUrl(branch, COMPLETED_ISSUES_URL)) .length(); } } diff --git a/src/main/java/ru/ulstu/extractor/gitrepository/service/GithubApi.java b/src/main/java/ru/ulstu/extractor/gitrepository/service/GithubApi.java index 11145ca..e744bb7 100644 --- a/src/main/java/ru/ulstu/extractor/gitrepository/service/GithubApi.java +++ b/src/main/java/ru/ulstu/extractor/gitrepository/service/GithubApi.java @@ -7,11 +7,10 @@ import ru.ulstu.extractor.http.HttpService; @Service public class GithubApi implements GitApi { private final HttpService httpService; - 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"; + private static final String BRANCHES_COUNT_URL = "https://api.github.com/repos/%s/%s/branches"; + private static final String STARS_COUNT_URL = "https://api.github.com/repos/%s/%s"; + private static final String OPEN_ISSUES_URL = "https://api.github.com/repos/%s/%s/issues?state=open"; + private static final String AUTHOR_COMPLETED_ISSUES_URL = "https://api.github.com/repos/%s/%s/issues?state=open"; public GithubApi(HttpService httpService) { this.httpService = httpService; @@ -20,42 +19,35 @@ public class GithubApi implements GitApi { @Override public Integer getBranchesCount(Branch branch) { return httpService - .get(getFormattedUrl(branch.getGitRepository().getUrl(), BRANCHES_COUNT_URL)) + .get(getFormattedUrl(branch, BRANCHES_COUNT_URL)) .length(); } @Override public Integer getStarsCount(Branch branch) { return httpService - .get(getFormattedUrl(branch.getGitRepository().getUrl(), STARS_COUNT_URL)) + .get(getFormattedUrl(branch, STARS_COUNT_URL)) .getJSONObject(0) - .getInt("stars_count"); + .getInt("watchers"); } @Override public Integer getOpenIssuesCount(Branch branch) { return httpService - .get(getFormattedUrl(branch.getGitRepository().getUrl(), OPEN_ISSUES_URL)) + .get(getFormattedUrl(branch, OPEN_ISSUES_URL)) .length(); } @Override - public String getFormattedUrl(String gitRepositoryUrl, String template) { - String[] urlParts = gitRepositoryUrl.split("/"); - return String.format(template, urlParts[0] + "/" + urlParts[1] + "/" + urlParts[2], urlParts[3], urlParts[4]); + public String getFormattedUrl(Branch branch, String template) { + String[] urlParts = branch.getGitRepository().getUrl().split("/"); + return String.format(template, 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)) + .get(getFormattedUrl(branch, AUTHOR_COMPLETED_ISSUES_URL)) .length(); } } diff --git a/src/main/java/ru/ulstu/extractor/gitrepository/service/GitlabApi.java b/src/main/java/ru/ulstu/extractor/gitrepository/service/GitlabApi.java index 975e0f8..60feab5 100644 --- a/src/main/java/ru/ulstu/extractor/gitrepository/service/GitlabApi.java +++ b/src/main/java/ru/ulstu/extractor/gitrepository/service/GitlabApi.java @@ -1,5 +1,6 @@ package ru.ulstu.extractor.gitrepository.service; +import org.json.JSONArray; import org.springframework.stereotype.Service; import ru.ulstu.extractor.branch.model.Branch; import ru.ulstu.extractor.http.HttpService; @@ -7,11 +8,11 @@ import ru.ulstu.extractor.http.HttpService; @Service public class GitlabApi implements GitApi { private final HttpService httpService; - 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"; + private static final String BRANCHES_COUNT_URL = "%s/api/v4/projects/%s/repository/branches"; + private final static String PROJECT_ID_URL = "https://gitlab.com/api/v4/users/%s/projects?search=%s"; + private static final String PROJECT_INFO_URL = "%s/api/v4/projects/%s"; + private static final String OPEN_ISSUES_URL = "%s/api/v4/projects/%s/issues?state=opened"; + private static final String COMPLETED_ISSUES_URL = "%s/api/v4/projects/%s/issues?state=closed"; public GitlabApi(HttpService httpService) { this.httpService = httpService; @@ -20,42 +21,51 @@ public class GitlabApi implements GitApi { @Override public Integer getBranchesCount(Branch branch) { return httpService - .get(getFormattedUrl(branch.getGitRepository().getUrl(), BRANCHES_COUNT_URL)) + .get(getFormattedUrl(branch, BRANCHES_COUNT_URL)) .length(); } @Override public Integer getStarsCount(Branch branch) { return httpService - .get(getFormattedUrl(branch.getGitRepository().getUrl(), STARS_COUNT_URL)) + .get(getFormattedUrl(branch, PROJECT_INFO_URL)) .getJSONObject(0) - .getInt("stars_count"); + .getInt("star_count"); } @Override public Integer getOpenIssuesCount(Branch branch) { return httpService - .get(getFormattedUrl(branch.getGitRepository().getUrl(), OPEN_ISSUES_URL)) + .get(getFormattedUrl(branch, OPEN_ISSUES_URL)) .length(); } @Override - public String getFormattedUrl(String gitRepositoryUrl, String template) { - String[] urlParts = gitRepositoryUrl.split("/"); - return String.format(template, urlParts[0] + "/" + urlParts[1] + "/" + urlParts[2], urlParts[3], urlParts[4]); + public String getFormattedUrl(Branch branch, String template) { + String[] urlParts = branch.getGitRepository().getUrl().split("/"); + return String.format(template, urlParts[0] + "/" + urlParts[1] + "/" + urlParts[2], getProjectId(branch)); + } + + public String getFormattedUrlForProjectId(Branch branch, String template) { + String[] urlParts = branch.getGitRepository().getUrl().split("/"); + // получаем корректное название репозитория, gitlab всегда добавляет .git в конец + return String.format(template, urlParts[3], branch.getGitRepository().getName()); } @Override public Integer getAuthorsCompletedIssues(Branch branch) { return httpService - .get(getFormattedUrl(branch.getGitRepository().getUrl(), AUTHOR_COMPLETED_ISSUES_URL)) + .get(getFormattedUrl(branch, COMPLETED_ISSUES_URL)) .length(); } - @Override - public Integer getAuthorsCount(Branch branch) { - return httpService - .get(getFormattedUrl(branch.getGitRepository().getUrl(), AUTHORS_COUNT_URL)) - .length(); + private String getProjectId(Branch branch) { + JSONArray projects = httpService.get(getFormattedUrlForProjectId(branch, PROJECT_ID_URL)); + for (int i = 0; i < projects.length(); i++) { + if (projects.getJSONObject(i).get("name").equals(branch.getGitRepository().getName())) { + return String.valueOf(projects.getJSONObject(i).getInt("id")); + } + } + throw new RuntimeException("Id проекта не найден: " + branch.getGitRepository().getName()); } } diff --git a/src/main/java/ru/ulstu/extractor/http/HttpService.java b/src/main/java/ru/ulstu/extractor/http/HttpService.java index 2c24f1f..1e53488 100644 --- a/src/main/java/ru/ulstu/extractor/http/HttpService.java +++ b/src/main/java/ru/ulstu/extractor/http/HttpService.java @@ -9,6 +9,7 @@ import org.springframework.stereotype.Service; import org.springframework.web.reactive.function.BodyInserters; import org.springframework.web.reactive.function.client.WebClient; +import java.time.Duration; import java.util.Optional; @Service @@ -49,6 +50,7 @@ public class HttpService { .accept(MediaType.APPLICATION_JSON) .retrieve() .bodyToMono(String.class) + .timeout(Duration.ofMinutes(1)) .toFuture().get(); if (response.startsWith("[")) { return new JSONArray(response); 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 deleted file mode 100644 index a07007c..0000000 --- a/src/main/java/ru/ulstu/extractor/ts/creator/scheduled/AuthorTS.java +++ /dev/null @@ -1,36 +0,0 @@ -package ru.ulstu.extractor.ts.creator.scheduled; - -import org.springframework.context.ApplicationContext; -import org.springframework.stereotype.Component; -import ru.ulstu.extractor.branch.model.Branch; -import ru.ulstu.extractor.ts.model.TimeSeriesType; -import ru.ulstu.extractor.ts.model.TimeSeriesValue; -import ru.ulstu.extractor.ts.service.TimeSeriesService; - -@Component -public class AuthorTS extends ScheduledTimeSeriesCreator { - private final TimeSeriesService timeSeriesService; - private final ApplicationContext applicationContext; - - public AuthorTS(TimeSeriesService timeSeriesService, - ApplicationContext applicationContext) { - this.timeSeriesService = timeSeriesService; - this.applicationContext = applicationContext; - } - - @Override - public TimeSeriesType getTimeSeriesType() { - return TimeSeriesType.AUTHORS; - } - - @Override - public TimeSeriesValue getNewTimeSeriesValue(Branch branch) { - return new TimeSeriesValue(applicationContext.getBean(getGitApiServiceClass(branch)) - .getAuthorsCount(branch)); - } - - @Override - public TimeSeriesService getTimeSeriesService() { - return timeSeriesService; - } -} -- 2.34.1 From a5c9d15d4f7f19e46bdc2bfc0d0840a9a33121ac Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Mon, 20 Feb 2023 10:10:41 +0400 Subject: [PATCH 5/5] #89 -- Fix logs --- .../ts/service/ScheduledTimeSeriesService.java | 6 +++--- .../ulstu/extractor/ts/service/TimeSeriesService.java | 10 +++++----- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/main/java/ru/ulstu/extractor/ts/service/ScheduledTimeSeriesService.java b/src/main/java/ru/ulstu/extractor/ts/service/ScheduledTimeSeriesService.java index 4dc636e..55aeae5 100644 --- a/src/main/java/ru/ulstu/extractor/ts/service/ScheduledTimeSeriesService.java +++ b/src/main/java/ru/ulstu/extractor/ts/service/ScheduledTimeSeriesService.java @@ -22,13 +22,13 @@ public class ScheduledTimeSeriesService { this.branchService = branchService; } - @Scheduled(cron = "0 */5 * * * *", zone = "Europe/Samara") + @Scheduled(cron = "0 0 * * * *", zone = "Europe/Samara") public void addTimeSeriesPoints() { - log.debug("ConferenceScheduler.checkDeadlineBeforeWeek started"); + log.debug("Старт добавления новых точек временного ряда"); List branches = branchService.findAll(); branches.forEach(branch -> { scheduledTimeSeriesCreators.forEach(creator -> creator.addTimeSeriesValue(branch)); }); - log.debug("ConferenceScheduler.checkDeadlineBeforeWeek finished"); + log.debug("Завершение добавления новых точек временного ряда"); } } diff --git a/src/main/java/ru/ulstu/extractor/ts/service/TimeSeriesService.java b/src/main/java/ru/ulstu/extractor/ts/service/TimeSeriesService.java index 3989f2e..d5e12e6 100644 --- a/src/main/java/ru/ulstu/extractor/ts/service/TimeSeriesService.java +++ b/src/main/java/ru/ulstu/extractor/ts/service/TimeSeriesService.java @@ -47,13 +47,13 @@ public class TimeSeriesService { @Transactional public TimeSeries save(String timeSeriesName, Branch branch, TimeSeriesType timeSeriesType, List timeSeriesValues) { - LOG.debug("Start save {} time series with {} time series values ", timeSeriesName, timeSeriesValues.size()); + LOG.debug("Начало сохранения временного ряда {} с {} значениями", timeSeriesName, timeSeriesValues.size()); final TimeSeries timeSeries = findOrCreate(timeSeriesName, branch, timeSeriesType); List timeSeriesValuesToRemove = timeSeries.getValues(); timeSeries.setValues(timeSeriesValues); - LOG.debug("Save time series {} ", timeSeries.getName()); + LOG.debug("Сохранение временного ряда {} ", timeSeries.getName()); TimeSeries savedTimeSeries = timeSeriesRepository.save(timeSeries); - LOG.debug("Clear {} time series values ", timeSeriesValuesToRemove.size()); + LOG.debug("Очистить {} точек временного ряда", timeSeriesValuesToRemove.size()); timeSeriesValueRepository.deleteAll(timeSeriesValuesToRemove); sendToTimeSeriesService(savedTimeSeries); return savedTimeSeries; @@ -100,7 +100,7 @@ public class TimeSeriesService { new Thread(() -> { try { httpService.post(TIME_SERIES_SAVE_SERVICE_URL, new JSONObject(new JsonTimeSeries(timeSeries))); - LOG.debug("Успешно отправлен на сервис"); + LOG.debug("{} успешно отправлен на сервис временных рядов", timeSeries.getName()); } catch (Exception ex) { LOG.debug(ex.getMessage()); } @@ -113,7 +113,7 @@ public class TimeSeriesService { public TimeSeries getById(Integer tsId) { return timeSeriesRepository.findById(tsId) - .orElseThrow(() -> new RuntimeException("Time series not found by id " + tsId)); + .orElseThrow(() -> new RuntimeException("Временной ряд не найден по идентификатору " + tsId)); } public List getAllTimeSeriesTypes() { -- 2.34.1