Skip to content

Commit

Permalink
Added UUID-based PidGeneration and created new FedoraIdentifiers reso…
Browse files Browse the repository at this point in the history
…urce class
  • Loading branch information
ajs6f committed Jan 20, 2013
1 parent e48993c commit a85eaa2
Show file tree
Hide file tree
Showing 6 changed files with 109 additions and 26 deletions.
Expand Up @@ -39,7 +39,6 @@ public abstract class AbstractResource {

private final Logger logger = Logger.getLogger(AbstractResource.class);

static protected int pid_index = 0;
static protected Configuration freemarker = null;
static protected Workspace ws = null;

Expand Down Expand Up @@ -127,7 +126,6 @@ protected InputStream renderTemplate(final String templatename,
}

protected String mintPid() {
pid_index += 1;
return "assigned_pid_" + pid_index;
return java.util.UUID.randomUUID().toString();
}
}
@@ -0,0 +1,45 @@
package org.fcrepo.ffmodeshapeprototype;

import java.io.IOException;

import javax.jcr.RepositoryException;
import javax.ws.rs.DefaultValue;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Response;

import org.modeshape.jcr.ConfigurationException;

import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.ImmutableSet.Builder;

import freemarker.template.TemplateException;

@Path("/")
public class FedoraIdentifiers extends AbstractResource {

public FedoraIdentifiers() throws ConfigurationException,
RepositoryException, IOException {
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();
}
}
17 changes: 1 addition & 16 deletions src/main/java/org/fcrepo/ffmodeshapeprototype/FedoraObjects.java
Expand Up @@ -88,21 +88,6 @@ public Response deleteObject(@PathParam("pid") final String pid)
}


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

ImmutableSet.Builder<String> b = new ImmutableSet.Builder<String>();
for(int i = 0; i < Integer.parseInt(numPids); i++) {
b.add(mintPid());
}
return Response
.ok()
.entity(renderTemplate("nextPid.ftl",
ImmutableMap.of("pids", (Object) b.build())))
.build();
}


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

import static junit.framework.Assert.assertEquals;

import javax.servlet.http.HttpServletResponse;

import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.methods.PostMethod;
import org.jboss.resteasy.plugins.server.tjws.TJWSEmbeddedJaxrsServer;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

/**
* Created with IntelliJ IDEA. User: cabeer Date: 1/17/13 Time: 14:11 To change
* this template use File | Settings | File Templates.
*/
public class FedoraIdentifiersTest {

private TJWSEmbeddedJaxrsServer server;
int SERVER_PORT = 9999;

@Before
public void start() {

server = new TJWSEmbeddedJaxrsServer();
server.setPort(SERVER_PORT);
server.getDeployment().getActualResourceClasses()
.add(FedoraIdentifiers.class);
server.start();
}

@After
public void stop() {
server.stop();
}

@Test
public void testGetNextPid() throws Exception {
HttpClient client = new HttpClient();
PostMethod method = new PostMethod("http://localhost:" + SERVER_PORT
+ "/nextPID");
method.addRequestHeader("Accepts", "text/xml");
int status = client.executeMethod(method);
System.out.println("Executed testGetNextPid()");
System.out.println(method.getResponseBodyAsString());
assertEquals(HttpServletResponse.SC_OK, status);
}
}
Expand Up @@ -67,11 +67,4 @@ public void testDeleteObject() throws Exception {
assertEquals(204, status);
}

@Test
public void testGetNextPid() throws Exception {
HttpClient client = new HttpClient();
PostMethod method = new PostMethod("http://localhost:" + SERVER_PORT + "/objects/nextPID");
int status = client.executeMethod(method);
assertEquals(200, status);
}
}
13 changes: 13 additions & 0 deletions src/test/resources/log4j.properties
@@ -0,0 +1,13 @@

# This is not needed by Jetty - but it helps with many web apps.

log4j.rootLogger=INFO, stdout

log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n

# Set up the default logging to be INFO level, then override specific units
log4j.logger.org.infinispan=DEBUG
log4j.logger.org.modeshape=DEBUG
log4j.logger.org.fcrepo=DEBUG

0 comments on commit a85eaa2

Please sign in to comment.