From: Patrick Schmitz Date: Sat, 9 Jun 2012 00:09:11 +0000 (-0700) Subject: CSPACE-4989, CSPACE-4115 Simplified queries that compute the referencing objects... X-Git-Url: https://git.aero2k.de/?a=commitdiff_plain;h=b938805b4c01817bc382be3a72080dbef6464d31;p=tmp%2Fjakarta-migration.git CSPACE-4989, CSPACE-4115 Simplified queries that compute the referencing objects given a refName. Will improve performance, and make the system more stable. Enabled checking Cataloging records, for Used-By computations. --- diff --git a/services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/AuthorityResource.java b/services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/AuthorityResource.java index cdf3b4c8b..058f67a64 100644 --- a/services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/AuthorityResource.java +++ b/services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/AuthorityResource.java @@ -798,9 +798,7 @@ public abstract class AuthorityResource List 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 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 4c381d690..5e01c2430 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 @@ -46,7 +46,9 @@ import org.collectionspace.services.client.PoxPayloadOut; import org.collectionspace.services.common.ServiceMain; import org.collectionspace.services.common.context.ServiceContext; import org.collectionspace.services.common.context.AbstractServiceContextImpl; +import org.collectionspace.services.common.api.RefNameUtils; import org.collectionspace.services.common.api.Tools; +import org.collectionspace.services.common.api.RefNameUtils.AuthorityTermInfo; import org.collectionspace.services.common.authorityref.AuthorityRefDocList; import org.collectionspace.services.common.authorityref.AuthorityRefList; import org.collectionspace.services.common.config.TenantBindingConfigReaderImpl; @@ -55,6 +57,7 @@ import org.collectionspace.services.common.document.DocumentException; import org.collectionspace.services.common.document.DocumentNotFoundException; import org.collectionspace.services.common.document.DocumentUtils; import org.collectionspace.services.common.document.DocumentWrapper; +import org.collectionspace.services.common.query.QueryManager; import org.collectionspace.services.common.repository.RepositoryClient; import org.collectionspace.services.nuxeo.client.java.DocHandlerBase; import org.collectionspace.services.nuxeo.client.java.RepositoryJavaClientImpl; @@ -314,6 +317,10 @@ public class RefNameServiceUtils { nRefsFound += nRefsFoundThisPage; } pageNumProcessed++; + if(docList.size() docTypes = new ArrayList(); - String query = computeWhereClauseForAuthorityRefDocs(escapedRefName, refPropName, docTypes, servicebindings, + String query = computeWhereClauseForAuthorityRefDocs(refName, refPropName, docTypes, servicebindings, queriedServiceBindings, authRefFieldsByService ); if (query == null) { // found no authRef fields - nothing to query return null; @@ -369,13 +373,13 @@ public class RefNameServiceUtils { private static final boolean READY_FOR_COMPLEX_QUERY = true; private static String computeWhereClauseForAuthorityRefDocs( - String escapedRefName, + String refName, String refPropName, ArrayList docTypes, List servicebindings, Map queriedServiceBindings, Map> authRefFieldsByService ) { - StringBuilder whereClause = new StringBuilder(); + boolean fFirst = true; List authRefFieldPaths; for (ServiceBindingType sb : servicebindings) { @@ -397,35 +401,30 @@ public class RefNameServiceUtils { queriedServiceBindings.put(docType, sb); authRefFieldsByService.put(docType, authRefsInfo); docTypes.add(docType); - for (AuthRefConfigInfo arci : authRefsInfo) { - // Build up the where clause for each authRef field - if(!READY_FOR_COMPLEX_QUERY) { // filter complex field references - if(arci.pathEls.length>1) - continue; // skip this one - } - if (fFirst) { - fFirst = false; - } else { - whereClause.append(" OR "); - } - //whereClause.append(prefix); - whereClause.append(arci.getFullPath()); - whereClause.append("='"); - whereClause.append(escapedRefName); - whereClause.append("'"); - } + fFirst = false; + } + if (fFirst) { // found no authRef fields - nothing to query + return null; } + // We used to build a complete matches query, but that was too complex. + // Just build a keyword query based upon some key pieces - the urn syntax elements and the shortID + // Note that this will also match the Item itself, but that will get filtered out when + // we compute actual matches. + AuthorityTermInfo authTermInfo = RefNameUtils.parseAuthorityTermInfo(refName); + + String keywords = RefNameUtils.URN_PREFIX + + " AND " + (authTermInfo.inAuthority.name!=null? + authTermInfo.inAuthority.name:authTermInfo.inAuthority.csid) + + " AND " + (authTermInfo.name!=null? + authTermInfo.name:authTermInfo.csid); + + String whereClauseStr = QueryManager.createWhereClauseFromKeywords(keywords); - String whereClauseStr = whereClause.toString(); // for debugging if (logger.isTraceEnabled()) { - logger.trace("The 'where' clause of the xyz method is: ", whereClauseStr); + logger.trace("The 'where' clause to find refObjs is: ", whereClauseStr); } - if (fFirst) { // found no authRef fields - nothing to query - return null; - } else { - return whereClause.toString(); - } + return whereClauseStr; } /* @@ -519,9 +518,11 @@ public class RefNameServiceUtils { "getAuthorityRefDocs: Problem fetching values from repo: " + ce.getLocalizedMessage()); } if (nRefsFoundInDoc == 0) { - throw new RuntimeException( - "getAuthorityRefDocs: Could not find refname in object:" - + docType + ":" + NuxeoUtils.getCsid(docModel)); + logger.warn( + "getAuthorityRefDocs: Result: " + + docType + " [" + NuxeoUtils.getCsid(docModel) + + "] does not reference [" + + refName + "]"); } nRefsFoundTotal += nRefsFoundInDoc; }