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: dc7e255d43 [formerly 396a9a99863ce9a616eecde6466f1c4d43b8d566]
Former-commit-id: 8acfa99e77
This commit is contained in:
Brad Gonzales 2013-12-02 11:44:09 -06:00
parent 2fa17aab7f
commit dd8eb8c2b4
2 changed files with 34 additions and 3 deletions

View file

@ -22,6 +22,8 @@
<!-- Super Set of all possible WMO grib patterns -->
<!-- Is specifically not restricting on CCCC since HPE isn't populating it -->
<regex>^[EHLMOYZ][A-Z]{3}\d{2}</regex>
<!-- Exclude Data Delivery specific patterns -->
<regexExclude>^LZ[ABC][ABC]9[123] KWBC</regexExclude>
<!-- ECMWF decrypted -->
<regex>ecmwf_decrypted</regex>

View file

@ -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.
* </pre>
*
* @author brockwoo
@ -68,8 +69,17 @@ public class RequestPatterns implements ISerializableObject {
@XmlElements({ @XmlElement(name = "regex", type = String.class) })
private List<String> patterns = new ArrayList<String>(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<String> exclusionPatterns = new ArrayList<String>(0);
private List<Pattern> compiledPatterns = new ArrayList<Pattern>(0);
private List<Pattern> compiledExclusionPatterns = new ArrayList<Pattern>(0);
protected Log patternFailedLogger = LogFactory.getLog("PatternFailedLog");
/**
@ -112,7 +122,13 @@ public class RequestPatterns implements ISerializableObject {
*
*/
public void compilePatterns() {
compiledPatterns = new ArrayList<Pattern>(patterns.size());
compiledPatterns = compilePatterns(patterns);
compiledExclusionPatterns = compilePatterns(exclusionPatterns);
}
private List<Pattern> compilePatterns(List<String> patterns) {
List<Pattern> compiledPatterns = new ArrayList<Pattern>(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;
boolean isExcluded = false;
for (Pattern headerPattern : compiledExclusionPatterns) {
if (headerPattern.matcher(header).find()) {
isExcluded = true;
break;
}
}
if (!isExcluded) {
for (Pattern headerPattern : compiledPatterns) {
if (headerPattern.matcher(header).find()) {
isFound = true;
break;
}
}
}
return isFound;
}