001/*
002 * The contents of this file are subject to the license and copyright
003 * detailed in the LICENSE and NOTICE files at the root of the source
004 * tree.
005 */
006package org.fcrepo.kernel.api.services;
007
008import java.time.Instant;
009
010import org.fcrepo.kernel.api.RdfStream;
011import org.fcrepo.kernel.api.Transaction;
012import org.fcrepo.kernel.api.identifiers.FedoraId;
013
014/**
015 * Service used to manage membership properties of resources
016 *
017 * @author bbpennel
018 */
019public interface MembershipService {
020
021    /**
022     * Return an RdfStream of membership relations of which the provided resource is the subject.
023     *
024     * @param transaction transaction
025     * @param fedoraId the resource to get membership relations for.
026     * @return RdfStream of membership relations.
027     */
028    RdfStream getMembership(final Transaction transaction, final FedoraId fedoraId);
029
030    /**
031     * Update membership properties based on the creation of the specified resource
032     *
033     * @param transaction transaction
034     * @param fedoraId ID of the object created
035     */
036    void resourceCreated(final Transaction transaction, final FedoraId fedoraId);
037
038    /**
039     * Update membership properties based on the modification of the specified resource
040     *
041     * @param transaction transaction
042     * @param fedoraId ID of the object modified
043     */
044    void resourceModified(final Transaction transaction, final FedoraId fedoraId);
045
046    /**
047     * Update membership properties based on the deletion of the specified resource
048     *
049     * @param transaction transaction
050     * @param fedoraId ID of the object deleted
051     */
052    void resourceDeleted(final Transaction transaction, final FedoraId fedoraId);
053
054    /**
055     * Regenerate the membership history for specified Direct or Indirect container.
056     *
057     * @param transaction transaction
058     * @param containerId ID of the container
059     */
060    void populateMembershipHistory(final Transaction transaction, final FedoraId containerId);
061
062    /**
063     * Get the timestamp of the most recent member added or removed, or null if none.
064     * @param transaction transaction or null if none
065     * @param fedoraId the resource id
066     * @return the timestamp or null
067     */
068    Instant getLastUpdatedTimestamp(final Transaction transaction, final FedoraId fedoraId);
069
070    /**
071     * Commit any pending membership changes.
072     * @param transaction the transaction
073     */
074    void commitTransaction(final Transaction transaction);
075
076    /**
077     * Rollback any pending membership changes.
078     * @param transaction the transaction
079     */
080    void rollbackTransaction(final Transaction transaction);
081
082    /**
083     * Truncates the membership index. This should only be called when rebuilding the index.
084     */
085    void reset();
086}