Search in sources :

Example 61 with RowMeta

use of org.pentaho.di.core.row.RowMeta in project pentaho-kettle by pentaho.

the class SalesforceUpdateTest method testWriteToSalesForceForNullExtIdField_WithExtIdYES.

@Test
public void testWriteToSalesForceForNullExtIdField_WithExtIdYES() throws Exception {
    SalesforceUpdate sfInputStep = new SalesforceUpdate(smh.stepMeta, smh.stepDataInterface, 0, smh.transMeta, smh.trans);
    SalesforceUpdateMeta meta = generateSalesforceUpdateMeta(new String[] { ACCOUNT_EXT_ID_ACCOUNT_ID_C_ACCOUNT }, new Boolean[] { true });
    SalesforceUpdateData data = generateSalesforceUpdateData();
    sfInputStep.init(meta, data);
    RowMeta rowMeta = new RowMeta();
    ValueMetaBase valueMeta = new ValueMetaString("AccExtId");
    rowMeta.addValueMeta(valueMeta);
    smh.initStepDataInterface.inputRowMeta = rowMeta;
    sfInputStep.writeToSalesForce(new Object[] { null });
    assertEquals(1, data.sfBuffer[0].getFieldsToNull().length);
    assertEquals(ACCOUNT_ID, data.sfBuffer[0].getFieldsToNull()[0]);
    assertNull(SalesforceConnection.getChildren(data.sfBuffer[0]));
}
Also used : ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) RowMeta(org.pentaho.di.core.row.RowMeta) ValueMetaBase(org.pentaho.di.core.row.value.ValueMetaBase) Test(org.junit.Test)

Example 62 with RowMeta

use of org.pentaho.di.core.row.RowMeta in project pentaho-kettle by pentaho.

the class SalesforceUpdateTest method testWriteToSalesForceForNotNullExtIdField_WithExtIdYES.

@Test
public void testWriteToSalesForceForNotNullExtIdField_WithExtIdYES() throws Exception {
    SalesforceUpdate sfInputStep = new SalesforceUpdate(smh.stepMeta, smh.stepDataInterface, 0, smh.transMeta, smh.trans);
    SalesforceUpdateMeta meta = generateSalesforceUpdateMeta(new String[] { ACCOUNT_EXT_ID_ACCOUNT_ID_C_ACCOUNT }, new Boolean[] { true });
    SalesforceUpdateData data = generateSalesforceUpdateData();
    sfInputStep.init(meta, data);
    RowMeta rowMeta = new RowMeta();
    ValueMetaBase valueMeta = new ValueMetaString("AccExtId");
    rowMeta.addValueMeta(valueMeta);
    smh.initStepDataInterface.inputRowMeta = rowMeta;
    sfInputStep.writeToSalesForce(new Object[] { "tkas88" });
    assertEquals(0, data.sfBuffer[0].getFieldsToNull().length);
    assertEquals(1, SalesforceConnection.getChildren(data.sfBuffer[0]).length);
    assertEquals(Constants.PARTNER_SOBJECT_NS, SalesforceConnection.getChildren(data.sfBuffer[0])[0].getName().getNamespaceURI());
    assertEquals("Account", SalesforceConnection.getChildren(data.sfBuffer[0])[0].getName().getLocalPart());
    assertNull(SalesforceConnection.getChildren(data.sfBuffer[0])[0].getValue());
    assertFalse(SalesforceConnection.getChildren(data.sfBuffer[0])[0].hasChildren());
}
Also used : ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) RowMeta(org.pentaho.di.core.row.RowMeta) ValueMetaBase(org.pentaho.di.core.row.value.ValueMetaBase) Test(org.junit.Test)

Example 63 with RowMeta

use of org.pentaho.di.core.row.RowMeta in project pentaho-kettle by pentaho.

the class SalesforceUpsertTest method testWriteToSalesForceForNotNullExtIdField_WithExtIdNO.

@Test
public void testWriteToSalesForceForNotNullExtIdField_WithExtIdNO() throws Exception {
    SalesforceUpsert sfInputStep = new SalesforceUpsert(smh.stepMeta, smh.stepDataInterface, 0, smh.transMeta, smh.trans);
    SalesforceUpsertMeta meta = generateSalesforceUpsertMeta(new String[] { ACCOUNT_ID }, new Boolean[] { false });
    SalesforceUpsertData data = generateSalesforceUpsertData();
    sfInputStep.init(meta, data);
    RowMeta rowMeta = new RowMeta();
    ValueMetaBase valueMeta = new ValueMetaString("AccNoExtId");
    rowMeta.addValueMeta(valueMeta);
    smh.initStepDataInterface.inputRowMeta = rowMeta;
    sfInputStep.writeToSalesForce(new Object[] { "001i000001c5Nv9AAE" });
    assertEquals(0, data.sfBuffer[0].getFieldsToNull().length);
    assertEquals(1, SalesforceConnection.getChildren(data.sfBuffer[0]).length);
    assertEquals(Constants.PARTNER_SOBJECT_NS, SalesforceConnection.getChildren(data.sfBuffer[0])[0].getName().getNamespaceURI());
    assertEquals(ACCOUNT_ID, SalesforceConnection.getChildren(data.sfBuffer[0])[0].getName().getLocalPart());
    assertEquals("001i000001c5Nv9AAE", SalesforceConnection.getChildren(data.sfBuffer[0])[0].getValue());
    assertFalse(SalesforceConnection.getChildren(data.sfBuffer[0])[0].hasChildren());
}
Also used : ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) RowMeta(org.pentaho.di.core.row.RowMeta) ValueMetaBase(org.pentaho.di.core.row.value.ValueMetaBase) Test(org.junit.Test)

Example 64 with RowMeta

use of org.pentaho.di.core.row.RowMeta in project pentaho-kettle by pentaho.

the class SapInputDialog method setComboValues.

private void setComboValues() {
    Runnable fieldLoader = new Runnable() {

        public void run() {
            try {
                prevFields = transMeta.getPrevStepFields(stepname);
            } catch (KettleException e) {
                prevFields = new RowMeta();
                String msg = BaseMessages.getString(PKG, "SapInputDialog.DoMapping.UnableToFindInput");
                logError(msg);
            }
            String[] prevStepFieldNames = prevFields.getFieldNames();
            Arrays.sort(prevStepFieldNames);
            for (int i = 0; i < inputFieldColumns.size(); i++) {
                ColumnInfo colInfo = outputFieldColumns.get(i);
                colInfo.setComboValues(prevStepFieldNames);
            }
        }
    };
    new Thread(fieldLoader).start();
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) RowMeta(org.pentaho.di.core.row.RowMeta) ColumnInfo(org.pentaho.di.ui.core.widget.ColumnInfo)

Example 65 with RowMeta

use of org.pentaho.di.core.row.RowMeta in project pentaho-kettle by pentaho.

the class ShapeFileReader method processRow.

public synchronized boolean processRow(StepMetaInterface smi, StepDataInterface sdi) throws KettleStepException {
    meta = (ShapeFileReaderMeta) smi;
    data = (ShapeFileReaderData) sdi;
    boolean retval = true;
    if (data.shapeNr >= data.shapeFile.getNrShapes()) {
        setOutputDone();
        return false;
    }
    if (first) {
        first = false;
        data.outputRowMeta = new RowMeta();
        meta.getFields(data.outputRowMeta, getStepname(), null, null, this);
    }
    // building new row
    Object[] outputRow = RowDataUtil.allocateRowData(data.outputRowMeta.size());
    int outputIndex;
    // getting shape # data.shapeNr from shapefile
    // Get the shape from the shapefile
    // 
    ShapeInterface si = data.shapeFile.getShape(data.shapeNr);
    switch(si.getType()) {
        case Shape.SHAPE_TYPE_POLYLINE_M:
            {
                // PolyLimeM";
                ShapePolyLineM eplm = (ShapePolyLineM) si;
                int partnr = 0;
                for (int j = 0; j < eplm.nrpoints; j++) {
                    // PolyLimeM, point #"+j;
                    for (int k = 0; k < eplm.nrparts; k++) {
                        if (j == eplm.part_starts[k])
                            partnr++;
                    }
                    outputIndex = 0;
                    // adding the basics";
                    // Add the basics...
                    // The filename...
                    outputRow[outputIndex++] = meta.getShapeFilename();
                    // The file type
                    outputRow[outputIndex++] = data.shapeFile.getFileHeader().getShapeTypeDesc();
                    // The shape nr
                    outputRow[outputIndex++] = new Long(data.shapeNr + 1);
                    // The part nr
                    outputRow[outputIndex++] = new Long(partnr);
                    // The nr of parts
                    outputRow[outputIndex++] = new Long(eplm.nrparts);
                    // The point nr
                    outputRow[outputIndex++] = new Long(j + 1);
                    // The nr of points
                    outputRow[outputIndex++] = new Long(eplm.nrpoints);
                    // The X coordinate
                    outputRow[outputIndex++] = new Double(eplm.point[j].x);
                    // The Y coordinate
                    outputRow[outputIndex++] = new Double(eplm.point[j].y);
                    // The measure
                    outputRow[outputIndex++] = new Double(eplm.measures[j]);
                    // The Values in the DBF file...
                    // PolyLimeM, point #"+j+", add dbf data";
                    Object[] dbfData = si.getDbfData();
                    RowMetaInterface dbfMeta = si.getDbfMeta();
                    for (int d = 0; d < dbfMeta.size(); d++) {
                        outputRow[outputIndex++] = dbfData[d];
                    }
                    linesInput++;
                    // Put it out to the rest of the world...
                    putRow(data.outputRowMeta, outputRow);
                }
            }
            break;
        case Shape.SHAPE_TYPE_POLYGON:
            {
                // ShapePolygon";
                ShapePolygon epl = (ShapePolygon) si;
                int partnr = 0;
                for (int j = 0; j < epl.nrpoints; j++) {
                    // PolyLime, point #"+j;
                    for (int k = 0; k < epl.nrparts; k++) {
                        if (j == epl.part_starts[k])
                            partnr++;
                    }
                    outputIndex = 0;
                    // adding the basics";
                    // Add the basics...
                    // The filename...
                    outputRow[outputIndex++] = meta.getShapeFilename();
                    // The file type
                    outputRow[outputIndex++] = data.shapeFile.getFileHeader().getShapeTypeDesc();
                    // The shape nr
                    outputRow[outputIndex++] = new Long(data.shapeNr + 1);
                    // The part nr
                    outputRow[outputIndex++] = new Long(partnr);
                    // The nr of parts
                    outputRow[outputIndex++] = new Long(epl.nrparts);
                    // The point nr
                    outputRow[outputIndex++] = new Long(j + 1);
                    // The nr of points
                    outputRow[outputIndex++] = new Long(epl.nrpoints);
                    // The X coordinate
                    outputRow[outputIndex++] = new Double(epl.point[j].x);
                    // The Y coordinate
                    outputRow[outputIndex++] = new Double(epl.point[j].y);
                    // The measure
                    outputRow[outputIndex++] = new Double(0.0);
                    // The Values in the DBF file...
                    // PolyLime, point #"+j+", add dbf data";
                    // 
                    Object[] dbfData = si.getDbfData();
                    RowMetaInterface dbfMeta = si.getDbfMeta();
                    for (int d = 0; d < dbfMeta.size(); d++) {
                        outputRow[outputIndex++] = dbfData[d];
                    }
                    linesInput++;
                    // Put it out to the rest of the world...
                    putRow(data.outputRowMeta, outputRow);
                }
            }
            break;
        case Shape.SHAPE_TYPE_POLYLINE:
            {
                // PolyLime";
                ShapePolyLine epl = (ShapePolyLine) si;
                int partnr = 0;
                for (int j = 0; j < epl.nrpoints; j++) {
                    // PolyLime, point #"+j;
                    for (int k = 0; k < epl.nrparts; k++) {
                        if (j == epl.part_starts[k])
                            partnr++;
                    }
                    outputIndex = 0;
                    // adding the basics";
                    // Add the basics...
                    // The filename...
                    outputRow[outputIndex++] = meta.getShapeFilename();
                    // The file type
                    outputRow[outputIndex++] = data.shapeFile.getFileHeader().getShapeTypeDesc();
                    // The shape nr
                    outputRow[outputIndex++] = new Long(data.shapeNr + 1);
                    // The part nr
                    outputRow[outputIndex++] = new Long(partnr);
                    // The nr of parts
                    outputRow[outputIndex++] = new Long(epl.nrparts);
                    // The point nr
                    outputRow[outputIndex++] = new Long(j + 1);
                    // The nr of points
                    outputRow[outputIndex++] = new Long(epl.nrpoints);
                    // The X coordinate
                    outputRow[outputIndex++] = new Double(epl.point[j].x);
                    // The Y coordinate
                    outputRow[outputIndex++] = new Double(epl.point[j].y);
                    // The measure
                    outputRow[outputIndex++] = new Double(0.0);
                    // The Values in the DBF file...
                    // PolyLime, point #"+j+", add dbf data";
                    // 
                    Object[] dbfData = si.getDbfData();
                    RowMetaInterface dbfMeta = si.getDbfMeta();
                    for (int d = 0; d < dbfMeta.size(); d++) {
                        outputRow[outputIndex++] = dbfData[d];
                    }
                    linesInput++;
                    // Put it out to the rest of the world...
                    putRow(data.outputRowMeta, outputRow);
                }
            }
            break;
        case Shape.SHAPE_TYPE_POINT:
            {
                // Point";
                ShapePoint ep = (ShapePoint) si;
                // Add the basics...
                outputIndex = 0;
                // The filename...
                outputRow[outputIndex++] = meta.getShapeFilename();
                // The file type
                outputRow[outputIndex++] = data.shapeFile.getFileHeader().getShapeTypeDesc();
                // The shape nr
                outputRow[outputIndex++] = new Long(data.shapeNr);
                // The part nr
                outputRow[outputIndex++] = new Long(0L);
                // The nr of parts
                outputRow[outputIndex++] = new Long(0L);
                // The point nr
                outputRow[outputIndex++] = new Long(0L);
                // The nr of points
                outputRow[outputIndex++] = new Long(0L);
                // The X coordinate
                outputRow[outputIndex++] = new Double(ep.x);
                // The Y coordinate
                outputRow[outputIndex++] = new Double(ep.y);
                // The measure
                outputRow[outputIndex++] = new Double(0.0);
                // The Values in the DBF file...
                // PolyLimeM, point #"+data.shapeNr+", add dbf data";
                // 
                Object[] dbfData = si.getDbfData();
                RowMetaInterface dbfMeta = si.getDbfMeta();
                for (int d = 0; d < dbfMeta.size(); d++) {
                    outputRow[outputIndex++] = dbfData[d];
                }
                linesInput++;
                // Put it out to the rest of the world...
                putRow(data.outputRowMeta, outputRow);
            }
            break;
        default:
            System.out.println("Unable to parse shape type [" + Shape.getEsriTypeDesc(si.getType()) + "] : not yet implemented.");
            throw new KettleStepException("Unable to parse shape type [" + Shape.getEsriTypeDesc(si.getType()) + "] : not yet implemented.");
    }
    // Next shape please!
    data.shapeNr++;
    if ((linesInput % Const.ROWS_UPDATE) == 0)
        logBasic("linenr " + linesInput);
    return retval;
}
Also used : KettleStepException(org.pentaho.di.core.exception.KettleStepException) RowMeta(org.pentaho.di.core.row.RowMeta) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) ShapePoint(org.pentaho.gis.shapefiles.ShapePoint) ShapePoint(org.pentaho.gis.shapefiles.ShapePoint) ShapePolyLineM(org.pentaho.gis.shapefiles.ShapePolyLineM) ShapePolyLine(org.pentaho.gis.shapefiles.ShapePolyLine) ShapeInterface(org.pentaho.gis.shapefiles.ShapeInterface) ShapePolygon(org.pentaho.gis.shapefiles.ShapePolygon)

Aggregations

RowMeta (org.pentaho.di.core.row.RowMeta)540 RowMetaInterface (org.pentaho.di.core.row.RowMetaInterface)280 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)249 ValueMetaInterface (org.pentaho.di.core.row.ValueMetaInterface)209 Test (org.junit.Test)174 ValueMetaInteger (org.pentaho.di.core.row.value.ValueMetaInteger)135 KettleException (org.pentaho.di.core.exception.KettleException)112 ArrayList (java.util.ArrayList)68 KettleStepException (org.pentaho.di.core.exception.KettleStepException)56 RowMetaAndData (org.pentaho.di.core.RowMetaAndData)52 ValueMetaDate (org.pentaho.di.core.row.value.ValueMetaDate)44 ValueMetaNumber (org.pentaho.di.core.row.value.ValueMetaNumber)41 RowSet (org.pentaho.di.core.RowSet)34 KettleDatabaseException (org.pentaho.di.core.exception.KettleDatabaseException)27 ValueMetaBase (org.pentaho.di.core.row.value.ValueMetaBase)26 SQLException (java.sql.SQLException)24 FileObject (org.apache.commons.vfs2.FileObject)24 ValueMetaBoolean (org.pentaho.di.core.row.value.ValueMetaBoolean)23 StepMeta (org.pentaho.di.trans.step.StepMeta)23 ErrorDialog (org.pentaho.di.ui.core.dialog.ErrorDialog)23