public SecurityDomain(String name, String alias) { ValidateUtil.validateNotEmpty(name, "name"); ValidateUtil.validateNotEmpty(alias, "alias"); _name = name; _alias = alias; }
/** * Checks that a given concept map type object is valid. * * @see org.springframework.validation.Validator#validate(java.lang.Object, * org.springframework.validation.Errors) * @should fail if the concept map type object is null * @should fail if the name is null * @should fail if the name is an empty string * @should fail if the name is a white space character * @should fail if the concept map type name is a duplicate * @should pass if the name is unique amongst all concept map type names * @should pass validation if field lengths are correct * @should fail validation if field lengths are not correct */ public void validate(Object obj, Errors errors) { if (obj == null || !(obj instanceof ConceptMapType)) { throw new IllegalArgumentException( "The parameter obj should not be null and must be of type" + ConceptMapType.class); } ConceptMapType conceptMapType = (ConceptMapType) obj; String name = conceptMapType.getName(); if (!StringUtils.hasText(name)) { errors.rejectValue( "name", "ConceptMapType.error.nameRequired", "The name property is required for a concept map type"); return; } name = name.trim(); ConceptMapType duplicate = Context.getConceptService().getConceptMapTypeByName(name); if (duplicate != null && !OpenmrsUtil.nullSafeEquals(duplicate.getUuid(), conceptMapType.getUuid())) { errors.rejectValue( "name", "ConceptMapType.duplicate.name", "Duplicate concept map type name: " + name); } ValidateUtil.validateFieldLengths( errors, obj.getClass(), "name", "description", "retireReason"); }
/** * 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 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"); } }
/** * Validates a PatientIdentifier. * * @see org.springframework.validation.Validator#validate(java.lang.Object, * org.springframework.validation.Errors) * @should pass validation if field lengths are correct * @should fail validation if field lengths are not correct */ public void validate(Object obj, Errors errors) { PatientIdentifier pi = (PatientIdentifier) obj; try { validateIdentifier(pi); ValidateUtil.validateFieldLengths(errors, obj.getClass(), "identifier", "voidReason"); } catch (Exception e) { errors.reject(e.getMessage()); } }
public void validate(Object obj, Errors errors) { if (obj != null) { super.validate(obj, errors); ValidateUtil.validateFieldLengths( errors, obj.getClass(), "name", "description", "datatypeClassname", "preferredHandlerClassname", "retireReason"); } }
/** * Validates the given Patient. Currently just checks for errors in identifiers. TODO: Check for * errors in all Patient fields. * * @param obj The patient to validate. * @param errors Errors * @see org.springframework.validation.Validator#validate(java.lang.Object, * org.springframework.validation.Errors) * @should fail validation if gender is blank * @should fail validation if birthdate makes patient older that 120 years old * @should fail validation if birthdate is a future date * @should fail validation if a preferred patient identifier is not chosen * @should fail validation if voidReason is blank when patient is voided * @should fail validation if causeOfDeath is blank when patient is dead * @should fail validation if a preferred patient identifier is not chosen for voided patients * @should not fail when patient has only one identifier and its not preferred * @should pass validation if field lengths are correct * @should fail validation if field lengths are not correct */ public void validate(Object obj, Errors errors) { if (log.isDebugEnabled()) { log.debug(this.getClass().getName() + ".validate..."); } if (obj == null) { return; } super.validate(obj, errors); Patient patient = (Patient) obj; ValidationUtils.rejectIfEmptyOrWhitespace(errors, "gender", "Person.gender.required"); // Make sure they chose a preferred ID Boolean preferredIdentifierChosen = false; // Voided patients have only voided identifiers since they were voided with the patient, // so get all otherwise get the active ones Collection<PatientIdentifier> identifiers = patient.isVoided() ? patient.getIdentifiers() : patient.getActiveIdentifiers(); for (PatientIdentifier pi : identifiers) { if (pi.isPreferred()) { preferredIdentifierChosen = true; } } if (!preferredIdentifierChosen && identifiers.size() != 1) { errors.reject("error.preferredIdentifier"); } int index = 0; if (!errors.hasErrors()) { // Validate PatientIdentifers if (patient.getIdentifiers() != null) { for (PatientIdentifier identifier : patient.getIdentifiers()) { errors.pushNestedPath("identifiers[" + index + "]"); patientIdentifierValidator.validate(identifier, errors); errors.popNestedPath(); index++; } } } ValidateUtil.validateFieldLengths(errors, obj.getClass(), "voidReason"); }
/** * Get an attribute mapping for the attribute with the given Id. * * @param attributeId Id of an attribute whose mapping to lookup. Not empty. @see AttributeIds * @return An attribute mapping for the attribute with the given Id. Null if there is no mapping * for the specified attribute. */ public IdentityStoreAttributeMapping getAttributeMapping(String attributeId) { ValidateUtil.validateNotEmpty(attributeId, attributeId); return this._storeAttributes.get(attributeId); }
/** * add an attribute mapping for this object. Not null. * * @param attributeMapping */ public void addAttributeMapping(IdentityStoreAttributeMapping attributeMapping) { ValidateUtil.validateNotNull(attributeMapping, "attributeMapping"); this._storeAttributes.put(attributeMapping.getAttributeId(), attributeMapping); }
public String getGroup() { if (ValidateUtil.isValid(group)) { return " GROUP By " + group; } return ""; }
public String getHaving() { if (ValidateUtil.isValid(having)) { return " HAVING " + having; } return ""; }
public String getJoin() { if (ValidateUtil.isValid(join)) { return " " + join; } return ""; }
public static LocalDate parseLocalDate(String localDateAsString) { if (ValidateUtil.isEmptyText(localDateAsString)) { return null; } return LocalDate.parse(localDateAsString); }