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.models;
019
020import java.util.stream.Stream;
021
022import org.fcrepo.kernel.api.Transaction;
023import org.fcrepo.kernel.api.exception.PathNotFoundException;
024import org.fcrepo.kernel.api.identifiers.FedoraId;
025
026/**
027 * Interface to a factory to instantiate FedoraResources
028 *
029 * @author whikloj
030 * @since 2019-09-23
031 */
032public interface ResourceFactory {
033
034    /**
035     * Get a FedoraResource for existing resource without using a transaction.
036     *
037     * @param fedoraID The path or identifier for the resource.
038     * @return The resource.
039     * @throws PathNotFoundException If the identifier cannot be found.
040     */
041    public FedoraResource getResource(final FedoraId fedoraID)
042            throws PathNotFoundException;
043
044    /**
045     * Get a FedoraResource for existing resource
046     *
047     * @param transaction The transaction associated with this request or null if not in a transaction.
048     * @param fedoraID The identifier for the resource.
049     * @return The resource.
050     * @throws PathNotFoundException If the identifier cannot be found.
051     */
052    public FedoraResource getResource(final Transaction transaction, final FedoraId fedoraID)
053            throws PathNotFoundException;
054
055    /**
056     * Get a FedoraResource for existing resource
057     *
058     * @param transactionId The transaction id associated with this request or null if not in a transaction.
059     * @param fedoraID The identifier for the resource.
060     * @return The resource.
061     * @throws PathNotFoundException If the identifier cannot be found.
062     */
063    public FedoraResource getResource(final String transactionId, final FedoraId fedoraID)
064            throws PathNotFoundException;
065
066    /**
067     * Get a resource as a particular type without a transaction
068     *
069     * @param <T> type for the resource
070     * @param fedoraID The identifier for the resource.
071     * @param clazz class the resource will be cast to
072     * @return The resource.
073     * @throws PathNotFoundException If the identifier cannot be found.
074     */
075    public <T extends FedoraResource> T getResource(final FedoraId fedoraID,
076            final Class<T> clazz) throws PathNotFoundException;
077
078    /**
079     * Get a resource as a particular type
080     *
081     * @param <T> type for the resource
082     * @param transaction The transaction associated with this request or null
083     * @param fedoraID The identifier for the resource.
084     * @param clazz class the resource will be cast to
085     * @return The resource.
086     * @throws PathNotFoundException If the identifier cannot be found.
087     */
088    public <T extends FedoraResource> T getResource(final Transaction transaction, final FedoraId fedoraID,
089                                                    final Class<T> clazz) throws PathNotFoundException;
090
091    /**
092     * Get the containing resource (if exists).
093     * @param transactionId The current transaction id
094     * @param resourceId The internal identifier
095     * @return The containing resource or null if none.
096     */
097    public FedoraResource getContainer(final String transactionId, final FedoraId resourceId);
098
099    /**
100     * Get immediate children of the resource
101     * @param transactionId The transaction id
102     * @param resourceId Identifier of the resource
103     * @return Stream of child resources
104     */
105    public Stream<FedoraResource> getChildren(final String transactionId, final FedoraId resourceId);
106}