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; 019 020import static com.google.common.collect.ImmutableSet.of; 021import static org.apache.jena.rdf.model.ResourceFactory.createProperty; 022import static org.apache.jena.rdf.model.ResourceFactory.createResource; 023import static org.apache.jena.vocabulary.RDF.type; 024 025import java.util.Set; 026import java.util.function.Predicate; 027import java.util.stream.Collectors; 028 029import org.apache.jena.graph.Triple; 030import org.apache.jena.rdf.model.Property; 031import org.apache.jena.rdf.model.Resource; 032 033import com.google.common.collect.ImmutableSet; 034 035/** 036 * A lexicon of the RDF properties that the fcrepo kernel (or close-to-core modules) use 037 * 038 * @author ajs6f 039 */ 040public final class RdfLexicon { 041 042 /** 043 * Repository namespace "fedora" 044 **/ 045 public static final String REPOSITORY_NAMESPACE = "http://fedora.info/definitions/v4/repository#"; 046 047 public static final String REPOSITORY_WEBAC_NAMESPACE = "http://fedora.info/definitions/v4/webac#"; 048 049 public static final String FCREPO_API_NAMESPACE = "http://fedora.info/definitions/fcrepo#"; 050 051 public static final String ACTIVITY_STREAMS_NAMESPACE = "https://www.w3.org/ns/activitystreams#"; 052 053 public static final String EBUCORE_NAMESPACE = "http://www.ebu.ch/metadata/ontologies/ebucore/ebucore#"; 054 055 public static final String OA_NAMESPACE = "http://www.w3.org/ns/oa#"; 056 057 public static final String PROV_NAMESPACE = "http://www.w3.org/ns/prov#"; 058 059 public static final String PREMIS_NAMESPACE = "http://www.loc.gov/premis/rdf/v1#"; 060 061 public static final String MEMENTO_NAMESPACE = "http://mementoweb.org/ns#"; 062 063 public static final String RDF_NAMESPACE = "http://www.w3.org/1999/02/22-rdf-syntax-ns#"; 064 065 066 /** 067 * Namespace for the W3C WebAC vocabulary. 068 */ 069 public static final String WEBAC_NAMESPACE_VALUE = "http://www.w3.org/ns/auth/acl#"; 070 071 /** 072 * Linked Data Platform namespace. 073 */ 074 public static final String LDP_NAMESPACE = "http://www.w3.org/ns/ldp#"; 075 076 /** 077 * Is this namespace one that the repository manages? 078 */ 079 public static final Predicate<String> isManagedNamespace = p -> p.equals(REPOSITORY_NAMESPACE) || 080 p.equals(LDP_NAMESPACE) || p.equals(MEMENTO_NAMESPACE); 081 082 /** 083 * Tests if the triple has a predicate of rdf:type and an object with a managed namespace. 084 * @see RdfLexicon#isManagedNamespace 085 */ 086 public static final Predicate<Triple> restrictedType = s -> s.getPredicate().equals(type.asNode()) && 087 (s.getObject().isURI() && isManagedNamespace.test(s.getObject().getNameSpace())); 088 089 // FIXITY 090 public static final Resource PREMIS_FIXITY = 091 createResource(PREMIS_NAMESPACE + "Fixity"); 092 public static final Resource PREMIS_EVENT_OUTCOME_DETAIL = 093 createResource(PREMIS_NAMESPACE + "EventOutcomeDetail"); 094 095 public static final Property HAS_MESSAGE_DIGEST = 096 createProperty(PREMIS_NAMESPACE + "hasMessageDigest"); 097 098 public static final Property HAS_SIZE = 099 createProperty(PREMIS_NAMESPACE + "hasSize"); 100 public static final Property HAS_FIXITY_RESULT = 101 createProperty(PREMIS_NAMESPACE + "hasFixity"); 102 103 private static final Set<Property> fixityProperties = of( 104 HAS_FIXITY_RESULT, HAS_MESSAGE_DIGEST); 105 106 public static final Property HAS_FIXITY_STATE = 107 createProperty(PREMIS_NAMESPACE + "hasEventOutcome"); 108 109 public static final Property WRITABLE = 110 createProperty(REPOSITORY_NAMESPACE + "writable"); 111 112 public static final String FEDORA_NON_RDF_SOURCE_DESCRIPTION_URI = REPOSITORY_NAMESPACE + 113 "NonRdfSourceDescription"; 114 115 // Server managed properties 116 public static final Property CREATED_DATE = 117 createProperty(REPOSITORY_NAMESPACE + "created"); 118 public static final Property CREATED_BY = 119 createProperty(REPOSITORY_NAMESPACE + "createdBy"); 120 public static final Property LAST_MODIFIED_DATE = 121 createProperty(REPOSITORY_NAMESPACE + "lastModified"); 122 public static final Property LAST_MODIFIED_BY = 123 createProperty(REPOSITORY_NAMESPACE + "lastModifiedBy"); 124 125 public static final Resource FEDORA_CONTAINER = 126 createResource(REPOSITORY_NAMESPACE + "Container"); 127 public static final Resource FEDORA_BINARY = 128 createResource(REPOSITORY_NAMESPACE + "Binary"); 129 public static final Resource FEDORA_RESOURCE = 130 createResource(REPOSITORY_NAMESPACE + "Resource"); 131 public static final Resource FEDORA_PAIR_TREE = 132 createResource(REPOSITORY_NAMESPACE + "Pairtree"); 133 public static final Resource ARCHIVAL_GROUP = 134 createResource(REPOSITORY_NAMESPACE + "ArchivalGroup"); 135 136 // Linked Data Platform 137 public static final Property PAGE = 138 createProperty(LDP_NAMESPACE + "Page"); 139 public static final Resource CONTAINER = 140 createResource(LDP_NAMESPACE + "Container"); 141 public static final Resource BASIC_CONTAINER = 142 createResource(LDP_NAMESPACE + "BasicContainer"); 143 public static final Resource DIRECT_CONTAINER = 144 createResource(LDP_NAMESPACE + "DirectContainer"); 145 public static final Resource INDIRECT_CONTAINER = 146 createResource(LDP_NAMESPACE + "IndirectContainer"); 147 public static final Property MEMBERSHIP_RESOURCE = 148 createProperty(LDP_NAMESPACE + "membershipResource"); 149 public static final Property HAS_MEMBER_RELATION = 150 createProperty(LDP_NAMESPACE + "hasMemberRelation"); 151 public static final Property INSERTED_CONTENT_RELATION = 152 createProperty(LDP_NAMESPACE + "insertedContentRelation"); 153 public static final Property IS_MEMBER_OF_RELATION = 154 createProperty(LDP_NAMESPACE + "isMemberOfRelation"); 155 public static final Property CONTAINS = 156 createProperty(LDP_NAMESPACE + "contains"); 157 public static final Property LDP_MEMBER = 158 createProperty(LDP_NAMESPACE + "member"); 159 public static final Resource RESOURCE = 160 createResource(LDP_NAMESPACE + "Resource"); 161 public static final Resource RDF_SOURCE = 162 createResource(LDP_NAMESPACE + "RDFSource"); 163 public static final Resource NON_RDF_SOURCE = 164 createResource(LDP_NAMESPACE + "NonRDFSource"); 165 public static final Property CONSTRAINED_BY = 166 createProperty(LDP_NAMESPACE + "constrainedBy"); 167 public static final Property MEMBER_SUBJECT = 168 createProperty(LDP_NAMESPACE + "MemberSubject"); 169 170 private static final Set<Property> ldpManagedProperties = of(CONTAINS); 171 172 // REPOSITORY INFORMATION 173 public static final Property HAS_TRANSACTION_SERVICE = 174 createProperty(REPOSITORY_NAMESPACE + "hasTransactionProvider"); 175 public static final Resource REPOSITORY_ROOT = 176 createResource(REPOSITORY_NAMESPACE + "RepositoryRoot"); 177 178 // OTHER SERVICES 179 public static final Property HAS_FIXITY_SERVICE = 180 createProperty(REPOSITORY_NAMESPACE + "hasFixityService"); 181 182 public static final Property HAS_MIME_TYPE = 183 createProperty(EBUCORE_NAMESPACE + "hasMimeType"); 184 public static final Property HAS_ORIGINAL_NAME = 185 createProperty(EBUCORE_NAMESPACE + "filename"); 186 187 // EXTERNAL CONTENT 188 public static final Property EXTERNAL_CONTENT = createProperty(FCREPO_API_NAMESPACE + "ExternalContent"); 189 public static final Property PROXY_FOR = createProperty(REPOSITORY_NAMESPACE + "proxyFor"); 190 public static final Property REDIRECTS_TO = createProperty(REPOSITORY_NAMESPACE + "redirectsTo"); 191 192 // RDF EXTRACTION 193 public static final Property INBOUND_REFERENCES = createProperty(FCREPO_API_NAMESPACE + "PreferInboundReferences"); 194 public static final Property PREFER_SERVER_MANAGED = createProperty(REPOSITORY_NAMESPACE + "ServerManaged"); 195 public static final Property PREFER_MINIMAL_CONTAINER = createProperty(LDP_NAMESPACE + 196 "PreferMinimalContainer"); 197 public static final Property PREFER_CONTAINMENT = createProperty(LDP_NAMESPACE + "PreferContainment"); 198 public static final Property PREFER_MEMBERSHIP = createProperty(LDP_NAMESPACE + "PreferMembership"); 199 200 201 public static final Property EMBED_CONTAINED = createProperty(OA_NAMESPACE + "PreferContainedDescriptions"); 202 203 204 // WEBAC 205 public static final String WEBAC_ACCESS_CONTROL_VALUE = WEBAC_NAMESPACE_VALUE + "accessControl"; 206 207 public static final String SERVER_MANAGED_PROPERTIES_MODE = "fcrepo.properties.management"; 208 209 public static final String WEBAC_ACCESS_TO = WEBAC_NAMESPACE_VALUE + "accessTo"; 210 211 public static final String WEBAC_ACCESS_TO_CLASS = WEBAC_NAMESPACE_VALUE + "accessToClass"; 212 213 public static final Property WEBAC_ACCESS_TO_PROPERTY = createProperty(WEBAC_ACCESS_TO); 214 215 public static final String FEDORA_WEBAC_ACL_URI = REPOSITORY_WEBAC_NAMESPACE + "Acl"; 216 217 // Properties which are managed by the server but are not from managed namespaces 218 private static final Set<Property> serverManagedProperties; 219 static { 220 final ImmutableSet.Builder<Property> b = ImmutableSet.builder(); 221 b.addAll(fixityProperties).addAll(ldpManagedProperties); 222 serverManagedProperties = b.build(); 223 } 224 225 private static final Predicate<Property> hasFedoraNamespace = 226 p -> !p.isAnon() && p.getNameSpace().startsWith(REPOSITORY_NAMESPACE); 227 228 private static Predicate<Property> hasMementoNamespace = 229 p -> !p.isAnon() && p.getNameSpace().startsWith(MEMENTO_NAMESPACE); 230 231 // Server managed properties which may be overridden by clients when the server is in "relaxed" mode 232 private static final Set<Property> relaxableProperties = of(LAST_MODIFIED_BY, LAST_MODIFIED_DATE, CREATED_BY, 233 CREATED_DATE); 234 235 // Detects if a server managed property is allowed to be updated in "relaxed" mode 236 public static final Predicate<Property> isRelaxed = 237 p -> relaxableProperties.contains(p) 238 && ("relaxed".equals(System.getProperty(SERVER_MANAGED_PROPERTIES_MODE))); 239 240 /** 241 * Detects whether an RDF property is managed by the repository. 242 */ 243 public static final Predicate<Property> isManagedPredicate = 244 hasFedoraNamespace.or(hasMementoNamespace).or(p -> serverManagedProperties.contains(p)); 245 246 // VERSIONING 247 /** 248 * Memento TimeMap type. 249 */ 250 public static final String VERSIONING_TIMEMAP_TYPE = MEMENTO_NAMESPACE + "TimeMap"; 251 public static final Resource VERSIONING_TIMEMAP = createResource(VERSIONING_TIMEMAP_TYPE); 252 253 /** 254 * Memento TimeGate type. 255 */ 256 public static final String VERSIONING_TIMEGATE_TYPE = MEMENTO_NAMESPACE + "TimeGate"; 257 258 /** 259 * Type for memento objects. 260 */ 261 public static final String MEMENTO_TYPE = MEMENTO_NAMESPACE + "Memento"; 262 263 /** 264 * This is an internal RDF type for versionable resources, this may be replaced by a Memento type. 265 */ 266 public static final Resource VERSIONED_RESOURCE = 267 createResource(MEMENTO_NAMESPACE + "OriginalResource"); 268 269 public static final Property MEMENTO_ORIGINAL_RESOURCE = 270 createProperty(MEMENTO_NAMESPACE + "original"); 271 272 /* 273 * Interaction Models. 274 */ 275 public static final Set<Resource> INTERACTION_MODEL_RESOURCES = of( 276 BASIC_CONTAINER, INDIRECT_CONTAINER, DIRECT_CONTAINER, NON_RDF_SOURCE); 277 278 /** 279 * String set of valid interaction models with full LDP URI. 280 */ 281 public static final Set<String> INTERACTION_MODELS_FULL = INTERACTION_MODEL_RESOURCES.stream().map(Resource::getURI) 282 .collect(Collectors.toSet()); 283 284 /** 285 * This defines what we assume if you don't specify. 286 */ 287 public static final Resource DEFAULT_INTERACTION_MODEL = BASIC_CONTAINER; 288 289 private RdfLexicon() { 290 // This constructor left intentionally blank. 291 } 292}