Search in sources :

Example 1 with LastViewedAssociation

use of uk.ac.ebi.spot.goci.curation.model.LastViewedAssociation in project goci by EBISPOT.

the class AssociationControllerTest method viewStudySnps.

@Test
public void viewStudySnps() throws Exception {
    SnpAssociationTableView snpAssociationTableView = new SnpAssociationTableView();
    LastViewedAssociation lastViewedAssociation = new LastViewedAssociation();
    Pageable pagination = new PageRequest(0, 100);
    List<Association> list = new ArrayList<Association>();
    list.add(ASSOCIATION);
    Page<Association> returnPage = new PageImpl<Association>(list, pagination, list.size());
    when(associationRepository.findByStudyId(STUDY.getId(), pagination)).thenReturn(returnPage);
    when(snpAssociationTableViewService.createSnpAssociationTableView(ASSOCIATION)).thenReturn(snpAssociationTableView);
    when(associationOperationsService.getLastViewedAssociation(Matchers.anyLong())).thenReturn(lastViewedAssociation);
    when(studyRepository.findOne(Matchers.anyLong())).thenReturn(STUDY);
    mockMvc.perform(get("/studies/1234/associations").accept(MediaType.TEXT_HTML_VALUE)).andExpect(status().isOk()).andExpect(model().attribute("snpAssociationTableViews", hasSize(1))).andExpect(model().attribute("snpAssociationTableViews", instanceOf(Collection.class))).andExpect(model().attribute("lastViewedAssociation", instanceOf(LastViewedAssociation.class))).andExpect(model().attribute("totalAssociations", 1L)).andExpect(model().attributeExists("study")).andExpect(view().name("study_association"));
    verify(associationRepository, times(1)).findByStudyId(STUDY.getId(), pagination);
    verify(snpAssociationTableViewService, times(1)).createSnpAssociationTableView(ASSOCIATION);
    verify(associationOperationsService, times(1)).getLastViewedAssociation(Matchers.anyLong());
    verify(studyRepository, times(1)).findOne(Matchers.anyLong());
}
Also used : PageImpl(org.springframework.data.domain.PageImpl) LastViewedAssociation(uk.ac.ebi.spot.goci.curation.model.LastViewedAssociation) PageRequest(org.springframework.data.domain.PageRequest) Pageable(org.springframework.data.domain.Pageable) LastViewedAssociation(uk.ac.ebi.spot.goci.curation.model.LastViewedAssociation) Association(uk.ac.ebi.spot.goci.model.Association) ArrayList(java.util.ArrayList) SnpAssociationTableView(uk.ac.ebi.spot.goci.curation.model.SnpAssociationTableView) Test(org.junit.Test)

Example 2 with LastViewedAssociation

use of uk.ac.ebi.spot.goci.curation.model.LastViewedAssociation in project goci by EBISPOT.

the class AssociationController method viewStudySnps.

/*  Study SNP/Associations */
// Generate list of SNP associations linked to a study
@RequestMapping(value = "/studies/{studyId}/associations", produces = MediaType.TEXT_HTML_VALUE, method = RequestMethod.GET)
public String viewStudySnps(Model model, @PathVariable Long studyId, @RequestParam(required = false) Long associationId) {
    // Get all associations for a study
    Collection<Association> associations = associationRepository.findByStudyId(studyId);
    // For our associations create a table view object and return
    Collection<SnpAssociationTableView> snpAssociationTableViews = new ArrayList<SnpAssociationTableView>();
    for (Association association : associations) {
        SnpAssociationTableView snpAssociationTableView = snpAssociationTableViewService.createSnpAssociationTableView(association);
        snpAssociationTableViews.add(snpAssociationTableView);
    }
    model.addAttribute("snpAssociationTableViews", snpAssociationTableViews);
    // Determine last viewed association
    LastViewedAssociation lastViewedAssociation = associationOperationsService.getLastViewedAssociation(associationId);
    model.addAttribute("lastViewedAssociation", lastViewedAssociation);
    // Pass back count of associations
    Integer totalAssociations = associations.size();
    model.addAttribute("totalAssociations", totalAssociations);
    // Also passes back study object to view so we can create links back to main study page
    model.addAttribute("study", studyRepository.findOne(studyId));
    return "study_association";
}
Also used : LastViewedAssociation(uk.ac.ebi.spot.goci.curation.model.LastViewedAssociation) LastViewedAssociation(uk.ac.ebi.spot.goci.curation.model.LastViewedAssociation) SnpAssociationTableView(uk.ac.ebi.spot.goci.curation.model.SnpAssociationTableView)

Example 3 with LastViewedAssociation

use of uk.ac.ebi.spot.goci.curation.model.LastViewedAssociation in project goci by EBISPOT.

the class AssociationController method viewStudySnps.

/*  Study SNP/Associations */
// Generate list of SNP associations linked to a study
@RequestMapping(value = "/studies/{studyId}/associations", produces = MediaType.TEXT_HTML_VALUE, method = RequestMethod.GET)
public String viewStudySnps(Model model, @PathVariable Long studyId, @RequestParam(required = false) Long associationId, @RequestParam(defaultValue = "1", required = false) Integer page) {
    // Get all associations for a study - ORIGINAL
    // Collection<Association> associations = associationRepository.findByStudyId(studyId);
    // Get pages of associations
    Page<Association> associations = associationRepository.findByStudyId(studyId, constructPageSpecification(page - 1));
    // For our associations create a table view object and return
    Collection<SnpAssociationTableView> snpAssociationTableViews = new ArrayList<SnpAssociationTableView>();
    for (Association association : associations) {
        SnpAssociationTableView snpAssociationTableView = snpAssociationTableViewService.createSnpAssociationTableView(association);
        snpAssociationTableViews.add(snpAssociationTableView);
    }
    model.addAttribute("snpAssociationTableViews", snpAssociationTableViews);
    // Determine last viewed association
    LastViewedAssociation lastViewedAssociation = associationOperationsService.getLastViewedAssociation(associationId);
    model.addAttribute("lastViewedAssociation", lastViewedAssociation);
    // Pass back count of associations
    // Integer totalAssociations = associations.size();
    long totalAssociations;
    totalAssociations = associations.getTotalElements();
    model.addAttribute("totalAssociations", totalAssociations);
    // Also passes back study object to view so we can create links back to main study page
    model.addAttribute("study", studyRepository.findOne(studyId));
    if (page == 1) {
        return "study_association";
    } else {
        return "study_association_by_page";
    }
}
Also used : LastViewedAssociation(uk.ac.ebi.spot.goci.curation.model.LastViewedAssociation) LastViewedAssociation(uk.ac.ebi.spot.goci.curation.model.LastViewedAssociation) SnpAssociationTableView(uk.ac.ebi.spot.goci.curation.model.SnpAssociationTableView) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

LastViewedAssociation (uk.ac.ebi.spot.goci.curation.model.LastViewedAssociation)3 SnpAssociationTableView (uk.ac.ebi.spot.goci.curation.model.SnpAssociationTableView)3 ArrayList (java.util.ArrayList)1 Test (org.junit.Test)1 PageImpl (org.springframework.data.domain.PageImpl)1 PageRequest (org.springframework.data.domain.PageRequest)1 Pageable (org.springframework.data.domain.Pageable)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 Association (uk.ac.ebi.spot.goci.model.Association)1