Search in sources :

Example 26 with Study

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");
}
Also used : Study(uk.ac.ebi.spot.goci.model.Study) Test(org.junit.Test)

Example 27 with Study

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();
}
Also used : Housekeeping(uk.ac.ebi.spot.goci.model.Housekeeping) Study(uk.ac.ebi.spot.goci.model.Study) HousekeepingBuilder(uk.ac.ebi.spot.goci.builder.HousekeepingBuilder) StudyBuilder(uk.ac.ebi.spot.goci.builder.StudyBuilder) UnpublishReason(uk.ac.ebi.spot.goci.model.UnpublishReason) Test(org.junit.Test)

Example 28 with Study

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());
}
Also used : Study(uk.ac.ebi.spot.goci.model.Study) Association(uk.ac.ebi.spot.goci.model.Association) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) SingleNucleotidePolymorphism(uk.ac.ebi.spot.goci.model.SingleNucleotidePolymorphism) ParseException(java.text.ParseException) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) Test(org.junit.Test)

Example 29 with Study

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";
}
Also used : Study(uk.ac.ebi.spot.goci.model.Study) NoteSubject(uk.ac.ebi.spot.goci.model.NoteSubject) MultiStudyNoteForm(uk.ac.ebi.spot.goci.curation.model.MultiStudyNoteForm) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 30 with Study

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";
}
Also used : Study(uk.ac.ebi.spot.goci.model.Study) StudyNoteForm(uk.ac.ebi.spot.goci.curation.model.StudyNoteForm) MultiStudyNoteForm(uk.ac.ebi.spot.goci.curation.model.MultiStudyNoteForm) NoteSubject(uk.ac.ebi.spot.goci.model.NoteSubject) StudyNote(uk.ac.ebi.spot.goci.model.StudyNote) SecureUser(uk.ac.ebi.spot.goci.model.SecureUser) ErrorNotification(uk.ac.ebi.spot.goci.curation.model.errors.ErrorNotification) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

Study (uk.ac.ebi.spot.goci.model.Study)44 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)20 ArrayList (java.util.ArrayList)7 Association (uk.ac.ebi.spot.goci.model.Association)7 Housekeeping (uk.ac.ebi.spot.goci.model.Housekeeping)6 MultiStudyNoteForm (uk.ac.ebi.spot.goci.curation.model.MultiStudyNoteForm)5 Date (java.util.Date)4 Test (org.junit.Test)4 Ancestry (uk.ac.ebi.spot.goci.model.Ancestry)4 NoteSubject (uk.ac.ebi.spot.goci.model.NoteSubject)4 SecureUser (uk.ac.ebi.spot.goci.model.SecureUser)4 SingleNucleotidePolymorphism (uk.ac.ebi.spot.goci.model.SingleNucleotidePolymorphism)4 ParseException (java.text.ParseException)3 SimpleDateFormat (java.text.SimpleDateFormat)3 Autowired (org.springframework.beans.factory.annotation.Autowired)3 Service (org.springframework.stereotype.Service)3 StudyNoteForm (uk.ac.ebi.spot.goci.curation.model.StudyNoteForm)3 RiskAllele (uk.ac.ebi.spot.goci.model.RiskAllele)3 StudyNote (uk.ac.ebi.spot.goci.model.StudyNote)3 IOException (java.io.IOException)2