001/* 002 * The contents of this file are subject to the license and copyright 003 * detailed in the LICENSE and NOTICE files at the root of the source 004 * tree. 005 */ 006package org.fcrepo.kernel.api.models; 007 008import java.net.URI; 009import java.time.Instant; 010 011import java.util.List; 012import java.util.Optional; 013import java.util.stream.Stream; 014 015import org.fcrepo.kernel.api.RdfStream; 016import org.fcrepo.kernel.api.exception.PathNotFoundException; 017import org.fcrepo.kernel.api.identifiers.FedoraId; 018 019/** 020 * A resource in a Fedora repository. 021 * 022 * @author ajs6f 023 * @since Jan 10, 2014 024 */ 025public interface FedoraResource { 026 027 /** 028 * Get the fedora identifier for this resource 029 * 030 * @return the fedora identifier 031 */ 032 String getId(); 033 034 /** 035 * Get the FedoraId for this resource. 036 * @return the FedoraId identifier. 037 */ 038 FedoraId getFedoraId(); 039 040 /** 041 * Get the FedoraId for the Archival Group of this resource, if it exists 042 * @return an Optional containing the FedoraId 043 */ 044 Optional<FedoraId> getArchivalGroupId(); 045 046 /** 047 * Get the resource which contains this resource. 048 * 049 * @return the parent resource 050 * @throws PathNotFoundException thrown if the parent cannot be found 051 */ 052 FedoraResource getParent() throws PathNotFoundException; 053 054 /** 055 * Get the FedoraId of this resource's parent 056 * 057 * @return the parent resource's id 058 */ 059 FedoraId getParentId(); 060 061 /** 062 * Get the children of this resource 063 * @return a stream of Fedora resources 064 */ 065 default Stream<FedoraResource> getChildren() { 066 return getChildren(false); 067 } 068 069 /** 070 * Get the children of this resource, possibly recursively 071 * @param recursive whether to recursively fetch child resources 072 * @return a stream of Fedora resources 073 */ 074 Stream<FedoraResource> getChildren(Boolean recursive); 075 076 /** 077 * Get the container of this resource 078 * @return the container of this resource 079 */ 080 FedoraResource getContainer(); 081 082 /** 083 * Get the Original Resource for which this resource is a memento or timemap for. If this resource is not a 084 * memento or timemap, then it is the original. 085 * 086 * @return the original resource for this 087 */ 088 FedoraResource getOriginalResource(); 089 090 /** 091 * Get the TimeMap/LDPCv of this resource 092 * 093 * @return the container for TimeMap/LDPCv of this resource 094 */ 095 TimeMap getTimeMap(); 096 097 /** 098 * Retrieve the mementoDatetime property and return it as an Instant 099 * 100 * @return the Instant for this resource 101 */ 102 Instant getMementoDatetime(); 103 104 /** 105 * Returns true if this resource is a Memento. 106 * 107 * @return true if the resource is a Memento. 108 */ 109 boolean isMemento(); 110 111 /** 112 * Returns true if this resource is an ACL. 113 * 114 * @return true if the resource is an ACL. 115 */ 116 boolean isAcl(); 117 118 /** 119 * Retrieve the Memento with the closest datetime to the request. 120 * 121 * @param mementoDatetime The requested date time. 122 * @return The closest Memento or null. 123 */ 124 FedoraResource findMementoByDatetime(Instant mementoDatetime); 125 126 /** 127 * Get the ACL of this resource 128 * @return the container for ACL of this resource 129 */ 130 FedoraResource getAcl(); 131 132 /** 133 * Does this resource have a property 134 * @param relPath the given path 135 * @return the boolean value whether the resource has a property 136 */ 137 boolean hasProperty(String relPath); 138 139 /** 140 * Get the date this resource was created 141 * @return created date 142 */ 143 Instant getCreatedDate(); 144 145 /** 146 * Get the created by value 147 * 148 * @return created by 149 */ 150 String getCreatedBy(); 151 152 /** 153 * Get the date this resource was last modified 154 * @return last modified date 155 */ 156 Instant getLastModifiedDate(); 157 158 /** 159 * Get the last modified by value 160 * @return last modified by 161 */ 162 String getLastModifiedBy(); 163 164 /** 165 * Check if this object uses a given RDF type 166 * 167 * @param type the given type 168 * @return whether the object has the given type 169 */ 170 boolean hasType(final String type); 171 172 /** 173 * Get only the user provided types from their RDF. 174 * @return a list of types from the user provided RDF. 175 */ 176 List<URI> getUserTypes(); 177 178 /** 179 * Get only the system defined types from their RDF. 180 * @param forRdf whether we only want types for displaying in a RDF body. 181 * @return a list of types from the user provided RDF. 182 */ 183 List<URI> getSystemTypes(final boolean forRdf); 184 185 /** 186 * Get the RDF:type values for this resource, this is usually the combination of getUserTypes and 187 * getSystemTypes(false) to get ALL the types. 188 * @return a list of types for this resource 189 */ 190 List<URI> getTypes(); 191 192 /** 193 * Return the RDF properties for this resource. 194 * 195 * @return the RDF properties of this object. 196 */ 197 RdfStream getTriples(); 198 199 /** 200 * Construct an ETag value for the resource. 201 * 202 * @return constructed etag value 203 */ 204 String getEtagValue(); 205 206 /** 207 * Construct a State Token value for the resource. 208 * 209 * @return constructed state-token value 210 */ 211 String getStateToken(); 212 213 /** 214 * Check if a resource is an original resource 215 * (ie versionable, as opposed to non-versionable resources 216 * like mementos, timemaps, and acls). 217 * @return whether the resource is an original resource. 218 */ 219 boolean isOriginalResource(); 220 221 /** 222 * Get the description for this resource 223 * @return the description for this resource 224 */ 225 FedoraResource getDescription(); 226 227 /** 228 * Get the resource described by this resource 229 * @return the resource being described 230 */ 231 FedoraResource getDescribedResource(); 232 233 /** 234 * Get the resource's interaction model. 235 * @return the interaction model. 236 */ 237 String getInteractionModel(); 238}