Search in sources :

Example 6 with RootResource

use of ca.corefacility.bioinformatics.irida.web.assembler.resource.RootResource in project irida by phac-nml.

the class RESTProjectSamplesController method removeSampleFromProject.

/**
 * Remove a specific {@link Sample} from the collection of {@link Sample}s
 * associated with a {@link Project}.
 *
 * @param projectId
 *            the {@link Project} identifier.
 * @param sampleId
 *            the {@link Sample} identifier.
 * @return a response including links back to the specific {@link Project}
 *         and collection of {@link Sample}.
 */
@RequestMapping(value = "/api/projects/{projectId}/samples/{sampleId}", method = RequestMethod.DELETE)
public ModelMap removeSampleFromProject(@PathVariable Long projectId, @PathVariable Long sampleId) {
    ModelMap modelMap = new ModelMap();
    // load the sample and project
    Project p = projectService.read(projectId);
    Sample s = sampleService.read(sampleId);
    // remove the relationship.
    projectService.removeSampleFromProject(p, s);
    // respond to the client.
    RootResource resource = new RootResource();
    // add links back to the collection of samples and to the project
    // itself.
    resource.add(linkTo(methodOn(RESTProjectSamplesController.class).getProjectSamples(projectId)).withRel(REL_PROJECT_SAMPLES));
    resource.add(linkTo(RESTProjectsController.class).slash(projectId).withRel(RESTProjectsController.REL_PROJECT));
    // add the links to the response.
    modelMap.addAttribute(RESTGenericController.RESOURCE_NAME, resource);
    return modelMap;
}
Also used : RootResource(ca.corefacility.bioinformatics.irida.web.assembler.resource.RootResource) Project(ca.corefacility.bioinformatics.irida.model.project.Project) Sample(ca.corefacility.bioinformatics.irida.model.sample.Sample) ModelMap(org.springframework.ui.ModelMap) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 7 with RootResource

use of ca.corefacility.bioinformatics.irida.web.assembler.resource.RootResource in project irida by phac-nml.

the class RESTProjectUsersController method removeUserFromProject.

/**
 * Remove the relationship between a {@link Project} and a {@link User}.
 *
 * @param projectId the {@link Project} identifier to remove the {@link User} from.
 * @param userId    the {@link User} identifier to remove from the {@link Project}.
 * @return a response including links back to the {@link Project} and the {@link User} collection for
 *         the {@link Project}.
 * @throws ProjectWithoutOwnerException if removing this user will leave the project without an owner
 */
@RequestMapping(value = "/api/projects/{projectId}/users/{userId}", method = RequestMethod.DELETE)
public ModelMap removeUserFromProject(@PathVariable Long projectId, @PathVariable String userId) throws ProjectWithoutOwnerException {
    // Read the project and user from the database
    Project p = projectService.read(projectId);
    User u = userService.getUserByUsername(userId);
    // ask the project service to remove the user from the project
    projectService.removeUserFromProject(p, u);
    // prepare a link back to the user collection of the project
    RootResource response = new RootResource();
    response.add(linkTo(methodOn(RESTProjectUsersController.class).getUsersForProject(projectId)).withRel(REL_PROJECT_USERS));
    // prepare a link back to the project
    response.add(linkTo(RESTProjectsController.class).slash(projectId).withRel(RESTProjectsController.REL_PROJECT));
    // respond to the client
    ModelMap modelMap = new ModelMap();
    modelMap.addAttribute(RESTGenericController.RESOURCE_NAME, response);
    return modelMap;
}
Also used : RootResource(ca.corefacility.bioinformatics.irida.web.assembler.resource.RootResource) Project(ca.corefacility.bioinformatics.irida.model.project.Project) User(ca.corefacility.bioinformatics.irida.model.user.User) ModelMap(org.springframework.ui.ModelMap) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 8 with RootResource

use of ca.corefacility.bioinformatics.irida.web.assembler.resource.RootResource in project irida by phac-nml.

the class RESTGenericController method delete.

/**
 * Delete the instance of the resource identified by a specific identifier.
 *
 * @param identifier
 *            the identifier that should be deleted from the database.
 * @return a response indicating that the resource was deleted.
 */
@RequestMapping(value = "/{identifier}", method = RequestMethod.DELETE)
public ModelMap delete(@PathVariable Long identifier) {
    ModelMap modelMap = new ModelMap();
    // ask the service to delete the resource specified by the identifier
    crudService.delete(identifier);
    RootResource rootResource = new RootResource();
    rootResource.add(linkTo(getClass()).withRel(REL_COLLECTION));
    modelMap.addAttribute(RESOURCE_NAME, rootResource);
    // respond to the client with a successful message
    return modelMap;
}
Also used : RootResource(ca.corefacility.bioinformatics.irida.web.assembler.resource.RootResource) ModelMap(org.springframework.ui.ModelMap) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 9 with RootResource

use of ca.corefacility.bioinformatics.irida.web.assembler.resource.RootResource in project irida by phac-nml.

the class RESTGenericController method update.

/**
 * Update some of the fields of an individual resource in the database. The
 * client should only send the key-value pairs for the properties that are
 * to be updated in the database.
 *
 * @param identifier
 *            the identifier of the resource to be updated.
 * @param representation
 *            the properties to be updated and their new values.
 * @return a response indicating that the resource was updated.
 */
@RequestMapping(value = "/{identifier}", method = RequestMethod.PATCH, consumes = { MediaType.APPLICATION_JSON_VALUE, MediaType.APPLICATION_XML_VALUE })
public ModelMap update(@PathVariable Long identifier, @RequestBody Map<String, Object> representation) {
    // update the resource specified by the client. clients *may* be able
    // to update the identifier of some resources, and so we should get a
    // handle on the updated resource so that we can respond with a
    // possibly updated location.
    Type resource = crudService.updateFields(identifier, representation);
    Long id = resource.getId();
    logger.debug("Updated resource with ID [" + resource.getId() + "]");
    // construct the possibly updated location of the resource using the id
    // of the resource as returned by the service after updating.
    // create a response including the new location.
    ModelMap modelMap = new ModelMap();
    RootResource rootResource = new RootResource();
    rootResource.add(linkTo(getClass()).slash(id).withSelfRel());
    rootResource.add(linkTo(getClass()).withRel(REL_COLLECTION));
    modelMap.addAttribute(RESOURCE_NAME, rootResource);
    // respond to the client
    return modelMap;
}
Also used : RootResource(ca.corefacility.bioinformatics.irida.web.assembler.resource.RootResource) MediaType(org.springframework.http.MediaType) ModelMap(org.springframework.ui.ModelMap) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 10 with RootResource

use of ca.corefacility.bioinformatics.irida.web.assembler.resource.RootResource in project irida by phac-nml.

the class RESTSampleSequenceFilesController method removeSequenceFileFromSample.

/**
 * Remove a {@link SequencingObject} from a {@link Sample}.
 *
 * @param sampleId   the source {@link Sample} identifier.
 * @param objectType The type of sequencing object being removed
 * @param objectId   the identifier of the {@link SequencingObject} to move.
 * @return a status indicating the success of the move.
 */
@RequestMapping(value = "/api/samples/{sampleId}/{objectType}/{objectId}", method = RequestMethod.DELETE)
public ModelMap removeSequenceFileFromSample(@PathVariable Long sampleId, @PathVariable String objectType, @PathVariable Long objectId) {
    ModelMap modelMap = new ModelMap();
    // load the project, sample and sequence file from the database
    Sample s = sampleService.read(sampleId);
    SequencingObject seqObject = sequencingObjectService.readSequencingObjectForSample(s, objectId);
    // ask the service to remove the sample from the sequence file
    sampleService.removeSequencingObjectFromSample(s, seqObject);
    // respond with a link to the sample, the new location of the sequence
    // file (as it is associated with the
    // project)
    RootResource resource = new RootResource();
    resource.add(linkTo(methodOn(RESTProjectSamplesController.class).getSample(sampleId)).withRel(REL_SAMPLE));
    resource.add(linkTo(methodOn(RESTSampleSequenceFilesController.class).getSampleSequenceFiles(sampleId)).withRel(REL_SAMPLE_SEQUENCE_FILES));
    modelMap.addAttribute(RESTGenericController.RESOURCE_NAME, resource);
    return modelMap;
}
Also used : RootResource(ca.corefacility.bioinformatics.irida.web.assembler.resource.RootResource) SequencingObject(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequencingObject) Sample(ca.corefacility.bioinformatics.irida.model.sample.Sample) ModelMap(org.springframework.ui.ModelMap) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

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