use of ca.corefacility.bioinformatics.irida.web.assembler.resource.RootResource in project irida by phac-nml.
the class RESTRootController method getLinks.
/**
* Creates a response with a set of links used to discover the rest of the
* system.
*
* @param request
* Incoming HTTP request object to check the user's role.
*
* @return a response to the client.
*/
@RequestMapping(method = RequestMethod.GET, value = "/api")
public ModelMap getLinks(final HttpServletRequest request) {
logger.debug("Discovering application");
RootResource resource = new RootResource();
List<Link> links = new ArrayList<>();
links.addAll(buildLinks(PUBLIC_CONTROLLERS));
if (RESTRICTED_ROLES.stream().anyMatch(r -> request.isUserInRole(r))) {
links.addAll(buildLinks(RESTRICTED_CONTROLLERS));
}
// add a self-rel to the current page
resource.add(linkTo(methodOn(RESTRootController.class).getLinks(request)).withSelfRel());
// add all of the links to the response
resource.add(links);
ModelMap map = new ModelMap();
map.addAttribute(RESTGenericController.RESOURCE_NAME, resource);
// respond to the client
return map;
}
use of ca.corefacility.bioinformatics.irida.web.assembler.resource.RootResource in project irida by phac-nml.
the class SampleSequenceFilesControllerTest method testRemoveSequenceFileFromSample.
@Test
public void testRemoveSequenceFileFromSample() throws IOException {
Sample s = TestDataFactory.constructSample();
SingleEndSequenceFile so = TestDataFactory.constructSingleEndSequenceFile();
when(sampleService.read(s.getId())).thenReturn(s);
when(sequencingObjectService.readSequencingObjectForSample(s, so.getId())).thenReturn(so);
ModelMap modelMap = controller.removeSequenceFileFromSample(s.getId(), "unpaired", so.getId());
verify(sampleService, times(1)).read(s.getId());
verify(sequencingObjectService).readSequencingObjectForSample(s, so.getId());
verify(sampleService, times(1)).removeSequencingObjectFromSample(s, so);
Object o = modelMap.get(RESTGenericController.RESOURCE_NAME);
assertNotNull(o);
assertTrue(o instanceof RootResource);
RootResource resource = (RootResource) o;
Link sample = resource.getLink(RESTSampleSequenceFilesController.REL_SAMPLE);
Link sequenceFiles = resource.getLink(RESTSampleSequenceFilesController.REL_SAMPLE_SEQUENCE_FILES);
String sampleLocation = "http://localhost/api/samples/" + s.getId();
assertNotNull(sample);
assertEquals(sampleLocation, sample.getHref());
assertNotNull(sequenceFiles);
assertEquals(sampleLocation + "/sequenceFiles", sequenceFiles.getHref());
}
Aggregations