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