streams-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sblack...@apache.org
Subject svn commit: r1556893 [8/25] - in /incubator/streams/branches/sblackmon: ./ streams-config-graph/ streams-config-graph/src/ streams-config-graph/src/main/ streams-config-graph/src/main/java/ streams-config-graph/src/main/java/org/ streams-config-graph/s...
Date Thu, 09 Jan 2014 17:27:58 GMT
Added: incubator/streams/branches/sblackmon/streams-contrib/streams-provider-gnip/gnip-edc-googleplus/pom.xml
URL: http://svn.apache.org/viewvc/incubator/streams/branches/sblackmon/streams-contrib/streams-provider-gnip/gnip-edc-googleplus/pom.xml?rev=1556893&view=auto
==============================================================================
--- incubator/streams/branches/sblackmon/streams-contrib/streams-provider-gnip/gnip-edc-googleplus/pom.xml
(added)
+++ incubator/streams/branches/sblackmon/streams-contrib/streams-provider-gnip/gnip-edc-googleplus/pom.xml
Thu Jan  9 17:27:50 2014
@@ -0,0 +1,133 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <parent>
+        <groupId>org.apache.streams</groupId>
+        <artifactId>streams-provider-gnip</artifactId>
+        <version>0.1-SNAPSHOT</version>
+    </parent>
+    <modelVersion>4.0.0</modelVersion>
+
+    <artifactId>gnip-edc-googleplus</artifactId>
+
+    <dependencies>
+
+        <dependency>
+            <groupId>org.jsonschema2pojo</groupId>
+            <artifactId>jsonschema2pojo-core</artifactId>
+
+            <type>jar</type>
+            <scope>compile</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>com.fasterxml.jackson.core</groupId>
+            <artifactId>jackson-core</artifactId>
+            <version>2.1.1</version>
+        </dependency>
+
+        <dependency>
+            <groupId>com.fasterxml.jackson.dataformat</groupId>
+            <artifactId>jackson-dataformat-xml</artifactId>
+            <version>${jackson.version}</version>
+        </dependency>
+
+        <dependency>
+            <groupId>com.fasterxml</groupId>
+            <artifactId>jackson-xml-databind</artifactId>
+            <version>0.5.0</version>
+        </dependency>
+
+        <dependency>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+            <version>4.11</version>
+            <scope>test</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>org.slf4j</groupId>
+            <artifactId>slf4j-api</artifactId>
+            <version>1.6.1</version>
+        </dependency>
+
+        <dependency>
+            <groupId>ch.qos.logback</groupId>
+            <artifactId>logback-classic</artifactId>
+            <version>1.0.9</version>
+        </dependency>
+
+        <dependency>
+            <groupId>org.json</groupId>
+            <artifactId>json</artifactId>
+            <version>20090211</version>
+        </dependency>
+
+        <dependency>
+            <groupId>org.apache.streams</groupId>
+            <artifactId>streams-pojo</artifactId>
+            <version>0.1-SNAPSHOT</version>
+        </dependency>
+
+        <dependency>
+            <groupId>org.apache.streams</groupId>
+            <artifactId>gnip-powertrack</artifactId>
+            <version>0.1-SNAPSHOT</version>
+        </dependency>
+    </dependencies>
+
+    <build>
+        <sourceDirectory>src/main/java</sourceDirectory>
+        <testSourceDirectory>src/test/java</testSourceDirectory>
+        <resources>
+            <resource>
+                <directory>src/main/resources</directory>
+            </resource>
+        </resources>
+        <testResources>
+            <testResource>
+                <directory>src/test/resources</directory>
+            </testResource>
+        </testResources>
+        <plugins>
+            <plugin>
+                <artifactId>maven-clean-plugin</artifactId>
+                <version>2.5</version>
+                <configuration>
+                    <filesets>
+                        <fileset>
+                            <directory>target</directory>
+                            <includes>
+                                <include>**/*</include>
+                            </includes>
+                        </fileset>
+                    </filesets>
+                </configuration>
+            </plugin>
+            <!--<plugin>-->
+            <!--<groupId>org.jsonschema2pojo</groupId>-->
+            <!--<artifactId>jsonschema2pojo-maven-plugin</artifactId>-->
+            <!---->
+            <!--<configuration>-->
+            <!--<addCompileSourceRoot>true</addCompileSourceRoot>-->
+            <!--<generateBuilders>true</generateBuilders>-->
+            <!--<sourcePaths>-->
+            <!--<sourcePath>src/main/jsonschema/com/reddit</sourcePath>-->
+            <!--</sourcePaths>-->
+            <!--<outputDirectory>src/main/java</outputDirectory>-->
+            <!--<targetPackage>org.apache.streams</targetPackage>-->
+            <!--<useLongIntegers>true</useLongIntegers>-->
+            <!--<useJodaDates>false</useJodaDates>-->
+            <!--</configuration>-->
+            <!--<executions>-->
+            <!--<execution>-->
+            <!--<goals>-->
+            <!--<goal>generate</goal>-->
+            <!--</goals>-->
+            <!--</execution>-->
+            <!--</executions>-->
+            <!--</plugin>-->
+        </plugins>
+    </build>
+</project>
\ No newline at end of file

Added: incubator/streams/branches/sblackmon/streams-contrib/streams-provider-gnip/gnip-edc-googleplus/src/main/java/com/gplus/api/GPlusActivitySerializer.java
URL: http://svn.apache.org/viewvc/incubator/streams/branches/sblackmon/streams-contrib/streams-provider-gnip/gnip-edc-googleplus/src/main/java/com/gplus/api/GPlusActivitySerializer.java?rev=1556893&view=auto
==============================================================================
--- incubator/streams/branches/sblackmon/streams-contrib/streams-provider-gnip/gnip-edc-googleplus/src/main/java/com/gplus/api/GPlusActivitySerializer.java
(added)
+++ incubator/streams/branches/sblackmon/streams-contrib/streams-provider-gnip/gnip-edc-googleplus/src/main/java/com/gplus/api/GPlusActivitySerializer.java
Thu Jan  9 17:27:50 2014
@@ -0,0 +1,75 @@
+package com.gplus.api;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import org.apache.commons.lang.NotImplementedException;
+import org.apache.streams.data.ActivitySerializer;
+import org.apache.streams.data.util.ActivityUtil;
+import org.apache.streams.gnip.powertrack.GnipActivityFixer;
+import org.apache.streams.pojo.json.Activity;
+import org.json.JSONObject;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Created with IntelliJ IDEA.
+ * User: mdelaet
+ * Date: 8/30/13
+ * Time: 10:48 AM
+ * To change this template use File | Settings | File Templates.
+ */
+public class GPlusActivitySerializer implements ActivitySerializer {
+    private final static Logger LOGGER = LoggerFactory.getLogger(GPlusActivitySerializer.class);
+
+    @Override
+    public String serializationFormat() {
+        return "application/gplus+xml";
+    }
+
+    @Override
+    public String serialize(Activity deserialized) {
+        ObjectMapper jsonMapper = new ObjectMapper();
+        String jsonString = new String();
+        try{
+            jsonString = jsonMapper.writeValueAsString(deserialized);
+        }catch(Exception e){
+            LOGGER.error("Exception serializing Activity Object: " + e);
+        }
+        return jsonString;  //To change body of implemented methods use File | Settings |
File Templates.
+    }
+
+    @Override
+    public Activity deserialize(String serialized) {
+        ObjectMapper jsonMapper = new ObjectMapper();
+        JSONObject jsonObject = new JSONObject();
+        JSONObject fixedObject = new JSONObject();
+
+        try{
+            jsonObject = new JSONObject(serialized);
+            fixedObject = GnipActivityFixer.fix(jsonObject);
+        }catch(Exception e){
+            LOGGER.error("Exception deserializing string: " + e);
+        }
+
+        Activity activity = new Activity();
+        try {
+            activity = jsonMapper.readValue(fixedObject.toString(), Activity.class);
+            Map<String, Object> extension = ActivityUtil.ensureExtensions(activity);
+            extension.put("likes", fixedObject.getJSONObject("object").getJSONObject("plusoners").get("totalItems"));
+            extension.put("rebroadcast", fixedObject.getJSONObject("object").getJSONObject("resharers").get("totalItems"));
+        } catch( Exception e ) {
+            LOGGER.error(jsonObject.toString());
+            LOGGER.error(fixedObject.toString());
+            e.printStackTrace();
+        }
+        return activity;
+    }
+
+    @Override
+    public List<Activity> deserializeAll(String serializedList) {
+        //TODO Support
+        throw new NotImplementedException("Not currently supported by this deserializer");
+    }
+}

Added: incubator/streams/branches/sblackmon/streams-contrib/streams-provider-gnip/gnip-edc-googleplus/src/test/java/com/gplus/api/GPlusEDCAsActivityTest.java
URL: http://svn.apache.org/viewvc/incubator/streams/branches/sblackmon/streams-contrib/streams-provider-gnip/gnip-edc-googleplus/src/test/java/com/gplus/api/GPlusEDCAsActivityTest.java?rev=1556893&view=auto
==============================================================================
--- incubator/streams/branches/sblackmon/streams-contrib/streams-provider-gnip/gnip-edc-googleplus/src/test/java/com/gplus/api/GPlusEDCAsActivityTest.java
(added)
+++ incubator/streams/branches/sblackmon/streams-contrib/streams-provider-gnip/gnip-edc-googleplus/src/test/java/com/gplus/api/GPlusEDCAsActivityTest.java
Thu Jan  9 17:27:50 2014
@@ -0,0 +1,80 @@
+package com.gplus.api;
+
+import com.fasterxml.jackson.databind.DeserializationFeature;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.dataformat.xml.XmlMapper;
+import org.apache.streams.pojo.json.Activity;
+import org.junit.Assert;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.BufferedReader;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+
+/**
+ * Created with IntelliJ IDEA.
+ * User: mdelaet
+ * Date: 8/28/13
+ * Time: 2:53 PM
+ * To change this template use File | Settings | File Templates.
+ */
+public class GPlusEDCAsActivityTest {
+    private final static Logger LOGGER = LoggerFactory.getLogger(GPlusEDCAsActivityTest.class);
+
+    private ObjectMapper jsonMapper;
+    XmlMapper xmlMapper;
+    private GPlusActivitySerializer gplusSerializer;
+
+    public GPlusEDCAsActivityTest() {
+        gplusSerializer = new GPlusActivitySerializer();
+        jsonMapper = new ObjectMapper();
+        xmlMapper = new XmlMapper();
+    }
+
+    @Test
+    public void Tests()   throws Exception
+    {
+        InputStream is = GPlusEDCAsActivityTest.class.getResourceAsStream("/GPlusEDCFixed.json");
+        if(is == null) System.out.println("null");
+        InputStreamReader isr = new InputStreamReader(is);
+        BufferedReader br = new BufferedReader(isr);
+        xmlMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, Boolean.FALSE);
+        xmlMapper.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, Boolean.TRUE);
+        xmlMapper.configure(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT, Boolean.TRUE);
+        jsonMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, Boolean.FALSE);
+        jsonMapper.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, Boolean.TRUE);
+        jsonMapper.configure(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT, Boolean.TRUE);
+
+        try {
+            while (br.ready()) {
+                String line = br.readLine();
+
+                Activity activity = null;
+                try {
+                    activity = gplusSerializer.deserialize(line);
+                } catch( Exception e ) {
+                    LOGGER.error(line);
+                    e.printStackTrace();
+                    Assert.fail("Exception on gplus Serializer.deserialize(jsonString) :
" + e);
+                }
+
+                try {
+                    String activityString = gplusSerializer.serialize(activity);
+                    LOGGER.debug(activityString);
+                } catch (Exception e ){
+                    LOGGER.error(activity.toString());
+                    e.printStackTrace();
+                    Assert.fail("Exception on gplus Serializer.serialize(activity) : " +
e);
+                }
+
+            }
+        } catch( Exception e ) {
+            System.out.println("Exception: " + e);
+            LOGGER.error(e.getMessage());
+            Assert.fail("");
+        }
+    }
+
+}



Mime
View raw message