From 012703e0584b3838c72e71ee069082b2519cfbc6 Mon Sep 17 00:00:00 2001 From: Richard Millet Date: Tue, 4 Sep 2012 16:05:08 -0700 Subject: [PATCH] CSPACE-5488: Refactoring authority item partial term searches to work in resource super classes. --- .../common/vocabulary/AuthorityResource.java | 1 + .../common/config/ServiceConfigUtils.java | 17 +++++++++++++ .../document/AbstractDocumentHandlerImpl.java | 2 ++ .../java/RemoteDocumentModelHandlerImpl.java | 25 ++++++++++++++++++- 4 files changed, 44 insertions(+), 1 deletion(-) 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 1852ce0f4..febb685fd 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 @@ -652,6 +652,7 @@ public abstract class AuthorityResource * Most of the authority child classes will/should use this implementation. However, the Vocabulary service's item schema is * different enough that it will have to override this method in it's resource class. */ + @Override protected String getOrderByField() { String result = null; diff --git a/services/common/src/main/java/org/collectionspace/services/common/config/ServiceConfigUtils.java b/services/common/src/main/java/org/collectionspace/services/common/config/ServiceConfigUtils.java index be56353ed..e79d3dc80 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/config/ServiceConfigUtils.java +++ b/services/common/src/main/java/org/collectionspace/services/common/config/ServiceConfigUtils.java @@ -26,9 +26,12 @@ package org.collectionspace.services.common.config; import java.util.ArrayList; import java.util.List; +import org.collectionspace.services.common.context.ServiceContext; +import org.collectionspace.services.common.document.DocumentException; import org.collectionspace.services.common.document.DocumentHandler; import org.collectionspace.services.config.RepositoryClientConfigType; import org.collectionspace.services.config.ServiceConfig; +import org.collectionspace.services.config.service.DocHandlerParams; import org.collectionspace.services.config.service.ServiceBindingType; import org.collectionspace.services.config.tenant.TenantBindingType; import org.collectionspace.services.config.types.PropertyItemType; @@ -44,6 +47,20 @@ public class ServiceConfigUtils { final static Logger logger = LoggerFactory.getLogger(ServiceConfigUtils.class); + /* + * Returns the document handler parameters that were loaded at startup from the + * tenant bindings config file. + */ + public static DocHandlerParams.Params getDocHandlerParams(ServiceContext ctx) throws DocumentException { + ServiceBindingType sb = ctx.getServiceBinding(); + DocHandlerParams dhb = sb.getDocHandlerParams(); + if (dhb != null && dhb.getParams() != null) { + return dhb.getParams(); + } + throw new DocumentException("No DocHandlerParams configured for: " + + sb.getName()); + } + /** * Creates the document handler instance. * diff --git a/services/common/src/main/java/org/collectionspace/services/common/document/AbstractDocumentHandlerImpl.java b/services/common/src/main/java/org/collectionspace/services/common/document/AbstractDocumentHandlerImpl.java index e130ac95c..6b8b52c89 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/document/AbstractDocumentHandlerImpl.java +++ b/services/common/src/main/java/org/collectionspace/services/common/document/AbstractDocumentHandlerImpl.java @@ -70,6 +70,8 @@ public abstract class AbstractDocumentHandlerImpl abstract protected String getRefnameDisplayName(DocumentWrapper docWrapper); + abstract protected String getOrderByField(); + /* * Should return a reference name for the wrapper object */ diff --git a/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RemoteDocumentModelHandlerImpl.java b/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RemoteDocumentModelHandlerImpl.java index 7ac8b2c87..f4d1f4598 100644 --- a/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RemoteDocumentModelHandlerImpl.java +++ b/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RemoteDocumentModelHandlerImpl.java @@ -139,6 +139,30 @@ public abstract class RemoteDocumentModelHandlerImpl protected String getRefnameDisplayName(DocumentWrapper docWrapper) { return getRefnameDisplayName(docWrapper.getWrappedObject()); } + + /* + * Used get the order by field for list results if one is not specified with an HTTP query param. + * + * (non-Javadoc) + * @see org.collectionspace.services.common.document.AbstractDocumentHandlerImpl#getOrderByField() + */ + @Override + protected String getOrderByField() { + String result = null; + + DocHandlerParams.Params params = null; + try { + params = getDocHandlerParams(); + ListResultField field = params.getRefnameDisplayNameField(); + result = field.getSchema() + ":" + field.getXpath(); + } catch (Exception e) { + if (logger.isWarnEnabled()) { + logger.warn(String.format("Call failed to getOrderByField() for class %s", this.getClass().getName())); + } + } + + return result; + } private String getRefnameDisplayName(DocumentModel docModel) { // Look in the tenant bindings to see what field should be our display name for our refname value String result = null; @@ -155,7 +179,6 @@ public abstract class RemoteDocumentModelHandlerImpl result = getStringValue(docModel, schema, field); } catch (Exception e) { - // TODO Auto-generated catch block if (logger.isWarnEnabled()) { logger.warn(String.format("Call failed to getRefnameDisplayName() for class %s", this.getClass().getName())); } -- 2.47.3