示例#1
0
  /**
   * Updates column hint values by given data element attributes.
   *
   * @param dataAttrs the latest data element attributes
   * @param cachedDataAttrs the last(cached) data element attributes
   * @param newHint the column hint
   */
  private static void updateColumnHintFromDataAttrs(
      DataElementAttributes dataAttrs,
      DataElementAttributes cachedDataAttrs,
      ColumnHint newHint,
      OdaResultSetColumn column) {
    if (dataAttrs == null) return;

    Object oldValue = cachedDataAttrs == null ? null : cachedDataAttrs.getName();
    Object newValue = dataAttrs.getName();
    // If column name in hint already matches column name in column, don't
    // update it even if
    // oda has a new column name. Column name in hint and column has to
    // match as model use column name
    // as identifier to relate column and hint
    if (!CompareUtil.isEquals(
            newHint.getProperty(null, ColumnHint.COLUMN_NAME_MEMBER), column.getColumnName())
        && !CompareUtil.isEquals(oldValue, newValue))
      newHint.setProperty(ColumnHint.COLUMN_NAME_MEMBER, newValue);

    DataElementUIHints dataUIHints = dataAttrs.getUiHints();
    if (dataUIHints == null) return;

    DataElementUIHints cachedDataUIHints =
        cachedDataAttrs == null ? null : cachedDataAttrs.getUiHints();
    oldValue = cachedDataUIHints == null ? null : cachedDataUIHints.getDisplayName();
    newValue = dataUIHints.getDisplayName();
    if (!CompareUtil.isEquals(oldValue, newValue)) {
      newHint.setProperty(ColumnHint.DISPLAY_NAME_MEMBER, newValue);
    }

    oldValue = cachedDataUIHints == null ? null : cachedDataUIHints.getDisplayNameKey();
    newValue = dataUIHints.getDisplayNameKey();
    if (!CompareUtil.isEquals(oldValue, newValue)) {
      newHint.setProperty(ColumnHint.DISPLAY_NAME_ID_MEMBER, newValue);
    }

    // description to description in data ui hints: not support now

    /*
     * oldValue = cachedDataUIHints == null ? null : cachedDataUIHints
     * .getDescription( ); newValue = dataUIHints.getDescription( ); if (
     * oldValue == null || !oldValue.equals( newValue ) ) {
     * newHint.setProperty( ColumnHint.DESCRIPTION_MEMBER, newValue ); }
     *
     * oldValue = cachedDataUIHints == null ? null : cachedDataUIHints
     * .getDescriptionKey( ); newValue = dataUIHints.getDescriptionKey( );
     * if ( oldValue == null || !oldValue.equals( newValue ) ) {
     * newHint.setProperty( ColumnHint.DESCRIPTION_ID_MEMBER, newValue ); }
     */

  }
  /**
   * Updates values in DataElementAttributes to the given report parameter.
   *
   * @param dataAttrs the latest data element attributes
   * @param cachedDataAttrs the cached data element attributes
   * @param reportParam the report parameter
   * @throws SemanticException
   */
  private void updateDataElementAttrsToReportParam(
      DataElementAttributes dataAttrs,
      DataElementAttributes cachedDataAttrs,
      AbstractScalarParameterHandle reportParam)
      throws SemanticException {

    if (dataAttrs == null) return;

    boolean allowsNull = dataAttrs.allowsNull();
    if (cachedDataAttrs == null || cachedDataAttrs.allowsNull() != allowsNull)
      setReportParamIsRequired(reportParam, ALLOW_NULL_PROP_NAME, dataAttrs.allowsNull());

    // reportParam.setAllowNull( dataAttrs.allowsNull( ) );

    DataElementUIHints dataUiHints = dataAttrs.getUiHints();
    DataElementUIHints cachedDataUiHints =
        (cachedDataAttrs == null ? null : cachedDataAttrs.getUiHints());
    if (dataUiHints != null) {
      String displayName = dataUiHints.getDisplayName();
      String cachedDisplayName =
          cachedDataUiHints == null ? null : cachedDataUiHints.getDisplayName();

      boolean isChanged = false;

      if (cachedDisplayName == null || !cachedDisplayName.equals(displayName)) {
        isChanged = true;
        reportParam.setPromptText(displayName);
        reportParam.setPromptTextID(dataUiHints.getDisplayNameKey());
      }
      if (!isChanged && cachedDataUiHints != null && cachedDisplayName != null) {
        reportParam.setPromptText(cachedDisplayName);
        reportParam.setPromptTextID(cachedDataUiHints.getDisplayNameKey());
      }

      isChanged = false;
      String description = dataUiHints.getDescription();
      String cachedDescription =
          cachedDataUiHints == null ? null : cachedDataUiHints.getDescription();
      if (cachedDescription == null || !cachedDescription.equals(description)) {
        isChanged = true;
        reportParam.setHelpText(description);
        reportParam.setHelpTextKey(dataUiHints.getDescriptionKey());
      }

      if (!isChanged && cachedDataUiHints != null && cachedDescription != null) {
        reportParam.setHelpText(cachedDescription);
        reportParam.setHelpTextKey(cachedDataUiHints.getDescriptionKey());
      }
    }
  }