Search in sources :

Example 26 with EntityNotFoundException

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

the class RESTAnalysisSubmissionController method getAnalysisForSubmission.

/**
 * Get the {@link Analysis} for an {@link AnalysisSubmission}.
 *
 * @param identifier
 *            {@link AnalysisSubmission} identifier to read
 * @return ModelMap containing the {@link Analysis}
 */
@RequestMapping("/{identifier}/analysis")
public ModelMap getAnalysisForSubmission(@PathVariable Long identifier) {
    ModelMap model = new ModelMap();
    AnalysisSubmission read = analysisSubmissionService.read(identifier);
    if (read.getAnalysisState() != AnalysisState.COMPLETED) {
        throw new EntityNotFoundException("Analysis is not completed");
    }
    Analysis analysis = read.getAnalysis();
    analysis.add(linkTo(methodOn(RESTAnalysisSubmissionController.class).getAnalysisForSubmission(identifier)).withSelfRel());
    /*
		 * Add links to the available files
		 */
    for (String name : analysis.getAnalysisOutputFileNames()) {
        analysis.add(linkTo(methodOn(RESTAnalysisSubmissionController.class).getAnalysisOutputFile(identifier, name)).withRel(FILE_REL + "/" + name));
    }
    model.addAttribute(RESOURCE_NAME, analysis);
    return model;
}
Also used : Analysis(ca.corefacility.bioinformatics.irida.model.workflow.analysis.Analysis) ModelMap(org.springframework.ui.ModelMap) AnalysisSubmission(ca.corefacility.bioinformatics.irida.model.workflow.submission.AnalysisSubmission) EntityNotFoundException(ca.corefacility.bioinformatics.irida.exceptions.EntityNotFoundException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 27 with EntityNotFoundException

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

the class RemoteAPITokenServiceImplIT method testDeleteToken.

@Test(expected = EntityNotFoundException.class)
public void testDeleteToken() {
    RemoteAPI api = null;
    try {
        api = apiService.read(1L);
        tokenService.delete(api);
    } catch (EntityNotFoundException ex) {
        fail("Token should be able to be deleted");
    }
    tokenService.getToken(api);
}
Also used : RemoteAPI(ca.corefacility.bioinformatics.irida.model.RemoteAPI) EntityNotFoundException(ca.corefacility.bioinformatics.irida.exceptions.EntityNotFoundException) Test(org.junit.Test)

Example 28 with EntityNotFoundException

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

the class SequencingRunServiceImplIT method testAddSequenceFileToMiseqRun.

private void testAddSequenceFileToMiseqRun() throws IOException, InterruptedException {
    SequencingRun miseqRun = miseqRunService.read(1L);
    // we can't actually know a file name in the XML file that we use to
    // populate the database for these tests, so the files don't exist
    // anywhere. Create a new temp file and update that in the database
    // prior to adding a file to a miseq run so that we have something there
    // that we can link to.
    Path sequenceFile = Files.createTempFile(null, null);
    Files.write(sequenceFile, FASTQ_FILE_CONTENTS);
    SequenceFile sf = new SequenceFile(sequenceFile);
    SequencingObject so = new SingleEndSequenceFile(sf);
    so = objectService.create(so);
    miseqRunService.addSequencingObjectToSequencingRun(miseqRun, so);
    SequencingRun saved = miseqRunService.read(1L);
    SequencingObject readObject = objectService.read(so.getId());
    Set<SequencingObject> sequencingObjectsForSequencingRun = objectService.getSequencingObjectsForSequencingRun(saved);
    assertTrue("Saved miseq run should have seqence file", sequencingObjectsForSequencingRun.contains(so));
    if (SecurityContextHolder.getContext().getAuthentication().getAuthorities().stream().anyMatch(auth -> auth.getAuthority().equals("ROLE_ADMIN"))) {
        AnalysisFastQC analysis = null;
        do {
            try {
                readObject = objectService.read(so.getId());
                SequenceFile readFile = readObject.getFiles().iterator().next();
                analysis = analysisService.getFastQCAnalysisForSequenceFile(readObject, readFile.getId());
            } catch (final EntityNotFoundException e) {
                logger.info("Fastqc still isn't finished, sleeping a bit.");
                Thread.sleep(1000);
            }
        } while (analysis == null);
        assertNotNull("FastQC analysis should have been created for uploaded file.", analysis);
    }
}
Also used : Path(java.nio.file.Path) SequencingObject(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequencingObject) SequencingRun(ca.corefacility.bioinformatics.irida.model.run.SequencingRun) SequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile) SingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile) EntityNotFoundException(ca.corefacility.bioinformatics.irida.exceptions.EntityNotFoundException) SingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile) AnalysisFastQC(ca.corefacility.bioinformatics.irida.model.workflow.analysis.AnalysisFastQC)

Example 29 with EntityNotFoundException

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

the class GenericControllerTest method testUpdateBadResource.

@Test
public void testUpdateBadResource() throws InstantiationException, IllegalAccessException {
    when(crudService.updateFields(identifier, updatedFields)).thenThrow(new EntityNotFoundException("not found"));
    try {
        controller.update(identifier, updatedFields);
        fail();
    } catch (EntityNotFoundException e) {
    } catch (Exception e) {
        fail();
    }
}
Also used : EntityNotFoundException(ca.corefacility.bioinformatics.irida.exceptions.EntityNotFoundException) EntityNotFoundException(ca.corefacility.bioinformatics.irida.exceptions.EntityNotFoundException) ConstraintViolationException(javax.validation.ConstraintViolationException) GenericsException(ca.corefacility.bioinformatics.irida.web.controller.api.exception.GenericsException) Test(org.junit.Test)

Example 30 with EntityNotFoundException

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

the class UserControllerTest method testGetUserProjectsBadUser.

@Test
public void testGetUserProjectsBadUser() {
    String username = "superbad";
    when(userService.getUserByUsername(username)).thenThrow(new EntityNotFoundException(username));
    try {
        controller.getUserProjects(username);
        fail();
    } catch (EntityNotFoundException e) {
    } catch (Exception e) {
        fail();
    }
}
Also used : EntityNotFoundException(ca.corefacility.bioinformatics.irida.exceptions.EntityNotFoundException) 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