Search in sources :

Example 1 with CsvDatasourceImportStrategy

use of org.pentaho.metadata.automodel.importing.strategy.CsvDatasourceImportStrategy in project data-access by pentaho.

the class ModelerServiceIT method domainForCsvDatasource_GeneratedWithCsvDatasourceImportStrategy.

@Test
public void domainForCsvDatasource_GeneratedWithCsvDatasourceImportStrategy() throws Exception {
    ModelInfo modelInfo = new ModelInfo();
    ColumnInfo[] columnInfos = new ColumnInfo[] { createColumnInfo("id", "title") };
    modelInfo.setColumns(columnInfos);
    modelerService = spy(modelerService);
    DatabaseMeta dbMeta = mock(DatabaseMeta.class);
    doReturn(dbMeta).when(modelerService).getDatabaseMeta();
    TableModelerSource source = mock(TableModelerSource.class);
    doReturn(source).when(modelerService).createTableModelerSource(any(DatabaseMeta.class), anyString(), anyString(), anyString());
    modelerService.generateCSVDomain(modelInfo);
    verify(modelerService).toColumns(columnInfos);
    // most important thing here, is that domain is generated with CsvDatasourceImportStrategy
    verify(source).generateDomain(any(CsvDatasourceImportStrategy.class));
}
Also used : TableModelerSource(org.pentaho.agilebi.modeler.util.TableModelerSource) ModelInfo(org.pentaho.platform.dataaccess.datasource.wizard.models.ModelInfo) CsvDatasourceImportStrategy(org.pentaho.metadata.automodel.importing.strategy.CsvDatasourceImportStrategy) ColumnInfo(org.pentaho.platform.dataaccess.datasource.wizard.models.ColumnInfo) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta) Test(org.junit.Test)

Example 2 with CsvDatasourceImportStrategy

use of org.pentaho.metadata.automodel.importing.strategy.CsvDatasourceImportStrategy in project data-access by pentaho.

the class ModelerService method generateCSVDomain.

public Domain generateCSVDomain(ModelInfo modelInfo) throws Exception {
    initKettle();
    try {
        DatabaseMeta database = getDatabaseMeta();
        final String tableName = modelInfo.getStageTableName();
        final String datasourceName = modelInfo.getDatasourceName();
        Column[] columns = toColumns(modelInfo.getColumns());
        PhysicalTableImporter.ImportStrategy importStrategy = new CsvDatasourceImportStrategy(columns);
        TableModelerSource source = createTableModelerSource(database, tableName, null, datasourceName);
        return source.generateDomain(importStrategy);
    } catch (Exception e) {
        logger.error(e);
        throw new Exception(e.getLocalizedMessage());
    }
}
Also used : PhysicalTableImporter(org.pentaho.metadata.automodel.PhysicalTableImporter) TableModelerSource(org.pentaho.agilebi.modeler.util.TableModelerSource) CsvDatasourceImportStrategy(org.pentaho.metadata.automodel.importing.strategy.CsvDatasourceImportStrategy) Column(org.pentaho.metadata.model.thin.Column) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta) KettleException(org.pentaho.di.core.exception.KettleException)

Aggregations

TableModelerSource (org.pentaho.agilebi.modeler.util.TableModelerSource)2 DatabaseMeta (org.pentaho.di.core.database.DatabaseMeta)2 CsvDatasourceImportStrategy (org.pentaho.metadata.automodel.importing.strategy.CsvDatasourceImportStrategy)2 Test (org.junit.Test)1 KettleException (org.pentaho.di.core.exception.KettleException)1 PhysicalTableImporter (org.pentaho.metadata.automodel.PhysicalTableImporter)1 Column (org.pentaho.metadata.model.thin.Column)1 ColumnInfo (org.pentaho.platform.dataaccess.datasource.wizard.models.ColumnInfo)1 ModelInfo (org.pentaho.platform.dataaccess.datasource.wizard.models.ModelInfo)1