From 2c98661a46f4f16ddbe328dd6f3039035aeb3453 Mon Sep 17 00:00:00 2001 From: Aron Roberts Date: Sat, 9 Jun 2012 09:19:57 -0700 Subject: [PATCH] CSPACE-5271: Contact UriTemplate now has correct template type and path when stored in the UriTemplateRegistry. As well, its 'servicename' variable is no longer pre-populated, and a value for this variable must be now provided when building contact sub-resource URIs. --- .../jaxrs/CollectionSpaceJaxRsApplication.java | 13 +++++++++++-- .../services/common/ResourceBase.java | 18 +++++++++--------- .../contact/AuthorityResourceWithContacts.java | 7 +++++-- 3 files changed, 25 insertions(+), 13 deletions(-) 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 15a3008a3..c34b83663 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 @@ -129,7 +129,8 @@ public class CollectionSpaceJaxRsApplication extends Application singletons.add(new IDResource()); - // FIXME: Temporary for CSPACE-5271 + // FIXME: Temporary for CSPACE-5271 - please remove once + // that issue is resolved uriTemplateRegistry.dump(); /* @@ -143,7 +144,15 @@ public class CollectionSpaceJaxRsApplication extends Application private void addResourceToMapAndSingletons(ResourceBase resource) { singletons.add(resource); resourceMap.put(resource.getServiceName(), resource); - uriTemplateRegistry.putAll(resource.getUriTemplateMap()); + // Contacts itself should not have an entry in the URI template registry; + // there should be a Contacts entry in that registry only for use in + // building URIs for resources that have contacts as a sub-resource + // + // FIXME: There may be a more elegant way to filter this out; or it may + // fall out during implementation of CSPACE-2698 + if (! (resource instanceof ContactResource)) { + uriTemplateRegistry.putAll(resource.getUriTemplateMap()); + } } @Override 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 fa8b065f6..adce97fd3 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 @@ -398,13 +398,13 @@ public abstract class ResourceBase public String getDocType(String serviceName) { String docType = ""; - String arbitraryTenantId = ""; + String anyTenantId = ""; TenantBindingConfigReaderImpl reader = ServiceMain.getInstance().getTenantBindingConfigReader(); // FIXME: Makes the likely unsupportable assumption that the list of service names and associated // document types is materially identical across tenants - arbitraryTenantId = getArbitraryTenantId(reader); - if (Tools.notBlank(arbitraryTenantId)) { - ServiceBindingType sb = reader.getServiceBinding(arbitraryTenantId, serviceName); + anyTenantId = getAnyTenantId(reader); + if (Tools.notBlank(anyTenantId)) { + ServiceBindingType sb = reader.getServiceBinding(anyTenantId, serviceName); docType = sb.getObject().getName(); // reads the Nuxeo Document Type from tenant bindings configuration } return docType; @@ -433,19 +433,19 @@ public abstract class ResourceBase return template; } - public String getArbitraryTenantId(TenantBindingConfigReaderImpl reader) { - String arbitraryTenantId = ""; + public String getAnyTenantId(TenantBindingConfigReaderImpl reader) { + String anyTenantId = ""; Hashtable tenantBindings = reader.getTenantBindings(); if (tenantBindings != null && !tenantBindings.isEmpty()) { Enumeration keys = tenantBindings.keys(); while (keys.hasMoreElements()) { - arbitraryTenantId = (String) keys.nextElement(); - if (Tools.notBlank(arbitraryTenantId)) { + anyTenantId = (String) keys.nextElement(); + if (Tools.notBlank(anyTenantId)) { break; } } } - return arbitraryTenantId; + return anyTenantId; } } 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 edf510c8a..9d6f219ea 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 @@ -301,9 +301,9 @@ public abstract class AuthorityResourceWithContacts return ContactConstants.NUXEO_DOCTYPE; } - // FIXME: This currently populates only one entry in the UriTemplateRegistry + // This currently populates only one entry in the UriTemplateRegistry // for the Contacts docType, even though contacts can be a sub-resource of - // multiple authority item resources. (This method is called more than once, + // multiple authority item resources. (This method may be called more than once, // but each time the existing item with the same key in the map is overwritten.) @Override public Map getUriTemplateMap() { @@ -318,6 +318,9 @@ public abstract class AuthorityResourceWithContacts if (contactUriTemplate == null) { return uriTemplateMap; // return map as obtained from superclass } + // Remove any service name value stored in the template, as the service name + // for contact resources will vary, and must be provided at URI build time + contactUriTemplate.getStoredValuesMap().put(UriTemplateFactory.SERVICENAME_VAR, ""); uriTemplateMap.put(contactDocType, contactUriTemplate); return uriTemplateMap; } -- 2.47.3