From a7add46348bf4f3a4bb0556ec4eb79377d88d3d0 Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Tue, 21 Jun 2022 10:39:53 +0400 Subject: [PATCH] #58 -- fix models naming, refactor --- .../extractor/branch/BranchRepository.java | 21 --------- .../{ => controller}/BranchController.java | 7 +-- .../extractor/{ => branch}/model/Branch.java | 19 ++++---- .../branch/repository/BranchRepository.java | 21 +++++++++ .../branch/{ => service}/BranchService.java | 13 +++--- .../extractor/{ => commit}/model/Commit.java | 1 + .../model/CommitAuthorStatistic.java | 2 +- .../model/CommitEntityStatistic.java | 2 +- .../model/CommitTimeStatistic.java | 2 +- .../model/CommitUrlStatistic.java | 2 +- .../commit/repository/CommitRepository.java | 45 +++++++++++++++++++ .../{ => commit}/service/CommitService.java | 5 ++- .../controller/GitIndexingController.java | 2 +- .../controller/StatisticController.java | 4 +- .../GitRepositoryRepository.java | 6 +-- .../gitrepository/GitRepositoryService.java | 6 +-- .../model/GitRepository.java} | 10 +++-- .../repository/AuthorRepository.java | 6 +-- .../repository/CommitRepository.java | 45 ------------------- .../extractor/service/FilteringService.java | 2 +- .../ulstu/extractor/service/IndexService.java | 18 ++++---- .../extractor/service/TimeSeriesService.java | 2 +- .../java/ru/ulstu/extractor/ts/CommitsTS.java | 3 +- .../db/changelog-20220621_120000-schema.xml | 11 +++++ src/main/resources/db/changelog-master.xml | 1 + src/main/resources/templates/statistic.html | 2 +- 26 files changed, 140 insertions(+), 118 deletions(-) delete mode 100644 src/main/java/ru/ulstu/extractor/branch/BranchRepository.java rename src/main/java/ru/ulstu/extractor/branch/{ => controller}/BranchController.java (85%) rename src/main/java/ru/ulstu/extractor/{ => branch}/model/Branch.java (70%) create mode 100644 src/main/java/ru/ulstu/extractor/branch/repository/BranchRepository.java rename src/main/java/ru/ulstu/extractor/branch/{ => service}/BranchService.java (81%) rename src/main/java/ru/ulstu/extractor/{ => commit}/model/Commit.java (98%) rename src/main/java/ru/ulstu/extractor/{ => commit}/model/CommitAuthorStatistic.java (90%) rename src/main/java/ru/ulstu/extractor/{ => commit}/model/CommitEntityStatistic.java (90%) rename src/main/java/ru/ulstu/extractor/{ => commit}/model/CommitTimeStatistic.java (92%) rename src/main/java/ru/ulstu/extractor/{ => commit}/model/CommitUrlStatistic.java (89%) create mode 100644 src/main/java/ru/ulstu/extractor/commit/repository/CommitRepository.java rename src/main/java/ru/ulstu/extractor/{ => commit}/service/CommitService.java (92%) rename src/main/java/ru/ulstu/extractor/{model/Repository.java => gitrepository/model/GitRepository.java} (51%) delete mode 100644 src/main/java/ru/ulstu/extractor/repository/CommitRepository.java create mode 100644 src/main/resources/db/changelog-20220621_120000-schema.xml diff --git a/src/main/java/ru/ulstu/extractor/branch/BranchRepository.java b/src/main/java/ru/ulstu/extractor/branch/BranchRepository.java deleted file mode 100644 index 6034cb3..0000000 --- a/src/main/java/ru/ulstu/extractor/branch/BranchRepository.java +++ /dev/null @@ -1,21 +0,0 @@ -package ru.ulstu.extractor.branch; - -import org.springframework.data.domain.Page; -import org.springframework.data.domain.Pageable; -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.jpa.repository.Query; -import ru.ulstu.extractor.model.Branch; -import ru.ulstu.extractor.model.Repository; - -import java.util.List; - -public interface BranchRepository extends JpaRepository { - Branch findByRepositoryAndName(Repository repository, String name); - - @Query("select count(c) from Commit c LEFT JOIN c.branch b LEFT JOIN Repository r where r.id = ?1 AND b.name = ?2") - int getCommitsCount(Integer repositoryId, String name); - - List findByRepositoryId(Integer repositoryId); - - Page findByRepository(Repository repository, Pageable pageable); -} diff --git a/src/main/java/ru/ulstu/extractor/branch/BranchController.java b/src/main/java/ru/ulstu/extractor/branch/controller/BranchController.java similarity index 85% rename from src/main/java/ru/ulstu/extractor/branch/BranchController.java rename to src/main/java/ru/ulstu/extractor/branch/controller/BranchController.java index 47f823e..22432bd 100644 --- a/src/main/java/ru/ulstu/extractor/branch/BranchController.java +++ b/src/main/java/ru/ulstu/extractor/branch/controller/BranchController.java @@ -3,12 +3,13 @@ * You may use, distribute and modify this code, please write to: romanov73@gmail.com. */ -package ru.ulstu.extractor.branch; +package ru.ulstu.extractor.branch.controller; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestParam; +import ru.ulstu.extractor.branch.repository.BranchRepository; import ru.ulstu.extractor.gitrepository.GitRepositoryRepository; import springfox.documentation.annotations.ApiIgnore; @@ -30,7 +31,7 @@ public class BranchController { public String indexBranch( Model model, @RequestParam int repositoryId) { - model.addAttribute("branches", branchRepository.findByRepositoryId(repositoryId)); + model.addAttribute("branches", branchRepository.findByGitRepositoryId(repositoryId)); model.addAttribute("repository", gitRepositoryRepository.findById(repositoryId).get()); return LIST_REPOSITORY_BRANCHES; } @@ -40,7 +41,7 @@ public class BranchController { @RequestParam int repositoryId, @RequestParam Integer id) { branchRepository.deleteById(id); - model.addAttribute("branches", branchRepository.findByRepositoryId(repositoryId)); + model.addAttribute("branches", branchRepository.findByGitRepositoryId(repositoryId)); model.addAttribute("repository", gitRepositoryRepository.findById(repositoryId).get()); return LIST_REPOSITORY_BRANCHES; } diff --git a/src/main/java/ru/ulstu/extractor/model/Branch.java b/src/main/java/ru/ulstu/extractor/branch/model/Branch.java similarity index 70% rename from src/main/java/ru/ulstu/extractor/model/Branch.java rename to src/main/java/ru/ulstu/extractor/branch/model/Branch.java index 30c30dd..6837771 100644 --- a/src/main/java/ru/ulstu/extractor/model/Branch.java +++ b/src/main/java/ru/ulstu/extractor/branch/model/Branch.java @@ -3,10 +3,13 @@ * You may use, distribute and modify this code, please write to: romanov73@gmail.com. */ -package ru.ulstu.extractor.model; +package ru.ulstu.extractor.branch.model; import org.hibernate.annotations.Fetch; import org.hibernate.annotations.FetchMode; +import ru.ulstu.extractor.gitrepository.model.GitRepository; +import ru.ulstu.extractor.model.BaseEntity; +import ru.ulstu.extractor.model.Commit; import javax.persistence.CascadeType; import javax.persistence.Entity; @@ -22,7 +25,7 @@ public class Branch extends BaseEntity { private String name; @ManyToOne - private Repository repository; + private GitRepository gitRepository; @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY) @JoinColumn(name = "branch_id") @@ -36,8 +39,8 @@ public class Branch extends BaseEntity { this.name = name; } - public Branch(Repository repository, String branchName) { - this.repository = repository; + public Branch(GitRepository gitRepository, String branchName) { + this.gitRepository = gitRepository; this.name = branchName; } @@ -49,12 +52,12 @@ public class Branch extends BaseEntity { this.name = name; } - public Repository getRepository() { - return repository; + public GitRepository getGitRepository() { + return gitRepository; } - public void setRepository(Repository repository) { - this.repository = repository; + public void setGitRepository(GitRepository gitRepository) { + this.gitRepository = gitRepository; } public List getCommits() { diff --git a/src/main/java/ru/ulstu/extractor/branch/repository/BranchRepository.java b/src/main/java/ru/ulstu/extractor/branch/repository/BranchRepository.java new file mode 100644 index 0000000..af14f53 --- /dev/null +++ b/src/main/java/ru/ulstu/extractor/branch/repository/BranchRepository.java @@ -0,0 +1,21 @@ +package ru.ulstu.extractor.branch.repository; + +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import ru.ulstu.extractor.branch.model.Branch; +import ru.ulstu.extractor.gitrepository.model.GitRepository; + +import java.util.List; + +public interface BranchRepository extends JpaRepository { + Branch findByGitRepositoryAndName(GitRepository gitRepository, String name); + + @Query("select count(c) from Commit c LEFT JOIN c.branch b LEFT JOIN GitRepository r where r.id = ?1 AND b.name = ?2") + int getCommitsCount(Integer repositoryId, String name); + + List findByGitRepositoryId(Integer repositoryId); + + Page findByGitRepository(GitRepository gitRepository, Pageable pageable); +} diff --git a/src/main/java/ru/ulstu/extractor/branch/BranchService.java b/src/main/java/ru/ulstu/extractor/branch/service/BranchService.java similarity index 81% rename from src/main/java/ru/ulstu/extractor/branch/BranchService.java rename to src/main/java/ru/ulstu/extractor/branch/service/BranchService.java index e047bcb..3d6fd28 100644 --- a/src/main/java/ru/ulstu/extractor/branch/BranchService.java +++ b/src/main/java/ru/ulstu/extractor/branch/service/BranchService.java @@ -3,17 +3,18 @@ * You may use, distribute and modify this code, please write to: romanov73@gmail.com. */ -package ru.ulstu.extractor.branch; +package ru.ulstu.extractor.branch.service; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import ru.ulstu.extractor.branch.model.Branch; +import ru.ulstu.extractor.branch.repository.BranchRepository; +import ru.ulstu.extractor.commit.service.CommitService; +import ru.ulstu.extractor.gitrepository.model.GitRepository; import ru.ulstu.extractor.model.BaseEntity; -import ru.ulstu.extractor.model.Branch; import ru.ulstu.extractor.model.Commit; -import ru.ulstu.extractor.model.Repository; -import ru.ulstu.extractor.service.CommitService; import java.util.List; import java.util.stream.Collectors; @@ -50,8 +51,8 @@ public class BranchService { return branch; } - public Branch findByRepositoryAndName(Repository repository, String branchName) { - return branchRepository.findByRepositoryAndName(repository, branchName); + public Branch findByRepositoryAndName(GitRepository gitRepository, String branchName) { + return branchRepository.findByGitRepositoryAndName(gitRepository, branchName); } public List findAll() { diff --git a/src/main/java/ru/ulstu/extractor/model/Commit.java b/src/main/java/ru/ulstu/extractor/commit/model/Commit.java similarity index 98% rename from src/main/java/ru/ulstu/extractor/model/Commit.java rename to src/main/java/ru/ulstu/extractor/commit/model/Commit.java index daf9087..699ff94 100644 --- a/src/main/java/ru/ulstu/extractor/model/Commit.java +++ b/src/main/java/ru/ulstu/extractor/commit/model/Commit.java @@ -7,6 +7,7 @@ package ru.ulstu.extractor.model; import org.hibernate.annotations.Fetch; import org.hibernate.annotations.FetchMode; +import ru.ulstu.extractor.branch.model.Branch; import javax.persistence.CascadeType; import javax.persistence.Entity; diff --git a/src/main/java/ru/ulstu/extractor/model/CommitAuthorStatistic.java b/src/main/java/ru/ulstu/extractor/commit/model/CommitAuthorStatistic.java similarity index 90% rename from src/main/java/ru/ulstu/extractor/model/CommitAuthorStatistic.java rename to src/main/java/ru/ulstu/extractor/commit/model/CommitAuthorStatistic.java index 5587cb2..c3d98f4 100644 --- a/src/main/java/ru/ulstu/extractor/model/CommitAuthorStatistic.java +++ b/src/main/java/ru/ulstu/extractor/commit/model/CommitAuthorStatistic.java @@ -1,4 +1,4 @@ -package ru.ulstu.extractor.model; +package ru.ulstu.extractor.commit.model; public class CommitAuthorStatistic { private String author; diff --git a/src/main/java/ru/ulstu/extractor/model/CommitEntityStatistic.java b/src/main/java/ru/ulstu/extractor/commit/model/CommitEntityStatistic.java similarity index 90% rename from src/main/java/ru/ulstu/extractor/model/CommitEntityStatistic.java rename to src/main/java/ru/ulstu/extractor/commit/model/CommitEntityStatistic.java index 61dc428..2a1a677 100644 --- a/src/main/java/ru/ulstu/extractor/model/CommitEntityStatistic.java +++ b/src/main/java/ru/ulstu/extractor/commit/model/CommitEntityStatistic.java @@ -1,4 +1,4 @@ -package ru.ulstu.extractor.model; +package ru.ulstu.extractor.commit.model; public class CommitEntityStatistic { private Boolean entity; diff --git a/src/main/java/ru/ulstu/extractor/model/CommitTimeStatistic.java b/src/main/java/ru/ulstu/extractor/commit/model/CommitTimeStatistic.java similarity index 92% rename from src/main/java/ru/ulstu/extractor/model/CommitTimeStatistic.java rename to src/main/java/ru/ulstu/extractor/commit/model/CommitTimeStatistic.java index a9ca75c..4cdb369 100644 --- a/src/main/java/ru/ulstu/extractor/model/CommitTimeStatistic.java +++ b/src/main/java/ru/ulstu/extractor/commit/model/CommitTimeStatistic.java @@ -1,4 +1,4 @@ -package ru.ulstu.extractor.model; +package ru.ulstu.extractor.commit.model; public class CommitTimeStatistic { private final static String DATE_TEMPLATE = "%s.%s"; diff --git a/src/main/java/ru/ulstu/extractor/model/CommitUrlStatistic.java b/src/main/java/ru/ulstu/extractor/commit/model/CommitUrlStatistic.java similarity index 89% rename from src/main/java/ru/ulstu/extractor/model/CommitUrlStatistic.java rename to src/main/java/ru/ulstu/extractor/commit/model/CommitUrlStatistic.java index 3eb4b37..c075074 100644 --- a/src/main/java/ru/ulstu/extractor/model/CommitUrlStatistic.java +++ b/src/main/java/ru/ulstu/extractor/commit/model/CommitUrlStatistic.java @@ -1,4 +1,4 @@ -package ru.ulstu.extractor.model; +package ru.ulstu.extractor.commit.model; public class CommitUrlStatistic { private String url; diff --git a/src/main/java/ru/ulstu/extractor/commit/repository/CommitRepository.java b/src/main/java/ru/ulstu/extractor/commit/repository/CommitRepository.java new file mode 100644 index 0000000..d0558d8 --- /dev/null +++ b/src/main/java/ru/ulstu/extractor/commit/repository/CommitRepository.java @@ -0,0 +1,45 @@ +/* + * Copyright (C) 2021 Anton Romanov - All Rights Reserved + * You may use, distribute and modify this code, please write to: romanov73@gmail.com. + */ + +package ru.ulstu.extractor.commit.repository; + +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; +import ru.ulstu.extractor.commit.model.CommitAuthorStatistic; +import ru.ulstu.extractor.commit.model.CommitEntityStatistic; +import ru.ulstu.extractor.commit.model.CommitTimeStatistic; +import ru.ulstu.extractor.commit.model.CommitUrlStatistic; +import ru.ulstu.extractor.gitrepository.model.GitRepository; +import ru.ulstu.extractor.model.Commit; + +import java.util.List; + +public interface CommitRepository extends JpaRepository { + @Query("SELECT DISTINCT c FROM Commit c LEFT JOIN c.branch b LEFT JOIN c.fileChanges f LEFT JOIN c.author a LEFT JOIN b.gitRepository r WHERE r = :repository AND b.name = :branchName AND (:author IS NULL OR :author = '' OR a.name = :author) AND (:filter IS NULL OR :filter = '' OR lower(c.message) LIKE lower(concat('%', :filter,'%'))) AND (:entity IS NULL OR f.containsEntity = :entity)") + Page findByRepositoryAndBranch(Pageable pageable, @Param("repository") GitRepository gitRepository, @Param("branchName") String branchName, @Param("author") String author, @Param("filter") String filter, @Param("entity") Boolean entity); + + @Query("SELECT new ru.ulstu.extractor.commit.model.CommitAuthorStatistic(c.author.name, COUNT(DISTINCT c.hash)) FROM Commit c LEFT JOIN c.branch LEFT JOIN c.author a WHERE (:branchId IS NULL OR c.branch.id = :branchId) AND (:author IS NULL OR :author = '' OR a.name = :author) GROUP by c.author.name") + List getCommitAuthorStatistic(@Param("branchId") Integer branchId, @Param("author") String author); + + @Query("SELECT new ru.ulstu.extractor.commit.model.CommitUrlStatistic(c.branch.gitRepository.url, COUNT(DISTINCT c.hash)) FROM Commit c GROUP by c.branch.gitRepository.url") + List getCommitUrlStatistic(); + + @Query("SELECT new ru.ulstu.extractor.commit.model.CommitTimeStatistic(extract(month FROM c.date) as month, extract(year FROM c.date) as year, COUNT(DISTINCT c.hash)) FROM Commit c LEFT JOIN c.branch LEFT JOIN c.author a WHERE (:branchId IS NULL OR c.branch.id = :branchId) AND (:author IS NULL OR :author = '' OR a.name = :author) GROUP by extract(month from c.date), extract(year from c.date) ORDER by extract(year from c.date), extract(month from c.date)") + List getCommitTimeStatistic(@Param("branchId") Integer branchId, @Param("author") String author); + + @Query("SELECT new ru.ulstu.extractor.commit.model.CommitEntityStatistic(f.containsEntity, COUNT(DISTINCT c.hash)) FROM Commit c LEFT JOIN c.branch LEFT JOIN c.author a LEFT JOIN c.fileChanges f WHERE (:branchId IS NULL OR c.branch.id = :branchId) AND (:author IS NULL OR :author = '' OR a.name = :author) GROUP by f.containsEntity") + List getCommitEntityStatistic(@Param("branchId") Integer branchId, @Param("author") String author); + + @Query("SELECT new ru.ulstu.extractor.commit.model.CommitTimeStatistic(EXTRACT(MONTH FROM c.date), EXTRACT(YEAR FROM c.date), COUNT(DISTINCT c.hash)) FROM Commit c LEFT JOIN c.branch LEFT JOIN c.author a LEFT JOIN c.fileChanges f WHERE f.containsEntity = true AND (:branchId IS NULL OR c.branch.id = :branchId) AND (:author IS NULL OR :author = '' OR a.name = :author) GROUP by extract(month from c.date), extract(year from c.date) ORDER by extract(year from c.date), extract(month from c.date)") + List getCommitTimeEntityStatistic(@Param("branchId") Integer branchId, @Param("author") String author); + + void deleteByBranchIsNull(); + + @Query("SELECT b.commits FROM Branch b WHERE b.name = ?2 and b.gitRepository.id = ?1") + List findByRepositoryIdAndBranchName(Integer repositoryId, String name); +} diff --git a/src/main/java/ru/ulstu/extractor/service/CommitService.java b/src/main/java/ru/ulstu/extractor/commit/service/CommitService.java similarity index 92% rename from src/main/java/ru/ulstu/extractor/service/CommitService.java rename to src/main/java/ru/ulstu/extractor/commit/service/CommitService.java index 8da7bda..fd1c449 100644 --- a/src/main/java/ru/ulstu/extractor/service/CommitService.java +++ b/src/main/java/ru/ulstu/extractor/commit/service/CommitService.java @@ -3,12 +3,13 @@ * You may use, distribute and modify this code, please write to: romanov73@gmail.com. */ -package ru.ulstu.extractor.service; +package ru.ulstu.extractor.commit.service; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.stereotype.Service; +import ru.ulstu.extractor.commit.repository.CommitRepository; import ru.ulstu.extractor.model.Commit; -import ru.ulstu.extractor.repository.CommitRepository; +import ru.ulstu.extractor.service.AuthorService; import java.util.List; import java.util.stream.Collectors; diff --git a/src/main/java/ru/ulstu/extractor/controller/GitIndexingController.java b/src/main/java/ru/ulstu/extractor/controller/GitIndexingController.java index 3102ba5..7708a1f 100644 --- a/src/main/java/ru/ulstu/extractor/controller/GitIndexingController.java +++ b/src/main/java/ru/ulstu/extractor/controller/GitIndexingController.java @@ -15,8 +15,8 @@ import org.springframework.web.bind.annotation.ModelAttribute; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.servlet.mvc.support.RedirectAttributes; +import ru.ulstu.extractor.branch.model.Branch; import ru.ulstu.extractor.gitrepository.GitRepositoryService; -import ru.ulstu.extractor.model.Branch; import ru.ulstu.extractor.model.mvc.FilterForm; import ru.ulstu.extractor.model.mvc.RepoForm; import ru.ulstu.extractor.service.IndexService; diff --git a/src/main/java/ru/ulstu/extractor/controller/StatisticController.java b/src/main/java/ru/ulstu/extractor/controller/StatisticController.java index fd729ef..771a5a0 100644 --- a/src/main/java/ru/ulstu/extractor/controller/StatisticController.java +++ b/src/main/java/ru/ulstu/extractor/controller/StatisticController.java @@ -9,9 +9,9 @@ import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestParam; -import ru.ulstu.extractor.branch.BranchService; +import ru.ulstu.extractor.branch.service.BranchService; +import ru.ulstu.extractor.commit.repository.CommitRepository; import ru.ulstu.extractor.model.mvc.FilterForm; -import ru.ulstu.extractor.repository.CommitRepository; import ru.ulstu.extractor.service.FilteringService; import springfox.documentation.annotations.ApiIgnore; diff --git a/src/main/java/ru/ulstu/extractor/gitrepository/GitRepositoryRepository.java b/src/main/java/ru/ulstu/extractor/gitrepository/GitRepositoryRepository.java index a94a59a..ae9e821 100644 --- a/src/main/java/ru/ulstu/extractor/gitrepository/GitRepositoryRepository.java +++ b/src/main/java/ru/ulstu/extractor/gitrepository/GitRepositoryRepository.java @@ -1,8 +1,8 @@ package ru.ulstu.extractor.gitrepository; import org.springframework.data.jpa.repository.JpaRepository; -import ru.ulstu.extractor.model.Repository; +import ru.ulstu.extractor.gitrepository.model.GitRepository; -public interface GitRepositoryRepository extends JpaRepository { - Repository findByUrl(String url); +public interface GitRepositoryRepository extends JpaRepository { + GitRepository findByUrl(String url); } diff --git a/src/main/java/ru/ulstu/extractor/gitrepository/GitRepositoryService.java b/src/main/java/ru/ulstu/extractor/gitrepository/GitRepositoryService.java index 61eebf9..f05a91a 100644 --- a/src/main/java/ru/ulstu/extractor/gitrepository/GitRepositoryService.java +++ b/src/main/java/ru/ulstu/extractor/gitrepository/GitRepositoryService.java @@ -18,16 +18,16 @@ import org.springframework.beans.factory.annotation.Value; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Service; +import ru.ulstu.extractor.branch.model.Branch; +import ru.ulstu.extractor.gitrepository.model.GitRepository; import ru.ulstu.extractor.heuristic.model.BusinessLogicUnit; import ru.ulstu.extractor.heuristic.model.EntityUnit; import ru.ulstu.extractor.heuristic.model.ResourceUnit; import ru.ulstu.extractor.heuristic.service.StructuralUnitService; import ru.ulstu.extractor.model.Author; -import ru.ulstu.extractor.model.Branch; import ru.ulstu.extractor.model.Commit; import ru.ulstu.extractor.model.FileChange; import ru.ulstu.extractor.model.LineChange; -import ru.ulstu.extractor.model.Repository; import java.io.ByteArrayOutputStream; import java.io.File; @@ -346,7 +346,7 @@ public class GitRepositoryService { return Optional.empty(); } - public Page findAll(Pageable pageable) { + public Page findAll(Pageable pageable) { return gitRepositoryRepository.findAll(pageable); } } diff --git a/src/main/java/ru/ulstu/extractor/model/Repository.java b/src/main/java/ru/ulstu/extractor/gitrepository/model/GitRepository.java similarity index 51% rename from src/main/java/ru/ulstu/extractor/model/Repository.java rename to src/main/java/ru/ulstu/extractor/gitrepository/model/GitRepository.java index 651bfca..edabd3e 100644 --- a/src/main/java/ru/ulstu/extractor/model/Repository.java +++ b/src/main/java/ru/ulstu/extractor/gitrepository/model/GitRepository.java @@ -1,15 +1,17 @@ -package ru.ulstu.extractor.model; +package ru.ulstu.extractor.gitrepository.model; + +import ru.ulstu.extractor.model.BaseEntity; import javax.persistence.Entity; @Entity -public class Repository extends BaseEntity { +public class GitRepository extends BaseEntity { private String url; - public Repository() { + public GitRepository() { } - public Repository(String repositoryUrl) { + public GitRepository(String repositoryUrl) { url = repositoryUrl; } diff --git a/src/main/java/ru/ulstu/extractor/repository/AuthorRepository.java b/src/main/java/ru/ulstu/extractor/repository/AuthorRepository.java index 26b5f45..0ae8a20 100644 --- a/src/main/java/ru/ulstu/extractor/repository/AuthorRepository.java +++ b/src/main/java/ru/ulstu/extractor/repository/AuthorRepository.java @@ -8,14 +8,14 @@ package ru.ulstu.extractor.repository; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; +import ru.ulstu.extractor.gitrepository.model.GitRepository; import ru.ulstu.extractor.model.Author; -import ru.ulstu.extractor.model.Repository; import java.util.List; public interface AuthorRepository extends JpaRepository { - @Query("SELECT DISTINCT a.name FROM Commit c, Repository r, Branch b, Author a WHERE c.author = a AND c.branch = b AND r = b.repository AND (:repository IS NULL OR r = :repository) AND (:branchName IS NULL OR :branchName = '' OR b.name = :branchName) AND a.name IS NOT NULL AND a.name <> '' ORDER BY a.name") - List findByRepositoryAndBranch(@Param("repository") Repository repository, @Param("branchName") String branchName); + @Query("SELECT DISTINCT a.name FROM Commit c, GitRepository r, Branch b, Author a WHERE c.author = a AND c.branch = b AND r = b.gitRepository AND (:repository IS NULL OR r = :repository) AND (:branchName IS NULL OR :branchName = '' OR b.name = :branchName) AND a.name IS NOT NULL AND a.name <> '' ORDER BY a.name") + List findByRepositoryAndBranch(@Param("repository") GitRepository gitRepository, @Param("branchName") String branchName); List findByName(String name); diff --git a/src/main/java/ru/ulstu/extractor/repository/CommitRepository.java b/src/main/java/ru/ulstu/extractor/repository/CommitRepository.java deleted file mode 100644 index 8bf5e98..0000000 --- a/src/main/java/ru/ulstu/extractor/repository/CommitRepository.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright (C) 2021 Anton Romanov - All Rights Reserved - * You may use, distribute and modify this code, please write to: romanov73@gmail.com. - */ - -package ru.ulstu.extractor.repository; - -import org.springframework.data.domain.Page; -import org.springframework.data.domain.Pageable; -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.jpa.repository.Query; -import org.springframework.data.repository.query.Param; -import ru.ulstu.extractor.model.Commit; -import ru.ulstu.extractor.model.CommitAuthorStatistic; -import ru.ulstu.extractor.model.CommitEntityStatistic; -import ru.ulstu.extractor.model.CommitTimeStatistic; -import ru.ulstu.extractor.model.CommitUrlStatistic; -import ru.ulstu.extractor.model.Repository; - -import java.util.List; - -public interface CommitRepository extends JpaRepository { - @Query("SELECT DISTINCT c FROM Commit c LEFT JOIN c.branch b LEFT JOIN c.fileChanges f LEFT JOIN c.author a LEFT JOIN b.repository r WHERE r = :repository AND b.name = :branchName AND (:author IS NULL OR :author = '' OR a.name = :author) AND (:filter IS NULL OR :filter = '' OR lower(c.message) LIKE lower(concat('%', :filter,'%'))) AND (:entity IS NULL OR f.containsEntity = :entity)") - Page findByRepositoryAndBranch(Pageable pageable, @Param("repository") Repository repository, @Param("branchName") String branchName, @Param("author") String author, @Param("filter") String filter, @Param("entity") Boolean entity); - - @Query("SELECT new ru.ulstu.extractor.model.CommitAuthorStatistic(c.author.name, COUNT(DISTINCT c.hash)) FROM Commit c LEFT JOIN c.branch LEFT JOIN c.author a WHERE (:branchId IS NULL OR c.branch.id = :branchId) AND (:author IS NULL OR :author = '' OR a.name = :author) GROUP by c.author.name") - List getCommitAuthorStatistic(@Param("branchId") Integer branchId, @Param("author") String author); - - @Query("SELECT new ru.ulstu.extractor.model.CommitUrlStatistic(c.branch.repository.url, COUNT(DISTINCT c.hash)) FROM Commit c GROUP by c.branch.repository.url") - List getCommitUrlStatistic(); - - @Query("SELECT new ru.ulstu.extractor.model.CommitTimeStatistic(extract(month FROM c.date) as month, extract(year FROM c.date) as year, COUNT(DISTINCT c.hash)) FROM Commit c LEFT JOIN c.branch LEFT JOIN c.author a WHERE (:branchId IS NULL OR c.branch.id = :branchId) AND (:author IS NULL OR :author = '' OR a.name = :author) GROUP by extract(month from c.date), extract(year from c.date) ORDER by extract(year from c.date), extract(month from c.date)") - List getCommitTimeStatistic(@Param("branchId") Integer branchId, @Param("author") String author); - - @Query("SELECT new ru.ulstu.extractor.model.CommitEntityStatistic(f.containsEntity, COUNT(DISTINCT c.hash)) FROM Commit c LEFT JOIN c.branch LEFT JOIN c.author a LEFT JOIN c.fileChanges f WHERE (:branchId IS NULL OR c.branch.id = :branchId) AND (:author IS NULL OR :author = '' OR a.name = :author) GROUP by f.containsEntity") - List getCommitEntityStatistic(@Param("branchId") Integer branchId, @Param("author") String author); - - @Query("SELECT new ru.ulstu.extractor.model.CommitTimeStatistic(EXTRACT(MONTH FROM c.date), EXTRACT(YEAR FROM c.date), COUNT(DISTINCT c.hash)) FROM Commit c LEFT JOIN c.branch LEFT JOIN c.author a LEFT JOIN c.fileChanges f WHERE f.containsEntity = true AND (:branchId IS NULL OR c.branch.id = :branchId) AND (:author IS NULL OR :author = '' OR a.name = :author) GROUP by extract(month from c.date), extract(year from c.date) ORDER by extract(year from c.date), extract(month from c.date)") - List getCommitTimeEntityStatistic(@Param("branchId") Integer branchId, @Param("author") String author); - - void deleteByBranchIsNull(); - - @Query("SELECT b.commits FROM Branch b WHERE b.name = ?2 and b.repository.id = ?1") - List findByRepositoryIdAndBranchName(Integer repositoryId, String name); -} diff --git a/src/main/java/ru/ulstu/extractor/service/FilteringService.java b/src/main/java/ru/ulstu/extractor/service/FilteringService.java index 51802aa..ddeda0c 100644 --- a/src/main/java/ru/ulstu/extractor/service/FilteringService.java +++ b/src/main/java/ru/ulstu/extractor/service/FilteringService.java @@ -9,10 +9,10 @@ import com.sun.istack.NotNull; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Service; +import ru.ulstu.extractor.commit.repository.CommitRepository; import ru.ulstu.extractor.gitrepository.GitRepositoryRepository; import ru.ulstu.extractor.model.Commit; import ru.ulstu.extractor.repository.AuthorRepository; -import ru.ulstu.extractor.repository.CommitRepository; import java.util.List; import java.util.Map; diff --git a/src/main/java/ru/ulstu/extractor/service/IndexService.java b/src/main/java/ru/ulstu/extractor/service/IndexService.java index 875f357..d5415e2 100644 --- a/src/main/java/ru/ulstu/extractor/service/IndexService.java +++ b/src/main/java/ru/ulstu/extractor/service/IndexService.java @@ -10,12 +10,12 @@ import org.eclipse.jgit.api.errors.GitAPIException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Service; -import ru.ulstu.extractor.branch.BranchService; +import ru.ulstu.extractor.branch.model.Branch; +import ru.ulstu.extractor.branch.service.BranchService; import ru.ulstu.extractor.gitrepository.GitRepositoryRepository; import ru.ulstu.extractor.gitrepository.GitRepositoryService; -import ru.ulstu.extractor.model.Branch; +import ru.ulstu.extractor.gitrepository.model.GitRepository; import ru.ulstu.extractor.model.Commit; -import ru.ulstu.extractor.model.Repository; import ru.ulstu.extractor.ts.AbstractTimeSeriesCreator; import java.io.IOException; @@ -42,13 +42,13 @@ public class IndexService { } public void index(@NotNull String repositoryUrl, @NotNull String branchName) throws GitAPIException, IOException { - Repository repository = gitRepositoryRepository.findByUrl(repositoryUrl); - if (repository == null) { - repository = gitRepositoryRepository.save(new Repository(repositoryUrl)); + GitRepository gitRepository = gitRepositoryRepository.findByUrl(repositoryUrl); + if (gitRepository == null) { + gitRepository = gitRepositoryRepository.save(new GitRepository(repositoryUrl)); } - Branch branch = branchService.findByRepositoryAndName(repository, branchName); + Branch branch = branchService.findByRepositoryAndName(gitRepository, branchName); if (branch == null) { - branch = new Branch(repository, branchName); + branch = new Branch(gitRepository, branchName); } branchService.save(branch, Collections.emptyList()); int commitsFrom = 0; @@ -62,7 +62,7 @@ public class IndexService { commitsTo += COMMITS_PAGE_SIZE; commits = gitRepositoryService.getCommits(repositoryUrl, branchName, commitsFrom, commitsTo, false); } - Integer repositoryId = repository.getId(); + Integer repositoryId = gitRepository.getId(); timeSeriesCreators.forEach(tsCreator -> tsCreator.addTimeSeries(repositoryId, branchName)); LOG.debug("Complete indexing {} branch", branchName); } diff --git a/src/main/java/ru/ulstu/extractor/service/TimeSeriesService.java b/src/main/java/ru/ulstu/extractor/service/TimeSeriesService.java index 30a8327..644f6aa 100644 --- a/src/main/java/ru/ulstu/extractor/service/TimeSeriesService.java +++ b/src/main/java/ru/ulstu/extractor/service/TimeSeriesService.java @@ -40,7 +40,7 @@ public class TimeSeriesService { timeSeries.setValues(timeSeriesValues); LOG.debug("Save time series {} ", timeSeries.getName()); TimeSeries savedTimeSeries = timeSeriesRepository.save(timeSeries); - LOG.debug("Clear {} ime series values ", timeSeriesValuesToRemoveIds.size()); + LOG.debug("Clear {} time series values ", timeSeriesValuesToRemoveIds.size()); return savedTimeSeries; } diff --git a/src/main/java/ru/ulstu/extractor/ts/CommitsTS.java b/src/main/java/ru/ulstu/extractor/ts/CommitsTS.java index 6a2b6f2..8f7dae0 100644 --- a/src/main/java/ru/ulstu/extractor/ts/CommitsTS.java +++ b/src/main/java/ru/ulstu/extractor/ts/CommitsTS.java @@ -1,8 +1,8 @@ package ru.ulstu.extractor.ts; import org.springframework.stereotype.Component; +import ru.ulstu.extractor.commit.service.CommitService; import ru.ulstu.extractor.model.TimeSeriesValue; -import ru.ulstu.extractor.service.CommitService; import ru.ulstu.extractor.service.TimeSeriesService; import java.util.List; @@ -26,6 +26,7 @@ public class CommitsTS extends AbstractTimeSeriesCreator { @Override public List getTimeSeriesValues(Integer repositoryId, String branchName) { + //TODO: добавить постраничное чтение return commitService.findByRepositoryIdAndName(repositoryId, branchName) .stream() .map(c -> new TimeSeriesValue(c.getDate(), 1)) diff --git a/src/main/resources/db/changelog-20220621_120000-schema.xml b/src/main/resources/db/changelog-20220621_120000-schema.xml new file mode 100644 index 0000000..2df5c58 --- /dev/null +++ b/src/main/resources/db/changelog-20220621_120000-schema.xml @@ -0,0 +1,11 @@ + + + + + + + + + \ No newline at end of file diff --git a/src/main/resources/db/changelog-master.xml b/src/main/resources/db/changelog-master.xml index b9c9b69..e2afa54 100644 --- a/src/main/resources/db/changelog-master.xml +++ b/src/main/resources/db/changelog-master.xml @@ -13,4 +13,5 @@ + diff --git a/src/main/resources/templates/statistic.html b/src/main/resources/templates/statistic.html index e89c1a8..2ad0eb2 100644 --- a/src/main/resources/templates/statistic.html +++ b/src/main/resources/templates/statistic.html @@ -193,7 +193,7 @@