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);
}
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)));
}
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;
}
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);
}
}
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"));
}
Aggregations