use of org.pentaho.platform.dataaccess.datasource.wizard.models.ModelInfo in project data-access by pentaho.
the class CsvUtils method getModelInfo.
public ModelInfo getModelInfo(String project, String filename) throws FileNotFoundException {
// $NON-NLS-1$
XStream xstream = new XStream(new DomDriver("UTF-8"));
// $NON-NLS-1$
xstream.alias("modelInfo", ModelInfo.class);
// $NON-NLS-1$
xstream.alias("columnInfo", ColumnInfo.class);
// $NON-NLS-1$ //$NON-NLS-2$
String filepath = AgileHelper.getFolderPath(project) + "/" + filename + ".xml";
System.out.println(filepath);
File f = new File(filepath);
FileInputStream fis = new FileInputStream(f);
return (ModelInfo) xstream.fromXML(fis);
}
use of org.pentaho.platform.dataaccess.datasource.wizard.models.ModelInfo in project data-access by pentaho.
the class CsvUtils method generateFields.
/* package-local visibility for testing purposes */
ModelInfo generateFields(String project, String fileLocation, String filename, int rowLimit, String delimiter, String enclosure, int headerRows, boolean doData, boolean doColumns, String encoding) throws Exception {
ModelInfo result = new ModelInfo();
CsvFileInfo fileInfo = new CsvFileInfo();
result.setFileInfo(fileInfo);
CsvInspector inspector = new CsvInspector();
String sampleLine = getLines(fileLocation, 1, encoding);
int fileType = inspector.determineFileFormat(sampleLine);
String contents = getLines(fileLocation, rowLimit, encoding);
fileInfo.setContents(getLinesList(fileLocation, rowLimit, encoding));
if (delimiter.equals("")) {
// $NON-NLS-1$
delimiter = inspector.guessDelimiter(contents);
// $NON-NLS-1$
enclosure = "\"";
headerRows = 0;
}
fileInfo.setDelimiter(delimiter);
fileInfo.setEnclosure(enclosure);
fileInfo.setHeaderRows(headerRows);
// Resolves the file encoding using icu4j.
fileInfo.setEncoding(encoding);
fileInfo.setProject(project);
fileInfo.setTmpFilename(filename);
DataProfile data = getDataProfile(fileInfo, rowLimit, fileLocation, fileType, encoding);
if (doData) {
result.setData(data.getRows());
}
if (doColumns) {
result.setColumns(data.getColumns());
}
return result;
}
use of org.pentaho.platform.dataaccess.datasource.wizard.models.ModelInfo 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;
}
Aggregations