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 Generated SDO Classes

Java Code Example with Generated SDO Classes

The example shows Java code to run Enterprise Java Bean (EJB) calls based on Java classes that the MDM Hub generates based on the business entity and business entity services configuration.
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\GeneratedSDO.java
The following Java code is based on generated 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.informatica.mdm.sdo.cs.base.CoFilter; import com.informatica.mdm.sdo.cs.base.CoFilterNode; import com.informatica.mdm.sdo.cs.base.Key; import com.siperian.sif.client.EjbSiperianClient; import com.siperian.sif.client.SiperianClient; import commonj.sdo.DataObject; import commonj.sdo.helper.DataFactory; import commonj.sdo.helper.HelperContext; import mdm.informatica.co_ors.*; import mdm.informatica.cs_ors.*; import java.io.PrintStream; import java.util.Arrays; import java.util.Properties; public class GeneratedSDO { public static void main(String[] args) throws CompositeServiceException { if(args.length != 3) { System.err.println("USAGE: GeneratedSDO <ors> <user> <pass>"); return; } new GeneratedSDO(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 GeneratedSDO(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(); // 1. Create new person WritePerson createPerson = (WritePerson)dataFactory.create(WritePerson.class); WritePersonParameters createPersonParameters = (WritePersonParameters)dataFactory.create(WritePersonParameters.class); createPersonParameters.setSystemName(systemName); createPerson.setParameters(createPersonParameters); Person person = (Person)dataFactory.create(Person.class); createPerson.setObject(person); person.getChangeSummary().beginLogging(); PersonRoot personRoot = (PersonRoot)dataFactory.create(PersonRoot.class); personRoot.setFirstName("John"); personRoot.setLastName("Smith"); person.setPerson(personRoot); person.getChangeSummary().endLogging(); dump("*** CREATE NEW PERSON ...", createPerson); WritePersonReturn createPersonResponse = (WritePersonReturn)client.process(callContext, (DataObject)createPerson); dump("*** PERSON CREATED:", createPersonResponse); String personRowId = createPersonResponse.getObject().getPerson().getRowidObject(); Key key = (Key)dataFactory.create(Key.class); key.setRowid(personRowId); CoFilterNode coFilterNode = (CoFilterNode)dataFactory.create(CoFilterNode.class); coFilterNode.setName(Person.class.getSimpleName()); coFilterNode.setKey(key); CoFilter coFilter = (CoFilter)dataFactory.create(CoFilter.class); coFilter.setObject(coFilterNode); ReadPersonParameters readPersonParameters = (ReadPersonParameters)dataFactory.create(ReadPersonParameters.class); readPersonParameters.setCoFilter(coFilter); ReadPerson readPerson = (ReadPerson)dataFactory.create(ReadPerson.class); readPerson.setParameters(readPersonParameters); dump("*** READ CREATED PERSON...", readPerson); ReadPersonReturn readPersonResponse = (ReadPersonReturn)client.process(callContext, (DataObject)readPerson); dump("*** READ RESULT:", readPersonResponse); person = readPersonResponse.getObject(); ((DataObject)person).detach(); person.getChangeSummary().beginLogging(); personRoot = person.getPerson(); // add new 'one' child LUGenderLookup genderCd = (LUGenderLookup)dataFactory.create(LUGenderLookup.class); genderCd.setGenderCode("M"); personRoot.setGenderCd(genderCd); // add two 'many' children PersonTelephoneNumbersPager phonePager = (PersonTelephoneNumbersPager)dataFactory.create(PersonTelephoneNumbersPager.class); PersonTelephoneNumbers phone1 = (PersonTelephoneNumbers)dataFactory.create(PersonTelephoneNumbers.class); phone1.setPhoneNumber("111-11-11"); PersonTelephoneNumbers phone2 = (PersonTelephoneNumbers)dataFactory.create(PersonTelephoneNumbers.class); phone2.setPhoneNumber("222-22-22"); phonePager.setItem(Arrays.asList(phone1, phone2)); personRoot.setTelephoneNumbers(phonePager); person.getChangeSummary().endLogging(); WritePerson updatePerson = (WritePerson)dataFactory.create(WritePerson.class); updatePerson.setObject(person); WritePersonParameters updatePersonParameters = (WritePersonParameters)dataFactory.create(WritePersonParameters.class); updatePersonParameters.setSystemName(systemName); updatePersonParameters.setInteractionId(""); updatePerson.setParameters(updatePersonParameters); dump("*** UPDATE PERSON...", updatePerson); WritePersonReturn updatePersonResponse = (WritePersonReturn)client.process(callContext, (DataObject)updatePerson); dump("*** PERSON UPDATED:", updatePersonResponse); coFilterNode.setDepth(3); readPersonParameters.setReadSystemFields(true); dump("*** READ UPDATED PERSON WITH CHILDREN (with system fields)...", readPerson); readPersonResponse = (ReadPersonReturn)client.process(callContext, (DataObject)readPerson); dump("*** READ RESULT:", readPersonResponse); person = readPersonResponse.getObject(); ((DataObject)person).detach(); person.getChangeSummary().beginLogging(); // delete one phone person.getPerson().getTelephoneNumbers().getItem().remove(0); // change gender genderCd = (LUGenderLookup)dataFactory.create(LUGenderLookup.class); genderCd.setGenderCode("F"); personRoot.setGenderCd(genderCd); person.getChangeSummary().endLogging(); WritePerson deletePhone = (WritePerson)dataFactory.create(WritePerson.class); deletePhone.setObject(person); WritePersonParameters deletePhoneParameters = (WritePersonParameters)dataFactory.create(WritePersonParameters.class); deletePhoneParameters.setSystemName(systemName); deletePhone.setParameters(deletePhoneParameters); dump("*** DELETE CHILD...", deletePhone); WritePersonReturn deletePhoneResponse = (WritePersonReturn)client.process(callContext, (DataObject)deletePhone); dump("*** CHILD DELETED:", deletePhoneResponse); readPersonParameters.setReadSystemFields(false); dump("*** READ PERSON AFTER CHILD WAS DELETEED...", readPerson); readPersonResponse = (ReadPersonReturn)client.process(callContext, (DataObject)readPerson); dump("*** READ RESULT:", readPersonResponse); person = readPersonResponse.getObject(); ((DataObject)person).detach(); person.getChangeSummary().beginLogging(); ((DataObject)person.getPerson()).delete(); person.getChangeSummary().endLogging(); WritePerson deletePerson = (WritePerson)dataFactory.create(WritePerson.class); deletePerson.setObject(person); WritePersonParameters deletePersonParameters = (WritePersonParameters)dataFactory.create(WritePersonParameters.class); deletePersonParameters.setSystemName(systemName); deletePerson.setParameters(deletePersonParameters); dump("*** DELETE PERSON...", deletePerson); WritePersonReturn deletePersonResponse = (WritePersonReturn)client.process(callContext, (DataObject)deletePerson); dump("*** PERSON DELETED:", deletePersonResponse); dump("*** TRY TO READ PERSON AFTER DELETE", readPerson); try { readPersonResponse = (ReadPersonReturn)client.process(callContext, (DataObject)readPerson); dump("*** READ RESULT:", readPersonResponse); } catch (CompositeServiceException e) { out.println("*** READ RESULT: " + e.getLocalizedMessage()); } } private void dump(String title, Object object) { DataObject dataObject = (DataObject)object; 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!