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;
}
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));
}
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;
}
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;
}
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();
}
Aggregations