|
| 1 | +package org.fcrepo.lambdora.common.rdf; |
| 2 | +/* |
| 3 | + * Licensed to DuraSpace under one or more contributor license agreements. |
| 4 | + * See the NOTICE file distributed with this work for additional information |
| 5 | + * regarding copyright ownership. |
| 6 | + * |
| 7 | + * DuraSpace licenses this file to you under the Apache License, |
| 8 | + * Version 2.0 (the "License"); you may not use this file except in |
| 9 | + * compliance with the License. You may obtain a copy of the License at |
| 10 | + * |
| 11 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | + * |
| 13 | + * Unless required by applicable law or agreed to in writing, software |
| 14 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 15 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 16 | + * See the License for the specific language governing permissions and |
| 17 | + * limitations under the License. |
| 18 | + */ |
| 19 | + |
| 20 | +import com.google.common.collect.ImmutableSet; |
| 21 | +import org.apache.jena.rdf.model.Property; |
| 22 | +import org.apache.jena.rdf.model.Resource; |
| 23 | + |
| 24 | +import java.util.Set; |
| 25 | +import java.util.function.Predicate; |
| 26 | + |
| 27 | +import static org.apache.jena.rdf.model.ResourceFactory.createProperty; |
| 28 | +import static org.apache.jena.rdf.model.ResourceFactory.createResource; |
| 29 | + |
| 30 | +import static com.google.common.collect.ImmutableSet.of; |
| 31 | + |
| 32 | +/** |
| 33 | + * A lexicon of the RDF properties that the fcrepo kernel (or close-to-core modules) use |
| 34 | + * |
| 35 | + * @author ajs6f |
| 36 | + */ |
| 37 | +public final class RdfLexicon { |
| 38 | + |
| 39 | + /** |
| 40 | + * Repository namespace "fedora" |
| 41 | + **/ |
| 42 | + public static final String REPOSITORY_NAMESPACE = "http://fedora.info/definitions/v4/repository#"; |
| 43 | + |
| 44 | + public static final String EVENT_NAMESPACE = "http://fedora.info/definitions/v4/event#"; |
| 45 | + |
| 46 | + public static final String EBUCORE_NAMESPACE = "http://www.ebu.ch/metadata/ontologies/ebucore/ebucore#"; |
| 47 | + |
| 48 | + public static final String PROV_NAMESPACE = "http://www.w3.org/ns/prov#"; |
| 49 | + |
| 50 | + public static final String PREMIS_NAMESPACE = "http://www.loc.gov/premis/rdf/v1#"; |
| 51 | + |
| 52 | + /** |
| 53 | + * Fedora configuration namespace "fedora-config", used for user-settable |
| 54 | + * configuration properties. |
| 55 | + **/ |
| 56 | + // TODO from UCDetector: Constant "RdfLexicon.FEDORA_CONFIG_NAMESPACE" has 0 references |
| 57 | + // should be referenced again when versioning is back in REST api |
| 58 | + public static final String FEDORA_CONFIG_NAMESPACE = // NO_UCD (unused code) |
| 59 | + "info:fedoraconfig/"; |
| 60 | + |
| 61 | + /** |
| 62 | + * Linked Data Platform namespace. |
| 63 | + */ |
| 64 | + public static final String LDP_NAMESPACE = "http://www.w3.org/ns/ldp#"; |
| 65 | + |
| 66 | + /** |
| 67 | + * RDF Syntax namespace. |
| 68 | + */ |
| 69 | + public static final String RDF_SYNTAX_NAMESPACE = "http://www.w3.org/1999/02/22-rdf-syntax-ns#"; |
| 70 | + |
| 71 | + /** |
| 72 | + * SPARQL service description namespace. |
| 73 | + */ |
| 74 | + public static final String SPARQL_SD_NAMESPACE = |
| 75 | + "http://www.w3.org/ns/sparql-service-description#"; |
| 76 | + |
| 77 | + |
| 78 | + //RDF Syntax |
| 79 | + public static final Property TYPE = |
| 80 | + createProperty(RDF_SYNTAX_NAMESPACE + "type"); |
| 81 | + |
| 82 | + /** |
| 83 | + * Is this namespace one that the repository manages? |
| 84 | + */ |
| 85 | + public static final Predicate<String> isManagedNamespace = p -> p.equals(REPOSITORY_NAMESPACE); |
| 86 | + |
| 87 | + // MEMBERSHIP |
| 88 | + public static final Property HAS_PARENT = |
| 89 | + createProperty(REPOSITORY_NAMESPACE + "hasParent"); |
| 90 | + public static final Property HAS_CHILD = |
| 91 | + createProperty(REPOSITORY_NAMESPACE + "hasChild"); |
| 92 | + |
| 93 | + public static final Set<Property> membershipProperties = of(HAS_PARENT, HAS_CHILD); |
| 94 | + |
| 95 | + // FIXITY |
| 96 | + |
| 97 | + public static final Resource FIXITY_TYPE = createResource(PREMIS_NAMESPACE + "Fixity"); |
| 98 | + |
| 99 | + public static final Property HAS_MESSAGE_DIGEST_ALGORITHM = |
| 100 | + createProperty(PREMIS_NAMESPACE + "hasMessageDigestAlgorithm"); |
| 101 | + |
| 102 | + public static final Property HAS_MESSAGE_DIGEST = |
| 103 | + createProperty(PREMIS_NAMESPACE + "hasMessageDigest"); |
| 104 | + |
| 105 | + public static final Property HAS_SIZE = |
| 106 | + createProperty(PREMIS_NAMESPACE + "hasSize"); |
| 107 | + public static final Property HAS_FIXITY_RESULT = |
| 108 | + createProperty(PREMIS_NAMESPACE + "hasFixity"); |
| 109 | + |
| 110 | + public static final Property HAS_FIXITY_CHECK_COUNT = |
| 111 | + createProperty(REPOSITORY_NAMESPACE + "numFixityChecks"); |
| 112 | + public static final Property HAS_FIXITY_ERROR_COUNT = |
| 113 | + createProperty(REPOSITORY_NAMESPACE + "numFixityErrors"); |
| 114 | + public static final Property HAS_FIXITY_REPAIRED_COUNT = |
| 115 | + createProperty(REPOSITORY_NAMESPACE + "numFixityRepaired"); |
| 116 | + |
| 117 | + public static final Set<Property> fixityProperties = of( |
| 118 | + HAS_FIXITY_RESULT, HAS_MESSAGE_DIGEST, HAS_SIZE, |
| 119 | + HAS_FIXITY_CHECK_COUNT, HAS_FIXITY_ERROR_COUNT, HAS_FIXITY_REPAIRED_COUNT); |
| 120 | + |
| 121 | + public static final Resource EVENT_OUTCOME_INFORMATION = createResource(PREMIS_NAMESPACE + "EventOutcomeDetail"); |
| 122 | + |
| 123 | + public static final Property HAS_FIXITY_STATE = |
| 124 | + createProperty(PREMIS_NAMESPACE + "hasEventOutcome"); |
| 125 | + |
| 126 | + public static final Property WRITABLE = |
| 127 | + createProperty(REPOSITORY_NAMESPACE + "writable"); |
| 128 | + |
| 129 | + // Server managed properties |
| 130 | + public static final Property CREATED_DATE = |
| 131 | + createProperty(REPOSITORY_NAMESPACE + "created"); |
| 132 | + public static final Property CREATED_BY = |
| 133 | + createProperty(REPOSITORY_NAMESPACE + "createdBy"); |
| 134 | + public static final Property LAST_MODIFIED_DATE = |
| 135 | + createProperty(REPOSITORY_NAMESPACE + "lastModified"); |
| 136 | + public static final Property LAST_MODIFIED_BY = |
| 137 | + createProperty(REPOSITORY_NAMESPACE + "lastModifiedBy"); |
| 138 | + public static final Set<Property> serverManagedProperties = of( |
| 139 | + CREATED_DATE, CREATED_BY, LAST_MODIFIED_DATE, LAST_MODIFIED_BY); |
| 140 | + |
| 141 | + // Fedora Namespace properties |
| 142 | + public static final Property FEDORA_CONTAINER = |
| 143 | + createProperty(REPOSITORY_NAMESPACE + "Container"); |
| 144 | + public static final Property FEDORA_RESOURCE = |
| 145 | + createProperty(REPOSITORY_NAMESPACE + "Resource"); |
| 146 | + |
| 147 | + |
| 148 | + |
| 149 | + // Linked Data Platform |
| 150 | + public static final Property PAGE = |
| 151 | + createProperty(LDP_NAMESPACE + "Page"); |
| 152 | + public static final Resource CONTAINER = |
| 153 | + createResource(LDP_NAMESPACE + "Container"); |
| 154 | + public static final Resource BASIC_CONTAINER = |
| 155 | + createResource(LDP_NAMESPACE + "BasicContainer"); |
| 156 | + public static final Resource DIRECT_CONTAINER = |
| 157 | + createResource(LDP_NAMESPACE + "DirectContainer"); |
| 158 | + public static final Resource INDIRECT_CONTAINER = |
| 159 | + createResource(LDP_NAMESPACE + "IndirectContainer"); |
| 160 | + public static final Property MEMBERSHIP_RESOURCE = |
| 161 | + createProperty(LDP_NAMESPACE + "membershipResource"); |
| 162 | + public static final Property HAS_MEMBER_RELATION = |
| 163 | + createProperty(LDP_NAMESPACE + "hasMemberRelation"); |
| 164 | + public static final Property CONTAINS = |
| 165 | + createProperty(LDP_NAMESPACE + "contains"); |
| 166 | + public static final Property LDP_MEMBER = |
| 167 | + createProperty(LDP_NAMESPACE + "member"); |
| 168 | + public static final Property RDF_SOURCE = |
| 169 | + createProperty(LDP_NAMESPACE + "RDFSource"); |
| 170 | + public static final Property NON_RDF_SOURCE = |
| 171 | + createProperty(LDP_NAMESPACE + "NonRDFSource"); |
| 172 | + public static final Property CONSTRAINED_BY = |
| 173 | + createProperty(LDP_NAMESPACE + "constrainedBy"); |
| 174 | + public static final Property MEMBER_SUBJECT = |
| 175 | + createProperty(LDP_NAMESPACE + "MemberSubject"); |
| 176 | + |
| 177 | + /** |
| 178 | + * Prefix for internal repository resources |
| 179 | + */ |
| 180 | + public static final String INTERNAL_URI_PREFIX = "fedora://info"; |
| 181 | + |
| 182 | + private static final Set<Property> ldpManagedProperties = of(CONTAINS); |
| 183 | + |
| 184 | + // REPOSITORY INFORMATION |
| 185 | + public static final Property HAS_OBJECT_COUNT = |
| 186 | + createProperty(REPOSITORY_NAMESPACE + "objectCount"); |
| 187 | + public static final Property HAS_OBJECT_SIZE = |
| 188 | + createProperty(REPOSITORY_NAMESPACE + "objectSize"); |
| 189 | + public static final Property HAS_TRANSACTION_SERVICE = |
| 190 | + createProperty(REPOSITORY_NAMESPACE + "hasTransactionProvider"); |
| 191 | + public static final Property HAS_ACCESS_ROLES_SERVICE = |
| 192 | + createProperty(REPOSITORY_NAMESPACE + "hasAccessRoles"); |
| 193 | + |
| 194 | + public static final Set<Property> repositoryProperties = of( |
| 195 | + HAS_OBJECT_COUNT, HAS_OBJECT_SIZE, HAS_TRANSACTION_SERVICE); |
| 196 | + |
| 197 | + // NAMESPACES |
| 198 | + public static final Property HAS_NAMESPACE_PREFIX = |
| 199 | + createProperty("http://purl.org/vocab/vann/preferredNamespacePrefix"); |
| 200 | + public static final Property HAS_NAMESPACE_URI = |
| 201 | + createProperty("http://purl.org/vocab/vann/preferredNamespaceUri"); |
| 202 | + |
| 203 | + public static final Set<Property> namespaceProperties = of( |
| 204 | + HAS_NAMESPACE_PREFIX, HAS_NAMESPACE_URI); |
| 205 | + |
| 206 | + // OTHER SERVICES |
| 207 | + public static final Property HAS_VERSION_HISTORY = |
| 208 | + createProperty(REPOSITORY_NAMESPACE + "hasVersions"); |
| 209 | + public static final Property HAS_FIXITY_SERVICE = |
| 210 | + createProperty(REPOSITORY_NAMESPACE + "hasFixityService"); |
| 211 | + public static final Property HAS_SPARQL_ENDPOINT = |
| 212 | + createProperty(SPARQL_SD_NAMESPACE + "endpoint"); |
| 213 | + |
| 214 | + public static final Set<Property> otherServiceProperties = of( |
| 215 | + HAS_VERSION_HISTORY, HAS_FIXITY_SERVICE); |
| 216 | + |
| 217 | + |
| 218 | + // BINARY DESCRIPTIONS |
| 219 | + public static final Property DESCRIBES = |
| 220 | + createProperty("http://www.iana.org/assignments/relation/describes"); |
| 221 | + public static final Property DESCRIBED_BY = |
| 222 | + createProperty("http://www.iana.org/assignments/relation/describedby"); |
| 223 | + |
| 224 | + public static final Set<Property> structProperties = of(DESCRIBES, DESCRIBED_BY); |
| 225 | + |
| 226 | + // CONTENT |
| 227 | + public static final Resource CONTENT_LOCATION_TYPE = |
| 228 | + createResource(PREMIS_NAMESPACE + "ContentLocation"); |
| 229 | + public static final Resource INACCESSIBLE_RESOURCE = |
| 230 | + createResource(REPOSITORY_NAMESPACE + "inaccessibleResource"); |
| 231 | + public static final Property HAS_CONTENT_LOCATION = |
| 232 | + createProperty(PREMIS_NAMESPACE + "hasContentLocation"); |
| 233 | + public static final Property HAS_CONTENT_LOCATION_VALUE = |
| 234 | + createProperty(PREMIS_NAMESPACE + "hasContentLocationValue"); |
| 235 | + public static final Property HAS_MIME_TYPE = |
| 236 | + createProperty(EBUCORE_NAMESPACE + "hasMimeType"); |
| 237 | + public static final Property HAS_ORIGINAL_NAME = |
| 238 | + createProperty(EBUCORE_NAMESPACE + "filename"); |
| 239 | + |
| 240 | + public static final Set<Property> contentProperties = of(HAS_CONTENT_LOCATION, HAS_CONTENT_LOCATION_VALUE, |
| 241 | + HAS_SIZE); |
| 242 | + |
| 243 | + |
| 244 | + // VERSIONING |
| 245 | + public static final Property HAS_VERSION = |
| 246 | + createProperty(REPOSITORY_NAMESPACE + "hasVersion"); |
| 247 | + public static final Property HAS_VERSION_LABEL = |
| 248 | + createProperty(REPOSITORY_NAMESPACE + "hasVersionLabel"); |
| 249 | + |
| 250 | + public static final Set<Property> versioningProperties = of(HAS_VERSION, |
| 251 | + HAS_VERSION_LABEL); |
| 252 | + |
| 253 | + // RDF EXTRACTION |
| 254 | + public static final Property COULD_NOT_STORE_PROPERTY = |
| 255 | + createProperty(REPOSITORY_NAMESPACE + "couldNotStoreProperty"); |
| 256 | + public static final Property INBOUND_REFERENCES = createProperty(REPOSITORY_NAMESPACE + "InboundReferences"); |
| 257 | + public static final Property EMBED_CONTAINS = createProperty(REPOSITORY_NAMESPACE + "EmbedResources"); |
| 258 | + public static final Property SERVER_MANAGED = createProperty(REPOSITORY_NAMESPACE + "ServerManaged"); |
| 259 | + |
| 260 | + public static final Set<Property> managedProperties; |
| 261 | + |
| 262 | + static { |
| 263 | + final ImmutableSet.Builder<Property> b = ImmutableSet.builder(); |
| 264 | + b.addAll(membershipProperties).addAll(fixityProperties).addAll(ldpManagedProperties).addAll( |
| 265 | + repositoryProperties).addAll(namespaceProperties).addAll( |
| 266 | + otherServiceProperties).addAll(structProperties).addAll(contentProperties).addAll( |
| 267 | + versioningProperties).addAll(serverManagedProperties); |
| 268 | + managedProperties = b.build(); |
| 269 | + } |
| 270 | + |
| 271 | + public static final Set<Property> relaxableProperties |
| 272 | + = of(LAST_MODIFIED_BY, LAST_MODIFIED_DATE, CREATED_BY, CREATED_DATE); |
| 273 | + |
| 274 | + public static final String SERVER_MANAGED_PROPERTIES_MODE = "fcrepo.properties.management"; |
| 275 | + |
| 276 | + private static Predicate<Property> hasFedoraNamespace = |
| 277 | + p -> !p.isAnon() && p.getNameSpace().startsWith(REPOSITORY_NAMESPACE); |
| 278 | + |
| 279 | + public static final Predicate<Property> isRelaxed = |
| 280 | + p -> relaxableProperties.contains(p) |
| 281 | + && ("relaxed".equals(System.getProperty(SERVER_MANAGED_PROPERTIES_MODE))); |
| 282 | + |
| 283 | + /** |
| 284 | + * Detects whether an RDF property is managed by the repository. |
| 285 | + */ |
| 286 | + public static final Predicate<Property> isManagedPredicate = |
| 287 | + hasFedoraNamespace.or(p -> managedProperties.contains(p)); |
| 288 | + |
| 289 | + private RdfLexicon() { |
| 290 | + |
| 291 | + } |
| 292 | +} |
| 293 | + |
0 commit comments