From: Aron Roberts Date: Wed, 15 Aug 2012 02:18:12 +0000 (-0700) Subject: CSPACE-5271: Simplified design of URI-building registry to assume just one URI templa... X-Git-Url: https://git.aero2k.de/?a=commitdiff_plain;h=fa0c516f524153e7cfcc955bdc9305c7f90e80c3;p=tmp%2Fjakarta-migration.git CSPACE-5271: Simplified design of URI-building registry to assume just one URI template per document type. --- diff --git a/services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/AuthorityResource.java b/services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/AuthorityResource.java index e5b70c6fa..de9cf91d5 100644 --- a/services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/AuthorityResource.java +++ b/services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/AuthorityResource.java @@ -962,27 +962,24 @@ public abstract class AuthorityResource } protected String getItemDocType(String tenantId) { - return super.getDocType(tenantId, getItemServiceName()); + return getDocType(tenantId, getItemServiceName()); } - - /** - * Constructs and returns a map of URI templates for the current resource. - * This map assumes that there will be only one URI template of a given type - * ("resource", "item", etc.) for each resource. - * - * @return a map of URI templates for the current resource - */ + + /** + * Returns a UriRegistry entry: a map of tenant-qualified URI templates + * for the current resource, for all tenants + * + * @return a map of URI templates for the current resource, for all tenants + */ @Override - protected Map getUriTemplateMap() { - // Get the resource URI template from the superclass - Map uriTemplateMap = super.getUriTemplateMap(); - // Add the item URI template here, and return both templates in the map - StoredValuesUriTemplate itemUriTemplate = getUriTemplate(UriTemplateFactory.ITEM); - if (itemUriTemplate == null) { - return uriTemplateMap; // return map as obtained from superclass + public Map getUriRegistryEntries() { + Map uriRegistryEntriesMap = + super.getUriRegistryEntries(); + List tenantIds = getTenantBindingsReader().getTenantIds(); + for (String tenantId : tenantIds) { + uriRegistryEntriesMap.putAll(getUriRegistryEntries(tenantId, getItemDocType(tenantId), UriTemplateFactory.ITEM)); } - uriTemplateMap.put(itemUriTemplate.getUriTemplateType(), itemUriTemplate); - return uriTemplateMap; + return uriRegistryEntriesMap; } } diff --git a/services/common/src/main/java/org/collectionspace/services/common/ResourceBase.java b/services/common/src/main/java/org/collectionspace/services/common/ResourceBase.java index fb7d28f45..ef31879bb 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/ResourceBase.java +++ b/services/common/src/main/java/org/collectionspace/services/common/ResourceBase.java @@ -418,7 +418,7 @@ public abstract class ResourceBase protected String getDocType(String tenantId) { return getDocType(tenantId, getServiceName()); } - + /** * Returns the Nuxeo document type associated with a specified service, within a specified tenant. * @@ -438,6 +438,7 @@ public abstract class ResourceBase return docType; } docType = sb.getObject().getName(); // Reads the Nuxeo Document Type from tenant bindings configuration + System.out.println(tenantId + " : " + serviceName + " : " + docType); // FIXME: for debugging return docType; } @@ -447,40 +448,35 @@ public abstract class ResourceBase * * @return a map of URI templates for the current resource, for all tenants */ - public Map> getUriRegistryEntries() { - Map> uriRegistryEntriesMap = - new HashMap>(); - List tenantIds = getTenantIds(); - UriTemplateRegistryKey key; - String docType = ""; + public Map getUriRegistryEntries() { + Map uriRegistryEntriesMap = + new HashMap(); + List tenantIds = getTenantBindingsReader().getTenantIds(); for (String tenantId : tenantIds) { - docType = getDocType(tenantId); - if (Tools.notBlank(docType)) { - key = new UriTemplateRegistryKey(); - key.setTenantId(tenantId); - key.setDocType(docType); - uriRegistryEntriesMap.put(key, getUriTemplateMap()); - } + uriRegistryEntriesMap.putAll(getUriRegistryEntries(tenantId, getDocType(tenantId), UriTemplateFactory.RESOURCE)); } return uriRegistryEntriesMap; } - - /** - * Constructs and returns a map of URI templates for the current resource. - * This map assumes that there will be only one URI template of a given type - * ("reesource", "item", etc.) for each resource. - * - * @return a map of URI templates for the current resource - */ - protected Map getUriTemplateMap() { - Map uriTemplateMap = new HashMap(); - StoredValuesUriTemplate resourceUriTemplate = getUriTemplate(UriTemplateFactory.RESOURCE); - if (resourceUriTemplate == null) { - return uriTemplateMap; // return an empty map + /** + * Returns a UriRegistry entry: a map of tenant-qualified URI templates + * for the current resource, for a specified tenants + * + * @return a map of URI templates for the current resource, for a specified tenant + */ + protected Map getUriRegistryEntries(String tenantId, + String docType, UriTemplateFactory.UriTemplateType type) { + Map uriRegistryEntriesMap = + new HashMap(); + UriTemplateRegistryKey key; + if (Tools.isBlank(tenantId) || Tools.isBlank(docType)) { + return uriRegistryEntriesMap; } - uriTemplateMap.put(resourceUriTemplate.getUriTemplateType(), resourceUriTemplate); - return uriTemplateMap; + key = new UriTemplateRegistryKey(); + key.setTenantId(tenantId); + key.setDocType(docType); + uriRegistryEntriesMap.put(key, getUriTemplate(type)); + return uriRegistryEntriesMap; } /** @@ -498,30 +494,6 @@ public abstract class ResourceBase return template; } - /** - * Returns a list of tenant IDs, from tenant bindings configuration - * - * @return a list of tenant IDs - */ - // FIXME: This method may properly belong in a different services package or class. - // Also, we need to check for any existing methods that may duplicate this one. - protected List getTenantIds() { - List tenantIds = new ArrayList(); - String tenantId; - Hashtable tenantBindings = - getTenantBindingsReader().getTenantBindings(); - if (tenantBindings != null && !tenantBindings.isEmpty()) { - Enumeration keys = tenantBindings.keys(); - while (keys.hasMoreElements()) { - tenantId = (String) keys.nextElement(); - if (Tools.notBlank(tenantId)) { - tenantIds.add(tenantId); - } - } - } - return tenantIds; - } - /** * Returns a reader for reading values from tenant bindings configuration * 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 13129f019..b95e149b5 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 @@ -26,32 +26,19 @@ import java.util.HashMap; import java.util.Map; import java.util.Set; import org.collectionspace.services.common.UriTemplateRegistryKey; -import org.collectionspace.services.common.UriTemplateFactory.UriTemplateType; /** * UriTemplateRegistry.java * * 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; - } - } +public class UriTemplateRegistry extends HashMap { /** - * Dump all registry settings, For debugging purposes. + * Dumps all registry settings for debugging purposes. */ public void dump() { - for (Map.Entry> uriTemplateEntry : this.entrySet()) { + for (Map.Entry uriTemplateEntry : this.entrySet()) { System.out.println( "Tenant : DocType = " @@ -59,14 +46,8 @@ public class UriTemplateRegistry extends HashMap getTenantIds() { + List tenantIds = new ArrayList(); + String tenantId; + Hashtable tenantBindings = getTenantBindings(); + if (tenantBindings != null && !tenantBindings.isEmpty()) { + Enumeration keys = tenantBindings.keys(); + while (keys.hasMoreElements()) { + tenantId = (String) keys.nextElement(); + if (Tools.notBlank(tenantId)) { + tenantIds.add(tenantId); + } + } + } + return tenantIds; + } } diff --git a/services/contact/service/src/main/java/org/collectionspace/services/contact/AuthorityResourceWithContacts.java b/services/contact/service/src/main/java/org/collectionspace/services/contact/AuthorityResourceWithContacts.java index 2bc3eb136..b99ad31e3 100644 --- a/services/contact/service/src/main/java/org/collectionspace/services/contact/AuthorityResourceWithContacts.java +++ b/services/contact/service/src/main/java/org/collectionspace/services/contact/AuthorityResourceWithContacts.java @@ -24,6 +24,7 @@ package org.collectionspace.services.contact; import java.util.HashMap; +import java.util.List; import java.util.Map; import javax.ws.rs.Consumes; import javax.ws.rs.DELETE; @@ -42,6 +43,7 @@ import javax.ws.rs.core.UriInfo; import org.collectionspace.services.client.*; import org.collectionspace.services.common.StoredValuesUriTemplate; import org.collectionspace.services.common.UriTemplateFactory; +import org.collectionspace.services.common.UriTemplateRegistryKey; import org.collectionspace.services.common.vocabulary.AuthorityResource; import org.collectionspace.services.common.context.ServiceContext; import org.collectionspace.services.common.document.DocumentFilter; @@ -301,24 +303,21 @@ public abstract class AuthorityResourceWithContacts return ContactConstants.NUXEO_DOCTYPE; } - /** - * Constructs and returns a map of URI templates for the current resource. - * This map assumes that there will be only one URI template of a given type - * ("resource", "item", "contacts" etc.) for each resource. - * - * @return a map of URI templates for the current resource - */ + /** + * Returns a UriRegistry entry: a map of tenant-qualified URI templates + * for the current resource, for all tenants + * + * @return a map of URI templates for the current resource, for all tenants + */ @Override - protected Map getUriTemplateMap() { - // Get the resource and item URI templates from the superclass - Map uriTemplateMap = super.getUriTemplateMap(); - // Add the contact URI template here, and return all three templates in the map - StoredValuesUriTemplate contactUriTemplate = getUriTemplate(UriTemplateFactory.CONTACT); - if (contactUriTemplate == null) { - return uriTemplateMap; // return map as obtained from superclass + public Map getUriRegistryEntries() { + Map uriRegistryEntriesMap = + super.getUriRegistryEntries(); + List tenantIds = getTenantBindingsReader().getTenantIds(); + for (String tenantId : tenantIds) { + uriRegistryEntriesMap.putAll(getUriRegistryEntries(tenantId, getContactDocType(), UriTemplateFactory.CONTACT)); } - uriTemplateMap.put(contactUriTemplate.getUriTemplateType(), contactUriTemplate); - return uriTemplateMap; + return uriRegistryEntriesMap; } }