Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from futures/PidMinter
Pid minter
- Loading branch information
Showing
8 changed files
with
136 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
src/main/java/org/fcrepo/ffmodeshapeprototype/FedoraIdentifiers.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(pidMinter.mintPid()); | ||
} | ||
return Response | ||
.ok() | ||
.entity(renderTemplate("nextPid.ftl", | ||
ImmutableMap.of("pids", (Object) b.build()))).build(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
src/main/java/org/fcrepo/ffmodeshapeprototype/identifiers/PidMinter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package org.fcrepo.ffmodeshapeprototype.identifiers; | ||
|
||
public interface PidMinter { | ||
|
||
public String mintPid() ; | ||
|
||
} |
10 changes: 10 additions & 0 deletions
10
src/main/java/org/fcrepo/ffmodeshapeprototype/identifiers/UUIDPidMinter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package org.fcrepo.ffmodeshapeprototype.identifiers; | ||
|
||
public class UUIDPidMinter implements PidMinter { | ||
|
||
@Override | ||
public String mintPid() { | ||
return java.util.UUID.randomUUID().toString(); | ||
} | ||
|
||
} |
49 changes: 49 additions & 0 deletions
49
src/test/java/org/fcrepo/ffmodeshapeprototype/FedoraIdentifiersTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |