]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
CSPACE-2863 - Allowed multiple DocRef instances to be returned for refObjs sub-resour...
authorPatrick Schmitz <pschmitz@berkeley.edu>
Thu, 6 Jan 2011 22:46:43 +0000 (22:46 +0000)
committerPatrick Schmitz <pschmitz@berkeley.edu>
Thu, 6 Jan 2011 22:46:43 +0000 (22:46 +0000)
services/common/src/main/java/org/collectionspace/services/common/vocabulary/RefNameServiceUtils.java
services/intake/client/src/test/java/org/collectionspace/services/client/test/OrganizationAuthRefDocsTest.java

index 77d0d98416134cd27c160e8ff2b31cc26a1cab8d..5020ba00de567093c81579b36edb14272770357f 100644 (file)
@@ -111,16 +111,6 @@ public class RefNameServiceUtils {
             queriedServiceBindings.put(docType, sb);\r
             authRefFieldsByService.put(docType, authRefFields);\r
             docTypes.add(docType);\r
-            /*\r
-            // HACK - need to get qualified properties from the ServiceBinding\r
-            String prefix = "";\r
-            if(docType.equalsIgnoreCase("Intake"))\r
-            prefix = "intakes_common:";\r
-            else if(docType.equalsIgnoreCase("Loanin"))\r
-            prefix = "loansin_common:";\r
-            else if(docType.equalsIgnoreCase("Acquisition"))\r
-            prefix = "acquisitions_common:";\r
-             */\r
             Collection<String> fields = authRefFields.values();\r
             for (String field : fields) {\r
                 // Build up the where clause for each authRef field\r
@@ -201,15 +191,18 @@ public class RefNameServiceUtils {
                     //   such as "fieldCollectors", of a repeatable authority reference\r
                     //   field, such as "fieldCollector".\r
                     Object fieldValue = docModel.getProperty(strings[0], strings[1]);\r
-                    fRefFound = refNameFoundInField(refName, fieldValue);\r
-                    if (fRefFound) {\r
+                    boolean fRefMatches = refNameFoundInField(refName, fieldValue);\r
+                    if (fRefMatches) {\r
                         sourceField = authRefDescendantField;\r
-                        ilistItem.setSourceField(sourceField);\r
-                        // FIXME Returns only the first field in which the refName is found.\r
-                        // We may want to return all; this may require multiple sourceFields\r
-                        // in the list item schema; or else multiple list items, one per sourceField.\r
-                        // See CSPACE-2863 for a discussion of how this might be handled.\r
-                        break;\r
+                        // Handle multiple fields matching in one Doc. See CSPACE-2863.\r
+                       if(fRefFound) {\r
+                               // We already added ilistItem, so we need to clone that and add again\r
+                            ilistItem = cloneAuthRefDocItem(ilistItem, sourceField);\r
+                       } else {\r
+                               ilistItem.setSourceField(sourceField);\r
+                            fRefFound = true;\r
+                       }\r
+                        list.add(ilistItem);\r
                     }\r
 \r
                 } catch (ClientException ce) {\r
@@ -217,31 +210,26 @@ public class RefNameServiceUtils {
                             "getAuthorityRefDocs: Problem fetching: " + sourceField, ce);\r
                 }\r
             }\r
-            // Used before going to schema-qualified field names.\r
-            /*\r
-            for(String field:matchingAuthRefFields){\r
-            try {\r
-            if(refName.equals(docModel.getPropertyValue(field))) {\r
-            ilistItem.setSourceField(field);\r
-            fRefFound = true;\r
-            break;\r
-            }\r
-            } catch(ClientException ce) {\r
-            throw new RuntimeException(\r
-            "getAuthorityRefDocs: Problem fetching: "+field, ce);\r
-            }\r
-            }\r
-             * \r
-             */\r
             if (!fRefFound) {\r
                 throw new RuntimeException(\r
                         "getAuthorityRefDocs: Could not find refname in object:"\r
                         + docType + ":" + csid);\r
             }\r
-            list.add(ilistItem);\r
         }\r
         return wrapperList;\r
     }\r
+    \r
+    private static AuthorityRefDocList.AuthorityRefDocItem cloneAuthRefDocItem(\r
+               AuthorityRefDocList.AuthorityRefDocItem ilistItem, String sourceField) {\r
+       AuthorityRefDocList.AuthorityRefDocItem newlistItem = new AuthorityRefDocList.AuthorityRefDocItem();\r
+       newlistItem.setDocId(ilistItem.getDocId());\r
+       newlistItem.setDocName(ilistItem.getDocName());\r
+       newlistItem.setDocNumber(ilistItem.getDocNumber());\r
+       newlistItem.setDocType(ilistItem.getDocType());\r
+       newlistItem.setUri(ilistItem.getUri());\r
+       newlistItem.setSourceField(sourceField);\r
+       return newlistItem;\r
+    }\r
 \r
     /*\r
      * Identifies whether the refName was found in the supplied field.\r
index 192b16d2fc038b4f156412a4eb02a3a4a3f930b9..1bd7ae13db14a749c8799e81fff29cf59293bec4 100644 (file)
@@ -121,7 +121,8 @@ public class OrganizationAuthRefDocsTest extends BaseServiceTest {
                 "entryNumber-" + identifier,\r
                 "entryDate-" + identifier,\r
                 currentOwnerRefName,\r
-                depositorRefName,\r
+                // Use currentOwnerRefName twice to test fix for CSPACE-2863\r
+                currentOwnerRefName,    //depositorRefName,\r
                 conditionCheckerAssessorRefName,\r
                 insurerRefName,\r
                 valuerRefName );\r
@@ -249,7 +250,7 @@ public class OrganizationAuthRefDocsTest extends BaseServiceTest {
 \r
         // Optionally output additional data about list members for debugging.\r
         boolean iterateThroughList = true;\r
-        boolean fFoundIntake = false;\r
+        int nIntakesFound = 0;\r
         if(iterateThroughList && logger.isDebugEnabled()){\r
             List<AuthorityRefDocList.AuthorityRefDocItem> items =\r
                     list.getAuthorityRefDocItem();\r
@@ -262,12 +263,13 @@ public class OrganizationAuthRefDocsTest extends BaseServiceTest {
                                item.getDocName() + "] Number:[" +\r
                                item.getDocNumber() + "] in field:[" +\r
                                item.getSourceField() + "]");\r
-                if(!fFoundIntake && knownIntakeId.equalsIgnoreCase(item.getDocId())) {\r
-                               fFoundIntake = true;\r
+                if(knownIntakeId.equalsIgnoreCase(item.getDocId())) {\r
+                       nIntakesFound++;\r
                 }\r
                 i++;\r
             }\r
-            Assert.assertTrue(fFoundIntake, "Did not find Intake with authref!");\r
+            //\r
+            Assert.assertTrue((nIntakesFound==2), "Did not find Intake (twice) with authref!");\r
         }\r
     }\r
 \r