From 6220da6ac0d709995363fe5de25dc213fec26d00 Mon Sep 17 00:00:00 2001 From: Aron Roberts Date: Fri, 10 Aug 2012 17:55:33 -0700 Subject: [PATCH] CSPACE-5271: Added missing registry key class; updated comments; added convenience 'get' method to registry. --- .../CollectionSpaceJaxRsApplication.java | 6 +- .../services/common/UriTemplateRegistry.java | 12 +++ .../common/UriTemplateRegistryKey.java | 87 +++++++++++++++++++ 3 files changed, 102 insertions(+), 3 deletions(-) create mode 100644 services/common/src/main/java/org/collectionspace/services/common/UriTemplateRegistryKey.java diff --git a/services/JaxRsServiceProvider/src/main/java/org/collectionspace/services/jaxrs/CollectionSpaceJaxRsApplication.java b/services/JaxRsServiceProvider/src/main/java/org/collectionspace/services/jaxrs/CollectionSpaceJaxRsApplication.java index 313693ecd..5173917a4 100644 --- a/services/JaxRsServiceProvider/src/main/java/org/collectionspace/services/jaxrs/CollectionSpaceJaxRsApplication.java +++ b/services/JaxRsServiceProvider/src/main/java/org/collectionspace/services/jaxrs/CollectionSpaceJaxRsApplication.java @@ -149,10 +149,10 @@ public class CollectionSpaceJaxRsApplication extends Application /** * Build a registry of URI templates by querying each resource - * for its own entry in the registry. + * for its own entries in the registry. * - * That entry consists of a tenant-qualified map of URI templates, each - * associated with a specific document type + * These entries consist of one or more URI templates for + * building URIs for accessing that resource. */ private void buildUriTemplateRegistry() { ResourceBase resource = null; diff --git a/services/common/src/main/java/org/collectionspace/services/common/UriTemplateRegistry.java b/services/common/src/main/java/org/collectionspace/services/common/UriTemplateRegistry.java index 968554152..13129f019 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/UriTemplateRegistry.java +++ b/services/common/src/main/java/org/collectionspace/services/common/UriTemplateRegistry.java @@ -34,6 +34,18 @@ import org.collectionspace.services.common.UriTemplateFactory.UriTemplateType; * Maps document types to templates for building URIs, per tenant. */ public class UriTemplateRegistry extends HashMap> { + + /** + * Get a URI template by tenant, document type, and template type. + * + */ + public StoredValuesUriTemplate get(UriTemplateRegistryKey key, UriTemplateType type) { + if (get(key) != null) { + return get(key).get(type); + } else { + return null; + } + } /** * Dump all registry settings, For debugging purposes. diff --git a/services/common/src/main/java/org/collectionspace/services/common/UriTemplateRegistryKey.java b/services/common/src/main/java/org/collectionspace/services/common/UriTemplateRegistryKey.java new file mode 100644 index 000000000..d7d3a154c --- /dev/null +++ b/services/common/src/main/java/org/collectionspace/services/common/UriTemplateRegistryKey.java @@ -0,0 +1,87 @@ +package org.collectionspace.services.common; + +/** + * Defines a compound key consisting of the combination of a tenant ID and a + * Nuxeo document type (docType), for accessing entries in the + * UriTemplateRegistry. + */ +public class UriTemplateRegistryKey { + + private String tenantId; + private String docType; + + public void UriTemplateRegistryKey() { + } + + public void UriTemplateRegistryKey(String tenantId, String docType) { + this.tenantId = tenantId; + this.docType = docType; + } + + /** + * @return the tenantId + */ + public String getTenantId() { + return tenantId; + } + + /** + * @param tenantId the tenantId to set + */ + public void setTenantId(String tenantId) { + this.tenantId = tenantId; + } + + /** + * @return the docType + */ + public String getDocType() { + return docType; + } + + /** + * @param docType the docType to set + */ + public void setDocType(String docType) { + this.docType = docType; + } + + @Override + public boolean equals(Object o) { + + if (o == null) { + return false; + } + if (getClass() != o.getClass()) { + return false; + } + + if (o == this) { + return true; + } + + // Cast the compared-to object to an object of this type + UriTemplateRegistryKey key = (UriTemplateRegistryKey) o; + + // If either the tenant ID or docType values dont't match, whether + // only one is null, or via a failure of an 'equals' test of their + // values, return false + if (tenantId == null ? key.tenantId != null : !tenantId.equals(key.tenantId)) { + return false; + } + if (docType == null ? key.docType != null : !docType.equals(key.docType)) { + return false; + } + + return true; + + } + + @Override + public int hashCode() { + int hash = 3; + hash = 89 * hash + (this.tenantId != null ? this.tenantId.hashCode() : 0); + hash = 89 * hash + (this.docType != null ? this.docType.hashCode() : 0); + return hash; + } +} -- 2.47.3