use of com.sforce.ws.bind.XmlObject in project pentaho-kettle by pentaho.
the class SalesforceConnectionTest method testMessageElements.
@Test
public void testMessageElements() throws Exception {
XmlObject me = SalesforceConnection.fromTemplateElement("myName", 123, false);
assertNotNull(me);
assertEquals("myName", me.getName().getLocalPart());
assertNull(me.getValue());
me = null;
me = SalesforceConnection.fromTemplateElement("myName", 123, true);
assertNotNull(me);
assertEquals("myName", me.getName().getLocalPart());
assertEquals(123, me.getValue());
me = null;
me = SalesforceConnection.createMessageElement("myName", 123, false);
assertNotNull(me);
assertEquals("myName", me.getName().getLocalPart());
assertEquals(123, me.getValue());
me = null;
try {
me = SalesforceConnection.createMessageElement("myName", 123, true);
fail();
} catch (Exception expected) {
// Ignore, name was expected to have a colon ':'
}
me = null;
try {
me = SalesforceConnection.createMessageElement("myType:Name", "123", true);
assertNotNull(me);
assertEquals("Name", me.getName().getLocalPart());
assertEquals("myType", me.getField("type"));
assertEquals("123", me.getField("Name"));
} catch (Exception expected) {
fail();
}
me = null;
try {
me = SalesforceConnection.createMessageElement("myType:Name/MyLookupField", 123, true);
assertNotNull(me);
assertEquals("MyLookupField", me.getName().getLocalPart());
// assertEquals( "myType", me.getField( "type" ) );
assertEquals(123, me.getField("Name"));
} catch (Exception expected) {
fail();
}
}
use of com.sforce.ws.bind.XmlObject in project pentaho-kettle by pentaho.
the class SalesforceConnection method getMessageElementForHierarchy.
/**
* Drill down the SObject hierarchy based on the given field hierarchy until either null or the correct MessageElement
* is found
*/
private XmlObject getMessageElementForHierarchy(SObject con, String[] fieldHierarchy) {
final int lastIndex = fieldHierarchy.length - 1;
SObject currentSObject = con;
for (int index = 0; index <= lastIndex; index++) {
for (XmlObject element : getChildren(currentSObject)) {
if (element.getName().getLocalPart().equals(fieldHierarchy[index])) {
if (index == lastIndex) {
return element;
} else {
if (element instanceof SObject) {
// Found the next level, keep going
currentSObject = (SObject) element;
}
break;
}
}
}
}
return null;
}
use of com.sforce.ws.bind.XmlObject in project pentaho-kettle by pentaho.
the class SalesforceConnection method createForeignKeyElement.
private static XmlObject createForeignKeyElement(String type, String lookupField, String extIdName, Object extIdValue) throws Exception {
// Foreign key relationship to the object
XmlObject me = fromTemplateElement(lookupField, null, false);
me.addField("type", type);
me.addField(extIdName, extIdValue);
return me;
}
use of com.sforce.ws.bind.XmlObject in project pentaho-kettle by pentaho.
the class SalesforceConnection method createMessageElement.
public static XmlObject createMessageElement(String name, Object value, boolean useExternalKey) throws Exception {
XmlObject me = null;
if (useExternalKey) {
// We use an external key
// the structure should be like this :
// object:externalId/lookupField
// where
// object is the type of the object
// externalId is the name of the field in the object to resolve the value
// lookupField is the name of the field in the current object to update (is the "__r" version)
int indexOfType = name.indexOf(":");
if (indexOfType > 0) {
String type = name.substring(0, indexOfType);
String extIdName = null;
String lookupField = null;
String rest = name.substring(indexOfType + 1, name.length());
int indexOfExtId = rest.indexOf("/");
if (indexOfExtId > 0) {
extIdName = rest.substring(0, indexOfExtId);
lookupField = rest.substring(indexOfExtId + 1, rest.length());
} else {
extIdName = rest;
lookupField = extIdName;
}
me = createForeignKeyElement(type, lookupField, extIdName, value);
} else {
throw new KettleException(BaseMessages.getString(PKG, "SalesforceConnection.UnableToFindObjectType"));
}
} else {
me = fromTemplateElement(name, value, true);
}
return me;
}
use of com.sforce.ws.bind.XmlObject in project pentaho-kettle by pentaho.
the class SalesforceConnection method getChildren.
public static XmlObject[] getChildren(SObject object) {
List<String> reservedFieldNames = Arrays.asList("type", "fieldsToNull");
if (object == null) {
return null;
}
List<XmlObject> children = new ArrayList<>();
Iterator<XmlObject> iterator = object.getChildren();
while (iterator.hasNext()) {
XmlObject child = iterator.next();
if (child.getName().getNamespaceURI().equals(Constants.PARTNER_SOBJECT_NS) && reservedFieldNames.contains(child.getName().getLocalPart())) {
continue;
}
children.add(child);
}
if (children.size() == 0) {
return null;
}
return children.toArray(new XmlObject[children.size()]);
}
Aggregations