From 6c6e8fdc3bad455073024c7e0709417e503313bd Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Mon, 12 Apr 2021 16:38:01 +0400 Subject: [PATCH 1/4] #21 -- Add entity filter --- .../controller/GitFilteringController.java | 4 +++- .../controller/StatisticController.java | 5 +++++ .../model/CommitEntityStatistic.java | 20 +++++++++++++++++++ .../ulstu/extractor/model/mvc/FilterForm.java | 10 ++++++++++ .../repository/CommitRepository.java | 6 ++++-- .../extractor/service/FilteringService.java | 4 +++- .../resources/templates/filterCommits.html | 6 ++++++ 7 files changed, 51 insertions(+), 4 deletions(-) create mode 100644 src/main/java/ru/ulstu/extractor/model/CommitEntityStatistic.java diff --git a/src/main/java/ru/ulstu/extractor/controller/GitFilteringController.java b/src/main/java/ru/ulstu/extractor/controller/GitFilteringController.java index e172698..0e69083 100644 --- a/src/main/java/ru/ulstu/extractor/controller/GitFilteringController.java +++ b/src/main/java/ru/ulstu/extractor/controller/GitFilteringController.java @@ -40,7 +40,8 @@ public class GitFilteringController { @RequestParam Optional repositoryUrl, @RequestParam Optional branchName, @RequestParam Optional author, - @RequestParam Optional filter) { + @RequestParam Optional filter, + @RequestParam Optional entity) { int currentPage = page.orElse(1); int pageSize = size.orElse(DEFAULT_PAGE_SIZE); @@ -51,6 +52,7 @@ public class GitFilteringController { notEmptyBranchName, author.orElse(null), filter.orElse(null), + entity.orElse(null), new OffsetablePageRequest(currentPage - 1, pageSize)); int totalPages = commitsPage.getTotalPages(); if (totalPages > 0) { diff --git a/src/main/java/ru/ulstu/extractor/controller/StatisticController.java b/src/main/java/ru/ulstu/extractor/controller/StatisticController.java index 55f1f33..18044bd 100644 --- a/src/main/java/ru/ulstu/extractor/controller/StatisticController.java +++ b/src/main/java/ru/ulstu/extractor/controller/StatisticController.java @@ -48,6 +48,11 @@ public class StatisticController { } model.addAttribute("urls", url); +// List entityCommits = commitRepository.getCommitEntityStatistic().stream() +// .map(stat -> new Object[]{stat.getEntity(), stat.getCountCommit()}) +// .collect(Collectors.toList()); +// model.addAttribute("commitTimeData", timeCommits); + return STATISTIC; } } diff --git a/src/main/java/ru/ulstu/extractor/model/CommitEntityStatistic.java b/src/main/java/ru/ulstu/extractor/model/CommitEntityStatistic.java new file mode 100644 index 0000000..61dc428 --- /dev/null +++ b/src/main/java/ru/ulstu/extractor/model/CommitEntityStatistic.java @@ -0,0 +1,20 @@ +package ru.ulstu.extractor.model; + +public class CommitEntityStatistic { + private Boolean entity; + private Long countCommit; + + public CommitEntityStatistic(Boolean entity, Long countCommit) { + this.entity = entity; + this.countCommit = countCommit; + } + + public Boolean getEntity() { + return entity; + } + + public Long getCountCommit() { + return countCommit; + } + +} diff --git a/src/main/java/ru/ulstu/extractor/model/mvc/FilterForm.java b/src/main/java/ru/ulstu/extractor/model/mvc/FilterForm.java index 2d42b74..7d8b436 100644 --- a/src/main/java/ru/ulstu/extractor/model/mvc/FilterForm.java +++ b/src/main/java/ru/ulstu/extractor/model/mvc/FilterForm.java @@ -13,6 +13,7 @@ public class FilterForm { private String repositoryUrl; private String branchName; private String author; + private boolean entity; private Page commitsPage; public FilterForm() { @@ -62,6 +63,14 @@ public class FilterForm { this.branchName = branchName; } + public boolean getEntity() { + return entity; + } + + public void setEntity(boolean entity) { + this.entity = entity; + } + @Override public String toString() { return "FilterForm{" + @@ -70,6 +79,7 @@ public class FilterForm { ", branchName='" + branchName + '\'' + ", author='" + author + '\'' + ", commitsPage=" + commitsPage + + ", entity='" + entity + '}'; } } diff --git a/src/main/java/ru/ulstu/extractor/repository/CommitRepository.java b/src/main/java/ru/ulstu/extractor/repository/CommitRepository.java index 00fde10..55c7b13 100644 --- a/src/main/java/ru/ulstu/extractor/repository/CommitRepository.java +++ b/src/main/java/ru/ulstu/extractor/repository/CommitRepository.java @@ -19,8 +19,8 @@ import ru.ulstu.extractor.model.Repository; import java.util.List; public interface CommitRepository extends JpaRepository { - @Query("SELECT c FROM Commit c, Repository r, Branch b, Author a WHERE c.branch = b AND r = b.repository AND a = c.author AND 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,'%')))") - Page findByRepositoryAndBranch(Pageable pageable, @Param("repository") Repository repository, @Param("branchName") String branchName, @Param("author") String author, @Param("filter") String filter); + @Query("SELECT c FROM Commit c, Repository r, Branch b, Author a, FileChange f WHERE c.branch = b AND r = b.repository AND a = c.author AND f MEMBER OF c.fileChanges AND 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 GROUP by c.author.name") List getCommitAuthorStatistic(); @@ -31,4 +31,6 @@ public interface CommitRepository extends JpaRepository { @Query("SELECT new ru.ulstu.extractor.model.CommitTimeStatistic(cast(c.date as date), COUNT(DISTINCT c.hash)) FROM Commit c GROUP by cast(c.date as date) ORDER by cast(c.date as date)") List getCommitTimeStatistic(); +// @Query("SELECT new ru.ulstu.extractor.model.CommitEntityStatistic(f.containsEntity, COUNT(DISTINCT f.commit.hash)) FROM FileChange f GROUP by f.containsEntity") +// List getCommitEntityStatistic(); } diff --git a/src/main/java/ru/ulstu/extractor/service/FilteringService.java b/src/main/java/ru/ulstu/extractor/service/FilteringService.java index f85f3fb..c22cfae 100644 --- a/src/main/java/ru/ulstu/extractor/service/FilteringService.java +++ b/src/main/java/ru/ulstu/extractor/service/FilteringService.java @@ -42,13 +42,15 @@ public class FilteringService { @NotNull String branchName, String author, String filter, + Boolean entity, Pageable pageable) { return commitRepository.findByRepositoryAndBranch( pageable, repositoryRepository.findByUrl(repositoryUrl), branchName, author, - filter + filter, + entity ); } } diff --git a/src/main/resources/templates/filterCommits.html b/src/main/resources/templates/filterCommits.html index 0a44875..7f06b73 100644 --- a/src/main/resources/templates/filterCommits.html +++ b/src/main/resources/templates/filterCommits.html @@ -73,6 +73,12 @@
+
+ Содержит сущность: +
+
+ +
From b32bad1edafb460131b9d73d24f29b916348f18a Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Mon, 12 Apr 2021 17:10:23 +0400 Subject: [PATCH 2/4] #21 -- Clean filter --- .../ru/ulstu/extractor/controller/StatisticController.java | 6 ------ .../ru/ulstu/extractor/repository/CommitRepository.java | 2 -- 2 files changed, 8 deletions(-) diff --git a/src/main/java/ru/ulstu/extractor/controller/StatisticController.java b/src/main/java/ru/ulstu/extractor/controller/StatisticController.java index 18044bd..13595ee 100644 --- a/src/main/java/ru/ulstu/extractor/controller/StatisticController.java +++ b/src/main/java/ru/ulstu/extractor/controller/StatisticController.java @@ -47,12 +47,6 @@ public class StatisticController { url[i] = urlCommits.get(i)[0].toString().substring(urlCommits.get(i)[0].toString().lastIndexOf("/") + 1); } model.addAttribute("urls", url); - -// List entityCommits = commitRepository.getCommitEntityStatistic().stream() -// .map(stat -> new Object[]{stat.getEntity(), stat.getCountCommit()}) -// .collect(Collectors.toList()); -// model.addAttribute("commitTimeData", timeCommits); - return STATISTIC; } } diff --git a/src/main/java/ru/ulstu/extractor/repository/CommitRepository.java b/src/main/java/ru/ulstu/extractor/repository/CommitRepository.java index 55c7b13..9435847 100644 --- a/src/main/java/ru/ulstu/extractor/repository/CommitRepository.java +++ b/src/main/java/ru/ulstu/extractor/repository/CommitRepository.java @@ -31,6 +31,4 @@ public interface CommitRepository extends JpaRepository { @Query("SELECT new ru.ulstu.extractor.model.CommitTimeStatistic(cast(c.date as date), COUNT(DISTINCT c.hash)) FROM Commit c GROUP by cast(c.date as date) ORDER by cast(c.date as date)") List getCommitTimeStatistic(); -// @Query("SELECT new ru.ulstu.extractor.model.CommitEntityStatistic(f.containsEntity, COUNT(DISTINCT f.commit.hash)) FROM FileChange f GROUP by f.containsEntity") -// List getCommitEntityStatistic(); } From 0b0b8193b4a883eea129f097cd553f4f33b043a9 Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Tue, 13 Apr 2021 16:52:10 +0400 Subject: [PATCH 3/4] Add check entity --- .../ulstu/extractor/controller/GitFilteringController.java | 1 + src/main/resources/templates/filterCommits.html | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/java/ru/ulstu/extractor/controller/GitFilteringController.java b/src/main/java/ru/ulstu/extractor/controller/GitFilteringController.java index 0e69083..f683699 100644 --- a/src/main/java/ru/ulstu/extractor/controller/GitFilteringController.java +++ b/src/main/java/ru/ulstu/extractor/controller/GitFilteringController.java @@ -67,6 +67,7 @@ public class GitFilteringController { filterForm.setRepositoryUrl(notEmptyRepositoryUrl); filterForm.setAuthor(author.orElse(null)); filterForm.setFilter(filter.orElse(null)); + filterForm.setEntity(entity.orElse(false)); model.addAttribute("filterForm", filterForm); model.addAttribute("authors", filteringService.getRepositoryAuthors( notEmptyRepositoryUrl, diff --git a/src/main/resources/templates/filterCommits.html b/src/main/resources/templates/filterCommits.html index 7f06b73..63d8057 100644 --- a/src/main/resources/templates/filterCommits.html +++ b/src/main/resources/templates/filterCommits.html @@ -77,7 +77,7 @@ Содержит сущность:
- +
@@ -117,7 +117,8 @@ repositoryUrl=${filterForm.repositoryUrl}, branchName=${filterForm.branchName}, author=${filterForm.author}, - filter=${filterForm.filter})}" + filter=${filterForm.filter}, + entity=${filterForm.entity})}" th:text=${pageNumber} th:class="${pageNumber == filterForm.commitsPage.number} ? active">
From e61e13e3428c1af88ef277297072dc58c73c2979 Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Wed, 14 Apr 2021 11:42:10 +0400 Subject: [PATCH 4/4] Delete extra file --- .../ru/ulstu/extractor/model/NewClass.java | 55 ------------------- 1 file changed, 55 deletions(-) delete mode 100644 src/main/java/ru/ulstu/extractor/model/NewClass.java diff --git a/src/main/java/ru/ulstu/extractor/model/NewClass.java b/src/main/java/ru/ulstu/extractor/model/NewClass.java deleted file mode 100644 index e363be7..0000000 --- a/src/main/java/ru/ulstu/extractor/model/NewClass.java +++ /dev/null @@ -1,55 +0,0 @@ -package ru.ulstu.extractor.model; - -import org.eclipse.jgit.diff.DiffEntry; -import org.eclipse.jgit.diff.DiffFormatter; -import org.eclipse.jgit.revwalk.RevCommit; -import org.eclipse.jgit.revwalk.RevWalk; - -import java.io.IOException; -import java.util.Collections; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -public class NewClass { - - private final RevWalk revWalk; - private final DiffFormatter diffFormatter; - - private NewClass(RevWalk revWalk, DiffFormatter diffFormatter) { - this.revWalk = revWalk; - this.diffFormatter = diffFormatter; - } - - public Set getModified(final RevCommit commit) throws IOException { - final RevCommit[] parents = commit.getParents(); - final Set result = new HashSet<>(); - if (parents.length == 1) { // merge commit if length > 1 - final RevCommit parent = revWalk.parseCommit(parents[0].getId()); - // get diff of this commit to its parent, as list of paths - final List diffs = getDiffEntries(commit, parent); - for (final DiffEntry diff : diffs) { - final String changePath = diff.getChangeType().equals(DiffEntry.ChangeType.DELETE) ? diff.getOldPath() : diff.getNewPath(); - result.add(changePath); - } - } - return result; - } - - private List getDiffEntries(final RevCommit commit, final RevCommit parent) { - try { - return diffFormatter.scan(parent.getTree(), commit.getTree()); - } catch (Exception e) { - e.printStackTrace(); - } - return Collections.emptyList(); - } -} - -// Первая основная таблица: коммит, автор, дата -// Вторая таблица : коммит, имя файла, добавленные строки, удаленные строки - -// Фильтрация коммитов по автору(только основная таблица) -// Фильтрация коммитов по дате -// Фильтрация коммитов по именни файла, или добавленные строки. -