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
[formerlydc7e255d43
[formerly 396a9a99863ce9a616eecde6466f1c4d43b8d566]] Former-commit-id:8acfa99e77
Former-commit-id:dd8eb8c2b4
This commit is contained in:
parent
878f9fe3ea
commit
c596c6f672
2 changed files with 34 additions and 3 deletions
|
@ -22,6 +22,8 @@
|
||||||
<!-- Super Set of all possible WMO grib patterns -->
|
<!-- Super Set of all possible WMO grib patterns -->
|
||||||
<!-- Is specifically not restricting on CCCC since HPE isn't populating it -->
|
<!-- Is specifically not restricting on CCCC since HPE isn't populating it -->
|
||||||
<regex>^[EHLMOYZ][A-Z]{3}\d{2}</regex>
|
<regex>^[EHLMOYZ][A-Z]{3}\d{2}</regex>
|
||||||
|
<!-- Exclude Data Delivery specific patterns -->
|
||||||
|
<regexExclude>^LZ[ABC][ABC]9[123] KWBC</regexExclude>
|
||||||
|
|
||||||
<!-- ECMWF decrypted -->
|
<!-- ECMWF decrypted -->
|
||||||
<regex>ecmwf_decrypted</regex>
|
<regex>ecmwf_decrypted</regex>
|
||||||
|
|
|
@ -52,6 +52,7 @@ import com.raytheon.uf.common.serialization.ISerializableObject;
|
||||||
* for PatternSyntaxException.
|
* for PatternSyntaxException.
|
||||||
* Mar 19, 2013 1794 djohnson Add toString() for debugging.
|
* Mar 19, 2013 1794 djohnson Add toString() for debugging.
|
||||||
* Sep 10, 2013 2327 rjpeter Sized ArrayList declarations.
|
* Sep 10, 2013 2327 rjpeter Sized ArrayList declarations.
|
||||||
|
* Nov 21, 2013 2541 bgonzale Exclusion patterns.
|
||||||
* </pre>
|
* </pre>
|
||||||
*
|
*
|
||||||
* @author brockwoo
|
* @author brockwoo
|
||||||
|
@ -68,8 +69,17 @@ public class RequestPatterns implements ISerializableObject {
|
||||||
@XmlElements({ @XmlElement(name = "regex", type = String.class) })
|
@XmlElements({ @XmlElement(name = "regex", type = String.class) })
|
||||||
private List<String> patterns = new ArrayList<String>(0);
|
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> compiledPatterns = new ArrayList<Pattern>(0);
|
||||||
|
|
||||||
|
private List<Pattern> compiledExclusionPatterns = new ArrayList<Pattern>(0);
|
||||||
|
|
||||||
protected Log patternFailedLogger = LogFactory.getLog("PatternFailedLog");
|
protected Log patternFailedLogger = LogFactory.getLog("PatternFailedLog");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -112,7 +122,13 @@ public class RequestPatterns implements ISerializableObject {
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public void compilePatterns() {
|
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) {
|
for (String pattern : patterns) {
|
||||||
try {
|
try {
|
||||||
compiledPatterns.add(Pattern.compile(pattern));
|
compiledPatterns.add(Pattern.compile(pattern));
|
||||||
|
@ -123,24 +139,37 @@ public class RequestPatterns implements ISerializableObject {
|
||||||
patternFailedLogger.error(sb.toString(), e);
|
patternFailedLogger.error(sb.toString(), e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return compiledPatterns;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Takes a string and compares against the patterns in this container. The
|
* Takes a string and compares against the patterns in this container. The
|
||||||
* first one that matches breaks the search and returns true.
|
* first one that matches breaks the search and returns true.
|
||||||
*
|
*
|
||||||
|
* Check for exclusion first. It takes precedence over acceptance.
|
||||||
|
*
|
||||||
* @param header
|
* @param header
|
||||||
* The string to search for
|
* The string to search for
|
||||||
* @return a boolean indicating success
|
* @return a boolean indicating success
|
||||||
*/
|
*/
|
||||||
public boolean isDesiredHeader(String header) {
|
public boolean isDesiredHeader(String header) {
|
||||||
boolean isFound = false;
|
boolean isFound = false;
|
||||||
for (Pattern headerPattern : compiledPatterns) {
|
boolean isExcluded = false;
|
||||||
|
|
||||||
|
for (Pattern headerPattern : compiledExclusionPatterns) {
|
||||||
if (headerPattern.matcher(header).find()) {
|
if (headerPattern.matcher(header).find()) {
|
||||||
isFound = true;
|
isExcluded = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (!isExcluded) {
|
||||||
|
for (Pattern headerPattern : compiledPatterns) {
|
||||||
|
if (headerPattern.matcher(header).find()) {
|
||||||
|
isFound = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
return isFound;
|
return isFound;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue