Get/Set Property on SI through the Map
Get/Set property User Exit steps:
- User Exit code for get/set SI/nonSI properties
- Create the class from java code
- Create jar package from class
- Install SIProperty.jar
- Input data - example
- Property files used for test – example
- Translation Map and extended rule used for test – example
- Result - explanation
- 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);
}
}
- 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).
- 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%)
- Install SIProperty.jar
Install SIProperty.jar with install3rdParty.cmd/sh on SI
- 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.
- 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
- 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");
/////////////////////////////////////////////////////////////////////////////////////////////
- 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.