Search in sources :

Example 1 with Field

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);
    }
}
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) SalesforceConnection(org.pentaho.di.trans.steps.salesforce.SalesforceConnection) KettleException(org.pentaho.di.core.exception.KettleException) FieldType(com.sforce.soap.partner.FieldType) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface) Field(com.sforce.soap.partner.Field) ValueMetaNone(org.pentaho.di.core.row.value.ValueMetaNone) SourceToTargetMapping(org.pentaho.di.core.SourceToTargetMapping)

Example 2 with Field

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;
}
Also used : Field(com.sforce.soap.partner.Field)

Example 3 with Field

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;
}
Also used : Field(com.sforce.soap.partner.Field) ArrayList(java.util.ArrayList)

Example 4 with Field

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));
}
Also used : Field(com.sforce.soap.partner.Field) Schema(org.apache.avro.Schema) Type(org.apache.avro.Schema.Type) Test(org.junit.Test)

Example 5 with Field

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()));
}
Also used : Field(com.sforce.soap.partner.Field) DescribeSObjectResult(com.sforce.soap.partner.DescribeSObjectResult) Schema(org.apache.avro.Schema) Test(org.junit.Test)

Aggregations

Field (com.sforce.soap.partner.Field)19 Schema (org.apache.avro.Schema)12 Test (org.junit.Test)11 DescribeSObjectResult (com.sforce.soap.partner.DescribeSObjectResult)8 ArrayList (java.util.ArrayList)6 FieldType (com.sforce.soap.partner.FieldType)2 KettleException (org.pentaho.di.core.exception.KettleException)2 SalesforceConnection (org.pentaho.di.trans.steps.salesforce.SalesforceConnection)2 ErrorDialog (org.pentaho.di.ui.core.dialog.ErrorDialog)2 PartnerConnection (com.sforce.soap.partner.PartnerConnection)1 XmlObject (com.sforce.ws.bind.XmlObject)1 HashSet (java.util.HashSet)1 Type (org.apache.avro.Schema.Type)1 TableItem (org.eclipse.swt.widgets.TableItem)1 SourceToTargetMapping (org.pentaho.di.core.SourceToTargetMapping)1 RowMeta (org.pentaho.di.core.row.RowMeta)1 RowMetaInterface (org.pentaho.di.core.row.RowMetaInterface)1 ValueMetaInterface (org.pentaho.di.core.row.ValueMetaInterface)1 ValueMetaNone (org.pentaho.di.core.row.value.ValueMetaNone)1 SalesforceInputField (org.pentaho.di.trans.steps.salesforceinput.SalesforceInputField)1