List of usage examples for org.springframework.validation ValidationUtils rejectIfEmptyOrWhitespace
public static void rejectIfEmptyOrWhitespace(Errors errors, String field, String errorCode)
From source file:com.virtusa.akura.common.validator.StreamValidator.java
/** * Validates the object of the Stream./*from w w w. j ava2s . c o m*/ * * @param target - Populated object of Stream to validate * @param errors - Errors object that is building. May contain errors for the fields relating to types. */ public void validate(Object target, Errors errors) { ValidationUtils.rejectIfEmptyOrWhitespace(errors, FIELD_NAME_DESCRIPTION, AkuraWebConstant.MANDATORY_FIELD_ERROR_CODE); Stream stream = (Stream) target; String validatorPattern = ValidatorExpressionUtil.getValidatorPattern("REFERENCE.STREAM.VALIDATOR"); Pattern stringOnly = Pattern.compile(validatorPattern); Matcher makeMatch = stringOnly.matcher(stream.getDescription().trim()); if (makeMatch.find()) { errors.rejectValue(FIELD_NAME_DESCRIPTION, AkuraWebConstant.MISMATCH_ERROR); } }
From source file:io.acme.solution.api.validation.UserProfileValidator.java
@Override public void validate(final Object profile, final Errors errors) { ValidationUtils.rejectIfEmptyOrWhitespace(errors, UserProfile.FIELD_USERNAME, MessageKeys.UserProfile.EMPTY_USERNAME); ValidationUtils.rejectIfEmptyOrWhitespace(errors, UserProfile.FIELD_EMAIL, MessageKeys.UserProfile.EMPTY_EMAIL); ValidationUtils.rejectIfEmptyOrWhitespace(errors, UserProfile.FIELD_PASSWORD, MessageKeys.UserProfile.EMPTY_PASSWORD); this.rejectIfNotEmail((UserProfile) profile, errors); this.rejectIfNotUsername((UserProfile) profile, errors); }
From source file:it.f2informatica.core.validator.UserModelValidator.java
@Override public void validate(Object target, Errors errors) { UserModel userModel = (UserModel) target; ValidationUtils.rejectIfEmptyOrWhitespace(errors, "username", FIELD_MANDATORY); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "firstName", FIELD_MANDATORY); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "lastName", FIELD_MANDATORY); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "email", FIELD_MANDATORY); if (isSaveEvent(userModel)) { ValidationUtils.rejectIfEmptyOrWhitespace(errors, "password", FIELD_MANDATORY); }/* w ww . j a v a 2 s .c o m*/ invokeValidator(roleModelValidator, userModel.getRole(), "role", errors); doFurtherValidation(userModel, errors); }
From source file:com.ccserver.digital.validator.CreditCardApplicationValidator.java
private void validateGeneralTab(CreditCardApplicationDTO creditCardApplicationDTO, Errors errors) { // Validate date of issue ValidationUtils.rejectIfEmptyOrWhitespace(errors, "dob", ErrorCodes.FIELD_REQUIRED); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "firstName", ErrorCodes.FIELD_REQUIRED); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "lastName", ErrorCodes.FIELD_REQUIRED); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "gender", ErrorCodes.FIELD_REQUIRED); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "typeOfID", ErrorCodes.FIELD_REQUIRED); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "passportNumber", ErrorCodes.FIELD_REQUIRED); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "dateOfIssue", ErrorCodes.FIELD_REQUIRED); if (creditCardApplicationDTO.getCitizenship() != null && "+84".equals(creditCardApplicationDTO.getCitizenship().getCode())) { ValidationUtils.rejectIfEmptyOrWhitespace(errors, "placeOfIssue", ErrorCodes.FIELD_REQUIRED); }// ww w . j a v a 2 s.c om ValidationUtils.rejectIfEmptyOrWhitespace(errors, "passportNumber", ErrorCodes.FIELD_REQUIRED); LocalDateTime dateOfIssue = creditCardApplicationDTO.getDateOfIssue(); if (dateOfIssue != null) { if (dateOfIssue.isAfter(LocalDateTime.now())) { errors.rejectValue("dateOfIssue", ErrorCodes.FIELD_NOT_FUTURE); } } validateMobilephone(creditCardApplicationDTO, errors); }
From source file:org.openmrs.module.casereport.CaseReportTriggerValidator.java
/** * @see Validator#validate(Object, Errors) * @should fail if the case report trigger object is null * @should fail if the trigger name is null * @should fail if the trigger name is an empty string * @should fail if the trigger name is a white space character * @should fail if the case report field is null * @should fail if a case report with the same trigger already exists for the patient * @should pass for a valid case report trigger *///w w w . j av a 2 s .c o m @Override public void validate(Object target, Errors errors) { if (target == null || !(target instanceof CaseReportTrigger)) { throw new IllegalArgumentException( "The parameter obj should not be null and must be of type" + getClass()); } CaseReportTrigger trigger = (CaseReportTrigger) target; ValidationUtils.rejectIfEmptyOrWhitespace(errors, "name", "casereports.error.trigger.name.required"); ValidationUtils.rejectIfEmpty(errors, "caseReport", "casereports.error.trigger.casereport.required"); if (errors.hasErrors()) { return; } CaseReportService service = Context.getService(CaseReportService.class); CaseReport duplicate = service.getCaseReportByPatient(trigger.getCaseReport().getPatient()); if (duplicate != null) { CaseReportTrigger crt = duplicate.getCaseReportTriggerByName(trigger.getName()); if (crt != null && !crt.equals(trigger)) { errors.rejectValue("name", "casereport.error.trigger.duplicate", new Object[] { trigger.getName() }, null); } } }
From source file:com.wisemapping.validator.MapInfoValidator.java
protected void validateMapInfo(Errors errors, String title, String desc) { ValidationUtils.rejectIfEmptyOrWhitespace(errors, "title", Messages.FIELD_REQUIRED); if (title != null && title.length() > 0) { if (title.length() > Constants.MAX_MAP_NAME_LENGTH) { errors.rejectValue("title", "field.max.length", new Object[] { Constants.MAX_MAP_NAME_LENGTH }, "The title must have less than " + Constants.MAX_MAP_NAME_LENGTH + " characters."); } else {//from www.java 2 s . c om // Map already exists ? final MindmapService service = this.getMindmapService(); final User user = com.wisemapping.security.Utils.getUser(); final Mindmap mindMap = service.getMindmapByTitle(title, user); if (mindMap != null) { errors.rejectValue("title", Messages.MAP_TITLE_ALREADY_EXISTS); } } } ValidatorUtils.rejectIfExceeded(errors, "description", "The description must have less than " + Constants.MAX_MAP_DESCRIPTION_LENGTH + " characters.", desc, Constants.MAX_MAP_DESCRIPTION_LENGTH); }
From source file:org.tonguetied.web.AccountFormValidator.java
/** * This validation method check if the all mandatory fields on a * {@link AccountForm} object have been set. * //from ww w . ja v a2 s.c o m * @param form the {@link AccountForm} object to validate * @param errors contextual state about the validation process (never null) */ private void validateMandatoryFields(final AccountForm form, Errors errors) { ValidationUtils.rejectIfEmptyOrWhitespace(errors, FIELD_FIRSTNAME, "error.first.name.required"); ValidationUtils.rejectIfEmptyOrWhitespace(errors, FIELD_LASTNAME, "error.last.name.required"); ValidationUtils.rejectIfEmptyOrWhitespace(errors, FIELD_EMAIL, "error.email.required"); }
From source file:com.virtusa.akura.common.validator.CivilStatusValidator.java
/** * Validates the object of the CivilStatus. * * @param target - Populated object of CivilStatus to validate * @param errors - Errors object that is building. May contain errors for the fields relating to types. *//* www. j av a 2 s . com*/ public void validate(Object target, Errors errors) { ValidationUtils.rejectIfEmptyOrWhitespace(errors, DESCRIPTION, AkuraWebConstant.MANDATORY_FIELD_ERROR_CODE); CivilStatus civilStatus = (CivilStatus) target; String validatorPattern = ValidatorExpressionUtil.getValidatorPattern(REGE_EXP); Pattern stringOnly = Pattern.compile(validatorPattern); Matcher makeMatch = stringOnly.matcher(civilStatus.getDescription()); if (makeMatch.find()) { errors.rejectValue(DESCRIPTION, AkuraWebConstant.MISMATCH_ERROR); } }
From source file:com.wisemapping.validator.UserValidator.java
public void validate(@Nullable Object obj, @NotNull Errors errors) { UserBean user = (UserBean) obj;//www .j a v a 2 s .com if (user == null) { errors.rejectValue("user", "error.not-specified"); } else { // Validate email address ... final String email = user.getEmail(); boolean isValid = Utils.isValidateEmailAddress(email); if (isValid) { if (userService.getUserBy(email) != null) { errors.rejectValue("email", Messages.EMAIL_ALREADY_EXIST); } } else { Utils.validateEmailAddress(email, errors); } ValidationUtils.rejectIfEmptyOrWhitespace(errors, "firstname", Messages.FIELD_REQUIRED); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "lastname", Messages.FIELD_REQUIRED); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "password", Messages.FIELD_REQUIRED); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "retypePassword", Messages.FIELD_REQUIRED); ValidatorUtils.rejectIfExceeded(errors, "firstname", "The firstname must have less than " + Constants.MAX_USER_FIRSTNAME_LENGTH + " characters.", user.getFirstname(), Constants.MAX_USER_FIRSTNAME_LENGTH); ValidatorUtils.rejectIfExceeded(errors, "lastname", "The lastname must have less than " + Constants.MAX_USER_LASTNAME_LENGTH + " characters.", user.getLastname(), Constants.MAX_USER_LASTNAME_LENGTH); ValidatorUtils.rejectIfExceeded(errors, "password", "The password must have less than " + Constants.MAX_USER_PASSWORD_LENGTH + " characters.", user.getPassword(), Constants.MAX_USER_PASSWORD_LENGTH); ValidatorUtils.rejectIfExceeded(errors, "retypePassword", "The retypePassword must have less than " + Constants.MAX_USER_PASSWORD_LENGTH + " characters.", user.getRetypePassword(), Constants.MAX_USER_PASSWORD_LENGTH); final String password = user.getPassword(); if (password != null && !password.equals(user.getRetypePassword())) { errors.rejectValue("password", Messages.PASSWORD_MISSMATCH); } } }