use of org.springframework.validation.MapBindingResult in project spring-boot by spring-projects.
the class SpringValidatorTests method wrapLocalValidatorFactoryBean.
@Test
public void wrapLocalValidatorFactoryBean() {
SpringValidator wrapper = load(LocalValidatorFactoryBeanConfig.class);
assertThat(wrapper.supports(SampleData.class)).isTrue();
MapBindingResult errors = new MapBindingResult(new HashMap<String, Object>(), "test");
wrapper.validate(new SampleData(40), errors);
assertThat(errors.getErrorCount()).isEqualTo(1);
}
use of org.springframework.validation.MapBindingResult in project ORCID-Source by ORCID.
the class ManageProfileController method postEmailsJson.
@Deprecated
@RequestMapping(value = "/emails.json", method = RequestMethod.POST)
@ResponseBody
public org.orcid.pojo.ajaxForm.Emails postEmailsJson(HttpServletRequest request, @RequestBody org.orcid.pojo.ajaxForm.Emails emails) {
org.orcid.pojo.ajaxForm.Email newPrime = null;
List<String> allErrors = new ArrayList<String>();
for (org.orcid.pojo.ajaxForm.Email email : emails.getEmails()) {
MapBindingResult mbr = new MapBindingResult(new HashMap<String, String>(), "Email");
validateEmailAddress(email.getValue(), request, mbr);
List<String> emailErrors = new ArrayList<String>();
for (ObjectError oe : mbr.getAllErrors()) {
String msg = getMessage(oe.getCode(), email.getValue());
emailErrors.add(getMessage(oe.getCode(), email.getValue()));
allErrors.add(msg);
}
email.setErrors(emailErrors);
if (email.isPrimary())
newPrime = email;
}
if (newPrime == null) {
allErrors.add("A Primary Email Must be selected");
}
emails.setErrors(allErrors);
if (allErrors.size() == 0) {
emailManager.updateEmails(request, getCurrentUserOrcid(), emails.toV3Emails());
}
return emails;
}
use of org.springframework.validation.MapBindingResult in project ORCID-Source by ORCID.
the class ManageProfileController method addEmails.
@RequestMapping(value = "/addEmail.json", method = RequestMethod.POST)
@ResponseBody
public org.orcid.pojo.ajaxForm.Email addEmails(HttpServletRequest request, @RequestBody org.orcid.pojo.AddEmail email) {
List<String> errors = new ArrayList<String>();
ProfileEntity profile = profileEntityCacheManager.retrieve(getCurrentUserOrcid());
// Check password
if (orcidSecurityManager.isPasswordConfirmationRequired() && (email.getPassword() == null || !encryptionManager.hashMatches(email.getPassword(), profile.getEncryptedPassword()))) {
errors.add(getMessage("check_password_modal.incorrect_password"));
}
// if blank
if (PojoUtil.isEmpty(email.getValue())) {
errors.add(getMessage("Email.personalInfoForm.email"));
}
MapBindingResult mbr = new MapBindingResult(new HashMap<String, String>(), "Email");
// make sure there are no dups
validateEmailAddress(email.getValue(), false, false, request, mbr);
for (ObjectError oe : mbr.getAllErrors()) {
if (oe.getCode() != null) {
errors.add(getMessage(oe.getCode(), oe.getArguments()));
} else {
errors.add(oe.getDefaultMessage());
}
}
if (errors.isEmpty()) {
// clear errors
email.setErrors(new ArrayList<String>());
String currentUserOrcid = getCurrentUserOrcid();
emailManager.addEmail(request, currentUserOrcid, email.toV3Email());
} else {
email.setErrors(errors);
}
return email;
}
use of org.springframework.validation.MapBindingResult in project entando-core by entando.
the class UserValidator method createDeleteAdminError.
public static BindingResult createDeleteAdminError() {
Map<String, String> map = new HashMap<>();
map.put("username", "admin");
BindingResult bindingResult = new MapBindingResult(map, "username");
bindingResult.reject(UserValidator.ERRCODE_DELETE_ADMIN, new String[] {}, "user.admin.cant.delete");
return bindingResult;
}
use of org.springframework.validation.MapBindingResult in project entando-core by entando.
the class GuiFragmentValidatorTest method validateRightFragment.
@Test
public void validateRightFragment() throws Exception {
when(this.guiFragmentManager.getGuiFragment("not_existing")).thenReturn(null);
GuiFragmentRequestBody request = new GuiFragmentRequestBody("not_existing", "<h1>code</h1>");
MapBindingResult bindingResult = new MapBindingResult(new HashMap<Object, Object>(), "fragment");
validator.validate(request, bindingResult);
Assert.assertFalse(bindingResult.hasErrors());
Assert.assertEquals(0, bindingResult.getErrorCount());
}
Aggregations