use of org.talend.components.salesforce.tsalesforcebulkexec.TSalesforceBulkExecProperties in project components by Talend.
the class TSalesforceOutputBulkExecProperties method getOutputComponentProperties.
@Override
public ComponentProperties getOutputComponentProperties() {
TSalesforceBulkExecProperties bulkExecProperties = new TSalesforceBulkExecProperties("bulkExecProperties");
bulkExecProperties.init();
bulkExecProperties.copyValuesFrom(this, true, true);
// we need to pass also the possible values, only way from the studio to know it comes from a combo box (need to
// add quotes for generation)
bulkExecProperties.upsertRelationTable.columnName.setPossibleValues(upsertRelationTable.columnName.getPossibleValues());
bulkExecProperties.connection.referencedComponent.componentInstanceId.setTaggedValue(UpsertRelationTable.ADD_QUOTES, true);
bulkExecProperties.module.connection.referencedComponent.componentInstanceId.setTaggedValue(UpsertRelationTable.ADD_QUOTES, true);
for (Form form : bulkExecProperties.getForms()) {
bulkExecProperties.refreshLayout(form);
}
return bulkExecProperties;
}
use of org.talend.components.salesforce.tsalesforcebulkexec.TSalesforceBulkExecProperties in project components by Talend.
the class SalesforceBulkLoadTestIT method testUpdate.
@Test
public void testUpdate() throws Throwable {
List<String> ids = util.createTestData();
String id = ids.get(0);
final List<Map<String, String>> testData = new ArrayList<Map<String, String>>();
Map<String, String> datarow = new HashMap<String, String>();
datarow.put("Id", id);
datarow.put("FirstName", "Wei");
datarow.put("LastName", "Wang");
// update the field
datarow.put("Phone", "010-89492686");
testData.add(datarow);
datarow = new HashMap<String, String>();
// should reject
datarow.put("Id", "not_exist");
datarow.put("FirstName", "Who");
datarow.put("LastName", "Who");
datarow.put("Phone", "010-89492686");
testData.add(datarow);
String data_file = tempFolder.newFile("data.txt").getAbsolutePath();
// outputbulk part
TSalesforceOutputBulkDefinition definition = (TSalesforceOutputBulkDefinition) getComponentService().getComponentDefinition(TSalesforceOutputBulkDefinition.COMPONENT_NAME);
TSalesforceOutputBulkProperties modelProperties = util.simulateUserBasicAction(definition, data_file, util.getTestSchema4());
util.simulateRuntimeCaller(definition, modelProperties, util.getTestSchema4(), testData);
// bulkexec part
TSalesforceBulkExecDefinition defin = (TSalesforceBulkExecDefinition) getComponentService().getComponentDefinition(TSalesforceBulkExecDefinition.COMPONENT_NAME);
TSalesforceBulkExecProperties modelProps = (TSalesforceBulkExecProperties) defin.createRuntimeProperties();
Reader reader = util.initReader(defin, data_file, modelProps, util.getTestSchema4(), util.getTestSchema4());
modelProps.outputAction.setValue(TSalesforceBulkExecProperties.OutputAction.UPDATE);
try {
IndexedRecordConverter<Object, ? extends IndexedRecord> factory = null;
for (boolean available = reader.start(); available; available = reader.advance()) {
try {
Object data = reader.getCurrent();
factory = initCurrentData(factory, data);
IndexedRecord record = factory.convertToAvro(data);
String resultid = (String) record.get(0);
String phone = (String) record.get(3);
Assert.assertEquals(id, resultid);
Assert.assertEquals("010-89492686", phone);
} catch (DataRejectException e) {
java.util.Map<String, Object> info = e.getRejectInfo();
Object data = info.get("talend_record");
String err = (String) info.get("error");
factory = initCurrentData(factory, data);
IndexedRecord record = factory.convertToAvro(data);
String resultid = (String) record.get(0);
String firstname = (String) record.get(1);
String lastname = (String) record.get(2);
String phone = (String) record.get(3);
Assert.assertNull(resultid);
Assert.assertEquals("Who", firstname);
Assert.assertEquals("Who", lastname);
Assert.assertEquals("010-89492686", phone);
Assert.assertTrue(err != null);
}
}
} finally {
try {
reader.close();
} finally {
util.deleteTestData(ids);
}
}
}
use of org.talend.components.salesforce.tsalesforcebulkexec.TSalesforceBulkExecProperties in project components by Talend.
the class SalesforceBulkLoadTestIT method testUpsert.
@Test
public void testUpsert() throws Throwable {
List<String> ids = util.createTestData();
String id = ids.get(0);
final List<Map<String, String>> testData = new ArrayList<Map<String, String>>();
Map<String, String> datarow = new HashMap<String, String>();
// should update
datarow.put("Id", id);
datarow.put("FirstName", "Wei");
datarow.put("LastName", "Wang");
// update the field
datarow.put("Phone", "010-89492686");
testData.add(datarow);
datarow = new HashMap<String, String>();
// should insert
datarow.put("Id", null);
datarow.put("FirstName", "Who");
datarow.put("LastName", "Who");
datarow.put("Phone", "010-89492686");
testData.add(datarow);
String data_file = tempFolder.newFile("data.txt").getAbsolutePath();
// outputbulk part
TSalesforceOutputBulkDefinition definition = (TSalesforceOutputBulkDefinition) getComponentService().getComponentDefinition(TSalesforceOutputBulkDefinition.COMPONENT_NAME);
TSalesforceOutputBulkProperties modelProperties = util.simulateUserBasicAction(definition, data_file, util.getTestSchema4());
util.simulateRuntimeCaller(definition, modelProperties, util.getTestSchema4(), testData);
// bulkexec part
TSalesforceBulkExecDefinition defin = (TSalesforceBulkExecDefinition) getComponentService().getComponentDefinition(TSalesforceBulkExecDefinition.COMPONENT_NAME);
TSalesforceBulkExecProperties modelProps = (TSalesforceBulkExecProperties) defin.createRuntimeProperties();
Reader reader = util.initReader(defin, data_file, modelProps, util.getTestSchema4(), util.getTestSchema4());
modelProps.outputAction.setValue(TSalesforceBulkExecProperties.OutputAction.UPSERT);
modelProps.upsertKeyColumn.setValue("Id");
try {
IndexedRecordConverter<Object, ? extends IndexedRecord> factory = null;
int index = -1;
for (boolean available = reader.start(); available; available = reader.advance()) {
try {
Object data = reader.getCurrent();
factory = initCurrentData(factory, data);
IndexedRecord record = factory.convertToAvro(data);
String resultid = (String) record.get(0);
String phone = (String) record.get(3);
index++;
if (index == 0) {
Assert.assertEquals(id, resultid);
Assert.assertEquals("010-89492686", phone);
} else if (index == 1) {
Assert.assertTrue(resultid != null);
Assert.assertEquals("010-89492686", phone);
}
} catch (DataRejectException e) {
Assert.fail(e.getMessage());
}
}
} finally {
try {
reader.close();
} finally {
util.deleteTestData(ids);
}
}
}
use of org.talend.components.salesforce.tsalesforcebulkexec.TSalesforceBulkExecProperties in project components by Talend.
the class SalesforceSchemaTest method testOutputSchemaForTSalesforceBulkExec.
@Test
public void testOutputSchemaForTSalesforceBulkExec() throws Throwable {
TSalesforceBulkExecDefinition defin = (TSalesforceBulkExecDefinition) getComponentService().getComponentDefinition(TSalesforceBulkExecDefinition.COMPONENT_NAME);
TSalesforceBulkExecProperties modelProps = (TSalesforceBulkExecProperties) defin.createProperties();
assertBulk(modelProps);
}
use of org.talend.components.salesforce.tsalesforcebulkexec.TSalesforceBulkExecProperties 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