The validation methods are available at the OTD level, and can be called after the OTD is populated with it’s values. This usually occurs after a message is unmarshaled in the OTD.
The following fragment of code demonstrates the use of the validate method within a Collaboration. In this example, validate() is called and either “message OK’ or the exception error String is written to the log.
import com.stc.swift.validation.MFVRException; import com.stc.swift.validation.SVRException; import com.stc.swift.validation.ValidatingSWIFTMTOTD; import com.stc.swift.validation.bic.BICDir; import com.stc.swift.validation.BICPlusIBAN.*; import com.stc.swift.validation.MessageValidationException; import com.stc.swift.otd.v2008.std.mt_541.Mt_541; import java.util.*; public class ValidateMt_541_Modified { public boolean receive( com.stc.connectors.jms.Message input, xsd.ValidationReplyMessage.Result output, com.stc.connectors.jms.JMS invalidMessages, com.stc.connectors.jms.JMS validMessages, com.stc.swift.otd.v2008.std.mt_541.Mt_541 mt_541_1 ) throws Throwable { com.stc.connectors.jms.Message result = validMessages.createMessage(); result.setTextMessage( input.getTextMessage() ); String errors = null; String msg = ""; try { mt_541_1.unmarshal( (com.stc.otd.runtime.OtdInputStream) new com.stc.otd.runtime.provider.SimpleOtdInputStreamImpl( new java.io.ByteArrayInputStream( input.getTextMessage().getBytes() ) ) ); } catch ( Exception ex ) { errors = ex.getMessage(); errors += "\r\n"; errors += "Last successful parse: " + mt_541_1.getLastSuccessInfo(); result.storeUserProperty( "ValidationErrors", errors ); invalidMessages.send( result ); output.setErrorMessages( errors ); output.setIsError( true ); output.setSwiftMessage( input.getTextMessage() ); return false; } logger.info( "Unmarshalled MT541 message." ); logger.info( "MFVR validation to follow ....." ); // Call Default Validation logic for validation against applicable MFVRs try { mt_541_1.validate(); } catch ( MessageValidationException mve ) { errors = mve.getErrorMessage(); msg = mve.getMessage(); } logger.info( "Completed MFVR validation" ); logger.info( "BICPlusIBAN validation to follow ....." ); if (errors == null) { logger.info( "No MFVR Exception" ); } else { logger.info( "Found MFVR Exception" ); logger.info( "Errors: " + errors ); logger.info( "msg: " + msg ); } // End of "Default Validation" invoking // // Call BICPlusIBAN validation String BICPlusIBANresult = ""; String bicCode = mt_541_1.getBasicHeader().getLTAddress().substring( 0, 8 ); String ibanCode = "DE615088005034573201"; BICPlusIBANDir.setBIC_Code( bicCode ); BICPlusIBANDir.setIBAN_Code( ibanCode ); BICPlusIBANresult = "\n\n\n*** Validating BICPlusIBAN ***\n"; BICPlusIBANresult = BICPlusIBANresult + " BIC - " + BICPlusIBANDir.getBIC_code() + "\n"; BICPlusIBANresult = BICPlusIBANresult + " IBAN - " + BICPlusIBANDir.getIBAN_code() + "\n"; BICPlusIBANresult = BICPlusIBANresult + "\n a) Deriving the BIC from the IBAN...\n"; ArrayList bicList = BICPlusIBANDir.deriveBICfromIBAN(); if (bicList == null) { BICPlusIBANresult = BICPlusIBANresult + " ==> Unable to derive BIC data from given IBAN.\n"; if (errors != null) { errors = errors + "\n\nUnable to derive BIC data from given IBAN.\n"; } else { errors = errors + "\n\nUnable to derive BIC data from given IBAN.\n"; } } else { BICPlusIBANresult = BICPlusIBANresult + " ==> BIC CODE and BRANCH CODE = " + (String) bicList.get( 0 ) + ".\n"; BICPlusIBANresult = BICPlusIBANresult + " ==> IBAN BIC CODE and BRANCH CODE = " + (String) bicList.get( 1 ) + ".\n"; BICPlusIBANresult = BICPlusIBANresult + " ==> ROUTING BIC CODE and BRANCH CODE = " + (String) bicList.get( 2 ) + ".\n"; } BICPlusIBANresult = BICPlusIBANresult + "\n b) Validating the Bank ID...\n"; if (BICPlusIBANDir.validateBankID()) { BICPlusIBANresult = BICPlusIBANresult + " ==> Valid Bank ID found in BI file.\n"; } else { BICPlusIBANresult = BICPlusIBANresult + " ==> No valid Bank ID found in BI file.\n"; if (errors != null) { errors = errors + "No valid Bank ID found in BI file.\n"; } else { errors = errors + "No valid Bank ID found in BI file.\n"; } } BICPlusIBANresult = BICPlusIBANresult + "\n c) Validating the BIC...\n"; if (BICPlusIBANDir.validateBIC()) { BICPlusIBANresult = BICPlusIBANresult + " ==> Valid BIC data found in BI file.\n"; } else { BICPlusIBANresult = BICPlusIBANresult + " ==> No valid BIC data found in BI file.\n"; if (errors != null) { errors = errors + "No valid BIC data found in BI file.\n"; } else { errors = errors + "No valid BIC data found in BI file.\n"; } } BICPlusIBANresult = BICPlusIBANresult + "\n d) Validating the BIC/IBAN Combination...\n"; if (BICPlusIBANDir.validateBICIBANCombo()) { BICPlusIBANresult = BICPlusIBANresult + " ==> BIC and IBAN codes are belong to the same institution.\n\n\n"; } else { BICPlusIBANresult = BICPlusIBANresult + " ==> BIC and IBAN codes are NOT belong to the same institution.\n\n\n"; if (errors != null) { errors = errors + "BIC and IBAN codes are NOT belong to the same institution.\n\n\n"; } else { errors = errors + "BIC and IBAN codes are NOT belong to the same institution.\n\n\n"; } } logger.info( BICPlusIBANresult ); // if (errors != null) { // errors = errors + BICPlusIBANresult; result.storeUserProperty( "ValidationErrors", errors ); invalidMessages.send( result ); output.setErrorMessages( errors ); output.setIsError( true ); output.setSwiftMessage( input.getTextMessage() ); return false; } // passed validation String currMsg = result.getTextMessage(); currMsg = currMsg + BICPlusIBANresult; result.setTextMessage( currMsg ); validMessages.send( result ); output.setErrorMessages( "" ); output.setIsError( false ); output.setSwiftMessage( input.getTextMessage() ); return true; } |
To select a validation method from the Collaboration Editor’s Business Rules Designer, right-click the SWIFT message OTD and select Select method to call from the shortcut menu.