Search in sources :

Example 6 with Housekeeping

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

the class HousekeepingOperationsServiceTest method createHousekeeping.

@Test
public void createHousekeeping() throws Exception {
    // Stubbing
    when(curationStatusRepository.findByStatus("Awaiting Curation")).thenReturn(AWAITING_CURATION);
    when(curatorRepository.findByLastName("Level 1 Curator")).thenReturn(LEVEL_1_CURATOR);
    Housekeeping housekeeping = housekeepingOperationsService.createHousekeeping();
    verify(curationStatusRepository, times(1)).findByStatus("Awaiting Curation");
    verify(curatorRepository, times(1)).findByLastName("Level 1 Curator");
    verify(housekeepingRepository, times(1)).save(Matchers.any(Housekeeping.class));
    verifyZeroInteractions(studyRepository);
    // Assertions
    assertThat(housekeeping).extracting(curator -> curator.getCurator().getLastName()).contains("Level 1 Curator");
    assertThat(housekeeping).extracting(curationStatus -> curationStatus.getCurationStatus().getStatus()).contains("Awaiting Curation");
    assertThat(housekeeping.getStudyAddedDate()).isToday();
}
Also used : Housekeeping(uk.ac.ebi.spot.goci.model.Housekeeping) CurationStatusRepository(uk.ac.ebi.spot.goci.repository.CurationStatusRepository) CuratorBuilder(uk.ac.ebi.spot.goci.builder.CuratorBuilder) Matchers(org.mockito.Matchers) Mock(org.mockito.Mock) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) RunWith(org.junit.runner.RunWith) Test(org.junit.Test) Housekeeping(uk.ac.ebi.spot.goci.model.Housekeeping) Mockito.times(org.mockito.Mockito.times) Mockito.when(org.mockito.Mockito.when) CuratorRepository(uk.ac.ebi.spot.goci.repository.CuratorRepository) Mockito.verify(org.mockito.Mockito.verify) Mockito.verifyZeroInteractions(org.mockito.Mockito.verifyZeroInteractions) HousekeepingRepository(uk.ac.ebi.spot.goci.repository.HousekeepingRepository) MockitoJUnitRunner(org.mockito.runners.MockitoJUnitRunner) CurationStatusBuilder(uk.ac.ebi.spot.goci.builder.CurationStatusBuilder) CurationStatus(uk.ac.ebi.spot.goci.model.CurationStatus) Study(uk.ac.ebi.spot.goci.model.Study) StudyRepository(uk.ac.ebi.spot.goci.repository.StudyRepository) StudyBuilder(uk.ac.ebi.spot.goci.builder.StudyBuilder) HousekeepingBuilder(uk.ac.ebi.spot.goci.builder.HousekeepingBuilder) Curator(uk.ac.ebi.spot.goci.model.Curator) Before(org.junit.Before) Test(org.junit.Test)

Example 7 with Housekeeping

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

the class PrintController method getStudyInfoToPrint.

protected ArrayList<Object> getStudyInfoToPrint(Study studyToPrint) {
    // Get relevant study details
    Long studyId = studyToPrint.getId();
    // Get association information
    Collection<SnpAssociationTableView> snpAssociationTableViews = studyPrintService.generatePrintView(studyId);
    // Get housekeeping and ancestry information
    Housekeeping housekeeping = studyToPrint.getHousekeeping();
    Collection<StudyNote> studyNotes = studyToPrint.getNotes();
    String initialSampleDescription = studyToPrint.getInitialSampleSize();
    String replicateSampleDescription = studyToPrint.getReplicateSampleSize();
    // Creating a Hashtable
    ArrayList<Object> infoToPrint = new ArrayList<Object>();
    infoToPrint.add(studyToPrint);
    infoToPrint.add(housekeeping);
    infoToPrint.add(initialSampleDescription);
    infoToPrint.add(replicateSampleDescription);
    infoToPrint.add(ancestryRepository.findByStudyIdAndType(studyId, "initial"));
    infoToPrint.add(ancestryRepository.findByStudyIdAndType(studyId, "replication"));
    infoToPrint.add(snpAssociationTableViews);
    infoToPrint.add(studyNotes);
    return infoToPrint;
}
Also used : Housekeeping(uk.ac.ebi.spot.goci.model.Housekeeping) ArrayList(java.util.ArrayList) SnpAssociationTableView(uk.ac.ebi.spot.goci.curation.model.SnpAssociationTableView) StudyNote(uk.ac.ebi.spot.goci.model.StudyNote)

Example 8 with Housekeeping

use of uk.ac.ebi.spot.goci.model.Housekeeping 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 9 with Housekeeping

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

the class StudyUpdateService method updateStudy.

/**
     * Update a study entry in the database
     *
     * @param existingStudyId ID of study being edited
     * @param study           Study to update
     * @param user            User performing request
     */
public void updateStudy(Long existingStudyId, Study study, SecureUser user) {
    // Use id in URL to get study and then its associated housekeeping
    Study existingStudy = studyRepository.findOne(existingStudyId);
    Housekeeping existingHousekeeping = existingStudy.getHousekeeping();
    // Check changes and record update details
    String updateDescription = generateUpdateDescription(existingStudy, study);
    // Set the housekeeping of the study returned to one already linked to it in database
    // Need to do this as we don't return housekeeping in form
    study.setHousekeeping(existingHousekeeping);
    trackingOperationService.update(study, user, "STUDY_UPDATE", updateDescription);
    studyRepository.save(study);
    getLog().info("Study ".concat(String.valueOf(study.getId())).concat(" updated"));
}
Also used : Housekeeping(uk.ac.ebi.spot.goci.model.Housekeeping) Study(uk.ac.ebi.spot.goci.model.Study)

Example 10 with Housekeeping

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

the class StudyOperationsService method assignStudyStatus.

/**
     * Assign status to a study
     */
public String assignStudyStatus(Study study, StatusAssignment statusAssignment, SecureUser userFromRequest) {
    CurationStatus newStatus = curationStatusRepository.findOne(statusAssignment.getStatusId());
    CurationStatus currentStudyStatus = study.getHousekeeping().getCurationStatus();
    String message = null;
    // If the current and new status are different
    if (newStatus != null && newStatus != currentStudyStatus) {
        // Get housekeeping object and assign new status
        Housekeeping housekeeping = study.getHousekeeping();
        if (newStatus.getStatus().equals("Publish study")) {
            // Run pre-publish checks first
            Collection<Association> associations = associationRepository.findByStudyId(study.getId());
            message = publishStudyCheckService.runChecks(study, associations);
            // if checks pass then update the status and save objects
            if (message == null) {
                housekeeping.setCurationStatus(newStatus);
                updateStatus(study, housekeeping, userFromRequest);
            }
        } else {
            housekeeping.setCurationStatus(newStatus);
            updateStatus(study, housekeeping, userFromRequest);
        }
    } else {
        message = "Current status and new status are the same, no change required";
    }
    return message;
}
Also used : Housekeeping(uk.ac.ebi.spot.goci.model.Housekeeping) Association(uk.ac.ebi.spot.goci.model.Association) CurationStatus(uk.ac.ebi.spot.goci.model.CurationStatus)

Aggregations

Housekeeping (uk.ac.ebi.spot.goci.model.Housekeeping)11 Study (uk.ac.ebi.spot.goci.model.Study)6 CurationStatus (uk.ac.ebi.spot.goci.model.CurationStatus)4 HousekeepingBuilder (uk.ac.ebi.spot.goci.builder.HousekeepingBuilder)3 StudyBuilder (uk.ac.ebi.spot.goci.builder.StudyBuilder)3 Curator (uk.ac.ebi.spot.goci.model.Curator)3 Date (java.util.Date)2 Before (org.junit.Before)2 Test (org.junit.Test)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 Association (uk.ac.ebi.spot.goci.model.Association)2 ArrayList (java.util.ArrayList)1 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)1 RunWith (org.junit.runner.RunWith)1 Matchers (org.mockito.Matchers)1 Mock (org.mockito.Mock)1 Mockito.times (org.mockito.Mockito.times)1 Mockito.verify (org.mockito.Mockito.verify)1 Mockito.verifyZeroInteractions (org.mockito.Mockito.verifyZeroInteractions)1 Mockito.when (org.mockito.Mockito.when)1