streams-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sblack...@apache.org
Subject [08/10] incubator-streams git commit: improved configuration scheme
Date Sun, 16 Nov 2014 00:56:26 GMT
improved configuration scheme


Project: http://git-wip-us.apache.org/repos/asf/incubator-streams/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-streams/commit/a24b3be7
Tree: http://git-wip-us.apache.org/repos/asf/incubator-streams/tree/a24b3be7
Diff: http://git-wip-us.apache.org/repos/asf/incubator-streams/diff/a24b3be7

Branch: refs/heads/STREAMS-68,218
Commit: a24b3be723dbc7ccca7f34cc0f58ae8bb8838470
Parents: 93026a7
Author: Steve Blackmon <sblackmon@w2odigital.com>
Authored: Sat Nov 15 18:34:32 2014 -0600
Committer: Steve Blackmon <sblackmon@w2odigital.com>
Committed: Sat Nov 15 18:34:32 2014 -0600

----------------------------------------------------------------------
 streams-components/streams-converters/pom.xml   | 54 ++++++++++++++++++++
 .../converter/ActivityConverterProcessor.java   | 50 +++++++++++++-----
 .../streams/twitter/test/FullTweetTest.java     | 14 ++---
 .../streams/data/ActivityConverterResolver.java |  5 ++
 .../apache/streams/data/DocumentClassifier.java |  9 ++--
 5 files changed, 108 insertions(+), 24 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-streams/blob/a24b3be7/streams-components/streams-converters/pom.xml
----------------------------------------------------------------------
diff --git a/streams-components/streams-converters/pom.xml b/streams-components/streams-converters/pom.xml
index cf990cb..78f42b9 100644
--- a/streams-components/streams-converters/pom.xml
+++ b/streams-components/streams-converters/pom.xml
@@ -80,6 +80,60 @@
         </testResources>
         <plugins>
 
+            <plugin>
+                <groupId>org.codehaus.mojo</groupId>
+                <artifactId>build-helper-maven-plugin</artifactId>
+                <version>1.8</version>
+                <executions>
+                    <execution>
+                        <id>add-source</id>
+                        <phase>generate-sources</phase>
+                        <goals>
+                            <goal>add-source</goal>
+                        </goals>
+                        <configuration>
+                            <sources>
+                                <source>target/generated-sources/jsonschema2pojo</source>
+                            </sources>
+                        </configuration>
+                    </execution>
+                    <execution>
+                        <id>add-source-jaxb2</id>
+                        <phase>generate-sources</phase>
+                        <goals>
+                            <goal>add-source</goal>
+                        </goals>
+                        <configuration>
+                            <sources>
+                                <source>target/generated-sources/jaxb2</source>
+                            </sources>
+                        </configuration>
+                    </execution>
+                </executions>
+            </plugin>
+            <plugin>
+                <groupId>org.jsonschema2pojo</groupId>
+                <artifactId>jsonschema2pojo-maven-plugin</artifactId>
+                <configuration>
+                    <addCompileSourceRoot>true</addCompileSourceRoot>
+                    <generateBuilders>true</generateBuilders>
+                    <sourcePaths>
+                        <sourcePath>src/main/jsonschema</sourcePath>
+                    </sourcePaths>
+                    <outputDirectory>target/generated-sources/jsonschema2pojo</outputDirectory>
+                    <targetPackage>org.apache.streams.converter</targetPackage>
+                    <useLongIntegers>true</useLongIntegers>
+                    <useJodaDates>true</useJodaDates>
+                    <includeJsr303Annotations>true</includeJsr303Annotations>
+                </configuration>
+                <executions>
+                    <execution>
+                        <goals>
+                            <goal>generate</goal>
+                        </goals>
+                    </execution>
+                </executions>
+            </plugin>
         </plugins>
     </build>
 

http://git-wip-us.apache.org/repos/asf/incubator-streams/blob/a24b3be7/streams-components/streams-converters/src/main/java/org/apache/streams/converter/ActivityConverterProcessor.java
----------------------------------------------------------------------
diff --git a/streams-components/streams-converters/src/main/java/org/apache/streams/converter/ActivityConverterProcessor.java
b/streams-components/streams-converters/src/main/java/org/apache/streams/converter/ActivityConverterProcessor.java
index 629f979..521c906 100644
--- a/streams-components/streams-converters/src/main/java/org/apache/streams/converter/ActivityConverterProcessor.java
+++ b/streams-components/streams-converters/src/main/java/org/apache/streams/converter/ActivityConverterProcessor.java
@@ -38,21 +38,22 @@ public class ActivityConverterProcessor extends TypeConverterProcessor
{
 
     private final static Logger LOGGER = LoggerFactory.getLogger(ActivityConverterProcessor.class);
 
+    protected ActivityConverterProcessorConfiguration configuration;
+
     private List<DocumentClassifier> classifiers;
     private List<ActivityConverterResolver> resolvers;
 
     public ActivityConverterProcessor() {
         super(Activity.class);
-        this.classifiers = Lists.newArrayList((DocumentClassifier)BaseDocumentClassifier.getInstance());
-        this.resolvers = Lists.newArrayList((ActivityConverterResolver) BaseActivityConverterResolver.getInstance());
+        this.classifiers = Lists.newArrayList();
+        this.resolvers = Lists.newArrayList();
     }
 
-    public ActivityConverterProcessor(List<DocumentClassifier> classifiers, List<ActivityConverterResolver>
factories) {
+    public ActivityConverterProcessor(ActivityConverterProcessorConfiguration configuration)
{
         super(Activity.class);
-        this.classifiers = classifiers;
-        this.resolvers = factories;
-        this.classifiers.add(BaseDocumentClassifier.getInstance());
-        this.resolvers.add(BaseActivityConverterResolver.getInstance());
+        this.configuration = configuration;
+        this.classifiers = Lists.newArrayList();
+        this.resolvers = Lists.newArrayList();
     }
 
     @Override
@@ -75,7 +76,12 @@ public class ActivityConverterProcessor extends TypeConverterProcessor
{
             }
 
             //Preconditions.checkNotNull(datumClass);
-            if( datumClass == null) return result;
+            if( datumClass == null) {
+                LOGGER.warn("Unable to classify");
+                return result;
+            } else {
+                LOGGER.debug("Classifies document as " + datumClass.getSimpleName());
+            }
 
             // This implementation is primitive, greedy, takes first it can resolve
             Class converterClass = null;
@@ -86,7 +92,13 @@ public class ActivityConverterProcessor extends TypeConverterProcessor
{
             }
 
             //Preconditions.checkNotNull(converterClass);
-            if( converterClass == null) return result;
+            if( converterClass == null) {
+                LOGGER.warn("Unable to resolve converterClass");
+                return result;
+            }
+            else {
+                LOGGER.debug("Resolved converter: " + converterClass.getSimpleName());
+            }
 
             ActivityConverter converter = ActivityConverterFactory.getInstance(converterClass);
 
@@ -100,12 +112,18 @@ public class ActivityConverterProcessor extends TypeConverterProcessor
{
                 typedDoc = TypeConverterUtil.convert(inDoc, datumClass, mapper);
 
             //Preconditions.checkNotNull(typedDoc);
-            if( typedDoc == null) return result;
+            if( typedDoc == null) {
+                LOGGER.warn("Unable to convert " + inDoc.getClass().getSimpleName() + " to
" + datumClass.getSimpleName());
+                return result;
+            }
 
             Activity activity = converter.deserialize(typedDoc);
 
             //Preconditions.checkNotNull(activity);
-            if( activity == null) return result;
+            if( activity == null) {
+                LOGGER.warn("Unable to convert " + datumClass.getClass().getCanonicalName()
+ " to Activity");
+                return result;
+            }
 
             entry.setDocument(activity);
 
@@ -123,8 +141,14 @@ public class ActivityConverterProcessor extends TypeConverterProcessor
{
     @Override
     public void prepare(Object configurationObject) {
         super.prepare(configurationObject);
-        Preconditions.checkArgument(classifiers.size() > 0);
-        Preconditions.checkArgument(resolvers.size() > 0);
+        if( configuration != null ) {
+            if (configuration.getClassifiers() != null && configuration.getClassifiers().size()
> 0)
+                this.classifiers.addAll(configuration.getClassifiers());
+            if (configuration.getResolvers() != null && configuration.getResolvers().size()
> 0)
+                this.resolvers.addAll(configuration.getResolvers());
+        }
+        this.classifiers.add(BaseDocumentClassifier.getInstance());
+        this.resolvers.add(BaseActivityConverterResolver.getInstance());
     }
 
 };

http://git-wip-us.apache.org/repos/asf/incubator-streams/blob/a24b3be7/streams-contrib/streams-provider-twitter/src/test/java/org/apache/streams/twitter/test/FullTweetTest.java
----------------------------------------------------------------------
diff --git a/streams-contrib/streams-provider-twitter/src/test/java/org/apache/streams/twitter/test/FullTweetTest.java
b/streams-contrib/streams-provider-twitter/src/test/java/org/apache/streams/twitter/test/FullTweetTest.java
index a661f2c..63dcf51 100644
--- a/streams-contrib/streams-provider-twitter/src/test/java/org/apache/streams/twitter/test/FullTweetTest.java
+++ b/streams-contrib/streams-provider-twitter/src/test/java/org/apache/streams/twitter/test/FullTweetTest.java
@@ -23,18 +23,16 @@ import com.fasterxml.jackson.databind.ObjectMapper;
 import com.fasterxml.jackson.databind.node.ObjectNode;
 import com.google.common.collect.Lists;
 import org.apache.streams.converter.ActivityConverterProcessor;
+import org.apache.streams.converter.ActivityConverterProcessorConfiguration;
 import org.apache.streams.core.StreamsDatum;
 import org.apache.streams.data.ActivityConverterResolver;
 import org.apache.streams.data.DocumentClassifier;
-import org.apache.streams.exceptions.ActivitySerializerException;
 import org.apache.streams.jackson.StreamsJacksonMapper;
 import org.apache.streams.pojo.json.Activity;
 import org.apache.streams.twitter.pojo.Retweet;
-import org.apache.streams.twitter.pojo.Tweet;
 import org.apache.streams.twitter.serializer.StreamsTwitterMapper;
 import org.apache.streams.twitter.serializer.TwitterConverterResolver;
 import org.apache.streams.twitter.serializer.TwitterDocumentClassifier;
-import org.apache.streams.twitter.serializer.TwitterJsonActivityConverter;
 import org.junit.Assert;
 import org.junit.Test;
 import org.slf4j.Logger;
@@ -95,10 +93,12 @@ public class FullTweetTest {
 
         Activity activity = null;
         try {
-            ActivityConverterProcessor converter = new ActivityConverterProcessor(
-                    Lists.newArrayList((DocumentClassifier)TwitterDocumentClassifier.getInstance()),
-                    Lists.newArrayList((ActivityConverterResolver)TwitterConverterResolver.getInstance()));
-            converter.prepare(null);
+            ActivityConverterProcessorConfiguration converterProcessorConfiguration = new
ActivityConverterProcessorConfiguration()
+                    .withClassifiers(Lists.newArrayList((DocumentClassifier)TwitterDocumentClassifier.getInstance()))
+                    .withResolvers(Lists.newArrayList((ActivityConverterResolver)TwitterConverterResolver.getInstance()));
+
+            ActivityConverterProcessor converter = new ActivityConverterProcessor(converterProcessorConfiguration);
+            converter.prepare(converterProcessorConfiguration);
             List<StreamsDatum> result = converter.process(new StreamsDatum(TWITTER_JSON));
             activity = (Activity)result.get(0).getDocument();
         } catch (Throwable e) {

http://git-wip-us.apache.org/repos/asf/incubator-streams/blob/a24b3be7/streams-pojo/src/main/java/org/apache/streams/data/ActivityConverterResolver.java
----------------------------------------------------------------------
diff --git a/streams-pojo/src/main/java/org/apache/streams/data/ActivityConverterResolver.java
b/streams-pojo/src/main/java/org/apache/streams/data/ActivityConverterResolver.java
index f4d7a92..84f098a 100644
--- a/streams-pojo/src/main/java/org/apache/streams/data/ActivityConverterResolver.java
+++ b/streams-pojo/src/main/java/org/apache/streams/data/ActivityConverterResolver.java
@@ -27,6 +27,11 @@ import java.io.Serializable;
  */
 public interface ActivityConverterResolver extends Serializable {
 
+    /*
+      Every implementing class should have a static getInstance() method
+      But java 7 does not allow the interface to require that
+     */
+
     /**
      * Identifies a class that con convert this document to an activity
      *

http://git-wip-us.apache.org/repos/asf/incubator-streams/blob/a24b3be7/streams-pojo/src/main/java/org/apache/streams/data/DocumentClassifier.java
----------------------------------------------------------------------
diff --git a/streams-pojo/src/main/java/org/apache/streams/data/DocumentClassifier.java b/streams-pojo/src/main/java/org/apache/streams/data/DocumentClassifier.java
index ea0055f..3c6b5e5 100644
--- a/streams-pojo/src/main/java/org/apache/streams/data/DocumentClassifier.java
+++ b/streams-pojo/src/main/java/org/apache/streams/data/DocumentClassifier.java
@@ -18,17 +18,18 @@
 
 package org.apache.streams.data;
 
-import org.apache.streams.exceptions.ActivitySerializerException;
-import org.apache.streams.pojo.json.Activity;
-
 import java.io.Serializable;
-import java.util.List;
 
 /**
  * Serializes and deserializes Activities
  */
 public interface DocumentClassifier extends Serializable {
 
+    /*
+      Every implementing class should have a static getInstance() method
+      But java 7 does not allow the interface to require that
+     */
+
     /**
      * Gets the supported content type that can be deserialized/serialized
      *


Mime
View raw message