Author: bfoster
Date: Sat Apr 19 09:54:37 2014
New Revision: 1588630
URL: http://svn.apache.org/r1588630
Log:
- Added new GenericEmailParser
Modified:
oodt/trunk/pushpull/src/main/java/org/apache/oodt/cas/pushpull/filerestrictions/parsers/GenericEmailParser.java
oodt/trunk/pushpull/src/main/resources/policy/ParserToRetrievalMethodMap.xml
oodt/trunk/pushpull/src/main/resources/push_pull_framework.properties
oodt/trunk/pushpull/src/test/org/apache/oodt/cas/pushpull/filerestrictions/parsers/GenericEmailParserTest.java
Modified:
oodt/trunk/pushpull/src/main/java/org/apache/oodt/cas/pushpull/filerestrictions/parsers/GenericEmailParser.java
URL:
http://svn.apache.org/viewvc/oodt/trunk/pushpull/src/main/java/org/apache/oodt/cas/pushpull/filerestrictions/parsers/GenericEmailParser.java?rev=1588630&r1=1588629&r2=1588630&view=diff
==============================================================================
---
oodt/trunk/pushpull/src/main/java/org/apache/oodt/cas/pushpull/filerestrictions/parsers/GenericEmailParser.java
(original)
+++
oodt/trunk/pushpull/src/main/java/org/apache/oodt/cas/pushpull/filerestrictions/parsers/GenericEmailParser.java
Sat Apr 19 09:54:37 2014
@@ -43,22 +43,31 @@ public class GenericEmailParser implemen
public static final String FILE_PATTERNS_PROPERTY_NAME =
"org.apache.oodt.cas.pushpull.generic.email.parser.file.pattern";
+ public static final String CHECK_FOR_PATTERN_PROPERTY_NAME =
+ "org.apache.oodt.cas.pushpull.generic.email.parser.check.for.pattern";
private final String filePattern;
+ private final String checkForPattern;
public GenericEmailParser() {
filePattern = loadFilePattern();
+ checkForPattern = loadCheckForPattern();
}
- public GenericEmailParser(String filePattern) {
+ public GenericEmailParser(String filePattern, String checkForPattern) {
this.filePattern = filePattern;
+ this.checkForPattern = checkForPattern;
}
@Override
public VirtualFileStructure parse(FileInputStream emailFile) throws
ParserException {
VirtualFile root = VirtualFile.createRootDir();
- List<String> filePaths = generateFilePaths(readEmail(emailFile));
+ String emailText = readEmail(emailFile);
+ if (!isValidEmail(emailText)) {
+ throw new ParserException("Failed to find check for pattern in email: "
+ checkForPattern);
+ }
+ List<String> filePaths = generateFilePaths(emailText);
for (String filePath : filePaths) {
new VirtualFile(root, filePath, false);
@@ -90,7 +99,17 @@ public class GenericEmailParser implemen
return filePaths;
}
+ private boolean isValidEmail(String emailText) {
+ Pattern pattern = Pattern.compile(checkForPattern);
+ Matcher m = pattern.matcher(emailText);
+ return m.find();
+ }
+
private String loadFilePattern() {
return System.getProperty(FILE_PATTERNS_PROPERTY_NAME);
}
+
+ private String loadCheckForPattern() {
+ return System.getProperty(CHECK_FOR_PATTERN_PROPERTY_NAME);
+ }
}
Modified:
oodt/trunk/pushpull/src/main/resources/policy/ParserToRetrievalMethodMap.xml
URL:
http://svn.apache.org/viewvc/oodt/trunk/pushpull/src/main/resources/policy/ParserToRetrievalMethodMap.xml?rev=1588630&r1=1588629&r2=1588630&view=diff
==============================================================================
---
oodt/trunk/pushpull/src/main/resources/policy/ParserToRetrievalMethodMap.xml
(original)
+++
oodt/trunk/pushpull/src/main/resources/policy/ParserToRetrievalMethodMap.xml
Sat Apr 19 09:54:37 2014
@@ -24,6 +24,7 @@
<rtvlMethod
class="org.apache.oodt.cas.pushpull.retrievalmethod.ListRetriever">
<parser
class="org.apache.oodt.cas.pushpull.filerestrictions.parsers.FileListParser"/>
<parser
class="org.apache.oodt.cas.pushpull.filerestrictions.parsers.ClassNoaaEmailParser"/>
+ <parser
class="org.apache.oodt.cas.pushpull.filerestrictions.parsers.GenericEmailParser"/>
</rtvlMethod>
</rtvlMethods>
Modified: oodt/trunk/pushpull/src/main/resources/push_pull_framework.properties
URL:
http://svn.apache.org/viewvc/oodt/trunk/pushpull/src/main/resources/push_pull_framework.properties?rev=1588630&r1=1588629&r2=1588630&view=diff
==============================================================================
--- oodt/trunk/pushpull/src/main/resources/push_pull_framework.properties
(original)
+++ oodt/trunk/pushpull/src/main/resources/push_pull_framework.properties Sat
Apr 19 09:54:37 2014
@@ -98,3 +98,6 @@ org.apache.oodt.cas.pushpull.file.retrie
org.apache.oodt.cas.pushpull.allow.only.defined.types=true
org.apache.oodt.cas.pushpull.filerestrictions.parsers.class.noaa.email.parser.contains.exprs=CLASS\
has\ processed,anonymous
+
+org.apache.oodt.cas.pushpull.generic.email.parser.file.pattern=Wav File:
([^\\s]+)
+org.apache.oodt.cas.pushpull.generic.email.parser.check.for.pattern=Pattern to
valid email has expected text
Modified:
oodt/trunk/pushpull/src/test/org/apache/oodt/cas/pushpull/filerestrictions/parsers/GenericEmailParserTest.java
URL:
http://svn.apache.org/viewvc/oodt/trunk/pushpull/src/test/org/apache/oodt/cas/pushpull/filerestrictions/parsers/GenericEmailParserTest.java?rev=1588630&r1=1588629&r2=1588630&view=diff
==============================================================================
---
oodt/trunk/pushpull/src/test/org/apache/oodt/cas/pushpull/filerestrictions/parsers/GenericEmailParserTest.java
(original)
+++
oodt/trunk/pushpull/src/test/org/apache/oodt/cas/pushpull/filerestrictions/parsers/GenericEmailParserTest.java
Sat Apr 19 09:54:37 2014
@@ -55,10 +55,18 @@ public class GenericEmailParserTest {
@Test
public void testGenericEmailParser() throws ParserException,
FileNotFoundException {
- GenericEmailParser parser = new GenericEmailParser("Wav File: ([^\\s]+)");
+ GenericEmailParser parser = new GenericEmailParser(
+ "Wav File: ([^\\s]+)", "Dear Lousy Customer,");
VirtualFileStructure vfs = parser.parse(new FileInputStream(emailFile));
List<String> filePaths =
FileRestrictions.toStringList(vfs.getRootVirtualFile());
assertThat(filePaths.size(), Matchers.is(1));
assertThat(filePaths.get(0), Matchers.is("/some/path/to/a/wav/file.wav"));
}
+
+ @Test (expected = ParserException.class)
+ public void testFailedValidEmailCheck() throws ParserException,
FileNotFoundException {
+ GenericEmailParser parser = new GenericEmailParser(
+ "Wav File: ([^\\s]+)", "Phrase Not Found");
+ parser.parse(new FileInputStream(emailFile));
+ }
}