From ca75e22e0a79bf4c5bd1c95cd4c6f59e76da4977 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Alcarraz?= Date: Sat, 15 Jun 2019 12:46:29 -0500 Subject: [PATCH] new property allow-extra-fields for CheckFields This let's use the CheckFields participant for controlling mandatory fields, and parse some optional ones, but no need to define all possible optionals. Also changed a StringBuffer for a StringBuilder for a local variable --- .../org/jpos/transaction/participant/CheckFields.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/jpos/src/main/java/org/jpos/transaction/participant/CheckFields.java b/jpos/src/main/java/org/jpos/transaction/participant/CheckFields.java index 433ff59bec..03f234c24e 100644 --- a/jpos/src/main/java/org/jpos/transaction/participant/CheckFields.java +++ b/jpos/src/main/java/org/jpos/transaction/participant/CheckFields.java @@ -46,12 +46,13 @@ public class CheckFields implements TransactionParticipant, Configurable { private Pattern CAPTUREDATE_PATTERN = Pattern.compile("^\\d{4}"); private Pattern ORIGINAL_DATA_ELEMENTS_PATTERN = Pattern.compile("^\\d{30,41}$"); private boolean ignoreCardValidation = false; + private boolean allowExtraFields = false; public int prepare (long id, Serializable context) { Context ctx = (Context) context; Result rc = ctx.getResult(); try { - ISOMsg m = (ISOMsg) ctx.get (request); + ISOMsg m = ctx.get (request); if (m == null) { ctx.getResult().fail(CMF.INVALID_TRANSACTION, Caller.info(), "'%s' not available in Context", request); return ABORTED | NO_JOIN | READONLY; @@ -59,7 +60,7 @@ public int prepare (long id, Serializable context) { Set validFields = new HashSet<>(); assertFields (ctx, m, cfg.get ("mandatory", ""), true, validFields, rc); assertFields (ctx, m, cfg.get ("optional", ""), false, validFields, rc); - assertNoExtraFields (m, validFields, rc); + if (!allowExtraFields) assertNoExtraFields (m, validFields, rc); } catch (Throwable t) { rc.fail(CMF.SYSTEM_ERROR, Caller.info(), t.getMessage()); ctx.log(t); @@ -71,6 +72,7 @@ public void setConfiguration (Configuration cfg) { this.cfg = cfg; request = cfg.get ("request", ContextConstants.REQUEST.toString()); ignoreCardValidation = cfg.getBoolean("ignore-card-validation", false); + allowExtraFields = cfg.getBoolean("allow-extra-fields", false); } private void assertFields(Context ctx, ISOMsg m, String fields, boolean mandatory, Set validFields, Result rc) { @@ -126,7 +128,7 @@ private void assertFields(Context ctx, ISOMsg m, String fields, boolean mandator } } private void assertNoExtraFields (ISOMsg m, Set validFields, Result rc) { - StringBuffer sb = new StringBuffer(); + StringBuilder sb = new StringBuilder(); for (int i=1; i<=m.getMaxField(); i++) { // we start at 1, MTI is always valid String s = Integer.toString (i); if (m.hasField(i) && !validFields.contains (s)) {