List of usage examples for org.springframework.validation ValidationUtils rejectIfEmpty
public static void rejectIfEmpty(Errors errors, String field, String errorCode)
From source file:org.openmrs.validator.OrderValidator.java
/** * Checks the form object for any inconsistencies/errors * //from www . ja va 2 s .c o m * @see org.springframework.validation.Validator#validate(java.lang.Object, * org.springframework.validation.Errors) * @should fail validation if order is null * @should fail validation if order and encounter have different patients * @should fail validation if voided is null * @should fail validation if concept is null * @should fail validation if patient is null * @should fail validation if encounter is null * @should fail validation if orderer is null * @should fail validation if urgency is null * @should fail validation if action is null * @should fail validation if dateActivated after dateStopped * @should fail validation if dateActivated after autoExpireDate * @should fail validation if dateActivated is before encounter's encounterDatetime * @should fail validation if scheduledDate is set and urgency is not set as ON_SCHEDULED_DATE * @should fail validation if scheduledDate is null when urgency is ON_SCHEDULED_DATE * @should fail validation if orderType.javaClass does not match order.class * @should pass validation if the class of the order is a subclass of orderType.javaClass * @should pass validation if all fields are correct * @should not allow a future dateActivated * @should pass validation if field lengths are correct * @should fail validation if field lengths are not correct */ public void validate(Object obj, Errors errors) { Order order = (Order) obj; if (order == null) { errors.reject("error.general"); } else { // for the following elements Order.hbm.xml says: not-null="true" ValidationUtils.rejectIfEmpty(errors, "voided", "error.null"); //For DrugOrders, the api will set the concept to drug.concept if (!DrugOrder.class.isAssignableFrom(order.getClass())) { ValidationUtils.rejectIfEmpty(errors, "concept", "Concept.noConceptSelected"); } ValidationUtils.rejectIfEmpty(errors, "patient", "error.null"); ValidationUtils.rejectIfEmpty(errors, "encounter", "error.null"); ValidationUtils.rejectIfEmpty(errors, "orderer", "error.null"); ValidationUtils.rejectIfEmpty(errors, "urgency", "error.null"); ValidationUtils.rejectIfEmpty(errors, "action", "error.null"); validateSamePatientInOrderAndEncounter(order, errors); validateOrderTypeClass(order, errors); validateDateActivated(order, errors); validateScheduledDate(order, errors); ValidateUtil.validateFieldLengths(errors, obj.getClass(), "orderReasonNonCoded", "accessionNumber", "commentToFulfiller", "voidReason"); } }
From source file:org.openmrs.validator.PersonMergeLogValidator.java
/** * Checks the form object for any inconsistencies/errors * //from ww w.j av a 2s. c o m * @see org.springframework.validation.Validator#validate(java.lang.Object, * org.springframework.validation.Errors) * @should fail validation if personMergeLogData is null * @should fail validation if winner is null * @should fail validation if loser is null * @should pass validation if all fields are correct * @should pass validation if field lengths are correct * @should fail validation if field lengths are not correct */ public void validate(Object obj, Errors errors) { PersonMergeLog personMergeLog = (PersonMergeLog) obj; if (personMergeLog == null) { errors.rejectValue("persnMergeLog", "error.general"); } else { ValidationUtils.rejectIfEmpty(errors, "personMergeLogData", "error.null"); ValidationUtils.rejectIfEmpty(errors, "winner", "error.null"); ValidationUtils.rejectIfEmpty(errors, "loser", "error.null"); ValidateUtil.validateFieldLengths(errors, obj.getClass(), "voidReason"); } }