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