List of usage examples for org.springframework.validation MapBindingResult getAllErrors
@Override
public List<ObjectError> getAllErrors()
From source file:org.orcid.frontend.web.controllers.ManageProfileController.java
@RequestMapping(value = "/addEmail.json", method = RequestMethod.POST) public @ResponseBody org.orcid.pojo.Email addEmailsJson(HttpServletRequest request, @RequestBody org.orcid.pojo.AddEmail email) { List<String> errors = new ArrayList<String>(); // Check password if (email.getPassword() == null || !encryptionManager.hashMatches(email.getPassword(), getEffectiveProfile().getPassword())) { errors.add(getMessage("check_password_modal.incorrect_password")); }// www . ja v a 2 s.c o m if (errors.isEmpty()) { String newPrime = null; String oldPrime = null; List<String> emailErrors = new ArrayList<String>(); // clear errros email.setErrors(new ArrayList<String>()); // if blank if (email.getValue() == null || email.getValue().trim().equals("")) { emailErrors.add(getMessage("Email.personalInfoForm.email")); } OrcidProfile currentProfile = getEffectiveProfile(); List<Email> emails = currentProfile.getOrcidBio().getContactDetails().getEmail(); 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()) { emailErrors.add(getMessage(oe.getCode(), email.getValue())); } email.setErrors(emailErrors); if (emailErrors.size() == 0) { if (email.isPrimary()) { for (Email curEmail : emails) { if (curEmail.isPrimary()) oldPrime = curEmail.getValue(); curEmail.setPrimary(false); } newPrime = email.getValue(); } emails.add(email); currentProfile.getOrcidBio().getContactDetails().setEmail(emails); email.setSource(sourceManager.retrieveSourceOrcid()); emailManager.addEmail(currentProfile.getOrcidIdentifier().getPath(), email); // send verifcation email for new address notificationManager.sendVerificationEmail(currentProfile, email.getValue()); // if primary also send change notification. if (newPrime != null && !newPrime.equalsIgnoreCase(oldPrime)) { request.getSession().setAttribute(ManageProfileController.CHECK_EMAIL_VALIDATED, false); notificationManager.sendEmailAddressChangedNotification(currentProfile, new Email(oldPrime)); } } } else { email.setErrors(errors); } return email; }
From source file:org.orcid.frontend.web.controllers.ManageProfileController.java
@SuppressWarnings("unchecked") @RequestMapping(value = "/emails.json", method = RequestMethod.POST) public @ResponseBody org.orcid.pojo.ajaxForm.Emails postEmailsJson(HttpServletRequest request, @RequestBody org.orcid.pojo.ajaxForm.Emails emails) { org.orcid.pojo.Email newPrime = null; org.orcid.pojo.Email oldPrime = null; List<String> allErrors = new ArrayList<String>(); for (org.orcid.pojo.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);//from ww w .ja va 2s . co m } email.setErrors(emailErrors); if (email.isPrimary()) newPrime = email; } if (newPrime == null) { allErrors.add("A Primary Email Must be selected"); } OrcidProfile currentProfile = getEffectiveProfile(); if (currentProfile.getOrcidBio().getContactDetails().retrievePrimaryEmail() != null) oldPrime = new org.orcid.pojo.Email( currentProfile.getOrcidBio().getContactDetails().retrievePrimaryEmail()); emails.setErrors(allErrors); if (allErrors.size() == 0) { currentProfile.getOrcidBio().getContactDetails().setEmail((List<Email>) (Object) emails.getEmails()); emailManager.updateEmails(currentProfile.getOrcidIdentifier().getPath(), currentProfile.getOrcidBio().getContactDetails().getEmail()); if (newPrime != null && !newPrime.getValue().equalsIgnoreCase(oldPrime.getValue())) { notificationManager.sendEmailAddressChangedNotification(currentProfile, new Email(oldPrime.getValue())); if (!newPrime.isVerified()) { notificationManager.sendVerificationEmail(currentProfile, newPrime.getValue()); request.getSession().setAttribute(ManageProfileController.CHECK_EMAIL_VALIDATED, false); } } } return emails; }
From source file:org.orcid.frontend.web.controllers.RegistrationController.java
public Registration regEmailValidate(HttpServletRequest request, Registration reg, boolean isOauthRequest, boolean isKeyup) { reg.getEmail().setErrors(new ArrayList<String>()); if (!isKeyup && (reg.getEmail().getValue() == null || reg.getEmail().getValue().trim().isEmpty())) { setError(reg.getEmail(), "Email.registrationForm.email"); }// w w w .ja va2s . c om // validate email MapBindingResult mbr = new MapBindingResult(new HashMap<String, String>(), "Email"); // make sure there are no dups validateEmailAddress(reg.getEmail().getValue(), false, true, request, mbr); for (ObjectError oe : mbr.getAllErrors()) { if (isOauthRequest && oe.getCode().equals("orcid.frontend.verify.duplicate_email")) { // XXX reg.getEmail().getErrors().add(getMessage("oauth.registration.duplicate_email", oe.getArguments())); } else { reg.getEmail().getErrors().add(getMessage(oe.getCode(), oe.getArguments())); } } // validate confirm if already field out if (reg.getEmailConfirm().getValue() != null) { regEmailConfirmValidate(reg); } return reg; }