Skip to content

Commit

Permalink
Merge pull request #1465 from phac-nml/get_sample_by_name
Browse files Browse the repository at this point in the history
deprecated getSampleBySequencerId, added getSampleBySampleName
  • Loading branch information
ericenns authored Feb 10, 2023
2 parents 5bf783d + a33a50a commit 492ffd1
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* [Developer/UI]: Fix for updating sample modified date when metadata is deleted. See [PR 1457](https://github.com/phac-nml/irida/pull/1457).
* [Developer]: Added support for cloud based storage. Currently, Microsoft Azure Blob and Amazon AWS S3 are supported. [See PR 1194](https://github.com/phac-nml/irida/pull/1194)
* [Developer]: Updated metadata uploader to use react-router-dom Outlet. [See PR 1464](https://github.com/phac-nml/irida/pull/1464)
* [Developer]: Deprecated "/api/projects/{projectId}/samples/bySequencerId/{seqeuncerId}" in favour of "/api/projects/{projectId}/samples/bySampleName", which accepts a json property "sampleName"

## [22.09.7] - 2022/01/24
* [UI]: Fixed bugs on NCBI Export page preventing the NCBI `submission.xml` file from being properly written. See [PR 1451](https://github.com/phac-nml/irida/pull/1451)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ public ResponseResource<ResourceCollection<Sample>> getProjectSamples(@PathVaria
* @param seqeuncerId the string id of the sample
* @return The found sample
*/
@Deprecated()
@RequestMapping(value = "/api/projects/{projectId}/samples/bySequencerId/{seqeuncerId}", method = RequestMethod.GET)
public ModelAndView getProjectSampleBySequencerId(@PathVariable Long projectId, @PathVariable String seqeuncerId) {
Project p = projectService.read(projectId);
Expand All @@ -258,6 +259,28 @@ public ModelAndView getProjectSampleBySequencerId(@PathVariable Long projectId,
return new ModelAndView(redirectView);
}

/**
* Get samples by a given string name
*
* @param projectId the Project to get samples from
* @param sampleName String containing sample name
* @return The found sample
*/
@RequestMapping(value = "/api/projects/{projectId}/samples/bySampleName", method = RequestMethod.GET)
public ModelAndView getProjectSampleBySampleName(@PathVariable Long projectId, @RequestParam String sampleName) {
Project p = projectService.read(projectId);

Sample sampleBySampleName = sampleService.getSampleBySampleName(p, sampleName);

Link withSelfRel = linkTo(
methodOn(RESTProjectSamplesController.class).getSample(sampleBySampleName.getId())).withSelfRel();
String href = withSelfRel.getHref();

RedirectView redirectView = new RedirectView(href);

return new ModelAndView(redirectView);
}

/**
* Get the representation of a specific sample that's associated with the
* project.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package ca.corefacility.bioinformatics.irida.web.controller.test.integration.project;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.*;
import java.util.concurrent.*;

import org.apache.http.HttpResponse;
Expand Down Expand Up @@ -388,4 +385,31 @@ public void testReadSamplesAsSequencer() {
.when()
.get(projectSamplesUri);
}

@Test
public void testReadSampleByName() {
String rootUri = uriTemplateHandler.getRootUri() + "/api";
String projectUri = rootUri + "/projects/5";
String sampleByNameUri = projectUri + "/samples/bySampleName?sampleName=sample1";
String expectedSampleUri = rootUri + "/samples/1";

final Response r = asAdmin().expect()
.body("resource.links.rel", hasItems("self", "sample/sequenceFiles"))
.when()
.get(sampleByNameUri);
final String responseBody = r.getBody().asString();
final String selfUri = from(responseBody).get("resource.links.find{it.rel == 'self'}.href");
assertEquals(expectedSampleUri, selfUri);
}

@Test
public void testReadSampleByNameError() {
String projectUri = uriTemplateHandler.getRootUri() + "/api/projects/5";
String sampleByNameUri = projectUri + "/samples/bySampleName?sampleName=not_a_sample";

asAdmin().expect()
.statusCode(equalTo(404))
.when()
.get(sampleByNameUri);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import com.google.common.net.HttpHeaders;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.view.RedirectView;

import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.Mockito.*;
Expand Down Expand Up @@ -190,6 +192,25 @@ public void testGetProjectSample() throws IOException {

}

@Test
public void testGetProjectSampleByName() throws IOException {
Project p = TestDataFactory.constructProject();
Sample s = TestDataFactory.constructSample();

// mock out the service calls
when(projectService.read(p.getId())).thenReturn(p);
when(sampleService.getSampleBySampleName(p, s.getSampleName())).thenReturn(s);

String sampleLocation = "http://localhost/api/samples/" + s.getId();

ModelAndView responseObject = controller.getProjectSampleBySampleName(p.getId(), s.getSampleName());

verify(sampleService).getSampleBySampleName(p, s.getSampleName());

RedirectView rv = (RedirectView) responseObject.getView();
assertEquals(sampleLocation, rv.getUrl());
}

@Test
public void testUpdateSample() {
Sample s = TestDataFactory.constructSample();
Expand Down

0 comments on commit 492ffd1

Please sign in to comment.