Skip to content

Commit

Permalink
All endpoints save FedoraTransactions are injected, remains to add un…
Browse files Browse the repository at this point in the history
…it tests
  • Loading branch information
ajs6f committed Jun 12, 2013
1 parent 047aaf2 commit e86270f
Show file tree
Hide file tree
Showing 10 changed files with 186 additions and 105 deletions.
@@ -1,5 +1,9 @@

package org.fcrepo.api.repository;

import static javax.ws.rs.core.Response.status;
import static org.apache.http.HttpStatus.SC_BAD_REQUEST;
import static org.apache.http.HttpStatus.SC_NO_CONTENT;
import static org.slf4j.LoggerFactory.getLogger;

import java.io.IOException;
Expand All @@ -13,22 +17,27 @@
import javax.ws.rs.core.Response;

import org.apache.commons.io.IOUtils;
import org.apache.http.HttpStatus;
import org.apache.jena.riot.WebContent;
import org.fcrepo.AbstractResource;
import org.fcrepo.FedoraResource;
import org.fcrepo.session.InjectedSession;
import org.modeshape.common.collection.Problems;
import org.slf4j.Logger;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import com.codahale.metrics.annotation.Timed;

@Component
@Scope("prototype")
@Path("/fcr:properties")
public class FedoraRepositoriesProperties extends AbstractResource {

private static final Logger logger = getLogger(FedoraRepositoriesProperties.class);
@InjectedSession
protected Session session;

private static final Logger logger =
getLogger(FedoraRepositoriesProperties.class);

/**
* Update an object using SPARQL-UPDATE
Expand All @@ -40,31 +49,39 @@ public class FedoraRepositoriesProperties extends AbstractResource {
@POST
@Consumes({WebContent.contentTypeSPARQLUpdate})
@Timed
public Response updateSparql(final InputStream requestBodyStream) throws RepositoryException, IOException {

final Session session = getAuthenticatedSession();
public Response updateSparql(final InputStream requestBodyStream)
throws RepositoryException, IOException {

try {
if (requestBodyStream != null) {

if(requestBodyStream != null) {

final FedoraResource result = nodeService.getObject(session, "/");
final FedoraResource result =
nodeService.getObject(session, "/");

result.updatePropertiesDataset(IOUtils.toString(requestBodyStream));
Problems problems = result.getDatasetProblems();
result.updatePropertiesDataset(IOUtils
.toString(requestBodyStream));
final Problems problems = result.getDatasetProblems();
if (problems != null && problems.hasProblems()) {
logger.info("Found these problems updating the properties for {}: {}", "/", problems.toString());
return Response.status(Response.Status.FORBIDDEN).entity(problems.toString()).build();
logger.info(
"Found these problems updating the properties for {}: {}",
"/", problems.toString());
return status(Response.Status.FORBIDDEN).entity(
problems.toString()).build();
}

session.save();

return Response.status(HttpStatus.SC_NO_CONTENT).build();
return status(SC_NO_CONTENT).build();
} else {
return Response.status(HttpStatus.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();
}
}

public void setSession(final Session session) {
this.session = session;
}
}
@@ -1,11 +1,19 @@

package org.fcrepo.api.repository;

import javax.jcr.Session;
import javax.ws.rs.Path;

import org.fcrepo.api.FedoraIdentifiers;
import org.fcrepo.session.InjectedSession;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

@Component
@Scope("prototype")
@Path("/fcr:pid")
public class FedoraRepositoryIdentifiers extends FedoraIdentifiers {

@InjectedSession
protected Session session;
}
@@ -1,30 +1,19 @@
package org.fcrepo.api.repository;


import static javax.ws.rs.core.Response.created;
import static org.slf4j.LoggerFactory.getLogger;

import java.io.IOException;
import java.io.InputStream;
import java.util.Map;
package org.fcrepo.api.repository;

import javax.annotation.Resource;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
import javax.ws.rs.DefaultValue;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Response;

import org.fcrepo.AbstractResource;
import org.fcrepo.api.FedoraImport;
import org.fcrepo.exception.InvalidChecksumException;
import org.fcrepo.serialization.FedoraObjectSerializer;
import org.slf4j.Logger;
import org.fcrepo.session.InjectedSession;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

@Component
@Scope("prototype")
@Path("/fcr:import")
public class FedoraRepositoryImport extends FedoraImport {

@InjectedSession
protected Session session;

}
@@ -1,7 +1,10 @@

package org.fcrepo.api.repository;

import static com.hp.hpl.jena.update.UpdateAction.parseExecute;
import static javax.ws.rs.core.MediaType.TEXT_HTML;
import static javax.ws.rs.core.Response.status;
import static org.apache.http.HttpStatus.SC_NO_CONTENT;
import static org.apache.jena.riot.WebContent.contentTypeSPARQLUpdate;
import static org.fcrepo.http.RDFMediaType.N3;
import static org.fcrepo.http.RDFMediaType.N3_ALT1;
Expand All @@ -24,14 +27,14 @@
import javax.ws.rs.core.Response;

import org.apache.commons.io.IOUtils;
import org.apache.http.HttpStatus;
import org.fcrepo.AbstractResource;
import org.fcrepo.responses.HtmlTemplate;
import org.fcrepo.session.InjectedSession;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import com.codahale.metrics.annotation.Timed;
import com.hp.hpl.jena.query.Dataset;
import com.hp.hpl.jena.update.UpdateAction;

/**
* The purpose of this class is to allow clients to manipulate the JCR
Expand All @@ -44,30 +47,31 @@
*
*/
@Component
@Scope("prototype")
@Path("/fcr:namespaces")
public class FedoraRepositoryNamespaces extends AbstractResource {

@InjectedSession
protected Session session;

/**
* Register multiple object namespaces.
*
* @return 204
* @throws RepositoryException
*/
@POST
@Timed
@Timed
@Consumes({contentTypeSPARQLUpdate})
public Response updateNamespaces(final InputStream requestBodyStream)
throws RepositoryException, IOException {

final Session session = getAuthenticatedSession();
try {

final Dataset dataset = nodeService.getNamespaceRegistryGraph(session);

UpdateAction.parseExecute(IOUtils.toString(requestBodyStream), dataset);

final Dataset dataset =
nodeService.getNamespaceRegistryGraph(session);
parseExecute(IOUtils.toString(requestBodyStream), dataset);
session.save();

return Response.status(HttpStatus.SC_NO_CONTENT).build();
return status(SC_NO_CONTENT).build();
} finally {
session.logout();
}
Expand All @@ -79,22 +83,22 @@ public Response updateNamespaces(final InputStream requestBodyStream)
* @throws IOException
*/
@GET
@Timed
@Produces({N3, N3_ALT1, N3_ALT2, TURTLE, RDF_XML, RDF_JSON,
NTRIPLES, TEXT_HTML})
@Timed
@Produces({N3, N3_ALT1, N3_ALT2, TURTLE, RDF_XML, RDF_JSON, NTRIPLES,
TEXT_HTML})
@HtmlTemplate("jcr:namespaces")
public Dataset getNamespaces() throws RepositoryException,
IOException {
public Dataset getNamespaces() throws RepositoryException, IOException {

final Session session = getAuthenticatedSession();
try {

final Dataset dataset = nodeService.getNamespaceRegistryGraph(session);

final Dataset dataset =
nodeService.getNamespaceRegistryGraph(session);
return dataset;
} finally {
session.logout();
}
}

public void setSession(final Session session) {
this.session = session;
}
}
@@ -1,6 +1,9 @@

package org.fcrepo.api.repository;

import static javax.ws.rs.core.Response.created;
import static javax.ws.rs.core.Response.status;
import static org.apache.http.HttpStatus.SC_CONFLICT;
import static org.slf4j.LoggerFactory.getLogger;

import java.io.IOException;
Expand All @@ -18,52 +21,69 @@
import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriInfo;

import org.apache.http.HttpStatus;
import org.fcrepo.AbstractResource;
import org.fcrepo.FedoraResource;
import org.fcrepo.api.FedoraNodes;
import org.fcrepo.exception.InvalidChecksumException;
import org.fcrepo.session.InjectedSession;
import org.fcrepo.utils.FedoraJcrTypes;
import org.slf4j.Logger;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

@Component
@Scope("prototype")
@Path("/fcr:new")
public class FedoraRepositoryUnnamedObjects extends AbstractResource {

private static final Logger logger = getLogger(FedoraRepositoryUnnamedObjects.class);
@InjectedSession
protected Session session;

private static final Logger logger =
getLogger(FedoraRepositoryUnnamedObjects.class);

/**
* Create an anonymous object with a newly minted name
* @return 201
*/
@POST
public Response ingestAndMint(
@QueryParam("mixin") @DefaultValue(FedoraJcrTypes.FEDORA_OBJECT) String mixin,
@QueryParam("checksumType") final String checksumType,
@QueryParam("checksum") final String checksum,
@HeaderParam("Content-Type") final MediaType requestContentType,
final InputStream requestBodyStream, @Context UriInfo uriInfo) throws RepositoryException, IOException, InvalidChecksumException {
public Response ingestAndMint(@QueryParam("mixin")
@DefaultValue(FedoraJcrTypes.FEDORA_OBJECT)
final String mixin, @QueryParam("checksumType")
final String checksumType, @QueryParam("checksum")
final String checksum, @HeaderParam("Content-Type")
final MediaType requestContentType, final InputStream requestBodyStream,
@Context
final UriInfo uriInfo) throws RepositoryException, IOException,
InvalidChecksumException {
final String pid = pidMinter.mintPid();

String path = "/" + pid;

final String path = "/" + pid;
logger.debug("Attempting to ingest with path: {}", path);

final Session session = getAuthenticatedSession();

try {
if (nodeService.exists(session, path)) {
return Response.status(HttpStatus.SC_CONFLICT).entity(path + " is an existing resource").build();
return status(SC_CONFLICT).entity(
path + " is an existing resource").build();
}

final FedoraResource resource = createObjectOrDatastreamFromRequestContent(FedoraNodes.class, session, path, mixin, uriInfo, requestBodyStream, requestContentType, checksumType, checksum);
final FedoraResource resource =
createObjectOrDatastreamFromRequestContent(
FedoraNodes.class, session, path, mixin, uriInfo,
requestBodyStream, requestContentType,
checksumType, checksum);

session.save();
logger.debug("Finished creating {} with path: {}", mixin, path);
return created(uriInfo.getBaseUriBuilder().path(FedoraNodes.class).build(resource.getPath().substring(1))).entity(path).build();
return created(
uriInfo.getBaseUriBuilder().path(FedoraNodes.class).build(
resource.getPath().substring(1))).entity(path)
.build();
} finally {
session.logout();
}
}

public void setSession(final Session session) {
this.session = session;
}
}

0 comments on commit e86270f

Please sign in to comment.