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;
023
024import java.util.Set;
025import java.util.function.Predicate;
026import java.util.stream.Collectors;
027
028import org.apache.jena.rdf.model.Property;
029import org.apache.jena.rdf.model.Resource;
030
031import com.google.common.collect.ImmutableSet;
032
033/**
034 * A lexicon of the RDF properties that the fcrepo kernel (or close-to-core modules) use
035 *
036 * @author ajs6f
037 */
038public final class RdfLexicon {
039
040    /**
041     * Repository namespace "fedora"
042    **/
043    public static final String REPOSITORY_NAMESPACE = "http://fedora.info/definitions/v4/repository#";
044
045    public static final String FCREPO_API_NAMESPACE = "http://fedora.info/definitions/fcrepo#";
046
047    public static final String ACTIVITY_STREAMS_NAMESPACE = "https://www.w3.org/ns/activitystreams#";
048
049    public static final String EBUCORE_NAMESPACE = "http://www.ebu.ch/metadata/ontologies/ebucore/ebucore#";
050
051    public static final String OA_NAMESPACE = "http://www.w3.org/ns/oa#";
052
053    public static final String PROV_NAMESPACE = "http://www.w3.org/ns/prov#";
054
055    public static final String PREMIS_NAMESPACE = "http://www.loc.gov/premis/rdf/v1#";
056
057    public static final String MEMENTO_NAMESPACE = "http://mementoweb.org/ns#";
058
059    public static final String RDF_NAMESPACE = "http://www.w3.org/1999/02/22-rdf-syntax-ns#";
060
061    /**
062     * Namespace for the W3C WebAC vocabulary.
063     */
064    public static final String WEBAC_NAMESPACE_VALUE = "http://www.w3.org/ns/auth/acl#";
065
066    /**
067     * Fedora configuration namespace "fedora-config", used for user-settable
068     * configuration properties.
069     **/
070    // TODO from UCDetector: Constant "RdfLexicon.FEDORA_CONFIG_NAMESPACE" has 0 references
071    // should be referenced again when versioning is back in REST api
072    public static final String FEDORA_CONFIG_NAMESPACE = // NO_UCD (unused code)
073            "info:fedoraconfig/";
074
075    /**
076     * Linked Data Platform namespace.
077     */
078    public static final String LDP_NAMESPACE = "http://www.w3.org/ns/ldp#";
079
080    /**
081     * Is this namespace one that the repository manages?
082     */
083    public static final Predicate<String> isManagedNamespace = p -> p.equals(REPOSITORY_NAMESPACE) ||
084            p.equals(LDP_NAMESPACE) || p.equals(MEMENTO_NAMESPACE);
085
086    // FIXITY
087
088    public static final Resource FIXITY_TYPE = createResource(PREMIS_NAMESPACE + "Fixity");
089
090    public static final Property HAS_MESSAGE_DIGEST_ALGORITHM =
091            createProperty(PREMIS_NAMESPACE + "hasMessageDigestAlgorithm");
092
093    public static final Property HAS_MESSAGE_DIGEST =
094            createProperty(PREMIS_NAMESPACE + "hasMessageDigest");
095
096    public static final Property HAS_SIZE =
097        createProperty(PREMIS_NAMESPACE + "hasSize");
098    public static final Property HAS_FIXITY_RESULT =
099        createProperty(PREMIS_NAMESPACE + "hasFixity");
100
101    private static final Set<Property> fixityProperties = of(
102            HAS_FIXITY_RESULT, HAS_MESSAGE_DIGEST);
103
104    public static final Resource EVENT_OUTCOME_INFORMATION = createResource(PREMIS_NAMESPACE + "EventOutcomeDetail");
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    // Server managed properties
113    public static final Property CREATED_DATE =
114            createProperty(REPOSITORY_NAMESPACE + "created");
115    public static final Property CREATED_BY =
116            createProperty(REPOSITORY_NAMESPACE + "createdBy");
117    public static final Property LAST_MODIFIED_DATE =
118            createProperty(REPOSITORY_NAMESPACE + "lastModified");
119    public static final Property LAST_MODIFIED_BY =
120            createProperty(REPOSITORY_NAMESPACE + "lastModifiedBy");
121
122    public static final Resource FEDORA_CONTAINER =
123            createResource(REPOSITORY_NAMESPACE + "Container");
124    public static final Resource FEDORA_BINARY =
125            createResource(REPOSITORY_NAMESPACE + "Binary");
126    public static final Resource FEDORA_RESOURCE =
127            createResource(REPOSITORY_NAMESPACE + "Resource");
128
129    // Linked Data Platform
130    public static final Property PAGE =
131        createProperty(LDP_NAMESPACE + "Page");
132    public static final Resource CONTAINER =
133            createResource(LDP_NAMESPACE + "Container");
134    public static final Resource BASIC_CONTAINER =
135            createResource(LDP_NAMESPACE + "BasicContainer");
136    public static final Resource DIRECT_CONTAINER =
137            createResource(LDP_NAMESPACE + "DirectContainer");
138    public static final Resource INDIRECT_CONTAINER =
139            createResource(LDP_NAMESPACE + "IndirectContainer");
140    public static final Property MEMBERSHIP_RESOURCE =
141            createProperty(LDP_NAMESPACE + "membershipResource");
142    public static final Property HAS_MEMBER_RELATION =
143            createProperty(LDP_NAMESPACE + "hasMemberRelation");
144    public static final Property CONTAINS =
145        createProperty(LDP_NAMESPACE + "contains");
146    public static final Property LDP_MEMBER =
147            createProperty(LDP_NAMESPACE + "member");
148    public static final Resource RESOURCE =
149            createResource(LDP_NAMESPACE + "Resource");
150    public static final Resource RDF_SOURCE =
151            createResource(LDP_NAMESPACE + "RDFSource");
152    public static final Resource NON_RDF_SOURCE =
153        createResource(LDP_NAMESPACE + "NonRDFSource");
154    public static final Property CONSTRAINED_BY =
155            createProperty(LDP_NAMESPACE + "constrainedBy");
156    public static final Property MEMBER_SUBJECT =
157            createProperty(LDP_NAMESPACE + "MemberSubject");
158
159    private static final Set<Property> ldpManagedProperties = of(CONTAINS);
160
161    // REPOSITORY INFORMATION
162    public static final Property HAS_TRANSACTION_SERVICE =
163            createProperty(REPOSITORY_NAMESPACE + "hasTransactionProvider");
164
165    // OTHER SERVICES
166    public static final Property HAS_FIXITY_SERVICE =
167            createProperty(REPOSITORY_NAMESPACE + "hasFixityService");
168
169    // BINARY DESCRIPTIONS
170    public static final Property DESCRIBES =
171            createProperty("http://www.iana.org/assignments/relation/describes");
172    public static final Property DESCRIBED_BY =
173            createProperty("http://www.iana.org/assignments/relation/describedby");
174
175    public static final Resource INACCESSIBLE_RESOURCE =
176            createResource(REPOSITORY_NAMESPACE + "inaccessibleResource");
177    public static final Property HAS_MIME_TYPE =
178            createProperty(EBUCORE_NAMESPACE + "hasMimeType");
179    public static final Property HAS_ORIGINAL_NAME =
180            createProperty(EBUCORE_NAMESPACE + "filename");
181
182    // EXTERNAL CONTENT
183    public static final Property EXTERNAL_CONTENT = createProperty(FCREPO_API_NAMESPACE + "ExternalContent");
184    public static final Property PROXY_FOR = createProperty(REPOSITORY_NAMESPACE + "proxyFor");
185    public static final Property REDIRECTS_TO = createProperty(REPOSITORY_NAMESPACE + "redirectsTo");
186
187    // RDF EXTRACTION
188    public static final Property INBOUND_REFERENCES = createProperty(FCREPO_API_NAMESPACE + "PreferInboundReferences");
189    public static final Property PREFER_SERVER_MANAGED = createProperty(REPOSITORY_NAMESPACE + "ServerManaged");
190
191    public static final Property EMBED_CONTAINED = createProperty(OA_NAMESPACE + "PreferContainedDescriptions");
192
193
194    // WEBAC
195    public static final String WEBAC_ACCESS_CONTROL_VALUE = WEBAC_NAMESPACE_VALUE + "accessControl";
196
197    public static final String SERVER_MANAGED_PROPERTIES_MODE = "fcrepo.properties.management";
198
199    // Properties which are managed by the server but are not from managed namespaces
200    private static final Set<Property> serverManagedProperties;
201    static {
202        final ImmutableSet.Builder<Property> b = ImmutableSet.builder();
203        b.addAll(fixityProperties).addAll(ldpManagedProperties);
204        serverManagedProperties = b.build();
205    }
206
207    private static final Predicate<Property> hasFedoraNamespace =
208        p -> !p.isAnon() && p.getNameSpace().startsWith(REPOSITORY_NAMESPACE);
209
210    private static Predicate<Property> hasMementoNamespace =
211        p -> !p.isAnon() && p.getNameSpace().startsWith(MEMENTO_NAMESPACE);
212
213    // Server managed properties which may be overridden by clients when the server is in "relaxed" mode
214    private static final Set<Property> relaxableProperties = of(LAST_MODIFIED_BY, LAST_MODIFIED_DATE, CREATED_BY,
215            CREATED_DATE);
216
217    // Detects if a server managed property is allowed to be updated in "relaxed" mode
218    public static final Predicate<Property> isRelaxed =
219            p -> relaxableProperties.contains(p)
220                    && ("relaxed".equals(System.getProperty(SERVER_MANAGED_PROPERTIES_MODE)));
221
222    /**
223     * Detects whether an RDF property is managed by the repository.
224     */
225    public static final Predicate<Property> isManagedPredicate =
226            hasFedoraNamespace.or(hasMementoNamespace).or(p -> serverManagedProperties.contains(p));
227
228    /**
229     * Fedora defined JCR node type with supertype of nt:file with two nt:folder named fedora:timemap and
230     * fedora:binaryTimemap inside.
231     */
232    public static final String NT_VERSION_FILE = "nt:versionFile";
233
234    /**
235     * Fedora defined JCR node type which can have no children except optionally a timemap
236     */
237    public static final String NT_LEAF_NODE = "nt:leafNode";
238
239    /**
240     * Fedora defined node path for a binary description.
241     */
242    public static final String FEDORA_DESCRIPTION = "fedora:description";
243
244    // VERSIONING
245    /**
246     * Memento TimeMap type.
247     */
248    public static final String VERSIONING_TIMEMAP_TYPE = MEMENTO_NAMESPACE + "TimeMap";
249
250    /**
251     * Memento TimeGate type.
252     */
253    public static final String VERSIONING_TIMEGATE_TYPE = MEMENTO_NAMESPACE + "TimeGate";
254
255    /**
256     * Type for memento objects.
257     */
258    public static final String MEMENTO_TYPE = MEMENTO_NAMESPACE + "Memento";
259
260    /**
261     * This is an internal RDF type for versionable resources, this may be replaced by a Memento type.
262     */
263    public static final Resource VERSIONED_RESOURCE =
264        createResource(MEMENTO_NAMESPACE + "OriginalResource");
265
266    /*
267     * Interaction Models.
268     */
269    public static final Set<Resource> INTERACTION_MODEL_RESOURCES = of(
270            BASIC_CONTAINER, INDIRECT_CONTAINER, DIRECT_CONTAINER, NON_RDF_SOURCE);
271
272    public static final Set<String> INTERACTION_MODELS = INTERACTION_MODEL_RESOURCES.stream()
273            .map(m -> m.getURI().replace(LDP_NAMESPACE, "ldp:"))
274            .collect(Collectors.toSet());
275
276    private RdfLexicon() {
277
278    }
279}