Search in sources :

Example 1 with DescribeGlobalSObjectResult

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

the class SalesforceRuntimeCommon method getSchemaNames.

public static List<NamedThing> getSchemaNames(PartnerConnection connection) throws IOException {
    List<NamedThing> returnList = new ArrayList<>();
    DescribeGlobalResult result = null;
    try {
        result = connection.describeGlobal();
    } catch (ConnectionException e) {
        throw new ComponentException(e);
    }
    DescribeGlobalSObjectResult[] objects = result.getSobjects();
    for (DescribeGlobalSObjectResult obj : objects) {
        LOG.debug("module label: " + obj.getLabel() + " name: " + obj.getName());
        returnList.add(new SimpleNamedThing(obj.getName(), obj.getLabel()));
    }
    return returnList;
}
Also used : DescribeGlobalResult(com.sforce.soap.partner.DescribeGlobalResult) DescribeGlobalSObjectResult(com.sforce.soap.partner.DescribeGlobalSObjectResult) SimpleNamedThing(org.talend.daikon.SimpleNamedThing) ArrayList(java.util.ArrayList) ComponentException(org.talend.components.api.exception.ComponentException) NamedThing(org.talend.daikon.NamedThing) SimpleNamedThing(org.talend.daikon.SimpleNamedThing) ConnectionException(com.sforce.ws.ConnectionException)

Example 2 with DescribeGlobalSObjectResult

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

the class SalesforceRuntimeCommonTest method testGetSchemaNames.

@Test
public void testGetSchemaNames() throws Exception {
    DescribeGlobalResult result = new DescribeGlobalResult();
    DescribeGlobalSObjectResult sObjectResult1 = new DescribeGlobalSObjectResult();
    sObjectResult1.setName("Account");
    sObjectResult1.setLabel("Account");
    DescribeGlobalSObjectResult sObjectResult2 = new DescribeGlobalSObjectResult();
    sObjectResult2.setName("Contact");
    sObjectResult2.setLabel("Contact");
    DescribeGlobalSObjectResult sObjectResult3 = new DescribeGlobalSObjectResult();
    sObjectResult3.setName("Campaign");
    sObjectResult3.setLabel("Campaign");
    result.setSobjects(new IDescribeGlobalSObjectResult[] { sObjectResult1, sObjectResult2, sObjectResult3 });
    PartnerConnection conn = mock(PartnerConnection.class);
    doReturn(result).when(conn).describeGlobal();
    List<NamedThing> schemaNames = SalesforceRuntimeCommon.getSchemaNames(conn);
    assertThat(schemaNames, containsInAnyOrder((NamedThing) new SimpleNamedThing("Account", "Account"), new SimpleNamedThing("Contact", "Contact"), new SimpleNamedThing("Campaign", "Campaign")));
}
Also used : DescribeGlobalResult(com.sforce.soap.partner.DescribeGlobalResult) IDescribeGlobalSObjectResult(com.sforce.soap.partner.IDescribeGlobalSObjectResult) DescribeGlobalSObjectResult(com.sforce.soap.partner.DescribeGlobalSObjectResult) PartnerConnection(com.sforce.soap.partner.PartnerConnection) SimpleNamedThing(org.talend.daikon.SimpleNamedThing) NamedThing(org.talend.daikon.NamedThing) SimpleNamedThing(org.talend.daikon.SimpleNamedThing) Test(org.junit.Test)

Example 3 with DescribeGlobalSObjectResult

use of com.sforce.soap.partner.DescribeGlobalSObjectResult in project teiid by teiid.

the class SalesForceMetadataProcessor method processMetadata.

public void processMetadata() throws TranslatorException {
    try {
        DescribeGlobalResult globalResult = connection.getObjects();
        DescribeGlobalSObjectResult[] objects = globalResult.getSobjects();
        for (DescribeGlobalSObjectResult object : objects) {
            addTable(object);
        }
        List<String> names = new ArrayList<String>();
        for (String name : this.tableMap.keySet()) {
            names.add(name);
            if (names.size() < 100) {
                continue;
            }
            getColumnsAndRelationships(names);
        }
        if (!names.isEmpty()) {
            getColumnsAndRelationships(names);
        }
        addRelationships();
        // Mark id fields are auto increment values, as they are not allowed to be updated
        for (Table table : this.metadataFactory.getSchema().getTables().values()) {
            if (importStatistics) {
                try {
                    Long val = this.connection.getCardinality(table.getNameInSource());
                    if (val != null) {
                        table.setCardinality(val);
                    }
                } catch (Exception e) {
                    // $NON-NLS-1$
                    LogManager.logDetail(LogConstants.CTX_CONNECTOR, e, "Could not get cardinality for", table);
                }
            }
            if (table.getPrimaryKey() == null) {
                continue;
            }
            for (Column column : table.getPrimaryKey().getColumns()) {
                if (!column.isUpdatable()) {
                    column.setAutoIncremented(true);
                }
            }
        }
    } catch (ResourceException e) {
        throw new TranslatorException(e);
    }
}
Also used : DescribeGlobalResult(com.sforce.soap.partner.DescribeGlobalResult) Table(org.teiid.metadata.Table) DescribeGlobalSObjectResult(com.sforce.soap.partner.DescribeGlobalSObjectResult) Column(org.teiid.metadata.Column) ArrayList(java.util.ArrayList) ResourceException(javax.resource.ResourceException) TranslatorException(org.teiid.translator.TranslatorException) ResourceException(javax.resource.ResourceException) TranslatorException(org.teiid.translator.TranslatorException)

Example 4 with DescribeGlobalSObjectResult

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

the class SalesforceSourceOrSink method getSchemaNames.

protected List<NamedThing> getSchemaNames(PartnerConnection connection) throws IOException {
    List<NamedThing> returnList = new ArrayList<>();
    DescribeGlobalResult result = null;
    try {
        result = connection.describeGlobal();
    } catch (ConnectionException e) {
        throw new ComponentException(e);
    }
    DescribeGlobalSObjectResult[] objects = result.getSobjects();
    for (DescribeGlobalSObjectResult obj : objects) {
        LOG.debug("module label: " + obj.getLabel() + " name: " + obj.getName());
        returnList.add(new SimpleNamedThing(obj.getName(), obj.getLabel()));
    }
    return returnList;
}
Also used : DescribeGlobalResult(com.sforce.soap.partner.DescribeGlobalResult) DescribeGlobalSObjectResult(com.sforce.soap.partner.DescribeGlobalSObjectResult) SimpleNamedThing(org.talend.daikon.SimpleNamedThing) ArrayList(java.util.ArrayList) ComponentException(org.talend.components.api.exception.ComponentException) NamedThing(org.talend.daikon.NamedThing) SimpleNamedThing(org.talend.daikon.SimpleNamedThing) ConnectionException(com.sforce.ws.ConnectionException)

Example 5 with DescribeGlobalSObjectResult

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

the class SalesforceConnection method getAllAvailableObjects.

public String[] getAllAvailableObjects(boolean OnlyQueryableObjects) throws KettleException {
    DescribeGlobalResult dgr = null;
    List<String> objects = null;
    DescribeGlobalSObjectResult[] sobjectResults = null;
    try {
        // Get object
        dgr = getBinding().describeGlobal();
        // let's get all objects
        sobjectResults = dgr.getSobjects();
        int nrObjects = dgr.getSobjects().length;
        objects = new ArrayList<String>();
        for (int i = 0; i < nrObjects; i++) {
            DescribeGlobalSObjectResult o = dgr.getSobjects()[i];
            if ((OnlyQueryableObjects && o.isQueryable()) || !OnlyQueryableObjects) {
                objects.add(o.getName());
            }
        }
        return objects.toArray(new String[objects.size()]);
    } catch (Exception e) {
        throw new KettleException(BaseMessages.getString(PKG, "SalesforceInput.Error.GettingModules"), e);
    } finally {
        if (dgr != null) {
            dgr = null;
        }
        if (objects != null) {
            objects.clear();
            objects = null;
        }
        if (sobjectResults != null) {
            sobjectResults = null;
        }
    }
}
Also used : DescribeGlobalResult(com.sforce.soap.partner.DescribeGlobalResult) KettleException(org.pentaho.di.core.exception.KettleException) DescribeGlobalSObjectResult(com.sforce.soap.partner.DescribeGlobalSObjectResult) SOAPException(javax.xml.soap.SOAPException) KettleException(org.pentaho.di.core.exception.KettleException) ConnectionException(com.sforce.ws.ConnectionException) IOException(java.io.IOException)

Aggregations

DescribeGlobalResult (com.sforce.soap.partner.DescribeGlobalResult)5 DescribeGlobalSObjectResult (com.sforce.soap.partner.DescribeGlobalSObjectResult)5 ConnectionException (com.sforce.ws.ConnectionException)3 ArrayList (java.util.ArrayList)3 NamedThing (org.talend.daikon.NamedThing)3 SimpleNamedThing (org.talend.daikon.SimpleNamedThing)3 ComponentException (org.talend.components.api.exception.ComponentException)2 IDescribeGlobalSObjectResult (com.sforce.soap.partner.IDescribeGlobalSObjectResult)1 PartnerConnection (com.sforce.soap.partner.PartnerConnection)1 IOException (java.io.IOException)1 ResourceException (javax.resource.ResourceException)1 SOAPException (javax.xml.soap.SOAPException)1 Test (org.junit.Test)1 KettleException (org.pentaho.di.core.exception.KettleException)1 Column (org.teiid.metadata.Column)1 Table (org.teiid.metadata.Table)1 TranslatorException (org.teiid.translator.TranslatorException)1