Search in sources :

Example 41 with EntityNotFoundException

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

the class ProjectSampleMetadataController method setProjectSampleMetadataSampleId.

/**
 * Add the metadata to specific {@link Sample} based on the selected column to correspond to the {@link Sample} id.
 *
 * @param session
 * 		{@link HttpSession}.
 * @param projectId
 * 		{@link Long} identifier for the current {@link Project}.
 * @param sampleNameColumn
 * 		{@link String} the header to used to represent the {@link Sample} identifier.
 *
 * @return {@link Map} containing
 */
@RequestMapping(value = "/upload/setSampleColumn", method = RequestMethod.POST)
@ResponseBody
public Map<String, Object> setProjectSampleMetadataSampleId(HttpSession session, @PathVariable long projectId, @RequestParam String sampleNameColumn) {
    // Attempt to get the metadata from the sessions
    SampleMetadataStorage stored = (SampleMetadataStorage) session.getAttribute("pm-" + projectId);
    if (stored != null) {
        stored.setSampleNameColumn(sampleNameColumn);
        Project project = projectService.read(projectId);
        List<Map<String, String>> rows = stored.getRows();
        // Remove 'rows' since they are now going to be sorted into found and not found.
        stored.removeRows();
        List<Map<String, String>> found = new ArrayList<>();
        List<Map<String, String>> missing = new ArrayList<>();
        // Get the metadata out of the table.
        for (Map<String, String> row : rows) {
            try {
                // If this throws an error than the sample does not exist.
                sampleService.getSampleBySampleName(project, row.get(sampleNameColumn));
                found.add(row);
            } catch (EntityNotFoundException e) {
                missing.add(row);
            }
        }
        stored.saveFound(found);
        stored.saveMissing(missing);
    }
    return ImmutableMap.of("result", "complete");
}
Also used : SampleMetadataStorage(ca.corefacility.bioinformatics.irida.ria.utilities.SampleMetadataStorage) Project(ca.corefacility.bioinformatics.irida.model.project.Project) EntityNotFoundException(ca.corefacility.bioinformatics.irida.exceptions.EntityNotFoundException) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 42 with EntityNotFoundException

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

the class ProjectSamplesController method deleteProjectSamples.

/**
 * Remove a list of samples from a a Project.
 *
 * @param projectId
 * 		Id of the project to remove the samples from
 * @param sampleIds
 * 		An array of samples to remove from a project
 * @param locale
 * 		The locale of the web browser.
 *
 * @return Map containing either success or errors.
 */
@RequestMapping(value = "/projects/{projectId}/ajax/samples/delete", produces = MediaType.APPLICATION_JSON_VALUE, method = RequestMethod.POST)
@ResponseBody
public Map<String, Object> deleteProjectSamples(@PathVariable Long projectId, @RequestParam(value = "sampleIds[]") List<Long> sampleIds, Locale locale) {
    Project project = projectService.read(projectId);
    // Creating the message before removing the samples so that if the sample is only in one project it does not get removed
    // before its name can be used to create the message.
    Map<String, Object> result = new HashMap<>();
    if (sampleIds.size() == 1) {
        Sample sample = sampleService.read(sampleIds.get(0));
        result.put("message", messageSource.getMessage("project.samples.remove-success-singular", new Object[] { sample.getSampleName(), project.getLabel() }, locale));
    } else {
        result.put("message", messageSource.getMessage("project.samples.remove-success-plural", new Object[] { sampleIds.size(), project.getLabel() }, locale));
    }
    for (Long id : sampleIds) {
        try {
            Sample sample = sampleService.read(id);
            projectService.removeSampleFromProject(project, sample);
        } catch (EntityNotFoundException e) {
            result.put("error", "Cannot find sample with id: " + id);
        }
    }
    result.put("result", "success");
    return result;
}
Also used : Project(ca.corefacility.bioinformatics.irida.model.project.Project) Sample(ca.corefacility.bioinformatics.irida.model.sample.Sample) EntityNotFoundException(ca.corefacility.bioinformatics.irida.exceptions.EntityNotFoundException)

Example 43 with EntityNotFoundException

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

the class RemoteAPIController method read.

/**
 * Get an individual remote API's page
 *
 * @param apiId
 *            The ID of the api
 * @param model
 *            Model for the view
 * @param locale
 *            the locale specified by the browser.
 * @return The name of the remote api details page view
 */
@RequestMapping("/{apiId}")
public String read(@PathVariable Long apiId, Model model, Locale locale) {
    RemoteAPI remoteApi = remoteAPIService.read(apiId);
    model.addAttribute("remoteApi", remoteApi);
    try {
        RemoteAPIToken token = tokenService.getToken(remoteApi);
        model.addAttribute("tokenExpiry", dateTimeFormatter.print(token.getExpiryDate(), locale));
    } catch (EntityNotFoundException ex) {
        // Not returning a token here is acceptable. The view will have to
        // handle a state if the token does not exist
        logger.trace("No token for service " + remoteApi);
    }
    return DETAILS_PAGE;
}
Also used : RemoteAPI(ca.corefacility.bioinformatics.irida.model.RemoteAPI) RemoteAPIToken(ca.corefacility.bioinformatics.irida.model.RemoteAPIToken) EntityNotFoundException(ca.corefacility.bioinformatics.irida.exceptions.EntityNotFoundException)

Example 44 with EntityNotFoundException

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

the class SequenceFileController method downloadSequenceFileImages.

/**
 * Get images specific for individual sequence files.
 *
 * @param sequencingObjectId ID for the {@link SequencingObject}
 * @param sequenceFileId     Id for the {@link SequenceFile}
 * @param type               The type of image to get.
 * @param response           {@link HttpServletResponse}
 * @param thumb              Whether to scale the image for a thumbnail
 * @throws IOException if we can't write the image out to the response.
 */
@RequestMapping(value = "/sequenceFiles/img/{sequencingObjectId}/file/{sequenceFileId}/{type}")
public void downloadSequenceFileImages(@PathVariable Long sequencingObjectId, @PathVariable Long sequenceFileId, @PathVariable String type, HttpServletResponse response, @RequestParam(defaultValue = "false") boolean thumb) throws IOException {
    SequencingObject sequencingObject = sequencingObjectService.read(sequencingObjectId);
    SequenceFile file = sequencingObject.getFileWithId(sequenceFileId);
    AnalysisFastQC fastQC = analysisService.getFastQCAnalysisForSequenceFile(sequencingObject, file.getId());
    if (fastQC != null) {
        byte[] chart = new byte[0];
        if (type.equals(IMG_PERBASE)) {
            chart = fastQC.getPerBaseQualityScoreChart();
        } else if (type.equals(IMG_PERSEQUENCE)) {
            chart = fastQC.getPerSequenceQualityScoreChart();
        } else if (type.equals(IMG_DUPLICATION_LEVEL)) {
            chart = fastQC.getDuplicationLevelChart();
        } else {
            throw new EntityNotFoundException("Image not found");
        }
        if (thumb) {
            BufferedImage image = ImageIO.read(new ByteArrayInputStream(chart));
            BufferedImage thumbnail = Scalr.resize(image, Scalr.Method.QUALITY, Scalr.Mode.AUTOMATIC, 160, Scalr.OP_ANTIALIAS);
            ImageIO.write(thumbnail, "png", response.getOutputStream());
        } else {
            response.getOutputStream().write(chart);
        }
    }
    response.setContentType(MediaType.IMAGE_PNG_VALUE);
    response.flushBuffer();
}
Also used : SequencingObject(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequencingObject) SequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile) ByteArrayInputStream(java.io.ByteArrayInputStream) EntityNotFoundException(ca.corefacility.bioinformatics.irida.exceptions.EntityNotFoundException) AnalysisFastQC(ca.corefacility.bioinformatics.irida.model.workflow.analysis.AnalysisFastQC) BufferedImage(java.awt.image.BufferedImage) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 45 with EntityNotFoundException

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

the class OAuthTokenRestTemplateTest method testCreateRequestNoToken.

@Test(expected = IridaOAuthException.class)
public void testCreateRequestNoToken() throws URISyntaxException, IOException {
    when(tokenService.getToken(remoteAPI)).thenThrow(new EntityNotFoundException("no token for this service"));
    restTemplate.createRequest(serviceURI, HttpMethod.GET);
}
Also used : EntityNotFoundException(ca.corefacility.bioinformatics.irida.exceptions.EntityNotFoundException) Test(org.junit.Test)

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