Quantcast
Channel: SCN : All Content - Process Integration (PI) & SOA Middleware
Viewing all articles
Browse latest Browse all 7030

UDF Basic Building Block

$
0
0

Update 26-Apr-2015:Added 2 examples: Delimited string to context values and the reverse way.
Update 25-Apr-2015:
Added DisplayQueue screenshots.


Introduction

UDF can be written for many different purpose, and with many different way of coding. Still, there should be some reusable coding/statement/patterns that keep on occurs again and again. In this document, is my attempt to list down some common coding/statement and patterns that known. Below meant to be building blocks, mean not use it standalone, and should mix and match with other building blocks to come out something useful. It just like LEGO

 

Category

Requirement

UDF coding

Condition

Test if input field existed (not null).

This should be first checking for value, if null then do nothing.

if (value != null)

Condition

Test if context values existed (not null).

This should be first checking for contextValues, if empty context(null) then do nothing.

if (contextValues != null && contextValues.length > 0)

Condition

Test if has value (non-empty).

if (value != null && value.trim().length() > 0)

Condition

Test if value is suppress.

if (ResultList.SUPPRESS.equalsIgnoreCase(value)))

Condition

Test if value is context change.

if (ResultList.CC.equals(value))

ResultList

Add suppress to result.

result.addSuppress();

ResultList

Add context change to result.

result.addContextChange();

ResultList

Add value to result.

result.addValue(value);

ResultList

Add boolean true/false to result. Boolean value will be used in next function call.

result.addValue("true");
result.addValue("false");

ResultList

Add empty string to result. Empty string will create target node.

result.addValue("");

ArrayList

Create new array list.

List array = new ArrayList();

ArrayList

Add value to array.

array.add(value);

ArrayList

Test if array contains value.

if (array.contains(value))

Looping

Pattern

Single loop at contextValues, get each value to do something.

for (int i = 0; i < contextValues.length; i++){

   String value = contextValues[i];

   //Do something
}

Looping

Pattern

Create target node if some condition is met.

 

Suggested function name:
createIf<SomeConditions>

for (int i = 0; i < contextValues.length; i++){

   String value = contextValues[i];

  
   if(<SomeConditions is true>){

      result.addValue("");

   }

   else{

      result.addSuppress();

   }
}

Looping PatternPass value to target node if some condition is met.

 

Suggested function name:

passIf<SomeConditions>

for (int i = 0; i < contextValues.length; i++){

   String value = contextValues[i];

  
   if(<SomeConditions is true>){

      result.addValue(value);

   }

   else{

      result.addSuppress();

   }
}

Looping Pattern

Return true if some condition is met, otherwise false.

 

Suggested function name:
has<SomeConditions>
is<SomeConditions>

for (int i = 0; i < contextValues.length; i++){

   String value = contextValues[i];

  
   if(<SomeConditions is true>){

      result.addValue("true");

   }

   else{

      result.addValue("false");

   }
}

Looping Pattern

Return single true if some condition is met for values in context, otherwise single false.


Suggested function name:

 

contextHas<SomeConditions>
contextIs<SomeConditions>

String conditionMet = "false";

for (int i = 0; i < contextValues.length; i++){

   String value = contextValues[i];

  
   if(<SomeConditions is true>){

      conditionMet = "true";

      break;

   }
}


result.addValue(conditionMet);

Looping PatternOuter and inner loop at contextValues and secondContext, get both outer and inner value to compare and do something.

for (int i = 0; i < contextValues.length; i++){
   String value1 = contextValues[i];


   for (int j = 0; j < secondContext.length; j++){

      String value2 = secondContext[j];
      //Compare value1 and value2

      //Do something

   }
}

PositionGet value from contextValues based on index/position.

 

Suggested function name:

getValueByIndex
getFirstValue

getLastValue

input1 = contextValues
input2 = index(optional, starting at 1)

 

by index --> result.addValue(contextValues[index-1]);
first --> result.addValue(contextValues[0]);

last --> result.addValue(contextValues[contextValues.length-1]);

Context

Split each value in contexts with context change. Simulate splitByValue(ForEach).

for (int i = 0; i < contextValues.length; i++){

   String value = contextValues[i];

 

 

   result.addValue(value);

 

 

   if(i != contextValues.length - 1){

      result.addContextChange();

   }

}

Context

Remove all context change in contextValues. Simulate removeContext.

for (int i = 0; i < contextValues.length; i++){

 

   String value = contextValues[i];

 

   if (!ResultList.CC.equals(value)){

      result.addValue(value);

   }

}

Context

Return only unique values, remove duplicated values.

List uniqueList = new ArrayList();


for (int i = 0; i < contextValues.length; i++){

   String value = contextValues[i];


   if (!uniqueList.contains(value)) {

      uniqueList.add(value);

      result.addValue(value);

   }
}

ContextSplit input1 full string to context values by delimiter specified by input2.

input1 = fullString

input2 = delimiter


String dchar = delimiter[0];

 

for (int i = 0; i < fullString.length; i++){

 

   String[] splitString = fullString[i].split(dchar);

 

   for (int j = 0; j < splitString.length; j++) {

      result.addValue(splitString[j]);

   }

}

Context

Concatenate input1 context values to delimited string by delimiter specified by input2.

input1 =contextValues

input2 = delimiter

 

String fullString = "";

String dchar = delimiter[0];


for (int i = 0; i < contextValues.length; i++){

   String value = contextValues[i];


   if(i == 0){

      fullString = value;

   }

   else{

      fullString = fullString + dchar + value;

   }

}

 

result.addValue(fullString);


Viewing all articles
Browse latest Browse all 7030

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>