@ -8,7 +8,6 @@ package ru.ulstu.extractor.controller;
import org.springframework.data.domain.Page ;
import org.springframework.stereotype.Controller ;
import org.springframework.ui.Model ;
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.bind.annotation.RequestParam ;
@ -34,21 +33,23 @@ public class GitFilteringController {
this . filteringService = filteringService ;
}
@RequestMapping ( value = FILTER_COMMITS , method = RequestMethod . GET )
@RequestMapping ( value = FILTER_COMMITS , method = { RequestMethod . GET , RequestMethod . POST } )
public String listCommits (
Model model ,
@ ModelAttribute FilterForm filterForm ,
@RequestParam ( "page" ) Optional < Integer > pag e,
@RequestParam ( "size" ) Optional < Integer > size ,
@RequestParam String repositoryUrl ,
@RequestParam String branchName ) {
@ RequestParam Optional < Integer > page ,
@RequestParam Optional < Integer > siz e,
@RequestParam Optional < String > repositoryUrl ,
@RequestParam Optional< String> b ranchNam e,
@RequestParam Optional< String > author ) {
int currentPage = page . orElse ( 1 ) ;
int pageSize = size . orElse ( DEFAULT_PAGE_SIZE ) ;
String author = "Anton Romanov" ;
Page < Commit > commitsPage = filteringService . getCommits ( repositoryUrl ,
branchName ,
author ,
String notEmptyRepositoryUrl = repositoryUrl . orElseThrow ( ( ) - > new RuntimeException ( "Url repository not present" ) ) ;
String notEmptyBranchName = branchName . orElseThrow ( ( ) - > new RuntimeException ( "Branch name not present" ) ) ;
Page < Commit > commitsPage = filteringService . getCommits ( notEmptyRepositoryUrl ,
notEmptyBranchName ,
author . orElse ( null ) ,
new OffsetablePageRequest ( currentPage - 1 , pageSize ) ) ;
int totalPages = commitsPage . getTotalPages ( ) ;
if ( totalPages > 0 ) {
@ -57,31 +58,16 @@ public class GitFilteringController {
. collect ( Collectors . toList ( ) ) ;
model . addAttribute ( "pageNumbers" , pageNumbers ) ;
}
FilterForm filterForm = new FilterForm ( ) ;
filterForm . setCommitsPage ( commitsPage ) ;
filterForm . setBranch ( branchName ) ;
filterForm . setUrl ( repositoryUrl ) ;
filterForm . setBranchName ( notEmptyBranchName ) ;
filterForm . setRepositoryUrl ( notEmptyRepositoryUrl ) ;
filterForm . setAuthor ( author . orElse ( null ) ) ;
model . addAttribute ( "filterForm" , filterForm ) ;
model . addAttribute ( "authors" , filteringService . getRepositoryAuthors ( repositoryUrl , branchName ) ) ;
model . addAttribute ( "authors" , filteringService . getRepositoryAuthors (
notEmptyRepositoryUrl ,
notEmptyBranchName
) ) ;
return FILTER_COMMITS ;
}
// @RequestMapping(value = FILTER_COMMITS, method = RequestMethod.POST)
// public ModelAndView listFilterCommits(
// Model model,
// @ModelAttribute FilterForm filterForm) {
// Page<Commit> commitsPage = filteringService.getCommits(filterForm.getUrl(),
// filterForm.getBranch(),
// new OffsetablePageRequest(0, DEFAULT_PAGE_SIZE));
// int totalPages = commitsPage.getTotalPages();
// if (totalPages > 0) {
// List<Integer> pageNumbers = IntStream.rangeClosed(1, totalPages)
// .boxed()
// .collect(Collectors.toList());
// model.addAttribute("pageNumbers", pageNumbers);
// }
// filterForm.setCommitsPage(commitsPage);
// model.addAttribute("filterForm", filterForm);
// model.addAttribute("authors", filteringService.getRepositoryAuthors(filterForm.getUrl(), filterForm.getBranch()));
// return new ModelAndView()FILTER_COMMITS + "?repositoryUrl="+filterForm.getUrl() + "&branchName=" +filterForm.getBranch() ;
// }
}