Return-Path: X-Original-To: apmail-streams-commits-archive@minotaur.apache.org Delivered-To: apmail-streams-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id F23A910C48 for ; Thu, 9 Jan 2014 17:30:31 +0000 (UTC) Received: (qmail 4556 invoked by uid 500); 9 Jan 2014 17:29:12 -0000 Delivered-To: apmail-streams-commits-archive@streams.apache.org Received: (qmail 4405 invoked by uid 500); 9 Jan 2014 17:29:06 -0000 Mailing-List: contact commits-help@streams.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@streams.incubator.apache.org Delivered-To: mailing list commits@streams.incubator.apache.org Received: (qmail 4116 invoked by uid 99); 9 Jan 2014 17:28:57 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 09 Jan 2014 17:28:57 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 09 Jan 2014 17:28:54 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 43CAC2388B34; Thu, 9 Jan 2014 17:28:07 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1556893 [10/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/... Date: Thu, 09 Jan 2014 17:27:58 -0000 To: commits@streams.incubator.apache.org From: sblackmon@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20140109172807.43CAC2388B34@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Added: incubator/streams/branches/sblackmon/streams-contrib/streams-provider-gnip/gnip-edc-instagram/pom.xml URL: http://svn.apache.org/viewvc/incubator/streams/branches/sblackmon/streams-contrib/streams-provider-gnip/gnip-edc-instagram/pom.xml?rev=1556893&view=auto ============================================================================== --- incubator/streams/branches/sblackmon/streams-contrib/streams-provider-gnip/gnip-edc-instagram/pom.xml (added) +++ incubator/streams/branches/sblackmon/streams-contrib/streams-provider-gnip/gnip-edc-instagram/pom.xml Thu Jan 9 17:27:50 2014 @@ -0,0 +1,96 @@ + + + + org.apache.streams + streams-provider-gnip + 0.1-SNAPSHOT + + 4.0.0 + + gnip-edc-instagram + + + + + com.fasterxml.jackson.core + jackson-core + + + com.fasterxml.jackson.core + jackson-annotations + + + org.jsonschema2pojo + jsonschema2pojo-core + + + org.slf4j + slf4j-api + + + junit + junit + + + + + + src/test/java + + + src/main/resources + + + + + src/test/resources + + + + + org.codehaus.mojo + build-helper-maven-plugin + 1.8 + + + add-source + generate-sources + + add-source + + + + target/generated-sources/jsonschema2pojo/**/*.java + + + + + + + org.jsonschema2pojo + jsonschema2pojo-maven-plugin + + true + true + + src/main/jsonschema/com/instagram + + target/generated-sources/jsonschema2pojo + com.instagram + true + false + + + + + generate + + + + + + + + \ No newline at end of file Added: incubator/streams/branches/sblackmon/streams-contrib/streams-provider-gnip/gnip-edc-instagram/src/main/jsonschema/com/instagram/Instagram.json URL: http://svn.apache.org/viewvc/incubator/streams/branches/sblackmon/streams-contrib/streams-provider-gnip/gnip-edc-instagram/src/main/jsonschema/com/instagram/Instagram.json?rev=1556893&view=auto ============================================================================== --- incubator/streams/branches/sblackmon/streams-contrib/streams-provider-gnip/gnip-edc-instagram/src/main/jsonschema/com/instagram/Instagram.json (added) +++ incubator/streams/branches/sblackmon/streams-contrib/streams-provider-gnip/gnip-edc-instagram/src/main/jsonschema/com/instagram/Instagram.json Thu Jan 9 17:27:50 2014 @@ -0,0 +1,204 @@ +{ + "type": "object", + "$schema": "http://json-schema.org/draft-03/schema", + "id": "#", + "javaType" : "com.instagram.pojo.Instagram", + "properties": { + "caption": { + "type": "object", + "properties": { + "created_time": { + "format": "utc-millisec", + "type": "string" + }, + "from": { + "$ref": "#/properties/user" + }, + "id": { + "type": "string" + }, + "text": { + "type": "string" + } + } + }, + "comments": { + "type": "object", + "properties": { + "count": { + "type": "integer" + }, + "data": { + "type": "array", + "items": { + "type": "object", + "javaType" : "com.instagram.pojo.Comment", + "properties": { + "created_time": { + "format": "utc-millisec", + "type": "string" + }, + "from": { + "$ref": "#/properties/user" + }, + "id": { + "type": "string" + }, + "text": { + "type": "string" + } + } + } + } + } + }, + "created_time": { + "format": "utc-millisec", + "type": "string" + }, + "filter": { + "type": "string" + }, + "id": { + "type": "string" + }, + "images": { + "type": "object", + "properties": { + "low_resolution": { + "type": "object", + "javaType" : "com.instagram.pojo.Media", + "properties": { + "height": { + "type": "integer" + }, + "url": { + "format": "uri", + "type": "string" + }, + "width": { + "type": "integer" + } + } + }, + "standard_resolution": { + "$ref": "#/properties/images/properties/low_resolution" + }, + "thumbnail": { + "$ref": "#/properties/images/properties/low_resolution" + } + } + }, + "likes": { + "type": "object", + "properties": { + "count": { + "type": "integer" + }, + "data": { + "type": "array", + "items": { + "$ref": "#/properties/user" + } + } + } + }, + "link": { + "format": "uri", + "type": "string" + }, + "location": { + "type": "object", + "properties": { + "latitude": { + "type": "number" + }, + "longitude": { + "type": "number" + }, + "id": { + "type": "string" + }, + "street_address": { + "type": "string" + }, + "name": { + "type": "string" + } + } + }, + "tags": { + "type": "array", + "items": { + "type": "string" + } + }, + "type": { + "type": "string" + }, + "user": { + "type": "object", + "javaType" : "com.instagram.pojo.User", + "properties": { + "bio": { + "type": "string" + }, + "full_name": { + "type": "string" + }, + "id": { + "type": "string" + }, + "profile_picture": { + "format": "uri", + "type": "string" + }, + "username": { + "type": "string" + }, + "website": { + "format": "uri", + "type": "string" + } + } + }, + "user_has_liked": { + "type": "boolean" + }, + "users_in_photo": { + "type": "array", + "items": { + "type": "object", + "javaType" : "com.instagram.pojo.UserPosition", + "properties": { + "user": { + "$ref": "#/properties/user" + }, + "position": { + "type": "object", + "javaType" : "com.instagram.pojo.Position", + "properties": { + "x": { + "type": "number" + }, + "y": { + "type": "number" + } + } + } + } + } + }, + "videos": { + "type": "object", + "properties": { + "low_resolution": { + "$ref": "#/properties/images/properties/low_resolution" + }, + "standard_resolution": { + "$ref": "#/properties/images/properties/low_resolution" + } + } + } + } +} Added: incubator/streams/branches/sblackmon/streams-contrib/streams-provider-gnip/gnip-edc-instagram/src/test/java/com/instagram/test/InstagramSerDeTest.java URL: http://svn.apache.org/viewvc/incubator/streams/branches/sblackmon/streams-contrib/streams-provider-gnip/gnip-edc-instagram/src/test/java/com/instagram/test/InstagramSerDeTest.java?rev=1556893&view=auto ============================================================================== --- incubator/streams/branches/sblackmon/streams-contrib/streams-provider-gnip/gnip-edc-instagram/src/test/java/com/instagram/test/InstagramSerDeTest.java (added) +++ incubator/streams/branches/sblackmon/streams-contrib/streams-provider-gnip/gnip-edc-instagram/src/test/java/com/instagram/test/InstagramSerDeTest.java Thu Jan 9 17:27:50 2014 @@ -0,0 +1,47 @@ +package com.instagram.test; + +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.instagram.pojo.Instagram; +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; + +public class InstagramSerDeTest { + + private final static Logger LOGGER = LoggerFactory.getLogger(InstagramSerDeTest.class); + + private ObjectMapper mapper = new ObjectMapper(); + + @Test + public void Tests() + { + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, Boolean.TRUE); + mapper.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, Boolean.TRUE); + mapper.configure(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT, Boolean.TRUE); + + InputStream is = InstagramSerDeTest.class.getResourceAsStream("/instagram_jsons.txt"); + InputStreamReader isr = new InputStreamReader(is); + BufferedReader br = new BufferedReader(isr); + + try { + while (br.ready()) { + String line = br.readLine(); + LOGGER.debug(line); + + Instagram ser = mapper.readValue(line, Instagram.class); + + String des = mapper.writeValueAsString(ser); + LOGGER.debug(des); + } + } catch( Exception e ) { + e.printStackTrace(); + Assert.fail(); + } + } +} Added: incubator/streams/branches/sblackmon/streams-contrib/streams-provider-gnip/gnip-edc-instagram/src/test/resources/instagram_jsons.txt URL: http://svn.apache.org/viewvc/incubator/streams/branches/sblackmon/streams-contrib/streams-provider-gnip/gnip-edc-instagram/src/test/resources/instagram_jsons.txt?rev=1556893&view=auto ============================================================================== --- incubator/streams/branches/sblackmon/streams-contrib/streams-provider-gnip/gnip-edc-instagram/src/test/resources/instagram_jsons.txt (added) +++ incubator/streams/branches/sblackmon/streams-contrib/streams-provider-gnip/gnip-edc-instagram/src/test/resources/instagram_jsons.txt Thu Jan 9 17:27:50 2014 @@ -0,0 +1,6 @@ +{ "comments": { "data": [], "count": 0 }, "caption": { "created_time": "1296710352", "text": "Inside le truc #foodtruck", "from": { "username": "kevin", "full_name": "Kevin Systrom", "id": "3" }, "id": "26621408" }, "likes": { "count": 15, "data": [{ "username": "mikeyk", "full_name": "Mike Krieger", "id": "4", "profile_picture": "..." }] }, "link": "http://instagr.am/p/BWrVZ/", "user": { "username": "kevin", "profile_picture": "http://distillery.s3.amazonaws.com/profiles/profile_3_75sq_1295574122.jpg", "id": "3" }, "created_time": "1296710327", "images": { "low_resolution": { "url": "http://distillery.s3.amazonaws.com/media/2011/02/02/6ea7baea55774c5e81e7e3e1f6e791a7_6.jpg", "width": 306, "height": 306 }, "thumbnail": { "url": "http://distillery.s3.amazonaws.com/media/2011/02/02/6ea7baea55774c5e81e7e3e1f6e791a7_5.jpg", "width": 150, "height": 150 }, "standard_resolution": { "url": "http://distillery.s3.amazonaws.com/media/2011/02/02/6ea7baea55774c5e81e7e3e1f6e791a7_7.jpg", "width": 612, "height": 612 } }, "type": "image", "users_in_photo": [], "filter": "Earlybird", "tags": ["foodtruck"], "id": "22721881", "location": { "latitude": 37.778720183610183, "longitude": -122.3962783813477, "id": "520640", "street_address": "", "name": "Le Truc" } } +{ "location": { "id": "833", "latitude": 37.77956816727314, "longitude": -122.41387367248539, "name": "Civic Center BART" }, "comments": { "count": 16, "data": [ ] }, "caption": null, "link": "http://instagr.am/p/BXsFz/", "likes": { "count": 190, "data": [{ "username": "shayne", "full_name": "Shayne Sweeney", "id": "20", "profile_picture": "..." }] }, "created_time": "1296748524", "images": { "low_resolution": { "url": "http://distillery.s3.amazonaws.com/media/2011/02/03/efc502667a554329b52d9a6bab35b24a_6.jpg", "width": 306, "height": 306 }, "thumbnail": { "url": "http://distillery.s3.amazonaws.com/media/2011/02/03/efc502667a554329b52d9a6bab35b24a_5.jpg", "width": 150, "height": 150 }, "standard_resolution": { "url": "http://distillery.s3.amazonaws.com/media/2011/02/03/efc502667a554329b52d9a6bab35b24a_7.jpg", "width": 612, "height": 612 } }, "type": "image", "users_in_photo": [], "filter": "Earlybird", "tags": [], "id": "22987123", "user": { "username": "kevin", "full_name": "Kevin S", "profile_picture": "http://distillery.s3.amazonaws.com/profiles/profile_3_75sq_1295574122.jpg", "id": "3" } } +{ "type": "image", "users_in_photo": [], "filter": "Earlybird", "tags": ["expobar"], "comments": { "data": [], "count": 0 }, "caption": { "created_time": "1296532028", "text": "@mikeyk pulls a shot on our #Expobar", "from": { "username": "josh", "full_name": "Josh Riedel", "id": "33" }, "id": "25663923" }, "likes": { "count": 35, "data": [{ "username": "mikeyk", "full_name": "Mikeyk", "id": "4", "profile_picture": "..." }] }, "link": "http://instagr.am/p/BUS3X/", "user": { "username": "josh", "profile_picture": "...", "id": "33" }, "created_time": "1296531955", "images": { "low_resolution": { "url": "http://distillery.s3.amazonaws.com/media/2011/01/31/32d364527512437a8a17ba308a7c83bb_6.jpg", "width": 306, "height": 306 }, "thumbnail": { "url": "http://distillery.s3.amazonaws.com/media/2011/01/31/32d364527512437a8a17ba308a7c83bb_5.jpg", "width": 150, "height": 150 }, "standard_resolution": { "url": "http://distillery.s3.amazonaws.com/media/2011/01/31/32d364527512437a8a17ba308a7c83bb_ 7.jpg", "width": 612, "height": 612 } }, "user_has_liked": false, "id": "22097367", "location": { "latitude": 37.780885099999999, "id": "514276", "longitude": -122.3948632, "name": "Instagram" } } +{ "type": "image", "users_in_photo": [], "filter": "Earlybird", "tags": ["snow"], "comments": { "data": [{ "created_time": "1296703540", "text": "Snow", "from": { "username": "emohatch", "full_name": "Dave", "id": "1242695" }, "id": "26589964" }, { "created_time": "1296707889", "text": "#snow", "from": { "username": "emohatch", "full_name": "Emo Hatch", "id": "1242695" }, "id": "26609649" }], "count": 3 }, "caption": { "created_time": "1296703540", "text": "#Snow", "from": { "username": "emohatch", "id": "1242695" }, "id": "26589964" }, "likes": { "count": 1, "data": [{ "username": "mikeyk", "full_name": "Mike Krieger", "id": "4", "profile_picture": "http://distillery.s3.amazonaws.com/profiles/profile_1242695_75sq_1293915800.jpg" }] }, "link": "http://instagr.am/p/BWl6P/", "user": { "username": "emohatch", "profile_picture": "http://distillery.s3.amazonaws.com/profiles/profile_1242695_75sq_1293915800.jpg", "id": "1242695", "full_name": "Dave" }, "created_time": "1296703536", "images": { "low_resolution": { "url": "http://distillery.s3.amazonaws.com/media/2011/02/02/f9443f3443484c40b4792fa7c76214d5_6.jpg", "width": 306, "height": 306 }, "thumbnail": { "url": "http://distillery.s3.amazonaws.com/media/2011/02/02/f9443f3443484c40b4792fa7c76214d5_5.jpg", "width": 150, "height": 150 }, "standard_resolution": { "url": "http://distillery.s3.amazonaws.com/media/2011/02/02/f9443f3443484c40b4792fa7c76214d5_7.jpg", "width": 612, "height": 612 } }, "id": "22699663", "location": null } +{ "type": "image", "users_in_photo": [{ "user": { "username": "kevin", "full_name": "Kevin S", "id": "3", "profile_picture": "..." }, "position": { "x": 0.315, "y": 0.9111 } }], "filter": "Walden", "tags": [], "comments": { "data": [{ "created_time": "1279332030", "text": "Love the sign here", "from": { "username": "mikeyk", "full_name": "Mikey Krieger", "id": "4", "profile_picture": "http://distillery.s3.amazonaws.com/profiles/profile_1242695_75sq_1293915800.jpg" }, "id": "8" }, { "created_time": "1279341004", "text": "Chilako taco", "from": { "username": "kevin", "full_name": "Kevin S", "id": "3", "profile_picture": "..." }, "id": "3" }], "count": 2 }, "caption": null, "likes": { "count": 1, "data": [{ "username": "mikeyk", "full_name": "Mikeyk", "id": "4", "profile_picture": "..." }] }, "link": "http://instagr.am/p/D/", "user": { "username": "kevin", "full_name": "Kevin S", "profile_picture": "...", "bio": "...", "website": "...", "id": "3" }, "created_time": "1279340983", "image s": { "low_resolution": { "url": "http://distillery.s3.amazonaws.com/media/2010/07/16/4de37e03aa4b4372843a7eb33fa41cad_6.jpg", "width": 306, "height": 306 }, "thumbnail": { "url": "http://distillery.s3.amazonaws.com/media/2010/07/16/4de37e03aa4b4372843a7eb33fa41cad_5.jpg", "width": 150, "height": 150 }, "standard_resolution": { "url": "http://distillery.s3.amazonaws.com/media/2010/07/16/4de37e03aa4b4372843a7eb33fa41cad_7.jpg", "width": 612, "height": 612 } }, "id": "3", "location": null } +{ "type": "video", "videos": { "low_resolution": { "url": "http://distilleryvesper9-13.ak.instagram.com/090d06dad9cd11e2aa0912313817975d_102.mp4", "width": 480, "height": 480 }, "standard_resolution": { "url": "http://distilleryvesper9-13.ak.instagram.com/090d06dad9cd11e2aa0912313817975d_101.mp4", "width": 640, "height": 640 } }, "users_in_photo": null, "filter": "Vesper", "tags": ["snow"], "comments": { "data": [{ "created_time": "1279332030", "text": "Love the sign here", "from": { "username": "mikeyk", "full_name": "Mikey Krieger", "id": "4", "profile_picture": "http://distillery.s3.amazonaws.com/profiles/profile_1242695_75sq_1293915800.jpg" }, "id": "8" }, { "created_time": "1279341004", "text": "Chilako taco", "from": { "username": "kevin", "full_name": "Kevin S", "id": "3", "profile_picture": "..." }, "id": "3" }], "count": 2 }, "caption": null, "likes": { "count": 1, "data": [{ "username": "mikeyk", "full_name": "Mikeyk", "id": "4", "profile_picture": "..." }] }, "link": "htt p://instagr.am/p/D/", "user": { "username": "kevin", "full_name": "Kevin S", "profile_picture": "http://distillery.s3.amazonaws.com/profiles/profile_3_75sq_1295574122.jpg", "id": "3" }, "created_time": "1279340983", "images": { "low_resolution": { "url": "http://distilleryimage2.ak.instagram.com/11f75f1cd9cc11e2a0fd22000aa8039a_6.jpg", "width": 306, "height": 306 }, "thumbnail": { "url": "http://distilleryimage2.ak.instagram.com/11f75f1cd9cc11e2a0fd22000aa8039a_5.jpg", "width": 150, "height": 150 }, "standard_resolution": { "url": "http://distilleryimage2.ak.instagram.com/11f75f1cd9cc11e2a0fd22000aa8039a_7.jpg", "width": 612, "height": 612 } }, "id": "363839373298", "location": { "latitude": 37.780885099999999, "id": "514276", "longitude": -122.3948632, "name": "Instagram" } } Added: incubator/streams/branches/sblackmon/streams-contrib/streams-provider-gnip/gnip-edc-reddit/pom.xml URL: http://svn.apache.org/viewvc/incubator/streams/branches/sblackmon/streams-contrib/streams-provider-gnip/gnip-edc-reddit/pom.xml?rev=1556893&view=auto ============================================================================== --- incubator/streams/branches/sblackmon/streams-contrib/streams-provider-gnip/gnip-edc-reddit/pom.xml (added) +++ incubator/streams/branches/sblackmon/streams-contrib/streams-provider-gnip/gnip-edc-reddit/pom.xml Thu Jan 9 17:27:50 2014 @@ -0,0 +1,138 @@ + + + + org.apache.streams + streams-provider-gnip + 0.1-SNAPSHOT + + 4.0.0 + + gnip-edc-reddit + + + + + org.jsonschema2pojo + jsonschema2pojo-core + + jar + compile + + + + com.fasterxml.jackson.core + jackson-core + + + + com.fasterxml.jackson.dataformat + jackson-dataformat-xml + + + + com.fasterxml + jackson-xml-databind + 0.5.0 + + + + junit + junit + 4.11 + test + + + + org.slf4j + slf4j-api + 1.6.1 + + + + ch.qos.logback + logback-classic + 1.0.9 + + + + org.json + json + 20090211 + + + + org.apache.streams + streams-pojo + 0.1-SNAPSHOT + + + + org.apache.streams + gnip-powertrack + 0.1-SNAPSHOT + + + + + + src/main/java + src/test/java + + + src/main/resources + + + + + src/test/resources + + + + + maven-clean-plugin + 2.5 + + + + src/main/java/com/reddit/pojo + + **/* + + + + target + + **/* + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file Added: incubator/streams/branches/sblackmon/streams-contrib/streams-provider-gnip/gnip-edc-reddit/src/main/java/com/reddit/api/RedditActivitySerializer.java URL: http://svn.apache.org/viewvc/incubator/streams/branches/sblackmon/streams-contrib/streams-provider-gnip/gnip-edc-reddit/src/main/java/com/reddit/api/RedditActivitySerializer.java?rev=1556893&view=auto ============================================================================== --- incubator/streams/branches/sblackmon/streams-contrib/streams-provider-gnip/gnip-edc-reddit/src/main/java/com/reddit/api/RedditActivitySerializer.java (added) +++ incubator/streams/branches/sblackmon/streams-contrib/streams-provider-gnip/gnip-edc-reddit/src/main/java/com/reddit/api/RedditActivitySerializer.java Thu Jan 9 17:27:50 2014 @@ -0,0 +1,89 @@ +package com.reddit.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.HashMap; +import java.util.List; +import java.util.Map; + +/** + * Created with IntelliJ IDEA. + * User: mdelaet + * Date: 8/29/13 + * Time: 8:32 AM + * To change this template use File | Settings | File Templates. + */ +public class RedditActivitySerializer implements ActivitySerializer{ + private final static Logger LOGGER = LoggerFactory.getLogger(RedditActivitySerializer.class); + + public static final String DATE_FORMAT = "yyyy-MM-dd'T'HH:mm:ssZ"; + public static final String PROVIDER_NAME = "facebook"; + + + @Override + public String serializationFormat() { + return "application/reddit+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(); + + HashMap raw = new HashMap(); + raw.put("original", serialized); + + 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 extension = ActivityUtil.ensureExtensions(activity); + if (fixedObject.names().toString().contains("object")){ + if (fixedObject.getJSONObject("object").names().toString().contains("statistics")){ + if (fixedObject.getJSONObject("object").getJSONObject("statistics").names().toString().contains("upVotes")){ + extension.put("likes", fixedObject.getJSONObject("object").getJSONObject("statistics").get("upVotes")); + } + } + } + + } catch( Exception e ) { + LOGGER.error(jsonObject.toString()); + LOGGER.error(fixedObject.toString()); + e.printStackTrace(); + } + return activity; + } + + @Override + public List 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-reddit/src/test/java/com/reddit/api/RedditEDCAsActivityJSONTest.java URL: http://svn.apache.org/viewvc/incubator/streams/branches/sblackmon/streams-contrib/streams-provider-gnip/gnip-edc-reddit/src/test/java/com/reddit/api/RedditEDCAsActivityJSONTest.java?rev=1556893&view=auto ============================================================================== --- incubator/streams/branches/sblackmon/streams-contrib/streams-provider-gnip/gnip-edc-reddit/src/test/java/com/reddit/api/RedditEDCAsActivityJSONTest.java (added) +++ incubator/streams/branches/sblackmon/streams-contrib/streams-provider-gnip/gnip-edc-reddit/src/test/java/com/reddit/api/RedditEDCAsActivityJSONTest.java Thu Jan 9 17:27:50 2014 @@ -0,0 +1,82 @@ +package com.reddit.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/30/13 +* Time: 1:21 PM +* To change this template use File | Settings | File Templates. +*/ +public class RedditEDCAsActivityJSONTest { + private final static Logger LOGGER = LoggerFactory.getLogger(RedditEDCAsActivityJSONTest.class); + + private ObjectMapper jsonMapper; + XmlMapper xmlMapper; + private RedditActivitySerializer redditSerializer; + + public RedditEDCAsActivityJSONTest() { + redditSerializer = new RedditActivitySerializer(); + jsonMapper = new ObjectMapper(); + xmlMapper = new XmlMapper(); + } + + @Test + public void Tests() throws Exception + { + InputStream is = RedditEDCAsActivityJSONTest.class.getResourceAsStream("/RedditEDCFixed.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 = redditSerializer.deserialize(line); + } catch( Exception e ) { + LOGGER.error(line); + e.printStackTrace(); + Assert.fail("Exception on redditSerializer.deserialize(jsonString) : " + e); + } + + try { + String activityString = redditSerializer.serialize(activity); + System.out.println(jsonMapper.writeValueAsString(activity)); + }catch (Exception e ){ + LOGGER.error(activity.toString()); + e.printStackTrace(); + Assert.fail("Exception on redditSerializer.serialize(activity) : " + e); + } + + //LOGGER.info(activity); + } + } catch( Exception e ) { + System.out.println("Exception: " + e); + LOGGER.error(e.getMessage()); + Assert.fail(""); + } + } + +} +