Skip to content

Commit

Permalink
First draft, blocked on unintelligible auth ITs
Browse files Browse the repository at this point in the history
  • Loading branch information
ajs6f committed Mar 9, 2015
1 parent b7b5f97 commit 3d819aa
Show file tree
Hide file tree
Showing 27 changed files with 633 additions and 516 deletions.
Expand Up @@ -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");
Expand All @@ -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");
Expand All @@ -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();
Expand Down
Expand Up @@ -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;
Expand Down Expand Up @@ -192,7 +193,7 @@ public Triple apply(final Statement input) {
}
servletResponse.addHeader("Vary", "Accept, Range, Accept-Encoding, Accept-Language");

return Response.ok(rdfStream).build();
return ok(rdfStream.withThisContext(rdfStream.transform(new Deskolemizer(idTranslator, null)))).build();
}

protected RdfStream getResourceTriples() {
Expand Down Expand Up @@ -295,7 +296,9 @@ public RdfStream apply(final FedoraResource child) {
}


return rdfStream;
return rdfStream.withThisContext(rdfStream.transform(new Deskolemizer(idTranslator, resource == null ? null
: idTranslator.reverse()
.convert(resource).getModel())));
}

/**
Expand Down Expand Up @@ -595,14 +598,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);
}

/**
Expand Down
Expand Up @@ -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!");
Expand Down Expand Up @@ -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());
}
Expand Down
Expand Up @@ -19,7 +19,6 @@
import static com.google.common.collect.Iterables.any;
import static com.google.common.collect.Lists.newArrayList;
import static com.google.common.collect.Lists.transform;

import static com.hp.hpl.jena.graph.NodeFactory.createURI;
import static javax.ws.rs.core.MediaType.APPLICATION_OCTET_STREAM;
import static javax.ws.rs.core.MediaType.APPLICATION_OCTET_STREAM_TYPE;
Expand Down Expand Up @@ -74,6 +73,7 @@
import javax.ws.rs.core.UriBuilder;

import org.apache.commons.io.IOUtils;

import org.fcrepo.http.commons.api.rdf.HttpResourceConverter;
import org.fcrepo.http.commons.domain.MultiPrefer;
import org.fcrepo.kernel.identifiers.IdentifierConverter;
Expand All @@ -85,7 +85,9 @@
import org.fcrepo.kernel.services.BinaryService;
import org.fcrepo.kernel.services.ContainerService;
import org.fcrepo.kernel.services.NodeService;
import org.fcrepo.kernel.services.Service;
import org.fcrepo.kernel.utils.iterators.RdfStream;

import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
Expand Down Expand Up @@ -651,7 +653,8 @@ public void testPutNewObjectWithRdf() throws Exception {
toInputStream("_:a <info:x> _:c ."), null, null, null);

assertEquals(CREATED.getStatusCode(), actual.getStatus());
verify(mockContainer).replaceProperties(eq(idTranslator), any(Model.class), any(RdfStream.class));
verify(mockContainer).replaceProperties(eq(idTranslator), any(Model.class), any(RdfStream.class),
any(Service.class));
}

@Test
Expand Down Expand Up @@ -683,7 +686,8 @@ public void testPutReplaceRdfObject() throws Exception {
toInputStream("_:a <info:x> _:c ."), null, null, null);

assertEquals(NO_CONTENT.getStatusCode(), actual.getStatus());
verify(mockObject).replaceProperties(eq(idTranslator), any(Model.class), any(RdfStream.class));
verify(mockObject).replaceProperties(eq(idTranslator), any(Model.class), any(RdfStream.class),
any(Service.class));
}

@Test(expected = ClientErrorException.class)
Expand Down Expand Up @@ -766,7 +770,7 @@ public void testCreateNewObjectWithSparql() throws Exception {
MediaType.valueOf(contentTypeSPARQLUpdate), "b", toInputStream("x"));

assertEquals(CREATED.getStatusCode(), actual.getStatus());
verify(mockContainer).updateProperties(eq(idTranslator), eq("x"), any(RdfStream.class));
verify(mockContainer).updateProperties(eq(idTranslator), eq("x"), any(RdfStream.class), any(Service.class));
}

@Test
Expand All @@ -780,7 +784,8 @@ public void testCreateNewObjectWithRdf() throws Exception {
toInputStream("_:a <info:b> _:c ."));

assertEquals(CREATED.getStatusCode(), actual.getStatus());
verify(mockContainer).replaceProperties(eq(idTranslator), any(Model.class), any(RdfStream.class));
verify(mockContainer).replaceProperties(eq(idTranslator), any(Model.class), any(RdfStream.class),
any(Service.class));
}


Expand Down
Expand Up @@ -449,7 +449,7 @@ public void testGetNonRDFSource() throws Exception {
}

@Test
public void testGetNonRDFSourceDescription() throws Exception {
public void testGetNonRDFSourceDescription() throws IOException {
final String pid = getRandomUniquePid();

createDatastream(pid, "x", "some content");
Expand Down Expand Up @@ -646,19 +646,14 @@ public void testPatchWithBlankNode() throws Exception {
final HttpGet httpGet = new HttpGet(location);

final GraphStore graphStore = getGraphStore(httpGet);

LOGGER.debug("Recovered graph: {}", graphStore);
assertTrue(graphStore.contains(ANY, createResource(location).asNode(),
createProperty("info:some-predicate").asNode(), ANY));

final Node bnode = graphStore.find(ANY, createResource(location).asNode(),
createProperty("info:some-predicate").asNode(), ANY).next().getObject();

final HttpGet bnodeHttpGet = new HttpGet(bnode.getURI());

final GraphStore bnodeGraphStore = getGraphStore(bnodeHttpGet);

assertTrue(bnodeGraphStore.contains(ANY, bnode, DC_TITLE.asNode(), createLiteral("this is a title")));

assertTrue(bnode.isBlank());

}

Expand Down

0 comments on commit 3d819aa

Please sign in to comment.