diff --git a/src/main/java/ru/ulstu/extractor/controller/GitFilteringController.java b/src/main/java/ru/ulstu/extractor/controller/GitFilteringController.java index e172698..f683699 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) { @@ -65,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/java/ru/ulstu/extractor/controller/StatisticController.java b/src/main/java/ru/ulstu/extractor/controller/StatisticController.java index 55f1f33..13595ee 100644 --- a/src/main/java/ru/ulstu/extractor/controller/StatisticController.java +++ b/src/main/java/ru/ulstu/extractor/controller/StatisticController.java @@ -47,7 +47,6 @@ public class StatisticController { url[i] = urlCommits.get(i)[0].toString().substring(urlCommits.get(i)[0].toString().lastIndexOf("/") + 1); } model.addAttribute("urls", url); - 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/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(); - } -} - -// Первая основная таблица: коммит, автор, дата -// Вторая таблица : коммит, имя файла, добавленные строки, удаленные строки - -// Фильтрация коммитов по автору(только основная таблица) -// Фильтрация коммитов по дате -// Фильтрация коммитов по именни файла, или добавленные строки. - 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..9435847 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(); 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..63d8057 100644 --- a/src/main/resources/templates/filterCommits.html +++ b/src/main/resources/templates/filterCommits.html @@ -73,6 +73,12 @@
+
+ Содержит сущность: +
+
+ +
@@ -111,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">