Search in sources :

Example 6 with SqlPhysicalModel

use of org.pentaho.metadata.model.SqlPhysicalModel in project data-access by pentaho.

the class InMemoryDSWDatasourceServiceImpl method loadBusinessData.

public BusinessData loadBusinessData(String domainId, String modelId) throws DatasourceServiceException {
    Domain domain = getMetadataDomainRepository().getDomain(domainId);
    List<List<String>> data = null;
    if (domain.getPhysicalModels().get(0) instanceof InlineEtlPhysicalModel) {
        InlineEtlPhysicalModel model = (InlineEtlPhysicalModel) domain.getPhysicalModels().get(0);
        data = DatasourceInMemoryServiceHelper.getCsvDataSample(model.getFileLocation(), model.getHeaderPresent(), model.getDelimiter(), model.getEnclosure(), 5);
    } else {
        SqlPhysicalModel model = (SqlPhysicalModel) domain.getPhysicalModels().get(0);
        String query = model.getPhysicalTables().get(0).getTargetTable();
        SerializedResultSet resultSet = DatasourceInMemoryServiceHelper.getSerializeableResultSet(model.getDatasource().getDatabaseName(), query, 5, null);
        data = resultSet.getData();
    }
    return new BusinessData(domain, data);
}
Also used : BusinessData(org.pentaho.platform.dataaccess.datasource.beans.BusinessData) InlineEtlPhysicalModel(org.pentaho.metadata.model.InlineEtlPhysicalModel) SerializedResultSet(org.pentaho.platform.dataaccess.datasource.beans.SerializedResultSet) ArrayList(java.util.ArrayList) List(java.util.List) Domain(org.pentaho.metadata.model.Domain) SqlPhysicalModel(org.pentaho.metadata.model.SqlPhysicalModel)

Example 7 with SqlPhysicalModel

use of org.pentaho.metadata.model.SqlPhysicalModel in project data-access by pentaho.

the class DataAccessServiceTestBase method getDomain.

/**
 * Provide a mock domain
 *
 * @return
 */
private Domain getDomain() {
    LogicalColumn logicalColumn1;
    LogicalColumn logicalColumn2;
    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");
    table.setId("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);
    column.setId("cutomer_customername");
    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.setId("BT_CUSTOMERS");
    logicalTable.setPhysicalTable(table);
    logicalModel.getLogicalTables().add(logicalTable);
    logicalModel.setName(new LocalizedString(locale, "My Model"));
    logicalColumn1 = new LogicalColumn();
    logicalColumn1.setId("LC_CUSTOMERNAME");
    logicalColumn1.setPhysicalColumn(column);
    logicalColumn1.setAggregationType(AggregationType.COUNT);
    logicalColumn1.setLogicalTable(logicalTable);
    logicalColumn1.setDataType(DataType.STRING);
    logicalColumn2 = new LogicalColumn();
    logicalColumn2.setId("LC_CUSTOMERNUMBER");
    logicalColumn2.setAggregationType(AggregationType.COUNT);
    logicalColumn2.setPhysicalColumn(column);
    logicalColumn2.setLogicalTable(logicalTable);
    logicalColumn2.setDataType(DataType.NUMERIC);
    logicalTable.addLogicalColumn(logicalColumn1);
    logicalTable.addLogicalColumn(logicalColumn2);
    Domain thisDomain = new Domain();
    thisDomain.addPhysicalModel(model);
    thisDomain.addLogicalModel(logicalModel);
    return thisDomain;
}
Also used : LogicalModel(org.pentaho.metadata.model.LogicalModel) LogicalColumn(org.pentaho.metadata.model.LogicalColumn) SqlDataSource(org.pentaho.metadata.model.SqlDataSource) LocalizedString(org.pentaho.metadata.model.concept.types.LocalizedString) SqlPhysicalColumn(org.pentaho.metadata.model.SqlPhysicalColumn) LogicalTable(org.pentaho.metadata.model.LogicalTable) SqlPhysicalModel(org.pentaho.metadata.model.SqlPhysicalModel) LocalizedString(org.pentaho.metadata.model.concept.types.LocalizedString) Domain(org.pentaho.metadata.model.Domain) SqlPhysicalTable(org.pentaho.metadata.model.SqlPhysicalTable)

Example 8 with SqlPhysicalModel

use of org.pentaho.metadata.model.SqlPhysicalModel in project pentaho-platform by pentaho.

the class MetadataQueryComponentIT method getBasicDomain.

public Domain getBasicDomain() {
    SqlPhysicalModel model = new SqlPhysicalModel();
    SqlDataSource dataSource = new SqlDataSource();
    dataSource.setDatabaseName("SampleData");
    dataSource.setDialectType("HYPERSONIC");
    dataSource.setType(DataSourceType.JNDI);
    model.setDatasource(dataSource);
    SqlPhysicalTable table = new SqlPhysicalTable(model);
    table.setId("PT1");
    model.getPhysicalTables().add(table);
    table.setTargetTableType(TargetTableType.INLINE_SQL);
    table.setTargetTable("select distinct customername, salesrepemployeenumber from customers");
    SqlPhysicalColumn column = new SqlPhysicalColumn(table);
    column.setId("PC1");
    column.setTargetColumn("CUSTOMERNAME");
    column.setName(new LocalizedString("en_US", "Customer Name"));
    column.setDescription(new LocalizedString("en_US", "Customer Name Desc"));
    column.setDataType(DataType.STRING);
    table.getPhysicalColumns().add(column);
    SqlPhysicalColumn column2 = new SqlPhysicalColumn(table);
    column2.setId("PC2");
    column2.setTargetColumn("SALESREPEMPLOYEENUMBER");
    column2.setName(new LocalizedString("en_US", "Sales Rep"));
    column2.setDescription(new LocalizedString("en_US", "Sales Rep Employee Number"));
    column2.setDataType(DataType.NUMERIC);
    table.getPhysicalColumns().add(column2);
    LogicalModel logicalModel = new LogicalModel();
    logicalModel.setPhysicalModel(model);
    logicalModel.setId("MODEL");
    logicalModel.setName(new LocalizedString("en_US", "My Model"));
    logicalModel.setDescription(new LocalizedString("en_US", "A Description of the Model"));
    LogicalTable logicalTable = new LogicalTable();
    logicalTable.setId("LT");
    logicalTable.setPhysicalTable(table);
    logicalModel.getLogicalTables().add(logicalTable);
    LogicalColumn logicalColumn = new LogicalColumn();
    logicalColumn.setId("LC_CUSTOMERNAME");
    logicalColumn.setPhysicalColumn(column);
    logicalColumn.setLogicalTable(logicalTable);
    logicalTable.addLogicalColumn(logicalColumn);
    LogicalColumn logicalColumn2 = new LogicalColumn();
    logicalColumn2.setId("LC_SALESREP");
    logicalColumn2.setPhysicalColumn(column2);
    logicalColumn2.setLogicalTable(logicalTable);
    logicalTable.addLogicalColumn(logicalColumn2);
    Category mainCategory = new Category();
    mainCategory.setId("CATEGORY");
    mainCategory.setName(new LocalizedString("en_US", "Category"));
    mainCategory.addLogicalColumn(logicalColumn);
    mainCategory.addLogicalColumn(logicalColumn2);
    logicalModel.getCategories().add(mainCategory);
    Domain domain = new Domain();
    domain.setId("DOMAIN");
    domain.addPhysicalModel(model);
    domain.addLogicalModel(logicalModel);
    return domain;
}
Also used : LogicalModel(org.pentaho.metadata.model.LogicalModel) LogicalColumn(org.pentaho.metadata.model.LogicalColumn) Category(org.pentaho.metadata.model.Category) SqlDataSource(org.pentaho.metadata.model.SqlDataSource) SqlPhysicalColumn(org.pentaho.metadata.model.SqlPhysicalColumn) LogicalTable(org.pentaho.metadata.model.LogicalTable) SqlPhysicalModel(org.pentaho.metadata.model.SqlPhysicalModel) LocalizedString(org.pentaho.metadata.model.concept.types.LocalizedString) Domain(org.pentaho.metadata.model.Domain) SqlPhysicalTable(org.pentaho.metadata.model.SqlPhysicalTable)

Example 9 with SqlPhysicalModel

use of org.pentaho.metadata.model.SqlPhysicalModel 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 10 with SqlPhysicalModel

use of org.pentaho.metadata.model.SqlPhysicalModel 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)

Aggregations

SqlPhysicalModel (org.pentaho.metadata.model.SqlPhysicalModel)12 Domain (org.pentaho.metadata.model.Domain)9 LogicalModel (org.pentaho.metadata.model.LogicalModel)7 SqlPhysicalTable (org.pentaho.metadata.model.SqlPhysicalTable)7 SqlDataSource (org.pentaho.metadata.model.SqlDataSource)6 LocalizedString (org.pentaho.metadata.model.concept.types.LocalizedString)6 LogicalTable (org.pentaho.metadata.model.LogicalTable)5 ArrayList (java.util.ArrayList)4 List (java.util.List)4 LogicalColumn (org.pentaho.metadata.model.LogicalColumn)4 SqlPhysicalColumn (org.pentaho.metadata.model.SqlPhysicalColumn)4 BusinessData (org.pentaho.platform.dataaccess.datasource.beans.BusinessData)4 Category (org.pentaho.metadata.model.Category)3 LocaleType (org.pentaho.metadata.model.concept.types.LocaleType)3 SQLException (java.sql.SQLException)2 ModelerWorkspace (org.pentaho.agilebi.modeler.ModelerWorkspace)2 IPentahoResultSet (org.pentaho.commons.connection.IPentahoResultSet)2 DatabaseConnection (org.pentaho.database.model.DatabaseConnection)2 IDatabaseConnection (org.pentaho.database.model.IDatabaseConnection)2 DatabaseMeta (org.pentaho.di.core.database.DatabaseMeta)2