You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@streams.apache.org by steveblackmon <gi...@git.apache.org> on 2014/12/01 23:34:27 UTC
[GitHub] incubator-streams pull request: resolves STREAMS-212
GitHub user steveblackmon opened a pull request:
https://github.com/apache/incubator-streams/pull/149
resolves STREAMS-212
Generic TypeConverterProcessor
You can merge this pull request into a Git repository by running:
$ git pull https://github.com/steveblackmon/incubator-streams STREAMS-212
Alternatively you can review and apply these changes as the patch at:
https://github.com/apache/incubator-streams/pull/149.patch
To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:
This closes #149
----
commit b52e7653a720e41bd0f9b714556d7aeae3e84c7d
Author: sblackmon <sb...@w2odigital.com>
Date: 2014-12-01T22:25:45Z
resolves STREAMS-212
commit cc23286da4d266e8d4e5662272915bdc4c899651
Author: sblackmon <sb...@w2odigital.com>
Date: 2014-12-01T22:33:54Z
logging and javadocs
----
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] incubator-streams pull request: resolves STREAMS-212
Posted by asfgit <gi...@git.apache.org>.
Github user asfgit closed the pull request at:
https://github.com/apache/incubator-streams/pull/149
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] incubator-streams pull request: resolves STREAMS-212
Posted by robdouglas <gi...@git.apache.org>.
Github user robdouglas commented on the pull request:
https://github.com/apache/incubator-streams/pull/149#issuecomment-65864814
:+1:
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] incubator-streams pull request: resolves STREAMS-212
Posted by robdouglas <gi...@git.apache.org>.
Github user robdouglas commented on a diff in the pull request:
https://github.com/apache/incubator-streams/pull/149#discussion_r21405155
--- Diff: streams-components/streams-converters/src/main/java/org/apache/streams/converter/TypeConverterProcessor.java ---
@@ -0,0 +1,91 @@
+/*
+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
+with the License. You may obtain a copy of the License at
+
+ 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.converter;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.google.common.base.Preconditions;
+import com.google.common.collect.Lists;
+import org.apache.streams.core.StreamsDatum;
+import org.apache.streams.core.StreamsProcessor;
+import org.apache.streams.jackson.StreamsJacksonMapper;
+import org.apache.streams.pojo.json.Activity;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.Serializable;
+import java.util.List;
+
+/**
+ * TypeConverterProcessor converts between String json and jackson-compatible POJO objects.
+ *
+ * Activity is one supported jackson-compatible POJO, so JSON String and objects with structual similarities
+ * to Activity can be converted to Activity objects.
+ *
+ * However, conversion to Activity should probably use {@link org.apache.streams.converter.ActivityConverterProcessor}
+ *
+ */
+public class TypeConverterProcessor implements StreamsProcessor, Serializable {
+
+ private final static Logger LOGGER = LoggerFactory.getLogger(TypeConverterProcessor.class);
+
+ private List<String> formats = Lists.newArrayList();
+
+ protected ObjectMapper mapper;
+
+ protected Class outClass;
+
+ public TypeConverterProcessor(Class outClass) {
+ this.outClass = outClass;
+ }
+
+ public TypeConverterProcessor(Class outClass, List<String> formats) {
+ this(outClass);
+ this.formats = formats;
+ }
+
+ @Override
+ public List<StreamsDatum> process(StreamsDatum entry) {
+
+ List<StreamsDatum> result = Lists.newLinkedList();
+ Object inDoc = entry.getDocument();
+
+ Object outDoc = TypeConverterUtil.convert(inDoc, outClass, mapper);
+
+ if( outDoc != null ) {
+ entry.setDocument(outDoc);
+ result.add(entry);
+ }
+
+ return result;
+ }
+
+ @Override
+ public void prepare(Object configurationObject) {
+ if( formats.size() > 0 )
--- End diff --
Small Nit: Could you surround these lines with braces?
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---