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 org.fcrepo.kernel.api.RdfStream;
009import org.fcrepo.kernel.api.Transaction;
010import org.fcrepo.kernel.api.identifiers.FedoraId;
011import org.fcrepo.kernel.api.models.FedoraResource;
012
013/**
014 * Service to retrieve references to repository resources.
015 * @author whikloj
016 * @since 6.0.0
017 */
018public interface ReferenceService {
019
020    /**
021     * Return a RDF stream of statements referring to the provided resource.
022     *
023     * @param tx the transaction or null if no transaction.
024     * @param resource the resource to get inbound references for.
025     * @return RDF stream of inbound reference triples.
026     */
027    RdfStream getInboundReferences(final Transaction tx, final FedoraResource resource);
028
029    /**
030     * Delete all references from a resource to any other resource.
031     *
032     * @param tx the transaction
033     * @param resourceId the ID of the resource referencing others.
034     */
035    void deleteAllReferences(final Transaction tx, final FedoraId resourceId);
036
037    /**
038     * Parse the stream of triples for references, add any new ones and remove any missing ones.
039     * @param tx the transaction
040     * @param resourceId the subject ID of the triples.
041     * @param userPrincipal the user who's action is updating references.
042     * @param rdfStream the RDF stream.
043     */
044    void updateReferences(final Transaction tx, final FedoraId resourceId, final String userPrincipal,
045                          final RdfStream rdfStream);
046
047    /**
048     * Commit any pending references.
049     * @param tx the transaction.
050     */
051    void commitTransaction(final Transaction tx);
052
053    /**
054     * Rollback any pending references.
055     * @param tx the transaction.
056     */
057    void rollbackTransaction(final Transaction tx);
058
059    /**
060     * Truncates the reference index. This should only be called when rebuilding the index.
061     */
062    void reset();
063}