Skip to content
Permalink
Browse files

Re-Work true blank-node implementation

- Unit tests for new skolemization classes
- Unit tests for hash-URI machinery

Resolves: https://jira.duraspace.org/browse/FCREPO-1385
  • Loading branch information...
ajs6f authored and awoods committed Mar 9, 2015
1 parent 6e7e22e commit ceacc9832890906c8dee8f4533f5b33679d9b875
Showing with 1,074 additions and 544 deletions.
  1. +5 −3 fcrepo-auth-common/src/test/java/org/fcrepo/auth/integration/ContainerRolesPrincipalProviderIT.java
  2. +5 −3 fcrepo-auth-common/src/test/java/org/fcrepo/auth/integration/HttpHeaderPrincipalProviderIT.java
  3. +5 −3 fcrepo-auth-common/src/test/java/org/fcrepo/auth/integration/ModeShapeHonorsFADResponseIT.java
  4. +3 −3 ...rc/test/java/org/fcrepo/integration/connector/file/BasicReadWriteFedoraFileSystemConnectorIT.java
  5. +16 −5 fcrepo-http-api/src/main/java/org/fcrepo/http/api/ContentExposingResource.java
  6. +2 −3 fcrepo-http-api/src/main/java/org/fcrepo/http/api/FedoraBaseResource.java
  7. +5 −9 fcrepo-http-api/src/main/java/org/fcrepo/http/api/FedoraLdp.java
  8. +18 −57 fcrepo-http-api/src/test/java/org/fcrepo/http/api/FedoraLdpTest.java
  9. +10 −13 fcrepo-http-api/src/test/java/org/fcrepo/integration/http/api/FedoraLdpIT.java
  10. +4 −2 fcrepo-jms/src/test/java/org/fcrepo/integration/jms/observer/HeadersJMSIT.java
  11. +63 −10 fcrepo-kernel-impl/src/main/java/org/fcrepo/kernel/impl/FedoraResourceImpl.java
  12. +136 −0 fcrepo-kernel-impl/src/main/java/org/fcrepo/kernel/impl/rdf/Deskolemizer.java
  13. +78 −0 fcrepo-kernel-impl/src/main/java/org/fcrepo/kernel/impl/rdf/HashURIDetector.java
  14. +0 −113 fcrepo-kernel-impl/src/main/java/org/fcrepo/kernel/impl/rdf/JcrRdfTools.java
  15. +126 −0 fcrepo-kernel-impl/src/main/java/org/fcrepo/kernel/impl/rdf/Skolemizer.java
  16. +2 −2 fcrepo-kernel-impl/src/main/java/org/fcrepo/kernel/impl/rdf/impl/BlankNodeRdfContext.java
  17. +11 −26 fcrepo-kernel-impl/src/main/java/org/fcrepo/kernel/impl/utils/FedoraTypesUtils.java
  18. +47 −19 fcrepo-kernel-impl/src/main/java/org/fcrepo/kernel/impl/utils/JcrPropertyStatementListener.java
  19. +1 −4 ...kernel-impl/src/main/java/org/fcrepo/kernel/impl/utils/iterators/PersistingRdfStreamConsumer.java
  20. +1 −1 fcrepo-kernel-impl/src/main/resources/fedora-node-types.cnd
  21. +26 −18 fcrepo-kernel-impl/src/test/java/org/fcrepo/integration/kernel/impl/ContainerImplIT.java
  22. +19 −11 fcrepo-kernel-impl/src/test/java/org/fcrepo/integration/kernel/impl/FedoraResourceImplIT.java
  23. +6 −14 fcrepo-kernel-impl/src/test/java/org/fcrepo/kernel/impl/FedoraResourceImplTest.java
  24. +176 −0 fcrepo-kernel-impl/src/test/java/org/fcrepo/kernel/impl/rdf/DeskolemizerTest.java
  25. +128 −0 fcrepo-kernel-impl/src/test/java/org/fcrepo/kernel/impl/rdf/HashURIDetectorTest.java
  26. +0 −176 fcrepo-kernel-impl/src/test/java/org/fcrepo/kernel/impl/rdf/JcrRdfToolsTest.java
  27. +97 −0 fcrepo-kernel-impl/src/test/java/org/fcrepo/kernel/impl/rdf/SkolemizerTest.java
  28. +3 −3 fcrepo-kernel-impl/src/test/java/org/fcrepo/kernel/impl/rdf/impl/BlankNodeRdfContextTest.java
  29. +7 −7 fcrepo-kernel-impl/src/test/java/org/fcrepo/kernel/impl/utils/FedoraTypesUtilsTest.java
  30. +3 −5 fcrepo-kernel-impl/src/test/java/org/fcrepo/kernel/impl/utils/JcrPropertyStatementListenerTest.java
  31. +1 −1 fcrepo-kernel/src/main/java/org/fcrepo/kernel/FedoraJcrTypes.java
  32. +7 −4 fcrepo-kernel/src/main/java/org/fcrepo/kernel/models/FedoraResource.java
  33. +34 −23 fcrepo-kernel/src/main/java/org/fcrepo/kernel/utils/iterators/RdfStream.java
  34. +29 −6 fcrepo-kernel/src/test/java/org/fcrepo/kernel/utils/iterators/RdfStreamTest.java
@@ -16,10 +16,12 @@
package org.fcrepo.auth.integration;

import org.apache.http.auth.BasicUserPrincipal;

import org.fcrepo.auth.common.FedoraAuthorizationDelegate;
import org.fcrepo.auth.common.ServletContainerAuthenticationProvider;
import org.fcrepo.kernel.impl.services.ContainerServiceImpl;
import org.fcrepo.kernel.services.ContainerService;

import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -38,8 +40,8 @@
import javax.servlet.http.HttpServletRequest;

import static org.mockito.Matchers.any;
import static org.mockito.Mockito.atLeastOnce;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.slf4j.LoggerFactory.getLogger;
@@ -60,7 +62,7 @@
@Autowired
private FedoraAuthorizationDelegate fad;

private HttpServletRequest request = mock(HttpServletRequest.class);
private final HttpServletRequest request = mock(HttpServletRequest.class);

@Test
public void testFactory() {
@@ -91,7 +93,7 @@ public void testEmptyPrincipalProvider() throws RepositoryException {
}
final ContainerService os = new ContainerServiceImpl();
os.findOrCreate(session, "/myobject");
verify(fad, times(9)).hasPermission(any(Session.class), any(Path.class), any(String[].class));
verify(fad, atLeastOnce()).hasPermission(any(Session.class), any(Path.class), any(String[].class));
}


@@ -16,10 +16,12 @@
package org.fcrepo.auth.integration;

import org.apache.http.auth.BasicUserPrincipal;

import org.fcrepo.auth.common.FedoraAuthorizationDelegate;
import org.fcrepo.auth.common.ServletContainerAuthenticationProvider;
import org.fcrepo.kernel.impl.services.ContainerServiceImpl;
import org.fcrepo.kernel.services.ContainerService;

import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -38,8 +40,8 @@
import javax.servlet.http.HttpServletRequest;

import static org.mockito.Matchers.any;
import static org.mockito.Mockito.atLeastOnce;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.slf4j.LoggerFactory.getLogger;
@@ -60,7 +62,7 @@
@Autowired
private FedoraAuthorizationDelegate fad;

private HttpServletRequest request = mock(HttpServletRequest.class);
private final HttpServletRequest request = mock(HttpServletRequest.class);

@Test
public void testFactory() {
@@ -91,7 +93,7 @@ public void testEmptyPrincipalProvider() throws RepositoryException {
}
final ContainerService os = new ContainerServiceImpl();
os.findOrCreate(session, "/myobject");
verify(fad, times(9)).hasPermission(any(Session.class), any(Path.class), any(String[].class));
verify(fad, atLeastOnce()).hasPermission(any(Session.class), any(Path.class), any(String[].class));
}

}
@@ -16,17 +16,19 @@
package org.fcrepo.auth.integration;

import static org.mockito.Matchers.any;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.atLeastOnce;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.slf4j.LoggerFactory.getLogger;

import org.apache.http.auth.BasicUserPrincipal;

import org.fcrepo.auth.common.FedoraAuthorizationDelegate;
import org.fcrepo.auth.common.ServletContainerAuthenticationProvider;
import org.fcrepo.kernel.exception.RepositoryRuntimeException;
import org.fcrepo.kernel.services.ContainerService;
import org.fcrepo.kernel.impl.services.ContainerServiceImpl;

import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
@@ -103,7 +105,7 @@ public void testPermissiveFAD() throws RepositoryException {
}
final ContainerService os = new ContainerServiceImpl();
os.findOrCreate(session, "/myobject");
verify(fad, times(9)).hasPermission(any(Session.class), any(Path.class), any(String[].class));
verify(fad, atLeastOnce()).hasPermission(any(Session.class), any(Path.class), any(String[].class));
}

@Test(expected = AccessDeniedException.class)
@@ -128,6 +130,6 @@ public void testRestrictiveFAD() throws Throwable {
} catch (final RepositoryRuntimeException e) {
throw e.getCause();
}
verify(fad, times(5)).hasPermission(any(Session.class), any(Path.class), any(String[].class));
verify(fad, atLeastOnce()).hasPermission(any(Session.class), any(Path.class), any(String[].class));
}
}
@@ -71,7 +71,7 @@ public void testWriteProperty() throws RepositoryException {


// Write the properties
object.updateProperties(new DefaultIdentifierTranslator(session), sparql, new RdfStream());
object.updateProperties(new DefaultIdentifierTranslator(session), sparql, new RdfStream(), containerService);

// Verify
final Property property = object.getNode().getProperty("fedora:name");
@@ -97,7 +97,7 @@ public void testRemoveProperty() throws RepositoryException {

// Write the properties
final DefaultIdentifierTranslator graphSubjects = new DefaultIdentifierTranslator(session);
object.updateProperties(graphSubjects, sparql, new RdfStream());
object.updateProperties(graphSubjects, sparql, new RdfStream(), containerService);

// Verify property exists
final Property property = object.getNode().getProperty("fedora:remove");
@@ -114,7 +114,7 @@ public void testRemoveProperty() throws RepositoryException {
// Remove the properties
object.updateProperties(graphSubjects,
sparqlRemove,
object.getTriples(graphSubjects, PropertiesRdfContext.class));
object.getTriples(graphSubjects, PropertiesRdfContext.class), containerService);

// Persist the object (although the propery will be removed from memory without this.)
session.save();
@@ -74,6 +74,7 @@
import org.fcrepo.kernel.exception.InvalidChecksumException;
import org.fcrepo.kernel.exception.MalformedRdfException;
import org.fcrepo.kernel.exception.RepositoryRuntimeException;
import org.fcrepo.kernel.impl.rdf.Deskolemizer;
import org.fcrepo.kernel.impl.rdf.ManagedRdf;
import org.fcrepo.kernel.impl.rdf.impl.AclRdfContext;
import org.fcrepo.kernel.impl.rdf.impl.BlankNodeRdfContext;
@@ -116,12 +117,16 @@
* content.
*
* @author Mike Durbin
* @author ajs6f
*/
public abstract class ContentExposingResource extends FedoraBaseResource {

public static final MediaType MESSAGE_EXTERNAL_BODY = MediaType.valueOf("message/external-body");

@Context protected Request request;

private Deskolemizer deskolemizer;

@Context protected HttpServletResponse servletResponse;

@Inject
@@ -141,6 +146,13 @@

protected abstract String externalPath();

private Deskolemizer deskolemizer() {
if (deskolemizer != null) {
return deskolemizer;
}
return deskolemizer = new Deskolemizer(translator(), null);
}

protected Response getContent(final String rangeValue,
final RdfStream rdfStream) throws IOException {
if (resource() instanceof FedoraBinary) {
@@ -192,7 +204,7 @@ public Triple apply(final Statement input) {
}
servletResponse.addHeader("Vary", "Accept, Range, Accept-Encoding, Accept-Language");

return Response.ok(rdfStream).build();
return ok(rdfStream.map(deskolemizer())).build();
}

protected RdfStream getResourceTriples() {
@@ -294,8 +306,7 @@ public RdfStream apply(final FedoraResource child) {
httpTripleUtil.addHttpComponentModelsForResourceToStream(rdfStream, resource(), uriInfo, translator());
}


return rdfStream;
return rdfStream.map(deskolemizer());
}

/**
@@ -595,14 +606,14 @@ protected void replaceResourceWithStream(final FedoraResource resource,
final Model inputModel = createDefaultModel()
.read(requestBodyStream, getUri(resource).toString(), format.getName().toUpperCase());

resource.replaceProperties(translator(), inputModel, resourceTriples);
resource.replaceProperties(translator(), inputModel, resourceTriples, containerService);
}

protected void patchResourcewithSparql(final FedoraResource resource,
final String requestBody,
final RdfStream resourceTriples)
throws MalformedRdfException, AccessDeniedException {
resource.updateProperties(translator(), requestBody, resourceTriples);
resource.updateProperties(translator(), requestBody, resourceTriples, containerService);
}

/**
@@ -51,9 +51,8 @@
protected IdentifierConverter<Resource, FedoraResource> translator() {
if (idTranslator == null) {
idTranslator = new HttpResourceConverter(session(),
uriInfo.getBaseUriBuilder().clone().path(FedoraLdp.class));
uriInfo.getBaseUriBuilder().clone().path(FedoraLdp.class));
}

return idTranslator;
}

@@ -90,7 +89,7 @@ protected void setUpJMSInfo(final UriInfo uriInfo, final HttpHeaders headers) {
json.addProperty("userAgent",headers.getHeaderString("user-agent"));
}
obs.setUserData(json.toString());
} catch ( Exception ex ) {
} catch ( final Exception ex ) {
LOGGER.warn("Error setting baseURL", ex);
}
}
@@ -316,15 +316,14 @@ public Response createOrReplaceObjectRdf(
*
* @param requestBodyStream the request body stream
* @return 201
* @throws MalformedRdfException if malformed rdf exception occurred
* @throws AccessDeniedException if exception updating property occurred
* @throws IOException if IO exception occurred
*/
@PATCH
@Consumes({contentTypeSPARQLUpdate})
@Timed
public Response updateSparql(@ContentLocation final InputStream requestBodyStream)
throws IOException, MalformedRdfException, AccessDeniedException {
throws IOException, AccessDeniedException {

if (null == requestBodyStream) {
throw new BadRequestException("SPARQL-UPDATE requests must have content!");
@@ -359,13 +358,15 @@ public Response updateSparql(@ContentLocation final InputStream requestBodyStrea

return noContent().build();
} catch ( final RuntimeException ex ) {
LOGGER.debug("Caught exception:", ex);
final Throwable cause = ex.getCause();
if (cause instanceof PathNotFoundException) {
// the sparql update referred to a repository resource that doesn't exist
throw new BadRequestException(cause.getMessage());
}
throw ex;
} catch (final RepositoryException e) {
LOGGER.debug("Caught exception:", e);
if (e instanceof AccessDeniedException) {
throw new AccessDeniedException(e.getMessage());
}
@@ -419,13 +420,8 @@ public Response createObject(@QueryParam("checksum") final String checksum,
effectiveContentType,
contentDisposition);

final RdfStream resourceTriples;

if (result.isNew()) {
resourceTriples = new RdfStream();
} else {
resourceTriples = getResourceTriples();
}
final RdfStream resourceTriples =
result.isNew() ? new RdfStream().session(session) : getResourceTriples().session(session);

if (requestBodyStream == null) {
LOGGER.trace("No request body detected");
Oops, something went wrong.

0 comments on commit ceacc98

Please sign in to comment.
You can’t perform that action at this time.