]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
CSPACE-4989, CSPACE-4115 Simplified queries that compute the referencing objects...
authorPatrick Schmitz <pschmitz@berkeley.edu>
Sat, 9 Jun 2012 00:09:11 +0000 (17:09 -0700)
committerPatrick Schmitz <pschmitz@berkeley.edu>
Sat, 9 Jun 2012 00:09:11 +0000 (17:09 -0700)
services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/AuthorityResource.java
services/common/src/main/java/org/collectionspace/services/common/vocabulary/RefNameServiceUtils.java

index cdf3b4c8b579872c7db6aa4f0b3f7b801c4f41cd..058f67a64860e6c490cc5cfe4cf8becfcf49c998 100644 (file)
@@ -798,9 +798,7 @@ public abstract class AuthorityResource<AuthCommon, AuthItemHandler>
 
             List<String> serviceTypes = queryParams.remove(ServiceBindingUtils.SERVICE_TYPE_PROP);
             if(serviceTypes == null || serviceTypes.isEmpty()) {
-                // Temporary workaround for CSPACE-4983
-               // serviceTypes = ServiceBindingUtils.getCommonServiceTypes();
-                serviceTypes = ServiceBindingUtils.getCommonProcedureServiceTypes();
+               serviceTypes = ServiceBindingUtils.getCommonServiceTypes();
             }
             
             // Note that we have to create the service context for the Items, not the main service
index 4c381d6908569eb24ac76a410ce22dd373bee9bb..5e01c243026f03bf0a72ce8dda352d979c2a0c16 100644 (file)
@@ -46,7 +46,9 @@ import org.collectionspace.services.client.PoxPayloadOut;
 import org.collectionspace.services.common.ServiceMain;\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
@@ -55,6 +57,7 @@ import org.collectionspace.services.common.document.DocumentException;
 import org.collectionspace.services.common.document.DocumentNotFoundException;\r
 import org.collectionspace.services.common.document.DocumentUtils;\r
 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.nuxeo.client.java.DocHandlerBase;\r
 import org.collectionspace.services.nuxeo.client.java.RepositoryJavaClientImpl;\r
@@ -314,6 +317,10 @@ public class RefNameServiceUtils {
                                nRefsFound += nRefsFoundThisPage;\r
                        }\r
                        pageNumProcessed++;\r
+                       if(docList.size()<pageSize) {\r
+                               logger.debug("updateAuthorityRefDocs: assuming no more results, as nResults < pageSize");\r
+                               break;\r
+                       }\r
                }\r
         } catch (Exception e) {\r
                logger.error("Internal error updating the AuthorityRefDocs: " + e.getLocalizedMessage());\r
@@ -347,12 +354,9 @@ public class RefNameServiceUtils {
         // Filter the list for current user rights\r
         servicebindings = SecurityUtils.getReadableServiceBindingsForCurrentUser(servicebindings);\r
         \r
-        // Need to escape the quotes in the refName\r
-        // TODO What if they are already escaped?\r
-        String escapedRefName = refName.replaceAll("'", "\\\\'");\r
         ArrayList<String> docTypes = new ArrayList<String>();\r
         \r
-        String query = computeWhereClauseForAuthorityRefDocs(escapedRefName, refPropName, docTypes, servicebindings, \r
+        String query = computeWhereClauseForAuthorityRefDocs(refName, refPropName, docTypes, servicebindings, \r
                                                                                                queriedServiceBindings, authRefFieldsByService );\r
         if (query == null) { // found no authRef fields - nothing to query\r
             return null;\r
@@ -369,13 +373,13 @@ public class RefNameServiceUtils {
     private static final boolean READY_FOR_COMPLEX_QUERY = true;\r
     \r
     private static String computeWhereClauseForAuthorityRefDocs(\r
-               String escapedRefName,\r
+               String refName,\r
                String refPropName,\r
                ArrayList<String> docTypes,\r
                List<ServiceBindingType> servicebindings,\r
                Map<String, ServiceBindingType> queriedServiceBindings,\r
                Map<String, List<AuthRefConfigInfo>> authRefFieldsByService ) {\r
-        StringBuilder whereClause = new StringBuilder();\r
+\r
         boolean fFirst = true;\r
         List<String> authRefFieldPaths;\r
         for (ServiceBindingType sb : servicebindings) {\r
@@ -397,35 +401,30 @@ public class RefNameServiceUtils {
             queriedServiceBindings.put(docType, sb);\r
             authRefFieldsByService.put(docType, authRefsInfo);\r
             docTypes.add(docType);\r
-            for (AuthRefConfigInfo arci : authRefsInfo) {\r
-                // Build up the where clause for each authRef field\r
-               if(!READY_FOR_COMPLEX_QUERY) {  // filter complex field references\r
-                       if(arci.pathEls.length>1)\r
-                               continue;                               // skip this one\r
-               }\r
-                if (fFirst) {\r
-                    fFirst = false;\r
-                } else {\r
-                    whereClause.append(" OR ");\r
-                }\r
-                //whereClause.append(prefix);\r
-                whereClause.append(arci.getFullPath());\r
-                whereClause.append("='");\r
-                whereClause.append(escapedRefName);\r
-                whereClause.append("'");\r
-            }\r
+            fFirst = false;\r
+        }\r
+        if (fFirst) { // found no authRef fields - nothing to query\r
+            return null;\r
         }\r
+        // We used to build a complete matches query, but that was too complex.\r
+        // Just build a keyword query based upon some key pieces - the urn syntax elements and the shortID\r
+        // Note that this will also match the Item itself, but that will get filtered out when\r
+        // we compute actual matches.\r
+        AuthorityTermInfo authTermInfo = RefNameUtils.parseAuthorityTermInfo(refName);\r
+               \r
+        String keywords = RefNameUtils.URN_PREFIX \r
+                                       + " AND " + (authTermInfo.inAuthority.name!=null?\r
+                                                       authTermInfo.inAuthority.name:authTermInfo.inAuthority.csid)\r
+                                       + " AND " + (authTermInfo.name!=null?\r
+                                                       authTermInfo.name:authTermInfo.csid);\r
+        \r
+        String whereClauseStr = QueryManager.createWhereClauseFromKeywords(keywords);\r
         \r
-        String whereClauseStr = whereClause.toString(); // for debugging\r
         if (logger.isTraceEnabled()) {\r
-               logger.trace("The 'where' clause of the xyz method is: ", whereClauseStr);\r
+               logger.trace("The 'where' clause to find refObjs is: ", whereClauseStr);\r
         }\r
         \r
-        if (fFirst) { // found no authRef fields - nothing to query\r
-            return null;\r
-        } else {\r
-               return whereClause.toString(); \r
-        }\r
+        return whereClauseStr; \r
     }\r
     \r
     /*\r
@@ -519,9 +518,11 @@ public class RefNameServiceUtils {
                         "getAuthorityRefDocs: Problem fetching values from repo: " + ce.getLocalizedMessage());\r
             }\r
             if (nRefsFoundInDoc == 0) {\r
-                throw new RuntimeException(\r
-                        "getAuthorityRefDocs: Could not find refname in object:"\r
-                        + docType + ":" + NuxeoUtils.getCsid(docModel));\r
+                logger.warn(\r
+                        "getAuthorityRefDocs: Result: "\r
+                        + docType + " [" + NuxeoUtils.getCsid(docModel)\r
+                        + "] does not reference ["\r
+                        + refName + "]");\r
             }\r
             nRefsFoundTotal += nRefsFoundInDoc;\r
         }\r