Skip to content

Commit

Permalink
Remove dependency from kernel-api on fcrepo-mint
Browse files Browse the repository at this point in the history
- Add UniqueValueSupplier

Resolves: https://jira.duraspace.org/browse/FCREPO-1642
  • Loading branch information
acoburn authored and Andrew Woods committed Aug 6, 2015
1 parent 4dcab75 commit f7daf30
Show file tree
Hide file tree
Showing 9 changed files with 97 additions and 27 deletions.
7 changes: 0 additions & 7 deletions fcrepo-kernel-api/pom.xml
Expand Up @@ -13,8 +13,6 @@

<properties>
<osgi.import.packages>
org.fcrepo.mint,

javax.jcr.*,

com.google.common.*,
Expand Down Expand Up @@ -51,11 +49,6 @@
</dependencyManagement>

<dependencies>
<dependency>
<groupId>org.fcrepo</groupId>
<artifactId>fcrepo-mint</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
Expand Down
Expand Up @@ -27,14 +27,14 @@
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.function.Supplier;

import javax.jcr.RepositoryException;
import javax.jcr.observation.Event;

import org.fcrepo.kernel.api.exception.RepositoryRuntimeException;
import org.fcrepo.kernel.api.services.functions.HierarchicalIdentifierSupplier;
import org.fcrepo.kernel.api.services.functions.UniqueValueSupplier;
import org.fcrepo.kernel.api.utils.EventType;
import org.fcrepo.mint.UUIDPathMinter;

import com.google.common.base.Function;
import com.google.common.base.Joiner;
Expand All @@ -55,7 +55,7 @@ public class FedoraEvent {
private Set<Integer> eventTypes = new HashSet<>();
private Set<String> eventProperties = new HashSet<>();

private static final Supplier<String> pidMinter = new UUIDPathMinter();
private static final UniqueValueSupplier pidMinter = new DefaultPathMinter();

/**
* Wrap a JCR Event with our FedoraEvent decorators
Expand Down Expand Up @@ -202,4 +202,6 @@ public String apply(final Integer type) {
Joiner.on(',').join(eventProperties)).add("Path:", getPath()).add("Date: ",
getDate()).add("Info:", getInfo()).toString();
}

private static class DefaultPathMinter implements HierarchicalIdentifierSupplier { }
}
@@ -0,0 +1,49 @@
/**
* Copyright 2015 DuraSpace, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.fcrepo.kernel.api.services.functions;

import static java.util.UUID.randomUUID;

import java.util.stream.IntStream;
import java.util.StringJoiner;

/**
* Unique value minter that creates hierarchical IDs from a UUID
*
* @author awoods
* @author acoburn
*/
public interface HierarchicalIdentifierSupplier extends UniqueValueSupplier {

static final int DEFAULT_LENGTH = 2;
static final int DEFAULT_COUNT = 4;

/**
* Mint a unique identifier as a UUID
*
* @return uuid
*/
default public String get() {

final String s = randomUUID().toString();
final StringJoiner joiner = new StringJoiner("/", "", "/" + s);

IntStream.rangeClosed(0, DEFAULT_COUNT - 1)
.forEach(x -> joiner.add(s.substring(x * DEFAULT_LENGTH, (x + 1) * DEFAULT_LENGTH)));

return joiner.toString();
}
}
@@ -0,0 +1,27 @@
/**
* Copyright 2015 DuraSpace, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.fcrepo.kernel.api.services.functions;

import java.util.function.Supplier;

/**
* A {@link java.util.function.Supplier} interface that guarantees the uniqueness of its provided values.
*
* @author acoburn
*/
public interface UniqueValueSupplier extends Supplier<String> {

}
6 changes: 0 additions & 6 deletions fcrepo-kernel-modeshape/pom.xml
Expand Up @@ -16,7 +16,6 @@
<properties>
<osgi.import.packages>
org.fcrepo.kernel.api.*,
org.fcrepo.mint,
org.fcrepo.metrics,

javax.jcr.*,
Expand Down Expand Up @@ -108,11 +107,6 @@
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
</dependency>
<dependency>
<groupId>org.fcrepo</groupId>
<artifactId>fcrepo-mint</artifactId>
<version>${project.version}</version>
</dependency>

<!-- test gear -->
<dependency>
Expand Down
Expand Up @@ -35,7 +35,6 @@

import java.util.HashMap;
import java.util.Map;
import java.util.function.Supplier;

import javax.jcr.Node;
import javax.jcr.PathNotFoundException;
Expand All @@ -59,9 +58,10 @@
import org.fcrepo.kernel.api.exception.RepositoryRuntimeException;
import org.fcrepo.kernel.api.exception.ServerManagedPropertyException;
import org.fcrepo.kernel.api.identifiers.IdentifierConverter;
import org.fcrepo.kernel.api.services.functions.HierarchicalIdentifierSupplier;
import org.fcrepo.kernel.api.services.functions.UniqueValueSupplier;
import org.fcrepo.kernel.modeshape.rdf.converters.ValueConverter;
import org.fcrepo.kernel.modeshape.utils.NodePropertiesTools;
import org.fcrepo.mint.UUIDPathMinter;

import org.modeshape.jcr.api.JcrTools;
import org.slf4j.Logger;
Expand Down Expand Up @@ -108,7 +108,7 @@ public class JcrRdfTools {

private static final Model m = createDefaultModel();

private static final Supplier<String> pidMinter = new UUIDPathMinter();
private static final UniqueValueSupplier pidMinter = new DefaultPathMinter();

/**
* Constructor with even more context.
Expand Down Expand Up @@ -433,4 +433,6 @@ private static String skolemizedPrefix() {
return "/.well-known/genid/";
}

private static class DefaultPathMinter implements HierarchicalIdentifierSupplier { }

}
7 changes: 7 additions & 0 deletions fcrepo-mint/pom.xml
Expand Up @@ -13,6 +13,7 @@
<properties>
<osgi.import.packages>
org.fcrepo.metrics,
org.fcrepo.kernel.api.*,

javax.xml.*,

Expand All @@ -31,6 +32,12 @@
</properties>

<dependencies>
<dependency>
<groupId>org.fcrepo</groupId>
<artifactId>fcrepo-kernel-api</artifactId>
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>org.fcrepo</groupId>
<artifactId>fcrepo-metrics</artifactId>
Expand Down
4 changes: 2 additions & 2 deletions fcrepo-mint/src/main/java/org/fcrepo/mint/HttpPidMinter.java
Expand Up @@ -24,7 +24,6 @@
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.net.URI;
import java.util.function.Supplier;

import org.w3c.dom.Document;

Expand All @@ -49,6 +48,7 @@
import org.apache.http.auth.UsernamePasswordCredentials;
import org.apache.http.client.CredentialsProvider;
import org.apache.http.impl.client.BasicCredentialsProvider;
import org.fcrepo.kernel.api.services.functions.UniqueValueSupplier;
import org.xml.sax.SAXException;


Expand All @@ -58,7 +58,7 @@
* @author escowles
* @since 04/28/2014
*/
public class HttpPidMinter implements Supplier<String> {
public class HttpPidMinter implements UniqueValueSupplier {

private static final DocumentBuilderFactory DOCUMENT_BUILDER_FACTORY = DocumentBuilderFactory.newInstance();
private static final Logger LOGGER = getLogger(HttpPidMinter.class);
Expand Down
8 changes: 2 additions & 6 deletions fcrepo-mint/src/main/java/org/fcrepo/mint/UUIDPathMinter.java
Expand Up @@ -18,11 +18,11 @@
import static com.codahale.metrics.MetricRegistry.name;
import static java.util.UUID.randomUUID;

import java.util.function.Supplier;
import java.util.stream.IntStream;
import java.util.StringJoiner;

import org.fcrepo.metrics.RegistryService;
import org.fcrepo.kernel.api.services.functions.HierarchicalIdentifierSupplier;

import com.codahale.metrics.Timer;

Expand All @@ -31,15 +31,11 @@
*
* @author awoods
*/
public class UUIDPathMinter implements Supplier<String> {
public class UUIDPathMinter implements HierarchicalIdentifierSupplier {

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

private static final int DEFAULT_LENGTH = 2;

private static final int DEFAULT_COUNT = 4;

private final int length;

private final int count;
Expand Down

0 comments on commit f7daf30

Please sign in to comment.