Skip to content

Commit

Permalink
Broke pid minting out into a separate interface with default UUID-bas…
Browse files Browse the repository at this point in the history
…ed implementation
  • Loading branch information
ajs6f committed Jan 20, 2013
1 parent a85eaa2 commit 980cda9
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 31 deletions.
Expand Up @@ -16,6 +16,8 @@
import javax.ws.rs.core.Response;

import org.codehaus.jackson.map.ObjectMapper;
import org.fcrepo.ffmodeshapeprototype.identifiers.PidMinter;
import org.fcrepo.ffmodeshapeprototype.identifiers.UUIDPidMinter;
import org.infinispan.schematic.document.ParsingException;
import org.modeshape.common.SystemFailureException;
import org.modeshape.common.collection.Problems;
Expand All @@ -41,6 +43,8 @@ public abstract class AbstractResource {

static protected Configuration freemarker = null;
static protected Workspace ws = null;

protected static PidMinter pidMinter = new UUIDPidMinter();;

public AbstractResource() throws ConfigurationException,
RepositoryException, IOException {
Expand Down Expand Up @@ -125,7 +129,5 @@ protected InputStream renderTemplate(final String templatename,
return in;
}

protected String mintPid() {
return java.util.UUID.randomUUID().toString();
}

}
Expand Up @@ -26,20 +26,20 @@ public FedoraIdentifiers() throws ConfigurationException,
super();
}

@POST
@Path("/nextPID")
@Produces("text/xml")
public Response getNextPid(@QueryParam("numPids") @DefaultValue("1") Integer numPids) throws RepositoryException,
IOException, TemplateException {

ImmutableSet.Builder<String> b = new Builder<String>();
for(int i = 0; i < numPids; i++) {
b.add(mintPid());
}
return Response
.ok()
.entity(renderTemplate("nextPid.ftl",
ImmutableMap.of("pids", (Object) b.build())))
.build();
}
@POST
@Path("/nextPID")
@Produces("text/xml")
public Response getNextPid(
@QueryParam("numPids") @DefaultValue("1") Integer numPids)
throws RepositoryException, IOException, TemplateException {

ImmutableSet.Builder<String> b = new Builder<String>();
for (int i = 0; i < numPids; i++) {
b.add(pidMinter.mintPid());
}
return Response
.ok()
.entity(renderTemplate("nextPid.ftl",
ImmutableMap.of("pids", (Object) b.build()))).build();
}
}
19 changes: 7 additions & 12 deletions src/main/java/org/fcrepo/ffmodeshapeprototype/FedoraObjects.java
Expand Up @@ -32,14 +32,12 @@ public FedoraObjects() throws ConfigurationException, RepositoryException,
IOException {
super();
}
@POST
@Path("/new")
public Response ingestAndMint()
throws RepositoryException {
final String pid = mintPid();

return ingest(pid);
}
@POST
@Path("/new")
public Response ingestAndMint() throws RepositoryException {
return ingest(pidMinter.mintPid());
}

@POST
@Path("/{pid}")
Expand All @@ -51,9 +49,9 @@ public Response ingest(@PathParam("pid") final String pid)
if (session.hasPermission("/" + pid, "add_node")) {
final Node obj = root.addNode(pid, "fedora:object");
obj.addMixin("fedora:owned");
obj.addMixin("fedora:created");
obj.addMixin("fedora:created");
obj.setProperty("fedora:ownerId", "Fedo Radmin");
obj.setProperty("jcr:lastModified", Calendar.getInstance());
obj.setProperty("jcr:lastModified", Calendar.getInstance());
session.save();
return Response.status(Response.Status.CREATED).entity(pid).build();
} else {
Expand Down Expand Up @@ -86,8 +84,5 @@ public Response deleteObject(@PathParam("pid") final String pid)
throws RepositoryException {
return deleteResource(pid);
}




}
@@ -0,0 +1,7 @@
package org.fcrepo.ffmodeshapeprototype.identifiers;

public interface PidMinter {

public String mintPid() ;

}
@@ -0,0 +1,10 @@
package org.fcrepo.ffmodeshapeprototype.identifiers;

public class UUIDPidMinter implements PidMinter {

@Override
public String mintPid() {
return java.util.UUID.randomUUID().toString();
}

}

0 comments on commit 980cda9

Please sign in to comment.