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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations