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 path to the resource
061     *
062     * @return path
063     * @deprecated use getId()
064     */
065    @Deprecated
066    String getPath();
067
068    /**
069     * Get the children of this resource
070     * @return a stream of Fedora resources
071     */
072    default Stream<FedoraResource> getChildren() {
073        return getChildren(false);
074    }
075
076    /**
077     * Get the children of this resource, possibly recursively
078     * @param recursive whether to recursively fetch child resources
079     * @return a stream of Fedora resources
080     */
081    Stream<FedoraResource> getChildren(Boolean recursive);
082
083    /**
084     * Get the container of this resource
085     * @return the container of this resource
086     */
087    FedoraResource getContainer();
088
089    /**
090     * Get the Original Resource for which this resource is a memento or timemap for. If this resource is not a
091     * memento or timemap, then it is the original.
092     *
093     * @return the original resource for this
094     */
095    FedoraResource getOriginalResource();
096
097    /**
098     * Get the TimeMap/LDPCv of this resource
099     *
100     * @return the container for TimeMap/LDPCv of this resource
101     */
102    TimeMap getTimeMap();
103
104    /**
105     * Retrieve the mementoDatetime property and return it as an Instant
106     *
107     * @return the Instant for this resource
108     */
109    Instant getMementoDatetime();
110
111    /**
112     * Returns true if this resource is a Memento.
113     *
114     * @return true if the resource is a Memento.
115     */
116    boolean isMemento();
117
118    /**
119     * Returns true if this resource is an ACL.
120     *
121     * @return true if the resource is an ACL.
122     */
123    boolean isAcl();
124
125    /**
126     * Retrieve the Memento with the closest datetime to the request.
127     *
128     * @param mementoDatetime The requested date time.
129     * @return The closest Memento or null.
130     */
131    FedoraResource findMementoByDatetime(Instant mementoDatetime);
132
133    /**
134     * Get the ACL of this resource
135     * @return the container for ACL of this resource
136     */
137    FedoraResource getAcl();
138
139    /**
140     * Does this resource have a property
141     * @param relPath the given path
142     * @return the boolean value whether the resource has a property
143     */
144    boolean hasProperty(String relPath);
145
146    /**
147     * Get the date this resource was created
148     * @return created date
149     */
150    Instant getCreatedDate();
151
152    /**
153     * Get the created by value
154     *
155     * @return created by
156     */
157    String getCreatedBy();
158
159    /**
160     * Get the date this resource was last modified
161     * @return last modified date
162     */
163    Instant getLastModifiedDate();
164
165    /**
166     * Get the last modified by value
167     * @return last modified by
168     */
169    String getLastModifiedBy();
170
171    /**
172     * Check if this object uses a given RDF type
173     *
174     * @param type the given type
175     * @return whether the object has the given type
176     */
177    boolean hasType(final String type);
178
179    /**
180     * Get only the user provided types from their RDF.
181     * @return a list of types from the user provided RDF.
182     */
183    List<URI> getUserTypes();
184
185    /**
186     * Get only the system defined types from their RDF.
187     * @param forRdf whether we only want types for displaying in a RDF body.
188     * @return a list of types from the user provided RDF.
189     */
190    List<URI> getSystemTypes(final boolean forRdf);
191
192    /**
193     * Get the RDF:type values for this resource, this is usually the combination of getUserTypes and
194     * getSystemTypes(false) to get ALL the types.
195     * @return a list of types for this resource
196     */
197    List<URI> getTypes();
198
199    /**
200     * Return the RDF properties for this resource.
201     *
202     * @return the RDF properties of this object.
203     */
204    RdfStream getTriples();
205
206    /**
207     * Check if a resource was created in this session
208     *
209     * @return if resource created in this session
210     */
211    @Deprecated
212    Boolean isNew();
213
214    /**
215     * Construct an ETag value for the resource.
216     *
217     * @return constructed etag value
218     */
219    String getEtagValue();
220
221    /**
222     * Construct a State Token value for the resource.
223     *
224     * @return constructed state-token value
225     */
226    String getStateToken();
227
228    /**
229     * Check if a resource is an original resource
230     * (ie versionable, as opposed to non-versionable resources
231     * like mementos, timemaps, and acls).
232     * @return whether the resource is an original resource.
233     */
234    boolean isOriginalResource();
235
236    /**
237     * Get the description for this resource
238     * @return the description for this resource
239     */
240    FedoraResource getDescription();
241
242    /**
243     * Get the resource described by this resource
244     * @return the resource being described
245     */
246    FedoraResource getDescribedResource();
247
248    /**
249     * Get the resource's interaction model.
250     * @return the interaction model.
251     */
252    String getInteractionModel();
253}