use of com.sforce.soap.partner.Field in project pentaho-kettle by pentaho.
the class SalesforceInsertDialog 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, "SalesforceInsertDialog.DoMapping.UnableToFindSourceFields.Title"), BaseMessages.getString(PKG, "SalesforceInsertDialog.DoMapping.UnableToFindSourceFields.Message"), e);
return;
}
try {
SalesforceConnection connection = getConnection();
Field[] fields = connection.getObjectFields(transMeta.environmentSubstitute(wModule.getText()));
String[] fieldNames = connection.getFields(fields);
FieldType dateType = FieldType.date;
for (int i = 0; i < fields.length; i++) {
if (dateType.equals(fields[i].getType())) {
// Mark date columns as TYPE_DATE to strip time part later
targetFields.addValueMeta(ValueMetaFactory.createValueMeta(fieldNames[i], ValueMetaInterface.TYPE_DATE));
} else {
targetFields.addValueMeta(new ValueMetaNone(fieldNames[i]));
}
}
} catch (Exception e) {
new ErrorDialog(shell, BaseMessages.getString(PKG, "SalesforceInsertDialog.DoMapping.UnableToFindTargetFields.Title"), BaseMessages.getString(PKG, "SalesforceInsertDialog.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, "SalesforceInsertDialog.DoMapping.SomeSourceFieldsNotFound", missingSourceFields.toString()) + Const.CR;
}
if (missingTargetFields.length() > 0) {
message += BaseMessages.getString(PKG, "SalesforceInsertDialog.DoMapping.SomeTargetFieldsNotFound", missingSourceFields.toString()) + Const.CR;
}
message += Const.CR;
message += BaseMessages.getString(PKG, "SalesforceInsertDialog.DoMapping.SomeFieldsNotFoundContinue") + Const.CR;
MessageDialog.setDefaultImage(GUIResource.getInstance().getImageSpoon());
boolean goOn = MessageDialog.openConfirm(shell, BaseMessages.getString(PKG, "SalesforceInsertDialog.DoMapping.SomeFieldsNotFoundTitle"), message);
if (!goOn) {
return;
}
}
EnterMappingDialog d = new EnterMappingDialog(SalesforceInsertDialog.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 com.sforce.soap.partner.Field in project pentaho-kettle by pentaho.
the class SalesforceConnection method getFields.
/**
* Method returns names of the fields specified.
* @param fields fields
* @return fields' names
* @throws KettleException in case of error
* @see #getObjectFields(String)
*/
public String[] getFields(Field[] fields) throws KettleException {
if (fields != null) {
int nrFields = fields.length;
String[] fieldsMapp = new String[nrFields];
for (int i = 0; i < nrFields; i++) {
Field field = fields[i];
fieldsMapp[i] = field.getName();
}
return fieldsMapp;
}
return null;
}
use of com.sforce.soap.partner.Field in project pentaho-kettle by pentaho.
the class SalesforceConnection method getObjectFields.
/**
*Returns only updatable object fields and ID field if <b>excludeNonUpdatableFields</b> is true,
* otherwise all object field
* @param objectName the name of Saleforce object
* @param excludeNonUpdatableFields the flag that indicates if non-updatable fields should be excluded or not
* @return the list of object fields depending on filter or not non-updatable fields.
* @throws KettleException if any exception occurs
*/
public Field[] getObjectFields(String objectName, boolean excludeNonUpdatableFields) throws KettleException {
Field[] fieldList = getObjectFields(objectName);
if (excludeNonUpdatableFields) {
ArrayList<Field> finalFieldList = new ArrayList<Field>();
for (Field f : fieldList) {
// Leave out fields that can't be updated but
if (isIdField(f) || !f.isCalculated() && f.isUpdateable()) {
finalFieldList.add(f);
}
}
fieldList = finalFieldList.toArray(new Field[finalFieldList.size()]);
}
return fieldList;
}
use of com.sforce.soap.partner.Field in project components by Talend.
the class SalesforceAvroRegistryTest method testInferSchemaFieldPercent.
/**
* Tests {@link SalesforceAvroRegistry#inferSchema(Object)} returns {@link Schema} of type {@link Type#DOUBLE},
* when percent Field is passed
*
* This test-case related to https://jira.talendforge.org/browse/TDI-37479 bug
*/
@Test
public void testInferSchemaFieldPercent() {
Field percentField = new Field();
percentField.setType(FieldType.percent);
Schema schema = sRegistry.inferSchema(percentField);
Schema.Type actualType = schema.getType();
assertThat(actualType, is(Schema.Type.DOUBLE));
}
use of com.sforce.soap.partner.Field in project components by Talend.
the class SalesforceAvroRegistryStringTest method testPickList.
@Test
public void testPickList() throws Exception {
DescribeSObjectResult describeSObjectResult = new DescribeSObjectResult();
Field pickList = new Field();
pickList.setName("pickList");
pickList.setType(FieldType.picklist);
describeSObjectResult.setFields(new Field[] { pickList });
Schema schema = SalesforceAvroRegistryString.get().inferSchema(describeSObjectResult);
assertThat(1, is(schema.getFields().size()));
}
Aggregations