Custom building blocks
When writing a CEV building block which is a potential candidate for the next release of the product, take into account the following guidelines.
Create a rule sequence starting with CEV.
Use a groovy rule to implement the building block.
Use CEV naming conventions for the parameters of the building block, prefix them with the name of the building block. They can be accessed from params.
params.get("CEVAddInstructionCodeModifier.format")
JXPath parameters can also be used:
import org.apache.commons.jxpath.JXPathContext…String jxpath = params.get("CEVAddInstructionCodeModifier.jxpath")
JXPathContext jxPathContext = JXPathContext.newContext(context)
jxPathContext.setLenient(true)
Object value = jxPathContext.getValue(jxpath)
In case of a modifier
Add trace logging
params.get(“cev_logger”).trace("Add instruction code %s", code)
Invoke setModified
params.get(“cev_result”).setModified(true);
Add audit logging
params.get(“cev_logger”).audit("Add instruction code %s", "instructionCodes", "", code, code)
In case of a condition
Add trace logging
def logger = params.get("cev_logger")
logger.trace("Instructed amount: %s",
String.valueOf(instructedAmount))
logger.trace("High value minimum amount: %s", String.valueOf(highValueAmount))
invoke setValid
params.get(“cev_result”).setValid(valid)
Add logging when invalid
if (!isHighValue) {
logger.invalid("%s is too low", “instructedAmount”, String.valueOf(instructedAmount))
}
Example of a modifier
Name: CEVAddInstructionCodeModifier
Parameters: CEVAddInstructionCodeModifier.format CEVAddInstructionCodeModifier.code CEVAddInstructionCodeModifier.addInfo
if (context instanceof com.trax.payment.valueobject.Payment) {
def formatCode = params.get("CEVAddInstructionCodeModifier.format")
def code = params.get("CEVAddInstructionCodeModifier.code")
def addInfo = params.get("CEVAddInstructionCodeModifier.addInfo")
def format = com.trax.message.MessageHelper.getFormat(formatCode)
if (context.getInstructionCodes(format, code, null).empty) {
params.get("cev_logger").trace("Add instruction code %s", code)
context.addInstructionCode(format, code, addInfo)
params.get("cev_result").setModified(true)
params.get("cev_logger").audit("Add instruction code %s",
"instructionCodes", "", code, code)
}
}
return context
Example of a condition
Name: CEVHighValueCondition
if (context instanceof com.trax.payment.valueobject.Payment) {
def instructedAmount = context.instructedAmount.amount
def highValueAmount = com.trax.framework.util.ApplicationProperties
.getBigDecimal("UP-HighValueMinimumAmount", 0)
def logger = params.get("cev_logger")
logger.trace("Instructed amount: %s",
String.valueOf(instructedAmount))
logger.trace("High value minimum amount: %s", String.valueOf(highValueAmount))
def isHighValue = instructedAmount >= highValueAmount
params.get("cev_result").setValid(isHighValue)
if (!isHighValue) {
logger.invalid("%s is too low", "instructedAmount", String.valueOf(instructedAmount))
}
}
return context