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