#58 -- fix models naming, refactor
This commit is contained in:
parent
156cdbc672
commit
a7add46348
@ -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, Integer> {
|
|
||||||
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<Branch> findByRepositoryId(Integer repositoryId);
|
|
||||||
|
|
||||||
Page<Branch> findByRepository(Repository repository, Pageable pageable);
|
|
||||||
}
|
|
@ -3,12 +3,13 @@
|
|||||||
* You may use, distribute and modify this code, please write to: romanov73@gmail.com.
|
* 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.stereotype.Controller;
|
||||||
import org.springframework.ui.Model;
|
import org.springframework.ui.Model;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestParam;
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
|
import ru.ulstu.extractor.branch.repository.BranchRepository;
|
||||||
import ru.ulstu.extractor.gitrepository.GitRepositoryRepository;
|
import ru.ulstu.extractor.gitrepository.GitRepositoryRepository;
|
||||||
import springfox.documentation.annotations.ApiIgnore;
|
import springfox.documentation.annotations.ApiIgnore;
|
||||||
|
|
||||||
@ -30,7 +31,7 @@ public class BranchController {
|
|||||||
public String indexBranch(
|
public String indexBranch(
|
||||||
Model model,
|
Model model,
|
||||||
@RequestParam int repositoryId) {
|
@RequestParam int repositoryId) {
|
||||||
model.addAttribute("branches", branchRepository.findByRepositoryId(repositoryId));
|
model.addAttribute("branches", branchRepository.findByGitRepositoryId(repositoryId));
|
||||||
model.addAttribute("repository", gitRepositoryRepository.findById(repositoryId).get());
|
model.addAttribute("repository", gitRepositoryRepository.findById(repositoryId).get());
|
||||||
return LIST_REPOSITORY_BRANCHES;
|
return LIST_REPOSITORY_BRANCHES;
|
||||||
}
|
}
|
||||||
@ -40,7 +41,7 @@ public class BranchController {
|
|||||||
@RequestParam int repositoryId,
|
@RequestParam int repositoryId,
|
||||||
@RequestParam Integer id) {
|
@RequestParam Integer id) {
|
||||||
branchRepository.deleteById(id);
|
branchRepository.deleteById(id);
|
||||||
model.addAttribute("branches", branchRepository.findByRepositoryId(repositoryId));
|
model.addAttribute("branches", branchRepository.findByGitRepositoryId(repositoryId));
|
||||||
model.addAttribute("repository", gitRepositoryRepository.findById(repositoryId).get());
|
model.addAttribute("repository", gitRepositoryRepository.findById(repositoryId).get());
|
||||||
return LIST_REPOSITORY_BRANCHES;
|
return LIST_REPOSITORY_BRANCHES;
|
||||||
}
|
}
|
@ -3,10 +3,13 @@
|
|||||||
* You may use, distribute and modify this code, please write to: romanov73@gmail.com.
|
* 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.Fetch;
|
||||||
import org.hibernate.annotations.FetchMode;
|
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.CascadeType;
|
||||||
import javax.persistence.Entity;
|
import javax.persistence.Entity;
|
||||||
@ -22,7 +25,7 @@ public class Branch extends BaseEntity {
|
|||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
@ManyToOne
|
@ManyToOne
|
||||||
private Repository repository;
|
private GitRepository gitRepository;
|
||||||
|
|
||||||
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
|
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
|
||||||
@JoinColumn(name = "branch_id")
|
@JoinColumn(name = "branch_id")
|
||||||
@ -36,8 +39,8 @@ public class Branch extends BaseEntity {
|
|||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Branch(Repository repository, String branchName) {
|
public Branch(GitRepository gitRepository, String branchName) {
|
||||||
this.repository = repository;
|
this.gitRepository = gitRepository;
|
||||||
this.name = branchName;
|
this.name = branchName;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -49,12 +52,12 @@ public class Branch extends BaseEntity {
|
|||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Repository getRepository() {
|
public GitRepository getGitRepository() {
|
||||||
return repository;
|
return gitRepository;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setRepository(Repository repository) {
|
public void setGitRepository(GitRepository gitRepository) {
|
||||||
this.repository = repository;
|
this.gitRepository = gitRepository;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Commit> getCommits() {
|
public List<Commit> getCommits() {
|
@ -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, Integer> {
|
||||||
|
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<Branch> findByGitRepositoryId(Integer repositoryId);
|
||||||
|
|
||||||
|
Page<Branch> findByGitRepository(GitRepository gitRepository, Pageable pageable);
|
||||||
|
}
|
@ -3,17 +3,18 @@
|
|||||||
* You may use, distribute and modify this code, please write to: romanov73@gmail.com.
|
* 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.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
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.BaseEntity;
|
||||||
import ru.ulstu.extractor.model.Branch;
|
|
||||||
import ru.ulstu.extractor.model.Commit;
|
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.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
@ -50,8 +51,8 @@ public class BranchService {
|
|||||||
return branch;
|
return branch;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Branch findByRepositoryAndName(Repository repository, String branchName) {
|
public Branch findByRepositoryAndName(GitRepository gitRepository, String branchName) {
|
||||||
return branchRepository.findByRepositoryAndName(repository, branchName);
|
return branchRepository.findByGitRepositoryAndName(gitRepository, branchName);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Branch> findAll() {
|
public List<Branch> findAll() {
|
@ -7,6 +7,7 @@ package ru.ulstu.extractor.model;
|
|||||||
|
|
||||||
import org.hibernate.annotations.Fetch;
|
import org.hibernate.annotations.Fetch;
|
||||||
import org.hibernate.annotations.FetchMode;
|
import org.hibernate.annotations.FetchMode;
|
||||||
|
import ru.ulstu.extractor.branch.model.Branch;
|
||||||
|
|
||||||
import javax.persistence.CascadeType;
|
import javax.persistence.CascadeType;
|
||||||
import javax.persistence.Entity;
|
import javax.persistence.Entity;
|
@ -1,4 +1,4 @@
|
|||||||
package ru.ulstu.extractor.model;
|
package ru.ulstu.extractor.commit.model;
|
||||||
|
|
||||||
public class CommitAuthorStatistic {
|
public class CommitAuthorStatistic {
|
||||||
private String author;
|
private String author;
|
@ -1,4 +1,4 @@
|
|||||||
package ru.ulstu.extractor.model;
|
package ru.ulstu.extractor.commit.model;
|
||||||
|
|
||||||
public class CommitEntityStatistic {
|
public class CommitEntityStatistic {
|
||||||
private Boolean entity;
|
private Boolean entity;
|
@ -1,4 +1,4 @@
|
|||||||
package ru.ulstu.extractor.model;
|
package ru.ulstu.extractor.commit.model;
|
||||||
|
|
||||||
public class CommitTimeStatistic {
|
public class CommitTimeStatistic {
|
||||||
private final static String DATE_TEMPLATE = "%s.%s";
|
private final static String DATE_TEMPLATE = "%s.%s";
|
@ -1,4 +1,4 @@
|
|||||||
package ru.ulstu.extractor.model;
|
package ru.ulstu.extractor.commit.model;
|
||||||
|
|
||||||
public class CommitUrlStatistic {
|
public class CommitUrlStatistic {
|
||||||
private String url;
|
private String url;
|
@ -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<Commit, Integer> {
|
||||||
|
@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<Commit> 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<CommitAuthorStatistic> 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<CommitUrlStatistic> 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<CommitTimeStatistic> 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<CommitEntityStatistic> 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<CommitTimeStatistic> 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<Commit> findByRepositoryIdAndBranchName(Integer repositoryId, String name);
|
||||||
|
}
|
@ -3,12 +3,13 @@
|
|||||||
* You may use, distribute and modify this code, please write to: romanov73@gmail.com.
|
* 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.jdbc.core.JdbcTemplate;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
import ru.ulstu.extractor.commit.repository.CommitRepository;
|
||||||
import ru.ulstu.extractor.model.Commit;
|
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.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
@ -15,8 +15,8 @@ import org.springframework.web.bind.annotation.ModelAttribute;
|
|||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestMethod;
|
import org.springframework.web.bind.annotation.RequestMethod;
|
||||||
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
|
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.gitrepository.GitRepositoryService;
|
||||||
import ru.ulstu.extractor.model.Branch;
|
|
||||||
import ru.ulstu.extractor.model.mvc.FilterForm;
|
import ru.ulstu.extractor.model.mvc.FilterForm;
|
||||||
import ru.ulstu.extractor.model.mvc.RepoForm;
|
import ru.ulstu.extractor.model.mvc.RepoForm;
|
||||||
import ru.ulstu.extractor.service.IndexService;
|
import ru.ulstu.extractor.service.IndexService;
|
||||||
|
@ -9,9 +9,9 @@ import org.springframework.stereotype.Controller;
|
|||||||
import org.springframework.ui.Model;
|
import org.springframework.ui.Model;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestParam;
|
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.model.mvc.FilterForm;
|
||||||
import ru.ulstu.extractor.repository.CommitRepository;
|
|
||||||
import ru.ulstu.extractor.service.FilteringService;
|
import ru.ulstu.extractor.service.FilteringService;
|
||||||
import springfox.documentation.annotations.ApiIgnore;
|
import springfox.documentation.annotations.ApiIgnore;
|
||||||
|
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
package ru.ulstu.extractor.gitrepository;
|
package ru.ulstu.extractor.gitrepository;
|
||||||
|
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
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, Integer> {
|
public interface GitRepositoryRepository extends JpaRepository<GitRepository, Integer> {
|
||||||
Repository findByUrl(String url);
|
GitRepository findByUrl(String url);
|
||||||
}
|
}
|
||||||
|
@ -18,16 +18,16 @@ import org.springframework.beans.factory.annotation.Value;
|
|||||||
import org.springframework.data.domain.Page;
|
import org.springframework.data.domain.Page;
|
||||||
import org.springframework.data.domain.Pageable;
|
import org.springframework.data.domain.Pageable;
|
||||||
import org.springframework.stereotype.Service;
|
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.BusinessLogicUnit;
|
||||||
import ru.ulstu.extractor.heuristic.model.EntityUnit;
|
import ru.ulstu.extractor.heuristic.model.EntityUnit;
|
||||||
import ru.ulstu.extractor.heuristic.model.ResourceUnit;
|
import ru.ulstu.extractor.heuristic.model.ResourceUnit;
|
||||||
import ru.ulstu.extractor.heuristic.service.StructuralUnitService;
|
import ru.ulstu.extractor.heuristic.service.StructuralUnitService;
|
||||||
import ru.ulstu.extractor.model.Author;
|
import ru.ulstu.extractor.model.Author;
|
||||||
import ru.ulstu.extractor.model.Branch;
|
|
||||||
import ru.ulstu.extractor.model.Commit;
|
import ru.ulstu.extractor.model.Commit;
|
||||||
import ru.ulstu.extractor.model.FileChange;
|
import ru.ulstu.extractor.model.FileChange;
|
||||||
import ru.ulstu.extractor.model.LineChange;
|
import ru.ulstu.extractor.model.LineChange;
|
||||||
import ru.ulstu.extractor.model.Repository;
|
|
||||||
|
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
@ -346,7 +346,7 @@ public class GitRepositoryService {
|
|||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Page<Repository> findAll(Pageable pageable) {
|
public Page<GitRepository> findAll(Pageable pageable) {
|
||||||
return gitRepositoryRepository.findAll(pageable);
|
return gitRepositoryRepository.findAll(pageable);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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;
|
import javax.persistence.Entity;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
public class Repository extends BaseEntity {
|
public class GitRepository extends BaseEntity {
|
||||||
private String url;
|
private String url;
|
||||||
|
|
||||||
public Repository() {
|
public GitRepository() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Repository(String repositoryUrl) {
|
public GitRepository(String repositoryUrl) {
|
||||||
url = repositoryUrl;
|
url = repositoryUrl;
|
||||||
}
|
}
|
||||||
|
|
@ -8,14 +8,14 @@ package ru.ulstu.extractor.repository;
|
|||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
import org.springframework.data.jpa.repository.Query;
|
import org.springframework.data.jpa.repository.Query;
|
||||||
import org.springframework.data.repository.query.Param;
|
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.Author;
|
||||||
import ru.ulstu.extractor.model.Repository;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public interface AuthorRepository extends JpaRepository<Author, Integer> {
|
public interface AuthorRepository extends JpaRepository<Author, Integer> {
|
||||||
@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")
|
@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<String> findByRepositoryAndBranch(@Param("repository") Repository repository, @Param("branchName") String branchName);
|
List<String> findByRepositoryAndBranch(@Param("repository") GitRepository gitRepository, @Param("branchName") String branchName);
|
||||||
|
|
||||||
List<Author> findByName(String name);
|
List<Author> findByName(String name);
|
||||||
|
|
||||||
|
@ -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<Commit, Integer> {
|
|
||||||
@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<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 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<CommitAuthorStatistic> 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<CommitUrlStatistic> 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<CommitTimeStatistic> 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<CommitEntityStatistic> 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<CommitTimeStatistic> 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<Commit> findByRepositoryIdAndBranchName(Integer repositoryId, String name);
|
|
||||||
}
|
|
@ -9,10 +9,10 @@ import com.sun.istack.NotNull;
|
|||||||
import org.springframework.data.domain.Page;
|
import org.springframework.data.domain.Page;
|
||||||
import org.springframework.data.domain.Pageable;
|
import org.springframework.data.domain.Pageable;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
import ru.ulstu.extractor.commit.repository.CommitRepository;
|
||||||
import ru.ulstu.extractor.gitrepository.GitRepositoryRepository;
|
import ru.ulstu.extractor.gitrepository.GitRepositoryRepository;
|
||||||
import ru.ulstu.extractor.model.Commit;
|
import ru.ulstu.extractor.model.Commit;
|
||||||
import ru.ulstu.extractor.repository.AuthorRepository;
|
import ru.ulstu.extractor.repository.AuthorRepository;
|
||||||
import ru.ulstu.extractor.repository.CommitRepository;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
@ -10,12 +10,12 @@ import org.eclipse.jgit.api.errors.GitAPIException;
|
|||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.stereotype.Service;
|
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.GitRepositoryRepository;
|
||||||
import ru.ulstu.extractor.gitrepository.GitRepositoryService;
|
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.Commit;
|
||||||
import ru.ulstu.extractor.model.Repository;
|
|
||||||
import ru.ulstu.extractor.ts.AbstractTimeSeriesCreator;
|
import ru.ulstu.extractor.ts.AbstractTimeSeriesCreator;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@ -42,13 +42,13 @@ public class IndexService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void index(@NotNull String repositoryUrl, @NotNull String branchName) throws GitAPIException, IOException {
|
public void index(@NotNull String repositoryUrl, @NotNull String branchName) throws GitAPIException, IOException {
|
||||||
Repository repository = gitRepositoryRepository.findByUrl(repositoryUrl);
|
GitRepository gitRepository = gitRepositoryRepository.findByUrl(repositoryUrl);
|
||||||
if (repository == null) {
|
if (gitRepository == null) {
|
||||||
repository = gitRepositoryRepository.save(new Repository(repositoryUrl));
|
gitRepository = gitRepositoryRepository.save(new GitRepository(repositoryUrl));
|
||||||
}
|
}
|
||||||
Branch branch = branchService.findByRepositoryAndName(repository, branchName);
|
Branch branch = branchService.findByRepositoryAndName(gitRepository, branchName);
|
||||||
if (branch == null) {
|
if (branch == null) {
|
||||||
branch = new Branch(repository, branchName);
|
branch = new Branch(gitRepository, branchName);
|
||||||
}
|
}
|
||||||
branchService.save(branch, Collections.emptyList());
|
branchService.save(branch, Collections.emptyList());
|
||||||
int commitsFrom = 0;
|
int commitsFrom = 0;
|
||||||
@ -62,7 +62,7 @@ public class IndexService {
|
|||||||
commitsTo += COMMITS_PAGE_SIZE;
|
commitsTo += COMMITS_PAGE_SIZE;
|
||||||
commits = gitRepositoryService.getCommits(repositoryUrl, branchName, commitsFrom, commitsTo, false);
|
commits = gitRepositoryService.getCommits(repositoryUrl, branchName, commitsFrom, commitsTo, false);
|
||||||
}
|
}
|
||||||
Integer repositoryId = repository.getId();
|
Integer repositoryId = gitRepository.getId();
|
||||||
timeSeriesCreators.forEach(tsCreator -> tsCreator.addTimeSeries(repositoryId, branchName));
|
timeSeriesCreators.forEach(tsCreator -> tsCreator.addTimeSeries(repositoryId, branchName));
|
||||||
LOG.debug("Complete indexing {} branch", branchName);
|
LOG.debug("Complete indexing {} branch", branchName);
|
||||||
}
|
}
|
||||||
|
@ -40,7 +40,7 @@ public class TimeSeriesService {
|
|||||||
timeSeries.setValues(timeSeriesValues);
|
timeSeries.setValues(timeSeriesValues);
|
||||||
LOG.debug("Save time series {} ", timeSeries.getName());
|
LOG.debug("Save time series {} ", timeSeries.getName());
|
||||||
TimeSeries savedTimeSeries = timeSeriesRepository.save(timeSeries);
|
TimeSeries savedTimeSeries = timeSeriesRepository.save(timeSeries);
|
||||||
LOG.debug("Clear {} ime series values ", timeSeriesValuesToRemoveIds.size());
|
LOG.debug("Clear {} time series values ", timeSeriesValuesToRemoveIds.size());
|
||||||
return savedTimeSeries;
|
return savedTimeSeries;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
package ru.ulstu.extractor.ts;
|
package ru.ulstu.extractor.ts;
|
||||||
|
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
import ru.ulstu.extractor.commit.service.CommitService;
|
||||||
import ru.ulstu.extractor.model.TimeSeriesValue;
|
import ru.ulstu.extractor.model.TimeSeriesValue;
|
||||||
import ru.ulstu.extractor.service.CommitService;
|
|
||||||
import ru.ulstu.extractor.service.TimeSeriesService;
|
import ru.ulstu.extractor.service.TimeSeriesService;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -26,6 +26,7 @@ public class CommitsTS extends AbstractTimeSeriesCreator {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<TimeSeriesValue> getTimeSeriesValues(Integer repositoryId, String branchName) {
|
public List<TimeSeriesValue> getTimeSeriesValues(Integer repositoryId, String branchName) {
|
||||||
|
//TODO: добавить постраничное чтение
|
||||||
return commitService.findByRepositoryIdAndName(repositoryId, branchName)
|
return commitService.findByRepositoryIdAndName(repositoryId, branchName)
|
||||||
.stream()
|
.stream()
|
||||||
.map(c -> new TimeSeriesValue(c.getDate(), 1))
|
.map(c -> new TimeSeriesValue(c.getDate(), 1))
|
||||||
|
11
src/main/resources/db/changelog-20220621_120000-schema.xml
Normal file
11
src/main/resources/db/changelog-20220621_120000-schema.xml
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
<?xml version="1.1" encoding="UTF-8" standalone="no"?>
|
||||||
|
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.1.xsd">
|
||||||
|
<changeSet author="orion" id="20220621-120000-1">
|
||||||
|
<renameColumn tableName="branch" oldColumnName="repository_id" newColumnName="git_repository_id"/>
|
||||||
|
</changeSet>
|
||||||
|
<changeSet author="orion" id="20220621-120000-2">
|
||||||
|
<renameTable oldTableName="repository" newTableName="git_repository"/>
|
||||||
|
</changeSet>
|
||||||
|
</databaseChangeLog>
|
@ -13,4 +13,5 @@
|
|||||||
<include file="db/changelog-20210329_120000-schema.xml"/>
|
<include file="db/changelog-20210329_120000-schema.xml"/>
|
||||||
<include file="db/changelog-20210412_100000-schema.xml"/>
|
<include file="db/changelog-20210412_100000-schema.xml"/>
|
||||||
<include file="db/changelog-20220422_120000-schema.xml"/>
|
<include file="db/changelog-20220422_120000-schema.xml"/>
|
||||||
|
<include file="db/changelog-20220621_120000-schema.xml"/>
|
||||||
</databaseChangeLog>
|
</databaseChangeLog>
|
||||||
|
@ -193,7 +193,7 @@
|
|||||||
<option value="">Все ветки</option>
|
<option value="">Все ветки</option>
|
||||||
<option th:each="branch : ${branches}"
|
<option th:each="branch : ${branches}"
|
||||||
th:value="${branch.id}"
|
th:value="${branch.id}"
|
||||||
th:utext="${branch.repository.url} + ' - '+ ${branch.name}">
|
th:utext="${branch.gitRepository.url} + ' - '+ ${branch.name}">
|
||||||
</option>
|
</option>
|
||||||
</select>
|
</select>
|
||||||
<script th:inline="javascript">
|
<script th:inline="javascript">
|
||||||
|
Loading…
Reference in New Issue
Block a user