Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add UUIDPathMinter (and wire it into webapp by default) that prefixes…
… a generated uuid with some branch nodes to help manage level width
- Loading branch information
Showing
3 changed files
with
74 additions
and
1 deletion.
There are no files selected for viewing
37 changes: 37 additions & 0 deletions
37
fcrepo-kernel/src/main/java/org/fcrepo/identifiers/UUIDPathMinter.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,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(); | ||
} | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
fcrepo-kernel/src/test/java/org/fcrepo/identifiers/UUIDPathMinterTest.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,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()); | ||
|
||
} | ||
} |
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