/** * Reject the given field with the given error code if the value is empty. * <p>An 'empty' value in this context means either {@code null} or * the empty string "". * <p>The object whose field is being validated does not need to be passed * in because the {@link Errors} instance can resolve field values by itself * (it will usually hold an internal reference to the target object). * @param errors the {@code Errors} instance to register errors on * @param field the field name to check * @param errorCode the error code, interpretable as message key */ public static void rejectIfEmpty(Errors errors, String field, String errorCode) { rejectIfEmpty(errors, field, errorCode, null, null); }
ValidationUtils.rejectIfEmpty(errors, "encounterType", "Encounter.error.encounterType.required", "Encounter type is Required"); ValidationUtils.rejectIfEmpty(errors, "patient", "Encounter.error.patient.required", "Patient is required"); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "encounterDatetime", "Encounter.datetime.required"); if (encounter.getVisit() != null && !ObjectUtils.equals(encounter.getVisit().getPatient(), encounter.getPatient())) {
/** * Reject the given field with the given error code and error arguments * if the value is empty. * <p>An 'empty' value in this context means either {@code null} or * the empty string "". * <p>The object whose field is being validated does not need to be passed * in because the {@link Errors} instance can resolve field values by itself * (it will usually hold an internal reference to the target object). * @param errors the {@code Errors} instance to register errors on * @param field the field name to check * @param errorCode the error code, interpretable as message key * @param errorArgs the error arguments, for argument binding via MessageFormat * (can be {@code null}) */ public static void rejectIfEmpty(Errors errors, String field, String errorCode, Object[] errorArgs) { rejectIfEmpty(errors, field, errorCode, errorArgs, null); }
/** * Reject the given field with the given error code and default message * if the value is empty. * <p>An 'empty' value in this context means either {@code null} or * the empty string "". * <p>The object whose field is being validated does not need to be passed * in because the {@link Errors} instance can resolve field values by itself * (it will usually hold an internal reference to the target object). * @param errors the {@code Errors} instance to register errors on * @param field the field name to check * @param errorCode error code, interpretable as message key * @param defaultMessage fallback default message */ public static void rejectIfEmpty(Errors errors, String field, String errorCode, String defaultMessage) { rejectIfEmpty(errors, field, errorCode, null, defaultMessage); }
/** * Reject the given field with the given error code if the value is empty. * <p>An 'empty' value in this context means either {@code null} or * the empty string "". * <p>The object whose field is being validated does not need to be passed * in because the {@link Errors} instance can resolve field values by itself * (it will usually hold an internal reference to the target object). * @param errors the {@code Errors} instance to register errors on * @param field the field name to check * @param errorCode the error code, interpretable as message key */ public static void rejectIfEmpty(Errors errors, String field, String errorCode) { rejectIfEmpty(errors, field, errorCode, null, null); }
/** * Reject the given field with the given error code and default message * if the value is empty. * <p>An 'empty' value in this context means either {@code null} or * the empty string "". * <p>The object whose field is being validated does not need to be passed * in because the {@link Errors} instance can resolve field values by itself * (it will usually hold an internal reference to the target object). * @param errors the {@code Errors} instance to register errors on * @param field the field name to check * @param errorCode error code, interpretable as message key * @param defaultMessage fallback default message */ public static void rejectIfEmpty(Errors errors, String field, String errorCode, String defaultMessage) { rejectIfEmpty(errors, field, errorCode, null, defaultMessage); }
/** * Reject the given field with the given error code and error arguments * if the value is empty. * <p>An 'empty' value in this context means either {@code null} or * the empty string "". * <p>The object whose field is being validated does not need to be passed * in because the {@link Errors} instance can resolve field values by itself * (it will usually hold an internal reference to the target object). * @param errors the {@code Errors} instance to register errors on * @param field the field name to check * @param errorCode the error code, interpretable as message key * @param errorArgs the error arguments, for argument binding via MessageFormat * (can be {@code null}) */ public static void rejectIfEmpty(Errors errors, String field, String errorCode, Object[] errorArgs) { rejectIfEmpty(errors, field, errorCode, errorArgs, null); }
@Override public void validate(@Nullable Object obj, Errors errors) { ValidationUtils.rejectIfEmpty(errors, "name", "EMPTY", "You must enter a name!"); } }
@Override public void validate(DrugOrder order, Errors errors) { ValidationUtils.rejectIfEmpty(errors, "dosingInstructions", "DrugOrder.error.dosingInstructionsIsNullForDosingTypeFreeText"); }
@Test public void testValidationUtilsEmptyVariants() { TestBean tb = new TestBean(); Errors errors = new BeanPropertyBindingResult(tb, "tb"); ValidationUtils.rejectIfEmpty(errors, "name", "EMPTY_OR_WHITESPACE", new Object[] {"arg"}); assertTrue(errors.hasFieldErrors("name")); assertEquals("EMPTY_OR_WHITESPACE", errors.getFieldError("name").getCode()); assertEquals("arg", errors.getFieldError("name").getArguments()[0]); errors = new BeanPropertyBindingResult(tb, "tb"); ValidationUtils.rejectIfEmpty(errors, "name", "EMPTY_OR_WHITESPACE", new Object[] {"arg"}, "msg"); assertTrue(errors.hasFieldErrors("name")); assertEquals("EMPTY_OR_WHITESPACE", errors.getFieldError("name").getCode()); assertEquals("arg", errors.getFieldError("name").getArguments()[0]); assertEquals("msg", errors.getFieldError("name").getDefaultMessage()); }
private void validatePairedFields(DrugOrder order, Errors errors) { if (order.getDose() != null) { ValidationUtils.rejectIfEmpty(errors, "doseUnits", "DrugOrder.error.doseUnitsRequiredWithDose"); } if (order.getQuantity() != null) { ValidationUtils.rejectIfEmpty(errors, "quantityUnits", "DrugOrder.error.quantityUnitsRequiredWithQuantity"); } if (order.getDuration() != null) { ValidationUtils.rejectIfEmpty(errors, "durationUnits", "DrugOrder.error.durationUnitsRequiredWithDuration"); } }
@Override public void validate(DrugOrder order, Errors errors) { ValidationUtils.rejectIfEmpty(errors, "brandName", "DrugOrder.error.brandNameIsNull"); }
/** * Checks the form object for any inconsistencies/errors * * @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 */ @Override 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"); } }
/** * Checks that a given <code>Drug</code> object is valid. * * @param obj the Object to validate * @param errors holds the validation errors * @throws IllegalArgumentException Runtime Exception if the supplied argument is * null or not of type <code>Drug</code> * @see org.springframework.validation.Validator#validate(java.lang.Object, * org.springframework.validation.Errors) * @should fail if a concept is not specified */ @Override public void validate(Object obj, Errors errors) throws IllegalArgumentException { if (obj == null || !(obj instanceof Drug)) { throw new IllegalArgumentException("The parameter obj should not be null and must be of type" + Drug.class); } log.debug("request to validate drug having concept: " + ((Drug) obj).getConcept()); ValidationUtils.rejectIfEmpty(errors, "concept", "ConceptDrug.error.conceptRequired"); }
/** * @see DosingInstructions#validate(DrugOrder, org.springframework.validation.Errors) * @param order * @param errors * @should reject a duration unit with a mapping of an invalid type */ @Override public void validate(DrugOrder order, Errors errors) { ValidationUtils.rejectIfEmpty(errors, "dose", "DrugOrder.error.doseIsNullForDosingTypeSimple"); ValidationUtils.rejectIfEmpty(errors, "doseUnits", "DrugOrder.error.doseUnitsIsNullForDosingTypeSimple"); ValidationUtils.rejectIfEmpty(errors, "route", "DrugOrder.error.routeIsNullForDosingTypeSimple"); ValidationUtils.rejectIfEmpty(errors, "frequency", "DrugOrder.error.frequencyIsNullForDosingTypeSimple"); if (order.getAutoExpireDate() == null && order.getDurationUnits() != null && Duration.getCode(order.getDurationUnits()) == null) { errors.rejectValue("durationUnits", "DrugOrder.error.durationUnitsNotMappedToSnomedCtDurationCode"); } }
/** * @see org.springframework.validation.Validator#validate(java.lang.Object, org.springframework.validation.Errors) */ @Override public void validate(Object target, Errors errors) { Attribute<?, ?> attribute = (Attribute<?, ?>) target; ValidationUtils.rejectIfEmpty(errors, "attributeType", "error.null"); ValidationUtils.rejectIfEmpty(errors, "owner", "error.null"); Object value = attribute.getValue(); if (value == null) { errors.rejectValue("value", "error.null"); } else if (!CustomDatatypeUtil.validate(attribute)) { errors.rejectValue("value", "error.invalid"); } }
private void validateFieldsForOutpatientCareSettingType(DrugOrder order, Errors errors) { if (order.getAction() != Order.Action.DISCONTINUE && order.getCareSetting() != null && order.getCareSetting().getCareSettingType().equals(CareSetting.CareSettingType.OUTPATIENT)) { ValidationUtils.rejectIfEmpty(errors, "quantity", "DrugOrder.error.quantityIsNullForOutPatient"); ValidationUtils.rejectIfEmpty(errors, "numRefills", "DrugOrder.error.numRefillsIsNullForOutPatient"); } }
} else { ValidationUtils.rejectIfEmpty(errors, "voided", "error.null"); 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");
errors.reject("error.general"); } else { ValidationUtils.rejectIfEmpty(errors, "concept", "Concept.noConceptSelected");
ValidationUtils.rejectIfEmpty(errors, "patient", "allergyapi.patient.required");