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.net.URI;
021import java.time.Instant;
022
023import java.util.List;
024import java.util.stream.Stream;
025
026import org.fcrepo.kernel.api.RdfStream;
027import org.fcrepo.kernel.api.exception.PathNotFoundException;
028import org.fcrepo.kernel.api.identifiers.FedoraId;
029
030/**
031 * A resource in a Fedora repository.
032 *
033 * @author ajs6f
034 * @since Jan 10, 2014
035 */
036public interface FedoraResource {
037
038    /**
039     * Get the fedora identifier for this resource
040     *
041     * @return the fedora identifier
042     */
043    String getId();
044
045    /**
046     * Get the FedoraId for this resource.
047     * @return the FedoraId identifier.
048     */
049    FedoraId getFedoraId();
050
051    /**
052     * Get the resource which contains this resource.
053     *
054     * @return the parent resource
055     * @throws PathNotFoundException thrown if the parent cannot be found
056     */
057    FedoraResource getParent() throws PathNotFoundException;
058
059    /**
060     * Get the children of this resource
061     * @return a stream of Fedora resources
062     */
063    default Stream<FedoraResource> getChildren() {
064        return getChildren(false);
065    }
066
067    /**
068     * Get the children of this resource, possibly recursively
069     * @param recursive whether to recursively fetch child resources
070     * @return a stream of Fedora resources
071     */
072    Stream<FedoraResource> getChildren(Boolean recursive);
073
074    /**
075     * Get the container of this resource
076     * @return the container of this resource
077     */
078    FedoraResource getContainer();
079
080    /**
081     * Get the Original Resource for which this resource is a memento or timemap for. If this resource is not a
082     * memento or timemap, then it is the original.
083     *
084     * @return the original resource for this
085     */
086    FedoraResource getOriginalResource();
087
088    /**
089     * Get the TimeMap/LDPCv of this resource
090     *
091     * @return the container for TimeMap/LDPCv of this resource
092     */
093    TimeMap getTimeMap();
094
095    /**
096     * Retrieve the mementoDatetime property and return it as an Instant
097     *
098     * @return the Instant for this resource
099     */
100    Instant getMementoDatetime();
101
102    /**
103     * Returns true if this resource is a Memento.
104     *
105     * @return true if the resource is a Memento.
106     */
107    boolean isMemento();
108
109    /**
110     * Returns true if this resource is an ACL.
111     *
112     * @return true if the resource is an ACL.
113     */
114    boolean isAcl();
115
116    /**
117     * Retrieve the Memento with the closest datetime to the request.
118     *
119     * @param mementoDatetime The requested date time.
120     * @return The closest Memento or null.
121     */
122    FedoraResource findMementoByDatetime(Instant mementoDatetime);
123
124    /**
125     * Get the ACL of this resource
126     * @return the container for ACL of this resource
127     */
128    FedoraResource getAcl();
129
130    /**
131     * Does this resource have a property
132     * @param relPath the given path
133     * @return the boolean value whether the resource has a property
134     */
135    boolean hasProperty(String relPath);
136
137    /**
138     * Get the date this resource was created
139     * @return created date
140     */
141    Instant getCreatedDate();
142
143    /**
144     * Get the created by value
145     *
146     * @return created by
147     */
148    String getCreatedBy();
149
150    /**
151     * Get the date this resource was last modified
152     * @return last modified date
153     */
154    Instant getLastModifiedDate();
155
156    /**
157     * Get the last modified by value
158     * @return last modified by
159     */
160    String getLastModifiedBy();
161
162    /**
163     * Check if this object uses a given RDF type
164     *
165     * @param type the given type
166     * @return whether the object has the given type
167     */
168    boolean hasType(final String type);
169
170    /**
171     * Get only the user provided types from their RDF.
172     * @return a list of types from the user provided RDF.
173     */
174    List<URI> getUserTypes();
175
176    /**
177     * Get only the system defined types from their RDF.
178     * @param forRdf whether we only want types for displaying in a RDF body.
179     * @return a list of types from the user provided RDF.
180     */
181    List<URI> getSystemTypes(final boolean forRdf);
182
183    /**
184     * Get the RDF:type values for this resource, this is usually the combination of getUserTypes and
185     * getSystemTypes(false) to get ALL the types.
186     * @return a list of types for this resource
187     */
188    List<URI> getTypes();
189
190    /**
191     * Return the RDF properties for this resource.
192     *
193     * @return the RDF properties of this object.
194     */
195    RdfStream getTriples();
196
197    /**
198     * Construct an ETag value for the resource.
199     *
200     * @return constructed etag value
201     */
202    String getEtagValue();
203
204    /**
205     * Construct a State Token value for the resource.
206     *
207     * @return constructed state-token value
208     */
209    String getStateToken();
210
211    /**
212     * Check if a resource is an original resource
213     * (ie versionable, as opposed to non-versionable resources
214     * like mementos, timemaps, and acls).
215     * @return whether the resource is an original resource.
216     */
217    boolean isOriginalResource();
218
219    /**
220     * Get the description for this resource
221     * @return the description for this resource
222     */
223    FedoraResource getDescription();
224
225    /**
226     * Get the resource described by this resource
227     * @return the resource being described
228     */
229    FedoraResource getDescribedResource();
230
231    /**
232     * Get the resource's interaction model.
233     * @return the interaction model.
234     */
235    String getInteractionModel();
236}