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