goci-interfaces/goci-curation/src/main/java/uk/ac/ebi/spot/goci/curation/controller/StudyController.java
/* All studies and various filtered lists */
All studies and various filtered lists
All studies and various filtered lists
@RequestMapping(produces = MediaType.TEXT_HTML_VALUE, method = RequestMethod.GET)
    public String allStudiesPage(Model model,
                                 @RequestParam(required = false) Integer page,
                                 @RequestParam(required = false) String pubmed,
                                 @RequestParam(required = false) String author,
                                 @RequestParam(value = "studytype", required = false) String studyType,
                                 @RequestParam(value = "efotraitid", required = false) Long efoTraitId,
                                 @RequestParam(value = "notesquery", required = false) String notesQuery,
                                 @RequestParam(required = false) String gcstId,
                                 @RequestParam(required = false) String studyId,
                                 @RequestParam(required = false) Long status,
                                 @RequestParam(required = false) Long curator,
                                 @RequestParam(value = "sorttype", required = false) String sortType,
                                 @RequestParam(value = "diseasetraitid", required = false) Long diseaseTraitId,
                                 @RequestParam(required = false) Integer year,
                                 @RequestParam(required = false) Integer month) {
        model.addAttribute("baseUrl", depositionUiURL);
        Boolean pagination = true;
        if (page == null) {
            return "redirect:/studies?page=1";
        }
        StudyViewDto studyViewDto =
                studyOperationsService.getStudies(page, studyType, sortType, pubmed, author, pagination, efoTraitId,
                                                  diseaseTraitId, notesQuery, status, curator, month, year, gcstId, studyId);
        String filters = studyViewDto.getFilters();
        String sortString = studyViewDto.getSortString();
        List<Study> studies = studyViewDto.getStudies();
        Page<Study> studyPage = studyViewDto.getStudyPage();
        StudySearchFilter studySearchFilter = studyViewDto.getStudySearchFilter();
        String uri = "/studies?page=1";
        String downloadUrl = String.format("%s%s/export?page=all", Endpoint.API_V1, Endpoint.STUDIES);
        if (!filters.isEmpty()) {
            uri = uri + filters;
            downloadUrl += filters;
        }
        model.addAttribute("uri", uri);
        model.addAttribute("downloadUrl", downloadUrl);
        if (!filters.isEmpty()) {
            if (!sortString.isEmpty()) {
                filters = filters + sortString;
            }
        }
        else {
            if (!sortString.isEmpty()) {
                filters = sortString;
            }
        }
        model.addAttribute("filters", filters);
        long totalStudies;
        int current = 1;
        if (studies == null) {
            model.addAttribute("studies", studyPage);
            totalStudies = studyPage.getTotalElements();
            current = studyPage.getNumber() + 1;
            int begin = Math.max(1, current - 5); 
            int end =
                    Math.min(begin + 10, studyPage.getTotalPages()); 
            model.addAttribute("beginIndex", begin);
            model.addAttribute("endIndex", end);
            model.addAttribute("currentIndex", current);
        }
        else {
            model.addAttribute("studies", studies);
            totalStudies = studies.size();
        }
        model.addAttribute("totalStudies", totalStudies);
        model.addAttribute("pagination", pagination);
        model.addAttribute("studySearchFilter", studySearchFilter);
        Assignee assignee = new Assignee();
        StatusAssignment statusAssignment = new StatusAssignment();
        assignee.setUri("/studies?page=" + current + filters);
        statusAssignment.setUri("/studies?page=" + current + filters);
        model.addAttribute("assignee", assignee);
        model.addAttribute("statusAssignment", statusAssignment);
        Map<String, String> pubmedMap = submissionService.getSubmissionPubMedIds();
        studyPage.forEach(study->{
            if(pubmedMap.containsKey(study.getPublicationId().getPubmedId())){
                study.getPublicationId().setActiveSubmission(true);
                study.getPublicationId().setSubmissionId(pubmedMap.get(study.getPublicationId().getPubmedId()));
            }
        });
        return "studies";
    }
@ RequestMapping ( produces = MediaType . TEXT_HTML_VALUE , method = RequestMethod . GET ) public String allStudiesPage ( Model model , @ RequestParam ( required = false ) Integer page , @ RequestParam ( required = false ) String pubmed , @ RequestParam ( required = false ) String author , @ RequestParam ( value = "studytype" , required = false ) String studyType , @ RequestParam ( value = "efotraitid" , required = false ) Long efoTraitId , @ RequestParam ( value = "notesquery" , required = false ) String notesQuery , @ RequestParam ( required = false ) String gcstId , @ RequestParam ( required = false ) String studyId , @ RequestParam ( required = false ) Long status , @ RequestParam ( required = false ) Long curator , @ RequestParam ( value = "sorttype" , required = false ) String sortType , @ RequestParam ( value = "diseasetraitid" , required = false ) Long diseaseTraitId , @ RequestParam ( required = false ) Integer year , @ RequestParam ( required = false ) Integer month ) { model . addAttribute ( "baseUrl" , depositionUiURL ) ; Boolean pagination = true ; if ( page == null ) { return "redirect:/studies?page=1" ; } StudyViewDto studyViewDto = studyOperationsService . getStudies ( page , studyType , sortType , pubmed , author , pagination , efoTraitId , diseaseTraitId , notesQuery , status , curator , month , year , gcstId , studyId ) ; String filters = studyViewDto . getFilters ( ) ; String sortString = studyViewDto . getSortString ( ) ; List < Study > studies = studyViewDto . getStudies ( ) ; Page < Study > studyPage = studyViewDto . getStudyPage ( ) ; StudySearchFilter studySearchFilter = studyViewDto . getStudySearchFilter ( ) ; String uri = "/studies?page=1" ; String downloadUrl = String . format ( "%s%s/export?page=all" , Endpoint . API_V1 , Endpoint . STUDIES ) ; if ( ! filters . isEmpty ( ) ) { uri = uri + filters ; downloadUrl += filters ; } model . addAttribute ( "uri" , uri ) ; model . addAttribute ( "downloadUrl" , downloadUrl ) ; if ( ! filters . isEmpty ( ) ) { if ( ! sortString . isEmpty ( ) ) { filters = filters + sortString ; } } else { if ( ! sortString . isEmpty ( ) ) { filters = sortString ; } } model . addAttribute ( "filters" , filters ) ; long totalStudies ; int current = 1 ; if ( studies == null ) { model . addAttribute ( "studies" , studyPage ) ; totalStudies = studyPage . getTotalElements ( ) ; current = studyPage . getNumber ( ) + 1 ; int begin = Math . max ( 1 , current - 5 ) ; int end = Math . min ( begin + 10 , studyPage . getTotalPages ( ) ) ; model . addAttribute ( "beginIndex" , begin ) ; model . addAttribute ( "endIndex" , end ) ; model . addAttribute ( "currentIndex" , current ) ; } else { model . addAttribute ( "studies" , studies ) ; totalStudies = studies . size ( ) ; } model . addAttribute ( "totalStudies" , totalStudies ) ; model . addAttribute ( "pagination" , pagination ) ; model . addAttribute ( "studySearchFilter" , studySearchFilter ) ; Assignee assignee = new Assignee ( ) ; StatusAssignment statusAssignment = new StatusAssignment ( ) ; assignee . setUri ( "/studies?page=" + current + filters ) ; statusAssignment . setUri ( "/studies?page=" + current + filters ) ; model . addAttribute ( "assignee" , assignee ) ; model . addAttribute ( "statusAssignment" , statusAssignment ) ; Map < String , String > pubmedMap = submissionService . getSubmissionPubMedIds ( ) ; studyPage . forEach ( study -> { if ( pubmedMap . containsKey ( study . getPublicationId ( ) . getPubmedId ( ) ) ) { study . getPublicationId ( ) . setActiveSubmission ( true ) ; study . getPublicationId ( ) . setSubmissionId ( pubmedMap . get ( study . getPublicationId ( ) . getPubmedId ( ) ) ) ; } } ) ; return "studies" ; }
All studies and various filtered lists
All studies and various filtered lists
// This is passed back to model and determines if pagination is applied // Return study page and filters, filters will be used by pagination bar // If user has just sorted without any filter we need to pass this back to pagination bar // Construct table using pagination //Pagination variables // Returns the greater of two values // how many pages to display in the pagination bar // Add studySearchFilter to model so user can filter table // Add assignee and status assignment so user can assign study to curator or assign a status. Also set uri so we can redirect to page user was on