From c596c6f672031c77b73d1226466c7c2d6b8f764e Mon Sep 17 00:00:00 2001 From: Brad Gonzales Date: Mon, 2 Dec 2013 11:44:09 -0600 Subject: [PATCH] Issue #2541 Added exclude patterns to RequestPatterns. Added an exclude pattern to grib.xml to exclude data delivery sbn files. Change-Id: Id92865e1b58bdcf3744328bd0362636093a03521 Former-commit-id: dc7e255d43e2da726b77d916b80fdb698662db9f [formerly dc7e255d43e2da726b77d916b80fdb698662db9f [formerly 396a9a99863ce9a616eecde6466f1c4d43b8d566]] Former-commit-id: 8acfa99e77bda27c7b2a9a9b7348c5b76d72c84a Former-commit-id: dd8eb8c2b4113ccebbde017e609398d96fc21065 --- .../edex_static/base/distribution/grib.xml | 2 ++ .../uf/edex/distribution/RequestPatterns.java | 35 +++++++++++++++++-- 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/edexOsgi/com.raytheon.edex.plugin.grib/utility/edex_static/base/distribution/grib.xml b/edexOsgi/com.raytheon.edex.plugin.grib/utility/edex_static/base/distribution/grib.xml index 1d7e1d9943..3647f1c151 100644 --- a/edexOsgi/com.raytheon.edex.plugin.grib/utility/edex_static/base/distribution/grib.xml +++ b/edexOsgi/com.raytheon.edex.plugin.grib/utility/edex_static/base/distribution/grib.xml @@ -22,6 +22,8 @@ ^[EHLMOYZ][A-Z]{3}\d{2} + + ^LZ[ABC][ABC]9[123] KWBC ecmwf_decrypted diff --git a/edexOsgi/com.raytheon.uf.edex.distribution/src/com/raytheon/uf/edex/distribution/RequestPatterns.java b/edexOsgi/com.raytheon.uf.edex.distribution/src/com/raytheon/uf/edex/distribution/RequestPatterns.java index e18765ffba..b3f647d4cd 100644 --- a/edexOsgi/com.raytheon.uf.edex.distribution/src/com/raytheon/uf/edex/distribution/RequestPatterns.java +++ b/edexOsgi/com.raytheon.uf.edex.distribution/src/com/raytheon/uf/edex/distribution/RequestPatterns.java @@ -52,6 +52,7 @@ import com.raytheon.uf.common.serialization.ISerializableObject; * for PatternSyntaxException. * Mar 19, 2013 1794 djohnson Add toString() for debugging. * Sep 10, 2013 2327 rjpeter Sized ArrayList declarations. + * Nov 21, 2013 2541 bgonzale Exclusion patterns. * * * @author brockwoo @@ -68,8 +69,17 @@ public class RequestPatterns implements ISerializableObject { @XmlElements({ @XmlElement(name = "regex", type = String.class) }) private List patterns = new ArrayList(0); + /** + * List of patterns excluded by a plugin. Excludes takes precedence over + * acceptance and is applied first. + */ + @XmlElements({ @XmlElement(name = "regexExclude", type = String.class) }) + private List exclusionPatterns = new ArrayList(0); + private List compiledPatterns = new ArrayList(0); + private List compiledExclusionPatterns = new ArrayList(0); + protected Log patternFailedLogger = LogFactory.getLog("PatternFailedLog"); /** @@ -112,7 +122,13 @@ public class RequestPatterns implements ISerializableObject { * */ public void compilePatterns() { - compiledPatterns = new ArrayList(patterns.size()); + compiledPatterns = compilePatterns(patterns); + compiledExclusionPatterns = compilePatterns(exclusionPatterns); + } + + private List compilePatterns(List patterns) { + List compiledPatterns = new ArrayList(patterns.size()); + for (String pattern : patterns) { try { compiledPatterns.add(Pattern.compile(pattern)); @@ -123,24 +139,37 @@ public class RequestPatterns implements ISerializableObject { patternFailedLogger.error(sb.toString(), e); } } + return compiledPatterns; } /** * Takes a string and compares against the patterns in this container. The * first one that matches breaks the search and returns true. * + * Check for exclusion first. It takes precedence over acceptance. + * * @param header * The string to search for * @return a boolean indicating success */ public boolean isDesiredHeader(String header) { boolean isFound = false; - for (Pattern headerPattern : compiledPatterns) { + boolean isExcluded = false; + + for (Pattern headerPattern : compiledExclusionPatterns) { if (headerPattern.matcher(header).find()) { - isFound = true; + isExcluded = true; break; } } + if (!isExcluded) { + for (Pattern headerPattern : compiledPatterns) { + if (headerPattern.matcher(header).find()) { + isFound = true; + break; + } + } + } return isFound; }