Commit 8267e5bd authored by acoburn's avatar acoburn
Browse files

use a fcrepo-based interface for minting

parent 4b686a78
......@@ -26,7 +26,7 @@
<version>1.0.0-SNAPSHOT</version>
</parent>
<artifactId>acrepo-idmapper-pgsql</artifactId>
<artifactId>acrepo-idiomatic-pgsql</artifactId>
<packaging>bundle</packaging>
<name>Postgresql Dataservice Bundle</name>
......
......@@ -26,7 +26,7 @@
<version>1.0.0-SNAPSHOT</version>
</parent>
<artifactId>acrepo-idmapper</artifactId>
<artifactId>acrepo-ideomatic</artifactId>
<packaging>bundle</packaging>
<name>ID mapping service</name>
......@@ -46,7 +46,8 @@
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-jetty</artifactId>
<artifactId>camel-restlet</artifactId>
<version>${camel.version}</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
......@@ -89,7 +90,13 @@
<!-- testing -->
<dependency>
<groupId>edu.amherst.acdc</groupId>
<artifactId>acrepo-idmapper-pgsql</artifactId>
<artifactId>acrepo-idiomatic-pgsql</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>edu.amherst.acdc</groupId>
<artifactId>acrepo-mint-service</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
......
......@@ -11,7 +11,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package edu.amherst.acdc.idmapper;
package edu.amherst.acdc.idiomatic;
import org.apache.camel.LoggingLevel;
import org.apache.camel.PropertyInject;
......@@ -57,17 +57,6 @@ public class EventRouter extends RouteBuilder {
.maximumRedeliveries("{{error.maxRedeliveries}}")
.log("Event Routing Error: ${routeId}");
restConfiguration().component("jetty").port(
System.getProperty("acdc.ext.idmapper.port", port));
/**
* REST configuration
*/
rest("{{rest.prefix}}")
.get("{id}").to("direct:get")
.put("{id}").to("direct:update")
.delete("{id}").to("direct:delete");
/**
* Process a message via JMS
*/
......
......@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package edu.amherst.acdc.idmapper;
package edu.amherst.acdc.idiomatic;
import static org.fcrepo.camel.JmsHeaders.IDENTIFIER;
......
......@@ -22,6 +22,10 @@
<reference id="dataSource" interface="javax.sql.DataSource" filter="(osgi.jndi.service.name=idmapperds)"/>
<reference id="minterService"
interface="org.fcrepo.kernel.api.services.functions.UniqueValueSupplier"
filter="(osgi.jndi.service.name=minter)"/>
<!-- component-wide configuration of jdbc -->
<bean id="sql" class="org.apache.camel.component.sql.SqlComponent">
<property name="dataSource" ref="dataSource"/>
......@@ -32,7 +36,34 @@
</bean>
<camelContext xmlns="http://camel.apache.org/schema/blueprint">
<package>edu.amherst.acdc.idmapper</package>
<package>edu.amherst.acdc.idiomatic</package>
<restConfiguration bindingMode="auto" component="restlet"
contextPath="{{rest.prefix}}" port="{{rest.port}}"/>
<rest>
<post uri="/">
<to uri="direct:minter"/>
</post>
<get uri="/{id}">
<to uri="direct:get"/>
</get>
<put uri="/{id}">
<to uri="direct:update"/>
</put>
<delete uri="/{id}">
<to uri="direct:delete"/>
</delete>
</rest>
<route id="MinterRoute">
<description>Create a freshly minted ID</description>
<from uri="direct:minter"/>
<setBody>
<method ref="minterService" method="get"/>
</setBody>
</route>
</camelContext>
</blueprint>
......@@ -11,7 +11,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package edu.amherst.acdc.idmapper;
package edu.amherst.acdc.idiomatic;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import java.util.Dictionary;
import java.util.HashMap;
......@@ -29,6 +32,7 @@ import org.apache.camel.util.ObjectHelper;
import org.apache.commons.io.IOUtils;
import org.fcrepo.camel.JmsHeaders;
import org.postgresql.ds.PGPoolingDataSource;
import edu.amherst.acdc.mint.MinterService;
import org.junit.Test;
......@@ -71,6 +75,38 @@ public class RouteTest extends CamelBlueprintTestSupport {
@Override
protected void addServicesOnStartup(final Map<String, KeyValueHolder<Object, Dictionary>> services) {
services.put("dataSource", asService(new PGPoolingDataSource(), "name", "idmapperds"));
services.put("minterService", asService(new MinterService(7), "name", "minter"));
}
@Test
public void testMint() throws Exception {
context.getRouteDefinition("IdMappingRouter").adviceWith(context, new AdviceWithRouteBuilder() {
@Override
public void configure() throws Exception {
replaceFromWith("direct:start");
}
});
context.getRouteDefinition("MinterRoute").adviceWith(context, new AdviceWithRouteBuilder() {
@Override
public void configure() throws Exception {
weaveAddLast().to("mock:result");
}
});
context.start();
getMockEndpoint("mock:result").expectedMessageCount(2);
template.sendBody("direct:minter", null);
template.sendBody("direct:minter", null);
final String id1 = getMockEndpoint("mock:result").getExchanges().get(0).getIn().getBody(String.class);
final String id2 = getMockEndpoint("mock:result").getExchanges().get(1).getIn().getBody(String.class);
assertEquals(7, id1.length());
assertEquals(7, id2.length());
assertFalse(id1.equals(id2));
assertMockEndpointsSatisfied();
}
@Test
......
/**
* 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 edu.amherst.acdc.idmapper;
/**
* @author acoburn
*/
public final class IdMapperHeaders {
//public static final String EVENT_BASE_URI = "CamelAmherstIdMapperEventBaseUri";
//public static final String EVENT_URI = "CamelAuditEventUri";
private IdMapperHeaders() {
// prevent instantiation
}
}
......@@ -4,7 +4,7 @@
<repository>mvn:org.apache.camel.karaf/apache-camel/${camel.version}/xml/features</repository>
<repository>mvn:org.apache.activemq/activemq-karaf/${activemq.version}/xml/features</repository>
<feature name="acrepo-idmapper" version="${project.version}" resolver="(obr)" start-level="50">
<feature name="acrepo-idiomatic" version="${project.version}" resolver="(obr)" start-level="50">
<details>Installs the id mapping service</details>
<feature version="${camel.version}">camel</feature>
......@@ -14,12 +14,12 @@
<feature version="${camel.version}">camel-sql</feature>
<feature version="${fcrepo-camel.version}">fcrepo-camel</feature>
<bundle>mvn:edu.amherst.acdc/acrepo-idmapper/{project.version}</bundle>
<bundle>mvn:edu.amherst.acdc/acrepo-idiomatic/{project.version}</bundle>
<configfile finalname="/etc/edu.amherst.acdc.idmapper.cfg">mvn:edu.amherst.acdc/acrepo-idmapper/${project.version}/cfg/configuration</configfile>
<configfile finalname="/etc/edu.amherst.acdc.idiomatic.cfg">mvn:edu.amherst.acdc/acrepo-idiomatic/${project.version}/cfg/configuration</configfile>
</feature>
<feature name="acrepo-idmapper-pgsql" version="${project.version}" resolver="(obr)" start-level="50">
<feature name="acrepo-idiomatic-pgsql" version="${project.version}" resolver="(obr)" start-level="50">
<details>Installs the id mapping service database</details>
<feature>jdbc</feature>
......@@ -28,17 +28,17 @@
<bundle dependency="true">wrap:mvn:postgresql/postgresql/${postgresql.version}</bundle>
<bundle>mvn:edu.amherst.acdc/acrepo-idmapper-pgsql/{project.version}</bundle>
<bundle>mvn:edu.amherst.acdc/acrepo-idiomatic-pgsql/{project.version}</bundle>
<configfile finalname="/etc/edu.amherst.acdc.idmapper.pgsql.cfg">mvn:edu.amherst.acdc/acrepo-idmapper-pgsql/${project.version}/cfg/configuration</configfile>
<configfile finalname="/etc/edu.amherst.acdc.idiomatic.pgsql.cfg">mvn:edu.amherst.acdc/acrepo-idiomatic-pgsql/${project.version}/cfg/configuration</configfile>
</feature>
<feature name="acrepo-mint" version="${project.version}" resolver="(obr)" start-level="50">
<feature name="acrepo-mint-service" version="${project.version}" resolver="(obr)" start-level="50">
<details>Installs the id minter</details>
<bundle>mvn:edu.amherst.acdc/acrepo-mint/${project.version}</bundle>
<bundle>mvn:edu.amherst.acdc/acrepo-mint-service/${project.version}</bundle>
<configfile finalname="/etc/edu.amherst.acdc.mint.cfg">mvn:edu.amherst.acdc/acrepo-mint/${project.version}/cfg/configuration</configfile>
<configfile finalname="/etc/edu.amherst.acdc.mint.cfg">mvn:edu.amherst.acdc/acrepo-mint-service/${project.version}/cfg/configuration</configfile>
</feature>
</features>
......@@ -26,14 +26,14 @@
<version>1.0.0-SNAPSHOT</version>
</parent>
<artifactId>acrepo-mint</artifactId>
<artifactId>acrepo-mint-service</artifactId>
<packaging>bundle</packaging>
<name>repo-id-minter Blueprint Bundle</name>
<description>repo-id-minter OSGi blueprint bundle project.</description>
<name>Id Minter Blueprint Bundle</name>
<description>Repository Id Minter OSGi blueprint bundle project.</description>
<properties>
<osgi.export.packages>edu.amhers.acdc.mint</osgi.export.packages>
<osgi.export.packages>edu.amherst.acdc.mint*;version=${project.version}</osgi.export.packages>
</properties>
<dependencies>
......@@ -41,6 +41,14 @@
<groupId>org.apache.camel</groupId>
<artifactId>camel-core</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-blueprint</artifactId>
</dependency>
<dependency>
<groupId>org.fcrepo</groupId>
<artifactId>fcrepo-kernel-api</artifactId>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
......
......@@ -19,21 +19,22 @@ package edu.amherst.acdc.mint;
import static org.apache.commons.lang3.RandomStringUtils.randomAlphanumeric;
import org.apache.camel.Handler;
import org.fcrepo.kernel.api.services.functions.UniqueValueSupplier;
/**
* @author acoburn
* @since 9/14/15
*/
public class MinterServiceImpl implements MinterService {
public class MinterService implements UniqueValueSupplier {
private final int length;
private int length;
/**
* Minter Service Constructor
*
* Set the minter length property
*
* @param length the length of the ID
*/
public MinterServiceImpl(final int length) {
public MinterService(final int length) {
this.length = length;
}
......@@ -43,7 +44,7 @@ public class MinterServiceImpl implements MinterService {
* @return the new ID
*/
@Handler
public String mint() {
public String get() {
return randomAlphanumeric(length).toLowerCase();
}
......
......@@ -26,13 +26,19 @@
<cm:property-placeholder persistent-id="edu.amherst.acdc.mint" update-strategy="reload" >
<cm:default-properties>
<cm:property name="minter.length" value="7"/>
<cm:property name="rest.prefix" value="/mint"/>
<cm:property name="rest.port" value="9030"/>
</cm:default-properties>
</cm:property-placeholder>
<bean id="minterServiceBean" class="edu.amherst.acdc.mint.MinterServiceImpl">
<property name="length" value="${minter.length}"/>
<bean id="minterServiceBean" class="edu.amherst.acdc.mint.MinterService">
<argument value="${minter.length}"/>
</bean>
<service ref="minterServiceBean" interface="edu.amherst.acdc.mint.MinterService"/>
<service ref="minterServiceBean" interface="org.fcrepo.kernel.api.services.functions.UniqueValueSupplier">
<service-properties>
<entry key="osgi.jndi.service.name" value="minter"/>
</service-properties>
</service>
</blueprint>
......@@ -32,9 +32,9 @@ public class MinterServiceTest {
@Test
public void testMintId() {
final String id7 = new MinterServiceImpl(7).mint();
final String id8 = new MinterServiceImpl(8).mint();
final String id9 = new MinterServiceImpl(9).mint();
final String id7 = new MinterService(7).get();
final String id8 = new MinterService(8).get();
final String id9 = new MinterService(9).get();
assertEquals(7, id7.length());
assertTrue(compile(ID_PATTERN).matcher(id7).find());
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment