001/**
002 * Copyright 2015 DuraSpace, Inc.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *     http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016package org.fcrepo.kernel.models;
017
018import java.util.Date;
019import java.util.Iterator;
020
021import javax.jcr.AccessDeniedException;
022import javax.jcr.Node;
023import javax.jcr.Property;
024import javax.jcr.version.Version;
025import javax.jcr.version.VersionHistory;
026
027import com.hp.hpl.jena.rdf.model.Resource;
028
029import org.fcrepo.kernel.exception.MalformedRdfException;
030import org.fcrepo.kernel.identifiers.IdentifierConverter;
031import org.fcrepo.kernel.utils.iterators.RdfStream;
032
033import com.hp.hpl.jena.rdf.model.Model;
034
035/**
036 * @author ajs6f
037 * @since Jan 10, 2014
038 */
039public interface FedoraResource {
040
041    /**
042     * @return The JCR node that backs this object.
043     */
044    Node getNode();
045
046    /**
047     * Get the path to the JCR node
048     * @return path
049     */
050    String getPath();
051
052    /**
053     * Get the children of this resource
054     * @return iterator
055     */
056    Iterator<FedoraResource> getChildren();
057
058    /**
059     * Get the container of this resource
060     * @return the container of this resource
061     */
062    FedoraResource getContainer();
063
064    /**
065     * Get the child of this resource at the given path
066     * @param relPath the given path
067     * @return the child of this resource
068     */
069    FedoraResource getChild(String relPath);
070
071    /**
072     * Does this resource have a property
073     * @param relPath the given path
074     * @return the boolean value whether the resource has a property
075     */
076    boolean hasProperty(String relPath);
077
078    /**
079     * Retrieve the given property value for this resource
080     * @param relPath the given path
081     * @return the property
082     */
083    Property getProperty(String relPath);
084
085    /**
086     * Delete this resource, and any inbound references to it
087     */
088    void delete();
089
090    /**
091     * Get the date this datastream was created
092     * @return created date
093     */
094    Date getCreatedDate();
095
096    /**
097     * Get the date this datastream was last modified
098     * @return last modified date
099     */
100    Date getLastModifiedDate();
101
102    /**
103     * Check if this object uses a given mixin
104     * @param type the given type
105     * @return a collection of mixin names
106     */
107    boolean hasType(final String type);
108    /**
109     * Update the provided properties with a SPARQL Update query. The updated
110     * properties may be serialized to the JCR store.
111     *
112     * After applying the statement, clients SHOULD check the result
113     * of #getDatasetProblems, which may include problems when attempting to
114     * serialize the data to JCR.
115     *
116     * @param idTranslator the property of idTranslator
117     * @param sparqlUpdateStatement sparql update statement
118     * @param originalTriples original triples
119     * @throws MalformedRdfException if malformed rdf exception occurred
120     * @throws AccessDeniedException if access denied in updating properties
121     */
122    void updateProperties(final IdentifierConverter<Resource, FedoraResource> idTranslator,
123                          final String sparqlUpdateStatement,
124                          final RdfStream originalTriples) throws MalformedRdfException, AccessDeniedException;
125
126    /**
127     * Return the RDF properties of this object using the provided context
128     * @param idTranslator the property of idTranslator
129     * @param context the context
130     * @return the rdf properties of this object using the provided context
131     */
132    RdfStream getTriples(final IdentifierConverter<Resource, FedoraResource> idTranslator,
133                         final Class<? extends RdfStream> context);
134
135    /**
136     * Return the RDF properties of this object using the provided contexts
137     * @param idTranslator the property of idTranslator
138     * @param contexts the provided contexts
139     * @return the rdf properties of this object
140     */
141    RdfStream getTriples(IdentifierConverter<Resource, FedoraResource> idTranslator,
142                         Iterable<? extends Class<? extends RdfStream>> contexts);
143
144    /**
145     * Get the JCR Base version for the node
146     *
147     * @return base version
148     */
149    public Version getBaseVersion();
150
151    /**
152     * Get JCR VersionHistory for the node.
153     *
154     * @return version history
155     */
156    public VersionHistory getVersionHistory();
157
158    /**
159     * Check if a resource was created in this session
160     * @return if resource created in this session
161     */
162    Boolean isNew();
163
164    /**
165     * Replace the properties of this object with the properties from the given
166     * model
167     *
168     * @param idTranslator the given property of idTranslator
169     * @param inputModel the input model
170     * @param originalTriples the original triples
171     * @throws MalformedRdfException if malformed rdf exception occurred
172     */
173    void replaceProperties(final IdentifierConverter<Resource, FedoraResource> idTranslator,
174                                final Model inputModel,
175                                final RdfStream originalTriples) throws MalformedRdfException;
176
177    /**
178         * Construct an ETag value from the last modified date and path. JCR has a
179     * mix:etag type, but it only takes into account binary properties. We
180     * actually want whole-object etag data. TODO : construct and store an ETag
181     * value on object modify
182     *
183     * @return constructed etag value
184     */
185    String getEtagValue();
186
187    /**
188     * Enable versioning
189     */
190    void enableVersioning();
191
192    /**
193     * Disable versioning
194     */
195    void disableVersioning();
196
197    /**
198     * Check if a resource is versioned
199     * @return whether the resource is versioned
200     */
201    boolean isVersioned();
202
203    /**
204     * Check if a resource is frozen (a historic version).
205     * @return whether the resource is frozen
206     */
207    boolean isFrozenResource();
208
209    /**
210     * When this is a frozen node, get the ancestor that was explicitly versioned
211     * @return the ancestor that was explicity versioned
212     */
213    FedoraResource getVersionedAncestor();
214
215    /**
216     * Get the unfrozen equivalent of a frozen versioned node
217     * @return the unfrozen equivalent of a frozen versioned node
218     */
219    FedoraResource getUnfrozenResource();
220
221    /**
222     * Get the node for this object at the version provided.
223     * @param label the label
224     * @return the node for this object at the version provided
225     */
226    Node getNodeVersion(String label);
227}