External Custom Java Automator that Changes the OSM Task Status

A basic external custom Java automator that changes the OSM task status has the following characteristics:

  • The name of the custom automation package. For example:

    package com.mslv.oms.sample.atm_frame;
    
  • Import statements required for this custom automation plug-in. For example:

      import com.mslv.oms.automation.plugin.*;
      import com.mslv.oms.automation.*;
      import java.rmi.*;
    
  • An arbitrary class name that extends AbstractAutomator. For the automation framework to call an external custom Java sender, the plug-in must extend the AbstractAutomator class. This class resides in the com.mslv.automation.plugin package. The name reflects that this example is an external event receiver, receiving information from ASAP. For example:

      public class AsapResponseHandler extends AbstractAutomator {
    
  • The required run method, as dictated by the parent class, AbstractAutomator.

        public void run(String inputXML, AutomationContext task)
                    throws AutomationException {
    
  • Cast the AutomationContext object to the TaskContext object. This example assumes that the custom automation plug-in is triggered by an automated task, so the code is expecting the context input an argument to be an instance of the TaskContext object.

            TaskContext taskContext = (TaskContext)context;
    

    Note:

    You can use the TaskContext object to do many things, such as complete the task, suspend it, and so on. For more information about this class, see the OSM Javadocs.

  • Call a method on the TaskContext object to retrieve the task name.

            String taskName = taskContext.getTaskMnemonic();
    
  • Logs the information regarding the response that the plug-in is handling. AtmFrameCatalogLogger is available to this example plug-in based on the package in which the plug-in resides. You must replace this with your own solution logic.

            AtmFrameCatalogLogger.logTaskEventResponse
              (taskName,tctx.getOrderId(),tctx.getOrderHistoryId(),inputXML);
    

    Note:

    The automation framework keeps track of the order ID and the order history ID of the task that triggered the automation. There are two ways you can get the Order History ID:

    • By parsing the inputXML

    • By calling the TaskContext.getOrderHistoryId method as shown in this example.

    In most cases, these return the same order history ID. However, if you use automation to handle task events, the order history ID obtained from:

    • Parsing the inputXML returns the order history ID as it was when the task was generated

    • Calling the TaskContext.getOrderHistoryID method returns the order history ID as it is now (current)

  • Update the task status by calling a method on the TaskContext object.

            tctx.completeTaskOnExit("activation_successful"); }
    

The following example shows an external custom automator that updates the OSM task status. This example assumes that the automation definition is an external event receiver that is receiving a message from ASAP, and that it is triggered by an automated task.

  package com.mslv.oms.sample.atm_frame;
 
  import com.mslv.oms.automation.plugin.*;
  import com.mslv.oms.automation.*;
  import java.rmi.*;

  public class AsapResponseHandler 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);
        tctx.completeTaskOnExit("activation_successful"); }
      catch(RemoteException ex) {
        throw new AutomationException(ex); }
      catch(AutomationException x) {
        throw x; }
    }
  }