Skip to content

Commit

Permalink
Leaving in unfinished state
Browse files Browse the repository at this point in the history
  • Loading branch information
ajs6f committed Feb 10, 2014
1 parent 1ba154b commit 38d1b55
Show file tree
Hide file tree
Showing 26 changed files with 408 additions and 378 deletions.
Expand Up @@ -63,6 +63,7 @@
import javax.ws.rs.core.Response.ResponseBuilder;

import com.hp.hpl.jena.rdf.model.Model;

import org.apache.commons.io.IOUtils;
import org.apache.jena.riot.Lang;
import org.fcrepo.http.commons.AbstractResource;
Expand All @@ -71,7 +72,9 @@
import org.fcrepo.kernel.Datastream;
import org.fcrepo.kernel.FedoraResource;
import org.fcrepo.kernel.exception.InvalidChecksumException;
import org.fcrepo.kernel.impl.ReplacePropertiesTactic;
import org.fcrepo.kernel.utils.ContentDigest;
import org.fcrepo.kernel.utils.iterators.RdfStream;
import org.modeshape.jcr.ExecutionContext;
import org.modeshape.jcr.value.PathFactory;
import org.slf4j.Logger;
Expand Down Expand Up @@ -156,7 +159,7 @@ public Response batchModify(@PathParam("path") final List<PathSegment> pathList,

try {

final Set<Node> nodesChanged = new HashSet<Node>();
final Set<Node> nodesChanged = new HashSet<>();

// iterate through the multipart entities
for (final BodyPart part : multipart.getBodyParts()) {
Expand Down Expand Up @@ -248,7 +251,8 @@ public Response batchModify(@PathParam("path") final List<PathSegment> pathList,
subjects.getGraphSubject(resource.getNode()).toString(),
format);

resource.replaceProperties(subjects, inputModel);
resource.updateProperties(subjects, new ReplacePropertiesTactic(RdfStream
.fromModel(inputModel)));
} else {
throw new WebApplicationException(notAcceptable()
.entity("Invalid Content Type " + contentTypeString).build());
Expand Down Expand Up @@ -340,18 +344,16 @@ public Response batchDelete(@PathParam("path") final List<PathSegment> pathList,
* @param request
* @return
* @throws RepositoryException
* @throws IOException
* @throws NoSuchAlgorithmException
*/
@GET
@Produces("multipart/mixed")
@Timed
public Response getBinaryContents(@PathParam("path") final List<PathSegment> pathList,
@QueryParam("child") final List<String> requestedChildren,
@Context final Request request) throws RepositoryException, IOException,
NoSuchAlgorithmException {
@QueryParam("child") final List<String> requestedChildren,
@Context final Request request) throws RepositoryException, NoSuchAlgorithmException {

final List<Datastream> datastreams = new ArrayList<Datastream>();
final List<Datastream> datastreams = new ArrayList<>();

try {
final String path = toPath(pathList);
Expand Down
74 changes: 28 additions & 46 deletions fcrepo-http-api/src/main/java/org/fcrepo/http/api/FedoraNodes.java
Expand Up @@ -29,7 +29,6 @@
import static javax.ws.rs.core.Response.created;
import static javax.ws.rs.core.Response.noContent;
import static javax.ws.rs.core.Response.status;
import static javax.ws.rs.core.Response.Status.FORBIDDEN;
import static org.apache.http.HttpStatus.SC_BAD_GATEWAY;
import static org.apache.http.HttpStatus.SC_BAD_REQUEST;
import static org.apache.http.HttpStatus.SC_CONFLICT;
Expand All @@ -48,7 +47,6 @@
import static org.fcrepo.jcr.FedoraJcrTypes.FEDORA_OBJECT;
import static org.fcrepo.kernel.RdfLexicon.FIRST_PAGE;
import static org.fcrepo.kernel.RdfLexicon.NEXT_PAGE;
import static org.fcrepo.kernel.rdf.GraphProperties.PROBLEMS_MODEL_NAME;
import static org.slf4j.LoggerFactory.getLogger;

import java.io.IOException;
Expand Down Expand Up @@ -89,6 +87,7 @@
import com.hp.hpl.jena.rdf.model.ResourceFactory;
import com.sun.jersey.core.header.ContentDisposition;
import com.sun.jersey.multipart.FormDataParam;

import org.apache.commons.io.IOUtils;
import org.apache.jena.riot.Lang;
import org.fcrepo.http.commons.AbstractResource;
Expand All @@ -98,9 +97,11 @@
import org.fcrepo.http.commons.domain.COPY;
import org.fcrepo.http.commons.session.InjectedSession;
import org.fcrepo.kernel.Datastream;
import org.fcrepo.kernel.FedoraResourceImpl;
import org.fcrepo.kernel.FedoraResource;
import org.fcrepo.kernel.PropertiesUpdateTactic;
import org.fcrepo.kernel.exception.InvalidChecksumException;
import org.fcrepo.kernel.impl.ReplacePropertiesTactic;
import org.fcrepo.kernel.impl.SparqlUpdateTactic;
import org.fcrepo.kernel.rdf.GraphSubjects;
import org.fcrepo.kernel.utils.iterators.RdfStream;
import org.modeshape.jcr.api.JcrConstants;
Expand All @@ -110,7 +111,6 @@

import com.codahale.metrics.annotation.Timed;
import com.hp.hpl.jena.graph.Node;
import com.hp.hpl.jena.query.Dataset;
import com.hp.hpl.jena.rdf.model.Model;

/**
Expand Down Expand Up @@ -141,7 +141,6 @@ public class FedoraNodes extends AbstractResource {
* @param uriInfo
* @return
* @throws RepositoryException
* @throws IOException
*/
@GET
@Produces({TURTLE, N3, N3_ALT2, RDF_XML, NTRIPLES, APPLICATION_XML, TEXT_PLAIN, TURTLE_X,
Expand All @@ -152,7 +151,7 @@ public RdfStream describe(@PathParam("path") final List<PathSegment> pathList,
@QueryParam("non-member-properties") final String nonMemberProperties,
@Context final Request request,
@Context final HttpServletResponse servletResponse,
@Context final UriInfo uriInfo) throws RepositoryException, IOException {
@Context final UriInfo uriInfo) throws RepositoryException {
final String path = toPath(pathList);
LOGGER.trace("Getting profile for: {}", path);

Expand Down Expand Up @@ -242,13 +241,9 @@ public RdfStream describe(@PathParam("path") final List<PathSegment> pathList,
@PATCH
@Consumes({contentTypeSPARQLUpdate})
@Timed
public Response updateSparql(@PathParam("path")
final List<PathSegment> pathList,
@Context
final UriInfo uriInfo,
final InputStream requestBodyStream,
@Context final Request request)
throws RepositoryException, IOException {
public Response updateSparql(@PathParam("path") final List<PathSegment> pathList,
@Context final UriInfo uriInfo, final InputStream requestBodyStream,
@Context final Request request) throws RepositoryException, IOException {

final String path = toPath(pathList);
LOGGER.debug("Attempting to update path: {}", path);
Expand Down Expand Up @@ -276,29 +271,18 @@ public Response updateSparql(@PathParam("path")
throw new WebApplicationException(builder.build());
}

final Dataset properties = resource.updatePropertiesDataset(new HttpGraphSubjects(
session, FedoraNodes.class, uriInfo), IOUtils
.toString(requestBodyStream));
final String sparqlUpdateStatement = IOUtils.toString(requestBodyStream);


final Model problems = properties.getNamedModel(PROBLEMS_MODEL_NAME);
if (!problems.isEmpty()) {
LOGGER.info(
"Found these problems updating the properties for {}: {}",
path, problems);
return status(FORBIDDEN).entity(problems.toString())
.build();

}
final PropertiesUpdateTactic update = new SparqlUpdateTactic(sparqlUpdateStatement);
resource.updateProperties(new HttpGraphSubjects(session, FedoraNodes.class, uriInfo), update);

session.save();
versionService.nodeUpdated(resource.getNode());

return status(SC_NO_CONTENT).build();
} else {
return status(SC_BAD_REQUEST).entity(
"SPARQL-UPDATE requests must have content!").build();
}
return status(SC_BAD_REQUEST).entity(
"SPARQL-UPDATE requests must have content!").build();

} finally {
session.logout();
Expand Down Expand Up @@ -360,7 +344,7 @@ public Response createOrReplaceObjectRdf(
graphSubjects.getGraphSubject(resource.getNode()).toString(),
format);

resource.replaceProperties(graphSubjects, inputModel);
resource.updateProperties(graphSubjects, new ReplacePropertiesTactic(RdfStream.fromModel(inputModel)));
}

session.save();
Expand Down Expand Up @@ -450,7 +434,7 @@ public Response createObject(@PathParam("path")
}
}

final FedoraResourceImpl result;
final FedoraResource result;

switch (objectType) {
case FEDORA_OBJECT:
Expand All @@ -473,7 +457,9 @@ public Response createObject(@PathParam("path")
final String contentTypeString = contentType.toString();

if (contentTypeString.equals(contentTypeSPARQLUpdate)) {
result.updatePropertiesDataset(subjects, IOUtils.toString(requestBodyStream));
final String sparqlUpdateStatement = IOUtils.toString(requestBodyStream);
final PropertiesUpdateTactic update = new SparqlUpdateTactic(sparqlUpdateStatement);
result.updateProperties(new HttpGraphSubjects(session, FedoraNodes.class, uriInfo), update);
} else if (contentTypeToLang(contentTypeString) != null) {

final Lang lang = contentTypeToLang(contentTypeString);
Expand All @@ -483,16 +469,13 @@ public Response createObject(@PathParam("path")
"Invalid Content type " + contentType).build());
}

final String format = lang.getName()
.toUpperCase();
final String format = lang.getName().toUpperCase();

final Model inputModel =
createDefaultModel()
.read(requestBodyStream,
subjects.getGraphSubject(result.getNode()).toString(),
format);
createDefaultModel().read(requestBodyStream,
subjects.getGraphSubject(result.getNode()).toString(), format);

result.replaceProperties(subjects, inputModel);
result.updateProperties(subjects, new ReplacePropertiesTactic(RdfStream.fromModel(inputModel)));
} else if (result instanceof Datastream) {

final String originalFileName;
Expand Down Expand Up @@ -544,13 +527,12 @@ public Response createObject(@PathParam("path")
@POST
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Timed
public Response createObjectFromFormPost(
@PathParam("path") final List<PathSegment> pathList,
@FormDataParam("mixin") final String mixin,
@FormDataParam("slug") final String slug,
@Context final UriInfo uriInfo,
@FormDataParam("file") final InputStream file
) throws RepositoryException, URISyntaxException, InvalidChecksumException, ParseException, IOException {
public Response createObjectFromFormPost(@PathParam("path")
final List<PathSegment> pathList, @FormDataParam("mixin")
final String mixin, @FormDataParam("slug")
final String slug, @Context
final UriInfo uriInfo, @FormDataParam("file") final InputStream file)
throws RepositoryException, URISyntaxException, InvalidChecksumException, ParseException, IOException {

return createObject(pathList, mixin, null, null, null, slug, uriInfo, file);

Expand Down
Expand Up @@ -29,7 +29,6 @@
import static org.fcrepo.http.commons.test.util.TestHelpers.mockSession;
import static org.fcrepo.http.commons.test.util.TestHelpers.setField;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyString;
import static org.mockito.Matchers.eq;
Expand Down Expand Up @@ -59,15 +58,14 @@
import javax.ws.rs.core.Request;
import javax.ws.rs.core.Response;

import com.hp.hpl.jena.rdf.model.Model;
import org.apache.commons.io.IOUtils;
import org.fcrepo.kernel.Datastream;
import org.fcrepo.kernel.FedoraResourceImpl;
import org.fcrepo.kernel.PropertiesUpdateTactic;
import org.fcrepo.kernel.rdf.GraphSubjects;
import org.fcrepo.kernel.services.DatastreamService;
import org.fcrepo.kernel.services.NodeService;
import org.fcrepo.kernel.services.VersionService;

import org.junit.Before;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
Expand Down Expand Up @@ -180,12 +178,8 @@ public void testBatchRdfPost() throws Exception {
multipart.bodyPart(part);

testObj.batchModify(createPathList(pid), multipart);
ArgumentCaptor<Model> captor = ArgumentCaptor.forClass(Model.class);
verify(mockObject).replaceProperties(any(GraphSubjects.class), captor.capture());
final Model capturedModel = captor.getValue();
assertTrue(capturedModel.contains(capturedModel.createResource("http://localhost/fcrepo/" + pid),
capturedModel.createProperty("info:a"),
capturedModel.createLiteral("xyz")));
final ArgumentCaptor<PropertiesUpdateTactic> captor = ArgumentCaptor.forClass(PropertiesUpdateTactic.class);
verify(mockObject).updateProperties(any(GraphSubjects.class), captor.capture());
verify(mockSession).save();
}

Expand Down Expand Up @@ -271,7 +265,7 @@ public void testBatchDelete() throws Exception {
}

@Test
public void testDeleteDatastreams() throws RepositoryException, IOException {
public void testDeleteDatastreams() throws RepositoryException {
final String pid = "FedoraDatastreamsTest1";
final String path = "/" + pid;
final List<String> dsidList = asList("ds1", "ds2");
Expand Down Expand Up @@ -318,7 +312,6 @@ public void testGetDatastreamsContents() throws RepositoryException,

@Test
public void testGetDatastreamsContentsCached() throws RepositoryException,
IOException,
NoSuchAlgorithmException {
final String pid = "FedoraDatastreamsTest1";
final String dsId = "testDS";
Expand Down
Expand Up @@ -69,6 +69,7 @@
import org.fcrepo.kernel.Datastream;
import org.fcrepo.kernel.FedoraObject;
import org.fcrepo.kernel.FedoraResourceImpl;
import org.fcrepo.kernel.PropertiesUpdateTactic;
import org.fcrepo.kernel.identifiers.PidMinter;
import org.fcrepo.kernel.rdf.GraphSubjects;
import org.fcrepo.kernel.services.DatastreamService;
Expand Down Expand Up @@ -164,7 +165,7 @@ public void setUp() throws Exception {

@Test
@Ignore
public void testIngestAndMint() throws RepositoryException {
public void testIngestAndMint() {
// final Response actual =
// testObj.ingestAndMint(createPathList("objects"));
// assertNotNull(actual);
Expand Down Expand Up @@ -306,7 +307,7 @@ public void testDeleteObject() throws RepositoryException {
}

@Test
public void testDescribeObject() throws RepositoryException, IOException {
public void testDescribeObject() throws RepositoryException {
final String pid = "FedoraObjectsRdfTest1";
final String path = "/" + pid;

Expand All @@ -320,7 +321,6 @@ public void testDescribeObject() throws RepositoryException, IOException {
mockRdfStream2);
when(mockNodes.getObject(isA(Session.class), isA(String.class)))
.thenReturn(mockObject);
final Request mockRequest = mock(Request.class);
final RdfStream rdfStream =
testObj.describe(createPathList(path), 0, -2, null, mockRequest,
mockResponse, mockUriInfo);
Expand All @@ -331,7 +331,7 @@ public void testDescribeObject() throws RepositoryException, IOException {
}

@Test
public void testDescribeObjectNoInlining() throws RepositoryException, IOException {
public void testDescribeObjectNoInlining() throws RepositoryException {
final String pid = "FedoraObjectsRdfTest1";
final String path = "/" + pid;

Expand All @@ -346,7 +346,6 @@ public void testDescribeObjectNoInlining() throws RepositoryException, IOExcepti
mockRdfStream2);
when(mockNodes.getObject(isA(Session.class), isA(String.class)))
.thenReturn(mockObject);
final Request mockRequest = mock(Request.class);
final RdfStream rdfStream =
testObj.describe(createPathList(path), 0, -1, "", mockRequest, mockResponse,
mockUriInfo);
Expand All @@ -362,8 +361,6 @@ public void testSparqlUpdate() throws RepositoryException, IOException {
final InputStream mockStream =
new ByteArrayInputStream("my-sparql-statement".getBytes());
when(mockNodes.getObject(mockSession, path)).thenReturn(mockObject);
when(mockObject.updatePropertiesDataset(any(GraphSubjects.class), any(String.class)))
.thenReturn(mockDataset);
when(mockObject.getEtagValue()).thenReturn("");

when(mockObject.getLastModifiedDate()).thenReturn(Calendar.getInstance().getTime());
Expand All @@ -372,8 +369,8 @@ public void testSparqlUpdate() throws RepositoryException, IOException {
when(mockModel.isEmpty()).thenReturn(true);
testObj.updateSparql(createPathList(pid), getUriInfoImpl(), mockStream, mockRequest);

verify(mockObject).updatePropertiesDataset(any(GraphSubjects.class),
eq("my-sparql-statement"));
verify(mockObject).updateProperties(any(GraphSubjects.class),
any(PropertiesUpdateTactic.class));
verify(mockSession).save();
verify(mockSession).logout();
}
Expand All @@ -392,7 +389,7 @@ public void testReplaceRdf() throws IllegalArgumentException, Exception {
when(mockNodes.getObject(mockSession, path)).thenReturn(mockObject);

testObj.createOrReplaceObjectRdf(createPathList(pid), getUriInfoImpl(), MediaType.valueOf("application/n3"), mockStream, mockRequest);
verify(mockObject).replaceProperties(any(GraphSubjects.class), any(Model.class));
verify(mockObject).updateProperties(any(GraphSubjects.class), any(PropertiesUpdateTactic.class));
}

@Test
Expand Down

0 comments on commit 38d1b55

Please sign in to comment.