Example #1
0
  /**
   * Returns the rom data type in string.
   *
   * @param dataSourceId the id of the data source
   * @param dataSetId the ide of the data set
   * @param column the rom data set parameter
   * @param setHandleParams params defined in data set handle
   * @return the rom data type in string
   */
  private String getROMDataType(String dataSourceId, String dataSetId, OdaResultSetColumn column) {
    String name = column.getNativeName();
    Integer position = column.getPosition();
    Integer nativeDataType = column.getNativeDataType();

    OdaResultSetColumnHandle tmpParam =
        findOdaResultSetColumn(setDefinedResults.iterator(), name, position, nativeDataType);

    if (tmpParam == null)
      return AdapterUtil.convertNativeTypeToROMDataType(
          dataSourceId, dataSetId, column.getNativeDataType().intValue(), null);

    Integer tmpPosition = tmpParam.getPosition();
    if (tmpPosition == null)
      return AdapterUtil.convertNativeTypeToROMDataType(
          dataSourceId, dataSetId, column.getNativeDataType().intValue(), null);

    if (!tmpPosition.equals(column.getPosition()))
      return AdapterUtil.convertNativeTypeToROMDataType(
          dataSourceId, dataSetId, column.getNativeDataType().intValue(), null);

    Integer tmpNativeCodeType = tmpParam.getNativeDataType();
    if (tmpNativeCodeType == null || tmpNativeCodeType.equals(column.getNativeDataType()))
      return tmpParam.getDataType();

    String oldDataType = tmpParam.getDataType();
    return AdapterUtil.convertNativeTypeToROMDataType(
        dataSourceId, dataSetId, column.getNativeDataType().intValue(), oldDataType);
  }
  protected DynamicValuesQuery updateDynamicValueQuery(
      DataSetHandle setHandle,
      Object valueColumn,
      Object labelColumn,
      DataSetDesign dataSetDesign,
      boolean isEnabled) {
    DynamicValuesQuery valueQuery = null;

    if (setHandle instanceof OdaDataSetHandle && valueColumn != null) {
      valueQuery = designFactory.createDynamicValuesQuery();

      if (dataSetDesign != null) {
        DataSetDesign targetDataSetDesign = (DataSetDesign) EcoreUtil.copy(dataSetDesign);
        if (!setHandle.getName().equals(dataSetDesign.getName()))
          targetDataSetDesign =
              new ModelOdaAdapter().createDataSetDesign((OdaDataSetHandle) setHandle);
        valueQuery.setDataSetDesign(targetDataSetDesign);
      } else {
        DataSetDesign targetDataSetDesign =
            new ModelOdaAdapter().createDataSetDesign((OdaDataSetHandle) setHandle);
        valueQuery.setDataSetDesign(targetDataSetDesign);
      }
      valueQuery.setDisplayNameColumn(AdapterUtil.extractColumnName(labelColumn));
      valueQuery.setValueColumn(AdapterUtil.extractColumnName(valueColumn));
      valueQuery.setEnabled(isEnabled);
    }

    return valueQuery;
  }
 public static Resource getResource(EObject object) {
   InsertionAdapter adapter = AdapterUtil.adapt(object, InsertionAdapter.class);
   if (adapter != null) {
     return adapter.getResource();
   }
   if (object != null) return object.eResource();
   return null;
 }
 public Resource getResource() {
   if (resource == null) {
     Resource res = object.eResource();
     if (res != null) return res;
     InsertionAdapter insertionAdapter = AdapterUtil.adapt(object, InsertionAdapter.class);
     if (insertionAdapter != null) return insertionAdapter.getResource();
   }
   return resource;
 }
 /**
  * Sets the default value for ROM data set parameter.
  *
  * @param setParam the ROM data set parameter
  * @param literalValue the value
  */
 private void setROMDefaultValue(AbstractScalarParameterHandle setParam, Object value)
     throws SemanticException {
   List<Expression> newValues = null;
   if (!AdapterUtil.isNullExpression(value)) {
     assert value instanceof Expression;
     newValues = new ArrayList<Expression>();
     newValues.add(
         new Expression(
             ((Expression) value).getExpression(), ((Expression) value).getUserDefinedType()));
   }
   setParam.setDefaultValueList(newValues);
 }
Example #6
0
  /**
   * Creates a ResultSetDefinition with the given ROM ResultSet columns.
   *
   * @return the created ResultSetDefinition
   */
  private ResultSetDefinition newOdaResultSetDefinition() {
    Iterator romSets = setDefinedResults.iterator();
    String name = setHandle.getResultSetName();

    if (!romSets.hasNext()) return null;

    ResultSetDefinition odaSetDefn = null;
    ResultSetColumns odaSetColumns = null;

    if (!StringUtil.isBlank(name)) {
      odaSetDefn = designFactory.createResultSetDefinition();
      odaSetDefn.setName(name);
    }

    while (romSets.hasNext()) {
      if (odaSetDefn == null) odaSetDefn = designFactory.createResultSetDefinition();

      if (odaSetColumns == null) odaSetColumns = designFactory.createResultSetColumns();

      OdaResultSetColumnHandle setColumn = (OdaResultSetColumnHandle) romSets.next();

      // get the colum hint

      ColumnHintHandle hint =
          AdapterUtil.findColumnHint(
              (OdaResultSetColumn) setColumn.getStructure(), setDefinedColumnHints.iterator());

      ColumnDefinition columnDefn = designFactory.createColumnDefinition();

      DataElementAttributes dataAttrs = designFactory.createDataElementAttributes();

      String newName = setColumn.getNativeName();
      dataAttrs.setName(newName);

      Integer position = setColumn.getPosition();
      if (position != null) dataAttrs.setPosition(setColumn.getPosition().intValue());

      Integer nativeDataType = setColumn.getNativeDataType();
      if (nativeDataType != null) dataAttrs.setNativeDataTypeCode(nativeDataType.intValue());

      columnDefn.setAttributes(dataAttrs);
      odaSetColumns.getResultColumnDefinitions().add(columnDefn);

      if (hint == null) continue;

      updateOdaColumnHint(columnDefn, hint);
    }

    if (odaSetDefn != null) odaSetDefn.setResultSetColumns(odaSetColumns);

    return odaSetDefn;
  }
Example #7
0
  /**
   * Updates a structure list with the corresponding property handle.
   *
   * @param propHandle the property handle
   * @param structList the structure list
   * @throws SemanticException if any structure has invalid value.
   */
  private void updateROMResultSets(
      OdaDataSetHandle setHandle,
      ResultSetsAdapter tmpAdapter,
      ResultSetDefinition cachedResultDefn)
      throws SemanticException {
    List structList = tmpAdapter.newROMResultSets(cachedResultDefn);

    List columns = new ArrayList();
    List hints = new ArrayList();

    ResultSetColumnInfo.updateResultSetColumnList(structList, columns, hints);

    PropertyHandle propHandle = setHandle.getPropertyHandle(OdaDataSetHandle.RESULT_SET_PROP);
    propHandle.clearValue();

    if (!columns.isEmpty()) {
      for (int i = 0; i < columns.size(); i++) propHandle.addItem(columns.get(i));
    }

    propHandle = setHandle.getPropertyHandle(OdaDataSetHandle.COLUMN_HINTS_PROP);
    propHandle.clearValue();
    if (!hints.isEmpty()) {
      for (int i = 0; i < hints.size(); i++) {
        ColumnHint hint = (ColumnHint) hints.get(i);
        ColumnHintHandle oldHint =
            AdapterUtil.findColumnHint(
                (String) hint.getProperty(null, ColumnHint.COLUMN_NAME_MEMBER),
                setHandle.columnHintsIterator());

        if (oldHint == null) propHandle.addItem(hints.get(i));
        else {
          oldHint.setDisplayName((String) hint.getProperty(null, ColumnHint.DISPLAY_NAME_MEMBER));
          oldHint.setDisplayNameKey(
              (String) hint.getProperty(null, ColumnHint.DISPLAY_NAME_ID_MEMBER));
          oldHint.setHelpText((String) hint.getProperty(null, ColumnHint.HELP_TEXT_MEMBER));
          oldHint.setHelpTextKey((String) hint.getProperty(null, ColumnHint.HELP_TEXT_ID_MEMBER));
          oldHint.setFormat((String) hint.getProperty(null, ColumnHint.FORMAT_MEMBER));
        }
      }
    }

    // add column hints for the computed column

    List hints4ComputedColumn = tmpAdapter.getHintsForComputedColumn();
    for (int i = 0; i < hints4ComputedColumn.size(); i++) {
      propHandle.addItem((ColumnHint) hints4ComputedColumn.get(i));
    }

    // add filter condition for the result set
    tmpAdapter.updateROMFilterCondition();
  }
  public Type adapt(Java7Parser.TypeArgumentContext context, AdapterParameters adapterParameters) {

    /*
       typeArgument
           :   type
           |   QUES ( (EXTENDS | SUPER ) type )?
           ;
    */

    if (context.QUES() != null) {
      WildcardType wildcardType = new WildcardType();
      AdapterUtil.setComments(wildcardType, context, adapterParameters);
      AdapterUtil.setPosition(wildcardType, context);

      if (context.type() != null) {
        Type type = Adapters.getTypeContextAdapter().adapt(context.type(), adapterParameters);

        if (!(type instanceof ReferenceType)) {
          throw new ParseException(
              "type cannot be primitive when using super or extends in a type argument");
        }

        ReferenceType referenceType = (ReferenceType) type;

        if (context.SUPER() != null) {
          wildcardType.setSuper(referenceType);
        } else if (context.EXTENDS() != null) {
          wildcardType.setExtends(referenceType);
        }
      }

      return wildcardType;
    } else if (context.type() != null) {
      return Adapters.getTypeContextAdapter().adapt(context.type(), adapterParameters);
    }

    return null;
  }
  /**
   * Updates values in ScalarValueChoices to the given report parameter.
   *
   * @param dataAttrs the latest scalar values
   * @param cachedDataAttrs the cached scalar value
   * @param reportParam the report parameter
   * @throws SemanticException
   */
  private void updateROMSelectionList(
      ScalarValueChoices staticChoices,
      ScalarValueChoices cachedStaticChoices,
      AbstractScalarParameterHandle paramHandle)
      throws SemanticException {
    if (staticChoices == null) return;

    String newChoiceStr = DesignObjectSerializer.toExternalForm(staticChoices);
    String latestChoiceStr = DesignObjectSerializer.toExternalForm(cachedStaticChoices);

    if (latestChoiceStr != null && latestChoiceStr.equals(newChoiceStr)) return;

    AdapterUtil.updateROMSelectionList(staticChoices, cachedStaticChoices, paramHandle);
  }
  /**
   * Updates values in InputElementAttributes to the given report parameter.
   *
   * @param elementAttrs the latest input element attributes
   * @param cachedElementAttrs the cached input element attributes
   * @param reportParam the report parameter
   * @param setHandle the ROM data set that has the corresponding data set parameter
   * @throws SemanticException
   */
  protected void updateInputElementAttrsToReportParam(
      InputElementAttributes elementAttrs,
      InputElementAttributes cachedElementAttrs,
      AbstractScalarParameterHandle reportParam,
      OdaDataSetHandle setHandle)
      throws SemanticException {
    if (elementAttrs == null) return;

    // update default values.

    updateDefaultValueToReportParam(elementAttrs, cachedElementAttrs, reportParam);

    // update isOptional value
    Boolean isOptional = Boolean.valueOf(elementAttrs.isOptional());
    Boolean cachedIsOptional =
        cachedElementAttrs == null ? null : Boolean.valueOf(cachedElementAttrs.isOptional());
    if (!CompareUtil.isEquals(cachedIsOptional, isOptional))
      setReportParamIsRequired(reportParam, ALLOW_BLANK_PROP_NAME, isOptional.booleanValue());

    // update selection choices
    updateROMSelectionList(
        elementAttrs.getStaticValueChoices(),
        cachedElementAttrs == null ? null : cachedElementAttrs.getStaticValueChoices(),
        reportParam);

    // update dynamic list
    DynamicValuesQuery valueQuery = elementAttrs.getDynamicValueChoices();
    AdapterUtil.updateROMDyanmicList(
        valueQuery,
        cachedElementAttrs == null ? null : cachedElementAttrs.getDynamicValueChoices(),
        reportParam,
        setHandle);

    // for dynamic parameter, the flag is in DynamicValuesQuery is true
    // for static parameter, the DynamicValuesQuery is null or the flag is
    // false

    DynamicValuesQuery cachedValueQuery =
        cachedElementAttrs == null ? null : cachedElementAttrs.getDynamicValueChoices();

    boolean isEnabled = (valueQuery == null) ? false : valueQuery.isEnabled();

    if (reportParam.getContainer() != null
        && reportParam.getContainer() instanceof CascadingParameterGroupHandle) isEnabled = true;

    if (cachedValueQuery == null || cachedValueQuery.isEnabled() != isEnabled) {
      if (isEnabled) reportParam.setValueType(DesignChoiceConstants.PARAM_VALUE_TYPE_DYNAMIC);
      else reportParam.setValueType(DesignChoiceConstants.PARAM_VALUE_TYPE_STATIC);
    }
  }
  /**
   * @param elementAttrs
   * @param cachedElementAttrs
   * @param reportParam
   * @throws SemanticException
   */
  protected void updateDefaultValueToReportParam(
      InputElementAttributes elementAttrs,
      InputElementAttributes cachedElementAttrs,
      AbstractScalarParameterHandle reportParam)
      throws SemanticException {
    // update default values.

    StaticValues defaultValues = elementAttrs.getDefaultValues();
    StaticValues cachedDefaultValues =
        cachedElementAttrs == null ? null : cachedElementAttrs.getDefaultValues();

    if (new EcoreUtil.EqualityHelper().equals(cachedDefaultValues, defaultValues) == false) {
      AdapterUtil.updateROMDefaultValues(defaultValues, reportParam);
    }
  }
Example #12
0
  /** Updates column hints for computed columns. Saved in the field. */
  private void updateHintsForComputedColumn() {
    Iterator columns = setHandle.computedColumnsIterator();
    List<String> columnNames = new ArrayList<String>();
    while (columns.hasNext()) {
      ComputedColumnHandle tmpColumn = (ComputedColumnHandle) columns.next();
      columnNames.add(tmpColumn.getName());
    }

    for (int i = 0; i < columnNames.size(); i++) {
      String columnName = columnNames.get(i);
      ColumnHintHandle hintHandle =
          AdapterUtil.findColumnHint(columnName, setDefinedColumnHints.iterator());
      if (hintHandle == null) continue;

      if (columnHintsForComputedColumns == null)
        columnHintsForComputedColumns = new ArrayList<IStructure>();

      columnHintsForComputedColumns.add(hintHandle.getStructure().copy());
    }
  }