Skip to content

Commit

Permalink
Add UUIDPathMinter (and wire it into webapp by default) that prefixes…
Browse files Browse the repository at this point in the history
… a generated uuid with some branch nodes to help manage level width
  • Loading branch information
cbeer committed Jun 25, 2013
1 parent f635e17 commit dfd898c
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 1 deletion.
@@ -0,0 +1,37 @@
package org.fcrepo.identifiers;

import com.codahale.metrics.Timer;
import com.google.common.base.Joiner;
import com.google.common.base.Splitter;

import static com.codahale.metrics.MetricRegistry.name;
import static java.util.UUID.randomUUID;
import static org.fcrepo.metrics.RegistryService.getMetrics;

/**
* PID minter that creates hierarchical IDs for a UUID
*/
public class UUIDPathMinter extends BasePidMinter {

static final Timer timer = getMetrics().timer(name(UUIDPathMinter.class, "mint"));


/**
* Mint a unique identifier as a UUID
* @return
*/
@Override
public String mintPid() {

final Timer.Context context = timer.time();

try {
final String s = randomUUID().toString();
final Iterable<String> split = Splitter.fixedLength(2).split(s.substring(0, 8));

return Joiner.on("/").join(split) + "/" + s;
} finally {
context.stop();
}
}
}
@@ -0,0 +1,36 @@
/**
* The contents of this file are subject to the license and copyright terms
* detailed in the license directory at the root of the source tree (also
* available online at http://fedora-commons.org/license/).
*/

package org.fcrepo.identifiers;

import org.junit.Test;

import static java.util.regex.Pattern.compile;
import static org.junit.Assert.assertTrue;

/**
* @todo Add Documentation.
* @author Chris Beer
* @date Mar 14, 2013
*/
public class UUIDPathMinterTest {

/**
* @todo Add Documentation.
*/
@Test
public void testMintPid() throws Exception {

final PidMinter pidMinter = new UUIDPathMinter();

final String pid = pidMinter.mintPid();

assertTrue("PID wasn't a UUID path", compile(
"[a-f0-9]{3}/[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}")
.matcher(pid).find());

}
}
2 changes: 1 addition & 1 deletion fcrepo-webapp/src/main/resources/spring/rest.xml
Expand Up @@ -13,7 +13,7 @@
<context:annotation-config/>

<!-- Mints PIDs-->
<bean class="org.fcrepo.identifiers.UUIDPidMinter"/>
<bean class="org.fcrepo.identifiers.UUIDPathMinter"/>
<bean class="org.fcrepo.session.SessionFactory"/>

<context:component-scan base-package="org.fcrepo.services, org.modeshape.web.jcr.rest, org.fcrepo.api, org.fcrepo.serialization, org.fcrepo.responses, org.fcrepo.exceptionhandlers, org.fcrepo.audit, org.fcrepo.url"/>
Expand Down

0 comments on commit dfd898c

Please sign in to comment.