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.identifiers.FedoraId;
024
025/**
026 * Service used to manage membership properties of resources
027 *
028 * @author bbpennel
029 */
030public interface MembershipService {
031
032    /**
033     * Return an RdfStream of membership relations of which the provided resource is the subject.
034     *
035     * @param txId transaction id
036     * @param fedoraId the resource to get membership relations for.
037     * @return RdfStream of membership relations.
038     */
039    RdfStream getMembership(final String txId, final FedoraId fedoraId);
040
041    /**
042     * Update membership properties based on the creation of the specified resource
043     *
044     * @param txId transaction id
045     * @param fedoraId ID of the object created
046     */
047    void resourceCreated(final String txId, final FedoraId fedoraId);
048
049    /**
050     * Update membership properties based on the modification of the specified resource
051     *
052     * @param txId transaction id
053     * @param fedoraId ID of the object modified
054     */
055    void resourceModified(final String txId, final FedoraId fedoraId);
056
057    /**
058     * Update membership properties based on the deletion of the specified resource
059     *
060     * @param txId transaction id
061     * @param fedoraId ID of the object deleted
062     */
063    void resourceDeleted(final String txId, final FedoraId fedoraId);
064
065    /**
066     * Regenerate the membership history for specified Direct or Indirect container.
067     *
068     * @param txId transaction id
069     * @param containerId ID of the container
070     */
071    void populateMembershipHistory(final String txId, final FedoraId containerId);
072
073    /**
074     * Get the timestamp of the most recent member added or removed, or null if none.
075     * @param txId transaction id or null if none
076     * @param fedoraId the resource id
077     * @return the timestamp or null
078     */
079    Instant getLastUpdatedTimestamp(final String txId, final FedoraId fedoraId);
080
081    /**
082     * Commit any pending membership changes.
083     * @param txId the transaction id.
084     */
085    void commitTransaction(final String txId);
086
087    /**
088     * Rollback any pending membership changes.
089     * @param txId the transaction id.
090     */
091    void rollbackTransaction(final String txId);
092
093    /**
094     * Truncates the membership index. This should only be called when rebuilding the index.
095     */
096    void reset();
097}