use of org.springframework.dao.DataIntegrityViolationException in project irida by phac-nml.
the class UserServiceImplTest method testCreateUserWithUnknownIntegrityConstraintViolation.
@Test(expected = DataIntegrityViolationException.class)
public void testCreateUserWithUnknownIntegrityConstraintViolation() {
User u = new User();
DataIntegrityViolationException integrityViolationException = new DataIntegrityViolationException("Duplicate");
when(userRepository.save(any(User.class))).thenThrow(integrityViolationException);
when(validator.validateValue(eq(User.class), eq("password"), any(String.class))).thenReturn(new HashSet<ConstraintViolation<User>>());
userService.create(u);
}
use of org.springframework.dao.DataIntegrityViolationException in project irida by phac-nml.
the class UserServiceImplTest method testCreateUserWithUnknownIntegrityConstraintViolationName.
@Test(expected = EntityExistsException.class)
public void testCreateUserWithUnknownIntegrityConstraintViolationName() {
User u = new User();
ConstraintViolationException constraintViolationException = new ConstraintViolationException("Duplicate", null, "Not a very nicely formatted constraint violation name.");
DataIntegrityViolationException integrityViolationException = new DataIntegrityViolationException("Duplicate", constraintViolationException);
when(userRepository.save(any(User.class))).thenThrow(integrityViolationException);
when(validator.validateValue(eq(User.class), eq("password"), any(String.class))).thenReturn(new HashSet<ConstraintViolation<User>>());
userService.create(u);
}
use of org.springframework.dao.DataIntegrityViolationException in project irida by phac-nml.
the class GroupsController method editGroup.
/**
* Submit changes to the {@link UserGroup}.
*
* @param userGroupId
* the group ID to edit.
* @param name
* the new name of the group.
* @param description
* the new description of the group.
* @param principal
* the currently logged in user.
* @param model
* the model to add attributes to.
* @param locale
* the locale of the browser.
* @return the route to the editing page on validation failure, or the
* details page on success.
*/
@RequestMapping(path = "/{userGroupId}/edit", method = RequestMethod.POST)
public String editGroup(@PathVariable final Long userGroupId, @RequestParam final String name, @RequestParam final String description, final Principal principal, final Model model, final Locale locale) {
logger.debug("Editing group: [" + userGroupId + "]");
final Map<String, String> errors = new HashMap<>();
UserGroup group = userGroupService.read(userGroupId);
try {
group.setName(name);
group.setDescription(description);
userGroupService.update(group);
return getDetailsPage(userGroupId, principal, model);
} catch (final ConstraintViolationException e) {
for (final ConstraintViolation<?> v : e.getConstraintViolations()) {
errors.put(v.getPropertyPath().toString(), v.getMessage());
}
} catch (final EntityExistsException | DataIntegrityViolationException e) {
errors.put("name", messageSource.getMessage("group.name.exists", null, locale));
}
model.addAttribute("errors", errors);
model.addAttribute("group", userGroupService.read(userGroupId));
model.addAttribute("given_name", name);
model.addAttribute("given_description", description);
return GROUPS_EDIT;
}
use of org.springframework.dao.DataIntegrityViolationException in project ma-core-public by infiniteautomation.
the class AbstractDwr method remove.
/**
* Delete a VO
* @param id
* @return
*/
@DwrPermission(admin = true)
public ProcessResult remove(int id) {
ProcessResult response = new ProcessResult();
try {
dao.delete(id);
} catch (Exception e) {
// Handle the exceptions.
LOG.error(e);
VO vo = dao.get(id);
if (e instanceof DataIntegrityViolationException)
response.addContextualMessage(vo.getName(), "table.edit.unableToDeleteDueToConstraints");
else
response.addContextualMessage(vo.getName(), "table.edit.unableToDelete", e.getMessage());
}
response.addData("id", id);
return response;
}
use of org.springframework.dao.DataIntegrityViolationException in project ma-core-public by infiniteautomation.
the class AbstractRTDwr method remove.
@DwrPermission(admin = true)
@Override
public ProcessResult remove(int id) {
ProcessResult response = new ProcessResult();
try {
runtimeManager.delete(id);
} catch (Exception e) {
// Handle the exceptions.
LOG.error(e);
// TODO Clean up and generify these messages to some central place
if (e instanceof DataIntegrityViolationException)
response.addMessage(this.keyName + "Errors", new TranslatableMessage("dsEdit.unableToDeleteDueToConstraints"));
else
response.addMessage(this.keyName + "Errors", new TranslatableMessage("dsEdit.unableToDelete"));
}
response.addData("id", id);
return response;
}
Aggregations