Skip to content

Instantly share code, notes, and snippets.

@SriniBlog
SriniBlog / getGlobalParameter.java
Last active February 9, 2018 01:12
This method can be used in UDF to read the parameters from GlobalContainer instance
public String getGlobalParameter(String Parameter, Container container) throws StreamTransformationException{
String ParameterValue = "";
try{
GlobalContainer gc = container.getGlobalContainer();
ParameterValue = (String) gc.getParameter(parameter);
}catch(Exception ee){
ParameterValue = "";
}
return ParameterValue;
}
@SriniBlog
SriniBlog / validateFieldLength.java
Created December 22, 2015 17:03
This method is used to validate length of a field and then decide if it acceptable or not. If not, then raise exception not to proceed further.
public String validateFieldLength(String minLength, String maxLength, String FieldValue, Container container) throws StreamTransformationException{
try{
if ( FieldValue.length() < Integer.parseInt(minLength)) //check if FieldValue lenght is less than minlength
{
throw new RuntimeException(FieldValue + " length is incorrect");
}
if( FieldValue.length() > Integer.parseInt(maxLength) ) //check if FieldValue lenght is greater than maxLength. If yes, then truncate fieldValue
{
FieldValue = FieldValue.substring(0, Integer.parseInt(maxLength) );
}
@SriniBlog
SriniBlog / changeTimeZone.java
Last active December 23, 2015 05:11
This method is used to change Time Zone and get time based on that time zone.
public String changeTimeZone(Container container) throws StreamTransformationException{
String stTime = "";
try{
Calendar calendar = Calendar.getInstance();
java.text.SimpleDateFormat formatter = new java.text.SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ"); //Formatter to get the desired time stamp format
formatter.setTimeZone( TimeZone.getTimeZone("GMT") ); //Change to desired GMT timezone from here
stTime = formatter.format( calendar.getTime() );
}catch(Exception ee){
stTime= "";
}
@SriniBlog
SriniBlog / getTime.java
Created December 22, 2015 16:51
This method is used to get Time in HHmmSS Format using the Calender Function.
public String getTime(Container container) throws StreamTransformationException{
String stTime, stHH, stmm, stss;
stTime = "000000"; //Defaults
try{
Calendar cal = Calendar.getInstance();
//stTime = cal.getTime().toString(); -- Another short way
stHH = Integer.toString(cal.get(Calendar.HOUR_OF_DAY));
if(stHH.length()<2){
stHH = "0" + stHH;
@SriniBlog
SriniBlog / setDynamicFileName.java
Created December 22, 2015 16:45
This method is used in SAP PI Mapping UDF to write the FileName Dynamic Configuration
public boolean setDynamicFileName(String FieldValue, Container container) throws StreamTransformationException{
boolean success = false;
try{
//Get the DynamicConfiguration instance
DynamicConfiguration config = (DynamicConfiguration) container.getTransformationParameters().get(StreamTransformationConstants.DYNAMIC_CONFIGURATION);
//Define key to write in the Dynamic Configuration
DynamicConfigurationKey key1 = DynamicConfigurationKey.create("http://sap.com/xi/XI/System/File", "FileName");
//Write the FileName parameter from the Dynamic Configuration based on the key
@SriniBlog
SriniBlog / getDynamicFileName.java
Last active February 9, 2018 01:12
This method is used in SAP PI Mapping UDF to read the FileName from the Dynamic Configuration
public String getDynamicFileName(Container container) throws StreamTransformationException{
String FileValue = "";
try{
//Get the DynamicConfiguration instance
DynamicConfiguration config = (DynamicConfiguration) container.getTransformationParameters().get(StreamTransformationConstants.DYNAMIC_CONFIGURATION);
//Define key to read from the Dynamic Configuration
DynamicConfigurationKey key1 = DynamicConfigurationKey.create("http://sap.com/xi/XI/System/File", "FileName");
//Read the FileName parameter from the Dynamic Configuration based on the key
@SriniBlog
SriniBlog / getMessageID.java
Created December 22, 2015 16:36
This method is used in SAP PI Mapping UDF to read the message ID
public String getMessageID(Container container) throws StreamTransformationException{
String messageID = "";
java.util.Map map = container.getTransformationParameters();
messageID = (String) map.get( StreamTransformationConstants.MESSAGE_ID);
return messageID;
}
@SriniBlog
SriniBlog / setDynamicConfiguration.java
Created December 22, 2015 16:31
This method is used in SAP PI Mapping UDF to write the Dynamic Configuration
public boolean setDynamicConfiguration(String Namespace, String FieldName, String FieldValue, Container container) throws StreamTransformationException{
boolean success = false;
try{
//Get the DynamicConfiguration instance
DynamicConfiguration config = (DynamicConfiguration) container.getTransformationParameters().get(StreamTransformationConstants.DYNAMIC_CONFIGURATION);
//Define key to write in the Dynamic Configuration
DynamicConfigurationKey key1 = DynamicConfigurationKey.create(Namespace, FieldName);
//Write the parameter from the Dynamic Configuration based on the key
@SriniBlog
SriniBlog / getDynamicConfiguration.java
Last active December 22, 2015 16:39
This method is used in SAP PI Mapping UDF to read the Dynamic Configuration
public String getDynamicConfiguration(String Namespace, String FieldName, Container container) throws StreamTransformationException{
String FieldValue = "";
try{
//Get the DynamicConfiguration instance
DynamicConfiguration config = (DynamicConfiguration) container.getTransformationParameters().get(StreamTransformationConstants.DYNAMIC_CONFIGURATION);
//Define key to read from the Dynamic Configuration
DynamicConfigurationKey key1 = DynamicConfigurationKey.create(Namespace, FieldName);
//Read the parameter from the Dynamic Configuration based on the key
@SriniBlog
SriniBlog / WriteDynamicConfiguration_AdapterModule.java
Created December 18, 2015 15:08
This is the adapter module Utility to write the dynamic configuration from the channel module.
/**
*
*/
package com.sap.adaptermodule;
import javax.ejb.CreateException;
import javax.ejb.SessionBean;
import javax.ejb.SessionContext;