use of ca.corefacility.bioinformatics.irida.exceptions.ProjectSynchronizationException 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.exceptions.ProjectSynchronizationException in project irida by phac-nml.
the class ProjectSynchronizationService method syncSingleEndSequenceFile.
/**
* Synchronize a given {@link SingleEndSequenceFile} to the local
* installation
*
* @param file
* the {@link SingleEndSequenceFile} to sync
* @param sample
* the {@link Sample} to add the file to
*/
public void syncSingleEndSequenceFile(SingleEndSequenceFile file, Sample sample) {
RemoteStatus fileStatus = file.getRemoteStatus();
fileStatus.setSyncStatus(SyncStatus.UPDATING);
try {
file = singleEndRemoteService.mirrorSequencingObject(file);
file.getSequenceFile().setId(null);
file.getSequenceFile().getRemoteStatus().setSyncStatus(SyncStatus.SYNCHRONIZED);
objectService.createSequencingObjectInSample(file, sample);
fileStatus.setSyncStatus(SyncStatus.SYNCHRONIZED);
objectService.updateRemoteStatus(file.getId(), fileStatus);
} catch (Exception e) {
logger.error("Error transferring file: " + file.getRemoteStatus().getURL(), e);
throw new ProjectSynchronizationException("Could not synchronize file " + file.getRemoteStatus().getURL(), e);
}
}
use of ca.corefacility.bioinformatics.irida.exceptions.ProjectSynchronizationException in project irida by phac-nml.
the class ProjectSynchronizationService method syncSample.
/**
* Synchronize a given {@link Sample} to the local installation.
*
* @param sample the {@link Sample} to synchronize. This should have been read
* from a remote api.
* @param project The {@link Project} the {@link Sample} belongs in.
* @param existingSamples A map of samples that have already been synchronized. These will be checked to see if they've been updated
*/
public void syncSample(Sample sample, Project project, Map<String, Sample> existingSamples) {
Sample localSample;
if (existingSamples.containsKey(sample.getRemoteStatus().getURL())) {
// if the sample already exists check if it's been updated
localSample = existingSamples.get(sample.getRemoteStatus().getURL());
// if there's changes, update the sample
if (checkForChanges(localSample.getRemoteStatus(), sample)) {
logger.debug("found changes for sample " + sample.getSelfHref());
// ensure the ids are properly set
sample = updateIds(localSample, sample);
sample.getRemoteStatus().setSyncStatus(SyncStatus.UPDATING);
localSample = sampleService.update(sample);
}
} else {
// if the sample doesn't already exist create it
sample.getRemoteStatus().setSyncStatus(SyncStatus.UPDATING);
localSample = sampleService.create(sample);
projectService.addSampleToProject(project, sample, true);
}
// get the local files and organize by their url
Collection<SampleSequencingObjectJoin> localObjects = objectService.getSequencingObjectsForSample(localSample);
Map<String, SequencingObject> objectsByUrl = new HashMap<>();
localObjects.forEach(j -> {
SequencingObject pair = j.getObject();
// concatenated it
if (pair.getRemoteStatus() != null) {
String url = pair.getRemoteStatus().getURL();
objectsByUrl.put(url, pair);
}
});
List<SequenceFilePair> sequenceFilePairsForSample = pairRemoteService.getSequenceFilePairsForSample(sample);
List<ProjectSynchronizationException> syncErrors = new ArrayList<>();
for (SequenceFilePair pair : sequenceFilePairsForSample) {
if (!objectsByUrl.containsKey(pair.getRemoteStatus().getURL())) {
pair.setId(null);
try {
syncSequenceFilePair(pair, localSample);
} catch (ProjectSynchronizationException e) {
syncErrors.add(e);
}
}
}
List<SingleEndSequenceFile> unpairedFilesForSample = singleEndRemoteService.getUnpairedFilesForSample(sample);
for (SingleEndSequenceFile file : unpairedFilesForSample) {
if (!objectsByUrl.containsKey(file.getRemoteStatus().getURL())) {
file.setId(null);
try {
syncSingleEndSequenceFile(file, localSample);
} catch (ProjectSynchronizationException e) {
syncErrors.add(e);
}
}
}
if (syncErrors.isEmpty()) {
localSample.getRemoteStatus().setSyncStatus(SyncStatus.SYNCHRONIZED);
} else {
localSample.getRemoteStatus().setSyncStatus(SyncStatus.ERROR);
logger.error("Setting sample " + localSample.getId() + "sync status to ERROR due to sync errors with files");
}
sampleService.update(localSample);
}
Aggregations