001/*
002 * Licensed to DuraSpace under one or more contributor license agreements.
003 * See the NOTICE file distributed with this work for additional information
004 * regarding copyright ownership.
005 *
006 * DuraSpace licenses this file to you under the Apache License,
007 * Version 2.0 (the "License"); you may not use this file except in
008 * compliance with the License.  You may obtain a copy of the License at
009 *
010 *     http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software
013 * distributed under the License is distributed on an "AS IS" BASIS,
014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018package org.fcrepo.kernel.api.services;
019
020import java.time.Instant;
021
022import org.fcrepo.kernel.api.RdfStream;
023import org.fcrepo.kernel.api.Transaction;
024import org.fcrepo.kernel.api.identifiers.FedoraId;
025
026/**
027 * Service used to manage membership properties of resources
028 *
029 * @author bbpennel
030 */
031public interface MembershipService {
032
033    /**
034     * Return an RdfStream of membership relations of which the provided resource is the subject.
035     *
036     * @param transaction transaction
037     * @param fedoraId the resource to get membership relations for.
038     * @return RdfStream of membership relations.
039     */
040    RdfStream getMembership(final Transaction transaction, final FedoraId fedoraId);
041
042    /**
043     * Update membership properties based on the creation of the specified resource
044     *
045     * @param transaction transaction
046     * @param fedoraId ID of the object created
047     */
048    void resourceCreated(final Transaction transaction, final FedoraId fedoraId);
049
050    /**
051     * Update membership properties based on the modification of the specified resource
052     *
053     * @param transaction transaction
054     * @param fedoraId ID of the object modified
055     */
056    void resourceModified(final Transaction transaction, final FedoraId fedoraId);
057
058    /**
059     * Update membership properties based on the deletion of the specified resource
060     *
061     * @param transaction transaction
062     * @param fedoraId ID of the object deleted
063     */
064    void resourceDeleted(final Transaction transaction, final FedoraId fedoraId);
065
066    /**
067     * Regenerate the membership history for specified Direct or Indirect container.
068     *
069     * @param transaction transaction
070     * @param containerId ID of the container
071     */
072    void populateMembershipHistory(final Transaction transaction, final FedoraId containerId);
073
074    /**
075     * Get the timestamp of the most recent member added or removed, or null if none.
076     * @param transaction transaction or null if none
077     * @param fedoraId the resource id
078     * @return the timestamp or null
079     */
080    Instant getLastUpdatedTimestamp(final Transaction transaction, final FedoraId fedoraId);
081
082    /**
083     * Commit any pending membership changes.
084     * @param transaction the transaction
085     */
086    void commitTransaction(final Transaction transaction);
087
088    /**
089     * Rollback any pending membership changes.
090     * @param transaction the transaction
091     */
092    void rollbackTransaction(final Transaction transaction);
093
094    /**
095     * Truncates the membership index. This should only be called when rebuilding the index.
096     */
097    void reset();
098}