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 B113217680 for ; Tue, 31 Mar 2015 18:06:05 +0000 (UTC) Received: (qmail 32808 invoked by uid 500); 31 Mar 2015 18:05:59 -0000 Delivered-To: apmail-streams-dev-archive@streams.apache.org Received: (qmail 32764 invoked by uid 500); 31 Mar 2015 18:05:59 -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 32753 invoked by uid 99); 31 Mar 2015 18:05:58 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 31 Mar 2015 18:05:58 +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; Tue, 31 Mar 2015 18:05:57 +0000 Received: (qmail 31282 invoked by uid 99); 31 Mar 2015 18:05:37 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 31 Mar 2015 18:05:37 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 41176E17F5; Tue, 31 Mar 2015 18:05:37 +0000 (UTC) From: mfranklin To: dev@streams.incubator.apache.org Reply-To: dev@streams.incubator.apache.org References: In-Reply-To: Subject: [GitHub] incubator-streams pull request: STREAMS-259 Content-Type: text/plain Message-Id: <20150331180537.41176E17F5@git1-us-west.apache.org> Date: Tue, 31 Mar 2015 18:05:37 +0000 (UTC) X-Virus-Checked: Checked by ClamAV on apache.org Github user mfranklin commented on a diff in the pull request: https://github.com/apache/incubator-streams/pull/207#discussion_r27505660 --- Diff: streams-components/streams-filters/src/main/java/org/apache/streams/filters/VerbDefinitionKeepFilter.java --- @@ -0,0 +1,95 @@ +/* + * 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.filters; + +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.pojo.json.Activity; +import org.apache.streams.verbs.ObjectCombination; +import org.apache.streams.verbs.VerbDefinition; +import org.apache.streams.verbs.VerbDefinitionResolver; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.*; + +/** + * Checks one or more verb definitions against a stream of Activity documents, and drops any activities + * which do not match the filter criteria. + */ +public class VerbDefinitionKeepFilter implements StreamsProcessor { + + private static final String STREAMS_ID = "VerbDefinitionKeepFilter"; + private static final Logger LOGGER = LoggerFactory.getLogger(VerbDefinitionKeepFilter.class); + + protected Set verbDefinitionSet; + protected VerbDefinitionResolver resolver; + + public VerbDefinitionKeepFilter() { + // get with reflection + } + + public VerbDefinitionKeepFilter(Set verbDefinitionSet) { + this(); + this.verbDefinitionSet = verbDefinitionSet; + } + + @Override + public List process(StreamsDatum entry) { + + List result = Lists.newArrayList(); + + LOGGER.debug("{} filtering {}", STREAMS_ID, entry.getDocument().getClass()); + + Activity activity; + + Preconditions.checkArgument(entry.getDocument() instanceof Activity); + + activity = (Activity) entry.getDocument(); + + boolean match = false; + for( VerbDefinition verbDefinition : verbDefinitionSet) + if( verbDefinition.getValue() != null && + verbDefinition.getValue().equals(activity.getVerb())) + for (ObjectCombination objectCombination : verbDefinition.getObjects()) + if (VerbDefinitionResolver.filter(activity, objectCombination) == true) + match = true; --- End diff -- same comment as other filter. also can this be abstracted to a utility? --- 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. ---