Skip to content

Commit

Permalink
Merge branch 'hotfix-assemblies-not-available' into release-20.09.2
Browse files Browse the repository at this point in the history
  • Loading branch information
tom114 committed Oct 8, 2020
2 parents 2792894 + ce0cf1f commit 2fad571
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Changes
* [UI]: Added two additional fields to SISTR viewer describing the number of alleles found (20.09.1)
* [UI]: Fixed bug where users could not see or connect to Remote APIs (20.09.2)
* [UI]: Fixed bug on project page where incorrect link to Remote API was displayed. (20.09.2)
* [REST]: Added handling for synchronizing data from older IRIDA instances. It was failing for APIs without assembly functionality addded in 20.09. (20.09.2)

20.05 to 20.09
--------------
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package ca.corefacility.bioinformatics.irida.exceptions;

/**
* Exception thrown when there is no link for a given rel when reading from an API
*/
public class LinkNotFoundException extends RuntimeException {

public LinkNotFoundException(String message) {
super(message);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package ca.corefacility.bioinformatics.irida.service.remote;

import ca.corefacility.bioinformatics.irida.exceptions.LinkNotFoundException;
import ca.corefacility.bioinformatics.irida.model.assembly.GenomeAssembly;
import ca.corefacility.bioinformatics.irida.model.assembly.UploadedAssembly;
import ca.corefacility.bioinformatics.irida.model.sample.Sample;
Expand All @@ -15,8 +16,9 @@ public interface GenomeAssemblyRemoteService extends RemoteService<UploadedAssem
*
* @param sample the Sample to get assemblies for
* @return a list of {@link UploadedAssembly}
* @throws LinkNotFoundException if the targeted API does not support assemblies
*/
public List<UploadedAssembly> getGenomeAssembliesForSample(Sample sample);
public List<UploadedAssembly> getGenomeAssembliesForSample(Sample sample) throws LinkNotFoundException;

/**
* Download the given {@link UploadedAssembly} to the local server
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package ca.corefacility.bioinformatics.irida.service.remote;

import ca.corefacility.bioinformatics.irida.exceptions.IridaOAuthException;
import ca.corefacility.bioinformatics.irida.exceptions.LinkNotFoundException;
import ca.corefacility.bioinformatics.irida.exceptions.ProjectSynchronizationException;
import ca.corefacility.bioinformatics.irida.model.MutableIridaThing;
import ca.corefacility.bioinformatics.irida.model.RemoteAPI;
Expand Down Expand Up @@ -36,6 +37,8 @@
import java.util.*;
import java.util.stream.Collectors;

import com.google.common.collect.Lists;

/**
* Service class to run a project synchornization task. Ths class will be
* responsible for communicating with Remote IRIDA installations and pulling
Expand Down Expand Up @@ -371,8 +374,15 @@ public List<ProjectSynchronizationException> syncSample(Sample sample, Project p
}
}

//list the remote assemblies for the sample
List<UploadedAssembly> genomeAssembliesForSample = assemblyRemoteService.getGenomeAssembliesForSample(sample);
//list the remote assemblies for the sample.
List<UploadedAssembly> genomeAssembliesForSample;
try {
genomeAssembliesForSample = assemblyRemoteService.getGenomeAssembliesForSample(sample);
} catch (LinkNotFoundException e) {
//if the target IRIDA doesn't support assemblies yet, warn and ignore assemblies.
logger.warn("The sample on the referenced IRIDA doesn't support assemblies: " + sample.getSelfHref());
genomeAssembliesForSample = Lists.newArrayList();
}

//for each assembly
for (UploadedAssembly file : genomeAssembliesForSample) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import org.springframework.hateoas.Link;
import org.springframework.stereotype.Service;

import ca.corefacility.bioinformatics.irida.exceptions.LinkNotFoundException;
import ca.corefacility.bioinformatics.irida.model.RemoteAPI;
import ca.corefacility.bioinformatics.irida.model.assembly.UploadedAssembly;
import ca.corefacility.bioinformatics.irida.model.sample.Sample;
Expand Down Expand Up @@ -42,7 +43,10 @@ public GenomeAssemblyRemoteServiceImpl(GenomeAssemblyRemoteRepository repository
* {@inheritDoc}
*/
@Override
public List<UploadedAssembly> getGenomeAssembliesForSample(Sample sample) {
public List<UploadedAssembly> getGenomeAssembliesForSample(Sample sample) throws LinkNotFoundException {
if (!sample.hasLink(SAMPLE_ASSEMBLY_REL)) {
throw new LinkNotFoundException("No link for rel: " + SAMPLE_ASSEMBLY_REL);
}
Link link = sample.getLink(SAMPLE_ASSEMBLY_REL);
String href = link.getHref();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import java.util.Date;

import ca.corefacility.bioinformatics.irida.exceptions.IridaOAuthException;
import ca.corefacility.bioinformatics.irida.exceptions.LinkNotFoundException;
import ca.corefacility.bioinformatics.irida.model.assembly.GenomeAssembly;
import ca.corefacility.bioinformatics.irida.model.assembly.UploadedAssembly;
import ca.corefacility.bioinformatics.irida.service.impl.TestEmailController;
import org.junit.Before;
Expand Down Expand Up @@ -188,6 +190,23 @@ public void testExistingSample(){
verify(projectService,times(0)).addSampleToProject(expired, sample, true);
verify(sampleService,times(2)).update(any(Sample.class));
}

@Test
public void testSyncSampleNoAssemblies() {
Sample sample = new Sample();
RemoteStatus sampleStatus = new RemoteStatus("http://sample",api);
sample.setRemoteStatus(sampleStatus);

when(sampleService.create(sample)).thenReturn(sample);
when(assemblyRemoteService.getGenomeAssembliesForSample(sample)).thenThrow(new LinkNotFoundException("no link"));

syncService.syncSample(sample, expired, Maps.newHashMap());

verify(projectService).addSampleToProject(expired, sample, true);
verify(assemblyRemoteService, times(0)).mirrorAssembly(any(UploadedAssembly.class));

assertEquals(SyncStatus.SYNCHRONIZED,sample.getRemoteStatus().getSyncStatus());
}

@Test
public void testSyncFiles() {
Expand Down

0 comments on commit 2fad571

Please sign in to comment.