Navigation Menu

Skip to content

Commit

Permalink
convert transactions to the RESTful, globbing API style
Browse files Browse the repository at this point in the history
  • Loading branch information
cbeer committed Jun 21, 2013
1 parent 4d5ddd1 commit b290b5e
Show file tree
Hide file tree
Showing 10 changed files with 223 additions and 214 deletions.
Expand Up @@ -3,6 +3,9 @@
import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
import static javax.ws.rs.core.MediaType.TEXT_PLAIN;
import static javax.ws.rs.core.MediaType.TEXT_XML;
import static javax.ws.rs.core.Response.created;
import static javax.ws.rs.core.Response.noContent;
import static javax.ws.rs.core.Response.ok;

import java.util.List;

Expand All @@ -16,8 +19,10 @@
import javax.ws.rs.core.PathSegment;
import javax.ws.rs.core.Response;

import com.google.common.collect.ImmutableMap;
import org.fcrepo.AbstractResource;
import org.fcrepo.Transaction;
import org.fcrepo.TxSession;
import org.fcrepo.services.TransactionService;
import org.fcrepo.session.InjectedSession;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -26,7 +31,7 @@

@Component
@Scope("prototype")
@Path("/fcr:tx")
@Path("/{path: .*}/fcr:tx")
public class FedoraTransactions extends AbstractResource {

@Autowired
Expand All @@ -36,49 +41,64 @@ public class FedoraTransactions extends AbstractResource {
protected Session session;

@POST
@Produces({ APPLICATION_JSON, TEXT_XML })
public Transaction createTransaction() throws RepositoryException {
return txService.beginTransaction(session);
}
public Response createTransaction(@PathParam("path")
final List<PathSegment> pathList) throws RepositoryException {

@GET
@Path("/{txid}")
public Transaction getTransaction(@PathParam("txid")
final String txid) throws RepositoryException {
return txService.getTransaction(txid);
}
if (!pathList.isEmpty()) {
return Response.status(Response.Status.BAD_REQUEST).build();
}

@POST
@Path("/{txid}/fcr:commit")
@Produces({APPLICATION_JSON, TEXT_XML})
public Transaction commit(@PathParam("txid")
final String txid) throws RepositoryException {
return txService.commit(txid);
if (session instanceof TxSession) {
Transaction t = txService.getTransaction(((TxSession) session).getTxId());
t.updateExpiryDate();
return noContent().expires(t.getExpires()).build();

} else {
Transaction t = txService.beginTransaction(session);
return created(uriInfo.getBaseUriBuilder().path(FedoraNodes.class).buildFromMap(ImmutableMap.of("path", "tx:" + t.getId()))).expires(t.getExpires()).build();
}
}

@POST
@Path("/{txid}/fcr:rollback")
@Produces({APPLICATION_JSON, TEXT_XML})
public Transaction rollback(@PathParam("txid")
final String txid) throws RepositoryException {
return txService.rollback(txid);
@Path("fcr:commit")
public Response commit(@PathParam("path")
final List<PathSegment> pathList) throws RepositoryException {

final String path = toPath(pathList);

if (!path.equals("/")) {
return Response.status(Response.Status.BAD_REQUEST).build();
}

if (session instanceof TxSession) {
txService.commit(((TxSession) session).getTxId());
return noContent().build();

} else {
return Response.status(Response.Status.BAD_REQUEST).build();
}

}

@POST
@Path("/{txid}/{path: .*}/fcr:newhack")
@Produces({TEXT_PLAIN})
public Response createObjectInTransaction(@PathParam("txid")
final String txid, @PathParam("path")
final List<PathSegment> pathlist) throws RepositoryException {
final Transaction tx = txService.getTransaction(txid);
if (tx == null) {
throw new RepositoryException("Transaction with id " + txid +
" is not available");
@Path("fcr:rollback")
public Response rollback(@PathParam("path")
final List<PathSegment> pathList) throws RepositoryException {

final String path = toPath(pathList);

if (!path.equals("/")) {
return Response.status(Response.Status.BAD_REQUEST).build();
}


if (session instanceof TxSession) {
txService.rollback(((TxSession) session).getTxId());
return noContent().build();

} else {
return Response.status(Response.Status.BAD_REQUEST).build();
}
final String path = toPath(pathlist);
objectService.createObject(tx.getSession(), path);
tx.updateExpiryDate();
return Response.ok(path).build();
}

}
@@ -0,0 +1,19 @@
package org.fcrepo.api.repository;

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

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


@Component
@Scope("prototype")
@Path("/fcr:tx")
public class FedoraRepositoryTransactions extends FedoraTransactions {

@InjectedSession
protected Session session;
}

0 comments on commit b290b5e

Please sign in to comment.