Search in sources :

Example 6 with RemoteStatus

use of ca.corefacility.bioinformatics.irida.model.remote.RemoteStatus in project irida by phac-nml.

the class ProjectSynchronizationServiceTest method testSyncNewSample.

@Test
public void testSyncNewSample() {
    Sample sample = new Sample();
    RemoteStatus sampleStatus = new RemoteStatus("http://sample", api);
    sample.setRemoteStatus(sampleStatus);
    when(sampleService.create(sample)).thenReturn(sample);
    syncService.syncSample(sample, expired, Maps.newHashMap());
    verify(projectService).addSampleToProject(expired, sample, true);
    assertEquals(SyncStatus.SYNCHRONIZED, sample.getRemoteStatus().getSyncStatus());
}
Also used : Sample(ca.corefacility.bioinformatics.irida.model.sample.Sample) RemoteStatus(ca.corefacility.bioinformatics.irida.model.remote.RemoteStatus) Test(org.junit.Test)

Example 7 with RemoteStatus

use of ca.corefacility.bioinformatics.irida.model.remote.RemoteStatus in project irida by phac-nml.

the class ProjectSynchronizationServiceTest method testExistingSample.

@Test
public void testExistingSample() {
    Sample sample = new Sample();
    RemoteStatus sampleStatus = new RemoteStatus("http://sample", api);
    sample.setRemoteStatus(sampleStatus);
    Sample existingSample = new Sample();
    existingSample.setRemoteStatus(sampleStatus);
    when(sampleService.update(any(Sample.class))).thenReturn(sample);
    syncService.syncSample(sample, expired, ImmutableMap.of("http://sample", existingSample));
    verify(projectService, times(0)).addSampleToProject(expired, sample, true);
    verify(sampleService, times(2)).update(any(Sample.class));
}
Also used : Sample(ca.corefacility.bioinformatics.irida.model.sample.Sample) RemoteStatus(ca.corefacility.bioinformatics.irida.model.remote.RemoteStatus) Test(org.junit.Test)

Example 8 with RemoteStatus

use of ca.corefacility.bioinformatics.irida.model.remote.RemoteStatus in project irida by phac-nml.

the class ProjectSynchronizationServiceTest method testSyncFiles.

@Test
public void testSyncFiles() {
    Sample sample = new Sample();
    SequenceFilePair pair = new SequenceFilePair();
    RemoteStatus pairStatus = new RemoteStatus("http://pair", api);
    pair.setRemoteStatus(pairStatus);
    pair.setId(1L);
    when(pairRemoteService.mirrorSequencingObject(pair)).thenReturn(pair);
    syncService.syncSequenceFilePair(pair, sample);
    verify(pairRemoteService).mirrorSequencingObject(pair);
    verify(objectService).createSequencingObjectInSample(pair, sample);
}
Also used : SequenceFilePair(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFilePair) Sample(ca.corefacility.bioinformatics.irida.model.sample.Sample) RemoteStatus(ca.corefacility.bioinformatics.irida.model.remote.RemoteStatus) Test(org.junit.Test)

Example 9 with RemoteStatus

use of ca.corefacility.bioinformatics.irida.model.remote.RemoteStatus in project irida by phac-nml.

the class ProjectSynchronizationService method syncSequenceFilePair.

/**
 * Synchronize a given {@link SequenceFilePair} to the local installation.
 *
 * @param pair
 *            the {@link SequenceFilePair} to sync. This should have been
 *            read from a remote api.
 * @param sample
 *            The {@link Sample} to add the pair to.
 */
public void syncSequenceFilePair(SequenceFilePair pair, Sample sample) {
    pair.getRemoteStatus().setSyncStatus(SyncStatus.UPDATING);
    try {
        pair = pairRemoteService.mirrorSequencingObject(pair);
        pair.getFiles().forEach(s -> {
            s.setId(null);
            s.getRemoteStatus().setSyncStatus(SyncStatus.SYNCHRONIZED);
        });
        objectService.createSequencingObjectInSample(pair, sample);
        RemoteStatus pairStatus = pair.getRemoteStatus();
        pairStatus.setSyncStatus(SyncStatus.SYNCHRONIZED);
        objectService.updateRemoteStatus(pair.getId(), pairStatus);
    } catch (Exception e) {
        logger.error("Error transferring file: " + pair.getRemoteStatus().getURL(), e);
        throw new ProjectSynchronizationException("Could not synchronize pair " + pair.getRemoteStatus().getURL(), e);
    }
}
Also used : ProjectSynchronizationException(ca.corefacility.bioinformatics.irida.exceptions.ProjectSynchronizationException) RemoteStatus(ca.corefacility.bioinformatics.irida.model.remote.RemoteStatus) IridaOAuthException(ca.corefacility.bioinformatics.irida.exceptions.IridaOAuthException) ProjectSynchronizationException(ca.corefacility.bioinformatics.irida.exceptions.ProjectSynchronizationException)

Example 10 with RemoteStatus

use of ca.corefacility.bioinformatics.irida.model.remote.RemoteStatus in project irida by phac-nml.

the class ProjectSynchronizationService method syncProject.

/**
 * Synchronize a given {@link Project} to the local installation.
 *
 * @param project
 *            the {@link Project} to synchronize. This should have been read
 *            from a remote api.
 */
private void syncProject(Project project) {
    project.getRemoteStatus().setSyncStatus(SyncStatus.UPDATING);
    projectService.update(project);
    String projectURL = project.getRemoteStatus().getURL();
    Project readProject = projectRemoteService.read(projectURL);
    // ensure we use the same IDs
    readProject = updateIds(project, readProject);
    // if project was updated remotely, update it here
    if (checkForChanges(project.getRemoteStatus(), readProject)) {
        logger.debug("found changes for project " + readProject.getSelfHref());
        // need to keep the status and frequency of the local project
        RemoteStatus originalStatus = project.getRemoteStatus();
        readProject.getRemoteStatus().setSyncStatus(originalStatus.getSyncStatus());
        readProject.setSyncFrequency(project.getSyncFrequency());
        project = projectService.update(readProject);
    }
    List<Join<Project, Sample>> localSamples = sampleService.getSamplesForProject(project);
    // get all the samples by their url
    Map<String, Sample> samplesByUrl = new HashMap<>();
    localSamples.forEach(j -> {
        Sample sample = j.getObject();
        // If a user has added a sample for some reason, ignore it
        if (sample.getRemoteStatus() != null) {
            String url = sample.getRemoteStatus().getURL();
            samplesByUrl.put(url, sample);
        } else {
            logger.warn("Sample " + sample.getId() + " is not a remote sample.  It will not be synchronized.");
        }
    });
    List<Sample> readSamplesForProject = sampleRemoteService.getSamplesForProject(readProject);
    for (Sample s : readSamplesForProject) {
        s.setId(null);
        s = syncSampleMetadata(s);
        syncSample(s, project, samplesByUrl);
    }
    project.setRemoteStatus(readProject.getRemoteStatus());
    project.getRemoteStatus().setSyncStatus(SyncStatus.SYNCHRONIZED);
    projectService.update(project);
}
Also used : Project(ca.corefacility.bioinformatics.irida.model.project.Project) HashMap(java.util.HashMap) Sample(ca.corefacility.bioinformatics.irida.model.sample.Sample) Join(ca.corefacility.bioinformatics.irida.model.joins.Join) SampleSequencingObjectJoin(ca.corefacility.bioinformatics.irida.model.sample.SampleSequencingObjectJoin) RemoteStatus(ca.corefacility.bioinformatics.irida.model.remote.RemoteStatus)

Aggregations

RemoteStatus (ca.corefacility.bioinformatics.irida.model.remote.RemoteStatus)15 Test (org.junit.Test)8 Sample (ca.corefacility.bioinformatics.irida.model.sample.Sample)7 Project (ca.corefacility.bioinformatics.irida.model.project.Project)5 RemoteAPI (ca.corefacility.bioinformatics.irida.model.RemoteAPI)3 HashMap (java.util.HashMap)3 IridaOAuthException (ca.corefacility.bioinformatics.irida.exceptions.IridaOAuthException)2 ProjectSynchronizationException (ca.corefacility.bioinformatics.irida.exceptions.ProjectSynchronizationException)2 SequenceFilePair (ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFilePair)2 User (ca.corefacility.bioinformatics.irida.model.user.User)2 Date (java.util.Date)2 Link (org.springframework.hateoas.Link)2 Authentication (org.springframework.security.core.Authentication)2 Join (ca.corefacility.bioinformatics.irida.model.joins.Join)1 ProjectSyncFrequency (ca.corefacility.bioinformatics.irida.model.project.ProjectSyncFrequency)1 SampleSequencingObjectJoin (ca.corefacility.bioinformatics.irida.model.sample.SampleSequencingObjectJoin)1 SequenceFile (ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile)1 SequencingObject (ca.corefacility.bioinformatics.irida.model.sequenceFile.SequencingObject)1 SingleEndSequenceFile (ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile)1 ProjectSynchronizationAuthenticationToken (ca.corefacility.bioinformatics.irida.security.ProjectSynchronizationAuthenticationToken)1