protected void updateEntityFields(ActionContext actionContext, IGTEntity entity)
     throws GTClientException {
   AS2DocTypeMappingAForm as2DocTypeMappingAForm =
       (AS2DocTypeMappingAForm) actionContext.getActionForm();
   entity.setFieldValue(
       IGTAS2DocTypeMappingEntity.AS2_DOC_TYPE, as2DocTypeMappingAForm.getAs2DocType());
   entity.setFieldValue(IGTAS2DocTypeMappingEntity.DOC_TYPE, as2DocTypeMappingAForm.getDocType());
   entity.setFieldValue(
       IGTAS2DocTypeMappingEntity.PARTNER_ID, as2DocTypeMappingAForm.getPartnerId());
 }
  protected void initialiseActionForm(ActionContext actionContext, IGTEntity entity)
      throws GTClientException {
    if (entity.isNewEntity()) {

    } else {
      AS2DocTypeMappingAForm form = (AS2DocTypeMappingAForm) actionContext.getActionForm();
      form.setAs2DocType((String) entity.getFieldValue(IGTAS2DocTypeMappingEntity.AS2_DOC_TYPE));
      form.setDocType((String) entity.getFieldValue(IGTAS2DocTypeMappingEntity.DOC_TYPE));
      form.setPartnerId((String) entity.getFieldValue(IGTAS2DocTypeMappingEntity.PARTNER_ID));
    }
  }
 public static boolean basicValidateFiles(
     ActionErrors actionErrors,
     Number fieldId,
     ActionForm form,
     IGTEntity entity,
     String[] extensions)
     throws GTClientException {
   try {
     boolean newEntity = entity.isNewEntity();
     if (!(form instanceof GTActionFormBase)) {
       throw new java.lang.UnsupportedOperationException(
           "Form must be a subclass of GTActionFormBase");
     }
     IGTFieldMetaInfo fmi = entity.getFieldMetaInfo(fieldId);
     if (fmi == null) {
       throw new java.lang.NullPointerException(
           "No fieldMetaInfo for field:" + fieldId + " of entity " + entity);
     }
     if ((!fmi.isDisplayable(newEntity)) || (!fmi.isEditable(newEntity))) {
       return true;
     }
     String fieldName = fmi.getFieldName(); // 20030410AH
     FormFileElement[] elements =
         ((GTActionFormBase) form).getFormFileElements(fieldName); // 20030410AH
     if (fmi.isMandatory(newEntity)) {
       if ((elements == null) || (elements.length == 0)) {
         addFieldError(actionErrors, fieldName, entity.getType(), REQUIRED, null); // 20021220AH
         return false;
       }
     }
     if (extensions != null) { // 20030410AH - Check file extensions are of those allowed
       boolean allOk = true;
       if (elements != null) {
         for (int i = 0; i < elements.length; i++) {
           String filename = elements[i].getFileName();
           if (filename == null)
             throw new NullPointerException("Internal assertion failure: filename is null");
           String extension = StaticUtils.getFileExtension(filename);
           if (StaticUtils.findValueInArray(extensions, extension, false) == -1) {
             String[] params = new String[] {filename};
             addFieldError(actionErrors, fieldName, entity.getType(), INVALID_EXTENSION, params);
             return false;
           }
         }
       }
     }
     return true;
   } catch (Throwable t) {
     throw new GTClientException("Error validating file field:" + fieldId, t);
   }
 }
 public static boolean basicValidateUrl(
     ActionErrors actionErrors, Number fieldId, ActionForm form, IGTEntity entity)
     throws GTClientException { // 20040211AH
   try {
     String fieldName = entity.getFieldName(fieldId);
     String value = (String) PropertyUtils.getSimpleProperty(form, fieldName);
     try {
       new URL(value);
     } catch (Exception e) {
       addFieldError(actionErrors, fieldName, entity.getType(), INVALID, null);
       return false;
     }
     return true;
   } catch (Exception e) {
     throw new GTClientException("Error validating (url) field:" + fieldId, e);
   }
 }
 protected void saveWithManager(ActionContext actionContext, IGTManager manager, IGTEntity entity)
     throws GTClientException {
   Short status = (Short) entity.getFieldValue(IGTConnectionSetupResultEntity.STATUS);
   boolean returnToUpdate = !(IGTConnectionSetupResultEntity.STATUS_SUCCESS.equals(status));
   actionContext.setAttribute(RETURN_TO_UPDATE_KEY, new Boolean(returnToUpdate));
   manager.update(entity);
   if (returnToUpdate) {
     initialiseActionForm(actionContext, entity);
     prepLists(actionContext, true); // yuck (we are calling it twice this way - but it works)
   }
 }
 public static boolean basicValidateStringArray(
     ActionErrors actionErrors, Number fieldId, ActionForm form, IGTEntity entity)
     throws GTClientException {
   try {
     String fieldName = entity.getFieldName(fieldId);
     String[] value = (String[]) PropertyUtils.getSimpleProperty(form, fieldName);
     return basicValidateStringArray(actionErrors, fieldName, value, fieldId, entity);
   } catch (Exception e) {
     throw new GTClientException("Error validating field:" + fieldId, e);
   }
 }
 public static boolean validateKeys(
     ActionErrors actionErrors, String field, String[] keys, Number entityField, IGTEntity entity)
     throws GTClientException {
   try {
     IGTFieldMetaInfo fmi = entity.getFieldMetaInfo(entityField);
     boolean newEntity = entity.isNewEntity();
     if (fmi == null) {
       throw new java.lang.NullPointerException(
           "No fieldMetaInfo for field:" + entityField + "(" + field + ") of entity " + entity);
     }
     if ((!fmi.isDisplayable(newEntity)) || (!fmi.isEditable(newEntity))) {
       return true;
     }
     if (fmi.isMandatory(newEntity)) {
       if ((keys == null) || (keys.length == 0)) {
         // actionErrors.add(field,new ActionError(entity.getType() + ".error." + field +
         // ".required"));
         addFieldError(actionErrors, field, entity.getType(), REQUIRED, null); // 20021220AH
         return false;
       } else { // 20030515AH - Check each key to make sure it has a value as we could well
         // just have an array with a single empty string (or such like)
         boolean someOk = false;
         boolean someEmpty = false;
         for (int i = 0; i < keys.length; i++) {
           if (StaticUtils.stringEmpty(keys[i])) {
             someEmpty = true;
           } else {
             someOk = true;
           }
         }
         if (someEmpty) {
           addFieldError(actionErrors, field, entity.getType(), someOk ? INVALID : REQUIRED, null);
           return false;
         }
       }
     }
     return true;
   } catch (Throwable t) {
     throw new GTClientException("Error validating field " + entityField, t);
   }
 }
 // 20030918 DDJ: Added method
 public static boolean basicValidateStringArray(
     ActionErrors actionErrors, String field, String[] value, Number entityField, IGTEntity entity)
     throws GTClientException {
   try {
     IGTFieldMetaInfo fmi = entity.getFieldMetaInfo(entityField);
     if (fmi == null) {
       throw new java.lang.NullPointerException(
           "No fieldMetaInfo for field:" + entityField + "(" + field + ") of entity " + entity);
     }
     boolean newEntity = entity.isNewEntity();
     if (!fmi.isDisplayable(newEntity) || !fmi.isEditable(newEntity)) {
       return true;
     }
     if (fmi.isMandatory(newEntity)) {
       if (value == null || value.length == 0) {
         // actionErrors.add(field,new ActionError(entity.getType() + ".error." + field +
         // ".required"));
         addFieldError(actionErrors, field, entity.getType(), REQUIRED, null);
         return false;
       }
     }
     // validate based on value class
     String valueClass = fmi.getValueClass();
     for (int i = 0; i < value.length; i++) {
       try {
         StaticUtils.convert(value[i], valueClass, true, false);
       } catch (UnsupportedOperationException valueClassUnsupported) {
         // swallow, ignore testing unsupported value class
       } catch (Throwable t) {
         addFieldError(actionErrors, field, entity.getType(), INVALID, null);
         return false;
       }
     }
     return true;
   } catch (Throwable t) {
     throw new GTClientException("Error validating field " + entityField, t);
   }
 }
  protected void validateActionForm(
      ActionContext actionContext, IGTEntity entity, ActionForm form, ActionErrors errors)
      throws GTClientException {
    // IGTServiceAssignmentEntity serviceAssignment = (IGTServiceAssignmentEntity)entity;
    ServiceAssignmentAForm tform = (ServiceAssignmentAForm) form;

    basicValidateString(errors, IGTServiceAssignmentEntity.USER_NAME, form, entity);
    basicValidateString(errors, IGTServiceAssignmentEntity.USER_TYPE, form, entity);
    String password = tform.getUserPassword();
    if (entity.isNewEntity() || (password != null && password.trim().length() > 0)) {
      basicValidateString(errors, IGTServiceAssignmentEntity.PASSWORD, form, entity);
    }
    basicValidateStringArray(errors, IGTServiceAssignmentEntity.WEBSERVICE_UIDS, form, entity);
  }
  protected void updateEntityFields(ActionContext actionContext, IGTEntity entity)
      throws GTClientException {
    IGTServiceAssignmentEntity serviceAssignment = (IGTServiceAssignmentEntity) entity;
    ServiceAssignmentAForm form = (ServiceAssignmentAForm) actionContext.getActionForm();
    serviceAssignment.setFieldValue(IGTServiceAssignmentEntity.USER_NAME, form.getUserName());
    serviceAssignment.setFieldValue(
        IGTServiceAssignmentEntity.USER_TYPE, IGTServiceAssignmentEntity.PARTNER_TYPE);
    String password = form.getUserPassword();
    if (entity.isNewEntity() || (password != null && password.trim().length() > 0)) {
      serviceAssignment.setFieldValue(IGTServiceAssignmentEntity.PASSWORD, form.getUserPassword());
    }

    Collection webServiceUids = StaticUtils.collectionValue(form.getWebServiceUids());
    serviceAssignment.setFieldValue(IGTServiceAssignmentEntity.WEBSERVICE_UIDS, webServiceUids);
  }
  /**
   * Performs rudimentary string field validation checking for the presence of data in fields that
   * are mandatory and the maximum length of the field.
   */
  public static boolean basicValidateString(
      ActionErrors actionErrors, String field, String value, Number entityField, IGTEntity entity)
      throws GTClientException {
    try {
      IGTFieldMetaInfo fmi = entity.getFieldMetaInfo(entityField);
      boolean newEntity = entity.isNewEntity();
      if (fmi == null) {
        throw new java.lang.NullPointerException(
            "No fieldMetaInfo for field:" + entityField + "(" + field + ") of entity " + entity);
      }
      if ((!fmi.isDisplayable(newEntity)) || (!fmi.isEditable(newEntity))) {
        return true;
      }
      if (fmi.isMandatory(newEntity)) {
        if ((value == null) || (value.equals(""))) {
          // actionErrors.add(field,new ActionError(entity.getType() + ".error." + field +
          // ".required"));
          addFieldError(actionErrors, field, entity.getType(), REQUIRED, null); // 20021220AH
          return false;
        }
      }

      if (fmi.getConstraintType() == IConstraint.TYPE_TEXT) {
        ITextConstraint textConstraint = (ITextConstraint) fmi.getConstraint();
        /* 20030918 DDJ: Fixed checking of minLength when maxLength = -1
        if(textConstraint.getMaxLength() > 0)
        {
          int valueLength = value==null ? 0 : value.length();
          if( (valueLength > textConstraint.getMaxLength())
              || (valueLength < textConstraint.getMinLength()) )
        */
        int valueLength = (value == null) ? 0 : value.length();
        if ((textConstraint.getMaxLength() > 0 && valueLength > textConstraint.getMaxLength())
            || (valueLength < textConstraint.getMinLength())) {
          // actionErrors.add(field,new ActionError(entity.getType() + ".error." + field +
          // ".invalid"));
          addFieldError(actionErrors, field, entity.getType(), INVALID, null); // 20021220AH
          return false;
        }
      }

      boolean valueEmpty = ((value == null) || ("".equals(value)));
      Number convertedValue = null;
      if ("java.lang.Integer".equals(fmi.getValueClass()) && !valueEmpty) {
        try {
          convertedValue = new Integer(value);
        } catch (Exception e) {
          // actionErrors.add(field,new ActionError(entity.getType() + ".error." + field +
          // ".invalid"));
          addFieldError(actionErrors, field, entity.getType(), INVALID, null); // 20021220AH
          return false;
        }
      } else if ("java.lang.Short".equals(fmi.getValueClass()) && !valueEmpty) {
        try {
          convertedValue = new Short(value);
        } catch (Exception e) {
          // actionErrors.add(field,new ActionError(entity.getType() + ".error." + field +
          // ".invalid"));
          addFieldError(actionErrors, field, entity.getType(), INVALID, null); // 20021220AH
          return false;
        }
      } else if ("java.lang.Long".equals(fmi.getValueClass()) && !valueEmpty) {
        try {
          convertedValue = new Long(value);
        } catch (Exception e) {
          // actionErrors.add(field,new ActionError(entity.getType() + ".error." + field +
          // ".invalid"));
          addFieldError(actionErrors, field, entity.getType(), INVALID, null); // 20021220AH
          return false;
        }
      }

      if (convertedValue != null
          && fmi.getConstraintType()
              == IConstraint.TYPE_RANGE) { // This is to apply range constraint
        try {
          IRangeConstraint rangeConstraint = (IRangeConstraint) fmi.getConstraint();
          Number min = rangeConstraint.getMin(0);
          Number max = rangeConstraint.getMax(0);
          if (min == null) throw new NullPointerException("min is null");
          if (max == null) throw new NullPointerException("min is null");
          if ((convertedValue.doubleValue() < min.doubleValue())
              || (convertedValue.doubleValue() > max.doubleValue()))
            throw new Exception("Value out of range, constraint min=" + min + ", max=" + max);
        } catch (Exception ex) {
          addFieldError(actionErrors, field, entity.getType(), INVALID, null);
          return false;
        }
      }
      return true;
    } catch (Throwable t) {
      throw new GTClientException("Error validating field " + entityField, t);
    }
  }