Временные ряды #59
@ -2,8 +2,10 @@ package ru.ulstu.extractor;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||
|
||||
@SpringBootApplication
|
||||
@EnableScheduling
|
||||
public class GitExtractorApplication {
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(GitExtractorApplication.class, args);
|
||||
|
@ -0,0 +1,21 @@
|
||||
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,16 +3,19 @@
|
||||
* You may use, distribute and modify this code, please write to: romanov73@gmail.com.
|
||||
*/
|
||||
|
||||
package ru.ulstu.extractor.service;
|
||||
package ru.ulstu.extractor.branch;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
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.repository.BranchRepository;
|
||||
import ru.ulstu.extractor.service.CommitService;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
@ -29,6 +32,7 @@ public class BranchService {
|
||||
this.commitService = commitService;
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public Branch save(Branch branch, List<Commit> commits) {
|
||||
LOG.debug("Start save {} branch with {} commits ", branch.getName(), commits.size());
|
||||
List<Integer> commitsToRemoveIds = branch.getCommits().stream().map(BaseEntity::getId).collect(Collectors.toList());
|
||||
@ -52,6 +56,14 @@ public class BranchService {
|
||||
return branchRepository.findByRepositoryAndName(repository, branchName);
|
||||
}
|
||||
|
||||
public int getCommitsCount(Integer repositoryId, String branchName) {
|
||||
return branchRepository.getCommitsCount(repositoryId, branchName);
|
||||
}
|
||||
|
||||
public Page<Branch> findByRepository(Repository repository, Pageable pageable) {
|
||||
return branchRepository.findByRepository(repository, pageable);
|
||||
}
|
||||
|
||||
public List<Branch> findAll() {
|
||||
return branchRepository.findAll();
|
||||
}
|
@ -9,8 +9,8 @@ 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.repository.BranchRepository;
|
||||
import ru.ulstu.extractor.repository.RepositoryRepository;
|
||||
import ru.ulstu.extractor.branch.BranchRepository;
|
||||
import ru.ulstu.extractor.gitrepository.GitRepositoryRepository;
|
||||
import springfox.documentation.annotations.ApiIgnore;
|
||||
|
||||
import static ru.ulstu.extractor.controller.Route.DELETE_BRANCH;
|
||||
@ -19,11 +19,11 @@ import static ru.ulstu.extractor.controller.Route.LIST_REPOSITORY_BRANCHES;
|
||||
@Controller
|
||||
@ApiIgnore
|
||||
public class BranchController {
|
||||
private final RepositoryRepository repositoryRepository;
|
||||
private final GitRepositoryRepository gitRepositoryRepository;
|
||||
private final BranchRepository branchRepository;
|
||||
|
||||
public BranchController(RepositoryRepository repositoryRepository, BranchRepository branchRepository) {
|
||||
this.repositoryRepository = repositoryRepository;
|
||||
public BranchController(GitRepositoryRepository gitRepositoryRepository, BranchRepository branchRepository) {
|
||||
this.gitRepositoryRepository = gitRepositoryRepository;
|
||||
this.branchRepository = branchRepository;
|
||||
}
|
||||
|
||||
@ -32,7 +32,7 @@ public class BranchController {
|
||||
Model model,
|
||||
@RequestParam int repositoryId) {
|
||||
model.addAttribute("branches", branchRepository.findByRepositoryId(repositoryId));
|
||||
model.addAttribute("repository", repositoryRepository.findById(repositoryId).get());
|
||||
model.addAttribute("repository", gitRepositoryRepository.findById(repositoryId).get());
|
||||
return LIST_REPOSITORY_BRANCHES;
|
||||
}
|
||||
|
||||
@ -42,7 +42,7 @@ public class BranchController {
|
||||
@RequestParam Integer id) {
|
||||
branchRepository.deleteById(id);
|
||||
model.addAttribute("branches", branchRepository.findByRepositoryId(repositoryId));
|
||||
model.addAttribute("repository", repositoryRepository.findById(repositoryId).get());
|
||||
model.addAttribute("repository", gitRepositoryRepository.findById(repositoryId).get());
|
||||
return LIST_REPOSITORY_BRANCHES;
|
||||
}
|
||||
}
|
||||
|
@ -15,10 +15,10 @@ 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.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.GitRepositoryService;
|
||||
import ru.ulstu.extractor.service.IndexService;
|
||||
import springfox.documentation.annotations.ApiIgnore;
|
||||
|
||||
|
@ -12,8 +12,8 @@ import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import ru.ulstu.extractor.gitrepository.GitRepositoryService;
|
||||
import ru.ulstu.extractor.model.Commit;
|
||||
import ru.ulstu.extractor.service.GitRepositoryService;
|
||||
import ru.ulstu.extractor.service.IndexService;
|
||||
import ru.ulstu.extractor.util.HttpUtils;
|
||||
|
||||
|
@ -9,7 +9,7 @@ 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.repository.RepositoryRepository;
|
||||
import ru.ulstu.extractor.gitrepository.GitRepositoryRepository;
|
||||
import springfox.documentation.annotations.ApiIgnore;
|
||||
|
||||
import static ru.ulstu.extractor.controller.Route.DELETE_INDEXED_REPOSITORY;
|
||||
@ -18,23 +18,23 @@ import static ru.ulstu.extractor.controller.Route.LIST_INDEXED_REPOSITORIES;
|
||||
@Controller
|
||||
@ApiIgnore
|
||||
public class RepositoryController {
|
||||
private final RepositoryRepository repositoryRepository;
|
||||
private final GitRepositoryRepository gitRepositoryRepository;
|
||||
|
||||
public RepositoryController(RepositoryRepository repositoryRepository) {
|
||||
this.repositoryRepository = repositoryRepository;
|
||||
public RepositoryController(GitRepositoryRepository gitRepositoryRepository) {
|
||||
this.gitRepositoryRepository = gitRepositoryRepository;
|
||||
}
|
||||
|
||||
@GetMapping(LIST_INDEXED_REPOSITORIES)
|
||||
public String indexNewRepo(Model model) {
|
||||
model.addAttribute("repositories", repositoryRepository.findAll());
|
||||
model.addAttribute("repositories", gitRepositoryRepository.findAll());
|
||||
return LIST_INDEXED_REPOSITORIES;
|
||||
}
|
||||
|
||||
@GetMapping(DELETE_INDEXED_REPOSITORY)
|
||||
public String deleteRepo(Model model,
|
||||
@RequestParam Integer id) {
|
||||
repositoryRepository.deleteById(id);
|
||||
model.addAttribute("repositories", repositoryRepository.findAll());
|
||||
gitRepositoryRepository.deleteById(id);
|
||||
model.addAttribute("repositories", gitRepositoryRepository.findAll());
|
||||
return "redirect:/" + LIST_INDEXED_REPOSITORIES;
|
||||
}
|
||||
}
|
||||
|
@ -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.model.mvc.FilterForm;
|
||||
import ru.ulstu.extractor.repository.CommitRepository;
|
||||
import ru.ulstu.extractor.service.BranchService;
|
||||
import ru.ulstu.extractor.service.FilteringService;
|
||||
import springfox.documentation.annotations.ApiIgnore;
|
||||
|
||||
|
@ -1,8 +1,8 @@
|
||||
package ru.ulstu.extractor.repository;
|
||||
package ru.ulstu.extractor.gitrepository;
|
||||
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import ru.ulstu.extractor.model.Repository;
|
||||
|
||||
public interface RepositoryRepository extends JpaRepository<Repository, Integer> {
|
||||
public interface GitRepositoryRepository extends JpaRepository<Repository, Integer> {
|
||||
Repository findByUrl(String url);
|
||||
}
|
@ -1,9 +1,4 @@
|
||||
/*
|
||||
* 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.service;
|
||||
package ru.ulstu.extractor.gitrepository;
|
||||
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.eclipse.jgit.api.CreateBranchCommand;
|
||||
@ -15,12 +10,13 @@ import org.eclipse.jgit.internal.storage.file.FileRepository;
|
||||
import org.eclipse.jgit.lib.ObjectId;
|
||||
import org.eclipse.jgit.lib.ObjectLoader;
|
||||
import org.eclipse.jgit.lib.ObjectReader;
|
||||
import org.eclipse.jgit.lib.Repository;
|
||||
import org.eclipse.jgit.revwalk.RevCommit;
|
||||
import org.eclipse.jgit.treewalk.TreeWalk;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
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.heuristic.model.BusinessLogicUnit;
|
||||
import ru.ulstu.extractor.heuristic.model.EntityUnit;
|
||||
@ -31,6 +27,7 @@ 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;
|
||||
@ -61,18 +58,20 @@ public class GitRepositoryService {
|
||||
private String customProjectsDir;
|
||||
private final ExecutorService executorService = Executors.newFixedThreadPool(4);
|
||||
private final ExecutorService executorServiceCommits = Executors.newFixedThreadPool(4);
|
||||
|
||||
private final StructuralUnitService structuralUnitService;
|
||||
private final GitRepositoryRepository gitRepositoryRepository;
|
||||
|
||||
public GitRepositoryService(StructuralUnitService structuralUnitService) {
|
||||
public GitRepositoryService(StructuralUnitService structuralUnitService,
|
||||
GitRepositoryRepository gitRepositoryRepository) {
|
||||
this.structuralUnitService = structuralUnitService;
|
||||
this.gitRepositoryRepository = gitRepositoryRepository;
|
||||
}
|
||||
|
||||
public List<Branch> getRemoteBranches(String url) throws GitAPIException, IOException {
|
||||
LOG.debug("Get remote branches of {}. Clone", url);
|
||||
cloneOrUpdateRepo(url);
|
||||
LOG.debug("Get remote branches of {}. Get branches", url);
|
||||
Repository localRepo = new FileRepository(getProjectGitDirectory(url));
|
||||
org.eclipse.jgit.lib.Repository localRepo = new FileRepository(getProjectGitDirectory(url));
|
||||
Git git = new Git(localRepo);
|
||||
List<Branch> branches = git.branchList().setListMode(ListBranchCommand.ListMode.REMOTE)
|
||||
.call()
|
||||
@ -88,7 +87,7 @@ public class GitRepositoryService {
|
||||
LOG.debug("Get local branches of {}. Clone", url);
|
||||
cloneOrUpdateRepo(url);
|
||||
LOG.debug("Get local branches of {}. Get branches", url);
|
||||
Repository localRepo = new FileRepository(getProjectGitDirectory(url));
|
||||
org.eclipse.jgit.lib.Repository localRepo = new FileRepository(getProjectGitDirectory(url));
|
||||
Git git = new Git(localRepo);
|
||||
List<Branch> branches = git.branchList()
|
||||
.call()
|
||||
@ -105,7 +104,7 @@ public class GitRepositoryService {
|
||||
if (needUpdate) {
|
||||
cloneOrUpdateRepo(repositoryUrl, branchName);
|
||||
}
|
||||
Repository localRepo = new FileRepository(getProjectGitDirectory(repositoryUrl));
|
||||
org.eclipse.jgit.lib.Repository localRepo = new FileRepository(getProjectGitDirectory(repositoryUrl));
|
||||
Git git = new Git(localRepo);
|
||||
|
||||
List<RevCommit> commits = new ArrayList<>();
|
||||
@ -144,7 +143,7 @@ public class GitRepositoryService {
|
||||
return list;
|
||||
}
|
||||
|
||||
private void checkoutBranch(String repositoryUrl, Git git, Repository localRepo, String branchName) throws GitAPIException, IOException {
|
||||
private void checkoutBranch(String repositoryUrl, Git git, org.eclipse.jgit.lib.Repository localRepo, String branchName) throws GitAPIException, IOException {
|
||||
LOG.debug("Checkout branch {} {}", repositoryUrl, branchName);
|
||||
git.pull().call();
|
||||
if (!localRepo.getBranch().equals(branchName)) {
|
||||
@ -192,7 +191,7 @@ public class GitRepositoryService {
|
||||
|
||||
private void cloneOrUpdateRepo(String repositoryUrl, String branchName) throws GitAPIException, IOException {
|
||||
Git git;
|
||||
Repository localRepo;
|
||||
org.eclipse.jgit.lib.Repository localRepo;
|
||||
if (projectDirExists(getProjectDirectoryFile(repositoryUrl))) {
|
||||
localRepo = new FileRepository(getProjectGitDirectory(repositoryUrl));
|
||||
git = new Git(localRepo);
|
||||
@ -240,7 +239,7 @@ public class GitRepositoryService {
|
||||
return file.exists();
|
||||
}
|
||||
|
||||
private List<FileChange> findDiffBetweenTwoRevisions(RevCommit laterCommit, RevCommit earlierCommit, Repository localRepo) {
|
||||
private List<FileChange> findDiffBetweenTwoRevisions(RevCommit laterCommit, RevCommit earlierCommit, org.eclipse.jgit.lib.Repository localRepo) {
|
||||
if (laterCommit == null || earlierCommit == null) {
|
||||
return null;
|
||||
}
|
||||
@ -256,7 +255,7 @@ public class GitRepositoryService {
|
||||
return parseOutputDiff(output, localRepo, laterCommit);
|
||||
}
|
||||
|
||||
private List<FileChange> parseOutputDiff(String output, Repository repository, RevCommit commit) {
|
||||
private List<FileChange> parseOutputDiff(String output, org.eclipse.jgit.lib.Repository repository, RevCommit commit) {
|
||||
List<FileChange> changes = new ArrayList<>();
|
||||
String[] strings = output.split("\n");
|
||||
FileChange fileChange = new FileChange();
|
||||
@ -322,7 +321,7 @@ public class GitRepositoryService {
|
||||
return changes;
|
||||
}
|
||||
|
||||
private String getContent(Repository repository, RevCommit commit, String path) {
|
||||
private String getContent(org.eclipse.jgit.lib.Repository repository, RevCommit commit, String path) {
|
||||
try (TreeWalk treeWalk = TreeWalk.forPath(repository, path, commit.getTree())) {
|
||||
if (treeWalk != null) {
|
||||
ObjectId blobId = treeWalk.getObjectId(0);
|
||||
@ -346,4 +345,8 @@ public class GitRepositoryService {
|
||||
}
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
public Page<Repository> findAll(Pageable pageable) {
|
||||
return gitRepositoryRepository.findAll(pageable);
|
||||
}
|
||||
}
|
@ -11,10 +11,10 @@ import org.slf4j.LoggerFactory;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import ru.ulstu.extractor.gitrepository.GitRepositoryService;
|
||||
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.service.GitRepositoryService;
|
||||
import ru.ulstu.extractor.util.HttpUtils;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
69
src/main/java/ru/ulstu/extractor/loader/GitScheduler.java
Normal file
69
src/main/java/ru/ulstu/extractor/loader/GitScheduler.java
Normal file
@ -0,0 +1,69 @@
|
||||
package ru.ulstu.extractor.loader;
|
||||
|
||||
import org.eclipse.jgit.api.errors.GitAPIException;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Service;
|
||||
import ru.ulstu.extractor.branch.BranchService;
|
||||
import ru.ulstu.extractor.gitrepository.GitRepositoryService;
|
||||
import ru.ulstu.extractor.model.Branch;
|
||||
import ru.ulstu.extractor.model.OffsetablePageRequest;
|
||||
import ru.ulstu.extractor.model.Repository;
|
||||
import ru.ulstu.extractor.service.IndexService;
|
||||
import ru.ulstu.extractor.ts.AbstractTSExtractor;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class GitScheduler {
|
||||
private final static int DEFAULT_PAGE_SIZE = 100;
|
||||
private final Logger log = LoggerFactory.getLogger(GitScheduler.class);
|
||||
private final GitRepositoryService gitRepositoryService;
|
||||
private final BranchService branchService;
|
||||
private final IndexService indexService;
|
||||
private final List<AbstractTSExtractor> tsExtractors;
|
||||
|
||||
public GitScheduler(GitRepositoryService gitRepositoryService,
|
||||
BranchService branchService,
|
||||
IndexService indexService,
|
||||
List<AbstractTSExtractor> tsExtractors) {
|
||||
this.gitRepositoryService = gitRepositoryService;
|
||||
this.branchService = branchService;
|
||||
this.indexService = indexService;
|
||||
this.tsExtractors = tsExtractors;
|
||||
}
|
||||
|
||||
@Scheduled(cron = "* */5 * * * *")
|
||||
public void getCommitsCount() {
|
||||
log.debug("Load commits count started");
|
||||
int repositoryPageNumber = 0;
|
||||
Page<Repository> repositoryPage;
|
||||
do {
|
||||
int branchPageNumber = 0;
|
||||
repositoryPage = gitRepositoryService.findAll(
|
||||
new OffsetablePageRequest(repositoryPageNumber, DEFAULT_PAGE_SIZE));
|
||||
Page<Branch> branchPage;
|
||||
for (Repository repository : repositoryPage.getContent()) {
|
||||
do {
|
||||
branchPage = branchService.findByRepository(repository,
|
||||
new OffsetablePageRequest(branchPageNumber, DEFAULT_PAGE_SIZE));
|
||||
for (Branch branch : branchPage.getContent()) {
|
||||
try {
|
||||
indexService.index(repository.getUrl(), branch.getName());
|
||||
tsExtractors.forEach(tsExtractor -> tsExtractor.addPoint(repository.getId(), branch.getName()));
|
||||
} catch (GitAPIException | IOException ex) {
|
||||
log.warn(ex.getMessage());
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
branchPageNumber++;
|
||||
} while (!branchPage.isEmpty());
|
||||
}
|
||||
repositoryPageNumber++;
|
||||
} while (!repositoryPage.isEmpty());
|
||||
log.debug("Load commits count finished");
|
||||
}
|
||||
}
|
@ -1,13 +0,0 @@
|
||||
package ru.ulstu.extractor.repository;
|
||||
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
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);
|
||||
|
||||
List<Branch> findByRepositoryId(Integer repositoryId);
|
||||
}
|
@ -1,13 +1,10 @@
|
||||
package ru.ulstu.extractor.repository;
|
||||
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import ru.ulstu.extractor.model.TimeSeries;
|
||||
import ru.ulstu.extractor.model.TimeSeriesValue;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface TimeSeriesValueRepository extends JpaRepository<TimeSeriesValue, Integer> {
|
||||
TimeSeriesValue findByTimeSeriesAndName(TimeSeries timeSeries, String name);
|
||||
//TimeSeriesValue findByTimeSeriesAndName(TimeSeries timeSeries, String name);
|
||||
|
||||
List<TimeSeriesValue> findTimeSeriesValueById(Integer repositoryId);
|
||||
//List<TimeSeriesValue> findTimeSeriesValueById(Integer repositoryId);
|
||||
}
|
||||
|
@ -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.gitrepository.GitRepositoryRepository;
|
||||
import ru.ulstu.extractor.model.Commit;
|
||||
import ru.ulstu.extractor.repository.AuthorRepository;
|
||||
import ru.ulstu.extractor.repository.CommitRepository;
|
||||
import ru.ulstu.extractor.repository.RepositoryRepository;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@ -21,20 +21,20 @@ import java.util.Map;
|
||||
public class FilteringService {
|
||||
private final AuthorRepository authorRepository;
|
||||
private final CommitRepository commitRepository;
|
||||
private final RepositoryRepository repositoryRepository;
|
||||
private final GitRepositoryRepository gitRepositoryRepository;
|
||||
|
||||
public FilteringService(AuthorRepository authorRepository,
|
||||
CommitRepository commitRepository,
|
||||
RepositoryRepository repositoryRepository) {
|
||||
GitRepositoryRepository gitRepositoryRepository) {
|
||||
this.authorRepository = authorRepository;
|
||||
this.commitRepository = commitRepository;
|
||||
this.repositoryRepository = repositoryRepository;
|
||||
this.gitRepositoryRepository = gitRepositoryRepository;
|
||||
}
|
||||
|
||||
public List<String> getRepositoryAuthors(@NotNull String repositoryUrl,
|
||||
@NotNull String branchName) {
|
||||
return authorRepository.findByRepositoryAndBranch(
|
||||
repositoryRepository.findByUrl(repositoryUrl),
|
||||
gitRepositoryRepository.findByUrl(repositoryUrl),
|
||||
branchName
|
||||
);
|
||||
}
|
||||
@ -51,7 +51,7 @@ public class FilteringService {
|
||||
Pageable pageable) {
|
||||
return commitRepository.findByRepositoryAndBranch(
|
||||
pageable,
|
||||
repositoryRepository.findByUrl(repositoryUrl),
|
||||
gitRepositoryRepository.findByUrl(repositoryUrl),
|
||||
branchName,
|
||||
author,
|
||||
filter,
|
||||
|
@ -10,10 +10,13 @@ import org.eclipse.jgit.api.errors.GitAPIException;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import ru.ulstu.extractor.branch.BranchService;
|
||||
import ru.ulstu.extractor.gitrepository.GitRepositoryRepository;
|
||||
import ru.ulstu.extractor.gitrepository.GitRepositoryService;
|
||||
import ru.ulstu.extractor.model.Branch;
|
||||
import ru.ulstu.extractor.model.Commit;
|
||||
import ru.ulstu.extractor.model.Repository;
|
||||
import ru.ulstu.extractor.repository.RepositoryRepository;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
@ -24,21 +27,22 @@ public class IndexService {
|
||||
private final static Logger LOG = LoggerFactory.getLogger(IndexService.class);
|
||||
private final static int COMMITS_PAGE_SIZE = 10;
|
||||
private final GitRepositoryService gitRepositoryService;
|
||||
private final RepositoryRepository repositoryRepository;
|
||||
private final GitRepositoryRepository gitRepositoryRepository;
|
||||
private final BranchService branchService;
|
||||
|
||||
public IndexService(GitRepositoryService gitRepositoryService,
|
||||
RepositoryRepository repositoryRepository,
|
||||
GitRepositoryRepository gitRepositoryRepository,
|
||||
BranchService branchService) {
|
||||
this.gitRepositoryService = gitRepositoryService;
|
||||
this.repositoryRepository = repositoryRepository;
|
||||
this.gitRepositoryRepository = gitRepositoryRepository;
|
||||
this.branchService = branchService;
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void index(@NotNull String repositoryUrl, @NotNull String branchName) throws GitAPIException, IOException {
|
||||
Repository repository = repositoryRepository.findByUrl(repositoryUrl);
|
||||
Repository repository = gitRepositoryRepository.findByUrl(repositoryUrl);
|
||||
if (repository == null) {
|
||||
repository = repositoryRepository.save(new Repository(repositoryUrl));
|
||||
repository = gitRepositoryRepository.save(new Repository(repositoryUrl));
|
||||
}
|
||||
Branch branch = branchService.findByRepositoryAndName(repository, branchName);
|
||||
if (branch == null) {
|
||||
|
@ -64,10 +64,10 @@ public class TimeSeriesService {
|
||||
TimeSeries timeSeries = findOrCreate(timeSeriesName);
|
||||
timeSeriesValueRepository.save(new TimeSeriesValue(timeSeries, date, value));
|
||||
}
|
||||
|
||||
public TimeSeriesValue findByTimeSeriesAndName(TimeSeries timeSeries, String name) {
|
||||
return timeSeriesValueRepository.findByTimeSeriesAndName(timeSeries, name);
|
||||
}
|
||||
//
|
||||
// public TimeSeriesValue findByTimeSeriesAndName(TimeSeries timeSeries, String name) {
|
||||
// return timeSeriesValueRepository.findByTimeSeriesAndName(timeSeries, name);
|
||||
// }
|
||||
|
||||
public List<TimeSeriesValue> findAll() {
|
||||
return timeSeriesValueRepository.findAll();
|
||||
|
@ -1,22 +1,21 @@
|
||||
package ru.ulstu.extractor.ts;
|
||||
|
||||
import ru.ulstu.extractor.model.TimeSeriesValue;
|
||||
import ru.ulstu.extractor.service.TimeSeriesService;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Date;
|
||||
|
||||
public abstract class AbstractTSExtractor {
|
||||
|
||||
public abstract String getTSName();
|
||||
|
||||
public abstract int getNewTSValue(Integer repositoryId, String branchName);
|
||||
|
||||
public abstract TimeSeriesService getTimeSeriesService();
|
||||
|
||||
public void addPoint(int value) {
|
||||
public void addPoint(Integer repositoryId, String branchName) {
|
||||
getTimeSeriesService().addTimeSeriesValue(
|
||||
String.format("%s %s %s", getTSName(), repositoryId, branchName),
|
||||
new Date(),
|
||||
getNewTSValue(repositoryId, branchName));
|
||||
}
|
||||
|
||||
public void addTS(List<TimeSeriesValue> values) {
|
||||
getTimeSeriesService().findOrCreate(getTSName());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -1,14 +1,18 @@
|
||||
package ru.ulstu.extractor.ts;
|
||||
|
||||
import org.springframework.stereotype.Component;
|
||||
import ru.ulstu.extractor.branch.BranchService;
|
||||
import ru.ulstu.extractor.service.TimeSeriesService;
|
||||
|
||||
@Component
|
||||
public class CommitsTS extends AbstractTSExtractor {
|
||||
private final TimeSeriesService timeSeriesService;
|
||||
private final BranchService branchService;
|
||||
|
||||
public CommitsTS(TimeSeriesService timeSeriesService) {
|
||||
public CommitsTS(TimeSeriesService timeSeriesService,
|
||||
BranchService branchService) {
|
||||
this.timeSeriesService = timeSeriesService;
|
||||
this.branchService = branchService;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -16,6 +20,11 @@ public class CommitsTS extends AbstractTSExtractor {
|
||||
return "Количество коммитов во времени";
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getNewTSValue(Integer repositoryId, String branchName) {
|
||||
return branchService.getCommitsCount(repositoryId, branchName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TimeSeriesService getTimeSeriesService() {
|
||||
return timeSeriesService;
|
||||
|
Loading…
Reference in New Issue
Block a user