Skip to content

Instantly share code, notes, and snippets.

@SriniBlog
SriniBlog / getSeeburgerVariable.java
Last active February 9, 2018 01:10
This UDF can be used to read the Seerburger Variable
public String getSeeburgerVariable(String variableName, Container container) throws StreamTransformationException{
AbstractTrace trace;
trace = container.getTrace();
String variableValue = "";
try
{
VariableBean be=VariableFactory.getVariableInstance("");
variableValue = be.getStringVariable(variableName);
if ( variableValue!= null)
@SriniBlog
SriniBlog / getStreamTransformationConstant.java
Created December 24, 2015 06:31
This UDF is used to get the Runtime Parameters from the StreamTransformation Constants
public String getStreamTransformationConstant(Container container) throws StreamTransformationException{
GlobalContainer globalContainer;
MappingTrace trace;
String headerField;
java.util.Map map;
trace = container.getTrace();
globalContainer = container.getGlobalContainer();
map = globalContainer.getTransformationParameters();
headerField = (String) map.get( StreamTransformationConstants.INTERFACE_NAMESPACE );
@SriniBlog
SriniBlog / splitValue.java
Created December 23, 2015 16:12
This Advanced UDF use to split the field value based on the splitter character
public void splitValue(String FieldValue, String SplitterChar, ResultList result, Container container) throws StreamTransformationException{
try{
//Split the string value based on the splitterchar
String [ ] strArray = FieldValue.split(SplitterChar);
int istrArray = strArray.length;
for (int i=0; i < istrArray; i++){
result.addValue(strArray[i]);
}
}catch(Exception ee){
}
@SriniBlog
SriniBlog / makeArray.java
Created December 23, 2015 16:11
If you want to combine many fields into a array to pass it as a variable to another function then this method will help to create the array
public void makeArray5(String[] a, String[] b, String[] c, String[] d, String[] e, ResultList result, Container container) throws StreamTransformationException{
String[] str = new String[5];
try{
str[0] = a[0].trim();
str[1] = b[0].trim();
str[2] = c[0].trim();
str[3] = d[0].trim();
str[4] = e[0].trim();
for (int i = 0; i < 10; i++) {
@SriniBlog
SriniBlog / hasLike.java
Last active December 23, 2015 16:10
This function checks the field if it has the value in the field.
public String hasLike(String FieldValue, String searchValue, Container container) throws StreamTransformationException{
String newFieldValue = "not found";
try{
//Find the index value of the searchvalue
int index = FieldValue.indexOf(searchValue);
if(index >= 0){ //if found
newFieldValue = "found";
}
}catch(Exception ee){
@SriniBlog
SriniBlog / subStrings.java
Created December 23, 2015 16:05
This function is similar to PI Standard Function but it won't throw exception like the standard UDF
public String subStrings(String FieldValue, String startPos, String endPos, Container container) throws StreamTransformationException{
String newFieldValue = "";
try{
int istartPos = Integer.parseInt(startPos);
int iendPos = Integer.parseInt(endPos);
if( startPos.equals("-1") ){ //startPos value is passed as -1 then substring from 0 till the endPos value
newFieldValue = FieldValue.substring(0,iendPos);
}else if ( endPos.equals("-1") ){ //endPos value is passed as -1 then substring from startPos till end
newFieldValue = FieldValue.substring(istartPos);
@SriniBlog
SriniBlog / removeLeadingZero.java
Created December 23, 2015 16:03
removeLeadingZero - This UDF will remove the leading Zero from the number field.
public String removeLeadingZero(String FieldValue, Container container) throws StreamTransformationException{
String newFieldValue = "";
try{
//Find 0 from starting and replace it with nothing
newFieldValue = FieldValue.replaceFirst("^0+", "");
}catch(Exception ee){
newFieldValue = FieldValue;
}
return newFieldValue;
}
@SriniBlog
SriniBlog / addLeadingZero.java
Created December 23, 2015 15:33
This UDF will add the leading zero to the number based on the length of the field.
public String addLeadingZero(String FieldValue, String Zeros, Container container) throws StreamTransformationException{
String newFieldValue = "";
String newZeros = "0";
try{
//Convert Zero to int iZeros
int iZeros = Integer.parseInt(Zeros);
//Check how Zeros to add
iZeros = iZeros-FieldValue.length();
@SriniBlog
SriniBlog / getInstanceUDF.java
Created December 23, 2015 09:10
This is a psedu code to show how to get the instance of the trace, dynamic configuration etc. inside the UDF
public String getInstanceUDF(Container container) throws StreamTransformationException{
GlobalContainer globalContainer;
MappingTrace trace;
String headerField;
java.util.Map map;
trace = container.getTrace();
globalContainer = container.getGlobalContainer();
map = globalContainer.getTransformationParameters();
headerField = (String) map.get( StreamTransformationConstants.INTERFACE_NAMESPACE );
@SriniBlog
SriniBlog / setGlobalParameter.java
Created December 23, 2015 08:05
This method can be used in UDF to write the parameter to GlobalContainer instance
public String setGlobalParameter(String Parameter, String ParameterValue, Container container) throws StreamTransformationException{
try{
GlobalContainer gc = container.getGlobalContainer();
gc.setParameter(Parameter, ParameterValue);
}catch(Exception ee){
}
return ParameterValue;
}