Table of Contents

Search

  1. Preface
  2. Introduction to Business Entity Services
  3. Enterprise Java Bean Business Entity Service Calls
  4. Representational State Transfer Business Entity Service Calls
  5. Simple Object Access Protocol Business Entity Service Calls
  6. Services for Cross-reference Records and BVT Calculations
  7. Supporting Corporate Linkage Service
  8. External Calls to Cleanse, Analyze, and Transform Data
  9. Using REST APIs to Add Records
  10. Using REST APIs to Upload Files

Java Code Example with Standard SDO Classes

Java Code Example with Standard SDO Classes

The example shows Java code to run Enterprise Java Bean (EJB) calls based on standard Service Data Objects (SDO) classes.
The example is in the following file in the resource kit:
C:\<
MDM Hub installation directory
>\hub\resourcekit\samples\COS\source\java\com\informatica\mdm\sample\cs\DynamicSDO.java
The following Java code is based on standard SDO classes and runs EJB business entity service calls to create a Person base object record, add multiple child records, delete one child record, and then delete the person record and all child records:
package com.informatica.mdm.sample.cs; import com.informatica.mdm.cs.CallContext; import com.informatica.mdm.cs.api.CompositeServiceException; import com.informatica.mdm.cs.client.CompositeServiceClient; import com.siperian.sif.client.EjbSiperianClient; import com.siperian.sif.client.SiperianClient; import commonj.sdo.DataObject; import commonj.sdo.Property; import commonj.sdo.Type; import commonj.sdo.helper.DataFactory; import commonj.sdo.helper.HelperContext; import java.io.PrintStream; import java.util.Arrays; import java.util.Properties; public class DynamicSDO { public static void main(String[] args) throws CompositeServiceException { if(args.length != 3) { System.err.println("USAGE: DynamicSDO <ors> <user> <pass>"); return; } new DynamicSDO(args[0], args[1], args[2]).execute(); } private String orsId; private String user; private String pass; private HelperContext helperContext; private PrintStream out = System.out; public DynamicSDO(String orsId, String user, String pass) { this.orsId = orsId; this.user = user; this.pass = pass; } public void execute() throws CompositeServiceException { String systemName = "Admin"; Properties config = new Properties(); config.put(SiperianClient.SIPERIANCLIENT_PROTOCOL, EjbSiperianClient.PROTOCOL_NAME); CompositeServiceClient client = CompositeServiceClient.newCompositeServiceClient(config); CallContext callContext = new CallContext(orsId, user, pass); helperContext = client.getHelperContext(callContext); DataFactory dataFactory = helperContext.getDataFactory(); // types for Read requests Type coFilterType = helperContext.getTypeHelper().getType("urn:cs-base.informatica.mdm", "CoFilter"); Type coFilterNodeType = helperContext.getTypeHelper().getType("urn:cs-base.informatica.mdm", "CoFilterNode"); Type keyType = helperContext.getTypeHelper().getType("urn:cs-base.informatica.mdm", "Key"); // ReadCO & WriteCO request types Type readPersonType = helperContext.getTypeHelper().getType("urn:cs-ors.informatica.mdm", "ReadPerson"); Type writePersonType = helperContext.getTypeHelper().getType("urn:cs-ors.informatica.mdm", "WritePerson"); // 1. Create new person DataObject createPerson = dataFactory.create(writePersonType); DataObject createPersonParameters = createPerson.createDataObject("parameters"); createPersonParameters.setString("systemName", systemName); DataObject person = createPerson.createDataObject("object"); person.getChangeSummary().beginLogging(); DataObject personRoot = person.createDataObject("Person"); personRoot.setString("firstName", "John"); personRoot.setString("lastName", "Smith"); person.getChangeSummary().endLogging(); dump("*** CREATE NEW PERSON ...", createPerson); DataObject createPersonResponse = client.process(callContext, createPerson); dump("*** PERSON CREATED:", createPersonResponse); String personRowId = createPersonResponse.getString("object/Person/rowidObject"); DataObject readPerson = dataFactory.create(readPersonType); DataObject readPersonParameters = readPerson.createDataObject("parameters"); DataObject coFilter = readPersonParameters.createDataObject("coFilter"); DataObject coFilterNode = coFilter.createDataObject("object"); coFilterNode.set("name", "Person"); DataObject key = coFilterNode.createDataObject("key"); key.set("rowid", personRowId); dump("*** READ CREATED PERSON...", readPerson); DataObject readPersonResponse = client.process(callContext, readPerson); dump("*** READ RESULT:", readPersonResponse); person = readPersonResponse.getDataObject("object"); person.detach(); person.getChangeSummary().beginLogging(); personRoot = person.getDataObject("Person"); // add new 'one' child DataObject genderCd = personRoot.createDataObject("genderCd"); genderCd.setString("genderCode", "M"); // add two 'many' children DataObject phonePager = personRoot.createDataObject("TelephoneNumbers"); Property item = phonePager.getInstanceProperty("item"); Type phoneType = item.getType(); DataObject phone1 = dataFactory.create(phoneType); phone1.setString("phoneNumber", "111-11-11"); DataObject phone2 = dataFactory.create(phoneType); phone2.setString("phoneNumber", "222-22-22"); phonePager.setList(item, Arrays.asList(phone1, phone2)); person.getChangeSummary().endLogging(); DataObject updatePerson = dataFactory.create(writePersonType); updatePerson.setDataObject("object", person); DataObject updatePersonParameters = updatePerson.createDataObject("parameters"); updatePersonParameters.setString("systemName", systemName); updatePersonParameters.setString("interactionId", ""); dump("*** UPDATE PERSON...", updatePerson); DataObject updatePersonResponse = client.process(callContext, updatePerson); dump("*** PERSON UPDATED:", updatePersonResponse); coFilterNode.set("depth", 3); readPersonParameters.setBoolean("readSystemFields", true); dump("*** READ UPDATED PERSON WITH CHILDREN...", readPerson); readPersonResponse = client.process(callContext, readPerson); dump("*** READ RESULT:", readPersonResponse); person = readPersonResponse.getDataObject("object"); person.detach(); person.getChangeSummary().beginLogging(); genderCd = person.getDataObject("Person").createDataObject("genderCd"); genderCd.setString("genderCode", "F"); // delete one phone DataObject phoneItem = person.getDataObject("Person/TelephoneNumbers/item[1]"); phoneItem.delete(); person.getChangeSummary().endLogging(); DataObject deletePhone = dataFactory.create(writePersonType); deletePhone.setDataObject("object", person); DataObject deletePhoneParameters = deletePhone.createDataObject("parameters"); deletePhoneParameters.setString("systemName", systemName); dump("*** DELETE CHILD...", deletePhone); DataObject deletePhoneResponse = client.process(callContext, deletePhone); dump("*** CHILD DELETED:", deletePhoneResponse); readPersonParameters.setBoolean("readSystemFields", false); dump("*** READ PERSON AFTER CHILD WAS DELETEED...", readPerson); readPersonResponse = client.process(callContext, readPerson); dump("*** READ RESULT:", readPersonResponse); person = readPersonResponse.getDataObject("object"); person.detach(); person.getChangeSummary().beginLogging(); person.getDataObject("Person").detach(); person.getChangeSummary().endLogging(); DataObject deletePerson = dataFactory.create(writePersonType); deletePerson.setDataObject("object", person); DataObject deletePersonParameters = deletePerson.createDataObject("parameters"); deletePersonParameters.setString("systemName", systemName); dump("*** DELETE PERSON...", deletePerson); DataObject deletePersonResponse = client.process(callContext, deletePerson); dump("*** PERSON DELETED:", deletePersonResponse); dump("*** TRY TO READ PERSON AFTER DELETE", readPerson); try { readPersonResponse = client.process(callContext, readPerson); dump("*** READ RESULT:", readPersonResponse); } catch (CompositeServiceException e) { out.println("*** READ RESULT: " + e.getLocalizedMessage()); } } private void dump(String title, DataObject dataObject) { String xml = helperContext.getXMLHelper().save( dataObject, dataObject.getType().getURI(), dataObject.getType().getName()); out.println(title); out.println(xml); out.println(); } }

0 COMMENTS

We’d like to hear from you!