From 5a97d107c39a884a353820e69849d35b28a322b3 Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Fri, 10 May 2024 11:43:40 +0400 Subject: [PATCH] #96 -- Add db records for generated time series --- .../ru/ulstu/extractor/branch/model/Branch.java | 10 ++-------- .../controler/RepositoryController.java | 13 +++++++++++-- .../controler/StatisticController.java | 5 ++++- .../gitrepository/model/GitRepository.java | 2 ++ .../controller/TimeSeriesMarkupController.java | 15 ++++++++++++--- .../ts/service/ScheduledTimeSeriesService.java | 8 +++++++- .../db/changelog-20230302_210000-schema.xml | 11 +++++++++++ 7 files changed, 49 insertions(+), 15 deletions(-) diff --git a/src/main/java/ru/ulstu/extractor/branch/model/Branch.java b/src/main/java/ru/ulstu/extractor/branch/model/Branch.java index 6d63841..7c428d0 100644 --- a/src/main/java/ru/ulstu/extractor/branch/model/Branch.java +++ b/src/main/java/ru/ulstu/extractor/branch/model/Branch.java @@ -6,14 +6,7 @@ import ru.ulstu.extractor.commit.model.Commit; import ru.ulstu.extractor.core.BaseEntity; import ru.ulstu.extractor.gitrepository.model.GitRepository; -import javax.persistence.CascadeType; -import javax.persistence.Entity; -import javax.persistence.EnumType; -import javax.persistence.Enumerated; -import javax.persistence.FetchType; -import javax.persistence.JoinColumn; -import javax.persistence.ManyToOne; -import javax.persistence.OneToMany; +import javax.persistence.*; import java.util.ArrayList; import java.util.List; @@ -21,6 +14,7 @@ import static ru.ulstu.extractor.branch.model.IndexingStatus.EMPTY; @Entity public class Branch extends BaseEntity { + public static Integer GENERATED_BRANCH_ID = 1; private String name; @ManyToOne diff --git a/src/main/java/ru/ulstu/extractor/gitrepository/controler/RepositoryController.java b/src/main/java/ru/ulstu/extractor/gitrepository/controler/RepositoryController.java index d27ee14..cefbe4d 100644 --- a/src/main/java/ru/ulstu/extractor/gitrepository/controler/RepositoryController.java +++ b/src/main/java/ru/ulstu/extractor/gitrepository/controler/RepositoryController.java @@ -7,8 +7,11 @@ import org.springframework.web.bind.annotation.RequestParam; import ru.ulstu.extractor.gitrepository.repository.GitRepositoryRepository; import springfox.documentation.annotations.ApiIgnore; +import java.util.stream.Collectors; + import static ru.ulstu.extractor.core.Route.DELETE_INDEXED_REPOSITORY; import static ru.ulstu.extractor.core.Route.LIST_INDEXED_REPOSITORIES; +import static ru.ulstu.extractor.gitrepository.model.GitRepository.GENERATED_REPOSITORY_ID; @Controller @ApiIgnore @@ -21,7 +24,10 @@ public class RepositoryController { @GetMapping(LIST_INDEXED_REPOSITORIES) public String indexNewRepo(Model model) { - model.addAttribute("repositories", gitRepositoryRepository.findAll()); + model.addAttribute("repositories", gitRepositoryRepository.findAll() + .stream() + .filter(r -> !r.getId().equals(GENERATED_REPOSITORY_ID)) + .collect(Collectors.toList())); return LIST_INDEXED_REPOSITORIES; } @@ -29,7 +35,10 @@ public class RepositoryController { public String deleteRepo(Model model, @RequestParam Integer id) { gitRepositoryRepository.deleteById(id); - model.addAttribute("repositories", gitRepositoryRepository.findAll()); + model.addAttribute("repositories", gitRepositoryRepository.findAll() + .stream() + .filter(r -> !r.getId().equals(GENERATED_REPOSITORY_ID)) + .collect(Collectors.toList())); return "redirect:/" + LIST_INDEXED_REPOSITORIES; } } diff --git a/src/main/java/ru/ulstu/extractor/gitrepository/controler/StatisticController.java b/src/main/java/ru/ulstu/extractor/gitrepository/controler/StatisticController.java index 63e75d8..766d3a7 100644 --- a/src/main/java/ru/ulstu/extractor/gitrepository/controler/StatisticController.java +++ b/src/main/java/ru/ulstu/extractor/gitrepository/controler/StatisticController.java @@ -14,6 +14,7 @@ import java.util.List; import java.util.Optional; import java.util.stream.Collectors; +import static ru.ulstu.extractor.branch.model.Branch.GENERATED_BRANCH_ID; import static ru.ulstu.extractor.core.Route.STATISTIC; @Controller @@ -60,7 +61,9 @@ public class StatisticController { filterForm.setEntity(entity.orElse(null)); model.addAttribute("filterForm", filterForm); model.addAttribute("entityPresent", filteringService.getEntityPresent()); - model.addAttribute("branches", branchService.findAll()); + model.addAttribute("branches", branchService.findAll().stream() + .filter(r -> !r.getId().equals(GENERATED_BRANCH_ID)) + .collect(Collectors.toList())); model.addAttribute("authors", filteringService.getRepositoryAuthors(branchId.orElse(null))); return STATISTIC; } 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 f4707c7..8017241 100644 --- a/src/main/java/ru/ulstu/extractor/gitrepository/model/GitRepository.java +++ b/src/main/java/ru/ulstu/extractor/gitrepository/model/GitRepository.java @@ -7,6 +7,8 @@ import javax.persistence.Entity; @Entity public class GitRepository extends BaseEntity { + + public static Integer GENERATED_REPOSITORY_ID = 1; private String url; private String repositoryId; diff --git a/src/main/java/ru/ulstu/extractor/markup/controller/TimeSeriesMarkupController.java b/src/main/java/ru/ulstu/extractor/markup/controller/TimeSeriesMarkupController.java index 3aef93a..ad67a0d 100644 --- a/src/main/java/ru/ulstu/extractor/markup/controller/TimeSeriesMarkupController.java +++ b/src/main/java/ru/ulstu/extractor/markup/controller/TimeSeriesMarkupController.java @@ -14,6 +14,9 @@ import ru.ulstu.extractor.ts.service.TimeSeriesService; import springfox.documentation.annotations.ApiIgnore; import java.util.List; +import java.util.stream.Collectors; + +import static ru.ulstu.extractor.branch.model.Branch.GENERATED_BRANCH_ID; @Controller @ApiIgnore @@ -32,14 +35,18 @@ public class TimeSeriesMarkupController { @GetMapping("time-series-markup") public String markupTs(Model model) { - model.addAttribute("branches", branchService.findAllValid()); + model.addAttribute("branches", branchService.findAllValid().stream() + .filter(r -> !r.getId().equals(GENERATED_BRANCH_ID)) + .collect(Collectors.toList())); model.addAttribute("markupForm", new MarkupForm()); return "markup"; } @PostMapping("time-series-markup") public String filter(Model model, @ModelAttribute MarkupForm markupForm) { - model.addAttribute("branches", branchService.findAllValid()); + model.addAttribute("branches", branchService.findAllValid().stream() + .filter(r -> !r.getId().equals(GENERATED_BRANCH_ID)) + .collect(Collectors.toList())); if (markupForm != null && markupForm.getBranchId() != null) { List tss = markupService.getTimeSeriesForMarkup( timeSeriesService.getGroupedTendencies( @@ -56,7 +63,9 @@ public class TimeSeriesMarkupController { @PostMapping(Route.ADD_MARKUP) public String addMarkups(Model model, @ModelAttribute MarkupForm markupForm) { - model.addAttribute("branches", branchService.findAllValid()); + model.addAttribute("branches", branchService.findAllValid().stream() + .filter(r -> !r.getId().equals(GENERATED_BRANCH_ID)) + .collect(Collectors.toList())); if (markupForm != null && markupForm.getBranchId() != null) { List tss = markupService.getTimeSeriesForMarkup( timeSeriesService.getGroupedTendencies( 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 d3fe476..5b961f9 100644 --- a/src/main/java/ru/ulstu/extractor/ts/service/ScheduledTimeSeriesService.java +++ b/src/main/java/ru/ulstu/extractor/ts/service/ScheduledTimeSeriesService.java @@ -9,6 +9,9 @@ import ru.ulstu.extractor.branch.service.BranchService; import ru.ulstu.extractor.ts.creator.scheduled.ScheduledTimeSeriesCreator; import java.util.List; +import java.util.stream.Collectors; + +import static ru.ulstu.extractor.branch.model.Branch.GENERATED_BRANCH_ID; @Service public class ScheduledTimeSeriesService { @@ -25,7 +28,10 @@ public class ScheduledTimeSeriesService { @Scheduled(cron = "0 0 8 * * *") public void addTimeSeriesPoints() { log.info("Старт добавления новых точек временного ряда"); - List branches = branchService.findAll(); + List branches = branchService.findAll() + .stream() + .filter(b -> !b.getId().equals(GENERATED_BRANCH_ID)) + .collect(Collectors.toList()); branches.forEach(branch -> { scheduledTimeSeriesCreators.forEach(creator -> creator.addTimeSeriesValue(branch)); }); diff --git a/src/main/resources/db/changelog-20230302_210000-schema.xml b/src/main/resources/db/changelog-20230302_210000-schema.xml index 670658e..135ac55 100644 --- a/src/main/resources/db/changelog-20230302_210000-schema.xml +++ b/src/main/resources/db/changelog-20230302_210000-schema.xml @@ -46,4 +46,15 @@ + + + 1 + Генерированный репозиторий + + + 1 + Сгенерированные показатели + 1 + + \ No newline at end of file