use of org.springframework.validation.ObjectError in project entando-core by entando.
the class RestExceptionHandler method processGlobalErrors.
private ErrorRestResponse processGlobalErrors(ErrorRestResponse dto, List<ObjectError> globalErrors) {
if (null != globalErrors) {
List<RestError> errors = new ArrayList<>();
for (ObjectError globalError : globalErrors) {
String localizedErrorMessage = resolveLocalizedErrorMessage(globalError);
errors.add(new RestError(globalError.getCode(), localizedErrorMessage));
}
dto.addErrors(errors);
}
return dto;
}
use of org.springframework.validation.ObjectError in project entando-core by entando.
the class UserValidatorTest method createErrorSelfDeleteContainsErrorMessage.
@Test
public void createErrorSelfDeleteContainsErrorMessage() {
MapBindingResult bindingResult = new MapBindingResult(new HashMap<Object, Object>(), "username");
BindingResult bindingSelfDeleteError = UserValidator.createSelfDeleteUserError(bindingResult);
assertEquals(1, bindingSelfDeleteError.getErrorCount());
List<ObjectError> errors = bindingSelfDeleteError.getAllErrors();
ObjectError error = errors.get(0);
assertEquals(UserValidator.ERRCODE_SELF_DELETE, error.getCode());
assertEquals("user.self.delete.error", error.getDefaultMessage());
}
use of org.springframework.validation.ObjectError in project entando-core by entando.
the class UserValidatorTest method createErrorDeleteAdminContainsErrorMessage.
@Test
public void createErrorDeleteAdminContainsErrorMessage() {
BindingResult bindingAdminDeleteError = UserValidator.createDeleteAdminError();
assertEquals(1, bindingAdminDeleteError.getErrorCount());
List<ObjectError> errors = bindingAdminDeleteError.getAllErrors();
ObjectError adminError = errors.get(0);
assertEquals(UserValidator.ERRCODE_DELETE_ADMIN, adminError.getCode());
assertEquals("user.admin.cant.delete", adminError.getDefaultMessage());
}
use of org.springframework.validation.ObjectError in project OpenClinica by OpenClinica.
the class DataEndpoint method mapFailConfirmation.
/**
* Create Error Response
*
* @param confirmation
* @return
* @throws Exception
*/
private Element mapFailConfirmation(Errors errors, String message) throws Exception {
DocumentBuilderFactory dbfac = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = dbfac.newDocumentBuilder();
Document document = docBuilder.newDocument();
Element responseElement = document.createElementNS(NAMESPACE_URI_V1, "importDataResponse");
Element resultElement = document.createElementNS(NAMESPACE_URI_V1, "result");
String confirmation = messages.getMessage("dataEndpoint.fail", null, "Fail", locale);
resultElement.setTextContent(confirmation);
responseElement.appendChild(resultElement);
if (errors != null) {
for (ObjectError error : errors.getAllErrors()) {
Element errorElement = document.createElementNS(NAMESPACE_URI_V1, "error");
String theMessage = messages.getMessage(error.getCode(), error.getArguments(), locale);
errorElement.setTextContent(theMessage);
responseElement.appendChild(errorElement);
}
}
if (message != null) {
Element msgElement = document.createElementNS(NAMESPACE_URI_V1, "error");
msgElement.setTextContent(message);
responseElement.appendChild(msgElement);
LOG.debug("sending fail message " + message);
}
return responseElement;
}
use of org.springframework.validation.ObjectError in project OpenClinica by OpenClinica.
the class StudyEventDefinitionEndpoint method mapFailConfirmation.
private Element mapFailConfirmation(String confirmation, Errors errors) throws Exception {
DocumentBuilderFactory dbfac = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = dbfac.newDocumentBuilder();
Document document = docBuilder.newDocument();
Element responseElement = document.createElementNS(NAMESPACE_URI_V1, "listAllResponse");
Element resultElement = document.createElementNS(NAMESPACE_URI_V1, "result");
resultElement.setTextContent(confirmation);
responseElement.appendChild(resultElement);
for (ObjectError error : errors.getAllErrors()) {
Element errorElement = document.createElementNS(NAMESPACE_URI_V1, "error");
String theMessage = messages.getMessage(error.getCode(), error.getArguments(), locale);
errorElement.setTextContent(theMessage);
responseElement.appendChild(errorElement);
}
return responseElement;
}
Aggregations