Skip to content

Instantly share code, notes, and snippets.

@esaounkine
Last active January 2, 2016 15:18
Show Gist options
  • Save esaounkine/8322155 to your computer and use it in GitHub Desktop.
Save esaounkine/8322155 to your computer and use it in GitHub Desktop.
sample code to create SWIFT MT 205COV using the Datamation SMV (more examples at http://wiki.datamation.gr/x/OIBH)
@Test
public void testCreating205COV() {
SwiftMessage message = new SwiftMessage();
// Set Tags for block1
message.setArgApplid("F");
message.setArgServid("01");
message.setArgLTaddrBlk1("AAAABEBBAXXX");
// Set Tags for block2
message.setArgInoutind("I");
message.setArgMsgtype("205");
message.setArgLTaddrBlk2("CCCCUS33AXXX");
message.setArgMsgprior("N");
addTagsToBlock(message.getBlock3(), ":119:COV");//this tag tells SWIFT that this is a COV message
addTagsToBlock(message.getBlock4(),
":20:987COV",
":21:090525/123COV",
":32A:090527USD10500,00",
":52A:AAAABEBB",
":58A:BBBBGB22",
":50F:/123564982101\n1/MR. BIG\n2/HIGH STREET 3\n3/BE/BRUSSELS",
":59:/987654321\nMR. SMALL\nLOW STREET 15\nLONDON GB",
":70:/INV/1234",
":33B:USD10500,00");
// Set Tags for block5 (This block is optional)
addTagsToBlock(message.getBlock5(), ":MAC:75D138E4", ":CHK:DE1B0D71FA96"); //add MAC and CHK to block5 vector
// Now validate and build the outgoing message in a string format as SWIFT expects it.
SwiftValidObj validation = new SwiftMsgValidator().validateMsg(message);
if (validation.hasErrors()){ //If validation error
ValidationErrorList errorList = validation.getValidationErrorList();
for(ValidationError error : errorList) { //Print error messages
System.out.println(error);
}
} else {
String swiftMessage = validation.getMessage();
System.out.println(swiftMessage); //Print the constructed Swift message.
}
}
private static void addTagsToBlock(List block, String... tags) {
for(String tag : tags) {
String tagKey = tag.replaceAll("(?s):(.*):.*", "$1");
String tagValueString = tag.replaceAll("(?s):.*:(.*)", "$1");
String[] lines = tagValueString.split("\n");
Vector tagValue = new Vector();
for(String line : lines) {
tagValue.add(line);
}
block.add(new Tag(tagKey, tagValue));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment