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.time.Instant; 022 023import java.util.List; 024import java.util.Set; 025import java.util.stream.Stream; 026 027import org.apache.jena.rdf.model.Resource; 028 029import org.fcrepo.kernel.api.FedoraVersion; 030import org.fcrepo.kernel.api.RdfStream; 031import org.fcrepo.kernel.api.TripleCategory; 032import org.fcrepo.kernel.api.exception.AccessDeniedException; 033import org.fcrepo.kernel.api.exception.MalformedRdfException; 034import org.fcrepo.kernel.api.identifiers.IdentifierConverter; 035 036import org.apache.jena.rdf.model.Model; 037 038/** 039 * @author ajs6f 040 * @since Jan 10, 2014 041 */ 042public interface FedoraResource { 043 044 /** 045 * Get the path to the resource 046 * @return path 047 */ 048 String getPath(); 049 050 /** 051 * Get the children of this resource 052 * @return a stream of Fedora resources 053 */ 054 default Stream<FedoraResource> getChildren() { 055 return getChildren(false); 056 } 057 058 /** 059 * Get the children of this resource, possibly recursively 060 * @param recursive whether to recursively fetch child resources 061 * @return a stream of Fedora resources 062 */ 063 Stream<FedoraResource> getChildren(Boolean recursive); 064 065 /** 066 * Get the container of this resource 067 * @return the container of this resource 068 */ 069 FedoraResource getContainer(); 070 071 /** 072 * Get the child of this resource at the given path 073 * @param relPath the given path 074 * @return the child of this resource 075 */ 076 FedoraResource getChild(String relPath); 077 078 /** 079 * Does this resource have a property 080 * @param relPath the given path 081 * @return the boolean value whether the resource has a property 082 */ 083 boolean hasProperty(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 resource was created 092 * @return created date 093 */ 094 Instant getCreatedDate(); 095 096 /** 097 * Get the date this resource was last modified 098 * @return last modified date 099 */ 100 Instant getLastModifiedDate(); 101 102 /** 103 * Check if this object uses a given RDF type 104 * 105 * <p>Note: the type parameter should be in prefixed short form, so ldp:Container or ex:Image 106 * are both acceptable types. This method does not assume any jcr to fedora prefix mappings are 107 * managed by the implementation, so hasType("jcr:frozenNode") is a valid use of this method.</p> 108 * 109 * @param type the given type 110 * @return whether the object has the given type 111 */ 112 boolean hasType(final String type); 113 114 /** 115 * Get the RDF:type values for this resource 116 * @return a list of types for this resource 117 */ 118 List<URI> getTypes(); 119 120 /** 121 * Update the provided properties with a SPARQL Update query. The updated 122 * properties may be serialized to the persistence layer. 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 TripleCategory 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(final IdentifierConverter<Resource, FedoraResource> idTranslator, 150 final Set<? extends TripleCategory> contexts); 151 152 /** 153 * Get the base version for the node 154 * 155 * @return base version 156 */ 157 FedoraResource getBaseVersion(); 158 159 /** 160 * Get a stream of versions associated with this resource 161 * 162 * @return the versions associated with this resource 163 */ 164 Stream<FedoraVersion> getVersions(); 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 for the resource. 187 * 188 * @return constructed etag value 189 */ 190 String getEtagValue(); 191 192 /** 193 * Enable versioning 194 */ 195 void enableVersioning(); 196 197 /** 198 * Disable versioning 199 */ 200 void disableVersioning(); 201 202 /** 203 * Check if a resource is versioned 204 * @return whether the resource is versioned 205 */ 206 boolean isVersioned(); 207 208 /** 209 * Check if a resource is frozen (a historic version). 210 * @return whether the resource is frozen 211 */ 212 boolean isFrozenResource(); 213 214 /** 215 * When this is a frozen node, get the ancestor that was explicitly versioned 216 * @return the ancestor that was explicity versioned 217 */ 218 FedoraResource getVersionedAncestor(); 219 220 /** 221 * Get the unfrozen equivalent of a frozen versioned node 222 * @return the unfrozen equivalent of a frozen versioned node 223 */ 224 FedoraResource getUnfrozenResource(); 225 226 /** 227 * Get a resource version for this object with the provided label. 228 * @param label the label 229 * @return the node for this object at the version provided 230 */ 231 FedoraResource getVersion(String label); 232 233 /** 234 * This method returns the version label of this frozen resource. 235 * If this resource is not frozen, null is returned. 236 * @return version label 237 */ 238 String getVersionLabelOfFrozenResource(); 239 240 /** 241 * Get the description for this resource 242 * @return the description for this resource 243 */ 244 FedoraResource getDescription(); 245 246 /** 247 * Get the resource described by this resource 248 * @return the resource being described 249 */ 250 FedoraResource getDescribedResource(); 251}