]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
CSPACE-5499 Added support to refObjs methods to only match the base of the refName...
authorPatrick Schmitz <pschmitz@berkeley.edu>
Tue, 2 Oct 2012 06:25:55 +0000 (23:25 -0700)
committerPatrick Schmitz <pschmitz@berkeley.edu>
Tue, 2 Oct 2012 06:25:55 +0000 (23:25 -0700)
services/common-api/src/main/java/org/collectionspace/services/common/api/RefNameUtils.java
services/common/src/main/java/org/collectionspace/services/common/vocabulary/RefNameServiceUtils.java

index c159617513afc04d6b56ac9b2a15495153b90daf..78cb700f1aebffa4dca439ba9556157c1092e8b3 100644 (file)
@@ -211,6 +211,16 @@ public class RefNameUtils {
        return new AuthorityTermInfo(refNameTokens);
     }
 
+    public static String stripAuthorityTermDisplayName(String refName)
+            throws IllegalArgumentException {
+       if(refName==null || !refName.startsWith(URN_PREFIX))
+               throw new IllegalArgumentException( "Null or invalid refName syntax");
+       String[] refNameTokens = refName.substring(URN_PREFIX_LEN).split(SEPARATOR, AUTH_ITEM_REFNAME_TOKENS);
+       int rightParen = refNameTokens[ITEM_INSTANCE_TOKEN].indexOf(')');
+       refNameTokens[ITEM_INSTANCE_TOKEN] = refNameTokens[ITEM_INSTANCE_TOKEN].substring(0, rightParen+1);
+       return URN_PREFIX + implodeStringArray(refNameTokens, SEPARATOR);
+    }
+
     public static String implodeStringArray(String tokens[], String separator) {
        if (tokens.length==0) {
                return "";
index 5268d340d6bbd1a481d34729eb2a046ee74d6381..58c5788e1dac3488e35753b2902ce98c5629095a 100644 (file)
@@ -246,7 +246,7 @@ public class RefNameServiceUtils {
             RepositoryClient<PoxPayloadIn, PoxPayloadOut> repoClient,\r
             List<String> serviceTypes,\r
             String refName,\r
-            String refPropName,\r
+            String refPropName, // authRef or termRef, authorities or vocab terms.\r
             DocumentFilter filter, boolean computeTotal)\r
             throws DocumentException, DocumentNotFoundException {\r
         AuthorityRefDocList wrapperList = new AuthorityRefDocList();\r
@@ -298,7 +298,11 @@ 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, ctx.getTenantId(), refName, queriedServiceBindings, authRefFieldsByService, // the actual list size needs to be updated to the size of "list"\r
+\r
+            // Strip off displayName and only match the base, so we get references to all \r
+            // the NPTs as well as the PT.\r
+               String strippedRefName = RefNameUtils.stripAuthorityTermDisplayName(refName);\r
+            int nRefsFound = processRefObjsDocList(docList, ctx.getTenantId(), strippedRefName, true, queriedServiceBindings, authRefFieldsByService, // the actual list size needs to be updated to the size of "list"\r
                     list, null);\r
 \r
             commonList.setPageSize(pageSize);\r
@@ -426,7 +430,9 @@ public class RefNameServiceUtils {
                     morePages = false;\r
                 }\r
 \r
-                int nRefsFoundThisPage = processRefObjsDocList(docList, ctx.getTenantId(), oldRefName, queriedServiceBindings, authRefFieldsByService, // Perform the refName updates on the list of document models\r
+                // Only match complete refNames - unless and until we decide how to resolve changes\r
+                // to NPTs we will defer that and only change PTs or refNames as passed in.\r
+                int nRefsFoundThisPage = processRefObjsDocList(docList, ctx.getTenantId(), oldRefName, false, queriedServiceBindings, authRefFieldsByService, // Perform the refName updates on the list of document models\r
                         null, newRefName);\r
                 if (nRefsFoundThisPage > 0) {\r
                     ((RepositoryJavaClientImpl) repoClient).saveDocListWithoutHandlerProcessing(ctx, repoSession, docList, true); // Flush the document model list out to Nuxeo storage\r
@@ -564,6 +570,7 @@ public class RefNameServiceUtils {
             DocumentModelList docList,\r
             String tenantId,\r
             String refName,\r
+            boolean matchBaseOnly,\r
             Map<String, ServiceBindingType> queriedServiceBindings,\r
             Map<String, List<AuthRefConfigInfo>> authRefFieldsByService,\r
             List<AuthorityRefDocList.AuthorityRefDocItem> list,\r
@@ -652,7 +659,7 @@ public class RefNameServiceUtils {
 \r
             ArrayList<RefNameServiceUtils.AuthRefInfo> foundProps = new ArrayList<RefNameServiceUtils.AuthRefInfo>();\r
             try {\r
-                findAuthRefPropertiesInDoc(docModel, matchingAuthRefFields, refName, foundProps); // REM - side effect that foundProps is set\r
+                findAuthRefPropertiesInDoc(docModel, matchingAuthRefFields, refName, matchBaseOnly, foundProps); // REM - side effect that foundProps is set\r
                 for (RefNameServiceUtils.AuthRefInfo ari : foundProps) {\r
                     if (ilistItem != null) {\r
                         if (nRefsFoundInDoc == 0) {    // First one?\r
@@ -700,6 +707,16 @@ public class RefNameServiceUtils {
             List<AuthRefConfigInfo> authRefFieldInfo,\r
             String refNameToMatch,\r
             List<AuthRefInfo> foundProps) {\r
+       return findAuthRefPropertiesInDoc(docModel, authRefFieldInfo, \r
+                                                                       refNameToMatch, false, foundProps);\r
+    }\r
+    \r
+    public static List<AuthRefInfo> findAuthRefPropertiesInDoc(\r
+            DocumentModel docModel,\r
+            List<AuthRefConfigInfo> authRefFieldInfo,\r
+            String refNameToMatch,\r
+            boolean matchBaseOnly,\r
+            List<AuthRefInfo> foundProps) {\r
         // Assume that authRefFieldInfo is keyed by the field name (possibly mapped for UI)\r
         // and the values are elPaths to the field, where intervening group structures in\r
         // lists of complex structures are replaced with "*". Thus, valid paths include\r
@@ -716,7 +733,7 @@ public class RefNameServiceUtils {
             try {\r
                 // Get first property and work down as needed.\r
                 Property prop = docModel.getProperty(arci.pathEls[0]);\r
-                findAuthRefPropertiesInProperty(foundProps, prop, arci, 0, refNameToMatch);\r
+                findAuthRefPropertiesInProperty(foundProps, prop, arci, 0, refNameToMatch, matchBaseOnly);\r
             } catch (Exception e) {\r
                 logger.error("Problem fetching property: " + arci.pathEls[0]);\r
             }\r
@@ -724,12 +741,13 @@ public class RefNameServiceUtils {
         return foundProps;\r
     }\r
 \r
-    public static List<AuthRefInfo> findAuthRefPropertiesInProperty(\r
+    private static List<AuthRefInfo> findAuthRefPropertiesInProperty(\r
             List<AuthRefInfo> foundProps,\r
             Property prop,\r
             AuthRefConfigInfo arci,\r
             int pathStartIndex, // Supports recursion and we work down the path\r
-            String refNameToMatch) {\r
+            String refNameToMatch,\r
+            boolean matchBaseOnly ) {\r
         if (pathStartIndex >= arci.pathEls.length) {\r
             throw new ArrayIndexOutOfBoundsException("Index = " + pathStartIndex + " for path: "\r
                     + arci.pathEls.toString());\r
@@ -740,7 +758,7 @@ public class RefNameServiceUtils {
         }\r
 \r
         if (prop instanceof StringProperty) {    // scalar string\r
-            addARIifMatches(refNameToMatch, arci, prop, foundProps);\r
+            addARIifMatches(refNameToMatch, matchBaseOnly, arci, prop, foundProps);\r
         } else if (prop instanceof List) {\r
             List<Property> propList = (List<Property>) prop;\r
             // run through list. Must either be list of Strings, or Complex\r
@@ -751,13 +769,13 @@ public class RefNameServiceUtils {
                                 + arci.pathEls.toString());\r
                         break;\r
                     } else {\r
-                        addARIifMatches(refNameToMatch, arci, listItemProp, foundProps);\r
+                        addARIifMatches(refNameToMatch, matchBaseOnly, arci, listItemProp, foundProps);\r
                     }\r
                 } else if (listItemProp.isComplex()) {\r
                     // Just recurse to handle this. Note that since this is a list of complex, \r
                     // which should look like listName/*/... we add 2 to the path start index \r
                     findAuthRefPropertiesInProperty(foundProps, listItemProp, arci,\r
-                            pathStartIndex + 2, refNameToMatch);\r
+                            pathStartIndex + 2, refNameToMatch, matchBaseOnly);\r
                 } else {\r
                     logger.error("Configuration for authRefs does not match schema structure: "\r
                             + arci.pathEls.toString());\r
@@ -770,7 +788,7 @@ public class RefNameServiceUtils {
                 Property localProp = prop.get(localPropName);\r
                 // Now just recurse, pushing down the path 1 step\r
                 findAuthRefPropertiesInProperty(foundProps, localProp, arci,\r
-                        pathStartIndex, refNameToMatch);\r
+                        pathStartIndex, refNameToMatch, matchBaseOnly);\r
             } catch (PropertyNotFoundException pnfe) {\r
                 logger.error("Could not find property: [" + localPropName + "] in path: "\r
                         + arci.getFullPath());\r
@@ -790,6 +808,7 @@ public class RefNameServiceUtils {
 \r
     private static void addARIifMatches(\r
             String refNameToMatch,\r
+            boolean matchBaseOnly,\r
             AuthRefConfigInfo arci,\r
             Property prop,\r
             List<AuthRefInfo> foundProps) {\r
@@ -797,7 +816,10 @@ public class RefNameServiceUtils {
         // OR have no refName to match but be non-empty\r
         try {\r
             String value = (String) prop.getValue();\r
-            if (((refNameToMatch != null) && refNameToMatch.equals(value))\r
+            if (((refNameToMatch != null) && \r
+                               (matchBaseOnly?\r
+                                       (value!=null && value.startsWith(refNameToMatch))\r
+                                       :refNameToMatch.equals(value)))\r
                     || ((refNameToMatch == null) && Tools.notBlank(value))) {\r
                 // Found a match\r
                 logger.debug("Found a match on property: " + prop.getPath() + " with value: [" + value + "]");\r