Search in sources :

Example 1 with BusinessData

use of org.pentaho.platform.dataaccess.datasource.beans.BusinessData in project data-access by pentaho.

the class InlineSqlModelerSource method generateDomain.

@Override
public Domain generateDomain(boolean dualModelingMode) throws ModelerException {
    try {
        BusinessData bd = datasourceImpl.generateLogicalModel(datasourceName, connectionName, dbType, query, "10");
        Domain domain = bd.getDomain();
        return domain;
    } catch (DatasourceServiceException dce) {
        throw new ModelerException(dce);
    }
}
Also used : BusinessData(org.pentaho.platform.dataaccess.datasource.beans.BusinessData) ModelerException(org.pentaho.agilebi.modeler.ModelerException) Domain(org.pentaho.metadata.model.Domain) DatasourceServiceException(org.pentaho.platform.dataaccess.datasource.wizard.service.DatasourceServiceException)

Example 2 with BusinessData

use of org.pentaho.platform.dataaccess.datasource.beans.BusinessData in project data-access by pentaho.

the class DSWDatasourceServiceImpl 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);
        String relativePath = PentahoSystem.getSystemSetting("file-upload-defaults/relative-path", // $NON-NLS-1$
        String.valueOf(CsvTransformGenerator.DEFAULT_RELATIVE_UPLOAD_FILE_PATH));
        String csvFileLoc = PentahoSystem.getApplicationContext().getSolutionPath(relativePath);
        data = DatasourceServiceHelper.getCsvDataSample(csvFileLoc + 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 = DatasourceServiceHelper.getSerializeableResultSet(model.getDatasource().getDatabaseName(), query, 5, PentahoSessionHolder.getSession());
        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) List(java.util.List) ArrayList(java.util.ArrayList) Domain(org.pentaho.metadata.model.Domain) SqlPhysicalModel(org.pentaho.metadata.model.SqlPhysicalModel)

Example 3 with BusinessData

use of org.pentaho.platform.dataaccess.datasource.beans.BusinessData 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 4 with BusinessData

use of org.pentaho.platform.dataaccess.datasource.beans.BusinessData in project data-access by pentaho.

the class DSWDatasourceServiceImplTest method testLoadBusinessData.

@Test
public void testLoadBusinessData() throws DatasourceServiceException {
    BusinessData businessData = dswService.loadBusinessData(DOMAIN_ID_2MODELS, MODEL_NAME);
    assertNotNull(businessData);
    // should load the domain with expected id
    assertEquals(DOMAIN_ID_2MODELS, businessData.getDomain().getId());
}
Also used : BusinessData(org.pentaho.platform.dataaccess.datasource.beans.BusinessData) Test(org.junit.Test)

Example 5 with BusinessData

use of org.pentaho.platform.dataaccess.datasource.beans.BusinessData 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)

Aggregations

BusinessData (org.pentaho.platform.dataaccess.datasource.beans.BusinessData)9 Domain (org.pentaho.metadata.model.Domain)7 ArrayList (java.util.ArrayList)4 List (java.util.List)4 SqlPhysicalModel (org.pentaho.metadata.model.SqlPhysicalModel)4 SerializedResultSet (org.pentaho.platform.dataaccess.datasource.beans.SerializedResultSet)4 DatasourceServiceException (org.pentaho.platform.dataaccess.datasource.wizard.service.DatasourceServiceException)4 Test (org.junit.Test)2 ModelerException (org.pentaho.agilebi.modeler.ModelerException)2 DatabaseConnection (org.pentaho.database.model.DatabaseConnection)2 IDatabaseConnection (org.pentaho.database.model.IDatabaseConnection)2 Category (org.pentaho.metadata.model.Category)2 InlineEtlPhysicalModel (org.pentaho.metadata.model.InlineEtlPhysicalModel)2 LogicalColumn (org.pentaho.metadata.model.LogicalColumn)2 LogicalModel (org.pentaho.metadata.model.LogicalModel)2 LogicalTable (org.pentaho.metadata.model.LogicalTable)2 SqlDataSource (org.pentaho.metadata.model.SqlDataSource)2 SqlPhysicalColumn (org.pentaho.metadata.model.SqlPhysicalColumn)2 SqlPhysicalTable (org.pentaho.metadata.model.SqlPhysicalTable)2 AggregationType (org.pentaho.metadata.model.concept.types.AggregationType)2