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