use of ca.corefacility.bioinformatics.irida.web.assembler.resource.ResourceCollection in project irida by phac-nml.
the class RESTProjectSamplesController method getProjectSamples.
/**
* Get the list of {@link Sample} associated with this {@link Project}.
*
* @param projectId
* the identifier of the {@link Project} to get the
* {@link Sample}s for.
* @return the list of {@link Sample}s associated with this {@link Project}.
*/
@RequestMapping(value = "/api/projects/{projectId}/samples", method = RequestMethod.GET)
public ModelMap getProjectSamples(@PathVariable Long projectId) {
ModelMap modelMap = new ModelMap();
Project p = projectService.read(projectId);
List<Join<Project, Sample>> relationships = sampleService.getSamplesForProject(p);
ResourceCollection<Sample> sampleResources = new ResourceCollection<>(relationships.size());
for (Join<Project, Sample> r : relationships) {
Sample sample = r.getObject();
addLinksForSample(Optional.of(p), sample);
sampleResources.add(sample);
}
sampleResources.add(linkTo(methodOn(RESTProjectSamplesController.class).getProjectSamples(projectId)).withSelfRel());
modelMap.addAttribute(RESTGenericController.RESOURCE_NAME, sampleResources);
return modelMap;
}
use of ca.corefacility.bioinformatics.irida.web.assembler.resource.ResourceCollection in project irida by phac-nml.
the class RESTProjectUsersController method getUsersForProject.
/**
* Get all users associated with a project.
*
* @param projectId
* the project id to get users for.
* @return a model with a collection of user resources.
* @throws ProjectWithoutOwnerException
* If removing a user will leave the project without an owner.
* Should NEVER be thrown in this method, but needs to be
* listed.
*/
@RequestMapping(value = "/api/projects/{projectId}/users", method = RequestMethod.GET)
public ModelMap getUsersForProject(@PathVariable Long projectId) throws ProjectWithoutOwnerException {
ResourceCollection<User> resources = new ResourceCollection<>();
// get all of the users belonging to this project
Project p = projectService.read(projectId);
Collection<Join<Project, User>> relationships = userService.getUsersForProject(p);
// and convert to a resource suitable for sending back to the client.
for (Join<Project, User> r : relationships) {
User u = r.getObject();
u.add(linkTo(RESTUsersController.class).slash(u.getUsername()).withSelfRel());
u.add(linkTo(methodOn(RESTProjectUsersController.class).removeUserFromProject(projectId, u.getUsername())).withRel(RESTGenericController.REL_RELATIONSHIP));
resources.add(u);
}
// add a link to this resource to the response
resources.add(linkTo(methodOn(RESTProjectUsersController.class, String.class).getUsersForProject(projectId)).withSelfRel());
// prepare the response for the client
ModelMap model = new ModelMap();
model.addAttribute(RESTGenericController.RESOURCE_NAME, resources);
return model;
}
use of ca.corefacility.bioinformatics.irida.web.assembler.resource.ResourceCollection in project irida by phac-nml.
the class RESTAnalysisSubmissionController method listOfType.
/**
* Get all analyses of a given type
*
* @param type
* The type to request
* @return ModelMap containing the requested type of resource
*/
@RequestMapping("/analysisType/{type}")
public ModelMap listOfType(@PathVariable String type) {
ModelMap model = new ModelMap();
if (!ANALYSIS_TYPES.containsKey(type)) {
throw new EntityNotFoundException("Analysis type not found");
}
AnalysisType analysisType = ANALYSIS_TYPES.get(type);
Set<UUID> workflowIds;
try {
workflowIds = iridaWorkflowsService.getAllWorkflowsByType(analysisType).stream().map(IridaWorkflow::getWorkflowDescription).map(IridaWorkflowDescription::getId).collect(Collectors.toSet());
} catch (IridaWorkflowNotFoundException e) {
throw new EntityNotFoundException("Analysis type not found", e);
}
List<AnalysisSubmission> analysesOfType = analysisSubmissionService.getAnalysisSubmissionsAccessibleByCurrentUserByWorkflowIds(workflowIds);
ResourceCollection<AnalysisSubmission> resourceCollection = new ResourceCollection<>(analysesOfType.size());
for (AnalysisSubmission s : analysesOfType) {
s.add(constructCustomResourceLinks(s));
s.add(linkTo(methodOn(RESTAnalysisSubmissionController.class).getResource(s.getId())).withSelfRel());
resourceCollection.add(s);
}
resourceCollection.add(linkTo(methodOn(RESTAnalysisSubmissionController.class).listOfType(type)).withSelfRel());
resourceCollection.add(linkTo(RESTAnalysisSubmissionController.class).withRel(SUBMISSIONS_REL));
model.addAttribute(RESOURCE_NAME, resourceCollection);
return model;
}
use of ca.corefacility.bioinformatics.irida.web.assembler.resource.ResourceCollection in project irida by phac-nml.
the class RESTAnalysisSubmissionController method getAnalysisInputFilePairs.
/**
* Get the {@link SequenceFilePair}s used for the {@link AnalysisSubmission}
*
* @param identifier
* {@link AnalysisSubmission} id
* @return list of {@link SequenceFilePair}s
*/
@RequestMapping("/{identifier}/sequenceFiles/pairs")
public ModelMap getAnalysisInputFilePairs(@PathVariable Long identifier) {
ModelMap map = new ModelMap();
AnalysisSubmission analysisSubmission = analysisSubmissionService.read(identifier);
Set<SequenceFilePair> pairs = sequencingObjectService.getSequencingObjectsOfTypeForAnalysisSubmission(analysisSubmission, SequenceFilePair.class);
ResourceCollection<SequenceFilePair> resources = new ResourceCollection<>(pairs.size());
for (SequenceFilePair pair : pairs) {
SampleSequencingObjectJoin join = sampleService.getSampleForSequencingObject(pair);
if (join != null) {
Long sampleId = join.getSubject().getId();
pair = RESTSampleSequenceFilesController.addSequencingObjectLinks(pair, sampleId);
resources.add(pair);
}
}
resources.add(linkTo(methodOn(RESTAnalysisSubmissionController.class).getAnalysisInputFilePairs(identifier)).withSelfRel());
map.addAttribute(RESTGenericController.RESOURCE_NAME, resources);
return map;
}
use of ca.corefacility.bioinformatics.irida.web.assembler.resource.ResourceCollection in project irida by phac-nml.
the class UserControllerTest method testGetUserProjects.
@Test
public void testGetUserProjects() {
// set up expectations
String username = "fbristow";
User u = new User();
u.setUsername(username);
List<Join<Project, User>> projects = new ArrayList<>();
Project p = TestDataFactory.constructProject();
Join<Project, User> join = new ProjectUserJoin(p, u, ProjectRole.PROJECT_USER);
projects.add(join);
// set up mocks
when(userService.getUserByUsername(username)).thenReturn(u);
when(projectService.getProjectsForUser(u)).thenReturn(projects);
// run the test
ModelMap output = controller.getUserProjects(username);
@SuppressWarnings("unchecked") ResourceCollection<Project> pulledProjects = (ResourceCollection<Project>) output.get("projectResources");
List<Project> projectResources = pulledProjects.getResources();
assertEquals(1, projectResources.size());
Project resource = projectResources.get(0);
assertEquals(p.getName(), resource.getName());
assertEquals(1, resource.getLinks().size());
Link link = resource.getLinks().get(0);
assertEquals(Link.REL_SELF, link.getRel());
assertTrue(link.getHref().contains(p.getId().toString()));
}
Aggregations