Merge branch '21--filter-by-entity' into 'master'

Resolve "Фильтр по сущности"

Closes #21

See merge request romanov73/git-extractor!19
This commit is contained in:
Anton Romanov 2021-04-12 13:11:41 +00:00
commit 1cd785ee41
7 changed files with 44 additions and 5 deletions

View File

@ -40,7 +40,8 @@ public class GitFilteringController {
@RequestParam Optional<String> repositoryUrl, @RequestParam Optional<String> repositoryUrl,
@RequestParam Optional<String> branchName, @RequestParam Optional<String> branchName,
@RequestParam Optional<String> author, @RequestParam Optional<String> author,
@RequestParam Optional<String> filter) { @RequestParam Optional<String> filter,
@RequestParam Optional<Boolean> entity) {
int currentPage = page.orElse(1); int currentPage = page.orElse(1);
int pageSize = size.orElse(DEFAULT_PAGE_SIZE); int pageSize = size.orElse(DEFAULT_PAGE_SIZE);
@ -51,6 +52,7 @@ public class GitFilteringController {
notEmptyBranchName, notEmptyBranchName,
author.orElse(null), author.orElse(null),
filter.orElse(null), filter.orElse(null),
entity.orElse(null),
new OffsetablePageRequest(currentPage - 1, pageSize)); new OffsetablePageRequest(currentPage - 1, pageSize));
int totalPages = commitsPage.getTotalPages(); int totalPages = commitsPage.getTotalPages();
if (totalPages > 0) { if (totalPages > 0) {

View File

@ -47,7 +47,6 @@ public class StatisticController {
url[i] = urlCommits.get(i)[0].toString().substring(urlCommits.get(i)[0].toString().lastIndexOf("/") + 1); url[i] = urlCommits.get(i)[0].toString().substring(urlCommits.get(i)[0].toString().lastIndexOf("/") + 1);
} }
model.addAttribute("urls", url); model.addAttribute("urls", url);
return STATISTIC; return STATISTIC;
} }
} }

View File

@ -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;
}
}

View File

@ -13,6 +13,7 @@ public class FilterForm {
private String repositoryUrl; private String repositoryUrl;
private String branchName; private String branchName;
private String author; private String author;
private boolean entity;
private Page<Commit> commitsPage; private Page<Commit> commitsPage;
public FilterForm() { public FilterForm() {
@ -62,6 +63,14 @@ public class FilterForm {
this.branchName = branchName; this.branchName = branchName;
} }
public boolean getEntity() {
return entity;
}
public void setEntity(boolean entity) {
this.entity = entity;
}
@Override @Override
public String toString() { public String toString() {
return "FilterForm{" + return "FilterForm{" +
@ -70,6 +79,7 @@ public class FilterForm {
", branchName='" + branchName + '\'' + ", branchName='" + branchName + '\'' +
", author='" + author + '\'' + ", author='" + author + '\'' +
", commitsPage=" + commitsPage + ", commitsPage=" + commitsPage +
", entity='" + entity +
'}'; '}';
} }
} }

View File

@ -19,8 +19,8 @@ import ru.ulstu.extractor.model.Repository;
import java.util.List; import java.util.List;
public interface CommitRepository extends JpaRepository<Commit, Integer> { public interface CommitRepository extends JpaRepository<Commit, Integer> {
@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,'%')))") @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<Commit> findByRepositoryAndBranch(Pageable pageable, @Param("repository") Repository repository, @Param("branchName") String branchName, @Param("author") String author, @Param("filter") String filter); Page<Commit> 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") @Query("SELECT new ru.ulstu.extractor.model.CommitAuthorStatistic(c.author.name, COUNT(DISTINCT c.hash)) FROM Commit c GROUP by c.author.name")
List<CommitAuthorStatistic> getCommitAuthorStatistic(); List<CommitAuthorStatistic> getCommitAuthorStatistic();

View File

@ -42,13 +42,15 @@ public class FilteringService {
@NotNull String branchName, @NotNull String branchName,
String author, String author,
String filter, String filter,
Boolean entity,
Pageable pageable) { Pageable pageable) {
return commitRepository.findByRepositoryAndBranch( return commitRepository.findByRepositoryAndBranch(
pageable, pageable,
repositoryRepository.findByUrl(repositoryUrl), repositoryRepository.findByUrl(repositoryUrl),
branchName, branchName,
author, author,
filter filter,
entity
); );
} }
} }

View File

@ -73,6 +73,12 @@
<div class="col-md-6 col-sm-12"> <div class="col-md-6 col-sm-12">
<input type="text" class="form-control" size="40" th:field="*{filter}"> <input type="text" class="form-control" size="40" th:field="*{filter}">
</div> </div>
<div class="col-md-2 col-sm-12">
Содержит сущность:
</div>
<div class="form-group form-check">
<input type="checkbox" class="form-check-input" th:field="*{entity}">
</div>
<div class="col-md-4 col-sm-12"> <div class="col-md-4 col-sm-12">
<input type="submit" class="btn btn-outline-success w-100" value="Применить фильтр"/> <input type="submit" class="btn btn-outline-success w-100" value="Применить фильтр"/>
</div> </div>