Author: shawkins
Date: 2012-03-28 11:25:43 -0400 (Wed, 28 Mar 2012)
New Revision: 3954
Added:
branches/7.7.x/connectors/connector-salesforce/src/test/java/org/
branches/7.7.x/connectors/connector-salesforce/src/test/java/org/teiid/
branches/7.7.x/connectors/connector-salesforce/src/test/java/org/teiid/resource/
branches/7.7.x/connectors/connector-salesforce/src/test/java/org/teiid/resource/adapter/
branches/7.7.x/connectors/connector-salesforce/src/test/java/org/teiid/resource/adapter/salesforce/
branches/7.7.x/connectors/connector-salesforce/src/test/java/org/teiid/resource/adapter/salesforce/TestSalesforceConnectionImpl.java
Modified:
branches/7.7.x/connectors/connector-salesforce/src/main/java/org/teiid/resource/adapter/salesforce/SalesforceConnectionImpl.java
branches/7.7.x/connectors/translator-salesforce/src/main/java/org/teiid/translator/salesforce/execution/GetDeletedExecutionImpl.java
branches/7.7.x/connectors/translator-salesforce/src/main/java/org/teiid/translator/salesforce/execution/GetUpdatedExecutionImpl.java
branches/7.7.x/connectors/translator-salesforce/src/main/java/org/teiid/translator/salesforce/execution/ProcedureExecutionParentImpl.java
Log:
TEIID-1978 correcting getDeleted and returned datetime/timestamp values
Modified:
branches/7.7.x/connectors/connector-salesforce/src/main/java/org/teiid/resource/adapter/salesforce/SalesforceConnectionImpl.java
===================================================================
---
branches/7.7.x/connectors/connector-salesforce/src/main/java/org/teiid/resource/adapter/salesforce/SalesforceConnectionImpl.java 2012-03-24
14:27:37 UTC (rev 3953)
+++
branches/7.7.x/connectors/connector-salesforce/src/main/java/org/teiid/resource/adapter/salesforce/SalesforceConnectionImpl.java 2012-03-28
15:25:43 UTC (rev 3954)
@@ -45,88 +45,85 @@
import com.sforce.soap.partner.sobject.SObject;
public class SalesforceConnectionImpl extends BasicConnection implements
SalesforceConnection {
- private SforceService sfService;
private Soap sfSoap;
- private SessionHeader sh;
- private CallOptions co;
- private SalesForceManagedConnectionFactory mcf;
private ObjectFactory partnerFactory = new ObjectFactory();
PackageVersionHeader pvHeader = partnerFactory.createPackageVersionHeader();
public SalesforceConnectionImpl(String username, String password, URL url,
SalesForceManagedConnectionFactory mcf) throws ResourceException {
- this.mcf = mcf;
- login(username, password, url);
+ login(username, password, url, mcf);
}
+ protected SalesforceConnectionImpl(Soap soap) {
+ this.sfSoap = soap;
+ }
+
String getUserName() throws ResourceException {
- try {
- return sfSoap.getUserInfo().getUserName();
- } catch (com.sforce.soap.partner.UnexpectedErrorFault e) {
- throw new ResourceException(e);
- }
+ try {
+ return sfSoap.getUserInfo().getUserName();
+ } catch (com.sforce.soap.partner.UnexpectedErrorFault e) {
+ throw new ResourceException(e);
+ }
}
Soap getBinding() {
return sfSoap;
}
- private void login(String username, String password, URL url) throws ResourceException
{
- if (!isValid()) {
- LoginResult loginResult = null;
- sfSoap = null;
- sfService = null;
- co = new CallOptions();
- // This value identifies Teiid as a SF certified solution.
- // It was provided by SF and should not be changed.
- co.setClient("RedHat/MetaMatrix/"); //$NON-NLS-1$
-
- if(url == null) {
- throw new ResourceException("SalesForce URL is not specified, please provide a
valid URL"); //$NON-NLS-1$
- }
+ private void login(String username, String password, URL url,
SalesForceManagedConnectionFactory mcf) throws ResourceException {
+ LoginResult loginResult = null;
+ SforceService sfService = null;
+ SessionHeader sh = null;
+ CallOptions co = new CallOptions();
+ // This value identifies Teiid as a SF certified solution.
+ // It was provided by SF and should not be changed.
+ co.setClient("RedHat/MetaMatrix/"); //$NON-NLS-1$
+
+ if(url == null) {
+ throw new ResourceException("SalesForce URL is not specified, please provide a
valid URL"); //$NON-NLS-1$
+ }
- Bus bus = BusFactory.getThreadDefaultBus();
- BusFactory.setThreadDefaultBus(mcf.getBus());
- try {
- sfService = new SforceService();
- sh = new SessionHeader();
-
- // Session Id must be passed in soapHeader - add the handler
- sfService.setHandlerResolver(new SalesforceHandlerResolver(sh));
-
- sfSoap = sfService.getSoap();
- ((BindingProvider)sfSoap).getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY,
url.toExternalForm());
- loginResult = sfSoap.login(username, password);
-
- // Set the SessionId after login, for subsequent calls
- sh.setSessionId(loginResult.getSessionId());
- } catch (LoginFault e) {
- throw new ResourceException(e);
- } catch (InvalidIdFault e) {
- throw new ResourceException(e);
- } catch (com.sforce.soap.partner.UnexpectedErrorFault e) {
- throw new ResourceException(e);
- } finally {
- BusFactory.setThreadDefaultBus(bus);
- }
- LogManager.logTrace(LogConstants.CTX_CONNECTOR, "Login was successful for
username " + username); //$NON-NLS-1$
-
- // Reset the SOAP endpoint to the returned server URL
- ((BindingProvider)sfSoap).getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY,loginResult.getServerUrl());
- // or maybe org.apache.cxf.message.Message.ENDPOINT_ADDRESS
- ((BindingProvider)sfSoap).getRequestContext().put(BindingProvider.SESSION_MAINTAIN_PROPERTY,Boolean.TRUE);
- // Set the timeout.
- //((BindingProvider)sfSoap).getRequestContext().put(JAXWSProperties.CONNECT_TIMEOUT,
timeout);
-
+ Bus bus = BusFactory.getThreadDefaultBus();
+ BusFactory.setThreadDefaultBus(mcf.getBus());
+ try {
+ sfService = new SforceService();
+ sh = new SessionHeader();
- // Test the connection.
- try {
- sfSoap.getUserInfo();
- } catch (com.sforce.soap.partner.UnexpectedErrorFault e) {
- throw new ResourceException(e);
- }
+ // Session Id must be passed in soapHeader - add the handler
+ sfService.setHandlerResolver(new SalesforceHandlerResolver(sh));
+
+ sfSoap = sfService.getSoap();
+ ((BindingProvider)sfSoap).getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY,
url.toExternalForm());
+ loginResult = sfSoap.login(username, password);
+
+ // Set the SessionId after login, for subsequent calls
+ sh.setSessionId(loginResult.getSessionId());
+ } catch (LoginFault e) {
+ throw new ResourceException(e);
+ } catch (InvalidIdFault e) {
+ throw new ResourceException(e);
+ } catch (com.sforce.soap.partner.UnexpectedErrorFault e) {
+ throw new ResourceException(e);
+ } finally {
+ BusFactory.setThreadDefaultBus(bus);
}
+ LogManager.logTrace(LogConstants.CTX_CONNECTOR, "Login was successful for username
" + username); //$NON-NLS-1$
+
+ // Reset the SOAP endpoint to the returned server URL
+ ((BindingProvider)sfSoap).getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY,loginResult.getServerUrl());
+ // or maybe org.apache.cxf.message.Message.ENDPOINT_ADDRESS
+ ((BindingProvider)sfSoap).getRequestContext().put(BindingProvider.SESSION_MAINTAIN_PROPERTY,Boolean.TRUE);
+ // Set the timeout.
+ //((BindingProvider)sfSoap).getRequestContext().put(JAXWSProperties.CONNECT_TIMEOUT,
timeout);
+
+
+ // Test the connection.
+ try {
+ sfSoap.getUserInfo();
+ } catch (com.sforce.soap.partner.UnexpectedErrorFault e) {
+ throw new ResourceException(e);
+ }
}
@@ -313,12 +310,11 @@
result.setEarliestDateAvailable(deleted.getEarliestDateAvailable().toGregorianCalendar());
List<DeletedRecord> records = deleted.getDeletedRecords();
List<DeletedObject> resultRecords = new ArrayList<DeletedObject>();
- DeletedObject object;
- if(null !=records) {
- for (DeletedObject record : resultRecords) {
- object = new DeletedObject();
- object.setID(record.getID());
- object.setDeletedDate(record.getDeletedDate());
+ if(records != null) {
+ for (DeletedRecord record : records) {
+ DeletedObject object = new DeletedObject();
+ object.setID(record.getId());
+ object.setDeletedDate(record.getDeletedDate().toGregorianCalendar());
resultRecords.add(object);
}
}
Added:
branches/7.7.x/connectors/connector-salesforce/src/test/java/org/teiid/resource/adapter/salesforce/TestSalesforceConnectionImpl.java
===================================================================
---
branches/7.7.x/connectors/connector-salesforce/src/test/java/org/teiid/resource/adapter/salesforce/TestSalesforceConnectionImpl.java
(rev 0)
+++
branches/7.7.x/connectors/connector-salesforce/src/test/java/org/teiid/resource/adapter/salesforce/TestSalesforceConnectionImpl.java 2012-03-28
15:25:43 UTC (rev 3954)
@@ -0,0 +1,57 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
+package org.teiid.resource.adapter.salesforce;
+
+import static org.junit.Assert.*;
+
+import javax.xml.datatype.DatatypeFactory;
+import javax.xml.datatype.XMLGregorianCalendar;
+
+import org.junit.Test;
+import org.mockito.Mockito;
+import org.teiid.translator.salesforce.execution.DeletedResult;
+
+import com.sforce.soap.partner.DeletedRecord;
+import com.sforce.soap.partner.GetDeletedResult;
+import com.sforce.soap.partner.Soap;
+
+@SuppressWarnings("nls")
+public class TestSalesforceConnectionImpl {
+
+ @Test public void testGetDeleted() throws Exception {
+ Soap soap = Mockito.mock(Soap.class);
+ GetDeletedResult gdr = new GetDeletedResult();
+ XMLGregorianCalendar c = DatatypeFactory.newInstance().newXMLGregorianCalendar();
+ gdr.setEarliestDateAvailable(c);
+ gdr.setLatestDateCovered(c);
+ DeletedRecord dr = new DeletedRecord();
+ dr.setDeletedDate(c);
+ dr.setId("id");
+ gdr.getDeletedRecords().add(dr);
+ Mockito.stub(soap.getDeleted("x", null, null)).toReturn(gdr);
+ SalesforceConnectionImpl sfci = new SalesforceConnectionImpl(soap);
+ DeletedResult result = sfci.getDeleted("x", null, null);
+ assertEquals(1, result.getResultRecords().size());
+ }
+
+}
Property changes on:
branches/7.7.x/connectors/connector-salesforce/src/test/java/org/teiid/resource/adapter/salesforce/TestSalesforceConnectionImpl.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Modified:
branches/7.7.x/connectors/translator-salesforce/src/main/java/org/teiid/translator/salesforce/execution/GetDeletedExecutionImpl.java
===================================================================
---
branches/7.7.x/connectors/translator-salesforce/src/main/java/org/teiid/translator/salesforce/execution/GetDeletedExecutionImpl.java 2012-03-24
14:27:37 UTC (rev 3953)
+++
branches/7.7.x/connectors/translator-salesforce/src/main/java/org/teiid/translator/salesforce/execution/GetDeletedExecutionImpl.java 2012-03-28
15:25:43 UTC (rev 3954)
@@ -50,9 +50,6 @@
public class GetDeletedExecutionImpl implements SalesforceProcedureExecution {
- private static final int EARLIESTDATEAVAILABLE = 4;
- private static final int RESULT = 5;
-
private ProcedureExecutionParent parent;
private DeletedResult deletedResult;
@@ -108,23 +105,21 @@
}
}
- @SuppressWarnings("unchecked")
@Override
public List<?> getOutputParameterValues() {
- List result = new ArrayList();
- result.add(deletedResult.getLatestDateCovered());
- result.add(deletedResult.getEarliestDateAvailable());
+ List<Timestamp> result = new ArrayList<Timestamp>();
+ result.add(new Timestamp(deletedResult.getLatestDateCovered().getTimeInMillis()));
+ result.add(new Timestamp(deletedResult.getEarliestDateAvailable().getTimeInMillis()));
return result;
}
- @SuppressWarnings("unchecked")
@Override
public List<?> next() {
- List result = null;
+ List<Object> result = null;
if(deletedResult.getResultRecords() != null && resultIndex <
deletedResult.getResultRecords().size()){
- result = new ArrayList(2);
+ result = new ArrayList<Object>(2);
result.add(deletedResult.getResultRecords().get(resultIndex).getID());
- result.add(deletedResult.getResultRecords().get(resultIndex).getDeletedDate());
+ result.add(new
Timestamp(deletedResult.getResultRecords().get(resultIndex).getDeletedDate().getTimeInMillis()));
resultIndex++;
}
return result;
Modified:
branches/7.7.x/connectors/translator-salesforce/src/main/java/org/teiid/translator/salesforce/execution/GetUpdatedExecutionImpl.java
===================================================================
---
branches/7.7.x/connectors/translator-salesforce/src/main/java/org/teiid/translator/salesforce/execution/GetUpdatedExecutionImpl.java 2012-03-24
14:27:37 UTC (rev 3953)
+++
branches/7.7.x/connectors/translator-salesforce/src/main/java/org/teiid/translator/salesforce/execution/GetUpdatedExecutionImpl.java 2012-03-28
15:25:43 UTC (rev 3954)
@@ -24,7 +24,6 @@
import java.sql.Timestamp;
import java.util.ArrayList;
-import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.List;
@@ -50,8 +49,6 @@
public class GetUpdatedExecutionImpl implements SalesforceProcedureExecution {
- private static final int RESULT = 4;
-
private ProcedureExecutionParent parent;
private UpdatedResult updatedResult;
private int idIndex = 0;
@@ -105,18 +102,17 @@
}
@Override
- public List<Calendar> getOutputParameterValues() {
- List<Calendar> result = new ArrayList<Calendar>(1);
- result.add(updatedResult.getLatestDateCovered());
+ public List<Timestamp> getOutputParameterValues() {
+ List<Timestamp> result = new ArrayList<Timestamp>(1);
+ result.add(new Timestamp(updatedResult.getLatestDateCovered().getTimeInMillis()));
return result;
}
- @SuppressWarnings("unchecked")
@Override
- public List next() {
- List result = null;
+ public List<?> next() {
+ List<Object> result = null;
if(updatedResult.getIDs() != null && idIndex <
updatedResult.getIDs().size()){
- result = new ArrayList(1);
+ result = new ArrayList<Object>(1);
result.add(updatedResult.getIDs().get(idIndex));
idIndex++;
}
Modified:
branches/7.7.x/connectors/translator-salesforce/src/main/java/org/teiid/translator/salesforce/execution/ProcedureExecutionParentImpl.java
===================================================================
---
branches/7.7.x/connectors/translator-salesforce/src/main/java/org/teiid/translator/salesforce/execution/ProcedureExecutionParentImpl.java 2012-03-24
14:27:37 UTC (rev 3953)
+++
branches/7.7.x/connectors/translator-salesforce/src/main/java/org/teiid/translator/salesforce/execution/ProcedureExecutionParentImpl.java 2012-03-28
15:25:43 UTC (rev 3954)
@@ -26,15 +26,17 @@
import org.teiid.language.Call;
import org.teiid.metadata.RuntimeMetadata;
-import org.teiid.translator.TranslatorException;
import org.teiid.translator.DataNotAvailableException;
import org.teiid.translator.ExecutionContext;
import org.teiid.translator.ProcedureExecution;
+import org.teiid.translator.TranslatorException;
import org.teiid.translator.salesforce.SalesforceConnection;
public class ProcedureExecutionParentImpl implements ProcedureExecution,
ProcedureExecutionParent {
+ public static final String GET_DELETED = "GetDeleted"; //$NON-NLS-1$
+ public static final String GET_UPDATED = "GetUpdated"; //$NON-NLS-1$
private Call command;
private ExecutionContext executionContext;
private RuntimeMetadata metadata;
@@ -75,9 +77,9 @@
if (name == null) {
name = getCommand().getProcedureName();
}
- if("GetUpdated".equalsIgnoreCase(name)) { //$NON-NLS-1$
+ if(GET_UPDATED.equalsIgnoreCase(name)) {
execution = new GetUpdatedExecutionImpl(this);
- } else if("GetDeleted".equalsIgnoreCase(name)) { //$NON-NLS-1$
+ } else if(GET_DELETED.equalsIgnoreCase(name)) {
execution = new GetDeletedExecutionImpl(this);
} else {
throw new AssertionError("Unknown procedure " +
getCommand().getProcedureName() + " with name in source " +
getCommand().getMetadataObject().getNameInSource()); //$NON-NLS-1$ //$NON-NLS-2$