@Before
  public void setUp() throws Exception {

    processor = new ValidCharactersConstraintProcessor();

    dictionaryValidationResult = new DictionaryValidationResult();
    dictionaryValidationResult.setErrorLevel(ErrorLevel.NOCONSTRAINT);

    addressEntry = new BusinessObjectEntry();

    List<AttributeDefinition> attributes = new ArrayList<AttributeDefinition>();

    cityAlphaPatternConstraint = new AlphaPatternConstraint();
    cityAlphaPatternConstraint.setMessageKey("validate.dummykey");
    cityAlphaPatternConstraint.setValidationMessageParams(new ArrayList<String>());

    cityDefinition = new AttributeDefinition();
    cityDefinition.setName("city");
    cityDefinition.setValidCharactersConstraint(cityAlphaPatternConstraint);
    attributes.add(cityDefinition);

    street1AlphaPatternConstraint = new AlphaPatternConstraint();
    street1AlphaPatternConstraint.setMessageKey("validate.dummykey");
    street1AlphaPatternConstraint.setValidationMessageParams(new ArrayList<String>());
    street1AlphaPatternConstraint.setAllowWhitespace(true);

    street1Definition = new AttributeDefinition();
    street1Definition.setName("street1");
    street1Definition.setValidCharactersConstraint(street1AlphaPatternConstraint);
    attributes.add(street1Definition);

    addressEntry.setAttributes(attributes);
  }
  /**
   * @see
   *     org.kuali.rice.krad.service.DataDictionaryService#getAttributeDisplayMask(java.lang.String,
   *     java.lang.String)
   */
  public AttributeSecurity getAttributeSecurity(String entryName, String attributeName) {
    AttributeSecurity attributeSecurity = null;

    AttributeDefinition attributeDefinition = getAttributeDefinition(entryName, attributeName);
    if (attributeDefinition != null) {
      attributeSecurity = attributeDefinition.getAttributeSecurity();
    }

    return attributeSecurity;
  }
  /**
   * @see org.kuali.rice.krad.service.DataDictionaryService#isAttributeRequired(java.lang.Class,
   *     java.lang.String)
   */
  public Boolean isAttributeRequired(String entryName, String attributeName) {
    Boolean required = null;

    AttributeDefinition attributeDefinition = getAttributeDefinition(entryName, attributeName);
    if (attributeDefinition != null) {
      required = attributeDefinition.isRequired();
    }

    return required;
  }
  /**
   * @see
   *     org.kuali.rice.krad.service.DataDictionaryService#getAttributeDescription(java.lang.String)
   */
  public String getAttributeDescription(String entryName, String attributeName) {
    String description = null;

    AttributeDefinition attributeDefinition = getAttributeDefinition(entryName, attributeName);
    if (attributeDefinition != null) {
      description = attributeDefinition.getDescription();
    }

    return description;
  }
  /**
   * @see org.kuali.rice.krad.service.DataDictionaryService#getAttributeSummary(java.lang.String)
   */
  public String getAttributeSummary(String entryName, String attributeName) {
    String summary = null;

    AttributeDefinition attributeDefinition = getAttributeDefinition(entryName, attributeName);
    if (attributeDefinition != null) {
      summary = attributeDefinition.getSummary();
    }

    return summary;
  }
  /**
   * @see org.kuali.rice.krad.service.DataDictionaryService#getAttributeMaxLength(java.lang.String)
   */
  public Integer getAttributeMaxLength(String entryName, String attributeName) {
    Integer maxLength = null;

    AttributeDefinition attributeDefinition = getAttributeDefinition(entryName, attributeName);
    if (attributeDefinition != null) {
      maxLength = attributeDefinition.getMaxLength();
    }

    return maxLength;
  }
 /**
  * @see
  *     org.kuali.rice.krad.service.DataDictionaryService#getAttributeValidatingErrorMessageKey(java.lang.String,
  *     java.lang.String)
  */
 public String getAttributeValidatingErrorMessageKey(String entryName, String attributeName) {
   AttributeDefinition attributeDefinition = getAttributeDefinition(entryName, attributeName);
   if (attributeDefinition != null) {
     if (attributeDefinition.hasValidationPattern()) {
       ValidationPattern validationPattern = attributeDefinition.getValidationPattern();
       return validationPattern.getValidationErrorMessageKey();
     }
   }
   return null;
 }
  /**
   * @see
   *     org.kuali.rice.krad.service.DataDictionaryService#getAttributeControlDefinition(java.lang.String)
   */
  public ControlDefinition getAttributeControlDefinition(String entryName, String attributeName) {
    ControlDefinition controlDefinition = null;

    AttributeDefinition attributeDefinition = getAttributeDefinition(entryName, attributeName);
    if (attributeDefinition != null) {
      controlDefinition = attributeDefinition.getControl();
    }

    return controlDefinition;
  }
  protected void addAttributesToLookupCriteria(LookupView view, DataObjectEntry dataObjectEntry) {
    AttributeDefinition activeAttribute = null;
    for (AttributeDefinition attr : dataObjectEntry.getAttributes()) {
      // Check if we have been told not to display this attribute here
      boolean dontDisplay =
          hasHintOfType(attr.getDataObjectAttribute(), UifDisplayHintType.NO_LOOKUP_CRITERIA);
      dontDisplay |= (attr.getControlField() instanceof HiddenControl);

      if (dontDisplay) {
        continue;
      }
      if (attr.getName().equals(KRADPropertyConstants.ACTIVE)) {
        activeAttribute = attr;
        continue; // leave until the end of the lookup criteria
      }
      LookupInputField field = ComponentFactory.getLookupCriteriaInputField();
      field.setPropertyName(attr.getName());
      field.setLabel(attr.getLabel());
      view.getCriteriaFields().add(field);
    }
    // If there was one, add the active attribute at the end
    if (activeAttribute != null) {
      LookupInputField field = ComponentFactory.getLookupCriteriaInputField();
      field.setPropertyName(activeAttribute.getName());
      field.setLabel(activeAttribute.getLabel());
      view.getCriteriaFields().add(field);
    }
  }
예제 #10
0
  @SuppressWarnings("unchecked")
  protected void addCollectionSectionsToInquiryView(
      InquiryView view, DataObjectEntry dataObjectEntry) {
    for (CollectionDefinition coll : dataObjectEntry.getCollections()) {
      // Create a new section
      DataObjectEntry collectionEntry =
          dataDictionaryService.getDataDictionary().getDataObjectEntry(coll.getDataObjectClass());
      // Extract the key fields on the collection which are linked to the parent.
      // When auto-generating the Inquiry Collection table, we want to exclude those.
      Collection<String> collectionFieldsLinkedToParent = new HashSet<String>();

      if (coll.getDataObjectCollection() != null) {
        for (DataObjectAttributeRelationship rel :
            coll.getDataObjectCollection().getAttributeRelationships()) {
          collectionFieldsLinkedToParent.add(rel.getChildAttributeName());
        }
      }

      if (collectionEntry == null) {
        LOG.warn(
            "Unable to find DataObjectEntry for collection class: " + coll.getDataObjectClass());
        continue;
      }

      CollectionGroup section = createCollectionInquirySection(coll.getName(), coll.getLabel());
      try {
        section.setCollectionObjectClass(Class.forName(coll.getDataObjectClass()));
      } catch (ClassNotFoundException e) {
        LOG.warn(
            "Unable to set class on collection section - class not found: "
                + coll.getDataObjectClass());
      }

      section.setPropertyName(coll.getName());
      // summary title : collection object label
      // Summary fields : PK fields?
      // add the attributes to the section
      for (AttributeDefinition attr : collectionEntry.getAttributes()) {
        boolean dontDisplay =
            hasHintOfType(attr.getDataObjectAttribute(), UifDisplayHintType.NO_INQUIRY);
        dontDisplay |= (attr.getControlField() instanceof HiddenControl);
        // Auto-exclude fields linked to the parent object
        dontDisplay |= collectionFieldsLinkedToParent.contains(attr.getName());

        if (dontDisplay) {
          continue;
        }

        DataField dataField = ComponentFactory.getDataField();
        dataField.setPropertyName(attr.getName());
        ((List<Component>) section.getItems()).add(dataField);
      }
      ((List<Group>) view.getItems()).add(section);
    }
  }
  /**
   * @see org.kuali.rice.krad.service.DataDictionaryService#getAttributeFormatter(java.lang.String)
   */
  public Class<? extends Formatter> getAttributeFormatter(String entryName, String attributeName) {
    Class formatterClass = null;

    AttributeDefinition attributeDefinition = getAttributeDefinition(entryName, attributeName);
    if (attributeDefinition != null) {
      if (attributeDefinition.hasFormatterClass()) {
        formatterClass = ClassLoaderUtils.getClass(attributeDefinition.getFormatterClass());
      }
    }

    return formatterClass;
  }
  /**
   * @see
   *     org.kuali.rice.krad.service.DataDictionaryService#getAttributeValuesScopeId(java.lang.Class,
   *     java.lang.String)
   */
  public Class<? extends KeyValuesFinder> getAttributeValuesFinderClass(
      String entryName, String attributeName) {
    Class valuesFinderClass = null;

    AttributeDefinition attributeDefinition = getAttributeDefinition(entryName, attributeName);
    if (attributeDefinition != null) {
      String valuesFinderClassName = attributeDefinition.getControl().getValuesFinderClass();
      valuesFinderClass = ClassLoaderUtils.getClass(valuesFinderClassName);
    }

    return valuesFinderClass;
  }
 /**
  * @see
  *     org.kuali.rice.krad.service.DataDictionaryService#getAttributeValidatingErrorMessageParameters(java.lang.String,
  *     java.lang.String)
  */
 public String[] getAttributeValidatingErrorMessageParameters(
     String entryName, String attributeName) {
   AttributeDefinition attributeDefinition = getAttributeDefinition(entryName, attributeName);
   if (attributeDefinition != null) {
     if (attributeDefinition.hasValidationPattern()) {
       ValidationPattern validationPattern = attributeDefinition.getValidationPattern();
       String attributeLabel = getAttributeErrorLabel(entryName, attributeName);
       return validationPattern.getValidationErrorMessageParameters(attributeLabel);
     }
   }
   return null;
 }
예제 #14
0
  @Override
  public ValidCharactersConstraint deriveValidCharactersConstraint(AttributeDefinition attrDef) {
    ValidCharactersConstraint validCharactersConstraint = null;
    // First - see if one was defined in the metadata (provided by krad-data module annotations)
    if (attrDef.getDataObjectAttribute() != null) {
      if (StringUtils.isNotBlank(
          attrDef.getDataObjectAttribute().getValidCharactersConstraintBeanName())) {
        Object consObj =
            dataDictionaryService.getDictionaryBean(
                attrDef.getDataObjectAttribute().getValidCharactersConstraintBeanName());
        if (consObj != null && consObj instanceof ValidCharactersConstraint) {
          validCharactersConstraint = (ValidCharactersConstraint) consObj;
        }
      }
    }
    // if not, make an intelligent guess from the data type
    if (validCharactersConstraint == null) {
      if (attrDef.getDataType() != null) {
        if (attrDef.getDataType() == DataType.CURRENCY) {
          validCharactersConstraint =
              (ValidCharactersConstraint)
                  dataDictionaryService.getDictionaryBean(CURRENCY_PATTERN_CONSTRAINT);
        } else if (attrDef.getDataType() == DataType.PRECISE_DECIMAL) {
          validCharactersConstraint =
              (ValidCharactersConstraint)
                  dataDictionaryService.getDictionaryBean(BIG_DECIMAL_PATTERN_CONSTRAINT);
        } else if (attrDef.getDataType().isNumeric()) {
          validCharactersConstraint =
              (ValidCharactersConstraint)
                  dataDictionaryService.getDictionaryBean(FLOATING_POINT_PATTERN_CONSTRAINT);
        } else if (attrDef.getDataType().isTemporal()) {
          if (attrDef.getDataType() == DataType.DATE) {
            validCharactersConstraint =
                (ValidCharactersConstraint)
                    dataDictionaryService.getDictionaryBean(DATE_PATTERN_CONSTRAINT);
          } else if (attrDef.getDataType() == DataType.TIMESTAMP) {
            validCharactersConstraint =
                (ValidCharactersConstraint)
                    dataDictionaryService.getDictionaryBean(TIMESTAMP_PATTERN_CONSTRAINT);
          }
        }
      }
    }
    // default to UTF8
    if (validCharactersConstraint == null) {
      validCharactersConstraint =
          (ValidCharactersConstraint)
              dataDictionaryService.getDictionaryBean(ANY_CHARACTER_PATTERN_CONSTRAINT);
    }

    return validCharactersConstraint;
  }
  /** @see org.kuali.rice.krad.service.DataDictionaryService#getAttributeSize(java.lang.String) */
  public Integer getAttributeSize(String entryName, String attributeName) {
    Integer size = null;

    AttributeDefinition attributeDefinition = getAttributeDefinition(entryName, attributeName);
    if (attributeDefinition != null) {
      ControlDefinition controlDefinition = attributeDefinition.getControl();
      if (controlDefinition.isText() || controlDefinition.isCurrency()) {
        size = controlDefinition.getSize();
      }
    }

    return size;
  }
  /**
   * @see
   *     org.kuali.rice.krad.service.DataDictionaryService#getAttributeValidatingExpression(java.lang.String)
   */
  public Pattern getAttributeValidatingExpression(String entryName, String attributeName) {
    Pattern regex = null;

    AttributeDefinition attributeDefinition = getAttributeDefinition(entryName, attributeName);
    if (attributeDefinition != null && (attributeDefinition.getValidationPattern() != null)) {
      regex = attributeDefinition.getValidationPattern().getRegexPattern();
    } else {
      // workaround for existing calls which don't bother checking for null return values
      regex = Pattern.compile(".*");
    }

    return regex;
  }
  /**
   * @see
   *     org.kuali.rice.krad.service.DataDictionaryService#getAttributeForceUppercase(java.lang.String)
   */
  public Boolean getAttributeForceUppercase(String entryName, String attributeName)
      throws UnknownBusinessClassAttributeException {
    Boolean forceUppercase = null;

    AttributeDefinition attributeDefinition = getAttributeDefinition(entryName, attributeName);
    if (attributeDefinition == null) {
      throw new UnknownBusinessClassAttributeException(
          "Could not find a matching data dictionary business class attribute entry for "
              + entryName
              + "."
              + attributeName);
    }
    forceUppercase = attributeDefinition.getForceUppercase();

    return forceUppercase;
  }
  /** @see org.kuali.rice.krad.service.DataDictionaryService#getAttributeLabel(java.lang.String) */
  public String getAttributeLabel(String entryName, String attributeName) {
    String label = "";

    AttributeDefinition attributeDefinition = getAttributeDefinition(entryName, attributeName);
    if (attributeDefinition != null) {
      // KULRICE-4445 prevent NullPointerException by ensuring a label is set
      label = attributeDefinition.getLabel();
      if (!StringUtils.isEmpty(attributeDefinition.getDisplayLabelAttribute())) {
        attributeDefinition =
            getAttributeDefinition(entryName, attributeDefinition.getDisplayLabelAttribute());
        if (attributeDefinition != null) {
          label = attributeDefinition.getLabel();
        }
      }
    }

    return label;
  }
  /**
   * @see org.kuali.rice.krad.service.DataDictionaryService#getAttributeShortLabel(java.lang.String)
   */
  public String getAttributeShortLabel(String entryName, String attributeName) {
    String shortLabel = "";

    AttributeDefinition attributeDefinition = getAttributeDefinition(entryName, attributeName);
    if (attributeDefinition != null) {
      if (!StringUtils.isEmpty(attributeDefinition.getDisplayLabelAttribute())) {
        attributeDefinition =
            getAttributeDefinition(entryName, attributeDefinition.getDisplayLabelAttribute());
        if (attributeDefinition != null) {
          shortLabel = attributeDefinition.getShortLabel();
        }
      } else {
        shortLabel = attributeDefinition.getShortLabel();
      }
    }

    return shortLabel;
  }
  /**
   * Calculates a map with the field length of all of the attributes of the class given by the
   * getBusinessObjectClass method
   */
  protected void initializeFieldLengthMap() {
    fieldLengthMap = new HashMap<String, Integer>();
    DataDictionaryService dataDictionaryService =
        SpringContext.getBean(DataDictionaryService.class);
    List<AttributeDefinition> attributes =
        dataDictionaryService
            .getDataDictionary()
            .getBusinessObjectEntry(getBusinessObjectClass().getName())
            .getAttributes();

    for (AttributeDefinition attributeDefinition : attributes) {
      Integer fieldLength;
      fieldLength =
          dataDictionaryService.getAttributeMaxLength(
              getBusinessObjectClass(), attributeDefinition.getName());
      fieldLengthMap.put(attributeDefinition.getName(), fieldLength);
    }
  }
  /**
   * Checks an account numbers exact length
   *
   * @param accountNumber
   * @param size to be returned
   * @return
   */
  protected boolean isValidAccountNumberLength(
      String accountNumber, AccountCreationStatusDTO accountCreationStatus) {

    boolean isValid = false;
    int fieldSize = -1;

    // grab account number length from DD and set size
    final org.kuali.rice.krad.datadictionary.BusinessObjectEntry entry =
        SpringContext.getBean(DataDictionaryService.class)
            .getDataDictionary()
            .getBusinessObjectEntry(Account.class.getName());
    AttributeDefinition attributeDefinition =
        entry.getAttributeDefinition(KFSPropertyConstants.ACCOUNT_NUMBER);

    if (ObjectUtils.isNotNull(attributeDefinition)) {
      final ValidationPattern validationPattern = attributeDefinition.getValidationPattern();

      if (ObjectUtils.isNotNull(validationPattern)
          && validationPattern instanceof AlphaNumericValidationPattern) {
        AlphaNumericValidationPattern alphaPattern =
            (AlphaNumericValidationPattern) validationPattern;
        fieldSize = alphaPattern.getExactLength();
      }
    }

    // skip if account number null
    if (ObjectUtils.isNotNull(accountNumber)) {

      // data dictionary defined size must equal length of incoming value
      if (fieldSize == accountNumber.length()) {
        isValid = true;
      }
    }

    if (isValid == false) {
      setFailStatus(
          accountCreationStatus,
          KcUtils.getErrorMessage(
              KcConstants.AccountCreationService.ERROR_KR_ALPHANUMERIC_VALIDATION_EXACT_LENGTH,
              new String[] {"account number", String.valueOf(fieldSize)}));
    }

    return isValid;
  }
예제 #22
0
 @Override
 public Control deriveControlAttributeFromMetadata(AttributeDefinition attrDef) {
   DataObjectAttribute dataObjectAttribute = attrDef.getDataObjectAttribute();
   Control c = getControlInstance(attrDef, dataObjectAttribute);
   // If we a have a control...we should - but just in case - don't want to be too dependent on
   // assumptions of the above code
   if (c != null) {
     customizeControlInstance(c, attrDef, dataObjectAttribute);
   }
   return c;
 }
  /**
   * Override of InputField copy to setup properties necessary to make the field usable for
   * inputting search criteria.
   *
   * <p>Note super is not being called because we don't want to add restirctions that can cause
   * problems with the use of wildcard {@inheritDoc}
   */
  @Override
  public void copyFromAttributeDefinition(AttributeDefinition attributeDefinition) {
    // label
    if (StringUtils.isEmpty(getLabel())) {
      setLabel(attributeDefinition.getLabel());
    }

    // short label
    if (StringUtils.isEmpty(getShortLabel())) {
      setShortLabel(attributeDefinition.getShortLabel());
    }

    // security
    if ((attributeDefinition.getAttributeSecurity() != null)
        && ((getDataFieldSecurity() == null)
            || (getDataFieldSecurity().getAttributeSecurity() == null))) {
      initializeComponentSecurity();

      getDataFieldSecurity().setAttributeSecurity(attributeDefinition.getAttributeSecurity());
    }

    // options
    if (getOptionsFinder() == null) {
      setOptionsFinder(attributeDefinition.getOptionsFinder());
    }

    // use control from dictionary if not specified and convert for searching
    if (getControl() == null) {
      Control control = convertControlToLookupControl(attributeDefinition);
      setControl(control);
    }

    // overwrite maxLength to allow for wildcards and ranges; set a minimum max length unless it is
    // greater than 100
    setMaxLength(100);
    if (attributeDefinition.getMaxLength() != null && (attributeDefinition.getMaxLength() > 100)) {
      setMaxLength(attributeDefinition.getMaxLength());
    }

    // set default value for active field to true
    if (getDefaultValue() == null
        || (getDefaultValue() instanceof String
            && StringUtils.isEmpty((String) getDefaultValue()))) {
      if ((StringUtils.equals(getPropertyName(), KRADPropertyConstants.ACTIVE))) {
        setDefaultValue(KRADConstants.YES_INDICATOR_VALUE);
      }
    }
  }
  /**
   * If control definition is defined on the given attribute definition, converts to an appropriate
   * control for searching (if necessary) and returns a copy for setting on the field.
   *
   * @param attributeDefinition attribute definition instance to retrieve control from
   * @return Control instance or null if not found
   */
  protected static Control convertControlToLookupControl(AttributeDefinition attributeDefinition) {
    if (attributeDefinition.getControlField() == null) {
      return null;
    }

    Control newControl = null;

    // convert checkbox to radio with yes/no/both options
    if (CheckboxControl.class.isAssignableFrom(attributeDefinition.getControlField().getClass())) {
      newControl =
          (RadioGroupControl)
              ComponentFactory.getNewComponentInstance(
                  ComponentFactory.CHECKBOX_CONVERTED_RADIO_CONTROL);
    }
    // text areas get converted to simple text inputs
    else if (TextAreaControl.class.isAssignableFrom(
        attributeDefinition.getControlField().getClass())) {
      newControl = ComponentFactory.getTextControl();
    } else {
      newControl = ComponentUtils.copy(attributeDefinition.getControlField(), "");
    }

    return newControl;
  }
예제 #25
0
  @SuppressWarnings("unchecked")
  protected void addAttributeSectionsToInquiryView(
      InquiryView view, DataObjectEntry dataObjectEntry) {
    // Set up data structures to manage the creation of sections
    Map<String, Group> inquirySectionsById = new HashMap<String, Group>();
    Group currentGroup = createInquirySection("default", dataObjectEntry.getObjectLabel());
    inquirySectionsById.put(currentGroup.getId(), currentGroup);
    ((List<Group>) view.getItems()).add(currentGroup);

    // Loop over the attributes on the data object, adding them into the inquiry
    // If we have an @Section notation, switch to the section, creating if the ID is unknown
    List<Component> items =
        (List<Component>) currentGroup.getItems(); // needed to deal with generics issue
    for (AttributeDefinition attr : dataObjectEntry.getAttributes()) {
      boolean dontDisplay =
          hasHintOfType(attr.getDataObjectAttribute(), UifDisplayHintType.NO_INQUIRY);
      dontDisplay |= (attr.getControlField() instanceof HiddenControl);
      // Check for a section hint
      // Create or retrieve existing section as determined by the ID on the annotation
      UifDisplayHint sectionHint =
          getHintOfType(attr.getDataObjectAttribute(), UifDisplayHintType.SECTION);
      if (sectionHint != null) {
        if (StringUtils.isNotBlank(sectionHint.id())) {
          currentGroup = inquirySectionsById.get(sectionHint.id());
          if (currentGroup == null) {
            String sectionLabel = sectionHint.label();
            if (StringUtils.isBlank(sectionLabel)) {
              sectionLabel = deriveHumanFriendlyNameFromPropertyName(sectionHint.id());
            }

            currentGroup = createInquirySection(sectionHint.id(), sectionHint.label());
            inquirySectionsById.put(currentGroup.getId(), currentGroup);
            ((List<Group>) view.getItems()).add(currentGroup);
          }
        } else {
          LOG.warn("SECTION UifDisplayHint given without an ID - assuming 'default'");
          currentGroup = inquirySectionsById.get("default");
        }
        items = (List<Component>) currentGroup.getItems();
      }

      // This is checked after the section test, since the @Section annotation
      // would be on the FK field
      if (dontDisplay) {
        continue;
      }

      DataField dataField = ComponentFactory.getDataField();
      dataField.setPropertyName(attr.getName());
      dataField.setLabel(attr.getLabel());
      items.add(dataField);
    }
  }
  private boolean verifyProposaEditableColumnsDataType(MaintenanceDocument maintenanceDocument) {
    ProposalColumnsToAlter newEditableProposalField =
        (ProposalColumnsToAlter) maintenanceDocument.getNewMaintainableObject().getDataObject();
    KcPersistenceStructureService kraPersistenceStructureService =
        KcServiceLocator.getService(KcPersistenceStructureService.class);
    DataDictionaryService dataDictionaryService =
        (DataDictionaryService) KNSServiceLocator.getDataDictionaryService();
    Map<String, String> fieldMap =
        kraPersistenceStructureService.getDBColumnToObjectAttributeMap(ProposalOverview.class);
    DataDictionaryEntry entry =
        dataDictionaryService
            .getDataDictionary()
            .getDictionaryObjectEntry(ProposalDevelopmentDocument.class.getName());

    boolean returnFlag = true;
    String editableProposalField = "";
    Integer fieldMaxLength = -1;
    Integer inputDataLength = -1;
    String proposalFieldDataType = "";
    String inputDataType = "";
    ValidationPattern validatingPattern = null;

    if (newEditableProposalField != null
        && StringUtils.isNotEmpty(newEditableProposalField.getColumnName())) {
      editableProposalField = fieldMap.get(newEditableProposalField.getColumnName());
      if (StringUtils.isNotEmpty(editableProposalField)) {
        if (entry != null) {
          AttributeDefinition attributeDefinition =
              entry.getAttributeDefinition(editableProposalField);
          if (attributeDefinition != null && attributeDefinition.hasValidationPattern()) {
            validatingPattern = attributeDefinition.getValidationPattern();
            if (validatingPattern != null) {
              proposalFieldDataType =
                  validationClassesMap.get(validatingPattern.getClass().getName());
              inputDataType = newEditableProposalField.getDataType();
              if (!proposalFieldDataType.equalsIgnoreCase(inputDataType)) {
                // throw error
                GlobalVariables.getMessageMap()
                    .putError(
                        Constants.PROPOSAL_EDITABLECOLUMN_DATATYPE,
                        KeyConstants.PROPOSAL_EDITABLECOLUMN_DATATYPE_MISMATCH);
                returnFlag = false;
              }
            }
          }
        }

        inputDataLength = newEditableProposalField.getDataLength();
        fieldMaxLength =
            dataDictionaryService.getAttributeMaxLength(
                DevelopmentProposal.class, editableProposalField);
        if (fieldMaxLength > inputDataLength) {
          // throw error
          GlobalVariables.getMessageMap()
              .putError(
                  Constants.PROPOSAL_EDITABLECOLUMN_DATALENGTH,
                  KeyConstants.PROPOSAL_EDITABLECOLUMN_DATALENGTH_MISMATCH);
          returnFlag = false;
        }
      }
    }

    return returnFlag;
  }
예제 #27
0
 protected void customizeControlInstance(
     Control c, AttributeDefinition attrDef, DataObjectAttribute dataObjectAttribute) {
   c.setRequired(attrDef.isRequired());
   if (c instanceof TextControl) {
     if (attrDef.getMaxLength() != null) {
       ((TextControl) c).setMaxLength(attrDef.getMaxLength());
       ((TextControl) c).setSize(attrDef.getMaxLength());
       // If it's a larger field, add the expand icon by default
       if (attrDef.getMaxLength() > 80) { // JHK : yes, this was a mostly arbitrary choice
         ((TextControl) c).setTextExpand(true);
       }
     }
     if (attrDef.getMinLength() != null) {
       ((TextControl) c).setMinLength(attrDef.getMinLength());
     }
   }
   if (c instanceof TextAreaControl) {
     if (attrDef.getMaxLength() != null) {
       ((TextAreaControl) c).setMaxLength(attrDef.getMaxLength());
       ((TextAreaControl) c).setRows(attrDef.getMaxLength() / ((TextAreaControl) c).getCols());
     }
     if (attrDef.getMinLength() != null) {
       ((TextAreaControl) c).setMinLength(attrDef.getMinLength());
     }
   }
 }
 /** @see org.kuali.rice.krad.service.DataDictionaryService#getAttributeInclusiveMax */
 public String getAttributeInclusiveMax(String entryName, String attributeName) {
   AttributeDefinition attributeDefinition = getAttributeDefinition(entryName, attributeName);
   return attributeDefinition == null ? null : attributeDefinition.getInclusiveMax();
 }
예제 #29
0
 protected Control getControlInstance(
     AttributeDefinition attrDef, DataObjectAttribute dataObjectAttribute) {
   Control c = null;
   // Check for the hidden hint - if present - then use that control type
   if (dataObjectAttribute != null
       && hasHintOfType(dataObjectAttribute, UifDisplayHintType.HIDDEN)) {
     c = ComponentFactory.getHiddenControl();
   } else if (attrDef.getOptionsFinder() != null) {
     // if a values finder has been established, use a radio button group or drop-down list
     if (dataObjectAttribute != null
         && hasHintOfType(dataObjectAttribute, UifDisplayHintType.RADIO)) {
       c = ComponentFactory.getRadioGroupControl();
     } else {
       c = ComponentFactory.getSelectControl();
     }
   } else if (attrDef.getName().endsWith(".principalName") && dataObjectAttribute != null) {
     // FIXME: JHK: Yes, I know this is a *HORRIBLE* hack - but the alternative
     // would look even more "hacky" and error-prone
     c = ComponentFactory.getUserControl();
     // Need to find the relationship information
     // get the relationship ID by removing .principalName from the attribute name
     String relationshipName = StringUtils.removeEnd(attrDef.getName(), ".principalName");
     DataObjectMetadata metadata =
         dataObjectService
             .getMetadataRepository()
             .getMetadata(dataObjectAttribute.getOwningType());
     if (metadata != null) {
       DataObjectRelationship relationship = metadata.getRelationship(relationshipName);
       if (relationship != null
           && CollectionUtils.isNotEmpty(relationship.getAttributeRelationships())) {
         ((UserControl) c)
             .setPrincipalIdPropertyName(
                 relationship.getAttributeRelationships().get(0).getParentAttributeName());
         ((UserControl) c)
             .setPersonNamePropertyName(
                 relationshipName + "." + KimConstants.AttributeConstants.NAME);
         ((UserControl) c).setPersonObjectPropertyName(relationshipName);
       }
     } else {
       LOG.warn(
           "Attempt to pull relationship name: "
               + relationshipName
               + " resulted in missing metadata when looking for: "
               + dataObjectAttribute.getOwningType());
     }
   } else {
     switch (attrDef.getDataType()) {
       case STRING:
         // TODO: Determine better way to store the "200" metric below
         if (attrDef.getMaxLength() != null && attrDef.getMaxLength().intValue() > 200) {
           c = ComponentFactory.getTextAreaControl();
         } else {
           c = ComponentFactory.getTextControl();
         }
         break;
       case BOOLEAN:
         c = ComponentFactory.getCheckboxControl();
         break;
       case DATE:
       case DATETIME:
       case TRUNCATED_DATE:
         c = ComponentFactory.getDateControl();
         break;
       case CURRENCY:
       case DOUBLE:
       case FLOAT:
       case INTEGER:
       case LARGE_INTEGER:
       case LONG:
       case PRECISE_DECIMAL:
         c = ComponentFactory.getTextControl();
         break;
       case MARKUP:
         c = ComponentFactory.getTextAreaControl();
         break;
       default:
         c = ComponentFactory.getTextControl();
         break;
     }
   }
   return c;
 }