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