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