001/* 002 * Licensed to DuraSpace under one or more contributor license agreements. 003 * See the NOTICE file distributed with this work for additional information 004 * regarding copyright ownership. 005 * 006 * DuraSpace licenses this file to you under the Apache License, 007 * Version 2.0 (the "License"); you may not use this file except in 008 * compliance with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, software 013 * distributed under the License is distributed on an "AS IS" BASIS, 014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 015 * See the License for the specific language governing permissions and 016 * limitations under the License. 017 */ 018package org.fcrepo.kernel.api.models; 019 020import java.net.URI; 021import java.util.Date; 022 023import java.util.List; 024import java.util.Set; 025import java.util.stream.Stream; 026 027import javax.jcr.version.Version; 028import javax.jcr.version.VersionHistory; 029 030import com.hp.hpl.jena.rdf.model.Resource; 031 032import org.fcrepo.kernel.api.exception.AccessDeniedException; 033import org.fcrepo.kernel.api.exception.MalformedRdfException; 034import org.fcrepo.kernel.api.identifiers.IdentifierConverter; 035import org.fcrepo.kernel.api.TripleCategory; 036import org.fcrepo.kernel.api.RdfStream; 037 038import com.hp.hpl.jena.rdf.model.Model; 039 040/** 041 * @author ajs6f 042 * @since Jan 10, 2014 043 */ 044public interface FedoraResource { 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 a stream of Fedora resources 055 */ 056 default Stream<FedoraResource> getChildren() { 057 return getChildren(false); 058 } 059 060 /** 061 * Get the children of this resource, possibly recursively 062 * @param recursive whether to recursively fetch child resources 063 * @return a stream of Fedora resources 064 */ 065 Stream<FedoraResource> getChildren(Boolean recursive); 066 067 /** 068 * Get the container of this resource 069 * @return the container of this resource 070 */ 071 FedoraResource getContainer(); 072 073 /** 074 * Get the child of this resource at the given path 075 * @param relPath the given path 076 * @return the child of this resource 077 */ 078 FedoraResource getChild(String relPath); 079 080 /** 081 * Does this resource have a property 082 * @param relPath the given path 083 * @return the boolean value whether the resource has a property 084 */ 085 boolean hasProperty(String relPath); 086 087 /** 088 * Delete this resource, and any inbound references to it 089 */ 090 void delete(); 091 092 /** 093 * Get the date this resource was created 094 * @return created date 095 */ 096 Date getCreatedDate(); 097 098 /** 099 * Get the date this resource was last modified 100 * @return last modified date 101 */ 102 Date getLastModifiedDate(); 103 104 /** 105 * Check if this object uses a given RDF type 106 * 107 * <p>Note: the type parameter should be in prefixed short form, so ldp:Container or ex:Image 108 * are both acceptable types. This method does not assume any jcr to fedora prefix mappings are 109 * managed by the implementation, so hasType("jcr:frozenNode") is a valid use of this method.</p> 110 * 111 * @param type the given type 112 * @return whether the object has the given type 113 */ 114 boolean hasType(final String type); 115 116 /** 117 * Get the RDF:type values for this resource 118 * @return a list of types for this resource 119 */ 120 List<URI> getTypes(); 121 122 /** 123 * Update the provided properties with a SPARQL Update query. The updated 124 * properties may be serialized to the JCR store. 125 * 126 * After applying the statement, clients SHOULD check the result 127 * of #getDatasetProblems, which may include problems when attempting to 128 * serialize the data to JCR. 129 * 130 * @param idTranslator the property of idTranslator 131 * @param sparqlUpdateStatement sparql update statement 132 * @param originalTriples original triples 133 * @throws MalformedRdfException if malformed rdf exception occurred 134 * @throws AccessDeniedException if access denied in updating properties 135 */ 136 void updateProperties(final IdentifierConverter<Resource, FedoraResource> idTranslator, 137 final String sparqlUpdateStatement, 138 final RdfStream originalTriples) throws MalformedRdfException, AccessDeniedException; 139 140 /** 141 * Return the RDF properties of this object using the provided context 142 * @param idTranslator the property of idTranslator 143 * @param context the context 144 * @return the rdf properties of this object using the provided context 145 */ 146 RdfStream getTriples(final IdentifierConverter<Resource, FedoraResource> idTranslator, 147 final TripleCategory context); 148 149 /** 150 * Return the RDF properties of this object using the provided contexts 151 * @param idTranslator the property of idTranslator 152 * @param contexts the provided contexts 153 * @return the rdf properties of this object 154 */ 155 RdfStream getTriples(final IdentifierConverter<Resource, FedoraResource> idTranslator, 156 final Set<? extends TripleCategory> contexts); 157 158 /** 159 * Get the JCR Base version for the node 160 * 161 * @return base version 162 */ 163 public Version getBaseVersion(); 164 165 /** 166 * Get JCR VersionHistory for the node. 167 * 168 * @return version history 169 */ 170 public VersionHistory getVersionHistory(); 171 172 /** 173 * Check if a resource was created in this session 174 * @return if resource created in this session 175 */ 176 Boolean isNew(); 177 178 /** 179 * Replace the properties of this object with the properties from the given 180 * model 181 * 182 * @param idTranslator the given property of idTranslator 183 * @param inputModel the input model 184 * @param originalTriples the original triples 185 * @throws MalformedRdfException if malformed rdf exception occurred 186 */ 187 void replaceProperties(final IdentifierConverter<Resource, FedoraResource> idTranslator, 188 final Model inputModel, 189 final RdfStream originalTriples) throws MalformedRdfException; 190 191 /** 192 * Construct an ETag value from the last modified date and path. JCR has a 193 * mix:etag type, but it only takes into account binary properties. We 194 * actually want whole-object etag data. TODO : construct and store an ETag 195 * value on object modify 196 * 197 * @return constructed etag value 198 */ 199 String getEtagValue(); 200 201 /** 202 * Enable versioning 203 */ 204 void enableVersioning(); 205 206 /** 207 * Disable versioning 208 */ 209 void disableVersioning(); 210 211 /** 212 * Check if a resource is versioned 213 * @return whether the resource is versioned 214 */ 215 boolean isVersioned(); 216 217 /** 218 * Check if a resource is frozen (a historic version). 219 * @return whether the resource is frozen 220 */ 221 boolean isFrozenResource(); 222 223 /** 224 * When this is a frozen node, get the ancestor that was explicitly versioned 225 * @return the ancestor that was explicity versioned 226 */ 227 FedoraResource getVersionedAncestor(); 228 229 /** 230 * Get the unfrozen equivalent of a frozen versioned node 231 * @return the unfrozen equivalent of a frozen versioned node 232 */ 233 FedoraResource getUnfrozenResource(); 234 235 /** 236 * Get a resource version for this object with the provided label. 237 * @param label the label 238 * @return the node for this object at the version provided 239 */ 240 FedoraResource getVersion(String label); 241 242 /** 243 * This method returns the version label of this frozen resource. 244 * If this resource is not frozen, null is returned. 245 * @return version label 246 */ 247 String getVersionLabelOfFrozenResource(); 248 249 /** 250 * Get the description for this resource 251 * @return the description for this resource 252 */ 253 FedoraResource getDescription(); 254 255 /** 256 * Get the resource described by this resource 257 * @return the resource being described 258 */ 259 FedoraResource getDescribedResource(); 260}