Search in sources :

Example 41 with RowMeta

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

the class SalesforceUpsertDialog method generateMappings.

/**
 * Reads in the fields from the previous steps and from the ONE next step and opens an EnterMappingDialog with this
 * information. After the user did the mapping, those information is put into the Select/Rename table.
 */
private void generateMappings() {
    if (!checkInput()) {
        return;
    }
    // Determine the source and target fields...
    // 
    RowMetaInterface sourceFields;
    RowMetaInterface targetFields = new RowMeta();
    try {
        sourceFields = transMeta.getPrevStepFields(stepMeta);
    } catch (KettleException e) {
        new ErrorDialog(shell, BaseMessages.getString(PKG, "SalesforceUpsertDialog.DoMapping.UnableToFindSourceFields.Title"), BaseMessages.getString(PKG, "SalesforceUpsertDialog.DoMapping.UnableToFindSourceFields.Message"), e);
        return;
    }
    try {
        String[] fields = getModuleFields();
        for (int i = 0; i < fields.length; i++) {
            targetFields.addValueMeta(new ValueMetaNone(fields[i]));
        }
    } catch (Exception e) {
        new ErrorDialog(shell, BaseMessages.getString(PKG, "SalesforceUpsertDialog.DoMapping.UnableToFindTargetFields.Title"), BaseMessages.getString(PKG, "SalesforceUpsertDialog.DoMapping.UnableToFindTargetFields.Message"), e);
        return;
    }
    String[] inputNames = new String[sourceFields.size()];
    for (int i = 0; i < sourceFields.size(); i++) {
        ValueMetaInterface value = sourceFields.getValueMeta(i);
        inputNames[i] = value.getName() + EnterMappingDialog.STRING_ORIGIN_SEPARATOR + value.getOrigin() + ")";
    }
    // Create the existing mapping list...
    // 
    List<SourceToTargetMapping> mappings = new ArrayList<SourceToTargetMapping>();
    StringBuffer missingSourceFields = new StringBuffer();
    StringBuffer missingTargetFields = new StringBuffer();
    int nrFields = wReturn.nrNonEmpty();
    for (int i = 0; i < nrFields; i++) {
        TableItem item = wReturn.getNonEmpty(i);
        String source = item.getText(2);
        String target = item.getText(1);
        int sourceIndex = sourceFields.indexOfValue(source);
        if (sourceIndex < 0) {
            missingSourceFields.append(Const.CR + "   " + source + " --> " + target);
        }
        int targetIndex = targetFields.indexOfValue(target);
        if (targetIndex < 0) {
            missingTargetFields.append(Const.CR + "   " + source + " --> " + target);
        }
        if (sourceIndex < 0 || targetIndex < 0) {
            continue;
        }
        SourceToTargetMapping mapping = new SourceToTargetMapping(sourceIndex, targetIndex);
        mappings.add(mapping);
    }
    // 
    if (missingSourceFields.length() > 0 || missingTargetFields.length() > 0) {
        String message = "";
        if (missingSourceFields.length() > 0) {
            message += BaseMessages.getString(PKG, "SalesforceUpsertDialog.DoMapping.SomeSourceFieldsNotFound", missingSourceFields.toString()) + Const.CR;
        }
        if (missingTargetFields.length() > 0) {
            message += BaseMessages.getString(PKG, "SalesforceUpsertDialog.DoMapping.SomeTargetFieldsNotFound", missingSourceFields.toString()) + Const.CR;
        }
        message += Const.CR;
        message += BaseMessages.getString(PKG, "SalesforceUpsertDialog.DoMapping.SomeFieldsNotFoundContinue") + Const.CR;
        MessageDialog.setDefaultImage(GUIResource.getInstance().getImageSpoon());
        boolean goOn = MessageDialog.openConfirm(shell, BaseMessages.getString(PKG, "SalesforceUpsertDialog.DoMapping.SomeFieldsNotFoundTitle"), message);
        if (!goOn) {
            return;
        }
    }
    EnterMappingDialog d = new EnterMappingDialog(SalesforceUpsertDialog.this.shell, sourceFields.getFieldNames(), targetFields.getFieldNames(), mappings);
    mappings = d.open();
    // 
    if (mappings != null) {
        // Clear and re-populate!
        // 
        wReturn.table.removeAll();
        wReturn.table.setItemCount(mappings.size());
        for (int i = 0; i < mappings.size(); i++) {
            SourceToTargetMapping mapping = mappings.get(i);
            TableItem item = wReturn.table.getItem(i);
            item.setText(2, sourceFields.getValueMeta(mapping.getSourcePosition()).getName());
            item.setText(1, targetFields.getValueMeta(mapping.getTargetPosition()).getName());
        }
        wReturn.setRowNums();
        wReturn.optWidth(true);
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) RowMeta(org.pentaho.di.core.row.RowMeta) EnterMappingDialog(org.pentaho.di.ui.core.dialog.EnterMappingDialog) TableItem(org.eclipse.swt.widgets.TableItem) ArrayList(java.util.ArrayList) ErrorDialog(org.pentaho.di.ui.core.dialog.ErrorDialog) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) KettleException(org.pentaho.di.core.exception.KettleException) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface) ValueMetaNone(org.pentaho.di.core.row.value.ValueMetaNone) SourceToTargetMapping(org.pentaho.di.core.SourceToTargetMapping)

Example 42 with RowMeta

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

the class SalesforceDeleteMetaTest method testGetFields.

@Test
public void testGetFields() throws KettleStepException {
    SalesforceDeleteMeta meta = new SalesforceDeleteMeta();
    meta.setDefault();
    RowMetaInterface r = new RowMeta();
    meta.getFields(r, "thisStep", null, null, new Variables(), null, null);
    assertEquals(0, r.size());
    r.clear();
    r.addValueMeta(new ValueMetaString("testString"));
    meta.getFields(r, "thisStep", null, null, new Variables(), null, null);
    assertEquals(1, r.size());
    assertEquals(ValueMetaInterface.TYPE_STRING, r.getValueMeta(0).getType());
    assertEquals("testString", r.getValueMeta(0).getName());
}
Also used : Variables(org.pentaho.di.core.variables.Variables) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) RowMeta(org.pentaho.di.core.row.RowMeta) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) SalesforceMetaTest(org.pentaho.di.trans.steps.salesforce.SalesforceMetaTest) Test(org.junit.Test)

Example 43 with RowMeta

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

the class SalesforceInputMetaTest method testGetFields.

@Test
public void testGetFields() throws KettleStepException {
    SalesforceInputMeta meta = new SalesforceInputMeta();
    meta.setDefault();
    RowMetaInterface r = new RowMeta();
    meta.getFields(r, "thisStep", null, null, new Variables(), null, null);
    assertEquals(0, r.size());
    meta.setInputFields(new SalesforceInputField[] { new SalesforceInputField("field1") });
    r.clear();
    meta.getFields(r, "thisStep", null, null, new Variables(), null, null);
    assertEquals(1, r.size());
    meta.setIncludeDeletionDate(true);
    meta.setDeletionDateField("DeletionDate");
    meta.setIncludeModule(true);
    meta.setModuleField("ModuleName");
    meta.setIncludeRowNumber(true);
    meta.setRowNumberField("RN");
    meta.setIncludeSQL(true);
    meta.setSQLField("sqlField");
    meta.setIncludeTargetURL(true);
    meta.setTargetURLField("Target");
    meta.setIncludeTimestamp(true);
    meta.setTimestampField("TS");
    r.clear();
    meta.getFields(r, "thisStep", null, null, new Variables(), null, null);
    assertEquals(7, r.size());
    assertTrue(r.indexOfValue("field1") >= 0);
    assertTrue(r.indexOfValue("DeletionDate") >= 0);
    assertTrue(r.indexOfValue("ModuleName") >= 0);
    assertTrue(r.indexOfValue("RN") >= 0);
    assertTrue(r.indexOfValue("sqlField") >= 0);
    assertTrue(r.indexOfValue("Target") >= 0);
    assertTrue(r.indexOfValue("TS") >= 0);
}
Also used : Variables(org.pentaho.di.core.variables.Variables) RowMeta(org.pentaho.di.core.row.RowMeta) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) SalesforceMetaTest(org.pentaho.di.trans.steps.salesforce.SalesforceMetaTest) Test(org.junit.Test)

Example 44 with RowMeta

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

the class SalesforceInsertMetaTest method testGetFields.

@Test
public void testGetFields() throws KettleStepException {
    SalesforceInsertMeta meta = new SalesforceInsertMeta();
    meta.setDefault();
    RowMetaInterface r = new RowMeta();
    meta.getFields(r, "thisStep", null, null, new Variables(), null, null);
    assertEquals(1, r.size());
    assertEquals("Id", r.getFieldNames()[0]);
    meta.setSalesforceIDFieldName("id_field");
    r.clear();
    meta.getFields(r, "thisStep", null, null, new Variables(), null, null);
    assertEquals(1, r.size());
    assertEquals("id_field", r.getFieldNames()[0]);
}
Also used : Variables(org.pentaho.di.core.variables.Variables) RowMeta(org.pentaho.di.core.row.RowMeta) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) SalesforceMetaTest(org.pentaho.di.trans.steps.salesforce.SalesforceMetaTest) Test(org.junit.Test)

Example 45 with RowMeta

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

the class SalesforceInsertTest method testWriteToSalesForceForNotNullExtIdField_WithExtIdNO.

@Test
public void testWriteToSalesForceForNotNullExtIdField_WithExtIdNO() throws Exception {
    SalesforceInsert sfInputStep = new SalesforceInsert(smh.stepMeta, smh.stepDataInterface, 0, smh.transMeta, smh.trans);
    SalesforceInsertMeta meta = generateSalesforceInsertMeta(new String[] { ACCOUNT_ID }, new Boolean[] { false });
    SalesforceInsertData data = generateSalesforceInsertData();
    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)

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