Search in sources :

Example 1 with TSalesforceInputProperties

use of org.talend.components.salesforce.tsalesforceinput.TSalesforceInputProperties in project components by Talend.

the class SalesforceBulkQueryInputReader method start.

@Override
public boolean start() throws IOException {
    if (bulkRuntime == null) {
        bulkRuntime = new SalesforceBulkRuntime(((SalesforceSource) getCurrentSource()).connect(container).bulkConnection);
        if (((TSalesforceInputProperties) properties).pkChunking.getValue()) {
            bulkRuntime.setChunkProperties((TSalesforceInputProperties) properties);
        }
        bulkRuntime.setSafetySwitch(((TSalesforceInputProperties) properties).safetySwitch.getValue());
        bulkRuntime.setJobTimeout((TSalesforceInputProperties) properties);
    }
    try {
        executeSalesforceBulkQuery();
    } catch (ConnectionException e) {
        // Wrap the exception in an IOException.
        throw new IOException(e);
    }
    return retrieveNextResultSet();
}
Also used : IOException(java.io.IOException) TSalesforceInputProperties(org.talend.components.salesforce.tsalesforceinput.TSalesforceInputProperties) ConnectionException(com.sforce.ws.ConnectionException)

Example 2 with TSalesforceInputProperties

use of org.talend.components.salesforce.tsalesforceinput.TSalesforceInputProperties in project components by Talend.

the class SalesforceBulkQueryInputReader method getModuleName.

private String getModuleName() {
    TSalesforceInputProperties inProperties = (TSalesforceInputProperties) properties;
    if (inProperties.manualQuery.getValue()) {
        SoqlQuery query = SoqlQuery.getInstance();
        query.init(inProperties.query.getValue());
        return query.getDrivingEntityName();
    } else {
        return properties.module.moduleName.getValue();
    }
}
Also used : SoqlQuery(org.talend.components.salesforce.soql.SoqlQuery) TSalesforceInputProperties(org.talend.components.salesforce.tsalesforceinput.TSalesforceInputProperties)

Example 3 with TSalesforceInputProperties

use of org.talend.components.salesforce.tsalesforceinput.TSalesforceInputProperties in project components by Talend.

the class SalesforceSourceOrSinkTestIT method prepareAndGetConnectionHolder.

private void prepareAndGetConnectionHolder(boolean isBulk) throws Exception {
    final SalesforceConnectionProperties connectionProperties = setupProps(null, false);
    connectionProperties.bulkConnection.setValue(isBulk);
    RuntimeContainer container = new DefaultComponentRuntimeContainerImpl() {

        @Override
        public String getCurrentComponentId() {
            return connectionProperties.getName();
        }
    };
    SalesforceSourceOrSink sourceOrSink = new SalesforceSourceOrSink();
    sourceOrSink.initialize(container, connectionProperties);
    // Creating and saving PartnerConnection + BulkConnection(holder) inside container.
    sourceOrSink.validate(container);
    PartnerConnection partnerConnection = (PartnerConnection) container.getComponentData(connectionProperties.getName(), SalesforceSourceOrSink.KEY_CONNECTION);
    TSalesforceInputProperties inputProperties = new TSalesforceInputProperties("input");
    inputProperties.connection.referencedComponent.componentInstanceId.setValue(connectionProperties.getName());
    sourceOrSink.initialize(container, inputProperties);
    ConnectionHolder actualHolder = sourceOrSink.connect(container);
    Assert.assertEquals(partnerConnection, actualHolder.connection);
    if (isBulk) {
        Assert.assertNotNull(actualHolder.bulkConnection);
    } else {
        // Check if bulk connection was not chosen but created.
        Assert.assertNull(actualHolder.bulkConnection);
    }
}
Also used : SalesforceConnectionProperties(org.talend.components.salesforce.SalesforceConnectionProperties) DefaultComponentRuntimeContainerImpl(org.talend.components.api.container.DefaultComponentRuntimeContainerImpl) PartnerConnection(com.sforce.soap.partner.PartnerConnection) TSalesforceInputProperties(org.talend.components.salesforce.tsalesforceinput.TSalesforceInputProperties) RuntimeContainer(org.talend.components.api.container.RuntimeContainer) ConnectionHolder(org.talend.components.salesforce.runtime.common.ConnectionHolder)

Example 4 with TSalesforceInputProperties

use of org.talend.components.salesforce.tsalesforceinput.TSalesforceInputProperties in project components by Talend.

the class SalesforceSessionReuseTestIT method testUseExistingConnection.

@Ignore("Need to solve test failed randomly")
@Test(timeout = 30_000)
public void testUseExistingConnection() throws Throwable {
    File sessionFolder = new File(tempFolder.getRoot().getPath() + "/tsalesforceconnection_1/");
    assertEquals(0, sessionFolder.getTotalSpace());
    LOGGER.debug("session folder: " + sessionFolder.getAbsolutePath());
    SalesforceConnectionProperties connProps = (SalesforceConnectionProperties) getComponentService().getComponentProperties(TSalesforceConnectionDefinition.COMPONENT_NAME);
    setupProps(connProps, !ADD_QUOTES);
    // setup session function
    connProps.reuseSession.setValue(true);
    connProps.sessionDirectory.setValue(sessionFolder.getAbsolutePath());
    final String currentComponentName = TSalesforceConnectionDefinition.COMPONENT_NAME + "_1";
    final java.util.Map<String, Object> globalMap = new java.util.HashMap<String, Object>();
    RuntimeContainer connContainer = new DefaultComponentRuntimeContainerImpl() {

        @Override
        public String getCurrentComponentId() {
            return currentComponentName;
        }

        @Override
        public Object getComponentData(String componentId, String key) {
            return globalMap.get(componentId + "_" + key);
        }

        @Override
        public void setComponentData(String componentId, String key, Object data) {
            globalMap.put(componentId + "_" + key, data);
        }

        @Override
        public Object getGlobalData(String key) {
            return globalMap.get(key);
        }
    };
    // 1. salesforce connection would save the session to a session file
    SalesforceSourceOrSink salesforceSourceOrSink = new SalesforceSourceOrSink();
    salesforceSourceOrSink.initialize(connContainer, connProps);
    assertEquals(ValidationResult.Result.OK, salesforceSourceOrSink.validate(connContainer).getStatus());
    // 2. set a wrong pwd to connection properties
    connProps.userPassword.password.setValue(WRONG_PWD);
    // Input component get connection from the tSalesforceConnection
    TSalesforceInputProperties inProps = (TSalesforceInputProperties) getComponentService().getComponentProperties(TSalesforceInputDefinition.COMPONENT_NAME);
    inProps.connection.referencedComponent.componentInstanceId.setValue(currentComponentName);
    inProps.connection.referencedComponent.setReference(connProps);
    checkAndAfter(inProps.connection.referencedComponent.getReference().getForm(Form.REFERENCE), "referencedComponent", inProps.connection);
    ComponentTestUtils.checkSerialize(inProps, errorCollector);
    assertEquals(2, inProps.getForms().size());
    Form f = inProps.module.getForm(Form.REFERENCE);
    assertTrue(f.getWidget("moduleName").isCallBeforeActivate());
    ComponentProperties moduleProps = (ComponentProperties) f.getProperties();
    try {
        // 3. input components would be get connection from connection session file
        moduleProps = (ComponentProperties) PropertiesTestUtils.checkAndBeforeActivate(getComponentService(), f, "moduleName", moduleProps);
        Object connection = connContainer.getComponentData(currentComponentName, SalesforceSourceOrSink.KEY_CONNECTION);
        assertNotNull(connection);
        ((PartnerConnection) connection).getConfig().setPassword(WRONG_PWD);
        // Check whether the session disable by other test.
        ((PartnerConnection) connection).getUserInfo();
        Property<?> prop = (Property<?>) f.getWidget("moduleName").getContent();
        assertTrue(prop.getPossibleValues().size() > 100);
        LOGGER.debug(moduleProps.getValidationResult().toString());
        assertEquals(ValidationResult.Result.OK, moduleProps.getValidationResult().getStatus());
        invalidSession(connProps, null);
        // This means that the session is disabled by current test
        // 4. invalid the session, then the session should be renew based on reference connection information(wrong pwd)
        // connect would be fail
        moduleProps = (ComponentProperties) PropertiesTestUtils.checkAndBeforeActivate(getComponentService(), f, "moduleName", moduleProps);
        assertEquals(ValidationResult.Result.ERROR, moduleProps.getValidationResult().getStatus());
        LOGGER.debug(moduleProps.getValidationResult().toString());
    } catch (ConnectionException e) {
        // Maybe get exception when same account run in parallel
        // The session maybe disabled by other test
        assertThat(e, instanceOf(LoginFault.class));
        assertEquals(ExceptionCode.INVALID_LOGIN, ((LoginFault) e).getExceptionCode());
        LOGGER.debug("session is disabled by other test!");
    }
    // 5.set correct pwd back
    setupProps(connProps, !ADD_QUOTES);
    moduleProps = (ComponentProperties) PropertiesTestUtils.checkAndBeforeActivate(getComponentService(), f, "moduleName", moduleProps);
    assertEquals(ValidationResult.Result.OK, moduleProps.getValidationResult().getStatus());
    LOGGER.debug(moduleProps.getValidationResult().toString());
}
Also used : ComponentProperties(org.talend.components.api.properties.ComponentProperties) SalesforceConnectionProperties(org.talend.components.salesforce.SalesforceConnectionProperties) DefaultComponentRuntimeContainerImpl(org.talend.components.api.container.DefaultComponentRuntimeContainerImpl) Form(org.talend.daikon.properties.presentation.Form) PartnerConnection(com.sforce.soap.partner.PartnerConnection) LoginFault(com.sforce.soap.partner.fault.LoginFault) TSalesforceInputProperties(org.talend.components.salesforce.tsalesforceinput.TSalesforceInputProperties) File(java.io.File) Property(org.talend.daikon.properties.property.Property) ConnectionException(com.sforce.ws.ConnectionException) RuntimeContainer(org.talend.components.api.container.RuntimeContainer) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 5 with TSalesforceInputProperties

use of org.talend.components.salesforce.tsalesforceinput.TSalesforceInputProperties in project components by Talend.

the class SalesforceSessionReuseTestIT method testBulkSessionRenew.

@Test
public void testBulkSessionRenew() throws Exception {
    // $NON-NLS-1$
    TSalesforceInputProperties props = (TSalesforceInputProperties) new TSalesforceInputProperties("foo").init();
    props.module.moduleName.setValue(EXISTING_MODULE_NAME);
    props.module.main.schema.setValue(getMakeRowSchema(false));
    props.connection = setupProps(null, !ADD_QUOTES);
    // setup session function
    props.connection.bulkConnection.setValue(true);
    props.queryMode.setValue(TSalesforceInputProperties.QueryMode.Bulk);
    props.condition.setValue("Name = '" + randomizedValue + "'");
    // Init session
    assertEquals(ValidationResult.Result.OK, testConnection(props).getStatus());
    BoundedReader<?> reader = createBoundedReader(props);
    assertThat(reader, instanceOf(SalesforceBulkQueryInputReader.class));
    reader.start();
    // Invalid the session by session id
    String sessionIdBeforeRenew = ((SalesforceBulkQueryInputReader) reader).bulkRuntime.getBulkConnection().getConfig().getSessionId();
    reader.close();
    Thread.sleep(1000);
    invalidSession(props.connection, sessionIdBeforeRenew);
    // Test renew session for bulk connections
    try {
        reader.start();
    } catch (IOException io) {
        if (io.getCause() instanceof AsyncApiException && io.getMessage().contains("Unable to find any data to create batch")) {
            // This kind of error shows that connection is established well, but some issue with test data.
            // It happens in SalesforceBulkRuntime inside of method createBatchFromStream, after job was created.
            LOGGER.warn("Issue with getting prepared test data. Error msg - {}", io.getMessage());
        } else {
            throw io;
        }
    }
    // Check the renew session
    String sessionIdAfterRenew = ((SalesforceBulkQueryInputReader) reader).bulkRuntime.getBulkConnection().getConfig().getSessionId();
    reader.close();
    assertNotEquals(sessionIdBeforeRenew, sessionIdAfterRenew);
}
Also used : IOException(java.io.IOException) TSalesforceInputProperties(org.talend.components.salesforce.tsalesforceinput.TSalesforceInputProperties) AsyncApiException(com.sforce.async.AsyncApiException) Test(org.junit.Test)

Aggregations

TSalesforceInputProperties (org.talend.components.salesforce.tsalesforceinput.TSalesforceInputProperties)55 Test (org.junit.Test)32 IndexedRecord (org.apache.avro.generic.IndexedRecord)30 Schema (org.apache.avro.Schema)11 ArrayList (java.util.ArrayList)10 ComponentDefinition (org.talend.components.api.component.ComponentDefinition)10 TSalesforceOutputProperties (org.talend.components.salesforce.tsalesforceoutput.TSalesforceOutputProperties)9 TSalesforceOutputDefinition (org.talend.components.salesforce.tsalesforceoutput.TSalesforceOutputDefinition)7 Result (org.talend.components.api.component.runtime.Result)6 DefaultComponentRuntimeContainerImpl (org.talend.components.api.container.DefaultComponentRuntimeContainerImpl)5 IOException (java.io.IOException)4 SalesforceConnectionProperties (org.talend.components.salesforce.SalesforceConnectionProperties)4 Form (org.talend.daikon.properties.presentation.Form)4 PartnerConnection (com.sforce.soap.partner.PartnerConnection)3 LoginFault (com.sforce.soap.partner.fault.LoginFault)3 File (java.io.File)3 List (java.util.List)3 Ignore (org.junit.Ignore)3 RuntimeContainer (org.talend.components.api.container.RuntimeContainer)3 TSalesforceInputDefinition (org.talend.components.salesforce.tsalesforceinput.TSalesforceInputDefinition)3