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