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
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
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
// 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
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
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
"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