/**
   * Updates a oda result set definition.
   *
   * @param param
   */
  private void updateOrVerifyResultSetColumnAndHint(
      DataSetDesign setDesign, OdaDataSetHandle setHandle, boolean update)
      throws SemanticException {
    ResultSets sets = setDesign.getResultSets();
    ResultSetDefinition setDefn = (ResultSetDefinition) sets.getResultSetDefinitions().get(0);
    ColumnDefinition columnDef = setDefn.getResultSetColumns().getResultColumnDefinitions().get(0);

    DataElementAttributes dataAttrs = columnDef.getAttributes();
    DataElementUIHints dataUIHints = dataAttrs.getUiHints();
    OutputElementAttributes usageHints = columnDef.getUsageHints();
    if (columnDef.getMultiDimensionAttributes() == null) {
      columnDef.setMultiDimensionAttributes(DesignFactory.eINSTANCE.createAxisAttributes());
    }

    if (update) {
      dataAttrs.setNativeDataTypeCode(DataType.DECIMAL_TYPE);
      dataUIHints.setDisplayName("new display name for column 1"); // $NON-NLS-1$
      usageHints.setHelpText("new help text for column 1"); // $NON-NLS-1$
      ValueFormatHints format = DesignFactory.eINSTANCE.createValueFormatHints();
      format.setDisplayFormat("new format"); // $NON-NLS-1$
      usageHints.setFormattingHints(format);
      columnDef.setUsageHints(usageHints);
      columnDef.getMultiDimensionAttributes().setAxisType(AxisType.MEASURE_LITERAL);
      columnDef.getMultiDimensionAttributes().setOnColumnLayout(true);
    } else {
      assertEquals(DataType.DECIMAL_TYPE, dataAttrs.getNativeDataTypeCode());
      assertEquals("new display name for column 1", dataUIHints.getDisplayName());
      assertEquals("new help text for column 1", usageHints.getHelpText());
      assertEquals("new format", usageHints.getFormattingHints().getDisplayFormat());
      assertEquals(AxisType.MEASURE_LITERAL, columnDef.getMultiDimensionAttributes().getAxisType());
      assertTrue(columnDef.getMultiDimensionAttributes().isSetOnColumnLayout());
    }
  }
Esempio n. 2
0
  /**
   * Creates a list containing ROM ResultSetColumn according to given ODA ResultSets.
   *
   * @param setDesign the data set design
   * @param setHandle the data set handle
   * @param cachedSetDefn the ODA result set in designer values
   * @return a list containing ROM ResultSetColumn.
   * @throws SemanticException
   */
  List<ResultSetColumnInfo> newROMResultSets(ResultSetDefinition cachedSetDefn)
      throws SemanticException {
    ResultSetColumns cachedSetColumns =
        cachedSetDefn == null ? null : cachedSetDefn.getResultSetColumns();

    ResultSetDefinition resultDefn = setDesign.getPrimaryResultSet();
    if (resultDefn == null) {
      ResultSets resultSets = setDesign.getResultSets();
      if (resultSets != null && !resultSets.getResultSetDefinitions().isEmpty())
        resultDefn = (ResultSetDefinition) resultSets.getResultSetDefinitions().get(0);
    }

    if (resultDefn == null) return null;

    ResultSetColumns setColumns = resultDefn.getResultSetColumns();
    if (setColumns == null) return null;

    EList<ColumnDefinition> odaSetColumns = setColumns.getResultColumnDefinitions();
    if (odaSetColumns.isEmpty()) return null;

    List<ColumnDefinition> oldColumnDefns = new ArrayList<ColumnDefinition>();
    if (cachedSetColumns != null) {
      EList<ColumnDefinition> tmpDefns = cachedSetColumns.getResultColumnDefinitions();
      for (int i = 0; i < tmpDefns.size(); i++) oldColumnDefns.add(tmpDefns.get(i));
    }

    List<OdaResultSetColumnHandle> oldColumns = new ArrayList<OdaResultSetColumnHandle>();
    for (int i = 0; i < setDefinedResults.size(); i++)
      oldColumns.add((OdaResultSetColumnHandle) setDefinedResults.get(i));

    List<ColumnHintHandle> oldColumnHints = new ArrayList<ColumnHintHandle>();
    for (int i = 0; i < setDefinedColumnHints.size(); i++)
      oldColumnHints.add((ColumnHintHandle) setDefinedColumnHints.get(i));

    List<ColumnDefinition> newColumnDefns = new ArrayList<ColumnDefinition>();
    for (int i = 0; i < odaSetColumns.size(); i++) newColumnDefns.add(odaSetColumns.get(i));

    ROMResultSetsHelper resultSetHelper =
        new ROMResultSetsHelper(
            oldColumnDefns,
            oldColumns,
            oldColumnHints,
            newColumnDefns,
            setDesign.getOdaExtensionDataSourceId(),
            setDesign.getOdaExtensionDataSetId());

    List<ResultSetColumnInfo> retList = new ArrayList<ResultSetColumnInfo>();
    ResultSetColumnInfo setInfo = null;

    for (int i = 0; i < newColumnDefns.size(); i++) {
      ROMResultColumnHelper columnHelper = resultSetHelper.getColumnHelper(i);
      OdaResultSetColumn newColumn = resultSetHelper.getNewColumn(i);
      ColumnDefinition newColumnDefn = columnHelper.getNewColumnDefn();
      ColumnHintHandle oldColumnHintHandle = columnHelper.getOldColumnHint();
      ColumnHint oldColumnHint =
          oldColumnHintHandle == null ? null : (ColumnHint) oldColumnHintHandle.getStructure();

      ColumnHint newColumnHint =
          newROMColumnHintFromColumnDefinition(newColumnDefn, null, oldColumnHint, newColumn);
      setInfo = new ResultSetColumnInfo(newColumn, newColumnHint);
      retList.add(setInfo);
    }

    updateHintsForComputedColumn();

    return retList;
  }
Esempio n. 3
0
  /**
   * Updates the data set handle with specified values.
   *
   * @param setDesign the data set design
   * @param setHandle the data set handle
   * @param isSourceChanged
   * @param requestParameters
   * @param requestResultSets
   * @throws SemanticException
   */
  private void updateDataSetHandle(
      DataSetDesign setDesign,
      OdaDataSetHandle setHandle,
      boolean isSourceChanged,
      DataSetParameters requestParameters,
      ResultSets requestResultSets)
      throws SemanticException {
    if (setDesign == null || setHandle == null) return;

    DesignUtil.validateObject(setDesign);

    CommandStack stack = setHandle.getModuleHandle().getCommandStack();

    stack.startTrans(null);
    try {
      // extension id is set without undo/redo support.

      setHandle
          .getElement()
          .setProperty(OdaDataSourceHandle.EXTENSION_ID_PROP, setDesign.getOdaExtensionDataSetId());

      setHandle.setName(setDesign.getName());
      setHandle.setDisplayName(setDesign.getDisplayName());
      setHandle.setDisplayNameKey(setDesign.getDisplayNameKey());

      // set public properties.

      Properties props = setDesign.getPublicProperties();
      if (props != null) {
        EList propList = props.getProperties();
        for (int i = 0; i < propList.size(); i++) {
          Property prop = (Property) propList.get(i);
          setHandle.setProperty(prop.getName(), prop.getValue());
        }
      }

      // set private properties.

      props = setDesign.getPrivateProperties();
      if (props != null) {
        EList propList = props.getProperties();
        for (int i = 0; i < propList.size(); i++) {
          Property prop = (Property) propList.get(i);
          setHandle.setPrivateDriverProperty(prop.getName(), prop.getValue());
        }
      }

      ResultSetDefinition cachedResultDefn = null;

      if (requestResultSets != null && !requestResultSets.getResultSetDefinitions().isEmpty())
        cachedResultDefn = (ResultSetDefinition) requestResultSets.getResultSetDefinitions().get(0);

      ResultSetsAdapter tmpAdapter = new ResultSetsAdapter(setHandle, setDesign);
      updateROMResultSets(setHandle, tmpAdapter, cachedResultDefn);

      setHandle.setResultSetName(setDesign.getPrimaryResultSetName());

      setHandle.setQueryText(setDesign.getQueryText());

      // designer values must be saved after convert data set parameters
      // and result set columns.

      // Set Parameter

      // Get user-defined parameters

      DataSetParameterAdapter dataParamAdapter = new DataSetParameterAdapter(setHandle, setDesign);
      dataParamAdapter.updateUserDefinedParameter(
          SchemaConversionUtil.convertToDesignParameters(requestParameters));

      // Update parameters of dataset handle.

      updateROMDataSetParams(dataParamAdapter, requestParameters);

      DataSourceDesign sourceDesign = setDesign.getDataSourceDesign();
      if (sourceDesign != null) {
        OdaDataSourceHandle sourceHandle = (OdaDataSourceHandle) setHandle.getDataSource();

        DataSourceAdapter dataSourceAdapter = new DataSourceAdapter();

        // only the local data source can be used.

        if (isSourceChanged
            && sourceHandle != null
            && !sourceHandle.getModuleHandle().isReadOnly()) {
          setHandle.setDataSource(sourceDesign.getName());
          dataSourceAdapter.updateDataSourceHandle(sourceDesign, sourceHandle);
        }

        // if the source is not changed, and it is not in the included
        // library, then we can update it.

        if (!isSourceChanged
            && sourceHandle != null
            && !sourceHandle.getModuleHandle().isReadOnly()
            && !(dataSourceAdapter.isEqualDataSourceDesign(
                dataSourceAdapter.createDataSourceDesign(sourceHandle), sourceDesign))) {
          dataSourceAdapter.updateDataSourceHandle(sourceDesign, sourceHandle);
        }
      } else setHandle.setDataSource(defaultDataSourceName);

      updateDesignerValue(
          setDesign,
          setHandle,
          requestParameters,
          dataParamAdapter.getUserDefinedParams(),
          requestResultSets);

      updateROMMessageFile(sourceDesign, setHandle.getModuleHandle());
    } catch (SemanticException e) {
      stack.rollback();
      throw e;
    }

    stack.commit();
  }
  /**
   * Converts ODA result set columns to ROM result set columns.
   *
   * <ul>
   *   <li>no the latest design session response, update ROM values.
   *   <li>if the latest design session response changed, update ROM values.
   *   <li>if the latest design session response didn't change and ROM values changed, don't update
   *       ROM values.
   * </ul>
   *
   * @throws Exception
   */
  public void testToROMResultSetsWithColumnHints() throws Exception {
    // create oda set handle.

    openDesign("OdaDataSetConvertResultSetsTest.xml"); // $NON-NLS-1$
    OdaDataSetHandle setHandle =
        (OdaDataSetHandle) designHandle.findDataSet("myDataSet1"); // $NON-NLS-1$

    // get the latest data set design.

    DataSetDesign setDesign = new ModelOdaAdapter().createDataSetDesign(setHandle);

    // oda data set design changed, update ROM values. still keep report
    // parameter link.

    ResultSets sets = setDesign.getResultSets();
    ResultSetDefinition setDefn = (ResultSetDefinition) sets.getResultSetDefinitions().get(0);

    updateOrVerifyResultSetDefinition1(setDefn, true);

    new ModelOdaAdapter().updateDataSetHandle(setDesign, setHandle, false);

    save();
    saveAndOpenDesign();
    setHandle = (OdaDataSetHandle) designHandle.findDataSet("myDataSet1"); // $NON-NLS-1$
    setDesign = new ModelOdaAdapter().createDataSetDesign(setHandle);
    sets = setDesign.getResultSets();
    setDefn = (ResultSetDefinition) sets.getResultSetDefinitions().get(0);
    //		updateOrVerifyResultSetDefinition1( setDefn , false);
    // assertTrue( compareTextFile( "OdaDataSetConvertResultSetsTest_golden.xml" ) ); //$NON-NLS-1$

    openDesign("OdaDataSetConvertResultSetsTest_1.xml"); // $NON-NLS-1$
    setHandle = (OdaDataSetHandle) designHandle.findDataSet("myDataSet1"); // $NON-NLS-1$

    // get the latest data set design.

    setDesign = new ModelOdaAdapter().createDataSetDesign(setHandle);

    // oda data set design changed, update ROM values.

    sets = setDesign.getResultSets();
    setDefn = (ResultSetDefinition) sets.getResultSetDefinitions().get(0);

    // oda data set design changed, update ROM values. still keep report
    // parameter link.

    updateOrVerifyResultSetDefinition1(setDefn, true);
    new ModelOdaAdapter().updateDataSetHandle(setDesign, setHandle, false);

    save();
    saveAndOpenDesign();
    setHandle = (OdaDataSetHandle) designHandle.findDataSet("myDataSet1"); // $NON-NLS-1$
    setDesign = new ModelOdaAdapter().createDataSetDesign(setHandle);
    sets = setDesign.getResultSets();
    setDefn = (ResultSetDefinition) sets.getResultSetDefinitions().get(0);
    //		updateOrVerifyResultSetDefinition1( setDefn , false);
    // assertTrue( compareTextFile( "OdaDataSetConvertResultSetsTest_1_golden.xml" ) );
    // //$NON-NLS-1$

    // the oda data set design is not changed. ROM values are changed.
    // Should keep rom values.

    openDesign("OdaDataSetConvertResultSetsTest_1.xml"); // $NON-NLS-1$
    setHandle = (OdaDataSetHandle) designHandle.findDataSet("myDataSet1"); // $NON-NLS-1$

    // get the latest data set design.

    setDesign = new ModelOdaAdapter().createDataSetDesign(setHandle);

    updateOrVerifyResultSetColumnAndHint(setDesign, setHandle, true);

    new ModelOdaAdapter().updateDataSetHandle(setDesign, setHandle, false);

    save();
    saveAndOpenDesign();
    setHandle = (OdaDataSetHandle) designHandle.findDataSet("myDataSet1"); // $NON-NLS-1$
    setDesign = new ModelOdaAdapter().createDataSetDesign(setHandle);

    //		updateOrVerifyResultSetColumnAndHint( setDesign, setHandle, false );
    // assertTrue( compareTextFile( "OdaDataSetConvertResultSetsTest_2_golden.xml" ) );
    // //$NON-NLS-1$
  }