Search in sources :

Example 11 with ResourceCollection

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;
}
Also used : Project(ca.corefacility.bioinformatics.irida.model.project.Project) Sample(ca.corefacility.bioinformatics.irida.model.sample.Sample) ModelMap(org.springframework.ui.ModelMap) Join(ca.corefacility.bioinformatics.irida.model.joins.Join) ResourceCollection(ca.corefacility.bioinformatics.irida.web.assembler.resource.ResourceCollection) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 12 with ResourceCollection

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;
}
Also used : Project(ca.corefacility.bioinformatics.irida.model.project.Project) User(ca.corefacility.bioinformatics.irida.model.user.User) ModelMap(org.springframework.ui.ModelMap) Join(ca.corefacility.bioinformatics.irida.model.joins.Join) RESTUsersController(ca.corefacility.bioinformatics.irida.web.controller.api.RESTUsersController) ResourceCollection(ca.corefacility.bioinformatics.irida.web.assembler.resource.ResourceCollection) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 13 with ResourceCollection

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;
}
Also used : AnalysisType(ca.corefacility.bioinformatics.irida.model.enums.AnalysisType) IridaWorkflowNotFoundException(ca.corefacility.bioinformatics.irida.exceptions.IridaWorkflowNotFoundException) ModelMap(org.springframework.ui.ModelMap) AnalysisSubmission(ca.corefacility.bioinformatics.irida.model.workflow.submission.AnalysisSubmission) IridaWorkflowDescription(ca.corefacility.bioinformatics.irida.model.workflow.description.IridaWorkflowDescription) EntityNotFoundException(ca.corefacility.bioinformatics.irida.exceptions.EntityNotFoundException) UUID(java.util.UUID) ResourceCollection(ca.corefacility.bioinformatics.irida.web.assembler.resource.ResourceCollection) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 14 with ResourceCollection

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;
}
Also used : SequenceFilePair(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFilePair) ModelMap(org.springframework.ui.ModelMap) AnalysisSubmission(ca.corefacility.bioinformatics.irida.model.workflow.submission.AnalysisSubmission) SampleSequencingObjectJoin(ca.corefacility.bioinformatics.irida.model.sample.SampleSequencingObjectJoin) ResourceCollection(ca.corefacility.bioinformatics.irida.web.assembler.resource.ResourceCollection) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 15 with ResourceCollection

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()));
}
Also used : User(ca.corefacility.bioinformatics.irida.model.user.User) ProjectUserJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectUserJoin) ModelMap(org.springframework.ui.ModelMap) ArrayList(java.util.ArrayList) Join(ca.corefacility.bioinformatics.irida.model.joins.Join) ProjectUserJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectUserJoin) Project(ca.corefacility.bioinformatics.irida.model.project.Project) Link(org.springframework.hateoas.Link) ResourceCollection(ca.corefacility.bioinformatics.irida.web.assembler.resource.ResourceCollection) Test(org.junit.Test)

Aggregations

ResourceCollection (ca.corefacility.bioinformatics.irida.web.assembler.resource.ResourceCollection)18 ModelMap (org.springframework.ui.ModelMap)18 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)12 Project (ca.corefacility.bioinformatics.irida.model.project.Project)10 Sample (ca.corefacility.bioinformatics.irida.model.sample.Sample)7 Join (ca.corefacility.bioinformatics.irida.model.joins.Join)6 Test (org.junit.Test)6 Link (org.springframework.hateoas.Link)6 SampleSequencingObjectJoin (ca.corefacility.bioinformatics.irida.model.sample.SampleSequencingObjectJoin)5 User (ca.corefacility.bioinformatics.irida.model.user.User)5 AnalysisSubmission (ca.corefacility.bioinformatics.irida.model.workflow.submission.AnalysisSubmission)5 SingleEndSequenceFile (ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile)3 EntityNotFoundException (ca.corefacility.bioinformatics.irida.exceptions.EntityNotFoundException)2 AnalysisType (ca.corefacility.bioinformatics.irida.model.enums.AnalysisType)2 ProjectSampleJoin (ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectSampleJoin)2 ProjectUserJoin (ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectUserJoin)2 SequenceFile (ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile)2 SequencingObject (ca.corefacility.bioinformatics.irida.model.sequenceFile.SequencingObject)2 LabelledRelationshipResource (ca.corefacility.bioinformatics.irida.web.assembler.resource.LabelledRelationshipResource)2 IridaWorkflowNotFoundException (ca.corefacility.bioinformatics.irida.exceptions.IridaWorkflowNotFoundException)1