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));
}
}
}
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;
}
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);
}
}
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;
}
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);
}
}
Aggregations