Search in sources :

Example 11 with ColumnInfo

use of org.pentaho.platform.dataaccess.datasource.wizard.models.ColumnInfo in project data-access by pentaho.

the class ModelerServiceIT method createColumnInfo.

private ColumnInfo createColumnInfo(String id, String title) {
    ColumnInfo columnInfo = new ColumnInfo();
    columnInfo.setId(id);
    columnInfo.setTitle(title);
    return columnInfo;
}
Also used : ColumnInfo(org.pentaho.platform.dataaccess.datasource.wizard.models.ColumnInfo)

Example 12 with ColumnInfo

use of org.pentaho.platform.dataaccess.datasource.wizard.models.ColumnInfo 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 13 with ColumnInfo

use of org.pentaho.platform.dataaccess.datasource.wizard.models.ColumnInfo in project data-access by pentaho.

the class TestUtil method createModel.

public static ModelInfo createModel() {
    CsvFileInfo fileInfo = new CsvFileInfo();
    fileInfo.setTmpFilename("unit_test.csv");
    fileInfo.setProject("testsolution");
    fileInfo.setHeaderRows(1);
    fileInfo.setDelimiter(",");
    fileInfo.setEnclosure("\"");
    ColumnInfo[] columns = new ColumnInfo[9];
    columns[0] = new ColumnInfo();
    columns[0].setDataType(DataType.NUMERIC);
    columns[0].setPrecision(0);
    columns[0].setId("PC_0");
    columns[0].setTitle("REGIONC");
    columns[0].setIndex(true);
    columns[0].setFieldType(ColumnInfo.FIELD_TYPE_BOTH);
    columns[0].setAggregateType(AggregationType.SUM.toString());
    columns[1] = new ColumnInfo();
    columns[1].setDataType(DataType.NUMERIC);
    columns[1].setId("PC_1");
    columns[1].setTitle("NWEIGHT");
    columns[1].setPrecision(5);
    columns[1].setIndex(true);
    columns[1].setFieldType(ColumnInfo.FIELD_TYPE_BOTH);
    columns[1].setAggregateType(AggregationType.SUM.toString());
    columns[2] = new ColumnInfo();
    columns[2].setDataType(DataType.NUMERIC);
    columns[2].setId("PC_2");
    columns[2].setTitle("Int");
    columns[2].setFieldType(ColumnInfo.FIELD_TYPE_BOTH);
    columns[2].setAggregateType(AggregationType.SUM.toString());
    columns[3] = new ColumnInfo();
    columns[3].setDataType(DataType.DATE);
    columns[3].setId("PC_3");
    columns[3].setTitle("xdate");
    columns[3].setFormat("mm/dd/yy");
    columns[3].setIndex(true);
    columns[3].setFieldType(ColumnInfo.FIELD_TYPE_DIMENSION);
    columns[3].setAggregateType(AggregationType.NONE.toString());
    columns[4] = new ColumnInfo();
    columns[4].setDataType(DataType.STRING);
    columns[4].setId("PC_4");
    columns[4].setTitle("");
    columns[4].setIgnore(true);
    columns[4].setFieldType(ColumnInfo.FIELD_TYPE_DIMENSION);
    columns[4].setAggregateType(AggregationType.NONE.toString());
    columns[5] = new ColumnInfo();
    columns[5].setDataType(DataType.STRING);
    columns[5].setId("PC_5");
    columns[5].setTitle("Location");
    columns[5].setIndex(true);
    columns[5].setLength(60);
    columns[5].setFieldType(ColumnInfo.FIELD_TYPE_DIMENSION);
    columns[5].setAggregateType(AggregationType.NONE.toString());
    columns[6] = new ColumnInfo();
    columns[6].setDataType(DataType.NUMERIC);
    columns[6].setId("PC_6");
    columns[6].setTitle("charlen");
    columns[6].setFieldType(ColumnInfo.FIELD_TYPE_BOTH);
    columns[6].setAggregateType(AggregationType.SUM.toString());
    columns[7] = new ColumnInfo();
    columns[7].setDataType(DataType.NUMERIC);
    columns[7].setId("PC_7");
    columns[7].setTitle("xfactor");
    columns[7].setPrecision(7);
    columns[7].setFieldType(ColumnInfo.FIELD_TYPE_BOTH);
    columns[7].setAggregateType(AggregationType.SUM.toString());
    columns[8] = new ColumnInfo();
    columns[8].setDataType(DataType.BOOLEAN);
    columns[8].setId("PC_8");
    columns[8].setTitle("Flag");
    columns[8].setIndex(true);
    columns[8].setFieldType(ColumnInfo.FIELD_TYPE_BOTH);
    columns[8].setAggregateType(AggregationType.SUM.toString());
    ModelInfo info = new ModelInfo();
    info.setFileInfo(fileInfo);
    info.setColumns(columns);
    info.setStageTableName("UNIT_TESTS");
    return info;
}
Also used : CsvFileInfo(org.pentaho.platform.dataaccess.datasource.wizard.models.CsvFileInfo) ModelInfo(org.pentaho.platform.dataaccess.datasource.wizard.models.ModelInfo) ColumnInfo(org.pentaho.platform.dataaccess.datasource.wizard.models.ColumnInfo)

Example 14 with ColumnInfo

use of org.pentaho.platform.dataaccess.datasource.wizard.models.ColumnInfo in project data-access by pentaho.

the class ModelerService method toColumns.

Column[] toColumns(ColumnInfo[] columnInfos) {
    Column[] columns = new Column[columnInfos.length];
    for (int i = 0; i < columnInfos.length; i++) {
        ColumnInfo columnInfo = columnInfos[i];
        final String id = columnInfo.getId();
        final String title = columnInfo.getTitle();
        if (id == null || title == null) {
            continue;
        }
        Column column = new Column();
        column.setId(id);
        column.setName(title);
        columns[i] = column;
    }
    return columns;
}
Also used : Column(org.pentaho.metadata.model.thin.Column) ColumnInfo(org.pentaho.platform.dataaccess.datasource.wizard.models.ColumnInfo)

Example 15 with ColumnInfo

use of org.pentaho.platform.dataaccess.datasource.wizard.models.ColumnInfo in project data-access by pentaho.

the class StageDataStep method generateDataTypeDisplay_horizontal.

private void generateDataTypeDisplay_horizontal() {
    // $NON-NLS-1$
    XulTree tree = (XulTree) document.getElementById("csvModelDataTable");
    tree.setRows(datasourceModel.getModelInfo().getColumns().length);
    bf.setBindingType(Binding.Type.ONE_WAY);
    tree.setBindingProvider(new FactoryBasedBindingProvider(bf) {

        @Override
        public BindingConvertor getConvertor(XulEventSource source, String prop1, XulEventSource target, String prop2) {
            if (source instanceof ColumnInfo) {
                if (prop1.equals("length") || prop1.equals("precision")) {
                    // $NON-NLS-1$ //$NON-NLS-2$
                    return BindingConvertor.integer2String();
                } else if (prop1.equals("include") && prop2.equals("value")) {
                    // this is the binding from the cell to the value of the checkbox
                    return null;
                } else if (prop1.equals("include")) {
                    // this binding is from the model to the checkbox
                    return BindingConvertor.boolean2String();
                } else if (prop1.equals("availableDataTypes")) {
                    // $NON-NLS-1$
                    return new BindingConvertor<List, Vector>() {

                        @SuppressWarnings("unchecked")
                        public Vector sourceToTarget(List value) {
                            return new Vector(value);
                        }

                        @SuppressWarnings("unchecked")
                        public List targetToSource(Vector value) {
                            return new ArrayList(value);
                        }
                    };
                } else if (prop1.equals("formatStrings")) {
                    // $NON-NLS-1$
                    return new BindingConvertor<List, Vector>() {

                        @SuppressWarnings("unchecked")
                        public Vector sourceToTarget(List value) {
                            return new Vector(value);
                        }

                        @SuppressWarnings("unchecked")
                        public List targetToSource(Vector value) {
                            return new ArrayList(value);
                        }
                    };
                } else if (prop1.equals("dataType") && prop2.equals("selectedIndex")) {
                    // $NON-NLS-1$ //$NON-NLS-2$
                    return new BindingConvertor<DataType, Integer>() {

                        @Override
                        public Integer sourceToTarget(DataType value) {
                            List<DataType> types = ColumnInfo.getAvailableDataTypes();
                            for (int i = 0; i < types.size(); i++) {
                                if (types.get(i).equals(value)) {
                                    return i;
                                }
                            }
                            return 0;
                        }

                        @Override
                        public DataType targetToSource(Integer value) {
                            return ColumnInfo.getAvailableDataTypes().get(value);
                        }
                    };
                } else if (prop1.equals("formatStringsDisabled")) {
                    return null;
                } else {
                    return BindingConvertor.string2String();
                }
            } else {
                return null;
            }
        }
    });
    tree.setElements(Arrays.asList(datasourceModel.getModelInfo().getColumns()));
    if (datasourceModel.getModelInfo().getColumns().length > 0) {
        tree.setSelectedRows(new int[] { 0 });
    }
    tree.update();
}
Also used : FactoryBasedBindingProvider(org.pentaho.ui.xul.binding.FactoryBasedBindingProvider) XulTree(org.pentaho.ui.xul.containers.XulTree) ArrayList(java.util.ArrayList) ColumnInfo(org.pentaho.platform.dataaccess.datasource.wizard.models.ColumnInfo) BindingConvertor(org.pentaho.ui.xul.binding.BindingConvertor) DataType(org.pentaho.metadata.model.concept.types.DataType) ArrayList(java.util.ArrayList) List(java.util.List) Vector(java.util.Vector) XulEventSource(org.pentaho.ui.xul.XulEventSource)

Aggregations

ColumnInfo (org.pentaho.platform.dataaccess.datasource.wizard.models.ColumnInfo)16 Test (org.junit.Test)5 ArrayList (java.util.ArrayList)4 StepMeta (org.pentaho.di.trans.step.StepMeta)3 ModelInfo (org.pentaho.platform.dataaccess.datasource.wizard.models.ModelInfo)3 List (java.util.List)2 CalculatorMetaFunction (org.pentaho.di.trans.steps.calculator.CalculatorMetaFunction)2 Column (org.pentaho.metadata.model.thin.Column)2 CsvFileInfo (org.pentaho.platform.dataaccess.datasource.wizard.models.CsvFileInfo)2 DataRow (org.pentaho.platform.dataaccess.datasource.wizard.models.DataRow)2 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 InputStreamReader (java.io.InputStreamReader)1 DecimalFormat (java.text.DecimalFormat)1 Locale (java.util.Locale)1 Vector (java.util.Vector)1 Before (org.junit.Before)1