Search in sources :

Example 31 with EntityNotFoundException

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

the class ControllerExceptionHandlerTest method testHandleNotFoundException.

@Test
public void testHandleNotFoundException() {
    ResponseEntity<ErrorResponse> response = controller.handleNotFoundException(new EntityNotFoundException("not found"));
    assertEquals(HttpStatus.NOT_FOUND, response.getStatusCode());
}
Also used : EntityNotFoundException(ca.corefacility.bioinformatics.irida.exceptions.EntityNotFoundException) ErrorResponse(ca.corefacility.bioinformatics.irida.web.controller.api.exception.ErrorResponse) Test(org.junit.Test)

Example 32 with EntityNotFoundException

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

the class SampleSequenceFilesControllerTest method testCantGetSequenceFileForOtherSample.

@Test(expected = EntityNotFoundException.class)
public void testCantGetSequenceFileForOtherSample() {
    Sample s = TestDataFactory.constructSample();
    Long objectId = 5L;
    Long fileId = 3L;
    when(sampleService.read(s.getId())).thenReturn(s);
    when(sequencingObjectService.readSequencingObjectForSample(s, objectId)).thenThrow(new EntityNotFoundException("not in sample"));
    controller.readSequenceFileForSequencingObject(s.getId(), "unpaired", objectId, fileId);
}
Also used : Sample(ca.corefacility.bioinformatics.irida.model.sample.Sample) EntityNotFoundException(ca.corefacility.bioinformatics.irida.exceptions.EntityNotFoundException) Test(org.junit.Test)

Example 33 with EntityNotFoundException

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

the class CRUDServiceImpl method updateFields.

/**
 * {@inheritDoc}
 */
@Override
@Transactional
public ValueType updateFields(KeyType id, Map<String, Object> updatedFields) throws ConstraintViolationException, EntityExistsException, InvalidPropertyException {
    // check if you can actually update the properties requested
    ValueType instance = read(id);
    for (String key : updatedFields.keySet()) {
        Object value = updatedFields.get(key);
        try {
            // setProperty doesn't throw an exception if the field name
            // can't be found, so we have to force an exception to be thrown
            // by calling getProperty manually first.
            DirectFieldAccessor dfa = new DirectFieldAccessor(instance);
            dfa.setPropertyValue(key, value);
        } catch (IllegalArgumentException | NotWritablePropertyException | TypeMismatchException e) {
            throw new InvalidPropertyException("Unable to access field [" + key + "]", valueType, e);
        }
    }
    // now that you know all of the requested methods exist, validate the
    // supplied values
    Set<ConstraintViolation<ValueType>> constraintViolations = new HashSet<>();
    // updated.
    for (String propertyName : updatedFields.keySet()) {
        Set<ConstraintViolation<ValueType>> propertyViolations = validator.validateValue(valueType, propertyName, updatedFields.get(propertyName));
        constraintViolations.addAll(propertyViolations);
    }
    // if any validations fail, throw a constraint violation exception.
    if (!constraintViolations.isEmpty()) {
        throw new ConstraintViolationException(constraintViolations);
    }
    // check if the entity exists in the database
    if (!exists(id)) {
        throw new EntityNotFoundException("Entity not found.");
    }
    // return repository.update(id, updatedFields);
    return repository.save(instance);
}
Also used : TypeMismatchException(org.springframework.beans.TypeMismatchException) EntityNotFoundException(ca.corefacility.bioinformatics.irida.exceptions.EntityNotFoundException) DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) NotWritablePropertyException(org.springframework.beans.NotWritablePropertyException) ConstraintViolation(javax.validation.ConstraintViolation) InvalidPropertyException(ca.corefacility.bioinformatics.irida.exceptions.InvalidPropertyException) ConstraintViolationException(javax.validation.ConstraintViolationException) HashSet(java.util.HashSet) Transactional(org.springframework.transaction.annotation.Transactional)

Example 34 with EntityNotFoundException

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

the class ProjectServiceImpl method updateUserGroupProjectRole.

/**
 * {@inheritDoc}
 */
@Override
@Transactional
@LaunchesProjectEvent(UserGroupRoleSetProjectEvent.class)
@PreAuthorize("hasRole('ROLE_ADMIN') or hasPermission(#project, 'canManageLocalProjectSettings')")
public Join<Project, UserGroup> updateUserGroupProjectRole(Project project, UserGroup userGroup, ProjectRole projectRole) throws ProjectWithoutOwnerException {
    final UserGroupProjectJoin j = ugpjRepository.findByProjectAndUserGroup(project, userGroup);
    if (j == null) {
        throw new EntityNotFoundException("Join between this project and group does not exist. Group: " + userGroup + " Project: " + project);
    }
    if (!allowRoleChange(project, j.getProjectRole())) {
        throw new ProjectWithoutOwnerException("This role change would leave the project without an owner");
    }
    j.setProjectRole(projectRole);
    return ugpjRepository.save(j);
}
Also used : ProjectWithoutOwnerException(ca.corefacility.bioinformatics.irida.exceptions.ProjectWithoutOwnerException) UserGroupProjectJoin(ca.corefacility.bioinformatics.irida.model.user.group.UserGroupProjectJoin) EntityNotFoundException(ca.corefacility.bioinformatics.irida.exceptions.EntityNotFoundException) LaunchesProjectEvent(ca.corefacility.bioinformatics.irida.events.annotations.LaunchesProjectEvent) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) Transactional(org.springframework.transaction.annotation.Transactional)

Example 35 with EntityNotFoundException

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

the class ProjectServiceImpl method updateUserProjectRole.

/**
 * {@inheritDoc}
 */
@Override
@Transactional
@LaunchesProjectEvent(UserRoleSetProjectEvent.class)
@PreAuthorize("hasRole('ROLE_ADMIN') or hasPermission(#project,'canManageLocalProjectSettings')")
public Join<Project, User> updateUserProjectRole(Project project, User user, ProjectRole projectRole) throws ProjectWithoutOwnerException {
    ProjectUserJoin projectJoinForUser = pujRepository.getProjectJoinForUser(project, user);
    if (projectJoinForUser == null) {
        throw new EntityNotFoundException("Join between this project and user does not exist. User: " + user + " Project: " + project);
    }
    if (!allowRoleChange(projectJoinForUser.getSubject(), projectJoinForUser.getProjectRole())) {
        throw new ProjectWithoutOwnerException("This role change would leave the project without an owner");
    }
    projectJoinForUser.setProjectRole(projectRole);
    return pujRepository.save(projectJoinForUser);
}
Also used : ProjectUserJoin(ca.corefacility.bioinformatics.irida.model.joins.impl.ProjectUserJoin) ProjectWithoutOwnerException(ca.corefacility.bioinformatics.irida.exceptions.ProjectWithoutOwnerException) EntityNotFoundException(ca.corefacility.bioinformatics.irida.exceptions.EntityNotFoundException) LaunchesProjectEvent(ca.corefacility.bioinformatics.irida.events.annotations.LaunchesProjectEvent) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) 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