Search in sources :

Example 21 with EntityNotFoundException

use of ca.corefacility.bioinformatics.irida.exceptions.EntityNotFoundException in project irida by phac-nml.

the class UserRepositoryImpl method loadUserByEmail.

/**
 * {@inheritDoc}
 */
@Override
public User loadUserByEmail(String email) throws EntityNotFoundException {
    Query q = entityManager.createQuery("from User u where u.email = :email");
    q.setParameter("email", email);
    try {
        User u = (User) q.getSingleResult();
        if (u == null) {
            throw new EntityNotFoundException("Could not find email.");
        }
        return u;
    } catch (Exception e) {
        throw new EntityNotFoundException("Could not find email.", e);
    }
}
Also used : User(ca.corefacility.bioinformatics.irida.model.user.User) Query(javax.persistence.Query) EntityNotFoundException(ca.corefacility.bioinformatics.irida.exceptions.EntityNotFoundException) UsernameNotFoundException(org.springframework.security.core.userdetails.UsernameNotFoundException) EntityNotFoundException(ca.corefacility.bioinformatics.irida.exceptions.EntityNotFoundException)

Example 22 with EntityNotFoundException

use of ca.corefacility.bioinformatics.irida.exceptions.EntityNotFoundException in project irida by phac-nml.

the class RESTSampleSequenceFilesController method readQCForSequenceFile.

/**
 * Get the fastqc metrics for a {@link SequenceFile}
 *
 * @param sampleId
 *            {@link Sample} id of the file
 * @param objectType
 *            type of {@link SequencingObject}
 * @param objectId
 *            id of the {@link SequencingObject}
 * @param fileId
 *            id of the {@link SequenceFile}
 * @return an {@link AnalysisFastQC} for the file
 */
@RequestMapping(value = "/api/samples/{sampleId}/{objectType}/{objectId}/files/{fileId}/qc", method = RequestMethod.GET)
public ModelMap readQCForSequenceFile(@PathVariable Long sampleId, @PathVariable String objectType, @PathVariable Long objectId, @PathVariable Long fileId) {
    ModelMap modelMap = new ModelMap();
    Sample sample = sampleService.read(sampleId);
    SequencingObject readSequencingObjectForSample = sequencingObjectService.readSequencingObjectForSample(sample, objectId);
    AnalysisFastQC fastQCAnalysisForSequenceFile = analysisService.getFastQCAnalysisForSequenceFile(readSequencingObjectForSample, fileId);
    if (fastQCAnalysisForSequenceFile == null) {
        throw new EntityNotFoundException("No QC data for file");
    }
    fastQCAnalysisForSequenceFile.add(linkTo(methodOn(RESTSampleSequenceFilesController.class).readSequenceFileForSequencingObject(sampleId, objectType, objectId, fileId)).withRel(REL_QC_SEQFILE));
    fastQCAnalysisForSequenceFile.add(linkTo(methodOn(RESTSampleSequenceFilesController.class).readQCForSequenceFile(sampleId, objectType, objectId, fileId)).withSelfRel());
    modelMap.addAttribute(RESTGenericController.RESOURCE_NAME, fastQCAnalysisForSequenceFile);
    return modelMap;
}
Also used : SequencingObject(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequencingObject) Sample(ca.corefacility.bioinformatics.irida.model.sample.Sample) ModelMap(org.springframework.ui.ModelMap) EntityNotFoundException(ca.corefacility.bioinformatics.irida.exceptions.EntityNotFoundException) AnalysisFastQC(ca.corefacility.bioinformatics.irida.model.workflow.analysis.AnalysisFastQC) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 23 with EntityNotFoundException

use of ca.corefacility.bioinformatics.irida.exceptions.EntityNotFoundException in project irida by phac-nml.

the class RESTProjectAnalysisController method getProjectAnalysesByType.

/**
 * Get the list of {@link AnalysisSubmission}s for this {@link Project} by
 * type of analysis.
 *
 * @param projectId
 *            The {@link Project} to search.
 * @param type
 *            The analysis type to search for.
 * @return A list of {@link AnalysisSubmission}s for the given
 *         {@link Project} by the given type.
 * @throws IridaWorkflowNotFoundException
 *             If the {@link AnalysisSubmission} is linked to a workflow not
 *             found in IRIDA.
 */
@RequestMapping(value = "/api/projects/{projectId}/analyses/{type}", method = RequestMethod.GET)
public ModelMap getProjectAnalysesByType(@PathVariable Long projectId, @PathVariable String type) throws IridaWorkflowNotFoundException {
    logger.debug("Loading analyses for project [" + projectId + "] by type [" + type + "]");
    if (!RESTAnalysisSubmissionController.ANALYSIS_TYPES.containsKey(type)) {
        throw new EntityNotFoundException("Analysis type [" + type + "] not found");
    }
    AnalysisType analysisType = RESTAnalysisSubmissionController.ANALYSIS_TYPES.get(type);
    ModelMap modelMap = new ModelMap();
    Project p = projectService.read(projectId);
    Collection<AnalysisSubmission> analysisSubmissions = analysisSubmissionService.getAnalysisSubmissionsSharedToProject(p);
    ResourceCollection<AnalysisSubmission> analysisResources = new ResourceCollection<>(analysisSubmissions.size());
    for (AnalysisSubmission submission : analysisSubmissions) {
        IridaWorkflow iridaWorkflow = iridaWorkflowsService.getIridaWorkflow(submission.getWorkflowId());
        AnalysisType submissionAnalysisType = iridaWorkflow.getWorkflowDescription().getAnalysisType();
        if (analysisType.equals(submissionAnalysisType)) {
            submission.add(linkTo(methodOn(RESTAnalysisSubmissionController.class, Long.class).getResource(submission.getId())).withSelfRel());
            analysisResources.add(submission);
        }
    }
    analysisResources.add(linkTo(methodOn(RESTProjectsController.class, Long.class).getResource(projectId)).withRel(PROJECT_REL));
    analysisResources.add(linkTo(methodOn(RESTProjectAnalysisController.class, Long.class).getProjectAnalysesByType(projectId, type)).withSelfRel());
    modelMap.addAttribute(ANALYSIS_RESOURCES, analysisResources);
    return modelMap;
}
Also used : AnalysisType(ca.corefacility.bioinformatics.irida.model.enums.AnalysisType) Project(ca.corefacility.bioinformatics.irida.model.project.Project) IridaWorkflow(ca.corefacility.bioinformatics.irida.model.workflow.IridaWorkflow) ModelMap(org.springframework.ui.ModelMap) AnalysisSubmission(ca.corefacility.bioinformatics.irida.model.workflow.submission.AnalysisSubmission) EntityNotFoundException(ca.corefacility.bioinformatics.irida.exceptions.EntityNotFoundException) ResourceCollection(ca.corefacility.bioinformatics.irida.web.assembler.resource.ResourceCollection) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 24 with EntityNotFoundException

use of ca.corefacility.bioinformatics.irida.exceptions.EntityNotFoundException in project irida by phac-nml.

the class RESTAnalysisSubmissionController method getAnalysisOutputFileContents.

/**
 * Get the actual file contents for an analysis output file.
 *
 * @param submissionId
 *            The {@link AnalysisSubmission} id
 * @param fileType
 *            The {@link AnalysisOutputFile} type as defined in the
 *            {@link Analysis} subclass
 * @return a {@link FileSystemResource} containing the contents of the
 *         {@link AnalysisOutputFile}.
 */
@RequestMapping(value = "/{submissionId}/analysis/file/{fileType}", produces = MediaType.TEXT_PLAIN_VALUE)
@ResponseBody
public FileSystemResource getAnalysisOutputFileContents(@PathVariable Long submissionId, @PathVariable String fileType) {
    AnalysisSubmission read = analysisSubmissionService.read(submissionId);
    if (read.getAnalysisState() != AnalysisState.COMPLETED) {
        throw new EntityNotFoundException("Analysis is not completed");
    }
    AnalysisOutputFile analysisOutputFile = read.getAnalysis().getAnalysisOutputFile(fileType);
    return new FileSystemResource(analysisOutputFile.getFile().toFile());
}
Also used : AnalysisSubmission(ca.corefacility.bioinformatics.irida.model.workflow.submission.AnalysisSubmission) EntityNotFoundException(ca.corefacility.bioinformatics.irida.exceptions.EntityNotFoundException) FileSystemResource(org.springframework.core.io.FileSystemResource) AnalysisOutputFile(ca.corefacility.bioinformatics.irida.model.workflow.analysis.AnalysisOutputFile) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 25 with EntityNotFoundException

use of ca.corefacility.bioinformatics.irida.exceptions.EntityNotFoundException 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)

Aggregations

EntityNotFoundException (ca.corefacility.bioinformatics.irida.exceptions.EntityNotFoundException)45 Test (org.junit.Test)12 Sample (ca.corefacility.bioinformatics.irida.model.sample.Sample)11 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)11 AnalysisSubmission (ca.corefacility.bioinformatics.irida.model.workflow.submission.AnalysisSubmission)10 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)8 Project (ca.corefacility.bioinformatics.irida.model.project.Project)7 Transactional (org.springframework.transaction.annotation.Transactional)7 User (ca.corefacility.bioinformatics.irida.model.user.User)6 RemoteAPIToken (ca.corefacility.bioinformatics.irida.model.RemoteAPIToken)5 AnalysisType (ca.corefacility.bioinformatics.irida.model.enums.AnalysisType)5 SequenceFile (ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile)5 AnalysisFastQC (ca.corefacility.bioinformatics.irida.model.workflow.analysis.AnalysisFastQC)5 ImmutableMap (com.google.common.collect.ImmutableMap)5 IridaWorkflowNotFoundException (ca.corefacility.bioinformatics.irida.exceptions.IridaWorkflowNotFoundException)4 SequencingObject (ca.corefacility.bioinformatics.irida.model.sequenceFile.SequencingObject)4 SingleEndSequenceFile (ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile)4 IridaWorkflow (ca.corefacility.bioinformatics.irida.model.workflow.IridaWorkflow)4 Analysis (ca.corefacility.bioinformatics.irida.model.workflow.analysis.Analysis)4 Path (java.nio.file.Path)4