Skip to content

Commit 9f0ad09

Browse files
dbernsteinAndrew Woods
authored andcommitted
Refactor constants (#57)
* Refactors commonly used strings into RdfLexicon constants class.
1 parent ad90a30 commit 9f0ad09

File tree

11 files changed

+377
-46
lines changed

11 files changed

+377
-46
lines changed

build.gradle

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ ext {
1414
jenaVersion = '3.4.0'
1515
daggerVersion = '2.12'
1616
awsSdkVersion = '1.11.218'
17+
guavaVersion = '20.0'
1718
}
1819

1920
allprojects {
@@ -72,6 +73,7 @@ subprojects {
7273

7374
//ensures that idea sees the generated source files in the src classpath
7475
def generated = new File(buildDir, "generated/source/apt/main")
76+
7577
idea.module.sourceDirs += generated
7678

7779
}
@@ -87,7 +89,7 @@ project(':lambdora-http-api') {
8789
'com.fasterxml.jackson.core:jackson-core:2.9.2',
8890
'com.fasterxml.jackson.core:jackson-databind:2.9.2',
8991
'com.fasterxml.jackson.core:jackson-annotations:2.9.2',
90-
'com.google.guava:guava:20.0',
92+
"com.google.guava:guava:${guavaVersion}",
9193
'org.apache.httpcomponents:httpcore:4.4.8',
9294
'org.apache.httpcomponents:httpmime:4.5.3',
9395
'org.glassfish.jersey.media:jersey-media-multipart:2.24',
@@ -141,6 +143,17 @@ project(':lambdora-common-test') {
141143
}
142144
}
143145

146+
project(':lambdora-common') {
147+
dependencies {
148+
compile("org.apache.jena:jena-core:${jenaVersion}",
149+
"org.apache.jena:jena-iri:${jenaVersion}",
150+
"org.apache.jena:jena-arq:${jenaVersion}",
151+
"com.google.guava:guava:${guavaVersion}"
152+
153+
)
154+
}
155+
}
156+
144157
task wrapper(type: Wrapper) {
145158
gradleVersion = '4.2.1'
146159
}
Lines changed: 293 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,293 @@
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+

lambdora-common/src/main/java/org/fcrepo/lambdora/common/utils/UriUtils.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,20 @@
22

33
import java.net.URI;
44

5+
import static org.fcrepo.lambdora.common.rdf.RdfLexicon.INTERNAL_URI_PREFIX;
6+
57
/**
68
* UriUtils
79
*
810
* @author dbernstein
911
*/
1012
public class UriUtils {
1113

12-
/**
13-
* Prefix for internal repository resources
14-
*/
15-
public static final String INTERNAL_URI_PREFIX = "fedora://info";
16-
1714
private UriUtils() {
1815
}
1916

17+
private static final URI ROOT = URI.create(INTERNAL_URI_PREFIX + "/");
18+
2019
/**
2120
* Returns the parent URI or null if the specified uri is the root uri
2221
*
@@ -27,13 +26,16 @@ public static URI getParent(final URI uri) {
2726
if (isRoot(uri)) {
2827
return null;
2928
} else {
29+
//get the parent path (with a slash on the end)
3030
final URI parent = uri.getPath().endsWith("/") ? uri.resolve("..") : uri.resolve(".");
3131
final String parentStr = parent.toString();
32+
//if the resolved parent is root, return it is as, otherwise remove the slash and
33+
//return it.
3234
return isRoot(parent) ? parent : URI.create(parentStr.substring(0, parentStr.length() - 1));
3335
}
3436
}
3537

3638
private static boolean isRoot(final URI uri) {
37-
return uri.getPath().equals("/");
39+
return ROOT.equals(uri);
3840
}
3941
}

lambdora-common/src/test/java/org/fcrepo/lambdora/common/utils/UriUtilsTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
import static junit.framework.TestCase.assertEquals;
88
import static junit.framework.TestCase.assertNull;
9-
import static org.fcrepo.lambdora.common.utils.UriUtils.INTERNAL_URI_PREFIX;
9+
import static org.fcrepo.lambdora.common.rdf.RdfLexicon.INTERNAL_URI_PREFIX;
1010

1111
/**
1212
* UriUtils

lambdora-http-api/src/main/java/org/fcrepo/lambdora/ldp/LambdoraLdp.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
import static org.fcrepo.http.commons.domain.RDFMediaType.TEXT_PLAIN_WITH_CHARSET;
6464
import static org.fcrepo.http.commons.domain.RDFMediaType.TURTLE_WITH_CHARSET;
6565
import static org.fcrepo.http.commons.domain.RDFMediaType.TURTLE_X;
66-
import static org.fcrepo.lambdora.common.utils.UriUtils.INTERNAL_URI_PREFIX;
66+
import static org.fcrepo.lambdora.common.rdf.RdfLexicon.INTERNAL_URI_PREFIX;
6767
import static org.slf4j.LoggerFactory.getLogger;
6868

6969
/**

0 commit comments

Comments
 (0)