public EntityAttributeValidation updateEntityAttributeValidation(
     EntityAttributeValidation validation) throws ApplicationException {
   if (validation == null) {
     return null;
   }
   if (validation.getEntityAttributeValidationId() == null || validation.getParameters() == null) {
     throw new ApplicationException(
         "An entity attribute validation must first be created before it is updated.");
   }
   try {
     entityDefinitionDao.updateEntityAttributeValidation(validation);
     return validation;
   } catch (DaoException e) {
     throw new ApplicationException(e.getMessage());
   }
 }
  public void updateEntityAttributeValidations(
      List<EntityAttributeValidation> validations, Entity updatedEntity, String attributeName)
      throws ApplicationException {
    if (validations == null) {
      return;
    }

    Entity existing = entityDefinitionDao.loadEntity(updatedEntity.getEntityVersionId());
    EntityAttribute existingAttribute = existing.findAttributeByName(attributeName);
    List<EntityAttributeValidation> existingValidations =
        loadEntityAttributeValidations(existingAttribute);

    Map<Integer, EntityAttributeValidation> newValidationById =
        new HashMap<Integer, EntityAttributeValidation>();
    for (EntityAttributeValidation validation : validations) {
      if (validation.getEntityAttributeValidationId() != null) {
        newValidationById.put(validation.getEntityAttributeValidationId(), validation);
      }
    }

    // remove deleted validations
    for (EntityAttributeValidation validation : existingValidations) {
      if (newValidationById.get(validation.getEntityAttributeValidationId()) == null) {
        deleteEntityAttributeValidation(validation);
      }
    }

    for (EntityAttributeValidation newValidation : validations) {
      if (newValidation.getEntityAttributeValidationId() != null) {
        updateEntityAttributeValidation(newValidation);
      } else {
        addEntityAttributeValidation(newValidation);
      }
    }
  }
 public EntityAttributeValidation addEntityAttributeValidation(
     EntityAttributeValidation validation) throws ApplicationException {
   if (validation == null
       || validation.getEntityAttribute() == null
       || validation.getParameters() == null) {
     throw new ApplicationException("This entity attribute validation is invalid.");
   }
   if (validation.getEntityAttributeValidationId() != null) {
     throw new ApplicationException(
         "This entity attribute validation already exists so it can only be updated.");
   }
   try {
     entityDefinitionDao.addEntityAttributeValidation(validation);
     return validation;
   } catch (DaoException e) {
     throw new ApplicationException(e.getMessage());
   }
 }