Search in sources :

Example 21 with ModelInfo

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);
}
Also used : DomDriver(com.thoughtworks.xstream.io.xml.DomDriver) ModelInfo(org.pentaho.platform.dataaccess.datasource.wizard.models.ModelInfo) XStream(com.thoughtworks.xstream.XStream) File(java.io.File) FileInputStream(java.io.FileInputStream)

Example 22 with ModelInfo

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;
}
Also used : CsvFileInfo(org.pentaho.platform.dataaccess.datasource.wizard.models.CsvFileInfo) ModelInfo(org.pentaho.platform.dataaccess.datasource.wizard.models.ModelInfo)

Example 23 with ModelInfo

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

Aggregations

ModelInfo (org.pentaho.platform.dataaccess.datasource.wizard.models.ModelInfo)23 IPentahoSession (org.pentaho.platform.api.engine.IPentahoSession)12 StandaloneSession (org.pentaho.platform.engine.core.system.StandaloneSession)11 CsvTransformGeneratorException (org.pentaho.platform.dataaccess.datasource.wizard.models.CsvTransformGeneratorException)10 DatabaseMeta (org.pentaho.di.core.database.DatabaseMeta)6 CsvFileInfo (org.pentaho.platform.dataaccess.datasource.wizard.models.CsvFileInfo)6 Test (org.junit.Test)4 File (java.io.File)3 ColumnInfo (org.pentaho.platform.dataaccess.datasource.wizard.models.ColumnInfo)3 DatasourceServiceException (org.pentaho.platform.dataaccess.datasource.wizard.service.DatasourceServiceException)3 XStream (com.thoughtworks.xstream.XStream)2 FileNotFoundException (java.io.FileNotFoundException)2 IOException (java.io.IOException)2 Date (java.util.Date)2 Matchers.anyString (org.mockito.Matchers.anyString)2 Database (org.pentaho.di.core.database.Database)2 CsvUtils (org.pentaho.platform.dataaccess.datasource.wizard.csv.CsvUtils)2 DataRow (org.pentaho.platform.dataaccess.datasource.wizard.models.DataRow)2 DatasourceDTO (org.pentaho.platform.dataaccess.datasource.wizard.models.DatasourceDTO)2 FileTransformStats (org.pentaho.platform.dataaccess.datasource.wizard.sources.csv.FileTransformStats)2