Search in sources :

Example 21 with LocalizedString

use of org.pentaho.metadata.model.concept.types.LocalizedString in project data-access by pentaho.

the class DatasourceModelTest method contructRelationalModel.

private GuiStateModel contructRelationalModel(GuiStateModel guiStateModel) {
    IDatabaseConnection connection = new DatabaseConnection();
    connection.setAccessType(DatabaseAccessType.NATIVE);
    // connection.setDriverClass("org.hsqldb.jdbcDriver");
    connection.setName("SampleData");
    connection.setPassword("password");
    // connection.setUrl("jdbc:hsqldb:file:target/test-classes/solution1/system/data/sampledata");
    connection.setUsername("pentaho_user");
    List<IDatabaseConnection> connectionList = new ArrayList<IDatabaseConnection>();
    connectionList.add(connection);
    guiStateModel.setConnections(connectionList);
    guiStateModel.setPreviewLimit("10");
    guiStateModel.validateRelational();
    LogicalColumn logColumn = new LogicalColumn();
    logColumn.setDataType(DataType.NUMERIC);
    List<AggregationType> aggTypeList = new ArrayList<AggregationType>();
    aggTypeList.add(AggregationType.AVERAGE);
    logColumn.setAggregationList(aggTypeList);
    logColumn.setName(new LocalizedString("En", "Column1"));
    BusinessData businessData = new BusinessData();
    List<List<String>> dataSample = new ArrayList<List<String>>();
    List<String> rowData = new ArrayList<String>();
    rowData.add("Data1");
    rowData.add("Data2");
    rowData.add("Data3");
    rowData.add("Data4");
    dataSample.add(rowData);
    String locale = LocaleHelper.getLocale().toString();
    SqlPhysicalModel model = new SqlPhysicalModel();
    SqlDataSource dataSource = new SqlDataSource();
    dataSource.setDatabaseName("SampleData");
    model.setDatasource(dataSource);
    SqlPhysicalTable table = new SqlPhysicalTable(model);
    model.getPhysicalTables().add(table);
    table.setTargetTableType(TargetTableType.INLINE_SQL);
    table.setTargetTable("select * from customers");
    SqlPhysicalColumn column = new SqlPhysicalColumn(table);
    column.setTargetColumn("customername");
    column.setName(new LocalizedString(locale, "Customer Name"));
    column.setDescription(new LocalizedString(locale, "Customer Name Desc"));
    column.setDataType(DataType.STRING);
    table.getPhysicalColumns().add(column);
    LogicalModel logicalModel = new LogicalModel();
    model.setId("MODEL");
    model.setName(new LocalizedString(locale, "My Model"));
    model.setDescription(new LocalizedString(locale, "A Description of the Model"));
    LogicalTable logicalTable = new LogicalTable();
    logicalTable.setPhysicalTable(table);
    logicalModel.getLogicalTables().add(logicalTable);
    LogicalColumn logicalColumn = new LogicalColumn();
    logicalColumn.setId("LC_CUSTOMERNAME");
    logicalColumn.setPhysicalColumn(column);
    logicalTable.addLogicalColumn(logicalColumn);
    Category mainCategory = new Category();
    mainCategory.setId("CATEGORY");
    mainCategory.setName(new LocalizedString(locale, "Category"));
    mainCategory.addLogicalColumn(logicalColumn);
    logicalModel.getCategories().add(mainCategory);
    Domain domain = new Domain();
    domain.addPhysicalModel(model);
    domain.addLogicalModel(logicalModel);
    List<LocaleType> localeTypeList = new ArrayList<LocaleType>();
    localeTypeList.add(new LocaleType("Code", "Locale Description"));
    domain.setLocales(localeTypeList);
    businessData.setData(dataSample);
    businessData.setDomain(domain);
    guiStateModel.setLocaleCode("en");
    guiStateModel.setLogicalModels(domain.getLogicalModels());
    guiStateModel.validateRelational();
    return guiStateModel;
}
Also used : BusinessData(org.pentaho.platform.dataaccess.datasource.beans.BusinessData) LogicalColumn(org.pentaho.metadata.model.LogicalColumn) Category(org.pentaho.metadata.model.Category) ArrayList(java.util.ArrayList) LocalizedString(org.pentaho.metadata.model.concept.types.LocalizedString) SqlPhysicalColumn(org.pentaho.metadata.model.SqlPhysicalColumn) LogicalTable(org.pentaho.metadata.model.LogicalTable) LocalizedString(org.pentaho.metadata.model.concept.types.LocalizedString) SqlPhysicalModel(org.pentaho.metadata.model.SqlPhysicalModel) AggregationType(org.pentaho.metadata.model.concept.types.AggregationType) SqlPhysicalTable(org.pentaho.metadata.model.SqlPhysicalTable) LogicalModel(org.pentaho.metadata.model.LogicalModel) SqlDataSource(org.pentaho.metadata.model.SqlDataSource) LocaleType(org.pentaho.metadata.model.concept.types.LocaleType) DatabaseConnection(org.pentaho.database.model.DatabaseConnection) IDatabaseConnection(org.pentaho.database.model.IDatabaseConnection) ArrayList(java.util.ArrayList) List(java.util.List) IDatabaseConnection(org.pentaho.database.model.IDatabaseConnection) Domain(org.pentaho.metadata.model.Domain)

Example 22 with LocalizedString

use of org.pentaho.metadata.model.concept.types.LocalizedString in project data-access by pentaho.

the class GuiStateModelTest method test.

@Test
public void test() {
    GuiStateModel guiStateModel = new GuiStateModel();
    Assert.assertEquals(0, guiStateModel.getConnections().size());
    Assert.assertEquals(false, guiStateModel.isRelationalValidated());
    IDatabaseConnection connection = new DatabaseConnection();
    connection.setAccessType(DatabaseAccessType.NATIVE);
    // connection.setDriverClass("org.hsqldb.jdbcDriver");
    connection.setName("SampleData");
    connection.setPassword("password");
    // connection.setUrl("jdbc:hsqldb:file:target/test-classes/solution1/system/data/sampledata");
    connection.setUsername("pentaho_user");
    List<IDatabaseConnection> connectionList = new ArrayList<IDatabaseConnection>();
    connectionList.add(connection);
    guiStateModel.setConnections(connectionList);
    guiStateModel.setPreviewLimit("10");
    guiStateModel.validateRelational();
    Assert.assertEquals(true, guiStateModel.isRelationalPreviewValidated());
    // Assert.assertEquals(false, relationalModel.isValidated());
    LogicalColumn logColumn = new LogicalColumn();
    logColumn.setDataType(DataType.NUMERIC);
    List<AggregationType> aggTypeList = new ArrayList<AggregationType>();
    aggTypeList.add(AggregationType.AVERAGE);
    logColumn.setAggregationList(aggTypeList);
    logColumn.setName(new LocalizedString("En", "Column1"));
    BusinessData businessData = new BusinessData();
    List<List<String>> dataSample = new ArrayList<List<String>>();
    List<String> rowData = new ArrayList<String>();
    rowData.add("Data1");
    rowData.add("Data2");
    rowData.add("Data3");
    rowData.add("Data4");
    dataSample.add(rowData);
    String locale = LocaleHelper.getLocale().toString();
    SqlPhysicalModel model = new SqlPhysicalModel();
    SqlDataSource dataSource = new SqlDataSource();
    dataSource.setDatabaseName("SampleData");
    model.setDatasource(dataSource);
    SqlPhysicalTable table = new SqlPhysicalTable(model);
    model.getPhysicalTables().add(table);
    table.setTargetTableType(TargetTableType.INLINE_SQL);
    table.setTargetTable("select * from customers");
    SqlPhysicalColumn column = new SqlPhysicalColumn(table);
    column.setTargetColumn("customername");
    column.setName(new LocalizedString(locale, "Customer Name"));
    column.setDescription(new LocalizedString(locale, "Customer Name Desc"));
    column.setDataType(DataType.STRING);
    table.getPhysicalColumns().add(column);
    LogicalModel logicalModel = new LogicalModel();
    model.setId("MODEL");
    model.setName(new LocalizedString(locale, "My Model"));
    model.setDescription(new LocalizedString(locale, "A Description of the Model"));
    LogicalTable logicalTable = new LogicalTable();
    logicalTable.setPhysicalTable(table);
    logicalModel.getLogicalTables().add(logicalTable);
    LogicalColumn logicalColumn = new LogicalColumn();
    logicalColumn.setId("LC_CUSTOMERNAME");
    logicalColumn.setPhysicalColumn(column);
    logicalTable.addLogicalColumn(logicalColumn);
    Category mainCategory = new Category();
    mainCategory.setId("CATEGORY");
    mainCategory.setName(new LocalizedString(locale, "Category"));
    mainCategory.addLogicalColumn(logicalColumn);
    logicalModel.getCategories().add(mainCategory);
    Domain domain = new Domain();
    domain.addPhysicalModel(model);
    domain.addLogicalModel(logicalModel);
    List<LocaleType> localeTypeList = new ArrayList<LocaleType>();
    localeTypeList.add(new LocaleType("Code", "Locale Description"));
    domain.setLocales(localeTypeList);
    businessData.setData(dataSample);
    businessData.setDomain(domain);
    guiStateModel.setLogicalModels(domain.getLogicalModels());
    guiStateModel.setLocaleCode("en");
    Assert.assertEquals(true, guiStateModel.isRelationalValidated());
}
Also used : BusinessData(org.pentaho.platform.dataaccess.datasource.beans.BusinessData) LogicalColumn(org.pentaho.metadata.model.LogicalColumn) Category(org.pentaho.metadata.model.Category) ArrayList(java.util.ArrayList) LocalizedString(org.pentaho.metadata.model.concept.types.LocalizedString) SqlPhysicalColumn(org.pentaho.metadata.model.SqlPhysicalColumn) LogicalTable(org.pentaho.metadata.model.LogicalTable) LocalizedString(org.pentaho.metadata.model.concept.types.LocalizedString) SqlPhysicalModel(org.pentaho.metadata.model.SqlPhysicalModel) AggregationType(org.pentaho.metadata.model.concept.types.AggregationType) SqlPhysicalTable(org.pentaho.metadata.model.SqlPhysicalTable) LogicalModel(org.pentaho.metadata.model.LogicalModel) SqlDataSource(org.pentaho.metadata.model.SqlDataSource) LocaleType(org.pentaho.metadata.model.concept.types.LocaleType) DatabaseConnection(org.pentaho.database.model.DatabaseConnection) IDatabaseConnection(org.pentaho.database.model.IDatabaseConnection) ArrayList(java.util.ArrayList) List(java.util.List) IDatabaseConnection(org.pentaho.database.model.IDatabaseConnection) Domain(org.pentaho.metadata.model.Domain) Test(org.junit.Test)

Example 23 with LocalizedString

use of org.pentaho.metadata.model.concept.types.LocalizedString in project data-access by pentaho.

the class MetadataServiceUtil method createCdaJson.

/**
 * Returns a CDA JSON representation of a query result set
 *
 * @param resultSet
 * @return
 * @throws JSONException
 */
public String createCdaJson(final IPentahoResultSet resultSet, String locale) throws JSONException {
    if (resultSet == null) {
        return null;
    }
    JSONObject json = new JSONObject();
    // Generate the metadata
    final JSONArray metadataArray = new JSONArray();
    final int columnCount = resultSet.getColumnCount();
    final int rowCount = resultSet.getRowCount();
    for (int i = 0; i < columnCount; i++) {
        JSONObject info = new JSONObject();
        // $NON-NLS-1$
        info.put("colIndex", i);
        // $NON-NLS-1$
        info.put("colName", resultSet.getMetaData().getColumnHeaders()[0][i]);
        DataType type = (DataType) resultSet.getMetaData().getAttribute(0, i, IPhysicalColumn.DATATYPE_PROPERTY);
        // $NON-NLS-1$
        info.put("colType", type.getName().toUpperCase());
        LocalizedString name = (LocalizedString) resultSet.getMetaData().getAttribute(0, i, Concept.NAME_PROPERTY);
        if (name != null && locale != null) {
            // $NON-NLS-1$
            info.put("colLabel", name.getString(locale));
        }
        metadataArray.put(info);
    }
    // $NON-NLS-1$
    json.put("metadata", metadataArray);
    // add the rows of data
    final JSONArray valuesArray = new JSONArray();
    for (int rowIdx = 0; rowIdx < rowCount; rowIdx++) {
        final JSONArray rowArray = new JSONArray();
        valuesArray.put(rowArray);
        for (int colIdx = 0; colIdx < columnCount; colIdx++) {
            rowArray.put(resultSet.getValueAt(rowIdx, colIdx));
        }
    }
    // $NON-NLS-1$
    json.put("resultset", valuesArray);
    return json.toString();
}
Also used : JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) DataType(org.pentaho.metadata.model.concept.types.DataType) LocalizedString(org.pentaho.metadata.model.concept.types.LocalizedString) Constraint(org.pentaho.metadata.query.model.Constraint)

Example 24 with LocalizedString

use of org.pentaho.metadata.model.concept.types.LocalizedString in project data-access by pentaho.

the class MetadataServiceTest method getMarshallableResultSet.

private MarshallableResultSet getMarshallableResultSet() {
    // Build the IPentahoResultSet
    Object[][] result = new Object[1][COLUMNS];
    result[0][0] = COLUMN_NAME;
    Object[] values = new Object[1];
    values[0] = RESULT;
    LocalizedString localizedString = mock(LocalizedString.class);
    when(localizedString.getString(anyString())).thenReturn(COLUMN_NAME);
    IPentahoMetaData iPentahoMetaData = mock(IPentahoMetaData.class);
    when(iPentahoMetaData.getColumnHeaders()).thenReturn(result);
    when(iPentahoMetaData.getAttribute(anyInt(), anyInt(), eq(IPhysicalColumn.DATATYPE_PROPERTY))).thenReturn(DataType.STRING);
    when(iPentahoMetaData.getAttribute(anyInt(), anyInt(), eq(Concept.NAME_PROPERTY))).thenReturn(localizedString);
    IPentahoResultSet iPentahoResultSet = mock(IPentahoResultSet.class);
    when(iPentahoResultSet.getRowCount()).thenReturn(ROWS);
    when(iPentahoResultSet.getColumnCount()).thenReturn(COLUMNS);
    when(iPentahoResultSet.getMetaData()).thenReturn(iPentahoMetaData);
    when(iPentahoResultSet.next()).thenReturn(values).thenReturn(null);
    when(metadataService.executeQuery(anyString(), any(Integer.class))).thenReturn(iPentahoResultSet);
    // Build the MarshallableResultSet
    MarshallableResultSet marshallableResultSet = mock(MarshallableResultSet.class);
    doCallRealMethod().when(marshallableResultSet).setResultSet(any(IPentahoResultSet.class));
    when(marshallableResultSet.getRows()).thenCallRealMethod();
    when(marshallableResultSet.getColumnNames()).thenCallRealMethod();
    return marshallableResultSet;
}
Also used : IPentahoResultSet(org.pentaho.commons.connection.IPentahoResultSet) MarshallableResultSet(org.pentaho.commons.connection.marshal.MarshallableResultSet) IPentahoMetaData(org.pentaho.commons.connection.IPentahoMetaData) LocalizedString(org.pentaho.metadata.model.concept.types.LocalizedString)

Example 25 with LocalizedString

use of org.pentaho.metadata.model.concept.types.LocalizedString in project data-access by pentaho.

the class MultitableGuiModel method generateLogicalRelationships.

@Deprecated
public List<LogicalRelationship> generateLogicalRelationships(List<JoinRelationshipModel> joins) {
    String locale = LocalizedString.DEFAULT_LOCALE;
    List<LogicalRelationship> logicalRelationships = new ArrayList<LogicalRelationship>();
    for (JoinRelationshipModel join : joins) {
        LogicalTable fromTable = new LogicalTable();
        fromTable.setName(new LocalizedString(locale, join.getLeftKeyFieldModel().getParentTable().getName()));
        LogicalTable toTable = new LogicalTable();
        toTable.setName(new LocalizedString(locale, join.getRightKeyFieldModel().getParentTable().getName()));
        LogicalColumn fromColumn = new LogicalColumn();
        fromColumn.setName(new LocalizedString(locale, join.getLeftKeyFieldModel().getName()));
        LogicalColumn toColumn = new LogicalColumn();
        toColumn.setName(new LocalizedString(locale, join.getRightKeyFieldModel().getName()));
        LogicalRelationship logicalRelationship = new LogicalRelationship();
        logicalRelationship.setFromTable(fromTable);
        logicalRelationship.setToTable(toTable);
        logicalRelationship.setFromColumn(fromColumn);
        logicalRelationship.setToColumn(toColumn);
        logicalRelationships.add(logicalRelationship);
    }
    return logicalRelationships;
}
Also used : LogicalColumn(org.pentaho.metadata.model.LogicalColumn) ArrayList(java.util.ArrayList) JoinRelationshipModel(org.pentaho.agilebi.modeler.models.JoinRelationshipModel) LocalizedString(org.pentaho.metadata.model.concept.types.LocalizedString) LogicalTable(org.pentaho.metadata.model.LogicalTable) LocalizedString(org.pentaho.metadata.model.concept.types.LocalizedString) LogicalRelationship(org.pentaho.metadata.model.LogicalRelationship)

Aggregations

LocalizedString (org.pentaho.metadata.model.concept.types.LocalizedString)25 LogicalColumn (org.pentaho.metadata.model.LogicalColumn)11 LogicalTable (org.pentaho.metadata.model.LogicalTable)10 LogicalModel (org.pentaho.metadata.model.LogicalModel)8 Domain (org.pentaho.metadata.model.Domain)6 ArrayList (java.util.ArrayList)5 Test (org.junit.Test)4 Category (org.pentaho.metadata.model.Category)4 SqlDataSource (org.pentaho.metadata.model.SqlDataSource)4 SqlPhysicalColumn (org.pentaho.metadata.model.SqlPhysicalColumn)4 SqlPhysicalModel (org.pentaho.metadata.model.SqlPhysicalModel)4 SqlPhysicalTable (org.pentaho.metadata.model.SqlPhysicalTable)4 TableItem (org.eclipse.swt.widgets.TableItem)3 Matchers.anyString (org.mockito.Matchers.anyString)3 List (java.util.List)2 MessageBox (org.eclipse.swt.widgets.MessageBox)2 IPentahoResultSet (org.pentaho.commons.connection.IPentahoResultSet)2 DatabaseConnection (org.pentaho.database.model.DatabaseConnection)2 IDatabaseConnection (org.pentaho.database.model.IDatabaseConnection)2 Concept (org.pentaho.metadata.model.concept.Concept)2