use of uk.ac.ebi.spot.goci.model.Study in project goci by EBISPOT.
the class StudyOperationServiceTest method testCreateStudy.
@Test
public void testCreateStudy() {
// Stubbing
when(housekeepingOperationsService.createHousekeeping()).thenReturn(NEW_HOUSEKEEPING);
// Test creating a study
Study study = studyOperationsService.createStudy(NEW_STUDY, SECURE_USER);
verify(trackingOperationService, times(1)).create(NEW_STUDY, SECURE_USER);
verify(studyRepository, times(1)).save(NEW_STUDY);
assertThat(study).extracting("author", "title", "publication", "pubmedId").contains("Smith X", "Test", "Nature", "1001002");
assertThat(study.getPublicationDate()).isToday();
assertThat(study.getHousekeeping().getStudyAddedDate()).isToday();
assertThat(study.getHousekeeping().getCurationStatus()).extracting("status").contains("Awaiting Curation");
assertThat(study.getHousekeeping().getCurator()).extracting("lastName").contains("Level 1 Curator");
}
use of uk.ac.ebi.spot.goci.model.Study in project goci by EBISPOT.
the class StudyOperationServiceTest method testUnpublishStudy.
@Test
public void testUnpublishStudy() {
// Create clones of our study/housekeeping before the method runs
Housekeeping housekeepingBeforeUnpublish = new HousekeepingBuilder().setId(799L).setCurationStatus(AWAITING_CURATION).setCurator(UNASSIGNED).build();
Study beforeUnPublish = new StudyBuilder().setId(802L).setHousekeeping(housekeepingBeforeUnpublish).build();
// Stubbing
when(studyRepository.findOne(STU1.getId())).thenReturn(STU1);
when(housekeepingRepository.findOne(STU1.getHousekeeping().getId())).thenReturn(STU1.getHousekeeping());
when(curationStatusRepository.findByStatus("Unpublished from catalog")).thenReturn(UNPUBLISH);
when(eventTypeService.determineEventTypeFromStatus(UNPUBLISH)).thenReturn("STUDY_STATUS_CHANGE_UNPUBLISHED_FROM_CATALOG");
studyOperationsService.unpublishStudy(STU1.getId(), Matchers.any(UnpublishReason.class), SECURE_USER);
verify(studyRepository, times(1)).findOne(STU1.getId());
verify(housekeepingRepository, times(1)).findOne(STU1.getHousekeeping().getId());
verify(curationStatusRepository, times(1)).findByStatus("Unpublished from catalog");
verify(eventTypeService, times(1)).determineEventTypeFromStatus(STU1.getHousekeeping().getCurationStatus());
verify(trackingOperationService, times(1)).update(STU1, SECURE_USER, "STUDY_STATUS_CHANGE_UNPUBLISHED_FROM_CATALOG");
verify(studyRepository, times(1)).save(STU1);
verifyZeroInteractions(mailService);
verifyZeroInteractions(publishStudyCheckService);
verifyZeroInteractions(associationRepository);
// Check housekeeping was saved
assertThat(STU1).isEqualToIgnoringGivenFields(beforeUnPublish, "housekeeping");
assertThat(STU1.getHousekeeping()).isEqualToIgnoringGivenFields(housekeepingBeforeUnpublish, "catalogUnpublishDate", "lastUpdateDate", "curationStatus");
assertThat(STU1.getHousekeeping().getCurationStatus()).extracting("status").contains("Unpublished from catalog");
assertThat(STU1.getHousekeeping().getCatalogUnpublishDate()).isToday();
}
use of uk.ac.ebi.spot.goci.model.Study in project goci by EBISPOT.
the class TestFiltering method testFilter.
@Test
public void testFilter() {
SingleNucleotidePolymorphism template = template(SingleNucleotidePolymorphism.class);
Filter<SingleNucleotidePolymorphism, String> filter = refine(template).on(template.getRsId()).hasValue("rs123456");
assertEquals("Filter type does not match expected", SingleNucleotidePolymorphism.class, filter.getFilteredType());
assertEquals("Filtered method does not match expected", "getRsId", filter.getFilteredMethod().getName());
assertEquals("Filtered value does not match expected", "rs123456", filter.getFilteredValues().get(0));
Association template2 = template(Association.class);
Filter<Association, Float> filter2 = refine(template2).on(template2.getPvalueMantissa()).hasValue(Float.valueOf("10"));
assertEquals("Filter type does not match expected", Association.class, filter2.getFilteredType());
assertEquals("Filtered method does not match expected", "getPvalueMantissa", filter2.getFilteredMethod().getName());
assertEquals(Float.valueOf("10"), filter2.getFilteredValues().get(0), 0.0d);
DateFormat df1 = new SimpleDateFormat("yyyy-MM-dd");
DateFormat df2 = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.S");
Date from = null;
Date to = null;
try {
from = df1.parse("2005-01-01");
to = df1.parse("2010-01-01");
} catch (ParseException e) {
e.printStackTrace();
}
String fromValue = df2.format(from).toString();
String toValue = df2.format(to).toString();
System.out.println(fromValue);
System.out.println(toValue);
Study study = template(Study.class);
Filter dateFilter = refine(study).on(study.getPublicationDate()).hasRange(fromValue, toValue);
Filter dateFilter2 = refine(study).on(study.getPublicationDate()).hasRange(fromValue, toValue);
assertEquals("Filter type does not match expected", Study.class, dateFilter.getFilteredType());
assertEquals("Filtered method does not match expected", "getPublicationDate", dateFilter.getFilteredMethod().getName());
assertEquals("Filtered value does not match expected", "2010-01-01T00:00:00.0", dateFilter.getFilteredRange().to());
assertEquals("Hashcodes of the two date filters differ", dateFilter.hashCode(), dateFilter2.hashCode());
}
use of uk.ac.ebi.spot.goci.model.Study in project goci by EBISPOT.
the class StudyNoteController method EnableEditNote.
//This will enable save/remove button for a study note and disable all other action for other notes
@RequestMapping(value = "/studies/{studyId}/notes", method = RequestMethod.POST, params = { "editNote" })
public String EnableEditNote(Model model, @PathVariable Long studyId, HttpServletRequest req) {
//Index of value to remove
final Integer rowId = Integer.valueOf(req.getParameter("editNote"));
//get the study
Study study = studyRepository.findOne(studyId);
model.addAttribute("study", study);
//get All note subjects for dropdown
//remove subjects including 'Imported from previous system' 'SystemNote'
Collection<NoteSubject> noteSubjects = noteSubjectService.findNonSystemNoteSubject();
model.addAttribute("availableNoteSubject", noteSubjects);
// an form object mapped from the studyNote object, it contains a list of notes
MultiStudyNoteForm msnf = studyNoteOperationsService.generateMultiStudyNoteForm(study.getNotes(), study);
//enable the edit for the note and disable all edit for other notes
msnf.startEdit(rowId);
model.addAttribute("multiStudyNoteForm", msnf);
return "study_notes";
}
use of uk.ac.ebi.spot.goci.model.Study in project goci by EBISPOT.
the class StudyNoteController method saveNote.
@RequestMapping(value = "/studies/{studyId}/notes", method = RequestMethod.POST, params = { "saveNote" })
public String saveNote(@ModelAttribute("multiStudyNoteForm") @Valid MultiStudyNoteForm multiStudyNoteForm, BindingResult bindingResult, Model model, @PathVariable Long studyId, HttpServletRequest req) {
//Index of value to save
final Integer rowId = Integer.valueOf(req.getParameter("saveNote"));
//get the study
Study study = studyRepository.findOne(studyId);
model.addAttribute("study", study);
//the newly added note can only be assigned one of the availlable subject, not including system note subjects.
Collection<NoteSubject> noteSubjects = noteSubjectService.findNonSystemNoteSubject();
model.addAttribute("availableNoteSubject", noteSubjects);
//form validation
if (bindingResult.hasErrors()) {
//reload system notes because they are not part of the input
multiStudyNoteForm.setSystemNoteForms(studyNoteOperationsService.generateSystemNoteForms(study.getNotes()));
model.addAttribute("availableNoteSubject", noteSubjects);
model.addAttribute("multiStudyNoteForm", multiStudyNoteForm);
return "study_notes";
}
//convert studynoteform to studynote domain object and save
StudyNoteForm snf = multiStudyNoteForm.getNomalNoteForms().get(rowId.intValue());
StudyNote noteToEdit = studyNoteOperationsService.convertToStudyNote(snf, study);
SecureUser user = currentUserDetailsService.getUserFromRequest(req);
ErrorNotification notification = studyOperationsService.addStudyNote(study, noteToEdit, user);
if (!notification.hasErrors()) {
return "redirect:/studies/" + studyId + "/notes";
} else {
//deal with error
// we want to display the error to the user simply on top of the form
getLog().warn("Request: " + req.getRequestURL() + " raised an error." + notification.errorMessage());
model.addAttribute("errors", "Update FAIL! " + notification.errorMessage());
multiStudyNoteForm.setSystemNoteForms(studyNoteOperationsService.generateSystemNoteForms(study.getNotes()));
model.addAttribute("availableNoteSubject", noteSubjects);
model.addAttribute("multiStudyNoteForm", multiStudyNoteForm);
}
return "study_notes";
}
Aggregations