001/*
002 * (C) Copyright 2011-2016 Nuxeo SA (http://nuxeo.com/) and others.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *     http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 *
016 * Contributors:
017 *     Thomas Roger <troger@nuxeo.com>
018 */
019package org.nuxeo.ecm.activity;
020
021import java.io.Serializable;
022import java.util.Map;
023
024/**
025 * Filter called by the {@code ActivityStreamService} to store and filter activities for specific use cases.
026 *
027 * @author <a href="mailto:troger@nuxeo.com">Thomas Roger</a>
028 * @since 5.5
029 */
030public interface ActivityStreamFilter {
031
032    /**
033     * Returns the id of this {@code ActivityStreamFilter}.
034     */
035    String getId();
036
037    /**
038     * Returns {@code true} if this {@code ActivityStreamFilter} is interested in the given {@code activity},
039     * {@code false} otherwise.
040     */
041    boolean isInterestedIn(Activity activity);
042
043    /**
044     * Called by the {@code ActivityStreamService} when a new {@code Activity} is stored.
045     * <p>
046     * The given {@code activity} must not be modified.
047     */
048    void handleNewActivity(ActivityStreamService activityStreamService, Activity activity);
049
050    /**
051     * Called by the {@code ActivityStreamService} before removing the given {@code activities}.
052     *
053     * @since 5.6
054     */
055    void handleRemovedActivities(ActivityStreamService activityStreamService, ActivitiesList activities);
056
057    /**
058     * Called by the {@code ActivityStreamService} before removing the given {@code activityReply}.
059     *
060     * @since 5.6
061     */
062    void handleRemovedActivityReply(ActivityStreamService activityStreamService, Activity activity,
063            ActivityReply activityReply);
064
065    /**
066     * Returns the list of activities filtered by the given parameters.
067     *
068     * @param activityStreamService the main {@code ActivityStreamService}
069     * @param parameters this query parameters.
070     * @param offset the offset (starting at 0) into the list of activities.
071     * @param limit the maximum number of activities to retrieve, or 0 for all of them.
072     */
073    ActivitiesList query(ActivityStreamService activityStreamService, Map<String, Serializable> parameters, long offset,
074            long limit);
075
076}