Search in sources :

Example 26 with SObject

use of com.sforce.soap.partner.sobject.SObject in project components by Talend.

the class SalesforceInputReader method getSchema.

@Override
protected Schema getSchema() throws IOException {
    TSalesforceInputProperties inProperties = (TSalesforceInputProperties) properties;
    if (querySchema == null) {
        querySchema = super.getSchema();
        if (inProperties.manualQuery.getValue()) {
            if (AvroUtils.isIncludeAllFields(properties.module.main.schema.getValue())) {
                SObject currentSObject = getCurrentSObject();
                Iterator<XmlObject> children = currentSObject.getChildren();
                List<String> columnsName = new ArrayList<>();
                int idCount = 0;
                while (children.hasNext()) {
                    String elementName = children.next().getName().getLocalPart();
                    if ("Id".equals(elementName) && idCount == 0) {
                        // Ignore the first 'Id' field which always return for query.
                        idCount++;
                        continue;
                    }
                    if (!columnsName.contains(elementName)) {
                        columnsName.add(elementName);
                    }
                }
                List<Schema.Field> copyFieldList = new ArrayList<>();
                for (String columnName : columnsName) {
                    Schema.Field se = querySchema.getField(columnName);
                    if (se != null) {
                        Schema.Field field = new Schema.Field(se.name(), se.schema(), se.doc(), se.defaultVal());
                        Map<String, Object> fieldProps = se.getObjectProps();
                        for (String propName : fieldProps.keySet()) {
                            Object propValue = fieldProps.get(propName);
                            if (propValue != null) {
                                field.addProp(propName, propValue);
                            }
                        }
                        copyFieldList.add(field);
                    }
                }
                Map<String, Object> objectProps = querySchema.getObjectProps();
                querySchema = Schema.createRecord(querySchema.getName(), querySchema.getDoc(), querySchema.getNamespace(), querySchema.isError());
                querySchema.getObjectProps().putAll(objectProps);
                querySchema.setFields(copyFieldList);
            }
        }
        querySchema.addProp(SalesforceSchemaConstants.COLUMNNAME_DELIMTER, inProperties.columnNameDelimiter.getStringValue());
        querySchema.addProp(SalesforceSchemaConstants.VALUE_DELIMITER, inProperties.normalizeDelimiter.getStringValue());
    }
    return querySchema;
}
Also used : Schema(org.apache.avro.Schema) ArrayList(java.util.ArrayList) TSalesforceInputProperties(org.talend.components.salesforce.tsalesforceinput.TSalesforceInputProperties) SObject(com.sforce.soap.partner.sobject.SObject) XmlObject(com.sforce.ws.bind.XmlObject) XmlObject(com.sforce.ws.bind.XmlObject) SObject(com.sforce.soap.partner.sobject.SObject)

Example 27 with SObject

use of com.sforce.soap.partner.sobject.SObject in project pentaho-kettle by pentaho.

the class SalesforceInputDialogTest method createObject.

private XmlObject createObject(String fieldName, String value, ObjectType type) {
    XmlObject result;
    switch(type) {
        case SOBJECT:
            result = new SObject();
            break;
        case XMLOBJECT:
            result = new XmlObject();
            break;
        default:
            throw new IllegalArgumentException();
    }
    result.setName(new QName(Constants.PARTNER_SOBJECT_NS, fieldName));
    result.setValue(value);
    return result;
}
Also used : QName(javax.xml.namespace.QName) SObject(com.sforce.soap.partner.sobject.SObject) XmlObject(com.sforce.ws.bind.XmlObject)

Example 28 with SObject

use of com.sforce.soap.partner.sobject.SObject in project pentaho-kettle by pentaho.

the class SalesforceConnection method getElements.

// Get SOQL meta data (not a Good way but i don't see any other way !)
// TODO : Go back to this one
// I am sure there is an easy way to return meta for a SOQL result
public XmlObject[] getElements() throws Exception {
    // Query first
    this.qr = getBinding().query(getSQL());
    // and then return records
    SObject con = getQueryResult().getRecords()[0];
    if (con == null) {
        return null;
    }
    return getChildren(con);
}
Also used : SObject(com.sforce.soap.partner.sobject.SObject)

Example 29 with SObject

use of com.sforce.soap.partner.sobject.SObject in project pentaho-kettle by pentaho.

the class SalesforceConnection method getRecord.

public SalesforceRecordValue getRecord(int recordIndex) {
    int index = recordIndex;
    SObject con = this.sObjects[index];
    SalesforceRecordValue retval = new SalesforceRecordValue(index);
    if (con == null) {
        return null;
    }
    if (this.recordsFilter == SalesforceConnectionUtils.RECORDS_FILTER_DELETED) {
        // in getDeletedList
        if (getDeletedList.containsKey(con.getId())) {
            // this record was deleted in the specified range datetime
            // We will return it
            retval.setRecordValue(con);
            retval.setDeletionDate(getDeletedList.get(con.getId()));
        } else if (index < getRecordsCount() - 1) {
            while (con != null && index < getRecordsCount() - 1 && !getDeletedList.containsKey(con.getId())) {
                // still not a record for us !!!
                // let's continue ...
                index++;
                con = this.sObjects[index];
            }
            // if we are here, it means that
            // we found a record to take
            // or we have fetched all available records
            retval.setRecordIndexChanges(true);
            retval.setRecordIndex(index);
            if (con != null && getChildren(con)[index] != null && getDeletedList.containsKey(con.getId())) {
                retval.setRecordValue(con);
                retval.setDeletionDate(getDeletedList.get(con.getId()));
            }
        }
        retval.setAllRecordsProcessed(index >= getRecordsCount() - 1);
    } else {
        // Case for retrieving record also for updated records
        retval.setRecordValue(con);
    }
    return retval;
}
Also used : SObject(com.sforce.soap.partner.sobject.SObject)

Example 30 with SObject

use of com.sforce.soap.partner.sobject.SObject in project pentaho-kettle by pentaho.

the class SalesforceUpdate method processRow.

@Override
public boolean processRow(StepMetaInterface smi, StepDataInterface sdi) throws KettleException {
    // get one row ... This does some basic initialization of the objects, including loading the info coming in
    Object[] outputRowData = getRow();
    if (outputRowData == null) {
        if (data.iBufferPos > 0) {
            flushBuffers();
        }
        setOutputDone();
        return false;
    }
    // If we haven't looked at a row before then do some basic setup.
    if (first) {
        first = false;
        data.sfBuffer = new SObject[meta.getBatchSizeInt()];
        data.outputBuffer = new Object[meta.getBatchSizeInt()][];
        // get total fields in the grid
        data.nrfields = meta.getUpdateLookup().length;
        // Check if field list is filled
        if (data.nrfields == 0) {
            throw new KettleException(BaseMessages.getString(PKG, "SalesforceUpdateDialog.FieldsMissing.DialogMessage"));
        }
        // Create the output row meta-data
        data.inputRowMeta = getInputRowMeta().clone();
        data.outputRowMeta = data.inputRowMeta.clone();
        meta.getFields(data.outputRowMeta, getStepname(), null, null, this, repository, metaStore);
        // Build the mapping of input position to field name
        data.fieldnrs = new int[meta.getUpdateStream().length];
        for (int i = 0; i < meta.getUpdateStream().length; i++) {
            data.fieldnrs[i] = getInputRowMeta().indexOfValue(meta.getUpdateStream()[i]);
            if (data.fieldnrs[i] < 0) {
                throw new KettleException("Field [" + meta.getUpdateStream()[i] + "] couldn't be found in the input stream!");
            }
        }
    }
    try {
        writeToSalesForce(outputRowData);
    } catch (Exception e) {
        throw new KettleStepException(BaseMessages.getString(PKG, "SalesforceUpdate.log.Exception"), e);
    }
    return true;
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) KettleStepException(org.pentaho.di.core.exception.KettleStepException) XmlObject(com.sforce.ws.bind.XmlObject) SObject(com.sforce.soap.partner.sobject.SObject) KettleException(org.pentaho.di.core.exception.KettleException) KettleStepException(org.pentaho.di.core.exception.KettleStepException)

Aggregations

SObject (com.sforce.soap.partner.sobject.SObject)45 XmlObject (com.sforce.ws.bind.XmlObject)23 Test (org.junit.Test)11 KettleException (org.pentaho.di.core.exception.KettleException)11 ArrayList (java.util.ArrayList)10 ConnectionException (com.sforce.ws.ConnectionException)9 KettleStepException (org.pentaho.di.core.exception.KettleStepException)9 QueryResult (com.sforce.soap.partner.QueryResult)5 IOException (java.io.IOException)5 ResourceException (javax.resource.ResourceException)5 QName (javax.xml.namespace.QName)5 Schema (org.apache.avro.Schema)5 SaveResult (com.sforce.soap.partner.SaveResult)4 IndexedRecord (org.apache.avro.generic.IndexedRecord)4 ValueMetaInterface (org.pentaho.di.core.row.ValueMetaInterface)4 RuntimeMetadata (org.teiid.metadata.RuntimeMetadata)4 ExecutionContext (org.teiid.translator.ExecutionContext)4 SalesforceConnection (org.teiid.translator.salesforce.SalesforceConnection)4 VisibleForTesting (com.google.common.annotations.VisibleForTesting)3 InvalidFieldFault (com.sforce.soap.partner.fault.InvalidFieldFault)3