Search in sources :

Example 6 with TSalesforceBulkExecProperties

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;
}
Also used : Form(org.talend.daikon.properties.presentation.Form) TSalesforceBulkExecProperties(org.talend.components.salesforce.tsalesforcebulkexec.TSalesforceBulkExecProperties)

Example 7 with TSalesforceBulkExecProperties

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);
        }
    }
}
Also used : IndexedRecord(org.apache.avro.generic.IndexedRecord) HashMap(java.util.HashMap) DataRejectException(org.talend.components.api.exception.DataRejectException) ArrayList(java.util.ArrayList) TSalesforceBulkExecDefinition(org.talend.components.salesforce.tsalesforcebulkexec.TSalesforceBulkExecDefinition) Reader(org.talend.components.api.component.runtime.Reader) TSalesforceBulkExecProperties(org.talend.components.salesforce.tsalesforcebulkexec.TSalesforceBulkExecProperties) TSalesforceOutputBulkProperties(org.talend.components.salesforce.tsalesforceoutputbulk.TSalesforceOutputBulkProperties) TSalesforceOutputBulkDefinition(org.talend.components.salesforce.tsalesforceoutputbulk.TSalesforceOutputBulkDefinition) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 8 with TSalesforceBulkExecProperties

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);
        }
    }
}
Also used : IndexedRecord(org.apache.avro.generic.IndexedRecord) HashMap(java.util.HashMap) DataRejectException(org.talend.components.api.exception.DataRejectException) ArrayList(java.util.ArrayList) TSalesforceBulkExecDefinition(org.talend.components.salesforce.tsalesforcebulkexec.TSalesforceBulkExecDefinition) Reader(org.talend.components.api.component.runtime.Reader) TSalesforceBulkExecProperties(org.talend.components.salesforce.tsalesforcebulkexec.TSalesforceBulkExecProperties) TSalesforceOutputBulkProperties(org.talend.components.salesforce.tsalesforceoutputbulk.TSalesforceOutputBulkProperties) TSalesforceOutputBulkDefinition(org.talend.components.salesforce.tsalesforceoutputbulk.TSalesforceOutputBulkDefinition) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 9 with TSalesforceBulkExecProperties

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);
}
Also used : TSalesforceBulkExecDefinition(org.talend.components.salesforce.tsalesforcebulkexec.TSalesforceBulkExecDefinition) TSalesforceBulkExecProperties(org.talend.components.salesforce.tsalesforcebulkexec.TSalesforceBulkExecProperties) Test(org.junit.Test)

Example 10 with TSalesforceBulkExecProperties

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

TSalesforceBulkExecProperties (org.talend.components.salesforce.tsalesforcebulkexec.TSalesforceBulkExecProperties)12 Test (org.junit.Test)6 IndexedRecord (org.apache.avro.generic.IndexedRecord)5 TSalesforceBulkExecDefinition (org.talend.components.salesforce.tsalesforcebulkexec.TSalesforceBulkExecDefinition)5 TSalesforceOutputBulkProperties (org.talend.components.salesforce.tsalesforceoutputbulk.TSalesforceOutputBulkProperties)5 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4 Map (java.util.Map)4 Reader (org.talend.components.api.component.runtime.Reader)4 DataRejectException (org.talend.components.api.exception.DataRejectException)4 TSalesforceOutputBulkDefinition (org.talend.components.salesforce.tsalesforceoutputbulk.TSalesforceOutputBulkDefinition)4 AsyncApiException (com.sforce.async.AsyncApiException)2 ConnectionException (com.sforce.ws.ConnectionException)2 IOException (java.io.IOException)2 ComponentException (org.talend.components.api.exception.ComponentException)1 TSalesforceGetDeletedProperties (org.talend.components.salesforce.tsalesforcegetdeleted.TSalesforceGetDeletedProperties)1 TSalesforceGetServerTimestampProperties (org.talend.components.salesforce.tsalesforcegetservertimestamp.TSalesforceGetServerTimestampProperties)1 TSalesforceGetUpdatedProperties (org.talend.components.salesforce.tsalesforcegetupdated.TSalesforceGetUpdatedProperties)1 TSalesforceInputProperties (org.talend.components.salesforce.tsalesforceinput.TSalesforceInputProperties)1 TSalesforceOutputBulkExecProperties (org.talend.components.salesforce.tsalesforceoutputbulkexec.TSalesforceOutputBulkExecProperties)1