From 68525ff735d108454ea7d7111becea910240105d Mon Sep 17 00:00:00 2001 From: Richard Millet Date: Tue, 4 Sep 2012 23:02:22 -0700 Subject: [PATCH] CSPACE-5488: More refactoring authority item partial term searches to work in resource super classes. --- .../common/vocabulary/AuthorityResource.java | 5 +- ...tMultiPartCollectionSpaceResourceImpl.java | 4 ++ .../services/common/ResourceBase.java | 48 +++++++++++++++++++ .../document/AbstractDocumentHandlerImpl.java | 4 +- .../java/RemoteDocumentModelHandlerImpl.java | 45 ++--------------- 5 files changed, 60 insertions(+), 46 deletions(-) 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 febb685fd..1493735ad 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 @@ -653,7 +653,7 @@ public abstract class AuthorityResource * different enough that it will have to override this method in it's resource class. */ @Override - protected String getOrderByField() { + protected String getOrderByField(ServiceContext ctx) { String result = null; result = NuxeoUtils.getPrimaryElPathPropertyName( @@ -663,7 +663,8 @@ public abstract class AuthorityResource return result; } - protected String getPartialTermMatchField() { + @Override + protected String getPartialTermMatchField(ServiceContext ctx) { String result = null; result = NuxeoUtils.getMultiElPathPropertyName( diff --git a/services/common/src/main/java/org/collectionspace/services/common/AbstractMultiPartCollectionSpaceResourceImpl.java b/services/common/src/main/java/org/collectionspace/services/common/AbstractMultiPartCollectionSpaceResourceImpl.java index 95f067c37..d7dab54da 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/AbstractMultiPartCollectionSpaceResourceImpl.java +++ b/services/common/src/main/java/org/collectionspace/services/common/AbstractMultiPartCollectionSpaceResourceImpl.java @@ -63,7 +63,11 @@ public abstract class AbstractMultiPartCollectionSpaceResourceImpl extends Abstr public ServiceContextFactory getServiceContextFactory() { return MultipartServiceContextFactory.get(); } + + abstract protected String getOrderByField(ServiceContext ctx); + abstract protected String getPartialTermMatchField(ServiceContext ctx); + @Override public DocumentHandler createDocumentHandler(ServiceContext ctx) throws Exception { return createDocumentHandler(ctx, ctx.getCommonPartLabel(), getCommonPartClass()); diff --git a/services/common/src/main/java/org/collectionspace/services/common/ResourceBase.java b/services/common/src/main/java/org/collectionspace/services/common/ResourceBase.java index 8c21ffb1a..a0c0731f3 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/ResourceBase.java +++ b/services/common/src/main/java/org/collectionspace/services/common/ResourceBase.java @@ -29,6 +29,7 @@ import org.collectionspace.services.client.PoxPayloadOut; import org.collectionspace.services.common.api.RefName; import org.collectionspace.services.common.api.Tools; import org.collectionspace.services.common.authorityref.AuthorityRefList; +import org.collectionspace.services.common.config.ServiceConfigUtils; import org.collectionspace.services.common.context.ServiceContext; import org.collectionspace.services.common.document.DocumentFilter; import org.collectionspace.services.common.document.DocumentHandler; @@ -37,6 +38,8 @@ import org.collectionspace.services.common.query.QueryManager; import org.collectionspace.services.common.vocabulary.RefNameServiceUtils; import org.collectionspace.services.common.vocabulary.RefNameServiceUtils.AuthRefConfigInfo; import org.collectionspace.services.config.ClientType; +import org.collectionspace.services.config.service.DocHandlerParams; +import org.collectionspace.services.config.service.ListResultField; import org.collectionspace.services.jaxb.AbstractCommonList; import org.collectionspace.services.nuxeo.client.java.DocumentModelHandler; import org.jboss.resteasy.plugins.providers.multipart.MultipartInput; @@ -379,6 +382,50 @@ public abstract class ResourceBase } //======================== UTILITY : getDocModelForRefName ======================================== + + /* + * 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(ServiceContext ctx) { + String result = null; + + DocHandlerParams.Params params = null; + try { + result = getPartialTermMatchField(ctx); + if (result == null) { + throw new Exception(); + } + } catch (Exception e) { + if (logger.isWarnEnabled()) { + logger.warn(String.format("Call failed to getOrderByField() for class %s", this.getClass().getName())); + } + } + + return result; + } + + @Override + protected String getPartialTermMatchField(ServiceContext ctx) { + String result = null; + + DocHandlerParams.Params params = null; + try { + params = ServiceConfigUtils.getDocHandlerParams(ctx); + ListResultField field = params.getRefnameDisplayNameField(); + result = field.getSchema() + ":" + field.getXpath(); + } catch (Exception e) { + if (logger.isWarnEnabled()) { + logger.warn(String.format("Call failed to getPartialTermMatchField() for class %s", this.getClass().getName())); + } + } + + return result; + } + /* * ResourceBase create and update calls will set the resourceMap into the service context * for all inheriting resource classes. Just use ServiceContext.getResourceMap() to get @@ -408,4 +455,5 @@ public abstract class ResourceBase return getDocModelForAuthorityItem(repoSession, RefName.AuthorityItem.parse(refName)); } + } 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 6b8b52c89..aba1a6dbc 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 @@ -69,9 +69,7 @@ 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 f4d1f4598..acd520a31 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 @@ -50,6 +50,7 @@ import org.collectionspace.services.client.RelationClient; import org.collectionspace.services.client.workflow.WorkflowClient; import org.collectionspace.services.common.ResourceBase; import org.collectionspace.services.common.authorityref.AuthorityRefList; +import org.collectionspace.services.common.config.ServiceConfigUtils; import org.collectionspace.services.common.context.JaxRsContext; import org.collectionspace.services.common.context.MultipartServiceContext; import org.collectionspace.services.common.context.ServiceBindingUtils; @@ -119,62 +120,24 @@ public abstract class RemoteDocumentModelHandlerImpl + MultipartServiceContext.class.getName()); } } - - /* - * Returns the document handler parameters that were loaded at startup from the - * tenant bindings config file. - */ - public DocHandlerParams.Params getDocHandlerParams() throws DocumentException { - MultipartServiceContext sc = (MultipartServiceContext) getServiceContext(); - ServiceBindingType sb = sc.getServiceBinding(); - DocHandlerParams dhb = sb.getDocHandlerParams(); - if (dhb != null && dhb.getParams() != null) { - return dhb.getParams(); - } - throw new DocumentException("No DocHandlerParams configured for: " - + sb.getName()); - } @Override 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; + ServiceContext ctx = this.getServiceContext(); DocHandlerParams.Params params = null; try { - params = getDocHandlerParams(); + params = ServiceConfigUtils.getDocHandlerParams(ctx); ListResultField field = params.getRefnameDisplayNameField(); String schema = field.getSchema(); if (schema == null || schema.trim().isEmpty()) { - schema = getServiceContext().getCommonPartLabel(); + schema = ctx.getCommonPartLabel(); } result = getStringValue(docModel, schema, field); -- 2.47.3