Search in sources :

Example 11 with RootResource

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;
}
Also used : RootResource(ca.corefacility.bioinformatics.irida.web.assembler.resource.RootResource) ModelMap(org.springframework.ui.ModelMap) ArrayList(java.util.ArrayList) Link(org.springframework.hateoas.Link) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 12 with RootResource

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());
}
Also used : RootResource(ca.corefacility.bioinformatics.irida.web.assembler.resource.RootResource) Sample(ca.corefacility.bioinformatics.irida.model.sample.Sample) ModelMap(org.springframework.ui.ModelMap) SingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile) Link(org.springframework.hateoas.Link) Test(org.junit.Test)

Aggregations

RootResource (ca.corefacility.bioinformatics.irida.web.assembler.resource.RootResource)12 ModelMap (org.springframework.ui.ModelMap)12 Test (org.junit.Test)6 Link (org.springframework.hateoas.Link)6 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)6 Project (ca.corefacility.bioinformatics.irida.model.project.Project)4 Sample (ca.corefacility.bioinformatics.irida.model.sample.Sample)4 User (ca.corefacility.bioinformatics.irida.model.user.User)2 SequencingObject (ca.corefacility.bioinformatics.irida.model.sequenceFile.SequencingObject)1 SingleEndSequenceFile (ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile)1 ArrayList (java.util.ArrayList)1 MediaType (org.springframework.http.MediaType)1 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)1