Índice

Search

  1. Prólogo
  2. Introducción a los servicios de entidad de negocio
  3. Llamadas de servicio de entidad de negocio Enterprise Java Bean
  4. Llamadas del servicio de entidad de negocio de transferencia de estado representacional
  5. Llamadas de servicios de entidad de negocio de Protocolo simple de acceso a objetos
  6. Servicios para registros de referencias cruzadas y cálculos de BVT
  7. Compatibilidad del servicio de vinculación empresarial
  8. Llamadas externas para limpiar, analizar y transformar datos
  9. Uso de las API de REST para añadir registros
  10. Uso de las API de REST para cargar archivos

Guía de servicios de entidad de negocio

Guía de servicios de entidad de negocio

Ejemplo de código Java con clases SDO estándares

Ejemplo de código Java con clases SDO estándares

En el ejemplo se muestra el código Java para ejecutar llamadas Enterprise Java Bean (EJB) basadas en las clases de Objeto de servicio de datos (SDO) estándar.
El ejemplo se encuentra en el siguiente archivo del kit de recursos:
C:\<
directorio de instalación de MDM Hub
>\hub\resourcekit\samples\COS\source\java\com\informatica\mdm\sample\cs\DynamicSDO.java
El siguiente código Java se basa en las clases SDO estándar y ejecuta llamadas de servicio de entidad de negocio EJB para crear un registro de objeto base de persona, agregar varios registros secundarios, eliminar un registro secundario y, a continuación, eliminar el registro de persona y todos los registros secundarios:
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(); } }