From e8ad13b11ddc124b6a5d45bbd28706904047900a Mon Sep 17 00:00:00 2001 From: Patrick Schmitz Date: Thu, 6 Jan 2011 22:46:43 +0000 Subject: [PATCH] CSPACE-2863 - Allowed multiple DocRef instances to be returned for refObjs sub-resource when a document has multiple references to a single authority term. Updated tests to verify this. --- .../vocabulary/RefNameServiceUtils.java | 58 ++++++++----------- .../test/OrganizationAuthRefDocsTest.java | 12 ++-- 2 files changed, 30 insertions(+), 40 deletions(-) diff --git a/services/common/src/main/java/org/collectionspace/services/common/vocabulary/RefNameServiceUtils.java b/services/common/src/main/java/org/collectionspace/services/common/vocabulary/RefNameServiceUtils.java index 77d0d9841..5020ba00d 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/vocabulary/RefNameServiceUtils.java +++ b/services/common/src/main/java/org/collectionspace/services/common/vocabulary/RefNameServiceUtils.java @@ -111,16 +111,6 @@ public class RefNameServiceUtils { queriedServiceBindings.put(docType, sb); authRefFieldsByService.put(docType, authRefFields); docTypes.add(docType); - /* - // HACK - need to get qualified properties from the ServiceBinding - String prefix = ""; - if(docType.equalsIgnoreCase("Intake")) - prefix = "intakes_common:"; - else if(docType.equalsIgnoreCase("Loanin")) - prefix = "loansin_common:"; - else if(docType.equalsIgnoreCase("Acquisition")) - prefix = "acquisitions_common:"; - */ Collection fields = authRefFields.values(); for (String field : fields) { // Build up the where clause for each authRef field @@ -201,15 +191,18 @@ public class RefNameServiceUtils { // such as "fieldCollectors", of a repeatable authority reference // field, such as "fieldCollector". Object fieldValue = docModel.getProperty(strings[0], strings[1]); - fRefFound = refNameFoundInField(refName, fieldValue); - if (fRefFound) { + boolean fRefMatches = refNameFoundInField(refName, fieldValue); + if (fRefMatches) { sourceField = authRefDescendantField; - ilistItem.setSourceField(sourceField); - // FIXME Returns only the first field in which the refName is found. - // We may want to return all; this may require multiple sourceFields - // in the list item schema; or else multiple list items, one per sourceField. - // See CSPACE-2863 for a discussion of how this might be handled. - break; + // Handle multiple fields matching in one Doc. See CSPACE-2863. + if(fRefFound) { + // We already added ilistItem, so we need to clone that and add again + ilistItem = cloneAuthRefDocItem(ilistItem, sourceField); + } else { + ilistItem.setSourceField(sourceField); + fRefFound = true; + } + list.add(ilistItem); } } catch (ClientException ce) { @@ -217,31 +210,26 @@ public class RefNameServiceUtils { "getAuthorityRefDocs: Problem fetching: " + sourceField, ce); } } - // Used before going to schema-qualified field names. - /* - for(String field:matchingAuthRefFields){ - try { - if(refName.equals(docModel.getPropertyValue(field))) { - ilistItem.setSourceField(field); - fRefFound = true; - break; - } - } catch(ClientException ce) { - throw new RuntimeException( - "getAuthorityRefDocs: Problem fetching: "+field, ce); - } - } - * - */ if (!fRefFound) { throw new RuntimeException( "getAuthorityRefDocs: Could not find refname in object:" + docType + ":" + csid); } - list.add(ilistItem); } return wrapperList; } + + private static AuthorityRefDocList.AuthorityRefDocItem cloneAuthRefDocItem( + AuthorityRefDocList.AuthorityRefDocItem ilistItem, String sourceField) { + AuthorityRefDocList.AuthorityRefDocItem newlistItem = new AuthorityRefDocList.AuthorityRefDocItem(); + newlistItem.setDocId(ilistItem.getDocId()); + newlistItem.setDocName(ilistItem.getDocName()); + newlistItem.setDocNumber(ilistItem.getDocNumber()); + newlistItem.setDocType(ilistItem.getDocType()); + newlistItem.setUri(ilistItem.getUri()); + newlistItem.setSourceField(sourceField); + return newlistItem; + } /* * Identifies whether the refName was found in the supplied field. diff --git a/services/intake/client/src/test/java/org/collectionspace/services/client/test/OrganizationAuthRefDocsTest.java b/services/intake/client/src/test/java/org/collectionspace/services/client/test/OrganizationAuthRefDocsTest.java index 192b16d2f..1bd7ae13d 100644 --- a/services/intake/client/src/test/java/org/collectionspace/services/client/test/OrganizationAuthRefDocsTest.java +++ b/services/intake/client/src/test/java/org/collectionspace/services/client/test/OrganizationAuthRefDocsTest.java @@ -121,7 +121,8 @@ public class OrganizationAuthRefDocsTest extends BaseServiceTest { "entryNumber-" + identifier, "entryDate-" + identifier, currentOwnerRefName, - depositorRefName, + // Use currentOwnerRefName twice to test fix for CSPACE-2863 + currentOwnerRefName, //depositorRefName, conditionCheckerAssessorRefName, insurerRefName, valuerRefName ); @@ -249,7 +250,7 @@ public class OrganizationAuthRefDocsTest extends BaseServiceTest { // Optionally output additional data about list members for debugging. boolean iterateThroughList = true; - boolean fFoundIntake = false; + int nIntakesFound = 0; if(iterateThroughList && logger.isDebugEnabled()){ List items = list.getAuthorityRefDocItem(); @@ -262,12 +263,13 @@ public class OrganizationAuthRefDocsTest extends BaseServiceTest { item.getDocName() + "] Number:[" + item.getDocNumber() + "] in field:[" + item.getSourceField() + "]"); - if(!fFoundIntake && knownIntakeId.equalsIgnoreCase(item.getDocId())) { - fFoundIntake = true; + if(knownIntakeId.equalsIgnoreCase(item.getDocId())) { + nIntakesFound++; } i++; } - Assert.assertTrue(fFoundIntake, "Did not find Intake with authref!"); + // + Assert.assertTrue((nIntakesFound==2), "Did not find Intake (twice) with authref!"); } } -- 2.47.3