From: Aron Roberts Date: Sat, 9 Jun 2012 00:44:57 +0000 (-0700) Subject: CSPACE-5271: List of docType keys for the UriTemplateRegistry now comes from tenant... X-Git-Url: https://git.aero2k.de/?a=commitdiff_plain;h=26fcba43b5e56792e20326f3120434e517c8d0c0;p=tmp%2Fjakarta-migration.git CSPACE-5271: List of docType keys for the UriTemplateRegistry now comes from tenant bindings configuration (albeit for an arbitrary tenant). All docTypes appear to be populated successfully. There is currently only one entry for the Contact doctype - whichever is last populated in the registry - although there can be multiple authority item types that count Contacts as a sub-resource. --- 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 b2aca1fd5..e1543c2c8 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 @@ -86,6 +86,10 @@ import java.util.List; import java.util.Map; import org.collectionspace.services.client.*; import org.collectionspace.services.common.*; + +import org.collectionspace.services.common.config.TenantBindingConfigReaderImpl; +import org.collectionspace.services.config.service.ServiceBindingType; + import org.collectionspace.services.nuxeo.util.NuxeoUtils; /** @@ -963,7 +967,33 @@ public abstract class AuthorityResource public String getItemDocType() { // FIXME: Proof of concept placeholder - return "item-" + getServiceName(); + // return "item-" + getServiceName(); + + return super.getDocType(getItemServiceName()); + + /* + // FIXME: Replace this outrageous hack; a tenant with this ID may not exist + String docType = ""; + final String DEFAULT_TENANT_ID = "1"; + TenantBindingConfigReaderImpl reader = ServiceMain.getInstance().getTenantBindingConfigReader(); + ServiceBindingType sb = reader.getServiceBinding(DEFAULT_TENANT_ID, getItemServiceName()); + docType = sb.getObject().getName(); + return docType; + + String docType = ""; + String arbitraryTenantId = ""; + ServiceBindingType sb; + TenantBindingConfigReaderImpl reader = ServiceMain.getInstance().getTenantBindingConfigReader(); + // FIXME: Makes the outrageous assumption that the list of service names and associated + // document types is essentially identical across tenants + arbitraryTenantId = getArbitraryTenantId(reader); + if (Tools.notBlank(arbitraryTenantId)) { + ServiceBindingType sb = reader.getServiceBinding(arbitraryTenantId, getItemServiceName()); + docType = sb.getObject().getName(); + } + return docType; + * + */ } @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 578159891..5eecf059d 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 @@ -23,6 +23,7 @@ */ package org.collectionspace.services.common; +import java.util.*; import org.collectionspace.services.client.IQueryManager; import org.collectionspace.services.client.PoxPayloadIn; import org.collectionspace.services.client.PoxPayloadOut; @@ -47,9 +48,11 @@ import org.nuxeo.ecm.core.api.repository.RepositoryInstance; import javax.ws.rs.*; import javax.ws.rs.core.*; -import java.util.HashMap; -import java.util.List; -import java.util.Map; + +import org.collectionspace.services.common.config.TenantBindingConfigReaderImpl; +import org.collectionspace.services.config.service.ServiceBindingType; +import org.collectionspace.services.config.tenant.TenantBindingType; + /** * $LastChangedRevision: $ @@ -383,8 +386,29 @@ public abstract class ResourceBase } public String getDocType() { - // FIXME: Proof of concept placeholder - return getServiceName(); + return getDocType(getServiceName()); + } + + // FIXME: This may well be a dreadful hack, just to get this initially working. + // + // Question: + // At the point we're seeking to populate docTypes in the uriTemplateRegistry, during system startup, + // we're not yet logged into any tenant, but instead it appears we are acting as the user SPRING_ADMIN. + // Could this potentially suggest reasonable method(s), other than those below, by which we can obtain + // the docType(s) associated with the current resource? + + public String getDocType(String serviceName) { + String docType = ""; + String arbitraryTenantId = ""; + TenantBindingConfigReaderImpl reader = ServiceMain.getInstance().getTenantBindingConfigReader(); + // FIXME: Makes the outrageous assumption that the list of service names and associated + // document types is essentially identical across tenants + arbitraryTenantId = getArbitraryTenantId(reader); + if (Tools.notBlank(arbitraryTenantId)) { + ServiceBindingType sb = reader.getServiceBinding(arbitraryTenantId, serviceName); + docType = sb.getObject().getName(); + } + return docType; } public Map getUriTemplateMap() { @@ -410,5 +434,19 @@ public abstract class ResourceBase return template; } + public String getArbitraryTenantId(TenantBindingConfigReaderImpl reader) { + String arbitraryTenantId = ""; + Hashtable tenantBindings = reader.getTenantBindings(); + if (tenantBindings != null && !tenantBindings.isEmpty()) { + Enumeration keys = tenantBindings.keys(); + while (keys.hasMoreElements()) { + arbitraryTenantId = (String) keys.nextElement(); + if (Tools.notBlank(arbitraryTenantId)) { + break; + } + } + } + return arbitraryTenantId; + } } 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 5d5553fd5..d81256c78 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 @@ -49,6 +49,7 @@ import org.collectionspace.services.common.document.DocumentHandler; import org.collectionspace.services.contact.ContactResource; import org.collectionspace.services.contact.ContactsCommon; import org.collectionspace.services.contact.ContactJAXBSchema; +import org.collectionspace.services.contact.nuxeo.ContactConstants; import org.collectionspace.services.contact.nuxeo.ContactDocumentModelHandler; import org.collectionspace.services.jaxb.AbstractCommonList; import org.jboss.resteasy.util.HttpResponseCodes; @@ -297,8 +298,7 @@ public abstract class AuthorityResourceWithContacts } public String getContactDocType() { - // FIXME: Proof of concept placeholder - return "contact-" + getServiceName(); + return ContactConstants.NUXEO_DOCTYPE; } @Override