Search in sources :

Example 1 with EntityNotFoundException

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

the class PasswordResetController method submitEmail.

/**
 * Create a password reset for the given email address
 *
 * @param email
 *            The email address to create a password reset for
 * @param model
 *            Model for the view
 *
 * @return Reset created page if the email exists in the system
 */
@RequestMapping(method = RequestMethod.POST)
public String submitEmail(@RequestParam String email, Model model) {
    setAuthentication();
    String page;
    model.addAttribute("email", email);
    try {
        User user = userService.loadUserByEmail(email);
        try {
            createNewPasswordReset(user);
            page = CREATED_REDIRECT + Base64.getEncoder().encodeToString(email.getBytes());
        } catch (final MailSendException e) {
            model.addAttribute("mailSendError", true);
            SecurityContextHolder.clearContext();
            page = noLoginResetPassword(model);
        }
    } catch (EntityNotFoundException ex) {
        model.addAttribute("emailError", true);
        SecurityContextHolder.clearContext();
        page = noLoginResetPassword(model);
    }
    return page;
}
Also used : User(ca.corefacility.bioinformatics.irida.model.user.User) MailSendException(org.springframework.mail.MailSendException) EntityNotFoundException(ca.corefacility.bioinformatics.irida.exceptions.EntityNotFoundException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with EntityNotFoundException

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

the class AnalysisController method getAjaxDownloadAnalysisSubmissionIndividualFile.

/**
 * Download single output files from an {@link AnalysisSubmission}
 *
 * @param analysisSubmissionId Id for a {@link AnalysisSubmission}
 * @param fileId               the id of the file to download
 * @param response             {@link HttpServletResponse}
 */
@RequestMapping(value = "/ajax/download/{analysisSubmissionId}/file/{fileId}")
public void getAjaxDownloadAnalysisSubmissionIndividualFile(@PathVariable Long analysisSubmissionId, @PathVariable Long fileId, HttpServletResponse response) {
    AnalysisSubmission analysisSubmission = analysisSubmissionService.read(analysisSubmissionId);
    Analysis analysis = analysisSubmission.getAnalysis();
    Set<AnalysisOutputFile> files = analysis.getAnalysisOutputFiles();
    Optional<AnalysisOutputFile> optFile = files.stream().filter(f -> f.getId().equals(fileId)).findAny();
    if (!optFile.isPresent()) {
        throw new EntityNotFoundException("Could not find file with id " + fileId);
    }
    FileUtilities.createSingleFileResponse(response, optFile.get());
}
Also used : PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) AnalysisType(ca.corefacility.bioinformatics.irida.model.enums.AnalysisType) ProjectService(ca.corefacility.bioinformatics.irida.service.ProjectService) FileUtilities(ca.corefacility.bioinformatics.irida.ria.utilities.FileUtilities) Model(org.springframework.ui.Model) MetadataTemplateField(ca.corefacility.bioinformatics.irida.model.sample.MetadataTemplateField) DataTablesResponse(ca.corefacility.bioinformatics.irida.ria.web.components.datatables.DataTablesResponse) AnalysisSubmissionService(ca.corefacility.bioinformatics.irida.service.AnalysisSubmissionService) MetadataTemplate(ca.corefacility.bioinformatics.irida.model.sample.MetadataTemplate) SecurityContextHolder(org.springframework.security.core.context.SecurityContextHolder) TypeReference(com.fasterxml.jackson.core.type.TypeReference) Path(java.nio.file.Path) JsonParseException(com.fasterxml.jackson.core.JsonParseException) ProjectMetadataTemplateJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectMetadataTemplateJoin) IridaWorkflowNotFoundException(ca.corefacility.bioinformatics.irida.exceptions.IridaWorkflowNotFoundException) AnalysisSubmission(ca.corefacility.bioinformatics.irida.model.workflow.submission.AnalysisSubmission) SequencingObjectService(ca.corefacility.bioinformatics.irida.service.SequencingObjectService) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) MediaType(org.springframework.http.MediaType) Collectors(java.util.stream.Collectors) AnalysesListingService(ca.corefacility.bioinformatics.irida.ria.web.services.AnalysesListingService) Principal(java.security.Principal) org.springframework.web.bind.annotation(org.springframework.web.bind.annotation) User(ca.corefacility.bioinformatics.irida.model.user.User) SampleService(ca.corefacility.bioinformatics.irida.service.sample.SampleService) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) Authentication(org.springframework.security.core.Authentication) java.util(java.util) ExecutionManagerException(ca.corefacility.bioinformatics.irida.exceptions.ExecutionManagerException) UpdateAnalysisSubmissionPermission(ca.corefacility.bioinformatics.irida.security.permissions.analysis.UpdateAnalysisSubmissionPermission) Analysis(ca.corefacility.bioinformatics.irida.model.workflow.analysis.Analysis) EntityNotFoundException(ca.corefacility.bioinformatics.irida.exceptions.EntityNotFoundException) Controller(org.springframework.stereotype.Controller) MetadataEntry(ca.corefacility.bioinformatics.irida.model.sample.metadata.MetadataEntry) MetadataTemplateService(ca.corefacility.bioinformatics.irida.service.sample.MetadataTemplateService) ToolExecution(ca.corefacility.bioinformatics.irida.model.workflow.analysis.ToolExecution) MessageSource(org.springframework.context.MessageSource) Logger(org.slf4j.Logger) Files(java.nio.file.Files) AnalysisState(ca.corefacility.bioinformatics.irida.model.enums.AnalysisState) DataTablesRequest(ca.corefacility.bioinformatics.irida.ria.web.components.datatables.config.DataTablesRequest) IridaWorkflowsService(ca.corefacility.bioinformatics.irida.service.workflow.IridaWorkflowsService) HttpServletResponse(javax.servlet.http.HttpServletResponse) SequenceFilePair(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFilePair) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Sample(ca.corefacility.bioinformatics.irida.model.sample.Sample) Project(ca.corefacility.bioinformatics.irida.model.project.Project) ProjectAnalysisSubmissionJoin(ca.corefacility.bioinformatics.irida.model.workflow.submission.ProjectAnalysisSubmissionJoin) AnalysisOutputFileInfo(ca.corefacility.bioinformatics.irida.ria.web.analysis.dto.AnalysisOutputFileInfo) AnalysisOutputFile(ca.corefacility.bioinformatics.irida.model.workflow.analysis.AnalysisOutputFile) java.io(java.io) UserService(ca.corefacility.bioinformatics.irida.service.user.UserService) JobError(ca.corefacility.bioinformatics.irida.model.workflow.analysis.JobError) IridaWorkflow(ca.corefacility.bioinformatics.irida.model.workflow.IridaWorkflow) DataTablesParams(ca.corefacility.bioinformatics.irida.ria.web.components.datatables.DataTablesParams) Analysis(ca.corefacility.bioinformatics.irida.model.workflow.analysis.Analysis) AnalysisSubmission(ca.corefacility.bioinformatics.irida.model.workflow.submission.AnalysisSubmission) EntityNotFoundException(ca.corefacility.bioinformatics.irida.exceptions.EntityNotFoundException) AnalysisOutputFile(ca.corefacility.bioinformatics.irida.model.workflow.analysis.AnalysisOutputFile)

Example 3 with EntityNotFoundException

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

the class AnalysisController method getDetailsPage.

/**
 * View details about an individual analysis submission
 *
 * @param submissionId the ID of the submission
 * @param model        Model for the view
 * @param locale       User's locale
 * @return name of the details page view
 */
@RequestMapping(value = "/{submissionId}", produces = MediaType.TEXT_HTML_VALUE)
public String getDetailsPage(@PathVariable Long submissionId, Model model, Locale locale) {
    logger.trace("reading analysis submission " + submissionId);
    AnalysisSubmission submission = analysisSubmissionService.read(submissionId);
    model.addAttribute("analysisSubmission", submission);
    UUID workflowUUID = submission.getWorkflowId();
    logger.trace("Workflow ID is " + workflowUUID);
    IridaWorkflow iridaWorkflow;
    try {
        iridaWorkflow = workflowsService.getIridaWorkflow(workflowUUID);
    } catch (IridaWorkflowNotFoundException e) {
        logger.error("Error finding workflow, ", e);
        throw new EntityNotFoundException("Couldn't find workflow for submission " + submission.getId(), e);
    }
    // Get the name of the workflow
    AnalysisType analysisType = iridaWorkflow.getWorkflowDescription().getAnalysisType();
    model.addAttribute("analysisType", analysisType);
    String viewName = getViewForAnalysisType(analysisType);
    String workflowName = messageSource.getMessage("workflow." + analysisType.toString() + ".title", null, locale);
    model.addAttribute("workflowName", workflowName);
    model.addAttribute("version", iridaWorkflow.getWorkflowDescription().getVersion());
    // Input files
    // - Paired
    Set<SequenceFilePair> inputFilePairs = sequencingObjectService.getSequencingObjectsOfTypeForAnalysisSubmission(submission, SequenceFilePair.class);
    model.addAttribute("paired_end", inputFilePairs);
    // Check if user can update analysis
    Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
    model.addAttribute("updatePermission", updateAnalysisPermission.isAllowed(authentication, submission));
    if (iridaWorkflow.getWorkflowDescription().requiresReference() && submission.getReferenceFile().isPresent()) {
        logger.debug("Adding reference file to page for submission with id [" + submission.getId() + "].");
        model.addAttribute("referenceFile", submission.getReferenceFile().get());
    } else {
        logger.debug("No reference file required for workflow.");
    }
    /*
		 * Preview information
		 */
    try {
        if (submission.getAnalysisState().equals(AnalysisState.COMPLETED)) {
            if (analysisType.equals(AnalysisType.PHYLOGENOMICS)) {
                tree(submission, model);
            } else if (analysisType.equals(AnalysisType.SISTR_TYPING)) {
                model.addAttribute("sistr", true);
            }
        }
    } catch (IOException e) {
        logger.error("Couldn't get preview for analysis", e);
    }
    return viewName;
}
Also used : IridaWorkflowNotFoundException(ca.corefacility.bioinformatics.irida.exceptions.IridaWorkflowNotFoundException) AnalysisType(ca.corefacility.bioinformatics.irida.model.enums.AnalysisType) SequenceFilePair(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFilePair) IridaWorkflow(ca.corefacility.bioinformatics.irida.model.workflow.IridaWorkflow) Authentication(org.springframework.security.core.Authentication) AnalysisSubmission(ca.corefacility.bioinformatics.irida.model.workflow.submission.AnalysisSubmission) EntityNotFoundException(ca.corefacility.bioinformatics.irida.exceptions.EntityNotFoundException)

Example 4 with EntityNotFoundException

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

the class AnalysisController method getSistrAnalysis.

/**
 * Get the sistr analysis information to display
 *
 * @param id ID of the analysis submission
 * @return Json results for the SISTR analysis
 */
@SuppressWarnings("resource")
@RequestMapping("/ajax/sistr/{id}")
@ResponseBody
public Map<String, Object> getSistrAnalysis(@PathVariable Long id) {
    AnalysisSubmission submission = analysisSubmissionService.read(id);
    Collection<Sample> samples = sampleService.getSamplesForAnalysisSubmission(submission);
    Map<String, Object> result = ImmutableMap.of("parse_results_error", true);
    final String sistrFileKey = "sistr-predictions";
    // Get details about the workflow
    UUID workflowUUID = submission.getWorkflowId();
    IridaWorkflow iridaWorkflow;
    try {
        iridaWorkflow = workflowsService.getIridaWorkflow(workflowUUID);
    } catch (IridaWorkflowNotFoundException e) {
        logger.error("Error finding workflow, ", e);
        throw new EntityNotFoundException("Couldn't find workflow for submission " + submission.getId(), e);
    }
    AnalysisType analysisType = iridaWorkflow.getWorkflowDescription().getAnalysisType();
    if (analysisType.equals(AnalysisType.SISTR_TYPING)) {
        Analysis analysis = submission.getAnalysis();
        Path path = analysis.getAnalysisOutputFile(sistrFileKey).getFile();
        try {
            String json = new Scanner(new BufferedReader(new FileReader(path.toFile()))).useDelimiter("\\Z").next();
            // verify file is proper json file
            ObjectMapper mapper = new ObjectMapper();
            List<Map<String, Object>> sistrResults = mapper.readValue(json, new TypeReference<List<Map<String, Object>>>() {
            });
            if (sistrResults.size() > 0) {
                // should only ever be one sample for these results
                if (samples.size() == 1) {
                    Sample sample = samples.iterator().next();
                    result = sistrResults.get(0);
                    result.put("parse_results_error", false);
                    result.put("sample_name", sample.getSampleName());
                } else {
                    logger.error("Invalid number of associated samles for submission " + submission);
                }
            } else {
                logger.error("SISTR results for file [" + path + "] are not correctly formatted");
            }
        } catch (FileNotFoundException e) {
            logger.error("File [" + path + "] not found", e);
        } catch (JsonParseException | JsonMappingException e) {
            logger.error("Error attempting to parse file [" + path + "] as JSON", e);
        } catch (IOException e) {
            logger.error("Error reading file [" + path + "]", e);
        }
    }
    return result;
}
Also used : AnalysisType(ca.corefacility.bioinformatics.irida.model.enums.AnalysisType) IridaWorkflow(ca.corefacility.bioinformatics.irida.model.workflow.IridaWorkflow) AnalysisSubmission(ca.corefacility.bioinformatics.irida.model.workflow.submission.AnalysisSubmission) JsonParseException(com.fasterxml.jackson.core.JsonParseException) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Path(java.nio.file.Path) Sample(ca.corefacility.bioinformatics.irida.model.sample.Sample) EntityNotFoundException(ca.corefacility.bioinformatics.irida.exceptions.EntityNotFoundException) IridaWorkflowNotFoundException(ca.corefacility.bioinformatics.irida.exceptions.IridaWorkflowNotFoundException) Analysis(ca.corefacility.bioinformatics.irida.model.workflow.analysis.Analysis) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 5 with EntityNotFoundException

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

the class ProjectsController method syncProject.

/**
 * Get a {@link Project} from a remote api and mark it to be synchronized in
 * this IRIDA installation
 *
 * @param url           the URL of the remote project
 * @param syncFrequency How often to sync the project
 * @param model         Model for the view
 * @return Redirect to the new project. If an oauth exception occurs it will
 * be forwarded back to the creation page.
 */
@RequestMapping(value = "/projects/synchronize", method = RequestMethod.POST)
public String syncProject(@RequestParam String url, @RequestParam ProjectSyncFrequency syncFrequency, Model model) {
    try {
        Project read = projectRemoteService.read(url);
        read.setId(null);
        read.getRemoteStatus().setSyncStatus(SyncStatus.MARKED);
        read.setSyncFrequency(syncFrequency);
        read = projectService.create(read);
        return "redirect:/projects/" + read.getId() + "/metadata";
    } catch (IridaOAuthException ex) {
        Map<String, String> errors = new HashMap<>();
        errors.put("oauthError", ex.getMessage());
        model.addAttribute("errors", errors);
        return getSynchronizeProjectPage(model);
    } catch (EntityNotFoundException ex) {
        Map<String, String> errors = new HashMap<>();
        errors.put("urlError", ex.getMessage());
        model.addAttribute("errors", errors);
        return getSynchronizeProjectPage(model);
    }
}
Also used : IridaOAuthException(ca.corefacility.bioinformatics.irida.exceptions.IridaOAuthException) DTProject(ca.corefacility.bioinformatics.irida.ria.web.models.datatables.DTProject) Project(ca.corefacility.bioinformatics.irida.model.project.Project) EntityNotFoundException(ca.corefacility.bioinformatics.irida.exceptions.EntityNotFoundException) ImmutableMap(com.google.common.collect.ImmutableMap) 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