Search in sources :

Example 91 with ComponentException

use of org.talend.components.api.exception.ComponentException in project components by Talend.

the class SalesforceSourceOrSink method getSchemaNames.

public static List<NamedThing> getSchemaNames(RuntimeContainer container, SalesforceProvideConnectionProperties properties) throws IOException {
    ClassLoader classLoader = SalesforceSourceOrSink.class.getClassLoader();
    // org.talend.components.salesforce.runtime.common.SalesforceRuntimeCommon.enableTLSv11AndTLSv12ForJava7()
    try (SandboxedInstance sandboxedInstance = RuntimeUtil.createRuntimeClassWithCurrentJVMProperties(getStaticRuntimeInfo(), classLoader)) {
        SalesforceSourceOrSink ss = (SalesforceSourceOrSink) sandboxedInstance.getInstance();
        ss.initialize(null, (ComponentProperties) properties);
        try {
            ss.connect(container);
            return ss.getSchemaNames(container);
        } catch (Exception ex) {
            throw new ComponentException(SalesforceRuntimeCommon.exceptionToValidationResult(ex));
        }
    }
}
Also used : SandboxedInstance(org.talend.daikon.sandbox.SandboxedInstance) ComponentException(org.talend.components.api.exception.ComponentException) AsyncApiException(com.sforce.async.AsyncApiException) ConnectionException(com.sforce.ws.ConnectionException) ComponentException(org.talend.components.api.exception.ComponentException) IOException(java.io.IOException)

Example 92 with ComponentException

use of org.talend.components.api.exception.ComponentException 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 93 with ComponentException

use of org.talend.components.api.exception.ComponentException in project components by Talend.

the class SalesforceSourceOrSink method connectBulk.

protected BulkConnection connectBulk(ConnectorConfig config) throws ComponentException {
    final SalesforceConnectionProperties connProps = getConnectionProperties();
    /*
         * When PartnerConnection is instantiated, a login is implicitly executed and, if successful, a valid session id is
         * stored in the ConnectorConfig instance. Use this key to initialize a BulkConnection:
         */
    ConnectorConfig bulkConfig = new ConnectorConfig();
    setProxy(bulkConfig);
    bulkConfig.setSessionId(config.getSessionId());
    // For session renew
    bulkConfig.setSessionRenewer(config.getSessionRenewer());
    bulkConfig.setUsername(config.getUsername());
    bulkConfig.setPassword(config.getPassword());
    /*
         * The endpoint for the Bulk API service is the same as for the normal SOAP uri until the /Soap/ part. From here
         * it's '/async/versionNumber'
         */
    String soapEndpoint = config.getServiceEndpoint();
    // Service endpoint should be like this:
    // https://ap1.salesforce.com/services/Soap/u/37.0/00D90000000eSq3
    String apiVersion = soapEndpoint.substring(soapEndpoint.lastIndexOf("/services/Soap/u/") + 17);
    apiVersion = apiVersion.substring(0, apiVersion.indexOf("/"));
    String restEndpoint = soapEndpoint.substring(0, soapEndpoint.indexOf("Soap/")) + "async/" + apiVersion;
    bulkConfig.setRestEndpoint(restEndpoint);
    // This should only be false when doing debugging.
    bulkConfig.setCompression(connProps.needCompression.getValue());
    bulkConfig.setTraceMessage(connProps.httpTraceMessage.getValue());
    bulkConfig.setValidateSchema(false);
    try {
        return new BulkConnection(bulkConfig);
    } catch (AsyncApiException e) {
        throw new ComponentException(e);
    }
}
Also used : SalesforceConnectionProperties(org.talend.components.salesforce.SalesforceConnectionProperties) ConnectorConfig(com.sforce.ws.ConnectorConfig) ComponentException(org.talend.components.api.exception.ComponentException) BulkConnection(com.sforce.async.BulkConnection) AsyncApiException(com.sforce.async.AsyncApiException)

Example 94 with ComponentException

use of org.talend.components.api.exception.ComponentException in project components by Talend.

the class SalesforceWriter method delete.

private DeleteResult[] delete(IndexedRecord input) throws IOException {
    // schema to delete rows.
    if (deleteFieldId == -1) {
        String ID = "Id";
        Schema.Field idField = input.getSchema().getField(ID);
        if (null == idField) {
            throw new ComponentException(new DefaultErrorCode(HttpServletResponse.SC_BAD_REQUEST, "message"), ExceptionContext.build().put("message", ID + " not found"));
        }
        deleteFieldId = idField.pos();
    }
    String id = (String) input.get(deleteFieldId);
    if (id != null) {
        deleteItems.add(input);
        if (deleteItems.size() >= commitLevel) {
            return doDelete();
        }
    }
    return null;
}
Also used : DefaultErrorCode(org.talend.daikon.exception.error.DefaultErrorCode) Schema(org.apache.avro.Schema) ComponentException(org.talend.components.api.exception.ComponentException)

Example 95 with ComponentException

use of org.talend.components.api.exception.ComponentException in project components by Talend.

the class SalesforceBulkExecRuntime method bulkExecute.

public void bulkExecute(RuntimeContainer container) {
    TSalesforceBulkExecProperties sprops = (TSalesforceBulkExecProperties) properties;
    try {
        SalesforceBulkRuntime bulkRuntime = new SalesforceBulkRuntime(connect(container).bulkConnection);
        bulkRuntime.setConcurrencyMode(sprops.bulkProperties.concurrencyMode.getValue());
        bulkRuntime.setAwaitTime(sprops.bulkProperties.waitTimeCheckBatchState.getValue());
        // We only support CSV file for bulk output
        bulkRuntime.executeBulk(sprops.module.moduleName.getStringValue(), sprops.outputAction.getValue(), sprops.upsertKeyColumn.getStringValue(), "csv", sprops.bulkFilePath.getStringValue(), sprops.bulkProperties.bytesToCommit.getValue(), sprops.bulkProperties.rowsToCommit.getValue());
        // count results
        for (int i = 0; i < bulkRuntime.getBatchCount(); i++) {
            for (BulkResult result : bulkRuntime.getBatchLog(i)) {
                dataCount++;
                if ("true".equalsIgnoreCase(String.valueOf(result.getValue("Success")))) {
                    successCount++;
                } else {
                    rejectCount++;
                }
            }
        }
        bulkRuntime.close();
    } catch (IOException | AsyncApiException | ConnectionException e) {
        throw new ComponentException(e);
    }
}
Also used : ComponentException(org.talend.components.api.exception.ComponentException) IOException(java.io.IOException) AsyncApiException(com.sforce.async.AsyncApiException) ConnectionException(com.sforce.ws.ConnectionException) TSalesforceBulkExecProperties(org.talend.components.salesforce.tsalesforcebulkexec.TSalesforceBulkExecProperties)

Aggregations

ComponentException (org.talend.components.api.exception.ComponentException)101 URL (java.net.URL)32 MalformedURLException (java.net.MalformedURLException)30 JarRuntimeInfo (org.talend.components.api.component.runtime.JarRuntimeInfo)27 IOException (java.io.IOException)18 ArrayList (java.util.ArrayList)17 InvalidKeyException (java.security.InvalidKeyException)14 Schema (org.apache.avro.Schema)14 URISyntaxException (java.net.URISyntaxException)12 StorageException (com.microsoft.azure.storage.StorageException)11 NamedThing (org.talend.daikon.NamedThing)11 ValidationResult (org.talend.daikon.properties.ValidationResult)10 SandboxedInstance (org.talend.daikon.sandbox.SandboxedInstance)10 IndexedRecord (org.apache.avro.generic.IndexedRecord)8 Test (org.junit.Test)8 SimpleNamedThing (org.talend.daikon.SimpleNamedThing)8 NetSuiteException (org.talend.components.netsuite.client.NetSuiteException)6 GeneralSecurityException (java.security.GeneralSecurityException)5 JDBCSource (org.talend.components.jdbc.runtime.JDBCSource)5 TJDBCInputDefinition (org.talend.components.jdbc.tjdbcinput.TJDBCInputDefinition)5