External Custom Java Automator that Updates Order Data

If an automated task sends data to an external system and the external system sends a response back, you may need to update OSM with the data received from the external system.

The following example shows how to update data in OSM. The code is an example of updating OSM with data received from Oracle Communications Unified Inventory Management (UIM) when calling the server extension FRDemo.AssignFacilities.

  package com.mslv.oms.sample.atm_frame;

  import com.mslv.oms.automation.plugin.*;
  import com.mslv.oms.automation.*;
  import java.rmi.*;
  import java.util.*;
  import java.io.*;
  import java.net.*;
  import org.xml.sax.*;
  import org.w3c.dom.*;
  import javax.xml.parsers.*;

  public class UIMResponseHandler extends AbstractAutomator {
  
    public void run( String inputXML, AutomationContext task)
                throws AutomationException {
      try {
        TaskContext tctx = (TaskContext)task;
        String taskName = tctx.getTaskMnemonic();
        AtmFrameCatalogLogger.logTaskEventResponse
          (taskName,tctx.getOrderId(),tctx.getOrderHistoryId(),inputXML);
 
        // Using the data returned from UIM, update the OSM order data
        String updateXml = generateOMSUpdateString(inputXML);
        tctx.updateOrderData(updateXml);

        // Complete the OSM task with the correct status
        tctx.completeTaskOnExit( "success" ); }

      catch(OrderUpdateException ex) {
        throw new AutomationException( ex ); }
      catch(RemoteException ex) {
        throw new AutomationException( ex ); }
     catch(AutomationException x ) {
       throw x; }
    }

    static private String generateOMSUpdateString(String inputXML) {
      StringBuffer osmUpdate = new StringBuffer("");
      try {
        osmUpdate = new StringBuffer
         ("<OrderDataUpdate xmlns=\"http://www.w3.org/2001/XMLSchema\""+
          " xmlns:xs=\"http://www.w3.org/2001/XMLSchema\"" +
          " xmlns:odu=\"http://www.oracle.com/OMS/OrderDataUpdate\"" +
          " targetNameSpace=\"http://www.oracle.com/OMS/OrderDataUpdate\">");
 
        // Use updates from UIM to update OSM
        osmUpdate.append("<AddMandatory>true</AddMandatory>");
        DocumentBuilderFactory docBuilderFactory =
          DocumentBuilderFactory.newInstance();
        DocumentBuilder parser = docBuilderFactory.newDocumentBuilder();
        Document doc = parser.parse(new StringBufferInputStream(inputXML));
        Element root = doc.getDocumentElement();
        root.normalize();
        NodeList a_site_list = root.getElementsByTagName("a_site information");
        NodeList a_site_data = a_site_list.item(0).getChildNodes();

        for(int i=0;i<a_site_data.getLength();i++) {
          Element e = (Element)a_site_data.item(i);
          osmUpdate.append("<Add path=\"/a_site_information/");
          osmUpdate.append(e.getTagName());
          osmUpdate.append("\">");
          osmUpdate.append(e.getFirstChild().getNodeValue());
          osmUpdate.append("</Add>"); 
        }

        NodeList z_site_list = root.getElementsByTagName("z_site_information");
        NodeList z_site_data = z_site_list.item(0).getChildNodes();

        for(int i=0;i<a_site_data.getLength();i++) {
          Element e = (Element)a_site_data.item(i);
          osmUpdate.append("<Add path=\"/z_site_information/");
          osmUpdate.append(e.getTagName());
          osmUpdate.append("\">");
          osmUpdate.append(e.getFirstChild().getNodeValue());
          osmUpdate.append("</Add>");
        }

        osmUpdate.append("</OrderDataUpdate>");

        System.out.println(omsUpdate.toString()); }

    catch(Exception e) {
      System.out.println(e.getMessage()); }
 
    return omsUpdate.toString();
    }
  }

The following code snippets from this example show:

  • How to display where OSM data is updated, using XML input to describe which data nodes to update.

            tctx.updateOrderData(updateXml);
    
  • How to build the OrderDataUpdate XML string to update the data in OSM using data garnered by parsing the UIM XML. See "Using OrderDataUpdate Elements to Pass Order Modification Data" for more information. This differs for every order template and every external system. This code represents the translation step where you convert the data from the format of an external system to the format that OSM expects.

        static private String generateOMSUpdateString(String inputXML) {
          StringBuffer osmUpdate = new StringBuffer("");
          try {
            osmUpdate = new StringBuffer
             ("<OrderDataUpdate xmlns=\"http://www.w3.org/2001/XMLSchema\""+
              " xmlns:xs=\"http://www.w3.org/2001/XMLSchema\"" +
              " xmlns:odu=\"http://www.oracle.com/OMS/OrderDataUpdate\"" +
              " targetNameSpace=\"http://www.oracle.com/OMS/OrderDataUpdate\">");
     
            // Use updates from UIM to update OSM
            osmUpdate.append("<AddMandatory>true</AddMandatory>");
            DocumentBuilderFactory docBuilderFactory =
              DocumentBuilderFactory.newInstance();
            DocumentBuilder parser = docBuilderFactory.newDocumentBuilder();
            Document doc = parser.parse(new StringBufferInputStream(inputXML));
            Element root = doc.getDocumentElement();
            root.normalize();
            NodeList a_site_list = root.getElementsByTagName("a_site information");
            NodeList a_site_data = a_site_list.item(0).getChildNodes();
    
            for(int i=0;i<a_site_data.getLength();i++) {
              Element e = (Element)a_site_data.item(i);
              osmUpdate.append("<Add path=\"/a_site_information/");
              osmUpdate.append(e.getTagName());
              osmUpdate.append("\">");
              osmUpdate.append(e.getFirstChild().getNodeValue());
              osmUpdate.append("</Add>"); 
            }
    
            NodeList z_site_list = root.getElementsByTagName("z_site_information");
            NodeList z_site_data = z_site_list.item(0).getChildNodes();
    
            for(int i=0;i<a_site_data.getLength();i++) {
              Element e = (Element)a_site_data.item(i);
              osmUpdate.append("<Add path=\"/z_site_information/");
              osmUpdate.append(e.getTagName());
              osmUpdate.append("\">");
              osmUpdate.append(e.getFirstChild().getNodeValue());
              osmUpdate.append("</Add>");
            }
    
            osmUpdate.append("</OrderDataUpdate>");
    
            System.out.println(omsUpdate.toString()); }
    
        catch(Exception e) {
          System.out.println(e.getMessage()); }
     
        return omsUpdate.toString();
        }
    

    The structure of the XML document to update OSM data is as follows:

    <OrderDataUpdate xmlns=\"http://www.w3.org/2001/XMLSchema\"
    xmlns:xs=\"http://www.w3.org/2001/XMLSchema\"
    xmlns:odu=\"http://www.oracle.com/OMS/OrderDataUpdate\"
    targetNameSpace=\"http://www.oracle.com/OMS/OrderDataUpdate\">
    <AddMandatory>true</AddMandatory>
    <Add path=\"/service_details/new_number\">98765</Add>
    <Update path=\"/customer_details/service_address/street\">55 Updated St</Update>
    <Delete path=\"/service_details/current_account_number\"></Delete>
    </OrderDataUpdate>
    

    This example illustrates adding a data node (Add path), updating a data node (Update path), and deleting a data node (Delete path).

  • How to specify a mandatory parameter. If set to true, the following rules apply:

            osmUpdate.append("<AddMandatory>true</AddMandatory>");
    
    • If you delete a mandatory node, AddMandatory replaces the node and populates it with the default value.

    • If the update is missing a mandatory node, AddMandatory adds the missing node and populates it with the default value.

      Note:

      If you add a mandatory field, but do not include a value, AddMandatory will not add a default value and the request will generate an error-error code 200.