]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
CSPACE-5271,CSPACE-5453: RefObjs code now uses URI Template Registry.
authorAron Roberts <aron@socrates.berkeley.edu>
Thu, 16 Aug 2012 01:06:33 +0000 (18:06 -0700)
committerAron Roberts <aron@socrates.berkeley.edu>
Thu, 16 Aug 2012 01:06:33 +0000 (18:06 -0700)
services/common/src/main/java/org/collectionspace/services/common/UriTemplateRegistryKey.java
services/common/src/main/java/org/collectionspace/services/common/vocabulary/RefNameServiceUtils.java
services/common/src/test/java/org/collectionspace/services/common/test/UriTemplateRegistryTest.java

index f7e85bd671cad06e20504424cdcedd8f0a12419e..a0560dce916fdbdb265ea13c693b623b45c0bc72 100644 (file)
@@ -63,9 +63,11 @@ public class UriTemplateRegistryKey {
         // 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
+        // FIXME: Look into possible case-sensitivity issues for registry keys - ADR 2012-08-15
+        
+        // If either the tenant ID or docType values don'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;
         }
index cc9aa87a9d56f8743402e3aaabb5e4cd7a70a390..265e969bf7317e0aa1ac7066f053cd0240bd7283 100644 (file)
@@ -573,10 +573,11 @@ public class RefNameServiceUtils {
                 ilistItem = new AuthorityRefDocList.AuthorityRefDocItem();\r
                 String csid = NuxeoUtils.getCsid(docModel);//NuxeoUtils.extractId(docModel.getPathAsString());\r
                 ilistItem.setDocId(csid);\r
-                UriTemplateRegistry uriTemplateRegistry = ServiceMain.getInstance().getUriTemplateRegistry();\r
-                StoredValuesUriTemplate storedValuesResourceTemplate = uriTemplateRegistry.get(new UriTemplateRegistryKey(docType, tenantId));\r
+                UriTemplateRegistry registry = ServiceMain.getInstance().getUriTemplateRegistry();\r
+                UriTemplateRegistryKey key = new UriTemplateRegistryKey(tenantId, docType);\r
+                StoredValuesUriTemplate template = registry.get(key);\r
                 Map<String, String> additionalValues = new HashMap<String, String>();\r
-                if (storedValuesResourceTemplate.getUriTemplateType() == UriTemplateFactory.ITEM) {\r
+                if (template.getUriTemplateType() == UriTemplateFactory.ITEM) {\r
                     try {\r
                         String inAuthorityCsid = (String) docModel.getPropertyValue("inAuthority"); // AuthorityItemJAXBSchema.IN_AUTHORITY\r
                         additionalValues.put(UriTemplateFactory.IDENTIFIER_VAR, inAuthorityCsid);\r
@@ -587,7 +588,7 @@ public class RefNameServiceUtils {
                 } else {\r
                     additionalValues.put(UriTemplateFactory.IDENTIFIER_VAR, csid);\r
                 }\r
-                String uriStr = storedValuesResourceTemplate.buildUri(additionalValues);\r
+                String uriStr = template.buildUri(additionalValues);\r
                 ilistItem.setUri(uriStr);\r
                 try {\r
                     ilistItem.setWorkflowState(docModel.getCurrentLifeCycleState());\r
index 165e73fd48ad2a72d7050d8ac5511cd8b5db7ad8..90c5a8c5cff5a447b1b0f97da0fe3489035f5f76 100644 (file)
-/**
- * This document is a part of the source code and related artifacts for
- * CollectionSpace, an open source collections management system for museums and
- * related institutions:
- *
- * http://www.collectionspace.org http://wiki.collectionspace.org
- *
- * Copyright (c) 2012 Regents of the University of California
- *
- * Licensed under the Educational Community License (ECL), Version 2.0. You may
- * not use this file except in compliance with this License.
- *
- * You may obtain a copy of the ECL 2.0 License at
- * https://source.collectionspace.org/collection-space/LICENSE.txt
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations under
- * the License.
- */
-package org.collectionspace.services.common.test;
-
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Map;
-import org.collectionspace.services.common.ServiceMain;
-import org.collectionspace.services.common.StoredValuesUriTemplate;
-import org.collectionspace.services.common.UriTemplateFactory;
-import org.collectionspace.services.common.UriTemplateRegistry;
-import org.collectionspace.services.common.UriTemplateRegistryKey;
-import org.collectionspace.services.common.api.Tools;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.testng.Assert;
-import org.testng.annotations.BeforeSuite;
-import org.testng.annotations.Test;
-
-public class UriTemplateRegistryTest {
-
-    private static final Logger logger = LoggerFactory.getLogger(UriTemplateRegistryTest.class);
-    UriTemplateRegistry registry;
-    final static String TEST_TENANT_ID = "1";
-    final static String TEST_DOCTYPE_NAME = "Doctype";
-    final static String TEST_TEMPATE = "/doctypes";
-    final static UriTemplateFactory.UriTemplateType TEST_URI_TEMPLATE_TYPE =
-            UriTemplateFactory.RESOURCE;
-
-    private void testBanner(String msg) {
-        String BANNER = "-------------------------------------------------------";
-        logger.debug("\r" + BANNER + "\r\n" + this.getClass().getName() + "\r\n" + msg + "\r\n" + BANNER);
-    }
-
-    /**
-     * Create a test entry in the registry.
-     */
-    @BeforeSuite
-    private void setUp() {
-        UriTemplateRegistryKey key = new UriTemplateRegistryKey(TEST_TENANT_ID, TEST_DOCTYPE_NAME);
-        Map<String,String> storedValues = new HashMap<String,String>();
-        StoredValuesUriTemplate template = new StoredValuesUriTemplate(TEST_URI_TEMPLATE_TYPE, TEST_TEMPATE, storedValues);
-        registry = new UriTemplateRegistry();
-        registry.put(key, template);
-    }
-
-    @Test
-    public void registryContainsEntries() {
-        testBanner("registryContainsEntries");
-        Assert.assertNotNull(registry);
-        Assert.assertFalse(registry.isEmpty());
-    }
-
-    /**
-     * Identify a valid entry in the registry, then use its key to successfully
-     * retrieve the entry once again.
-     */
-    @Test(dependsOnMethods = {"registryContainsEntries"})
-    public void getRegistryEntryByKey() {
-        testBanner("getRegistryEntryByKey");
-        UriTemplateRegistryKey key;
-        StoredValuesUriTemplate template;
-        boolean hasValidKey = false;
-        boolean hasValidTemplate = false;
-        for (Map.Entry<UriTemplateRegistryKey, StoredValuesUriTemplate> entry : registry.entrySet()) {
-            key = entry.getKey();
-            template = entry.getValue();
-            if (key != null && Tools.notBlank(key.getTenantId()) && Tools.notBlank(key.getDocType())) {
-                hasValidKey = true;
-            }
-            if (template != null && template.getUriTemplateType() != null && Tools.notBlank(template.toString())) {
-                hasValidTemplate = true;
-            }
-            if (hasValidKey && hasValidTemplate) {
-                break;
-            }
-            Assert.assertTrue(hasValidKey && hasValidTemplate);
-            StoredValuesUriTemplate retrievedTemplate = registry.get(key);
-            Assert.assertNotNull(retrievedTemplate);
-            Assert.assertEquals(template.toString(), retrievedTemplate.toString());
-
-        }
-    }
-}
+/**\r
+ * This document is a part of the source code and related artifacts for\r
+ * CollectionSpace, an open source collections management system for museums and\r
+ * related institutions:\r
+ *\r
+ * http://www.collectionspace.org http://wiki.collectionspace.org\r
+ *\r
+ * Copyright (c) 2012 Regents of the University of California\r
+ *\r
+ * Licensed under the Educational Community License (ECL), Version 2.0. You may\r
+ * not use this file except in compliance with this License.\r
+ *\r
+ * You may obtain a copy of the ECL 2.0 License at\r
+ * https://source.collectionspace.org/collection-space/LICENSE.txt\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT\r
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the\r
+ * License for the specific language governing permissions and limitations under\r
+ * the License.\r
+ */\r
+package org.collectionspace.services.common.test;\r
+\r
+import java.util.HashMap;\r
+import java.util.Iterator;\r
+import java.util.Map;\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.api.Tools;\r
+import org.slf4j.Logger;\r
+import org.slf4j.LoggerFactory;\r
+import org.testng.Assert;\r
+import org.testng.annotations.BeforeSuite;\r
+import org.testng.annotations.Test;\r
+\r
+public class UriTemplateRegistryTest {\r
+\r
+    private static final Logger logger = LoggerFactory.getLogger(UriTemplateRegistryTest.class);\r
+    UriTemplateRegistry registry;\r
+    final static String TEST_TENANT_ID = "1";\r
+    final static String TEST_DOCTYPE_NAME = "Doctype";\r
+    final static String TEST_TEMPATE = "/doctypes";\r
+    final static UriTemplateFactory.UriTemplateType TEST_URI_TEMPLATE_TYPE =\r
+            UriTemplateFactory.RESOURCE;\r
+\r
+    private void testBanner(String msg) {\r
+        String BANNER = "-------------------------------------------------------";\r
+        logger.debug("\r" + BANNER + "\r\n" + this.getClass().getName() + "\r\n" + msg + "\r\n" + BANNER);\r
+    }\r
+\r
+    /**\r
+     * Create a test entry in the registry.\r
+     */\r
+    @BeforeSuite\r
+    private void setUp() {\r
+        UriTemplateRegistryKey key = new UriTemplateRegistryKey(TEST_TENANT_ID, TEST_DOCTYPE_NAME);\r
+        Map<String,String> storedValues = new HashMap<String,String>();\r
+        StoredValuesUriTemplate template = new StoredValuesUriTemplate(TEST_URI_TEMPLATE_TYPE, TEST_TEMPATE, storedValues);\r
+        registry = new UriTemplateRegistry();\r
+        registry.put(key, template);\r
+    }\r
+\r
+    @Test\r
+    public void registryContainsEntries() {\r
+        testBanner("registryContainsEntries");\r
+        Assert.assertNotNull(registry);\r
+        Assert.assertFalse(registry.isEmpty());\r
+    }\r
+\r
+    /**\r
+     * Identify a valid entry in the registry, then use its key to successfully\r
+     * retrieve the entry once again.\r
+     */\r
+    @Test(dependsOnMethods = {"registryContainsEntries"})\r
+    public void getRegistryEntryByKey() {\r
+        testBanner("getRegistryEntryByKey");\r
+        UriTemplateRegistryKey key;\r
+        StoredValuesUriTemplate template;\r
+        boolean hasValidKey = false;\r
+        boolean hasValidTemplate = false;\r
+        for (Map.Entry<UriTemplateRegistryKey, StoredValuesUriTemplate> entry : registry.entrySet()) {\r
+            key = entry.getKey();\r
+            template = entry.getValue();\r
+            if (key != null && Tools.notBlank(key.getTenantId()) && Tools.notBlank(key.getDocType())) {\r
+                hasValidKey = true;\r
+            }\r
+            if (template != null && template.getUriTemplateType() != null && Tools.notBlank(template.toString())) {\r
+                hasValidTemplate = true;\r
+            }\r
+            if (hasValidKey && hasValidTemplate) {\r
+                break;\r
+            }\r
+            Assert.assertTrue(hasValidKey && hasValidTemplate);\r
+            StoredValuesUriTemplate retrievedTemplate = registry.get(key);\r
+            Assert.assertNotNull(retrievedTemplate);\r
+            Assert.assertEquals(template.toString(), retrievedTemplate.toString());\r
+\r
+        }\r
+    }\r
+}\r