Search in sources :

Example 1 with Ancestry

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

the class StudyDeletionService method deleteStudy.

/**
     * Delete a study
     *
     * @param study Study to delete
     * @param user  User
     */
public void deleteStudy(Study study, SecureUser user) {
    getLog().warn("Deleting study: ".concat(String.valueOf(study.getId())));
    // Before we delete the study get its associated ancestry
    Collection<Ancestry> ancestriesAttachedToStudy = ancestryRepository.findByStudyId(study.getId());
    // Delete ancestry information linked to this study
    for (Ancestry ancestry : ancestriesAttachedToStudy) {
        ancestryRepository.delete(ancestry);
    }
    // WeeklyTracking, CuratorTracking and Note. Please use this method!
    // Shared with === DataDeletionService ===
    studyService.deleteRelatedInfoByStudy(study);
    // Add deletion event
    trackingOperationService.delete(study, user);
    DeletedStudy deletedStudy = createDeletedStudy(study);
    // Delete study
    studyRepository.delete(study);
    // Save deleted study details
    getLog().info("Saving details of deleted study: ".concat(String.valueOf(deletedStudy.getId())));
    deletedStudyRepository.save(deletedStudy);
}
Also used : DeletedStudy(uk.ac.ebi.spot.goci.model.DeletedStudy) Ancestry(uk.ac.ebi.spot.goci.model.Ancestry)

Example 2 with Ancestry

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

the class PrintControllerTest method viewPrintableDetailsOfStudy.

@Test
public void viewPrintableDetailsOfStudy() throws Exception {
    // Set up some basic views
    SnpAssociationTableView snpAssociationTableView1 = new SnpAssociationTableView();
    snpAssociationTableView1.setBetaNum((float) 0.012);
    SnpAssociationTableView snpAssociationTableView2 = new SnpAssociationTableView();
    snpAssociationTableView1.setOrPerCopyNum((float) 5.97);
    // Stub
    when(studyRepository.findOne(STUDY.getId())).thenReturn(STUDY);
    Collection<Ancestry> initialStudyAncestryDescriptions = new ArrayList<>();
    Collection<Ancestry> replicationStudyAncestryDescriptions = new ArrayList<>();
    initialStudyAncestryDescriptions.add(ETH1);
    replicationStudyAncestryDescriptions.add(ETH2);
    replicationStudyAncestryDescriptions.add(ETH3);
    when(ancestryRepository.findByStudyIdAndType(STUDY.getId(), "initial")).thenReturn(initialStudyAncestryDescriptions);
    when(ancestryRepository.findByStudyIdAndType(STUDY.getId(), "replication")).thenReturn(replicationStudyAncestryDescriptions);
    when(studyPrintService.generatePrintView(STUDY.getId())).thenReturn(Arrays.asList(snpAssociationTableView1, snpAssociationTableView2));
    MvcResult mvcResult = this.mockMvc.perform(get("/studies/101/printview").accept(MediaType.TEXT_HTML_VALUE)).andExpect(request().asyncStarted()).andExpect(request().asyncResult("study_printview")).andReturn();
    this.mockMvc.perform(asyncDispatch(mvcResult)).andExpect(status().isOk()).andExpect(forwardedUrl("study_printview")).andExpect(model().attributeExists("studiesToPrint")).andExpect(model().attribute("studiesToPrint", instanceOf(Hashtable.class)));
}
Also used : ArrayList(java.util.ArrayList) Ancestry(uk.ac.ebi.spot.goci.model.Ancestry) MvcResult(org.springframework.test.web.servlet.MvcResult) SnpAssociationTableView(uk.ac.ebi.spot.goci.curation.model.SnpAssociationTableView) Test(org.junit.Test)

Example 3 with Ancestry

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

the class AncestryEventsViewService method createViews.

@Override
public List<EventView> createViews(Long studyId) {
    List<EventView> views = new ArrayList<>();
    Collection<Ancestry> ancestryCollection = ancestryRepository.findByStudyId(studyId);
    List<DeletedAncestry> deletedAncestryCollection = deletedAncestryRepository.findByStudyId(studyId);
    if (!ancestryCollection.isEmpty()) {
        ancestryCollection.forEach(ancestry -> {
            ancestry.getEvents().forEach(event -> {
                String eventName = eventTypeService.translateEventByEventType(event.getEventType());
                EventView eventView = new AncestryEventView(eventName, event.getEventDate(), ancestry.getId(), event.getUser().getEmail(), createAncestrySummary(ancestry));
                views.add(eventView);
            });
        });
    }
    return views;
}
Also used : ArrayList(java.util.ArrayList) DeletedAncestry(uk.ac.ebi.spot.goci.model.DeletedAncestry) Ancestry(uk.ac.ebi.spot.goci.model.Ancestry) DeletedAncestry(uk.ac.ebi.spot.goci.model.DeletedAncestry) AncestryEventView(uk.ac.ebi.spot.goci.curation.model.AncestryEventView) AncestryEventView(uk.ac.ebi.spot.goci.curation.model.AncestryEventView) EventView(uk.ac.ebi.spot.goci.curation.model.EventView)

Example 4 with Ancestry

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

the class DataDeletionService method deleteStudy.

private void deleteStudy(Study study) {
    System.out.println("Removing study \t" + study.getPublicationId().getFirstAuthor().getFullname() + "\t (ID:" + study.getId() + ") with \t" + study.getAssociations().size() + "\t association and \t" + study.getAncestries().size() + "\t ancestries");
    getLog().debug("Removing study \t" + study.getPublicationId().getFirstAuthor().getFullname() + "\t (ID:" + study.getId() + ") with \t" + study.getAssociations().size() + "\t association and \t" + study.getAncestries().size() + "\t ancestries");
    // THOR - Don't delete the publication and Author - OR check if there is just a publication.
    Long publicationId = study.getPublicationId().getId();
    study.setPublicationId(null);
    studyService.setPublicationIdNull(study.getId());
    Collection<Association> associations = study.getAssociations();
    associations.forEach(this::deleteAssociation);
    Collection<Ancestry> ancestries = ancestryRepository.findByStudyId(study.getId());
    for (Ancestry ancestry : ancestries) {
        ancestryRepository.delete(ancestry);
    }
    // WeeklyTracking, CuratorTracking and Note. Please use this method!
    // Shared with === DataDeletionService ===
    studyService.deleteRelatedInfoByStudy(study);
    // Delete study
    studyService.deleteByStudyId(study.getId());
    // THOR - delete the publication if there are no studies related
    Publication publication = publicationService.deepFindPublicationbyId(publicationId);
    if (publication.getStudies().size() == 0) {
        publicationAuthorsService.deleteByPublication(publication);
        Boolean delete = publicationService.deletePublication(publication);
    }
}
Also used : Association(uk.ac.ebi.spot.goci.model.Association) Ancestry(uk.ac.ebi.spot.goci.model.Ancestry) Publication(uk.ac.ebi.spot.goci.model.Publication)

Example 5 with Ancestry

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

the class StudyDuplicationServiceTest method duplicateStudy.

@Test
public void duplicateStudy() throws Exception {
    // Stubbing
    when(housekeepingOperationsService.createHousekeeping()).thenReturn(NEW_HOUSEKEEPING);
    when(ancestryRepository.findByStudyId(STUDY_TO_DUPLICATE.getId())).thenReturn(Arrays.asList(ETH1, ETH2));
    Study duplicateStudy = studyDuplicationService.duplicateStudy(STUDY_TO_DUPLICATE, SECURE_USER);
    // Verification
    verify(studyTrackingOperationService, times(1)).update(STUDY_TO_DUPLICATE, SECURE_USER, "STUDY_DUPLICATION");
    verify(studyRepository, times(1)).save(STUDY_TO_DUPLICATE);
    verify(studyTrackingOperationService, times(1)).create(duplicateStudy, SECURE_USER);
    verify(housekeepingOperationsService, times(1)).createHousekeeping();
    verify(ancestryRepository, times(1)).findByStudyId(STUDY_TO_DUPLICATE.getId());
    verify(ancestryRepository, times(2)).save(Matchers.any(Ancestry.class));
    verify(housekeepingOperationsService, times(1)).saveHousekeeping(duplicateStudy, duplicateStudy.getHousekeeping());
    // Assertions;
    assertThat(duplicateStudy).isEqualToIgnoringGivenFields(STUDY_TO_DUPLICATE, "housekeeping", "ancestries", "id", "author", "notes");
    assertEquals(duplicateStudy.getNotes().size(), 1);
    assertThat(duplicateStudy.getAuthor()).isEqualTo(STUDY_TO_DUPLICATE.getAuthor().concat(" DUP"));
    assertThat(duplicateStudy.getId()).isNotEqualTo(STUDY_TO_DUPLICATE.getId());
    assertThat(duplicateStudy.getHousekeeping().getStudyAddedDate()).isToday();
    /// Check ancestry
    assertThat(duplicateStudy.getAncestries()).extracting("id", "numberOfIndividuals", //                                                              "ancestralGroup",
    "description", //                                                               "countryOfRecruitment",
    "type").contains(tuple(null, 100, //                                "European",
    "ETH1 description", //                                "Ireland", "Ireland",
    "initial"), tuple(null, 200, //                                "European",
    "ETH2 description", //                                "U.K.", "U.K.",
    "replication"));
}
Also used : Study(uk.ac.ebi.spot.goci.model.Study) Ancestry(uk.ac.ebi.spot.goci.model.Ancestry) Test(org.junit.Test)

Aggregations

Ancestry (uk.ac.ebi.spot.goci.model.Ancestry)10 ArrayList (java.util.ArrayList)3 DeletedAncestry (uk.ac.ebi.spot.goci.model.DeletedAncestry)3 Study (uk.ac.ebi.spot.goci.model.Study)3 Test (org.junit.Test)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 AncestryEventView (uk.ac.ebi.spot.goci.curation.model.AncestryEventView)2 EventView (uk.ac.ebi.spot.goci.curation.model.EventView)2 Collection (java.util.Collection)1 List (java.util.List)1 StringJoiner (java.util.StringJoiner)1 Collectors (java.util.stream.Collectors)1 Autowired (org.springframework.beans.factory.annotation.Autowired)1 Service (org.springframework.stereotype.Service)1 MvcResult (org.springframework.test.web.servlet.MvcResult)1 InitialSampleDescription (uk.ac.ebi.spot.goci.curation.model.InitialSampleDescription)1 ReplicationSampleDescription (uk.ac.ebi.spot.goci.curation.model.ReplicationSampleDescription)1 SnpAssociationTableView (uk.ac.ebi.spot.goci.curation.model.SnpAssociationTableView)1 AncestralGroup (uk.ac.ebi.spot.goci.model.AncestralGroup)1 Association (uk.ac.ebi.spot.goci.model.Association)1