SI_Examples

Sterling Integrator examples like bpml, user exits, java code, extended rules codes, XSLT or any other type of code used in SI.
Mirjana's picture

User Exit - DB Interface

1.   Java Code for User Exit

 

package com.mirjana.userexit;

 

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

 

import com.sterlingcommerce.woodstock.translator.util.JDBCService;

 public class DBInterface {

     

      Connection con = null;
      PreparedStatement stm = null;
      ResultSet res = null;
      String result=null;

            public Connection getConnection(String poolName)

      {

            try

            {    
                  Connection con=JDBCService.getConnection(poolName);
                  return con;
            }

            catch (Exception e)

            {
                  e.printStackTrace();
                  return null;
            }

      }

      public PreparedStatement getPreparedStatement(String SQLstatement, Connection con) {

            try{

                  stm = con.prepareStatement(SQLstatement);

                  return stm;

            } catch (Exception e)

            {
                  e.printStackTrace();
                  return null;
            }

      }

      public ResultSet getResultSet(PreparedStatement stm) {

            try{
                  res = stm.executeQuery();
                  return res;

            } catch (Exception e)

            {
                  e.printStackTrace();
                  return null;
            }

      }

      public int getRowCount(ResultSet res, String SQLstatement)

          {

              int i = 0;
              try {
                 
                  stm = con.prepareStatement(SQLstatement);
                  res = stm.executeQuery();
                  res.next();
                  i = res.getInt("CNT");
                  return i;
                   

              } catch (Exception ex){

                  ex.printStackTrace();
                  return i;
              }

       }

      public void executeNext(ResultSet res)

      {

           
        try {
           
            res.next();
           
        } catch (Exception ex){ 
            ex.printStackTrace();
        }

     }

public String getData(ResultSet res, String columnName)

      {
      try {                        
                //res.next();       
                result = res.getString(columnName);            
        } catch (Exception ex){ 
            ex.printStackTrace();
        }

        return result;

      }

      public void closePreparedStatement(PreparedStatement stm) {

            try{
                  stm.close();
            } catch (Exception ex) {

                  ex.printStackTrace();

            }

      }

      public void closeResultSet(ResultSet res) {

           

            try{
                  res.close();
                 
            } catch (Exception ex) {
                  ex.printStackTrace();
            }

        }

            public void closeConnection(Connection con)

      {
            try
            {
                  if (con != null && !con.isClosed())
                  {
                        con.close();
                  }
            }
            catch (Exception e)
            {
                  e.printStackTrace();
            }
      }

            public void freeConn(String poolName,Connection con)

            {
                  try
                  {
                        if (con != null && !con.isClosed())
                        {
                              //con.close();
                              JDBCService.freeConnection(poolName,con);
                        }
                  }
                  catch (Exception e)
                  {
                        e.printStackTrace();
                  }
      }
}

 2.   Pre-Session extended rule

object jdbc_object, connection;

string[100] poolName, table, column, sql_string;

integer i;

object stm, res;

 

sql_string = "select BUILD_NUMBER, PRODUCT_LABEL from si_version where PRODUCT_LABEL = 'SI'";

// Conn object for obtaining connection

jdbc_object = new("com.mirjana.userexit.DBInterface");

connection = jdbc_object.getConnection("mysqlPool");

i = 1;

 3.   Extended rule in field level

string[255] sql_result_pl, sql_result_bn, pl, bn;

sql_result_pl = "a";

sql_result_bn = "b";

 

pl = "PRODUCT_LABEL";

bn = "BUILD_NUMBER";

 

stm = jdbc_object.getPreparedStatement(sql_string,connection);

res = jdbc_object.getResultSet(stm);

jdbc_object.executeNext(res);

sql_result_pl = jdbc_object.getData(res, pl);

sql_result_bn = jdbc_object.getData(res, bn);

 

#product_label = sql_result_pl;

#build_number = sql_result_bn;

 4.   Post-Session extended rule

jdbc_connection.freeConnection(connection) ;

Mirjana's picture

XSLT - use params and combine Primary Document and Process Data

Use param in XSLT – combine Primary Document and Process Data
 
Task:
·         Element in XML input should be referenced by counter, where XML input is in Primary Document and counter is in Process Data
·         HouseBill value from Reference/@Type attribute should be taken from the Primary Document and placed into REF_INFO in Process Data.
Value taken must be taken from specific position that is defined in counter element (RefTypeMarker element in Process Data).
Solution:
DocToDOM function, used in Assign element, can use Primary Document only and cannot reference counter from Process Data to use as predicate in XPath statement.
XSLT can be used where Primary Document will be source and Process Data element can be passed as parameter in additional_xslt_params
 
Input data:
<?xml version="1.0" encoding="UTF-8"?>
<ShipmentStatusMessage>
         <ShipmentStatuses>
                   <ShipmentStatus>
                            <ShipmentId>SORD0013714</ShipmentId>
                            <ShipmentReferences>
                                      <Reference Type="HouseBill">ORD0013714</Reference>
                                      <Reference Type="OrderReference">0493694</Reference>
                            </ShipmentReferences>
                            <StatusDetails>
                                      <Status>
                                               <EventCode>DLV</EventCode>
                                               <EventDescription>Delivered</EventDescription>
                                               <StatusDate>2013-03-18T00:00:00</StatusDate>
                                               <Comments>
                                                        <Line1/>
                                               </Comments>
                                      </Status>
                            </StatusDetails>
                   </ShipmentStatus>
         </ShipmentStatuses>
</ShipmentStatusMessage>
 

XSLT:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
         <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
         <xsl:param name="RefTypeMarkerParam"/>
         <xsl:template match="/">
                   <xsl:element name="REF_TYPE">
                            <xsl:value-of select="//*[local-name()='ShipmentReferences']//*[local-name()='Reference'][number($RefTypeMarkerParam)]/@Type"/>
                   </xsl:element>
         </xsl:template>
</xsl:stylesheet>
 
BPML:
<process name="default">
         <sequence name="startSeq">
                   <assign name="Assign" to="RefTypeMarker">1</assign>
                   <operation name="XSLT Service">
                            <participant name="XSLTService"/>
                            <output message="XSLTServiceTypeInputMessage">
                                      <assign to="." from="*"/>
                                      <assign to="additional_xslt_params" from="concat(’RefTypeMarkerParam=’,RefTypeMarker/text())"/>
                                      <assign to="xml_input_from">PrimaryDoc</assign>
                                      <assign to="xslt_name">xsltName</assign>
                            </output>
                            <input message="inmsg">
                                      <assign to="." from="DocToDOM(PrimaryDocument)"/>
                            </input>
                   </operation>
         </sequence>
</process>
 
Process Data (before XSLT):
 <?xml version="1.0" encoding="UTF-8"?>
<ProcessData>
         <PrimaryDocument SCIObjectID="VM-integrator:node1:13e36e50a02:14163"/>
         <RefTypeMarker>1</RefTypeMarker>
</ProcessData>
 

Process Data (after XSLT):

<?xml version="1.0" encoding="UTF-8"?>

<ProcessData>
         <PrimaryDocument SCIObjectID="VM-integrator:node1:13e36e50a02:14163"/>
         <RefTypeMarker>1</RefTypeMarker>
         <REF_TYPE>HouseBill</REF_TYPE>
</ProcessData>
 


 

 

Mirjana's picture

SFTP - looping through the list of files

1. Get the list of the files from SFTP – loop through them with counter

SFTP LIST – SFTP GET every file by name … any task you can add after get

  • Business Process


  • BPML Code
<process name="default">
          <rule name="moreFiles">
                    <condition>count(Files/File) &gt;= number(counter/text())</condition>
          </rule>
          <sequence name="main">
                    <operation name="SFTP Client Begin Session Service">
                              <participant name="SFTPClientBeginSession"/>
                              <output message="SFTPClientBeginSessionServiceTypeInputMessage">
                                        <assign to="." from="*"/>
                                        <assign to="KnownHostKeyId">VM-integrator:node1:13bfa51ac2e:60584</assign>
                                        <assign to="RemoteHost">vm-integrator</assign>
                                        <assign to="RemotePasswd">password</assign>
                                        <assign to="RemotePort">19039</assign>
                                        <assign to="RemoteUserId">admin</assign>
                                        <assign to="SFTPClientAdapter">SFTPClientAdapter</assign>
                              </output>
                              <input message="inmsg">
                                        <assign to="." from="*"/>
                              </input>
                    </operation>
                    <operation name="SFTP Client LIST Service">
                              <participant name="SFTPClientList"/>
                              <output message="SFTPClientListServiceTypeInputMessage">
                                        <assign to="." from="*"/>
                                        <assign to="SessionToken" from="SessionToken/text()"/>
                              </output>
                              <input message="inmsg">
                                        <assign to="." from="*"/>
                              </input>
                    </operation>
                    <assign to="counter">1</assign>
                    <sequence name="loopStart">
                              <choice>
                                        <select>
                                                  <case ref="moreFiles" activity="choiceStart"/>
                                        </select>
                                        <sequence name="choiceStart">
                                                  <sequence name="taskStart">
                                                            <operation name="SFTP Client GET Service">
                                                                      <participant name="SFTPClientGet"/>
                                                                      <output message="SFTPClientGetServiceTypeInputMessage">
                                                                                <assign to="." from="*"/>
                                                                                <assign to="RemoteFileName" from="Files/File[number(../../counter/text())]/Name/text()"/>
                                                                                <assign to="SessionToken" from="SessionToken/text()"/>
                                                                      </output>
                                                                      <input message="inmsg">
                                                                                <assign to="." from="*"/>
                                                                      </input>
                                                            </operation>
                                                            <assign to="counter" from="counter + 1"/>
                                                  </sequence>
                                                  <repeat ref="loopStart"/>
                                        </sequence>
                              </choice>
                    </sequence>
                    <operation name="SFTP Client End Session Service">
                              <participant name="SFTPClientEndSession"/>
                              <output message="SFTPClientEndSessionServiceTypeInputMessage">
                                        <assign to="." from="*"/>
                                        <assign to="SessionToken" from="SessionToken/text()"/>
                              </output>
                              <input message="inmsg">
                                        <assign to="." from="*"/>
                              </input>
                    </operation>
          </sequence>
</process>

 

2. Get the list of the files from SFTP – taking always the first one and release it after that

  •  Business Process

 

  • BPML Code
<process name="default">
          <rule name="moreFiles">
                    <condition>count(Files/File) &gt; 0</condition>
          </rule>
          <sequence name="main">
                    <operation name="SFTP Client Begin Session Service">
                              <participant name="SFTPClientBeginSession"/>
                              <output message="SFTPClientBeginSessionServiceTypeInputMessage">
                                        <assign to="." from="*"/>
                                        <assign to="KnownHostKeyId">VM-integrator:node1:13bfa51ac2e:60584</assign>
                                        <assign to="RemoteHost">vm-integrator</assign>
                                        <assign to="RemotePasswd">password</assign>
                                        <assign to="RemotePort">19039</assign>
                                        <assign to="RemoteUserId">admin</assign>
                                        <assign to="SFTPClientAdapter">SFTPClientAdapter</assign>
                              </output>
                              <input message="inmsg">
                                        <assign to="." from="*"/>
                              </input>
                    </operation>
                    <operation name="SFTP Client LIST Service">
                              <participant name="SFTPClientList"/>
                              <output message="SFTPClientListServiceTypeInputMessage">
                                        <assign to="." from="*"/>
                                        <assign to="SessionToken" from="SessionToken/text()"/>
                              </output>
                              <input message="inmsg">
                                        <assign to="." from="*"/>
                              </input>
                    </operation>
                    <sequence name="loopStart">
                              <choice>
                                        <select>
                                                  <case ref="moreFiles" activity="choiceStart"/>
                                        </select>
                                        <sequence name="choiceStart">
                                                  <sequence name="taskStart">
                                                            <operation name="SFTP Client GET Service">
                                                                      <participant name="SFTPClientGet"/>
                                                                      <output message="SFTPClientGetServiceTypeInputMessage">
                                                                                <assign to="." from="*"/>
                                                                                <assign to="RemoteFileName" from="Files/File[1]/Name/text()"/>
                                                                                <assign to="SessionToken" from="SessionToken/text()"/>
                                                                      </output>
                                                                      <input message="inmsg">
                                                                                <assign to="." from="*"/>
                                                                      </input>
                                                            </operation>
                                                            <operation name="Release Service">
                                                                      <participant name="ReleaseService"/>
                                                                      <output message="ReleaseServiceTypeInputMessage">
                                                                                <assign to="." from="*"/>
                                                                                <assign to="TARGET">Files/File[1]</assign>
                                                                      </output>
                                                                      <input message="inmsg">
                                                                                <assign to="." from="*"/>
                                                                      </input>
                                                            </operation>
                                                  </sequence>
                                                  <repeat ref="loopStart"/>
                                        </sequence>
                              </choice>
                    </sequence>
                    <operation name="SFTP Client End Session Service">
                              <participant name="SFTPClientEndSession"/>
                              <output message="SFTPClientEndSessionServiceTypeInputMessage">
                                        <assign to="." from="*"/>
                                        <assign to="SessionToken" from="SessionToken/text()"/>
                              </output>
                              <input message="inmsg">
                                        <assign to="." from="*"/>
                              </input>
                    </operation>
          </sequence>
</process>

 If you add Mailbox Add service after SFTP GET, or maybe SFTP /FTP PUT, you should release Primary Document and DocumentId:

<operation name="Release Service">
          <participant name="ReleaseService"/>
          <output message="ReleaseServiceTypeInputMessage">
                    <assign to="." from="*"/>
                    <assign to="TARGET">PrimaryDocument | DocumentId</assign>
          </output>
          <input message="inmsg">
                    <assign to="." from="*"/>
          </input>
</operation>

 

 

Mirjana's picture

WS - SOAP Response Validation

SOAP Response – validation against XML schema

1.    SOAP Response should be:

<bookstore>
          <book>
                    <title>Harry Potter</title>
                    <author>J K. Rowling</author>
                    <year>2005</year>
                    <price>29.99</price>
          </book>
          <book>
                    <title>Learning XML</title>
                    <author>Erik T. Ray</author>
                    <year>2003</year>
                    <price>39.95</price>
          </book>
</bookstore>
  • Here is one similar XML with namespaces:
<m:bookstore xmlns:m="http://www.webservice.pull_fileOut">
          <m:book>
                    <m:title>Harry Potter</m:title>
                    <m:author>J K. Rowling</m:author>
                    <m:year>2005</m:year>
                    <m:price>29.99</m:price>
          </m:book>
          <m:book>
                    <m:title>Learning XML</m:title>
                    <m:author>Erik T. Ray</m:author>
                    <m:year>2003</m:year>
                    <m:price>39.95</m:price>
          </m:book>
</m:bookstore>
 
2.    XML Schema that describes this response is:
 
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:m="http://www.webservice.pull_fileOut" xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.webservice.pull_fileOut" elementFormDefault="qualified" attributeFormDefault="unqualified">
          <xs:element name="bookstore">
                    <xs:complexType>
                              <xs:sequence>
                                        <xs:element ref="m:book" maxOccurs="unbounded"/>
                              </xs:sequence>
                    </xs:complexType>
          </xs:element>
          <xs:element name="book">
                    <xs:complexType>
                              <xs:sequence>
                                        <xs:element ref="m:title"/>
                                        <xs:element ref="m:author"/>
                                        <xs:element ref="m:year"/>
                                        <xs:element ref="m:price"/>
                              </xs:sequence>
                    </xs:complexType>
          </xs:element>
          <xs:element name="title">
                    <xs:simpleType>
                              <xs:restriction base="xs:string"/>
                    </xs:simpleType>
          </xs:element>
          <xs:element name="author">
                    <xs:simpleType>
                              <xs:restriction base="xs:string"/>
                    </xs:simpleType>
          </xs:element>
          <xs:element name="year">
                    <xs:simpleType>
                              <xs:restriction base="xs:string"/>
                    </xs:simpleType>
          </xs:element>
          <xs:element name="price">
                    <xs:simpleType>
                              <xs:restriction base="xs:string"/>
                    </xs:simpleType>
          </xs:element>
</xs:schema>

 3.    Namespace added in namespace.properties file

m = http://www.webservice.pull_fileOut

4.    Process Data with response prepared for returning back to client:

.....
.....
<WebservicesResponseNode>
    <m:bookstore xmlns:m="http://www.webservice.pull_fileOut">
      <m:book>
        <m:title>Harry Potter</m:title>
        <m:author>J K. Rowling</m:author>
        <m:year>2005</m:year>
        <m:price>29.99</m:price>
      </m:book>
      <m:book>
        <m:title>Learning XML</m:title>
        <m:author>Erik T. Ray</m:author>
        <m:year>2003</m:year>
        <m:price>39.95</m:price>
      </m:book>
    </m:bookstore>
  </WebservicesResponseNode>
</ProcessData>

5.    SOAP Response

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
          <soapenv:Body>
                    <m:bookstore xmlns:m="http://www.webservice.pull_fileOut">
                              <m:book>
                                        <m:title>Harry Potter</m:title>
                                        <m:author>J K. Rowling</m:author>
                                        <m:year>2005</m:year>
                                        <m:price>29.99</m:price>
                              </m:book>
                              <m:book>
                                        <m:title>Learning XML</m:title>
                                        <m:author>Erik T. Ray</m:author>
                                        <m:year>2003</m:year>
                                        <m:price>39.95</m:price>
                              </m:book>
                    </m:bookstore>
          </soapenv:Body>
</soapenv:Envelope>
Mirjana's picture

Root element add in the Primary Document

There are 3 ways to add a root element in XML structure.
1.   Add a root element in the Primary Document by XSLT
 
·         Input document:
 
<?xml version="1.0" encoding="UTF-8"?>
<AAA>
            <BBB></BBB>
</AAA>
 
·         XSLT:
 
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
            <xsl:output method="xml" indent="yes"/>
            <xsl:template match="/">
                        <xsl:element name="ZZZ">
                                   <xsl:copy-of select="*"/>
                        </xsl:element>
            </xsl:template>
</xsl:stylesheet>
 
 
·         BPML:
 
<process name="addRoot">
            <sequence>
                        <operation name="XSLT Service">
                                   <participant name="XSLTService"/>
                                   <output message="XSLTServiceTypeInputMessage">
                                               <assign to="." from="*"/>
                                               <assign to="xslt_name">addRoot</assign>
                                               <assign to="xml_input_from">PrimaryDoc</assign>
                                   </output>
                                   <input message="inmsg">
                                               <assign to="." from="*"/>
                                   </input>
                        </operation>
            </sequence>
</process>
 
 
·         Output document:
 
<?xml version="1.0" encoding="UTF-8"?>
<ZZZ>
      <AAA>
            <BBB>
            </BBB>
      </AAA>
</ZZZ>
 
2.   Add a root element in the Primary Document by Batch Service
 
·         Input Document:
<AAA>
<BBB>
</BBB>
</AAA>
 
·         BPML:
<process name="default">
            <sequence>
                        <assign to="prefix_root">&lt;ZZZ&gt;</assign>
                        <assign to="suffix_root">&lt;/ZZZ&gt;</assign>
                        <operation name="BatchProcessor">
                                   <participant name="BatchProcessorService"/>
                                   <output message="BatchProcessorInputMessage">
                                               <assign to="." from="*"/>
                                               <assign to="suffix_document">PrimaryDocument</assign>
                                               <assign to="use_xml">false</assign>
                                               <assign to="prefix_document">prefix_root</assign>
                                   </output>
                                   <input message="inmsg">
                                               <assign to="." from="*"/>
                                   </input>
                        </operation>
                        <operation name="BatchProcessor">
                                   <participant name="BatchProcessorService"/>
                                   <output message="BatchProcessorInputMessage">
                                               <assign to="." from="*"/>
                                               <assign to="suffix_document">suffix_root</assign>
                                               <assign to="use_xml">false</assign>
                                               <assign to="prefix_document">PrimaryDocument</assign>
                                   </output>
                                   <input message="inmsg">
                                               <assign to="." from="*"/>
                                   </input>
                        </operation>
            </sequence>
</process>
 

·         Output document:

 
<ZZZ>
            <AAA>
                        <BBB>
</BBB>
</AAA>
</ZZZ>
 
3.   Add a root element by Translation Map
We can create a simple map, positional to positional, with only one record and one field inside the record, in the input side.
Output side can have only one record.
No direct links!
 
·         INPUT (root ) element, extended rule, OnBegin:
 
writeblock("<ZZZ>");
 
·         Extended rule on field level in the input side:
 
string[255] buffer;
while readblock(buffer) do writeblock(buffer);
 
·         INPUT (root ) element, extended rule, OnEnd:
 
writeblock("</ZZZ>");
 

 

Mirjana's picture

Web Extension - example for a simple web application

Overview of little  test web application

 

This is an example of simple web application, by using Web Extension option in IBM Sterling Integrator. JSP technology is used for web application development.

Sterling Integrator contains JSP tag library that is a collection of predefined JSP components that you can use in your JSP Web templates.


You can use JSP tag libraries to:


• Reduce manual coding efforts of your JSP Web templates

• Reduce the amount of Java code in your JSP Web templates

 

Web application contains:

 

-         login page,

-         first page after login is one simple page with 2 text boxes, where you can write some values just to demonstrate how they will be transferred to a BP, into Process Data as well as Primary Document. These values are not used in BP in this example, but can be if you want. Submitting this page will open jsp2.jsp

-         jsp2.jsp will show you the list of all the users from SI database

-         and finally, by clicking on link of a user, you will get audit details or changes that user done in SI, that is jsp3.jsp

 

Web application SOMU_webApp.war can be downloaded here.

 

Mirjana's picture

Get and Set Properties on SI Server - User Exit

Get/Set Property on SI through the Map

 
Get/Set property User Exit steps:
 
  1. User Exit code for get/set SI/nonSI properties
  2. Create the class from java code
  3. Create jar package from class
  4. Install SIProperty.jar
  5. Input data - example
  6. Property files used for test – example
  7. Translation Map and extended rule used for test – example
  8. Result - explanation
 
  1. Java code (User Exit) for getting and setting properties in SI property file as well as any other file.
 
  • This java code contains 4 methods:
 
Ø       getProperty() – similar to sci-get-property() function that takes a property value from SI property based on key/name
Ø       setProperty() – similar to sci-set-property() function that sets a property value to SI property based on key/name
Ø       readPropertyFromFile() – read property value from a specific file and for a specific property name
Ø       addPropertyToFile() – set name-value pair into a file
 
·         User Exit java code
 
package com.tis.custom.userexit;
 
import com.sterlingcommerce.woodstock.util.frame.Manager;
import java.util.Properties;
import java.io.*;
 
publicclass SIProperty {
 
     
      public String getProperty(String vendorName, String propName)
      {
            String propValue = Manager.getProperty(vendorName, propName, true);
            System.out.println("SI Custom Property log ... gotten property is: " + propValue);
            return propValue;
      }
     
      public void setProperty(String vendorName, String propName, String propValue)
      {
            Properties props = Manager.getProperties(vendorName);
          if (props == null) {
            props = new Properties();
          }
          props.setProperty(propName, propValue);
          Manager.setVendorProperties(vendorName, props);
          System.out.println("SI Custom Property log ... set property is: " + propValue);
      }
     
      public String readPropertyFromFile(String vendorFileName, String propName)
      {
           
            String propValue = null;
            try {
                  FileInputStream fis = new FileInputStream(vendorFileName);
                  Properties props = new Properties();
            props.load(fis);
                  propValue = props.getProperty(propName);
                  fis.close();
            } catch(IOException e) {
                  e.printStackTrace();
            }
            System.out.println("SI Custom Property log ... gotten property from file: " + propValue);
            return propValue;
      }
     
      public void addPropertyToFile(String vendorFileName, String propName, String propValue)
      {
            try {
                  Properties pro = new Properties();
                  FileOutputStream fos = new FileOutputStream(vendorFileName);
                  pro.setProperty(propName, propValue);
                  pro.store(fos,null);
                  fos.close();
                  } catch (IOException e) {
                        e.printStackTrace();   
                  }
                  System.out.println("SI Custom Property log ... set property to file: " + propValue);
      }
}
 
  1. Compile java code 
·         As java class is created in the following packagecom.tis.custom.userexit, we can save the code in the following folder
 
C:\temp\com\tis\custom\userexit
 
And create the file with the name SIProperty.java
 
·         Command for compiling java code into class is:
 
C:\SterlingCommerce\SI50\install\jdk\bin>javac -classpath pathToPackage\Studio-API.jar c:\temp\com\tis\custom\userexit\SIProperty.java
 
Note:
·         Go to GIS/SI install folder, jdk/bin and use the same java, GIS/SI is using, for compiling java code. In that way we will avoid problems that can happen because of different java versions between compilation and running versions.
·         classpath setting in the command can be different depending on GIS/SI version. I presume, it can be woodstock.jar in GIS 4.x (in SIinstall/jar folder).
 
  1. Create jar package from SIProperty.class 
·         Delete SIProperty.java from C:\temp\com\tis\custom\userexit
·         Change directory up to c:\temp and run the following command to create SIProperty.jar:
 
C:\temp>C:\SterlingCommerce\SI50\install\jdk\bin\jar cvf SIProperty.jar com
 
·   Output of jar command is as follows:
 
added manifest
adding: com/tis/(in = 0) (out= 0)(stored 0%)
adding: com/tis/custom/(in = 0) (out= 0)(stored 0%)
adding: com/tis/custom/userexit/(in = 0) (out= 0)(stored 0%)
adding: com/tis/custom/userexit/SIProperty.class(in = 2108) (out= 982)(deflated
53%)
 
  1. Install SIProperty.jar 
Install SIProperty.jar with install3rdParty.cmd/sh on SI
 
  1. Input Data 
·         Input data is:
 
propName1
 
It can be anything, input data is as simple as possible, just to have anything to test the map.
 
  1. Property Files 
  • There is mirjana.properties file created in \install\properties folder and its content is:
 
propName1=propValu1
propName2=propValu2
keyHome = NikaDino
 
  • BP that will refresh that property so we can access the value:
 
<process name="default">
          <sequence>
                   <operation name="Cache Refresh Service">
                             <participant name="CacheRefreshService"/>
                             <output message="CacheRefreshServiceTypeInputMessage">
                                      <assign to="." from="*"/>
                                      <assign to="cache_name">mirjana</assign>
                                      <assign to="cache_type">properties</assign>
                             </output>
                             <input message="inmsg">
                                      <assign to="." from="*"/>
                             </input>
                   </operation>
          </sequence>
</process>
 
  • There is a file with properties that is not a part of SI installation, but simple file somewhere in the file system, e.g. c:\temp\a.properties, and its content is:
 
fileKey=fileVal
 
  1. Translation Map  
  • The map is simple, and 4 fields in the output will be populated by extended rule written in, that means property values before setting and after setting of SI property as well as non-SI property file
 

 
Extended rule in #filed, at the output side, is:
 
/////////////////////////////////////////////////////////////////////////////////////////////
 
// instantiate an object for SIProperty class
object SIProperty;
SIProperty = new("com.tis.custom.userexit.SIProperty");
 
// read/get property 'keyHome' from mirjana.properties
#propertyBeforeSetting = SIProperty.getProperty("mirjana.properties", "keyHome");
 
// set property 'keyHome' in mirjana.properties, from NikaDino to NEW_VALUE
SIProperty.setProperty("mirjana.properties", "keyHome", "NEW_VALUE");
 
// read/get property 'keyHome' from mirjana.properties after setting a new value
#propertyAfterSetting = SIProperty.getProperty("mirjana.properties", "keyHome");
 
 
 
// read/get property 'fileKey' from a.properties
#propertyFromFileBeforeSetting = SIProperty.readPropertyFromFile("c://temp//a.properties", "fileKey");
 
// set property name 'a' to value 'b'in a.properties
SIProperty.addPropertyToFile("c://temp//a.properties", "a", "b");
 
// read/get property 'a' from a.properties after setting a new value
#propertyFromFileAfterSetting = SIProperty.readPropertyFromFile("c://temp//a.properties", "a");
 
/////////////////////////////////////////////////////////////////////////////////////////////
 
  1. Result - explanation 
Map is run twice.
After running the map for the first and second time, the results are:
 
propValue1             NikaDino               NEW_VALUE              fileVal               b  
propValue1             NEW_VALUE          NEW_VALUE                                      b 
 
Property read from mirjana.property, for key/prop name (keyHome) is NikaDino, but another time it will be NEW_VALUE as property is set like that.
Also, a.properties contains fileKey=fileVal in the beginning but after setting it will contain a=b.
 
Note:
·         Keep in mind that setProperty() method set a value for a specific property name just in memory and after restarting SI, it will not be updated, but one from the property file will be loaded again. It will just live as long as the application (SI) lives.
·         After setting a new property in a file (a.properties), we do not create/append a new property in an existent file, but override it with new one. So this functionallity will always rewrite an old name-value pair with a new one.
 
Mirjana's picture

CLA2 with params

CLA2 - 3 parameters and Output file usage
 
  • Command line Adapter – configuration:
 
<process name="default">
          <sequence>
                   <operation name="Command Line 2 Adapter">
                             <participant name="CommandLineAdapter2"/>
                             <output message="CmdLine2InputMessage">
                                      <assign to="." from="*"/>
                                      <assign to="cmdLine">/home/si/bin/TEST_cmdWithParams.sh $0 $1 $2 $Output</assign>
                                      <assign to="parm0">abc</assign>
                                      <assign to="parm1">def</assign>
                                      <assign to="parm2">ghi</assign>
                                      <assign to="useOutput">true</assign>
                                      <assign to="workingDir">/home/si/bin</assign>
                             </output>
                             <input message="inmsg">
                                      <assign to="." from="*"/>
                             </input>
                   </operation>
          </sequence>
</process>
 
  • Unix script:
 
#! /bin/ksh
 
echo $1 > $4
echo $2 >> $4
echo $3 >> $4
 
  • Output/PrimaryDocument result:
 
abc
def
ghi
 

Extended rule - Converting GMT Date time into CE(S)T and Vice Versa

//Extended rule - Converting GMT Date time into CE(S)T and Vice Versa
 
datetime d1,d2,d3;
integer dMonth,dDay,tZone,dYear;
String[200] year,temp;
d1='';
d2='';
d3='';
year="";
dMonth=0;
dDay=0;
dYear=0;
tZone=0;
 
// let the date format be yyyy-mm-dd hh:mm:ss
//converting string to date format[#F is a field type is string]
 
d1=date("%Y-%m-%d %H:%M:%S", #F);
dMonth= get months (d1);
dYear= get years (d1);
ntoa(dYear,year);
 
temp=year+"-"+"03"+"-"+"31"+" 01:00:00";
d2=date("%Y-%m-%d %H:%M:%S",temp);
while(1)
do
begin
dDay=get days(d2);
if dDay=1 then break;
d2=d2<<days(-1);
end
 
temp=year+"-"+"10"+"-"+"31"+" 01:00:00";
d3=date("%Y-%m-%d %H:%M:%S",temp);
while(1)
do
begin
dDay=get days(d3);
if dDay=1 then break;
d3=d3<<days(-1);
end
 
//GMT to CE(S)T
 
if d1>d2 & d1<d3 then d1 = d1 << hours(2);
else d1 = d1 << hours(1);
 
//CE(S)T to GMT
 
//if d1>d2 & d1<d3 then d1 = d1 << hours(-2);
//else d1 = d1 << hours(-1);
 
strdate(d1,"%Y-%m-%d %H:%M:%S",#F);
Mirjana's picture

DOMToDoc function - take a specific node from Process Data

Request

Take UM element from Process Data and put it into PrimaryDocument with DOMToDoc() function.
 
Process Data
 
<?xml version="1.0" encoding="UTF-8"?>
<ProcessData>
          <PrimaryDocument SCIObjectID="MIRJANA:node1:1316a763640:145462"/>
          <UM>
                   <T1>aaa</T1>
                   <T2>bbb</T2>
          </UM>
          <Other>ggg</Other>
</ProcessData>
 
Primary Document after the operation should be:
 
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<UM>
          <T1>aaa</T1>
          <T2>bbb</T2>
</UM>
 
1. DOMToDoc function
 
 
DOMToDoc function setting
 

<assign to="." from="DOMToDoc(//*[name() = 'UM'], 'PrimaryDocument', 'no', 'UM')"></assign>

 … or even more simple …

 <assign to="." from="DOMToDoc(//UM,'PrimaryDocument','no', 'UM')"></assign>

 
2. XML Encoder
 
 
<operation name="XML Encoder">
          <participant name="XMLEncoder"/>
          <output message="XMLEncoderTypeInputMessage">
                   <assign to="." from="*"/>
                   <assign to="mode">process_data_to_document</assign>
                   <assign to="root_element">UM</assign>
                   <assign to="xPath">//UM/*</assign>
          </output>
          <input message="inmsg">
                   <assign to="." from="*"/>
          </input>
</operation>
 
 
 
 
 
 

 

Syndicate content