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