@ -8,7 +8,6 @@ package ru.ulstu.extractor.controller;
import org.springframework.data.domain.Page ;
import org.springframework.data.domain.Page ;
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.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.bind.annotation.RequestParam ;
import org.springframework.web.bind.annotation.RequestParam ;
@ -36,16 +35,22 @@ public class GitFilteringController {
@RequestMapping ( value = FILTER_COMMITS , method = RequestMethod . GET )
@RequestMapping ( value = FILTER_COMMITS , method = RequestMethod . GET )
public String listCommits (
public String listCommits (
Model model ,
Model model ,
@ModelAttribute FilterForm filterForm ,
@RequestParam Optional < Integer > page ,
@RequestParam ( "page" ) Optional < Integer > page ,
@RequestParam Optional < Integer > size ,
@RequestParam ( "size" ) Optional < Integer > size ,
@RequestParam Optional < String > repositoryUrl ,
@RequestParam String repositoryUrl ,
@RequestParam Optional < String > branchName ,
@RequestParam String branchName ) {
@RequestParam Optional < String > author ,
@RequestParam Optional < String > filter ) {
int currentPage = page . orElse ( 1 ) ;
int currentPage = page . orElse ( 1 ) ;
int pageSize = size . orElse ( DEFAULT_PAGE_SIZE ) ;
int pageSize = size . orElse ( DEFAULT_PAGE_SIZE ) ;
Page < Commit > commitsPage = filteringService . getCommits ( repositoryUrl ,
String notEmptyRepositoryUrl = repositoryUrl . orElseThrow ( ( ) - > new RuntimeException ( "Url repository not present" ) ) ;
branchName ,
String notEmptyBranchName = branchName . orElseThrow ( ( ) - > new RuntimeException ( "Branch name not present" ) ) ;
Page < Commit > commitsPage = filteringService . getCommits ( notEmptyRepositoryUrl ,
notEmptyBranchName ,
author . orElse ( null ) ,
filter . 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 ) {
@ -54,11 +59,17 @@ public class GitFilteringController {
. collect ( Collectors . toList ( ) ) ;
. collect ( Collectors . toList ( ) ) ;
model . addAttribute ( "pageNumbers" , pageNumbers ) ;
model . addAttribute ( "pageNumbers" , pageNumbers ) ;
}
}
FilterForm filterForm = new FilterForm ( ) ;
filterForm . setCommitsPage ( commitsPage ) ;
filterForm . setCommitsPage ( commitsPage ) ;
filterForm . setBranch ( branchName ) ;
filterForm . setBranchName ( notEmptyBranchName ) ;
filterForm . setUrl ( repositoryUrl ) ;
filterForm . setRepositoryUrl ( notEmptyRepositoryUrl ) ;
filterForm . setAuthor ( author . orElse ( null ) ) ;
filterForm . setFilter ( filter . orElse ( null ) ) ;
model . addAttribute ( "filterForm" , filterForm ) ;
model . addAttribute ( "filterForm" , filterForm ) ;
model . addAttribute ( "authors" , filteringService . getRepositoryAuthors ( repositoryUrl , branchName ) ) ;
model . addAttribute ( "authors" , filteringService . getRepositoryAuthors (
notEmptyRepositoryUrl ,
notEmptyBranchName
) ) ;
return FILTER_COMMITS ;
return FILTER_COMMITS ;
}
}
}
}