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