Search in sources :

Example 36 with EntityNotFoundException

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

the class RemoteAPITokenServiceImpl method getOldTokenId.

/**
 * Remove any old token for this user from the database
 *
 * @param apiToken
 *            the api token to remove.
 * @return the token that was found.
 */
protected RemoteAPIToken getOldTokenId(RemoteAPIToken apiToken) {
    RemoteAPIToken oldToken = null;
    try {
        oldToken = getToken(apiToken.getRemoteApi());
        logger.trace("Old token found for service " + apiToken.getRemoteApi());
        apiToken.setId(oldToken.getId());
    } catch (EntityNotFoundException ex) {
        logger.trace("No token found for service " + apiToken.getRemoteApi());
    }
    return apiToken;
}
Also used : RemoteAPIToken(ca.corefacility.bioinformatics.irida.model.RemoteAPIToken) EntityNotFoundException(ca.corefacility.bioinformatics.irida.exceptions.EntityNotFoundException)

Example 37 with EntityNotFoundException

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

the class RemoteAPITokenServiceImpl method getToken.

/**
 * {@inheritDoc}
 */
@Override
public RemoteAPIToken getToken(RemoteAPI remoteAPI) throws EntityNotFoundException {
    User user = userRepository.loadUserByUsername(getUserName());
    RemoteAPIToken readTokenForApiAndUser = tokenRepository.readTokenForApiAndUser(remoteAPI, user);
    if (readTokenForApiAndUser == null) {
        throw new EntityNotFoundException("Couldn't find an OAuth2 token for this API and User");
    }
    return readTokenForApiAndUser;
}
Also used : RemoteAPIToken(ca.corefacility.bioinformatics.irida.model.RemoteAPIToken) User(ca.corefacility.bioinformatics.irida.model.user.User) EntityNotFoundException(ca.corefacility.bioinformatics.irida.exceptions.EntityNotFoundException)

Example 38 with EntityNotFoundException

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

the class SequencingObjectServiceImpl method getUniqueSamplesForSequencingObjects.

/**
 * {@inheritDoc}
 */
@PreAuthorize("hasAnyRole('ROLE_ADMIN') or hasPermission(#sequenceFiles, 'canReadSequencingObject')")
@Override
public <T extends SequencingObject> Map<Sample, T> getUniqueSamplesForSequencingObjects(Set<T> sequenceFiles) throws DuplicateSampleException {
    Map<Sample, T> sequenceFilesSampleMap = new HashMap<>();
    for (T seqObj : sequenceFiles) {
        SequenceFile file = seqObj.getFiles().iterator().next();
        SampleSequencingObjectJoin join = ssoRepository.getSampleForSequencingObject(seqObj);
        if (join == null) {
            throw new EntityNotFoundException("No sample associated with sequence file " + seqObj.getClass() + "[id=" + seqObj.getId() + "]");
        } else {
            Sample sample = join.getSubject();
            if (sequenceFilesSampleMap.containsKey(sample)) {
                SequencingObject previousFile = sequenceFilesSampleMap.get(sample);
                throw new DuplicateSampleException("Sequence files " + file + ", " + previousFile + " have the same sample " + sample);
            } else {
                sequenceFilesSampleMap.put(sample, seqObj);
            }
        }
    }
    return sequenceFilesSampleMap;
}
Also used : SequencingObject(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequencingObject) SequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile) SingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile) HashMap(java.util.HashMap) Sample(ca.corefacility.bioinformatics.irida.model.sample.Sample) EntityNotFoundException(ca.corefacility.bioinformatics.irida.exceptions.EntityNotFoundException) SampleSequencingObjectJoin(ca.corefacility.bioinformatics.irida.model.sample.SampleSequencingObjectJoin) DuplicateSampleException(ca.corefacility.bioinformatics.irida.exceptions.DuplicateSampleException) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 39 with EntityNotFoundException

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

the class SampleServiceImpl method getSampleForProject.

/**
 * {@inheritDoc}
 */
@Override
@Transactional(readOnly = true)
@PreAuthorize("hasAnyRole('ROLE_ADMIN','ROLE_SEQUENCER') or (hasPermission(#project, 'canReadProject') and hasPermission(#sampleId, 'canReadSample'))")
public ProjectSampleJoin getSampleForProject(Project project, Long sampleId) {
    Sample sample = read(sampleId);
    ProjectSampleJoin join = psjRepository.readSampleForProject(project, sample);
    if (join == null) {
        throw new EntityNotFoundException("Join between the project and this identifier doesn't exist");
    }
    return join;
}
Also used : ProjectSampleJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectSampleJoin) Sample(ca.corefacility.bioinformatics.irida.model.sample.Sample) EntityNotFoundException(ca.corefacility.bioinformatics.irida.exceptions.EntityNotFoundException) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) Transactional(org.springframework.transaction.annotation.Transactional)

Example 40 with EntityNotFoundException

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

the class AnalysisExecutionServiceGalaxyAsync method transferAnalysisResults.

/**
 * Downloads and saves the results of an {@link AnalysisSubmission} that was
 * previously submitted from an execution manager.
 *
 * @param submittedAnalysis
 *            An {@link AnalysisSubmission} that was previously submitted.
 * @return A {@link Future} with an {@link AnalysisSubmission} object
 *         containing information about the particular analysis.
 * @throws ExecutionManagerException
 *             If there was an issue with the execution manager.
 * @throws IridaWorkflowNotFoundException
 *             If the workflow for this submission could not be found in
 *             IRIDA.
 * @throws IOException
 *             If there was an error loading the analysis results from an
 *             execution manager.
 * @throws IridaWorkflowAnalysisTypeException
 *             If there was an issue building an {@link Analysis} object.
 */
@Transactional
public Future<AnalysisSubmission> transferAnalysisResults(AnalysisSubmission submittedAnalysis) throws ExecutionManagerException, IOException, IridaWorkflowNotFoundException, IridaWorkflowAnalysisTypeException {
    checkNotNull(submittedAnalysis, "submittedAnalysis is null");
    checkNotNull(submittedAnalysis.getRemoteAnalysisId(), "remoteAnalysisId is null");
    if (!analysisSubmissionService.exists(submittedAnalysis.getId())) {
        throw new EntityNotFoundException("Could not find analysis submission for " + submittedAnalysis);
    }
    logger.debug("Getting results for " + submittedAnalysis);
    Analysis analysisResults = workspaceService.getAnalysisResults(submittedAnalysis);
    logger.trace("Saving results for " + submittedAnalysis);
    Analysis savedAnalysis = analysisService.create(analysisResults);
    // if samples should be updated, set to TRANSFERRED.  Otherwise just complete.
    if (submittedAnalysis.getUpdateSamples()) {
        submittedAnalysis.setAnalysisState(AnalysisState.TRANSFERRED);
    } else {
        submittedAnalysis.setAnalysisState(AnalysisState.COMPLETED);
    }
    try {
        submittedAnalysis.setAnalysis(savedAnalysis);
    } catch (AnalysisAlreadySetException e) {
        throw new ExecutionManagerException("Analysis already set", e);
    }
    AnalysisSubmission completedSubmission = analysisSubmissionService.update(submittedAnalysis);
    return new AsyncResult<>(completedSubmission);
}
Also used : Analysis(ca.corefacility.bioinformatics.irida.model.workflow.analysis.Analysis) AnalysisSubmission(ca.corefacility.bioinformatics.irida.model.workflow.submission.AnalysisSubmission) AnalysisAlreadySetException(ca.corefacility.bioinformatics.irida.exceptions.AnalysisAlreadySetException) EntityNotFoundException(ca.corefacility.bioinformatics.irida.exceptions.EntityNotFoundException) AsyncResult(org.springframework.scheduling.annotation.AsyncResult) ExecutionManagerException(ca.corefacility.bioinformatics.irida.exceptions.ExecutionManagerException) Transactional(org.springframework.transaction.annotation.Transactional)

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