]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
CSPACE-5271,CSPACE-5453: Moved population of the URI template registry to ServiceMain...
authorAron Roberts <aron@socrates.berkeley.edu>
Wed, 15 Aug 2012 23:58:28 +0000 (16:58 -0700)
committerAron Roberts <aron@socrates.berkeley.edu>
Wed, 15 Aug 2012 23:58:28 +0000 (16:58 -0700)
services/JaxRsServiceProvider/src/main/java/org/collectionspace/services/jaxrs/CollectionSpaceJaxRsApplication.java
services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/AuthorityResource.java
services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/nuxeo/AuthorityItemDocumentModelHandler.java
services/common/src/main/java/org/collectionspace/services/common/ServiceMain.java
services/common/src/main/java/org/collectionspace/services/common/UriTemplateRegistryHolder.java [deleted file]
services/common/src/main/java/org/collectionspace/services/common/UriTemplateRegistryKey.java
services/common/src/main/java/org/collectionspace/services/common/vocabulary/RefNameServiceUtils.java

index 5173917a4700158766ddb6133002b705006ca70e..72a7ac736a4b2b9ac945e62c56be71cf6c74023e 100644 (file)
@@ -82,12 +82,11 @@ import org.jboss.resteasy.spi.ResteasyProviderFactory;
  * $LastChangedDate$
  */
 public class CollectionSpaceJaxRsApplication extends Application
-                                       implements ResourceMapHolder, UriTemplateRegistryHolder {
+                                       implements ResourceMapHolder {
 
     private Set<Object> singletons = new HashSet<Object>();
     private Set<Class<?>> empty = new HashSet<Class<?>>();    
     private ResourceMap resourceMap = new ResourceMapImpl();
-    private UriTemplateRegistry uriTemplateRegistry = new UriTemplateRegistry();
     private ServletContext servletContext = null;
 
     public CollectionSpaceJaxRsApplication() {         
@@ -129,11 +128,6 @@ public class CollectionSpaceJaxRsApplication extends Application
 
         singletons.add(new IDResource());
         
-        buildUriTemplateRegistry();
-        // FIXME: Temporary for CSPACE-5271 - please remove once
-        // that issue is resolved
-        uriTemplateRegistry.dump();
-        
         /*
         singletons.add(new WorkflowResource());
         */
@@ -147,33 +141,6 @@ public class CollectionSpaceJaxRsApplication extends Application
         resourceMap.put(resource.getServiceName(), resource);
     }
     
-    /**
-     *  Build a registry of URI templates by querying each resource
-     *  for its own entries in the registry.
-     * 
-     *  These entries consist of one or more URI templates for
-     *  building URIs for accessing that resource.
-     */
-    private void buildUriTemplateRegistry() {
-        ResourceBase resource = null;
-        ResourceMap resources = getResourceMap();
-        for (Map.Entry<String, ResourceBase> entry : resources.entrySet()) {
-            resource = entry.getValue();
-            Map<UriTemplateRegistryKey, Map<UriTemplateFactory.UriTemplateType, StoredValuesUriTemplate>> entries =
-                    resource.getUriRegistryEntries();
-            getUriTemplateRegistry().putAll(entries);
-        }
-        // 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
-        //
-        // final String CONTACT_DOCTYPE = "Contact";
-        // uriTemplateRegistry.remove(CONTACT_DOCTYPE);
-    }
-    
 
     @Override
     public Set<Class<?>> getClasses() {
@@ -185,18 +152,11 @@ public class CollectionSpaceJaxRsApplication extends Application
         return singletons;
     }
 
+    @Override
     public ResourceMap getResourceMap() {
         return resourceMap;
     }
     
-    private void setUriTemplateRegistry(UriTemplateRegistry registry) {
-        this.uriTemplateRegistry = registry;
-    }
-    
-    public UriTemplateRegistry getUriTemplateRegistry() {
-        return uriTemplateRegistry;
-    }
-    
     public void setServletContext(ServletContext servletContext) {
        this.servletContext = servletContext;
     }
index de9cf91d557b6cf76e7399bdee39480d15515b79..cd6c6caf1d20234e8d618f90abb4b88b4f6ff7fa 100644 (file)
@@ -791,6 +791,7 @@ public abstract class AuthorityResource<AuthCommon, AuthItemHandler>
     public AuthorityRefDocList getReferencingObjects(
             @PathParam("csid") String parentspecifier,
             @PathParam("itemcsid") String itemspecifier,
+            @Context UriTemplateRegistry uriTemplateRegistry,
             @Context UriInfo ui) {
         AuthorityRefDocList authRefDocList = null;
         try {
@@ -811,7 +812,7 @@ public abstract class AuthorityResource<AuthCommon, AuthItemHandler>
             AuthorityItemDocumentModelHandler<?> handler = (AuthorityItemDocumentModelHandler<?>)
                                                                                                createItemDocumentHandler(ctx, parentcsid, null);
 
-            authRefDocList = handler.getReferencingObjects(ctx, serviceTypes, getRefPropName(), itemcsid);
+            authRefDocList = handler.getReferencingObjects(ctx, uriTemplateRegistry, serviceTypes, getRefPropName(), itemcsid);
         } catch (Exception e) {
             throw bigReThrow(e, ServiceMessages.GET_FAILED);
         }
index 22919c7aa04215ba8e64eca2ba8f0be9c676fb5e..a00b74f9242799d4c279a6cc49c3935e5c24f93e 100644 (file)
@@ -32,6 +32,7 @@ import org.collectionspace.services.client.PoxPayloadOut;
 import org.collectionspace.services.client.RelationClient;
 
 import org.collectionspace.services.common.ResourceBase;
+import org.collectionspace.services.common.UriTemplateRegistry;
 import org.collectionspace.services.common.api.CommonAPI;
 import org.collectionspace.services.common.api.RefName;
 import org.collectionspace.services.common.api.Tools;
@@ -454,6 +455,7 @@ public abstract class AuthorityItemDocumentModelHandler<AICommon>
     
     public AuthorityRefDocList getReferencingObjects(
                ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx,
+                UriTemplateRegistry uriTemplateRegistry, 
                List<String> serviceTypes,
                String propertyName,
             String itemcsid) throws Exception {
@@ -475,7 +477,7 @@ public abstract class AuthorityItemDocumentModelHandler<AICommon>
                        DocumentModel docModel = wrapper.getWrappedObject();
                        String refName = (String) docModel.getPropertyValue(AuthorityItemJAXBSchema.REF_NAME);
                 authRefDocList = RefNameServiceUtils.getAuthorityRefDocs(
-                               repoSession, ctx, repoClient,
+                               repoSession, ctx, uriTemplateRegistry, repoClient,
                         serviceTypes,
                         refName,
                         propertyName,
index 3a93a231b7fbc7160dca77c8bb9359a9df6879a8..51ccd3cd3ee485c50d42fa977931ca4654cf5367 100644 (file)
@@ -34,6 +34,7 @@ import org.collectionspace.services.config.types.PropertyItemType;
 import org.collectionspace.services.config.types.PropertyType;\r
 import org.collectionspace.services.nuxeo.client.java.NuxeoConnectorEmbedded;\r
 import org.collectionspace.services.nuxeo.client.java.TenantRepository;\r
+import org.jboss.resteasy.spi.ResteasyProviderFactory;\r
 \r
 import org.slf4j.Logger;\r
 import org.slf4j.LoggerFactory;\r
@@ -57,6 +58,7 @@ public class ServiceMain {
     private String serverRootDir = null;\r
     private ServicesConfigReaderImpl servicesConfigReader;\r
     private TenantBindingConfigReaderImpl tenantBindingConfigReader;\r
+    private UriTemplateRegistry uriTemplateRegistry = new UriTemplateRegistry();\r
     \r
     private static final String SERVER_HOME_PROPERTY = "catalina.home";\r
     \r
@@ -380,6 +382,42 @@ public class ServiceMain {
     public TenantBindingConfigReaderImpl getTenantBindingConfigReader() {\r
         return tenantBindingConfigReader;\r
     }\r
+    \r
+    /**\r
+     *  Populate a registry of URI templates by querying each resource\r
+     *  for its own entries in the registry.\r
+     * \r
+     *  These entries consist of one or more URI templates for\r
+     *  building URIs for accessing that resource.\r
+     */\r
+    private synchronized void populateUriTemplateRegistry() {\r
+       if (uriTemplateRegistry.isEmpty()) {\r
+            ResourceBase resource = null;\r
+            ResourceMap resourceMap = ResteasyProviderFactory.getContextData(ResourceMap.class);\r
+            for (Map.Entry<String, ResourceBase> entry : resourceMap.entrySet()) {\r
+                resource = entry.getValue();\r
+                Map<UriTemplateRegistryKey, StoredValuesUriTemplate> entries =\r
+                        resource.getUriRegistryEntries();\r
+                uriTemplateRegistry.putAll(entries);\r
+            }\r
+\r
+            // FIXME: Contacts itself should not have an entry in the URI template registry;\r
+            // there should be a Contacts entry in that registry only for use in\r
+            // building URIs for resources that have contacts as a sub-resource\r
+            // (This may also fall out during implementation of CSPACE-2698.)\r
+\r
+            // FIXME: Temporary for debugging in-process work on CSPACE-5271.\r
+            // Please remove the following statement once that issue is resolved.\r
+            uriTemplateRegistry.dump();\r
+       }\r
+    }\r
+\r
+    public UriTemplateRegistry getUriTemplateRegistry() {\r
+        if (uriTemplateRegistry.isEmpty()) {\r
+            populateUriTemplateRegistry();\r
+        }\r
+        return uriTemplateRegistry;\r
+    }\r
 \r
 \r
 }\r
diff --git a/services/common/src/main/java/org/collectionspace/services/common/UriTemplateRegistryHolder.java b/services/common/src/main/java/org/collectionspace/services/common/UriTemplateRegistryHolder.java
deleted file mode 100644 (file)
index a3ab98b..0000000
+++ /dev/null
@@ -1,6 +0,0 @@
-
-package org.collectionspace.services.common;
-
-public interface UriTemplateRegistryHolder {
-       public UriTemplateRegistry getUriTemplateRegistry();
-}
index d7d3a154cfb9b3d80ee8f113fbe7d47dabde5fa9..f7e85bd671cad06e20504424cdcedd8f0a12419e 100644 (file)
@@ -10,10 +10,10 @@ public class UriTemplateRegistryKey {
     private String tenantId;
     private String docType;
     
-    public void UriTemplateRegistryKey() {
+    public UriTemplateRegistryKey() {
     }
 
-    public void UriTemplateRegistryKey(String tenantId, String docType) {
+    public UriTemplateRegistryKey(String tenantId, String docType) {
         this.tenantId = tenantId;
         this.docType = docType;
     }
index cecee564f4c9348638fbfbc9c98e1104dcfe0df1..cc9aa87a9d56f8743402e3aaabb5e4cd7a70a390 100644 (file)
@@ -23,7 +23,6 @@
 package org.collectionspace.services.common.vocabulary;\r
 \r
 import java.util.ArrayList;\r
-import java.util.Collection;\r
 import java.util.HashMap;\r
 import java.util.Iterator;\r
 import java.util.List;\r
@@ -43,15 +42,17 @@ import org.slf4j.LoggerFactory;
 import org.collectionspace.services.client.PoxPayloadIn;\r
 import org.collectionspace.services.client.PoxPayloadOut;\r
 import org.collectionspace.services.common.ServiceMain;\r
+import org.collectionspace.services.common.StoredValuesUriTemplate;\r
+import org.collectionspace.services.common.UriTemplateFactory;\r
+import org.collectionspace.services.common.UriTemplateRegistry;\r
+import org.collectionspace.services.common.UriTemplateRegistryKey;\r
 import org.collectionspace.services.common.context.ServiceContext;\r
 import org.collectionspace.services.common.context.AbstractServiceContextImpl;\r
 import org.collectionspace.services.common.api.RefNameUtils;\r
 import org.collectionspace.services.common.api.Tools;\r
 import org.collectionspace.services.common.api.RefNameUtils.AuthorityTermInfo;\r
 import org.collectionspace.services.common.authorityref.AuthorityRefDocList;\r
-import org.collectionspace.services.common.authorityref.AuthorityRefList;\r
 import org.collectionspace.services.common.config.TenantBindingConfigReaderImpl;\r
-import org.collectionspace.services.common.config.URIUtils;\r
 import org.collectionspace.services.common.context.ServiceBindingUtils;\r
 import org.collectionspace.services.common.document.DocumentException;\r
 import org.collectionspace.services.common.document.DocumentFilter;\r
@@ -60,15 +61,14 @@ import org.collectionspace.services.common.document.DocumentUtils;
 import org.collectionspace.services.common.document.DocumentWrapper;\r
 import org.collectionspace.services.common.query.QueryManager;\r
 import org.collectionspace.services.common.repository.RepositoryClient;\r
-// import org.collectionspace.services.common.vocabulary.AuthorityItemJAXBSchema;\r
 import org.collectionspace.services.nuxeo.client.java.DocHandlerBase;\r
 import org.collectionspace.services.nuxeo.client.java.RepositoryJavaClientImpl;\r
 import org.collectionspace.services.common.security.SecurityUtils;\r
 import org.collectionspace.services.config.service.ServiceBindingType;\r
 import org.collectionspace.services.jaxb.AbstractCommonList;\r
 import org.collectionspace.services.nuxeo.util.NuxeoUtils;\r
+import org.jboss.resteasy.spi.ResteasyProviderFactory;\r
 \r
-import com.sun.xml.bind.v2.runtime.unmarshaller.XsiNilLoader.Array;\r
 \r
 /**\r
  * RefNameServiceUtils is a collection of services utilities related to refName\r
@@ -223,6 +223,7 @@ public class RefNameServiceUtils {
     public static AuthorityRefDocList getAuthorityRefDocs(\r
             RepositoryInstance repoSession,\r
             ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx,\r
+            UriTemplateRegistry uriTemplateRegistry,\r
             RepositoryClient<PoxPayloadIn, PoxPayloadOut> repoClient,\r
             List<String> serviceTypes,\r
             String refName,\r
@@ -278,7 +279,7 @@ public class RefNameServiceUtils {
             // item within any individual document scanned, so the number of\r
             // authority references may potentially exceed the total number\r
             // of documents scanned.\r
-            int nRefsFound = processRefObjsDocList(docList, refName, queriedServiceBindings, authRefFieldsByService, // the actual list size needs to be updated to the size of "list"\r
+            int nRefsFound = processRefObjsDocList(docList, ctx.getTenantId(), refName, queriedServiceBindings, authRefFieldsByService, // the actual list size needs to be updated to the size of "list"\r
                     list, null);\r
 \r
             commonList.setPageSize(pageSize);\r
@@ -356,7 +357,7 @@ public class RefNameServiceUtils {
         return refNameServiceTypes;\r
     }\r
     // Seems like a good value - no real data to set this well.\r
-    // Note: can set this value lower; e.g. to 3 during debugging; - ADR 2012-07-10\r
+    // Note: can set this value lower during debugging; e.g. to 3 - ADR 2012-07-10\r
     private static final int N_OBJS_TO_UPDATE_PER_LOOP = 100;\r
 \r
     public static int updateAuthorityRefDocs(\r
@@ -404,7 +405,7 @@ public class RefNameServiceUtils {
                     morePages = false;\r
                 }\r
 \r
-                int nRefsFoundThisPage = processRefObjsDocList(docList, oldRefName, queriedServiceBindings, authRefFieldsByService,\r
+                int nRefsFoundThisPage = processRefObjsDocList(docList, ctx.getTenantId(), oldRefName, queriedServiceBindings, authRefFieldsByService,\r
                         null, newRefName);\r
                 if (nRefsFoundThisPage > 0) {\r
                     ((RepositoryJavaClientImpl) repoClient).saveDocListWithoutHandlerProcessing(ctx, repoSession, docList, true);\r
@@ -540,6 +541,7 @@ public class RefNameServiceUtils {
      */\r
     private static int processRefObjsDocList(\r
             DocumentModelList docList,\r
+            String tenantId,\r
             String refName,\r
             Map<String, ServiceBindingType> queriedServiceBindings,\r
             Map<String, List<AuthRefConfigInfo>> authRefFieldsByService,\r
@@ -571,22 +573,22 @@ public class RefNameServiceUtils {
                 ilistItem = new AuthorityRefDocList.AuthorityRefDocItem();\r
                 String csid = NuxeoUtils.getCsid(docModel);//NuxeoUtils.extractId(docModel.getPathAsString());\r
                 ilistItem.setDocId(csid);\r
-                String uri = "";\r
-                // FIXME: Hack for CSPACE-5406; this instead should use the (forthcoming)\r
-                // URL pattern-to-Doctype registry described in CSPACE-5471 - ADR 2012-07-18\r
-                if (sb.getType().equalsIgnoreCase(URIUtils.AUTHORITY_SERVICE_CATEGORY)) {\r
-                    String authoritySvcName = URIUtils.getAuthoritySvcName(docType);\r
-                    String inAuthorityCsid;\r
+                UriTemplateRegistry uriTemplateRegistry = ServiceMain.getInstance().getUriTemplateRegistry();\r
+                StoredValuesUriTemplate storedValuesResourceTemplate = uriTemplateRegistry.get(new UriTemplateRegistryKey(docType, tenantId));\r
+                Map<String, String> additionalValues = new HashMap<String, String>();\r
+                if (storedValuesResourceTemplate.getUriTemplateType() == UriTemplateFactory.ITEM) {\r
                     try {\r
-                        inAuthorityCsid = (String) docModel.getPropertyValue("inAuthority"); // AuthorityItemJAXBSchema.IN_AUTHORITY\r
-                        uri = URIUtils.getAuthorityItemUri(authoritySvcName, inAuthorityCsid, csid);\r
+                        String inAuthorityCsid = (String) docModel.getPropertyValue("inAuthority"); // AuthorityItemJAXBSchema.IN_AUTHORITY\r
+                        additionalValues.put(UriTemplateFactory.IDENTIFIER_VAR, inAuthorityCsid);\r
+                        additionalValues.put(UriTemplateFactory.ITEM_IDENTIFIER_VAR, csid);\r
                     } catch (Exception e) {\r
                         logger.warn("Could not extract inAuthority property from authority item record: " + e.getMessage());\r
                     }\r
                 } else {\r
-                    uri = URIUtils.getUri(sb.getName(), csid);;\r
+                    additionalValues.put(UriTemplateFactory.IDENTIFIER_VAR, csid);\r
                 }\r
-                ilistItem.setUri(uri);\r
+                String uriStr = storedValuesResourceTemplate.buildUri(additionalValues);\r
+                ilistItem.setUri(uriStr);\r
                 try {\r
                     ilistItem.setWorkflowState(docModel.getCurrentLifeCycleState());\r
                     ilistItem.setUpdatedAt(DocHandlerBase.getUpdatedAtAsString(docModel));\r