001/*
002 * (C) Copyright 2011 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 */
019
020package org.nuxeo.ecm.activity;
021
022import java.io.Serializable;
023import java.util.Collection;
024import java.util.Map;
025
026/**
027 * Filter called by the {@code ActivityStreamService} to store and filter activities for specific use cases.
028 *
029 * @author <a href="mailto:troger@nuxeo.com">Thomas Roger</a>
030 * @since 5.5
031 */
032public interface ActivityStreamFilter {
033
034    /**
035     * Returns the id of this {@code ActivityStreamFilter}.
036     */
037    String getId();
038
039    /**
040     * Returns {@code true} if this {@code ActivityStreamFilter} is interested in the given {@code activity},
041     * {@code false} otherwise.
042     */
043    boolean isInterestedIn(Activity activity);
044
045    /**
046     * Called by the {@code ActivityStreamService} when a new {@code Activity} is stored.
047     * <p>
048     * The given {@code activity} must not be modified.
049     */
050    void handleNewActivity(ActivityStreamService activityStreamService, Activity activity);
051
052    /**
053     * Called by the {@code ActivityStreamService} before removing the activities referenced by the given
054     * {@code activityIds}.
055     *
056     * @deprecated since 5.6
057     */
058    @Deprecated
059    void handleRemovedActivities(ActivityStreamService activityStreamService, Collection<Serializable> activityIds);
060
061    /**
062     * Called by the {@code ActivityStreamService} before removing the given {@code activities}.
063     *
064     * @since 5.6
065     */
066    void handleRemovedActivities(ActivityStreamService activityStreamService, ActivitiesList activities);
067
068    /**
069     * Called by the {@code ActivityStreamService} before removing the given {@code activityReply}.
070     *
071     * @since 5.6
072     */
073    void handleRemovedActivityReply(ActivityStreamService activityStreamService, Activity activity,
074            ActivityReply activityReply);
075
076    /**
077     * Returns the list of activities filtered by the given parameters.
078     *
079     * @param activityStreamService the main {@code ActivityStreamService}
080     * @param parameters this query parameters.
081     * @param offset the offset (starting at 0) into the list of activities.
082     * @param limit the maximum number of activities to retrieve, or 0 for all of them.
083     */
084    ActivitiesList query(ActivityStreamService activityStreamService, Map<String, Serializable> parameters,
085            long offset, long limit);
086
087}