7 Replies Latest reply: Aug 10, 2012 8:52 AM by Lucas Andres Muñoz RSS

    Language to be used for automation plugins

    rickyp
      Hi,
      I want to ask regarding the language that we shuld use for automation plugins. Should we go for Xquery, XSLT or JAVA? Whata are the different factors to make a decision?
      Also, is there any preference between Xquery and xslt?

      Thanks.
        • 1. Re: Language to be used for automation plugins
          Lucas Andres Muñoz
          Hello rickyp ,

          I would like to recomend Xquery, in my actual project use this language as the prefered, it is because we found a lot of diferences while we were trying to write any especific automation plugin, for example to send a message or to execute any update in the order, the other reason is that we found a lot of examples in the solution PIP, there are a lot of examples in Xquery,
          and it was sufficient to deciede that Xquery and Xpath is the best choice, however, we found problems to send an e-mail, so we decide to do that in a JAVA Custom Atomation Plugin.

          Best Regards.

          Lucas
          • 2. Re: Language to be used for automation plugins
            954665
            Hi Lucas,

            Could you please give me a simple xquery automator external event receiver code which picks message posted by a internal xquery sender and updates a task.
            • 3. Re: Language to be used for automation plugins
              Lucas Andres Muñoz
              declare namespace oms="urn:com:metasolv:oms:xmlapi:1";
              declare namespace automator = "java:oracle.communications.ordermanagement.automation.plugin.ScriptReceiverContextInvocation";
              declare namespace context = "java:com.mslv.oms.automation.TaskContext";

              (:this namespace must be the same of the expected answer:)
              declare namespace nsrp="http://www.example.co/example";
              declare namespace log = "java:com.mslv.oms.logging.Log4JLogger";
              declare namespace saxon="http://saxon.sf.net/";
              declare namespace xsl="http://www.w3.org/1999/XSL/Transform";

              declare option saxon:output "method=xml";
              declare option saxon:output "saxon:indent-spaces=4";

              (: Declarar variables :)
              declare variable $automator external;
              declare variable $context external;
              declare variable $log external;

              (:Answer must be the Initial Node of the answer XML below you can see the example of a possible answer:)
              let $responseAct := fn:root()/nsrp:Answer

              let $taskDataOrder := fn:root(automator:getOrderAsDOM($automator))/oms:GetOrder.Response

              let $result := if(fn:exists($responseAct//nsrp:ResponseCode/text()) and ($responseAct//nsrp:ResponseCode/text() != 'ok')) then
                                       ('nook')
                                       else ('ok')
                        
              let $answer := <AnswerSOM>
                                                 <Result>{$result}</Result>
                                                 <ResultDescription>{$responseAct//nsrp:TranslatedResponseDescription/text()}</ResultDescription>
                                                 <ErrorCode>{$responseAct//nsrp:CodeResponse/text()}</ErrorCode>
                                                 <ErrorDescription>{$responseAct//nsrp:TranslatedResponse/text()}</ErrorDescription>
                                                 <ErrorReason>{$responseAct//nsrp:PlataformMessage/text()}</ErrorReason>
                                                 {
                                                      $responseAct//nsrp:InformacionAdicional                    
                                                 }
                                       </AnswerSOM>
                                            
              let $updateMessage := <OrderDataUpdate xmlns="http://www.metasolv.com/OMS/OrderDataUpdate/2002/10/25">
                                                                {
                                                                $answer                              
                                                                }
                                                           </OrderDataUpdate>

              let $updateMessageString := saxon:serialize($updateMessage, <xsl:output method='xml' omit-xml-declaration='yes' indent='yes' saxon:indent-spaces='4'/>)

              return
              (
                   log:info($log,fn:concat('XML UPTADE ORDER___: ',$updateMessageString)),
                   automator:setUpdateOrder($automator,'true'),
                   if (exists($result)) then (
                        context:completeTaskOnExit($context, 'Succes')
                   ) else (
                        context:completeTaskOnExit($context, 'Failed')
                   ),
                   $updateMessage
              )

              ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

              The next XML is a possible answer for this Xquery, if the correlation Id of the message in the queue is the same that the automator external is expecting to receive.

              <Answer xmlns="http://www.example.co/example" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
                   <Activation>
                        <ResponseCode>ok</ResponseCode>
                        <PlataformMessage>text</PlataformMessage>
                        <TranslatedResponseDescription>text</TranslatedResponseDescription>
                   </Activation>
              </Answer>


              Best Regards

              Lucas Andrés Muñoz Henao
              • 4. Re: Language to be used for automation plugins
                Viktor.Jarolim-Oracle
                Hi Ricky I agree I feel xquery is more powerful and also easier to use then xslt.
                regards
                Viktor
                • 5. Re: Language to be used for automation plugins
                  954665
                  hi Lucas,

                  Thanx for the help but I am quite an amateur in osm,that z why I could not follow the automator's code,I have written a simple xquery sender code that simply posts a message,prior to that I have done xslt sender and receiver,in which msg was posted in request queue...then that xml was put in the response queue and correlation ID was set,aftr the msg was consumed data got updated.I hope the same procedure applicable to Xquery too.

                  the code for sender internal i am using is

                  declare namespace saxon="http://saxon.sf.net/";
                  declare namespace xsl="http://www.w3.org/1999/XSL/Transform";
                  declare namespace fo="http://www.w3.org/1999/XSL/Format";
                  (: OSM namespaces :)
                  declare namespace oms="urn:com:metasolv:oms:xmlapi:1";

                  (: JAVA APIs namespaces :)
                  declare namespace UUID = "java:java.util.UUID";
                  declare namespace osmError = "java:com.mslv.oms.automation.OMSErrorCodes";
                  declare namespace dateUtil = "java:oracle.communications.ordermanagement.util.date.DateUtil";
                  declare namespace outboundMessage = "java:javax.jms.TextMessage";
                  declare namespace log = "java:org.apache.commons.logging.Log";

                  declare option saxon:output "method=xml";
                  declare option saxon:output "saxon:indent-spaces=4";

                  declare variable $automator external;
                  declare variable $context external;
                  declare variable $outboundMessage external;
                  declare variable $log external;
                  declare variable $exitStatus := "success";
                  let $taskData := fn:root(.)/oms:GetOrder.Response
                  let $logActiviyAndTaskTransition :=
                  <Answer>
                  <Activation>
                  <test>
                  {let $ownerData := $taskData/oms:_root/oms:Activation/oms:test/text()(:taking value from creation task:)
                     return $ownerData
                     }
                  </test>
                  <myval>xyz</myval>
                  </Activation>
                  </Answer>
                  return
                  $logActiviyAndTaskTransition ,
                  context:completeTaskOnExit($context, $exitStatus)


                  if possible please guide me the changes that needs to be done in the automator external so that xyz gets updated in myval,which i have left blank in creation task.

                  Regards

                  Shiya
                  • 6. Re: Language to be used for automation plugins
                    882807
                    Hi Shiya,

                    Your XQuery code for XQuerySender-InternalReceiver is fine.

                    Inorder to handle the response xml using XQueryAutomator ExternalReciever you can refer the below XQuery code. Below UpdateOrderRequest would be an example for you inroder to update the xyz value in Myval Tag. So locate MyVal Tag from _root in the TaskData/OrderTemplate inorder to update.

                    (: XQuery main module :)
                    declare namespace ord = "http://xmlns.oracle.com/communications/inventory/webservice/order";
                    declare namespace com = "http://xmlns.oracle.com/communications/inventory/webservice/common";
                    declare namespace faul="http://xmlns.oracle.com/communications/inventory/webservice/fault";
                    declare namespace soapenv="http://schemas.xmlsoap.org/soap/envelope/";
                    declare namespace oms="urn:com:metasolv:oms:xmlapi:1";
                    declare namespace context = "java:com.mslv.oms.automation.TaskContext";
                    declare namespace saxon= "http://saxon.sf.net/" ;
                    declare namespace xsl="http://www.w3.org/1999/XSL/Transform";
                    declare namespace java="http://xml.apache.org/xslt/java";
                    declare namespace log = "java:org.apache.commons.logging.Log";
                    declare namespace orderActivity = "java:oracle.communications.ordermanagement.log.LogOrderActivity";
                    (: only require to be declared when editing with Oxygen :)
                    declare namespace automator = "java:oracle.communications.ordermanagement.automation.plugin.ScriptReceiverContextInvocation";
                    (: only require to be declared when editing with Oxygen :)
                    declare namespace osmError = "java:com.mslv.oms.automation.OMSErrorCodes";
                    declare namespace autoContext = "java:com.mslv.oms.automation.OrderContextImpl";


                    declare option saxon:output "method=xml";
                    declare option saxon:output "saxon:indent-spaces=4";


                    declare variable $automator external;
                    declare variable $context external;
                    declare variable $log external;
                    declare variable $autoContext external;


                    declare variable $status as xs:string+ := ("success","failure");

                    let $taskExitStatus := if(fn:root(.)//ord:createOrderResponse)
                    then $status[1]
                    else $status[2]

                    let $errorMessage := if(fn:root(.)//faul:inventoryFault)
                    then substring-after(fn:root(.)//faul:inventoryFault/errorMessages/text(),'::')
                    else fn:root(.)//ord:createOrderResponse/com:messages/text()

                    let $orderId := if(fn:root(.)//ord:createOrderResponse)
                                        then substring-before(fn:root(.)//ord:createOrderResponse/orderKey/text(), '_')
                                        else substring-before(fn:root(.)//faul:inventoryFault/errorMessages/text(), '_')


                    let $updateOrderRequest :=
                    <UpdateOrder.Request xmlns="urn:com:metasolv:oms:xmlapi:1">
                    <OrderID>{$orderId}</OrderID>
                    <View>CheckInventory</View>
                    <UpdatedNodes>
                    <_root>
                    <Failure>
                    <UIMStatusMessage>{$errorMessage}</UIMStatusMessage>
                    </Failure>
                    </_root>
                    </UpdatedNodes>
                    </UpdateOrder.Request>
                    return
                    (
                    log:info($log,"UIM Automation Task is completed"),$updateOrderRequest,context:completeTaskOnExit($context, $taskExitStatus)
                    )

                    Edited by: NJabade on Aug 9, 2012 11:23 PM
                    • 7. Re: Language to be used for automation plugins
                      Lucas Andres Muñoz
                      Hi Shiya

                      declare namespace oms="urn:com:metasolv:oms:xmlapi:1";
                      declare namespace automator = "java:oracle.communications.ordermanagement.automation.plugin.ScriptReceiverContextInvocation";
                      declare namespace context = "java:com.mslv.oms.automation.TaskContext";

                      (:this namespace must be the same of the expected answer:)
                      declare namespace nsrp="http://www.example.co/example";
                      declare namespace log = "java:com.mslv.oms.logging.Log4JLogger";
                      declare namespace saxon="http://saxon.sf.net/";
                      declare namespace xsl="http://www.w3.org/1999/XSL/Transform";

                      declare option saxon:output "method=xml";
                      declare option saxon:output "saxon:indent-spaces=4";

                      (: Declarar variables :)
                      declare variable $automator external;
                      declare variable $context external;
                      declare variable $log external;

                      (:Answer must be the Initial Node of the answer XML below you can see the example of a possible answer:)
                      let $responseAct := fn:root()/nsrp:Answer

                      let $taskDataOrder := fn:root(automator:getOrderAsDOM($automator))/oms:GetOrder.Response

                      (:This catch the value of myval if exists in the answer:)
                      let $result := if(fn:exists($responseAct//nsrp:myval/text())) then
                      ($responseAct//nsrp:myval/text())
                      else ('not_myval_node_found')

                      (:If I undestand you Activation is in root of the taskData of the order and myval is child node of Activation like below:)
                      let $answer := <Activation>
                      <myval>{$result}</myval>
                      </Activation>

                      let $updateMessage := <OrderDataUpdate xmlns="http://www.metasolv.com/OMS/OrderDataUpdate/2002/10/25">
                      {
                      $answer
                      }
                      </OrderDataUpdate>

                      let $updateMessageString := saxon:serialize($updateMessage, <xsl:output method='xml' omit-xml-declaration='yes' indent='yes' saxon:indent-spaces='4'/>)

                      return
                      (
                      log:info($log,fn:concat('XML UPTADE ORDER___: ',$updateMessageString)),
                      automator:setUpdateOrder($automator,'true'),
                      if (exists($result)) then (
                      context:completeTaskOnExit($context, 'Succes')
                      ) else (
                      context:completeTaskOnExit($context, 'Failed')
                      ),
                      $updateMessage
                      )

                      //////////////////////////////////////////////////////////////////////////////////////////
                      another thing that I would change in your xquery sender, is to define some namespace for the xml like below:

                      let $logActiviyAndTaskTransition :=

                      <Answer xmlns="http://www.example.co/example">
                      <Activation>
                      <test>
                      {let $ownerData := $taskData/oms:_root/oms:Activation/oms:test/text()(:taking value from creation task:)
                      return $ownerData
                      }
                      </test>
                      <myval>xyz</myval>
                      </Activation>
                      </Answer>

                      Best Regards.