Return-Path: X-Original-To: apmail-streams-dev-archive@minotaur.apache.org Delivered-To: apmail-streams-dev-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 718A4CDD6 for ; Mon, 17 Nov 2014 15:45:54 +0000 (UTC) Received: (qmail 69040 invoked by uid 500); 17 Nov 2014 15:45:54 -0000 Delivered-To: apmail-streams-dev-archive@streams.apache.org Received: (qmail 68993 invoked by uid 500); 17 Nov 2014 15:45:54 -0000 Mailing-List: contact dev-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 dev@streams.incubator.apache.org Received: (qmail 68981 invoked by uid 99); 17 Nov 2014 15:45:54 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 17 Nov 2014 15:45:54 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED,T_RP_MATCHES_RCVD X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO mail.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with SMTP; Mon, 17 Nov 2014 15:45:52 +0000 Received: (qmail 68007 invoked by uid 99); 17 Nov 2014 15:45:32 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 17 Nov 2014 15:45:32 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 7590498D2B0; Mon, 17 Nov 2014 15:45:32 +0000 (UTC) From: robdouglas To: dev@streams.incubator.apache.org Reply-To: dev@streams.incubator.apache.org References: In-Reply-To: Subject: [GitHub] incubator-streams pull request: Streams 68,218 Content-Type: text/plain Message-Id: <20141117154532.7590498D2B0@tyr.zones.apache.org> Date: Mon, 17 Nov 2014 15:45:32 +0000 (UTC) X-Virus-Checked: Checked by ClamAV on apache.org Github user robdouglas commented on a diff in the pull request: https://github.com/apache/incubator-streams/pull/131#discussion_r20442870 --- Diff: streams-components/streams-converters/src/main/java/org/apache/streams/converter/ActivityConverterProcessor.java --- @@ -0,0 +1,167 @@ +/* +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.google.common.base.Preconditions; +import com.google.common.collect.Lists; +import org.apache.streams.core.StreamsDatum; +import org.apache.streams.data.ActivityConverter; +import org.apache.streams.data.ActivityConverterFactory; +import org.apache.streams.data.ActivityConverterResolver; +import org.apache.streams.data.DocumentClassifier; +import org.apache.streams.pojo.json.Activity; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.List; + +/** + * ActivityConverterProcessor is a utility processor for converting any datum document + * to an Activity. + * + * By default it will handle string json and objectnode representation of existing Activities. + * + * Implementations can add DocumentClassifiers and ActivityConverterResolvers to the processor + * to ensure additional ActivityConverters will be resolved and applied. + * + * A DocumentClassifier's reponsibility is to recognize document formats and label them, using + * a jackson-compatible POJO class. + * + * An ActivityConverterResolver's reponsibility is to identify ActivityConverter implementations + * capable of converting a raw document associated with that POJO class into an activity. + * + */ +public class ActivityConverterProcessor extends TypeConverterProcessor { + + private final static Logger LOGGER = LoggerFactory.getLogger(ActivityConverterProcessor.class); + + protected ActivityConverterProcessorConfiguration configuration; + + private List classifiers; + private List resolvers; + + public ActivityConverterProcessor() { + super(Activity.class); + this.classifiers = Lists.newArrayList(); + this.resolvers = Lists.newArrayList(); + } + + public ActivityConverterProcessor(ActivityConverterProcessorConfiguration configuration) { + super(Activity.class); + this.configuration = configuration; + this.classifiers = Lists.newArrayList(); + this.resolvers = Lists.newArrayList(); + } + + @Override + public List process(StreamsDatum entry) { + + Preconditions.checkArgument(classifiers.size() > 0); + Preconditions.checkArgument(resolvers.size() > 0); + + List result = Lists.newLinkedList(); + Object inDoc = entry.getDocument(); + + try { + + // This implementation is primitive, greedy, takes first it can resolve + Class datumClass = null; + for( DocumentClassifier classifier : classifiers ) { + datumClass = classifier.detectClass(inDoc); + if( classifier != null ) --- End diff -- Won't this break out of the loop on the first classifier, every time? Should this line be: if(datumClass != null)? --- 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. ---