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