Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into aw-45458545
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Woods committed May 10, 2013
2 parents 0283592 + cca4518 commit ebfd83d
Show file tree
Hide file tree
Showing 9 changed files with 98 additions and 63 deletions.
Expand Up @@ -99,7 +99,7 @@ public void testGetObjectGraph() throws Exception {
assertEquals(200, response.getStatusLine().getStatusCode());
final String content = EntityUtils.toString(response.getEntity());

assertTrue("Didn't find an expected ntriple", compile("<info:fedora/objects/FedoraDescribeTestGraph> <http://www.jcp.org/jcr/1.0mixinTypes> \"fedora:object\" \\.",
assertTrue("Didn't find an expected ntriple", compile("<info:fedora/objects/FedoraDescribeTestGraph> <info:fedora/fedora-system:def/internal#mixinTypes> \"fedora:object\" \\.",
DOTALL).matcher(content).find());

logger.debug("Retrieved object graph:\n" + content);
Expand Down Expand Up @@ -128,7 +128,7 @@ public void testUpdateObjectGraphWithProblems() throws Exception {
new HttpPost(serverAddress + "objects/FedoraDescribeTestGraphUpdateBad");
getObjMethod.addHeader("Content-Type", "application/sparql-update");
BasicHttpEntity e = new BasicHttpEntity();
e.setContent(new ByteArrayInputStream("INSERT { <info:fedora/objects/FedoraDescribeTestGraphUpdateBad> <http://www.jcp.org/jcr/1.0uuid> \"00e686e2-24d4-40c2-92ce-577c0165b158\" } WHERE {}\n".getBytes()));
e.setContent(new ByteArrayInputStream("INSERT { <info:fedora/objects/FedoraDescribeTestGraphUpdateBad> <info:fedora/fedora-system:def/internal#uuid> \"00e686e2-24d4-40c2-92ce-577c0165b158\" } WHERE {}\n".getBytes()));
getObjMethod.setEntity(e);
final HttpResponse response = client.execute(getObjMethod);
assertEquals(403, response.getStatusLine().getStatusCode());
Expand Down
12 changes: 9 additions & 3 deletions fcrepo-kernel/src/main/java/org/fcrepo/FedoraResource.java
Expand Up @@ -28,6 +28,7 @@
import java.util.Date;

import static org.fcrepo.services.ServiceHelpers.getObjectSize;
import static org.fcrepo.utils.FedoraTypesUtils.getRDFNamespaceForJcrNamespace;
import static org.fcrepo.utils.FedoraTypesUtils.map;
import static org.fcrepo.utils.FedoraTypesUtils.nodetype2name;
import static org.slf4j.LoggerFactory.getLogger;
Expand Down Expand Up @@ -165,7 +166,12 @@ public Model getPropertiesModel() throws RepositoryException {
final String nsURI = namespaceRegistry.getURI(prefix);
if (nsURI != null && !nsURI.equals("") &&
!prefix.equals("xmlns")) {
model.setNsPrefix(prefix, nsURI);

if (prefix.equals("jcr")) {
model.setNsPrefix("fedora-internal", getRDFNamespaceForJcrNamespace(nsURI));
} else {
model.setNsPrefix(prefix, getRDFNamespaceForJcrNamespace(nsURI));
}
}
}

Expand All @@ -179,12 +185,12 @@ public Model getPropertiesModel() throws RepositoryException {
final Value[] values = property.getValues();

for(Value v : values) {
model.add(subject, ResourceFactory.createProperty(nsProperty.getNamespaceURI(), nsProperty.getLocalName()), v.getString());
model.add(subject, ResourceFactory.createProperty(getRDFNamespaceForJcrNamespace(nsProperty.getNamespaceURI()), nsProperty.getLocalName()), v.getString());
}

} else {
final Value value = property.getValue();
model.add(subject, ResourceFactory.createProperty(nsProperty.getNamespaceURI(), nsProperty.getLocalName()), value.getString());
model.add(subject, ResourceFactory.createProperty(getRDFNamespaceForJcrNamespace(nsProperty.getNamespaceURI()), nsProperty.getLocalName()), value.getString());
}

}
Expand Down
24 changes: 24 additions & 0 deletions fcrepo-kernel/src/main/java/org/fcrepo/utils/FedoraTypesUtils.java
Expand Up @@ -20,6 +20,8 @@

import com.google.common.base.Function;
import com.google.common.base.Predicate;
import com.google.common.collect.BiMap;
import com.google.common.collect.ImmutableBiMap;
import org.modeshape.jcr.JcrValueFactory;
import org.modeshape.jcr.value.binary.StrategyHint;

Expand All @@ -31,6 +33,28 @@
*/
public abstract class FedoraTypesUtils {

public static BiMap<String, String> jcrNamespacesToRDFNamespaces = ImmutableBiMap.of(
"http://www.jcp.org/jcr/1.0", "info:fedora/fedora-system:def/internal#"
);

public static BiMap<String, String> rdfNamespacesToJcrNamespaces = jcrNamespacesToRDFNamespaces.inverse();

public static String getJcrNamespaceForRDFNamespace(final String rdfNamespaceUri) {
if (rdfNamespacesToJcrNamespaces.containsKey(rdfNamespaceUri)) {
return rdfNamespacesToJcrNamespaces.get(rdfNamespaceUri);
} else {
return rdfNamespaceUri;
}
}

public static String getRDFNamespaceForJcrNamespace(final String jcrNamespaceUri) {
if (jcrNamespacesToRDFNamespaces.containsKey(jcrNamespaceUri)) {
return jcrNamespacesToRDFNamespaces.get(jcrNamespaceUri);
} else {
return jcrNamespaceUri;
}
}

/**
* Predicate for determining whether this {@link Node} is a Fedora object.
*/
Expand Down
Expand Up @@ -19,6 +19,7 @@
import java.util.ArrayList;
import java.util.Collections;

import static org.fcrepo.utils.FedoraTypesUtils.getJcrNamespaceForRDFNamespace;
import static org.slf4j.LoggerFactory.getLogger;

public class JcrPropertyStatementListener extends StatementListener {
Expand Down Expand Up @@ -69,7 +70,7 @@ public void addedStatement( Statement s ) {
Collections.addAll(newValues, node.getProperty(propertyName).getValues());
newValues.add(newValue);

property.setValue((Value[]) newValues.toArray(new Value[0]));
property.setValue((Value[]) newValues.toArray(new Value[newValues.size()]));
} else {
// or we'll just overwrite it
property.setValue(newValue);
Expand Down Expand Up @@ -265,12 +266,14 @@ private String getPropertyNameFromPredicate(com.hp.hpl.jena.rdf.model.Property p

final String prefix;

final String namespace = getJcrNamespaceForRDFNamespace(predicate.getNameSpace());

final NamespaceRegistry namespaceRegistry = getNamespaceRegistry();

if (namespaceRegistry.isRegisteredUri(predicate.getNameSpace())) {
prefix = namespaceRegistry.getPrefix(predicate.getNameSpace());
if (namespaceRegistry.isRegisteredUri(namespace)) {
prefix = namespaceRegistry.getPrefix(namespace);
} else {
prefix = namespaceRegistry.registerNamespace(predicate.getNameSpace());
prefix = namespaceRegistry.registerNamespace(namespace);
}

final String localName = predicate.getLocalName();
Expand Down
Expand Up @@ -20,6 +20,7 @@
import org.junit.Test;
import org.springframework.test.context.ContextConfiguration;

import static java.util.regex.Pattern.compile;
import static org.junit.Assert.*;

@ContextConfiguration({"/spring-test/repo.xml"})
Expand Down Expand Up @@ -62,6 +63,8 @@ public void testObjectGraph() throws Exception {
final FedoraObject object = objectService.createObject(session, "/graphObject");
final GraphStore graphStore = object.getGraphStore();

assertFalse("Graph store should not contain JCR prefixes", compile("jcr").matcher(graphStore.toString()).find());
assertFalse("Graph store should contain our fedora-internal prefix", compile("fedora-internal").matcher(graphStore.toString()).find());
assertEquals("info:fedora/graphObject", object.getGraphSubject().toString());

UpdateAction.parseExecute("PREFIX dc: <http://purl.org/dc/terms/>\n" +
Expand Down
Expand Up @@ -25,6 +25,9 @@
import org.mockito.stubbing.Answer;

public abstract class TestHelpers {

private static final SecureRandom GARBAGE_GENERATOR = new SecureRandom("G4RbAG3".getBytes());

public static Node getContentNodeMock(final int size) {
return getContentNodeMock(randomData(size));
}
Expand Down Expand Up @@ -116,7 +119,7 @@ public static PropertyIterator getPropertyIterator(final int numValues,

public static byte[] randomData(final int byteLength) {
final byte[] bytes = new byte[byteLength];
new SecureRandom().nextBytes(bytes);
GARBAGE_GENERATOR.nextBytes(bytes);
return bytes;
}
}
Expand Up @@ -7,6 +7,7 @@
import java.io.IOException;
import java.security.SecureRandom;

import org.fcrepo.utils.TestHelpers;
import org.infinispan.container.entries.InternalCacheEntry;
import org.infinispan.loaders.CacheLoaderException;
import org.infinispan.loaders.CacheStore;
Expand Down Expand Up @@ -44,7 +45,7 @@ public void testRead() throws IOException {
@Test
public void testBufferedRead() throws IOException, CacheLoaderException {
InternalCacheEntry mockEntry = mock(InternalCacheEntry.class);
byte [] data = SecureRandom.getSeed(DATA_SIZE);
byte[] data = TestHelpers.randomData(DATA_SIZE);
when(mockEntry.getValue()).thenReturn(data);
when(mockStore.load(anyString())).thenReturn(mockEntry).thenReturn(mockEntry).thenReturn(null);
int partition = 234;
Expand All @@ -67,7 +68,7 @@ public void testBufferedRead() throws IOException, CacheLoaderException {

@Test
public void testAvailable() throws IOException, CacheLoaderException {
byte [] data = SecureRandom.getSeed(DATA_SIZE);
byte[] data = TestHelpers.randomData(DATA_SIZE);
when(mockEntry.getValue()).thenReturn(data);
when(mockStore.load(mockFirstChunk)).thenReturn(mockEntry);
assertEquals(0, testObj.available());
Expand All @@ -86,7 +87,7 @@ public void testAvailable() throws IOException, CacheLoaderException {
@Test
public void testSkip() throws IOException, CacheLoaderException {
long expected = (DATA_SIZE - 1);
byte [] data = SecureRandom.getSeed(DATA_SIZE);
byte[] data = TestHelpers.randomData(DATA_SIZE);
when(mockEntry.getValue()).thenReturn(data);
when(mockStore.load(mockFirstChunk)).thenReturn(mockEntry);
long actual = testObj.skip(expected);
Expand All @@ -101,7 +102,7 @@ public void testSkip() throws IOException, CacheLoaderException {
@Test
public void testSkipMultipleBuffers() throws IOException, CacheLoaderException {
InternalCacheEntry mockEntry = mock(InternalCacheEntry.class);
byte [] data = SecureRandom.getSeed(DATA_SIZE);
byte[] data = TestHelpers.randomData(DATA_SIZE);
when(mockEntry.getValue()).thenReturn(data);
when(mockStore.load(anyString())).thenReturn(mockEntry).thenReturn(mockEntry).thenReturn(null);

Expand Down
Expand Up @@ -6,6 +6,7 @@
import java.io.IOException;
import java.security.SecureRandom;

import org.fcrepo.utils.TestHelpers;
import org.infinispan.container.entries.InternalCacheEntry;
import org.infinispan.loaders.CacheLoaderException;
import org.infinispan.loaders.CacheStore;
Expand All @@ -15,7 +16,7 @@
public class StoreChunkOutputStreamTest {

private static final int DATA_SIZE = 1024;

private StoreChunkOutputStream testObj;

private CacheStore mockStore;
Expand All @@ -34,7 +35,7 @@ public void setUp() {

@Test
public void testWritingMultipleChunks() throws IOException, CacheLoaderException {
byte[] data = SecureRandom.getSeed(DATA_SIZE);
byte[] data = TestHelpers.randomData(DATA_SIZE);
for (int i=0; i< 1025; i++) {
testObj.write(data);
}
Expand All @@ -45,7 +46,7 @@ public void testWritingMultipleChunks() throws IOException, CacheLoaderException

@Test
public void testWritingMultipleChunksOnVersionedKey() throws IOException, CacheLoaderException {
byte[] data = SecureRandom.getSeed(DATA_SIZE);
byte[] data = TestHelpers.randomData(DATA_SIZE);
when(mockStore.load(mockKey + "-0")).thenReturn(mockEntry);
for (int i=0; i< 1025; i++) {
testObj.write(data);
Expand Down
86 changes: 40 additions & 46 deletions fcrepo-webapp/src/main/resources/config/fedora-node-types.cnd
Expand Up @@ -11,33 +11,52 @@
*/
<foaf = 'http://xmlns.com/foaf/0.1/'>

/*
* Generic Fedora namespace
*/
<fedora = 'info:fedora'>

/*
* Dublin Core. See:
*
* http://dublincore.org/documents/dcmi-namespace/
*/
<dc = 'http://purl.org/dc/terms/'>

/*
* Generic Fedora namespace
*/
<fedora = 'info:fedora/'>

<fedorarelsext = 'info:fedora/fedora-system:def/relations-external#'>


[fedora:relations] mixin

- fedorarelsext:isPartOf (REFERENCE) multiple COPY
- fedorarelsext:hasPart (REFERENCE) multiple COPY
- fedorarelsext:isConstituentOf (REFERENCE) multiple COPY
- fedorarelsext:hasConstituent (REFERENCE) multiple COPY
- fedorarelsext:isMemberOf (REFERENCE) multiple COPY
- fedorarelsext:hasMember (REFERENCE) multiple COPY
- fedorarelsext:isSubsetOf (REFERENCE) multiple COPY
- fedorarelsext:hasSubset (REFERENCE) multiple COPY
- fedorarelsext:isMemberOfCollection (REFERENCE) multiple COPY
- fedorarelsext:hasCollectionMember (REFERENCE) multiple COPY
- fedorarelsext:isDerivationOf (REFERENCE) multiple COPY
- fedorarelsext:hasDerivation (REFERENCE) multiple COPY
- fedorarelsext:isDependentOf (REFERENCE) multiple COPY
- fedorarelsext:hasDependent (REFERENCE) multiple COPY
- fedorarelsext:isDescriptionOf (REFERENCE) multiple COPY
- fedorarelsext:HasDescription (REFERENCE) multiple COPY
- fedorarelsext:isMetadataFor (REFERENCE) multiple COPY
- fedorarelsext:HasMetadata (REFERENCE) multiple COPY
- fedorarelsext:isAnnotationOf (REFERENCE) multiple COPY
- fedorarelsext:HasAnnotation (REFERENCE) multiple COPY
- fedorarelsext:hasEquivalent (REFERENCE) multiple COPY

/*
* Any Fedora resource.
*/
[fedora:resource] > mix:created, mix:lastModified, mix:lockable, mix:versionable mixin abstract

/*
* Temporary for us until we better understand the use of jcr:created.
*/
- fedora:created (STRING) COPY

/*
* See: http://dublincore.org/documents/dcmi-terms/#elements-identifier
*/
- dc:identifier (STRING) multiple COPY
[fedora:resource] > fedora:relations, mix:created, mix:lastModified, mix:lockable, mix:versionable mixin

- * (STRING) multiple COPY
- * (STRING) COPY


/*
Expand All @@ -50,36 +69,11 @@
* A Fedora datastream.
*/
[fedora:datastream] > fedora:resource, nt:file mixin

/*
* The MIMEtype of this datastream.
*/
- fedora:contentType (STRING) COPY


/*
* Indicates that this resource is owned.
* Some content that can have a checksum
*/
[fedora:owned] mixin noquery

/*
* The owner of this owned resource.
*/
- fedora:owner (REFERENCE) COPY

/*
* For use for when the owner-entities are not managed in the repository.
*/
- fedora:ownerId (STRING) COPY


/*
* Some entity that owns a Fedora resource.
*/
[fedora:owner] primaryitem foaf:name

/*
* The name of this owner.
*/
- foaf:name (STRING) multiple COPY

[fedora:binary] > nt:resource mixin
- fedora:size (LONG) COPY
- fedora:digest (STRING) COPY
- fedora:digestAlgorithm (STRING) COPY

0 comments on commit ebfd83d

Please sign in to comment.