http://git-wip-us.apache.org/repos/asf/incubator-streams/blob/0b512d8b/streams-contrib/streams-provider-gnip/gnip-edc-googleplus/src/main/java/com/gplus/api/GPlusActivitySerializer.java ---------------------------------------------------------------------- diff --git a/streams-contrib/streams-provider-gnip/gnip-edc-googleplus/src/main/java/com/gplus/api/GPlusActivitySerializer.java b/streams-contrib/streams-provider-gnip/gnip-edc-googleplus/src/main/java/com/gplus/api/GPlusActivitySerializer.java deleted file mode 100644 index 8b04d26..0000000 --- a/streams-contrib/streams-provider-gnip/gnip-edc-googleplus/src/main/java/com/gplus/api/GPlusActivitySerializer.java +++ /dev/null @@ -1,93 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -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.pojo.extensions.ExtensionUtil; -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<String> { - 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 = ExtensionUtil.getInstance().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(List<String> serializedList) { - //TODO Support - throw new NotImplementedException("Not currently supported by this deserializer"); - } -}
http://git-wip-us.apache.org/repos/asf/incubator-streams/blob/0b512d8b/streams-contrib/streams-provider-gnip/gnip-edc-googleplus/src/test/java/com/gplus/api/GPlusEDCAsActivityTest.java ---------------------------------------------------------------------- diff --git a/streams-contrib/streams-provider-gnip/gnip-edc-googleplus/src/test/java/com/gplus/api/GPlusEDCAsActivityTest.java b/streams-contrib/streams-provider-gnip/gnip-edc-googleplus/src/test/java/com/gplus/api/GPlusEDCAsActivityTest.java deleted file mode 100644 index 10e58e6..0000000 --- a/streams-contrib/streams-provider-gnip/gnip-edc-googleplus/src/test/java/com/gplus/api/GPlusEDCAsActivityTest.java +++ /dev/null @@ -1,95 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -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.Ignore; -import org.junit.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.io.BufferedReader; -import java.io.InputStream; -import java.io.InputStreamReader; - -/** - * Tests conversion of YoutubeEDC inputs to Activity - */ -@Ignore("ignore until test resources are available.") -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) LOGGER.debug("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 ) { - LOGGER.error("Exception: ", e); - Assert.fail(""); - } - } - -} http://git-wip-us.apache.org/repos/asf/incubator-streams/blob/0b512d8b/streams-contrib/streams-provider-gnip/gnip-edc-instagram/pom.xml ---------------------------------------------------------------------- diff --git a/streams-contrib/streams-provider-gnip/gnip-edc-instagram/pom.xml b/streams-contrib/streams-provider-gnip/gnip-edc-instagram/pom.xml deleted file mode 100644 index 2df9797..0000000 --- a/streams-contrib/streams-provider-gnip/gnip-edc-instagram/pom.xml +++ /dev/null @@ -1,116 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- - ~ Licensed to the Apache Software Foundation (ASF) under one - ~ or more contributor license agreements. See the NOTICE file - ~ distributed with this work for additional information - ~ regarding copyright ownership. The ASF licenses this file - ~ to you under the Apache License, Version 2.0 (the - ~ "License"); you may not use this file except in compliance - ~ - ~ http://www.apache.org/licenses/LICENSE-2.0 - ~ - ~ Unless required by applicable law or agreed to in writing, - ~ software distributed under the License is distributed on an - ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - ~ KIND, either express or implied. See the License for the - ~ specific language governing permissions and limitations - ~ under the License. - --> -<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"> - <modelVersion>4.0.0</modelVersion> - <parent> - <groupId>org.apache.streams</groupId> - <artifactId>streams-provider-gnip</artifactId> - <version>0.4-incubating-SNAPSHOT</version> - </parent> - - <artifactId>gnip-edc-instagram</artifactId> - <name>${project.artifactId}</name> - - <description>Gnip EDC Instagram Provider</description> - - <dependencies> - - <dependency> - <groupId>com.fasterxml.jackson.core</groupId> - <artifactId>jackson-core</artifactId> - </dependency> - <dependency> - <groupId>com.fasterxml.jackson.core</groupId> - <artifactId>jackson-annotations</artifactId> - </dependency> - <dependency> - <groupId>org.jsonschema2pojo</groupId> - <artifactId>jsonschema2pojo-core</artifactId> - </dependency> - <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - </dependency> - <dependency> - <groupId>org.apache.streams</groupId> - <artifactId>streams-testing</artifactId> - <version>${project.version}</version> - <scope>test</scope> - <type>test-jar</type> - </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> - <groupId>org.codehaus.mojo</groupId> - <artifactId>build-helper-maven-plugin</artifactId> - <executions> - <execution> - <id>add-source</id> - <phase>generate-sources</phase> - <goals> - <goal>add-source</goal> - </goals> - <configuration> - <sources> - <source>target/generated-sources/jsonschema2pojo/**/*.java</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>${project.basedir}/src/main/jsonschema/com/instagram/Instagram.json</sourcePath> - </sourcePaths> - <outputDirectory>target/generated-sources/jsonschema2pojo</outputDirectory> - <targetPackage>com.instagram</targetPackage> - <useLongIntegers>true</useLongIntegers> - <useJodaDates>true</useJodaDates> - </configuration> - <executions> - <execution> - <goals> - <goal>generate</goal> - </goals> - </execution> - </executions> - </plugin> - </plugins> - - </build> -</project> http://git-wip-us.apache.org/repos/asf/incubator-streams/blob/0b512d8b/streams-contrib/streams-provider-gnip/gnip-edc-instagram/src/main/jsonschema/com/instagram/Instagram.json ---------------------------------------------------------------------- diff --git a/streams-contrib/streams-provider-gnip/gnip-edc-instagram/src/main/jsonschema/com/instagram/Instagram.json b/streams-contrib/streams-provider-gnip/gnip-edc-instagram/src/main/jsonschema/com/instagram/Instagram.json deleted file mode 100644 index 0c9e4c0..0000000 --- a/streams-contrib/streams-provider-gnip/gnip-edc-instagram/src/main/jsonschema/com/instagram/Instagram.json +++ /dev/null @@ -1,208 +0,0 @@ -{ - "$schema": "http://json-schema.org/draft-03/schema", - "$license": [ - "http://www.apache.org/licenses/LICENSE-2.0" - ], - "id": "#", - "type": "object", - "javaType" : "com.instagram.pojo.Instagram", - "javaInterfaces": ["java.io.Serializable"], - "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" - } - } - } - } -} http://git-wip-us.apache.org/repos/asf/incubator-streams/blob/0b512d8b/streams-contrib/streams-provider-gnip/gnip-edc-instagram/src/test/java/com/instagram/test/InstagramSerDeTest.java ---------------------------------------------------------------------- diff --git a/streams-contrib/streams-provider-gnip/gnip-edc-instagram/src/test/java/com/instagram/test/InstagramSerDeTest.java b/streams-contrib/streams-provider-gnip/gnip-edc-instagram/src/test/java/com/instagram/test/InstagramSerDeTest.java deleted file mode 100644 index 978aba6..0000000 --- a/streams-contrib/streams-provider-gnip/gnip-edc-instagram/src/test/java/com/instagram/test/InstagramSerDeTest.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -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.Ignore; -import org.junit.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.io.BufferedReader; -import java.io.InputStream; -import java.io.InputStreamReader; - -/** - * Tests serialization of instagram inputs - */ -@Ignore("ignore until test resources are available.") -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(); - } - } -} http://git-wip-us.apache.org/repos/asf/incubator-streams/blob/0b512d8b/streams-contrib/streams-provider-gnip/gnip-edc-reddit/pom.xml ---------------------------------------------------------------------- diff --git a/streams-contrib/streams-provider-gnip/gnip-edc-reddit/pom.xml b/streams-contrib/streams-provider-gnip/gnip-edc-reddit/pom.xml deleted file mode 100644 index 5d44c43..0000000 --- a/streams-contrib/streams-provider-gnip/gnip-edc-reddit/pom.xml +++ /dev/null @@ -1,103 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- - ~ Licensed to the Apache Software Foundation (ASF) under one - ~ or more contributor license agreements. See the NOTICE file - ~ distributed with this work for additional information - ~ regarding copyright ownership. The ASF licenses this file - ~ to you under the Apache License, Version 2.0 (the - ~ "License"); you may not use this file except in compliance - ~ - ~ http://www.apache.org/licenses/LICENSE-2.0 - ~ - ~ Unless required by applicable law or agreed to in writing, - ~ software distributed under the License is distributed on an - ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - ~ KIND, either express or implied. See the License for the - ~ specific language governing permissions and limitations - ~ under the License. - --> -<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"> - <modelVersion>4.0.0</modelVersion> - <parent> - <groupId>org.apache.streams</groupId> - <artifactId>streams-provider-gnip</artifactId> - <version>0.4-incubating-SNAPSHOT</version> - </parent> - - <artifactId>gnip-edc-reddit</artifactId> - <name>${project.artifactId}</name> - - <description>Gnip EDC Reddit Provider</description> - - <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> - </dependency> - - <dependency> - <groupId>com.fasterxml.jackson.dataformat</groupId> - <artifactId>jackson-dataformat-xml</artifactId> - </dependency> - - <dependency> - <groupId>com.fasterxml</groupId> - <artifactId>jackson-xml-databind</artifactId> - </dependency> - - <dependency> - <groupId>org.json</groupId> - <artifactId>json</artifactId> - </dependency> - - <dependency> - <groupId>org.apache.streams</groupId> - <artifactId>streams-pojo</artifactId> - <version>${project.version}</version> - </dependency> - - <dependency> - <groupId>org.apache.streams</groupId> - <artifactId>streams-pojo-extensions</artifactId> - <version>${project.version}</version> - </dependency> - - <dependency> - <groupId>org.apache.streams</groupId> - <artifactId>gnip-powertrack</artifactId> - <version>${project.version}</version> - </dependency> - - <dependency> - <groupId>org.apache.streams</groupId> - <artifactId>streams-testing</artifactId> - <version>${project.version}</version> - <scope>test</scope> - <type>test-jar</type> - </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> - </build> -</project> http://git-wip-us.apache.org/repos/asf/incubator-streams/blob/0b512d8b/streams-contrib/streams-provider-gnip/gnip-edc-reddit/src/main/java/com/reddit/api/RedditActivitySerializer.java ---------------------------------------------------------------------- diff --git a/streams-contrib/streams-provider-gnip/gnip-edc-reddit/src/main/java/com/reddit/api/RedditActivitySerializer.java b/streams-contrib/streams-provider-gnip/gnip-edc-reddit/src/main/java/com/reddit/api/RedditActivitySerializer.java deleted file mode 100644 index d715629..0000000 --- a/streams-contrib/streams-provider-gnip/gnip-edc-reddit/src/main/java/com/reddit/api/RedditActivitySerializer.java +++ /dev/null @@ -1,107 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -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.pojo.extensions.ExtensionUtil; -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<String> { - 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<String, String> raw = new HashMap<String, String>(); - 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<String, Object> extension = ExtensionUtil.getInstance().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<Activity> deserializeAll(List<String> serializedList) { - //TODO Support - throw new NotImplementedException("Not currently supported by this deserializer"); - } -} http://git-wip-us.apache.org/repos/asf/incubator-streams/blob/0b512d8b/streams-contrib/streams-provider-gnip/gnip-edc-reddit/src/test/java/com/reddit/api/RedditEDCAsActivityJSONTest.java ---------------------------------------------------------------------- diff --git a/streams-contrib/streams-provider-gnip/gnip-edc-reddit/src/test/java/com/reddit/api/RedditEDCAsActivityJSONTest.java b/streams-contrib/streams-provider-gnip/gnip-edc-reddit/src/test/java/com/reddit/api/RedditEDCAsActivityJSONTest.java deleted file mode 100644 index 9044e12..0000000 --- a/streams-contrib/streams-provider-gnip/gnip-edc-reddit/src/test/java/com/reddit/api/RedditEDCAsActivityJSONTest.java +++ /dev/null @@ -1,97 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -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.Ignore; -import org.junit.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.io.BufferedReader; -import java.io.InputStream; -import java.io.InputStreamReader; - -/** - * Tests conversion of YoutubeEDC inputs to Activity - */ -@Ignore("ignore until test resources are available.") -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) LOGGER.debug("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 ) { - LOGGER.error("Exception: ", e); - Assert.fail(""); - } - } - -} - http://git-wip-us.apache.org/repos/asf/incubator-streams/blob/0b512d8b/streams-contrib/streams-provider-gnip/gnip-edc-youtube/pom.xml ---------------------------------------------------------------------- diff --git a/streams-contrib/streams-provider-gnip/gnip-edc-youtube/pom.xml b/streams-contrib/streams-provider-gnip/gnip-edc-youtube/pom.xml deleted file mode 100644 index 2aace1a..0000000 --- a/streams-contrib/streams-provider-gnip/gnip-edc-youtube/pom.xml +++ /dev/null @@ -1,139 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- - ~ Licensed to the Apache Software Foundation (ASF) under one - ~ or more contributor license agreements. See the NOTICE file - ~ distributed with this work for additional information - ~ regarding copyright ownership. The ASF licenses this file - ~ to you under the Apache License, Version 2.0 (the - ~ "License"); you may not use this file except in compliance - ~ - ~ http://www.apache.org/licenses/LICENSE-2.0 - ~ - ~ Unless required by applicable law or agreed to in writing, - ~ software distributed under the License is distributed on an - ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - ~ KIND, either express or implied. See the License for the - ~ specific language governing permissions and limitations - ~ under the License. - --> -<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> - <artifactId>streams-provider-gnip</artifactId> - <groupId>org.apache.streams</groupId> - <version>0.4-incubating-SNAPSHOT</version> - </parent> - <modelVersion>4.0.0</modelVersion> - - <artifactId>gnip-edc-youtube</artifactId> - <name>${project.artifactId}</name> - - <description>Gnip EDC YouTube Provider</description> - - <dependencies> - - <dependency> - <groupId>com.fasterxml.jackson.core</groupId> - <artifactId>jackson-core</artifactId> - </dependency> - <dependency> - <groupId>com.fasterxml.jackson.core</groupId> - <artifactId>jackson-annotations</artifactId> - </dependency> - <dependency> - <groupId>org.jsonschema2pojo</groupId> - <artifactId>jsonschema2pojo-core</artifactId> - </dependency> - <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - </dependency> - <dependency> - <groupId>org.apache.streams</groupId> - <artifactId>streams-core</artifactId> - </dependency> - <dependency> - <groupId>org.apache.streams</groupId> - <artifactId>streams-pojo</artifactId> - </dependency> - <dependency> - <groupId>org.apache.streams</groupId> - <artifactId>gnip-powertrack</artifactId> - <version>${project.version}</version> - </dependency> - <dependency> - <groupId>com.fasterxml</groupId> - <artifactId>aalto-xml</artifactId> - </dependency> - <dependency> - <groupId>org.apache.streams</groupId> - <artifactId>streams-testing</artifactId> - <version>${project.version}</version> - <scope>test</scope> - <type>test-jar</type> - </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> - <groupId>org.codehaus.mojo</groupId> - <artifactId>build-helper-maven-plugin</artifactId> - <executions> - <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.jvnet.jaxb2.maven2</groupId> - <artifactId>maven-jaxb2-plugin</artifactId> - <configuration> - <schemaDirectory>src/main/xmlschema/com/flickr/</schemaDirectory> - <generateDirectory>target/generated-sources/jaxb2</generateDirectory> - <verbose>true</verbose> - <debug>true</debug> - <encoding>${project.build.sourceEncoding}</encoding> - <forceRegenerate>true</forceRegenerate> - <removeOldOutput>false</removeOldOutput> - <generatePackage>com.flickr.api</generatePackage> - <plugins> - <plugin> - <groupId>org.jvnet.jaxb2_commons</groupId> - <artifactId>jaxb2-basics</artifactId> - <version>${jaxb2-basics.version}</version> - </plugin> - </plugins> - </configuration> - <executions> - <execution> - <goals> - <goal>generate</goal> - </goals> - </execution> - </executions> - </plugin> - </plugins> - - </build> -</project> http://git-wip-us.apache.org/repos/asf/incubator-streams/blob/0b512d8b/streams-contrib/streams-provider-gnip/gnip-edc-youtube/src/test/java/com/gnip/test/YouTubeEDCSerDeTest.java ---------------------------------------------------------------------- diff --git a/streams-contrib/streams-provider-gnip/gnip-edc-youtube/src/test/java/com/gnip/test/YouTubeEDCSerDeTest.java b/streams-contrib/streams-provider-gnip/gnip-edc-youtube/src/test/java/com/gnip/test/YouTubeEDCSerDeTest.java deleted file mode 100644 index c986000..0000000 --- a/streams-contrib/streams-provider-gnip/gnip-edc-youtube/src/test/java/com/gnip/test/YouTubeEDCSerDeTest.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package com.gnip.test; - -import com.fasterxml.jackson.databind.DeserializationFeature; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.dataformat.xml.XmlMapper; -import org.junit.Assert; -import org.junit.Ignore; -import org.junit.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.io.BufferedReader; -import java.io.InputStream; -import java.io.InputStreamReader; - -/** - * Tests serialization of YoutubeEDC inputs - */ -@Ignore("ignore until test resources are available.") -public class YouTubeEDCSerDeTest { - - private final static Logger LOGGER = LoggerFactory.getLogger(YouTubeEDCSerDeTest.class); - - private ObjectMapper mapper = new ObjectMapper(); -// XmlMapper mapper = new XmlMapper(); - - @Test - public void Tests() throws Exception - { - mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, Boolean.FALSE); - mapper.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, Boolean.TRUE); - mapper.configure(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT, Boolean.TRUE); - - InputStream is = YouTubeEDCSerDeTest.class.getResourceAsStream("/YoutubeEDC.xml"); - if(is == null) LOGGER.debug("null"); - InputStreamReader isr = new InputStreamReader(is); - BufferedReader br = new BufferedReader(isr); - XmlMapper xmlMapper = new XmlMapper(); - 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); - - ObjectMapper jsonMapper = new ObjectMapper(); - - try { - while (br.ready()) { - String line = br.readLine(); - //LOGGER.debug(line); - - Object activityObject = xmlMapper.readValue(line, Object.class); - - String jsonObject = jsonMapper.writeValueAsString(activityObject); - - //LOGGER.debug(jsonObject); - } - } catch( Exception e ) { - e.printStackTrace(); - Assert.fail(); - } - } -} http://git-wip-us.apache.org/repos/asf/incubator-streams/blob/0b512d8b/streams-contrib/streams-provider-gnip/gnip-edc-youtube/src/test/java/com/gnip/test/YoutubeEDCAsActivityTest.java ---------------------------------------------------------------------- diff --git a/streams-contrib/streams-provider-gnip/gnip-edc-youtube/src/test/java/com/gnip/test/YoutubeEDCAsActivityTest.java b/streams-contrib/streams-provider-gnip/gnip-edc-youtube/src/test/java/com/gnip/test/YoutubeEDCAsActivityTest.java deleted file mode 100644 index 1c12744..0000000 --- a/streams-contrib/streams-provider-gnip/gnip-edc-youtube/src/test/java/com/gnip/test/YoutubeEDCAsActivityTest.java +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package com.gnip.test; - -import com.fasterxml.jackson.databind.DeserializationFeature; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.dataformat.xml.XmlMapper; -import org.apache.streams.gnip.powertrack.GnipActivityFixer; -import org.apache.streams.pojo.json.Activity; -import org.json.JSONObject; -import org.junit.Assert; -import org.junit.Ignore; -import org.junit.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.io.BufferedReader; -import java.io.InputStream; -import java.io.InputStreamReader; - -/** - * Tests conversion of YoutubeEDC inputs to Activity - */ -@Ignore("ignore until test resources are available.") -public class YoutubeEDCAsActivityTest { - - private final static Logger LOGGER = LoggerFactory.getLogger(YoutubeEDCAsActivityTest.class); - - private ObjectMapper mapper = new ObjectMapper(); -// XmlMapper mapper = new XmlMapper(); - - @Test @Ignore - public void Tests() throws Exception - { - mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, Boolean.FALSE); - mapper.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, Boolean.TRUE); - mapper.configure(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT, Boolean.TRUE); - - InputStream is = YoutubeEDCAsActivityTest.class.getResourceAsStream("/YoutubeEDC.xml"); - if(is == null) LOGGER.debug("null"); - InputStreamReader isr = new InputStreamReader(is); - BufferedReader br = new BufferedReader(isr); - XmlMapper xmlMapper = new XmlMapper(); - 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); - - ObjectMapper jsonMapper = new ObjectMapper(); - - try { - while (br.ready()) { - String line = br.readLine(); - //LOGGER.debug(line); - - Object activityObject = xmlMapper.readValue(line, Object.class); - - String jsonString = jsonMapper.writeValueAsString(activityObject); - - JSONObject jsonObject = new JSONObject(jsonString); - - JSONObject fixedObject = GnipActivityFixer.fix(jsonObject); - - Activity activity = jsonMapper.readValue(fixedObject.toString(), Activity.class); - - } - } catch( Exception e ) { - e.printStackTrace(); - Assert.fail(); - } - } -} http://git-wip-us.apache.org/repos/asf/incubator-streams/blob/0b512d8b/streams-contrib/streams-provider-gnip/gnip-powertrack/README.md ---------------------------------------------------------------------- diff --git a/streams-contrib/streams-provider-gnip/gnip-powertrack/README.md b/streams-contrib/streams-provider-gnip/gnip-powertrack/README.md deleted file mode 100644 index 561db36..0000000 --- a/streams-contrib/streams-provider-gnip/gnip-powertrack/README.md +++ /dev/null @@ -1,8 +0,0 @@ -Apache Streams (incubating) -Licensed under Apache License 2.0 - http://www.apache.org/licenses/LICENSE-2.0 --------------------------------------------------------------------------------- - -org.apache.streams:gnip-powertrack -=========================================== - -[README.md](src/site/markdown/index.md "README") http://git-wip-us.apache.org/repos/asf/incubator-streams/blob/0b512d8b/streams-contrib/streams-provider-gnip/gnip-powertrack/pom.xml ---------------------------------------------------------------------- diff --git a/streams-contrib/streams-provider-gnip/gnip-powertrack/pom.xml b/streams-contrib/streams-provider-gnip/gnip-powertrack/pom.xml deleted file mode 100644 index f15fd22..0000000 --- a/streams-contrib/streams-provider-gnip/gnip-powertrack/pom.xml +++ /dev/null @@ -1,207 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- - ~ Licensed to the Apache Software Foundation (ASF) under one - ~ or more contributor license agreements. See the NOTICE file - ~ distributed with this work for additional information - ~ regarding copyright ownership. The ASF licenses this file - ~ to you under the Apache License, Version 2.0 (the - ~ "License"); you may not use this file except in compliance - ~ - ~ http://www.apache.org/licenses/LICENSE-2.0 - ~ - ~ Unless required by applicable law or agreed to in writing, - ~ software distributed under the License is distributed on an - ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - ~ KIND, either express or implied. See the License for the - ~ specific language governing permissions and limitations - ~ under the License. - --> -<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"> - <modelVersion>4.0.0</modelVersion> - <parent> - <groupId>org.apache.streams</groupId> - <artifactId>streams-provider-gnip</artifactId> - <version>0.4-incubating-SNAPSHOT</version> - </parent> - - <artifactId>gnip-powertrack</artifactId> - <name>${project.artifactId}</name> - - <description>Gnip Powertrack Provider</description> - - <dependencies> - <dependency> - <groupId>com.fasterxml.jackson.core</groupId> - <artifactId>jackson-core</artifactId> - </dependency> - <dependency> - <groupId>com.fasterxml.jackson.core</groupId> - <artifactId>jackson-annotations</artifactId> - </dependency> - <dependency> - <groupId>org.jsonschema2pojo</groupId> - <artifactId>jsonschema2pojo-core</artifactId> - </dependency> - <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - </dependency> - <dependency> - <groupId>com.fasterxml.jackson.dataformat</groupId> - <artifactId>jackson-dataformat-xml</artifactId> - </dependency> - <dependency> - <groupId>org.apache.streams</groupId> - <artifactId>streams-pojo</artifactId> - </dependency> - <dependency> - <groupId>org.json</groupId> - <artifactId>json</artifactId> - <version>20090211</version> - <scope>compile</scope> - <type>jar</type> - </dependency> - <dependency> - <groupId>org.apache.streams</groupId> - <artifactId>streams-testing</artifactId> - <version>${project.version}</version> - <scope>test</scope> - <type>test-jar</type> - </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> - <groupId>org.codehaus.mojo</groupId> - <artifactId>build-helper-maven-plugin</artifactId> - <executions> - <execution> - <id>add-source</id> - <phase>generate-sources</phase> - <goals> - <goal>add-source</goal> - </goals> - <configuration> - <sources> - <source>target/generated-sources/jsonschema2pojo/**/*.java</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> - <artifactId>maven-resources-plugin</artifactId> - </plugin> - <plugin> - <groupId>org.jsonschema2pojo</groupId> - <artifactId>jsonschema2pojo-maven-plugin</artifactId> - <configuration> - <addCompileSourceRoot>true</addCompileSourceRoot> - <generateBuilders>true</generateBuilders> - <sourcePaths> - <sourcePath>${project.basedir}/src/main/jsonschema/com/gnip/Gnip.json</sourcePath> - </sourcePaths> - <outputDirectory>target/generated-sources/jsonschema2pojo</outputDirectory> - <targetPackage>com.gnip</targetPackage> - <useLongIntegers>true</useLongIntegers> - <useJodaDates>true</useJodaDates> - </configuration> - <executions> - <execution> - <goals> - <goal>generate</goal> - </goals> - </execution> - </executions> - </plugin> - <plugin> - <groupId>org.jvnet.jaxb2.maven2</groupId> - <artifactId>maven-jaxb2-plugin</artifactId> - <configuration> - <schemaDirectory>src/main/xmlschema/com/gnip/</schemaDirectory> - <generateDirectory>target/generated-sources/jaxb2</generateDirectory> - <verbose>true</verbose> - <debug>true</debug> - <encoding>${project.build.sourceEncoding}</encoding> - <forceRegenerate>true</forceRegenerate> - <removeOldOutput>false</removeOldOutput> - <generatePackage>com.gnip.api</generatePackage> - <plugins> - <plugin> - <groupId>org.jvnet.jaxb2_commons</groupId> - <artifactId>jaxb2-basics</artifactId> - <version>${jaxb2-basics.version}</version> - </plugin> - </plugins> - </configuration> - <executions> - <execution> - <goals> - <goal>generate</goal> - </goals> - </execution> - </executions> - </plugin> - </plugins> - </build> - <profiles> - <profile> - <id>java8</id> - <activation> - <jdk>[1.8,]</jdk> - </activation> - <build> - <plugins> - <plugin> - <!-- We use this plugin to ensure that our usage of the - maven-jaxb2-plugin is JDK 8 compatible in absence of a fix - for https://java.net/jira/browse/MAVEN_JAXB2_PLUGIN-80. --> - <groupId>org.codehaus.mojo</groupId> - <artifactId>properties-maven-plugin</artifactId> - <version>1.0-alpha-2</version> - <executions> - <execution> - <id>set-additional-system-properties</id> - <goals> - <goal>set-system-properties</goal> - </goals> - </execution> - </executions> - <configuration> - <properties> - <property> - <name>javax.xml.accessExternalSchema</name> - <value>file,http</value> - </property> - </properties> - </configuration> - </plugin> - </plugins> - </build> - </profile> - </profiles> -</project> http://git-wip-us.apache.org/repos/asf/incubator-streams/blob/0b512d8b/streams-contrib/streams-provider-gnip/gnip-powertrack/src/main/java/org/apache/streams/gnip/powertrack/ActivityXMLActivitySerializer.java ---------------------------------------------------------------------- diff --git a/streams-contrib/streams-provider-gnip/gnip-powertrack/src/main/java/org/apache/streams/gnip/powertrack/ActivityXMLActivitySerializer.java b/streams-contrib/streams-provider-gnip/gnip-powertrack/src/main/java/org/apache/streams/gnip/powertrack/ActivityXMLActivitySerializer.java deleted file mode 100644 index e75927f..0000000 --- a/streams-contrib/streams-provider-gnip/gnip-powertrack/src/main/java/org/apache/streams/gnip/powertrack/ActivityXMLActivitySerializer.java +++ /dev/null @@ -1,240 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.streams.gnip.powertrack; - -import com.fasterxml.jackson.databind.DeserializationFeature; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.dataformat.xml.XmlMapper; -import org.apache.commons.lang.NotImplementedException; -import org.apache.commons.lang.StringUtils; -import org.apache.streams.data.ActivitySerializer; -import org.apache.streams.pojo.json.Activity; -import org.json.JSONException; -import org.json.JSONObject; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.w3c.dom.Document; -import org.w3c.dom.Element; -import org.w3c.dom.NodeList; -import org.xml.sax.InputSource; - -import javax.xml.parsers.DocumentBuilder; -import javax.xml.parsers.DocumentBuilderFactory; -import javax.xml.transform.OutputKeys; -import javax.xml.transform.Transformer; -import javax.xml.transform.TransformerFactory; -import javax.xml.transform.dom.DOMSource; -import javax.xml.transform.stream.StreamResult; -import java.io.StringReader; -import java.io.StringWriter; -import java.util.Iterator; -import java.util.List; - -/** - * Created with IntelliJ IDEA. - * User: rebanks - * Date: 9/5/13 - * Time: 3:07 PM - * To change this template use File | Settings | File Templates. - */ -public class ActivityXMLActivitySerializer implements ActivitySerializer<String> { - - private static final Logger LOGGER = LoggerFactory.getLogger(ActivityXMLActivitySerializer.class); - - private ObjectMapper mapper; - private XmlMapper xmlMapper; - - public ActivityXMLActivitySerializer() { - mapper = new ObjectMapper(); - mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, Boolean.FALSE); - mapper.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, Boolean.TRUE); - mapper.configure(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT, Boolean.TRUE); - xmlMapper = new XmlMapper(); - 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); - } - - - @Override - public String serializationFormat() { - return "gnip_activity_xml"; //To change body of implemented methods use File | Settings | File Templates. - } - - @Override - public String serialize(Activity deserialized) { - throw new UnsupportedOperationException(); - } - - @Override - public Activity deserialize(String serializedXML) { - Activity activity = null; - try { - activity = xmlMapper.readValue(new StringReader(setContentIfEmpty(serializedXML)), Activity.class); - activity = mapper.readValue(new StringReader(fixActivityXML(activity, serializedXML)), Activity.class); - } catch (Exception e) { - LOGGER.error("Exception correcting Gnip Activity Xml to Activity format.", e); - LOGGER.error("Xml that caused error : {}", serializedXML); - } - return activity; //To change body of implemented methods use File | Settings | File Templates. - } - - @Override - public List<Activity> deserializeAll(List<String> serializedList) { - throw new NotImplementedException("Not currently supported by this deserializer"); - } - - private String fixActivityXML(Activity activity, String xml) throws Exception{ - JSONObject jsonObject = new JSONObject(mapper.writeValueAsString(activity)); - JSONObject newObject = (JSONObject) fixActivityXML(jsonObject); - StringReader str = new StringReader(newObject.toString()); - newObject = formatFixedJSON(newObject); - newObject = fixDateFormats(newObject, xml); - newObject = createTopLevelConentField(newObject); - return newObject.toString(); - - } - - private Object fixActivityXML(Object obj) throws Exception { - if(obj instanceof JSONObject) { - JSONObject json = new JSONObject(); - JSONObject old = (JSONObject) obj; - Iterator keys = old.keys(); - while(keys.hasNext()) { - String key = (String) keys.next(); - if(StringUtils.isBlank(key)) { - return fixActivityXML(old.get(key)); - } - else if(!key.equals("type")){ - Object o = fixActivityXML(old.get(key)); - if(o != null) - json.put(key, o); - } - - } - if(json.keys().hasNext()) - return json; - else - return null; - } - else { - return obj; - } - - } - - private JSONObject formatFixedJSON(JSONObject json) throws Exception{ - JSONObject topLink = json.optJSONObject("link"); - if(topLink != null) { - json.put("link", topLink.getString("href")); - } - JSONObject actor = json.optJSONObject("actor"); - if(actor != null) { - JSONObject link = actor.optJSONObject("link"); - if(link != null) { - actor.put("link", link.get("href")); - } - } - JSONObject object = json.optJSONObject("object"); - if(object != null) { - JSONObject link = object.optJSONObject("link"); - if(link != null) { - object.put("link", link.get("href")); - } - } - String generator = json.optString("generator"); - if(generator != null) { - JSONObject gen = new JSONObject(); - gen.put("displayName", generator); - json.put("generator", gen); - } - return json; - } - - private JSONObject fixDateFormats(JSONObject json, String xml) throws Exception{ - DocumentBuilder docBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); - InputSource is = new InputSource(new StringReader(xml)); - Document doc = docBuilder.parse(is); - //why? - doc.getDocumentElement().normalize(); - if(json.optLong("published", -1L) != -1L) { - json.put("published", getValueFromXML("published", doc)); - } - if(json.optLong("updated", -1L) != -1L) { - json.put("updated", getValueFromXML("updated", doc)); - } - if(json.optLong("created", -1L) != -1L) { - json.put("created", getValueFromXML("created", doc)); - } - return json; - } - - private JSONObject createTopLevelConentField(JSONObject json) throws JSONException { - if(!json.isNull("content")) { - return json; - } - JSONObject object = json.optJSONObject("object"); - if(object != null) { - String content = object.optString("content"); - if(content == null) { - content = object.optString("summary"); - } - if(content != null) { - json.put("content", content); - } - } - return json; - } - - private String getValueFromXML(String tag, Document doc) throws Exception{ - Element base = (Element) doc.getElementsByTagName("entry").item(0); - return base.getElementsByTagName(tag).item(0).getTextContent(); - } - - private String setContentIfEmpty(String xml) throws Exception { - DocumentBuilder docBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); - InputSource is = new InputSource(new StringReader(xml)); - Document doc = docBuilder.parse(is); - doc.getDocumentElement().normalize(); - Element base = (Element) doc.getElementsByTagName("entry").item(0); - NodeList nodeList = base.getChildNodes(); -// for(int i=0; i < nodeList.getLength(); ++i) { -// System.out.println(nodeList.item(i).getNodeName()); -// } - Element obj = (Element)base.getElementsByTagName("activity:object").item(0); - Element content = (Element)obj.getElementsByTagName("content").item(0); -// System.out.println("Number of child nodes : "+content.getChildNodes().getLength()); -// System.out.println("Text content before : "+content.getTextContent()); - if(content.getTextContent() == null || content.getTextContent().equals("")) { - content.setTextContent(" "); - } -// System.out.println("Number of child nodes after : "+content.getChildNodes().getLength()); -// System.out.println("Text content after : "+content.getTextContent()); - TransformerFactory tf = TransformerFactory.newInstance(); - Transformer transformer = tf.newTransformer(); - transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); - StringWriter writer = new StringWriter(); - transformer.transform(new DOMSource(doc), new StreamResult(writer)); - String output = writer.getBuffer().toString().replaceAll("\n|\r", ""); -// System.out.println(output); -// System.out.println(output); -// System.out.println(content); - return output; - } -} http://git-wip-us.apache.org/repos/asf/incubator-streams/blob/0b512d8b/streams-contrib/streams-provider-gnip/gnip-powertrack/src/main/java/org/apache/streams/gnip/powertrack/GnipActivityFixer.java ---------------------------------------------------------------------- diff --git a/streams-contrib/streams-provider-gnip/gnip-powertrack/src/main/java/org/apache/streams/gnip/powertrack/GnipActivityFixer.java b/streams-contrib/streams-provider-gnip/gnip-powertrack/src/main/java/org/apache/streams/gnip/powertrack/GnipActivityFixer.java deleted file mode 100644 index 66ad914..0000000 --- a/streams-contrib/streams-provider-gnip/gnip-powertrack/src/main/java/org/apache/streams/gnip/powertrack/GnipActivityFixer.java +++ /dev/null @@ -1,151 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.streams.gnip.powertrack; - -import com.fasterxml.jackson.databind.DeserializationFeature; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.dataformat.xml.XmlMapper; -import org.apache.commons.lang.StringUtils; -import org.apache.streams.pojo.json.Activity; -import org.json.JSONException; -import org.json.JSONObject; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.io.StringReader; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Iterator; -import java.util.Map; - -/** - * Created with IntelliJ IDEA. - * User: mdelaet - * Date: 8/23/13 - * Time: 9:40 AM - * To change this template use File | Settings | File Templates. - */ -public class GnipActivityFixer { - - private final static Logger LOGGER = LoggerFactory.getLogger(GnipActivityFixer.class); - - private ObjectMapper mapper; - private XmlMapper xmlMapper; - - public GnipActivityFixer(){ - mapper = new ObjectMapper(); - mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, Boolean.FALSE); - mapper.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, Boolean.TRUE); - mapper.configure(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT, Boolean.TRUE); - xmlMapper = new XmlMapper(); - 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); - }; - - public static void findNullContents(JSONObject json, ArrayList<String> drilldownKeys, HashMap<ArrayList<String>, JSONObject> nullContents) throws Exception { - - Iterator itr = json.keys(); - while (itr.hasNext()){ - String element = (String) itr.next(); - - if (StringUtils.isBlank(element)){ - nullContents.put(drilldownKeys, json); - - } - else{ - try { - drilldownKeys.add(element); - if(json.get(element) instanceof JSONObject) - findNullContents((JSONObject) json.get(element), drilldownKeys, nullContents); - }catch(Exception e){ - LOGGER.info("Failed to convert in findNullKeys, " + e); - LOGGER.error("Element : {}", element); - LOGGER.error(json.toString()); - break; - } - } - drilldownKeys = new ArrayList<String>(); - } - } - - public static void editJson(JSONObject json, ArrayList<String> keyPath, Object nullFragment) throws JSONException { - Integer numKeys = keyPath.size(); - JSONObject newJson = new JSONObject(); - if (numKeys > 1){ - for (int i = numKeys-1; i > 0; i-=1){ - String key = keyPath.get(i); - if (i == numKeys -1){ - newJson = newJson.put(key, nullFragment); - } - else { - newJson = newJson.put(key, newJson); - } - } - json.put(keyPath.get(0), newJson); - } - else{ - json.put(keyPath.get(0), nullFragment); - } - } - - public static Activity fix(Activity activity) throws Exception { - ObjectMapper mapper = new ObjectMapper(); - - String des = mapper.writeValueAsString(activity); - JSONObject json = new JSONObject(des); - - HashMap<ArrayList<String>, JSONObject> nullContents = new HashMap<ArrayList<String>, JSONObject>(); - ArrayList<String> drilldownKeys = new ArrayList<String>(); - - findNullContents(json, drilldownKeys, nullContents); - - for ( Map.Entry<ArrayList<String>,JSONObject> entry : nullContents.entrySet() ) { - JSONObject frag = entry.getValue(); - editJson(json, entry.getKey(), frag.get("")); - } - - StringReader str = new StringReader(json.toString()); - Activity testAct = null; - try { - testAct = mapper.readValue(str, Activity.class); - } catch (Exception e) { - LOGGER.error("Exception creating activity.", e); - LOGGER.error("JSON : {}"+json.toString()); - } - - return testAct; - }; - - public static JSONObject fix(JSONObject json) throws Exception { - - HashMap<ArrayList<String>, JSONObject> nullContents = new HashMap<ArrayList<String>, JSONObject>(); - ArrayList<String> drilldownKeys = new ArrayList<String>(); - - findNullContents(json, drilldownKeys, nullContents); - - for ( Map.Entry<ArrayList<String>,JSONObject> entry : nullContents.entrySet() ) { - JSONObject frag = entry.getValue(); - editJson(json, entry.getKey(), frag.get("")); - } - - return json; - }; - -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-streams/blob/0b512d8b/streams-contrib/streams-provider-gnip/gnip-powertrack/src/main/java/org/apache/streams/gnip/powertrack/PowerTrackActivitySerializer.java ---------------------------------------------------------------------- diff --git a/streams-contrib/streams-provider-gnip/gnip-powertrack/src/main/java/org/apache/streams/gnip/powertrack/PowerTrackActivitySerializer.java b/streams-contrib/streams-provider-gnip/gnip-powertrack/src/main/java/org/apache/streams/gnip/powertrack/PowerTrackActivitySerializer.java deleted file mode 100644 index 55b1423..0000000 --- a/streams-contrib/streams-provider-gnip/gnip-powertrack/src/main/java/org/apache/streams/gnip/powertrack/PowerTrackActivitySerializer.java +++ /dev/null @@ -1,121 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.streams.gnip.powertrack; - -import com.fasterxml.jackson.databind.DeserializationFeature; -import com.fasterxml.jackson.databind.ObjectMapper; -import org.apache.commons.lang.NotImplementedException; -import org.apache.streams.data.ActivitySerializer; -import org.apache.streams.pojo.json.Activity; -import org.json.JSONObject; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.io.StringReader; -import java.util.List; - -/** - * Created with IntelliJ IDEA. - * User: rebanks - * Date: 9/5/13 - * Time: 2:29 PM - * To change this template use File | Settings | File Templates. - */ -public class PowerTrackActivitySerializer implements ActivitySerializer<String> { - - private static final Logger LOGGER = LoggerFactory.getLogger(PowerTrackActivitySerializer.class); - - private ObjectMapper mapper; - - public PowerTrackActivitySerializer() { - mapper = new ObjectMapper(); - mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, Boolean.FALSE); - mapper.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, Boolean.TRUE); - mapper.configure(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT, Boolean.TRUE); - } - - - - @Override - public String serializationFormat() { - return "gnip_powertrack"; //To change body of implemented methods use File | Settings | File Templates. - } - - @Override - public String serialize(Activity deserialized) { - throw new UnsupportedOperationException(); - } - - @Override - public Activity deserialize(String serialized) { - Activity activity = null; - try { - JSONObject jsonObject = new JSONObject(serialized); - String content = jsonObject.optString("content", null); - if(content == null) { - content = jsonObject.optString("body", null); - if(content == null) { - content = jsonObject.optString("summary", null); - if(content == null) { - JSONObject object = jsonObject.optJSONObject("object"); - if(object != null) { - content = object.optString("content", null); - if(content == null) { - content = object.optString("body", null); - if(content == null) { - content = object.optString("summary", null); - } - } - } - } - } - - } - if(content != null) { - jsonObject.put("content", content); - } - String dateTime = jsonObject.optString("postedTime"); - if(dateTime != null) { - jsonObject.put("published", dateTime); - } - JSONObject actor = jsonObject.optJSONObject("actor"); - if(actor != null) { - String url = actor.optString("image"); - if(url != null) { - JSONObject media = new JSONObject(); - media.put("url", url); - actor.put("image", media); - } - } - serialized = jsonObject.toString(); - StringReader reader = new StringReader(serialized); - activity = this.mapper.readValue(reader, Activity.class); - } catch (Exception e) { - LOGGER.error("Exception deserializing powertrack string to Activity Object.", e); - LOGGER.error("Exception on json : {}", serialized); - } - return activity; - } - - @Override - public List<Activity> deserializeAll(List<String> serializedList) { - throw new NotImplementedException("Not currently supported by this deserializer"); - } - -}