From b597907127760286817113bfe7eb9f0d35c33870 Mon Sep 17 00:00:00 2001 From: Richard Millet Date: Thu, 3 May 2012 12:56:31 -0700 Subject: [PATCH] CSPACE-5130: Adding special case code for Vocabulary item since we've decided to make them different than the standard authority items. --- .../common/vocabulary/AuthorityResource.java | 18 ++++++++++++++--- .../AuthorityItemDocumentModelHandler.java | 20 +++++++++---------- .../java/RemoteDocumentModelHandlerImpl.java | 2 +- .../vocabulary/VocabularyResource.java | 18 ++++++++++++++--- 4 files changed, 41 insertions(+), 17 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 8f60e0359..0fe7c37d7 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 @@ -649,6 +649,20 @@ public abstract class AuthorityResource return result.getBytes(); } + /* + * Most of the authority child classes will use this method. However, the Vocabulary service's item schema is + * different enough that it will have to override this method in it's resource class. + */ + protected String getQualifiedDisplayNameField() { + String result = null; + + result = NuxeoUtils.getPrimaryElPathPropertyName( + authorityItemCommonSchemaName, getItemTermInfoGroupXPathBase(), + AuthorityItemJAXBSchema.TERM_DISPLAY_NAME); + + return result; + } + /** * Gets the authorityItem list for the specified authority * If partialPerm is specified, keywords will be ignored. @@ -672,9 +686,7 @@ public abstract class AuthorityResource String keywords = queryParams.getFirst(IQueryManager.SEARCH_TYPE_KEYWORDS_KW); String advancedSearch = queryParams.getFirst(IQueryManager.SEARCH_TYPE_KEYWORDS_AS); - String qualifiedDisplayNameField = - NuxeoUtils.getPrimaryElPathPropertyName(authorityItemCommonSchemaName, - getItemTermInfoGroupXPathBase(), AuthorityItemJAXBSchema.TERM_DISPLAY_NAME); + String qualifiedDisplayNameField = getQualifiedDisplayNameField(); // Note that docType defaults to the ServiceName, so we're fine with that. ServiceContext ctx = null; diff --git a/services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/nuxeo/AuthorityItemDocumentModelHandler.java b/services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/nuxeo/AuthorityItemDocumentModelHandler.java index fb58dcd1a..904a67307 100644 --- a/services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/nuxeo/AuthorityItemDocumentModelHandler.java +++ b/services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/nuxeo/AuthorityItemDocumentModelHandler.java @@ -154,7 +154,7 @@ public abstract class AuthorityItemDocumentModelHandler for (int i = 0; i < nFields; i++) { ListResultField field = list.get(i); String elName = field.getElement(); - if (AuthorityItemJAXBSchema.TERM_DISPLAY_NAME.equals(elName)) { + if (AuthorityItemJAXBSchema.TERM_DISPLAY_NAME.equals(elName)) { //FIXME: Add a special if-case for Vocabulary item's displayName hasDisplayName = true; } else if (AuthorityItemJAXBSchema.SHORT_IDENTIFIER.equals(elName)) { hasShortId = true; @@ -167,7 +167,7 @@ public abstract class AuthorityItemDocumentModelHandler ListResultField field; if (!hasDisplayName) { field = new ListResultField(); - // Per CSPACE-5132, the name of this element remains 'displayName' + // Per CSPACE-5132, the name of this element remains 'displayName' //FIXME: Add a special case again for Vocab item's displayName // for backwards compatibility, although its value is obtained // from the termDisplayName field. // @@ -238,7 +238,7 @@ public abstract class AuthorityItemDocumentModelHandler // First, get a copy of the old displayName // oldDisplayNameOnUpdate = (String) wrapDoc.getWrappedObject().getProperty(authorityItemCommonSchemaName, // AuthorityItemJAXBSchema.DISPLAY_NAME); - oldDisplayNameOnUpdate = (String) getStringValueInPrimaryRepeatingComplexProperty( + oldDisplayNameOnUpdate = (String) getStringValueInPrimaryRepeatingComplexProperty( //FIXME - This won't work for vocabulary items wrapDoc.getWrappedObject(), authorityItemCommonSchemaName, getItemTermInfoGroupXPathBase(), AuthorityItemJAXBSchema.TERM_DISPLAY_NAME); @@ -248,7 +248,7 @@ public abstract class AuthorityItemDocumentModelHandler // handleComputedDisplayNames(wrapDoc.getWrappedObject()); // String newDisplayName = (String) wrapDoc.getWrappedObject().getProperty(authorityItemCommonSchemaName, // AuthorityItemJAXBSchema.DISPLAY_NAME); - String newDisplayName = (String) getStringValueInPrimaryRepeatingComplexProperty( + String newDisplayName = (String) getStringValueInPrimaryRepeatingComplexProperty( //FIXME - This won't work for vocabulary items wrapDoc.getWrappedObject(), authorityItemCommonSchemaName, this.authorityItemTermGroupXPathBase, AuthorityItemJAXBSchema.TERM_DISPLAY_NAME); @@ -268,9 +268,9 @@ public abstract class AuthorityItemDocumentModelHandler * @param docModel the doc model * @throws Exception the exception */ - protected void handleComputedDisplayNames(DocumentModel docModel) throws Exception { - // Do nothing by default. - } +// protected void handleComputedDisplayNames(DocumentModel docModel) throws Exception { +// // Do nothing by default. +// } /** * Handle refName updates for changes to display name. @@ -331,12 +331,12 @@ public abstract class AuthorityItemDocumentModelHandler private void handleDisplayNameAsShortIdentifier(DocumentModel docModel, String schemaName) throws Exception { String shortIdentifier = (String) docModel.getProperty(schemaName, AuthorityItemJAXBSchema.SHORT_IDENTIFIER); String termDisplayName = - (String) getStringValueInPrimaryRepeatingComplexProperty( + (String) getStringValueInPrimaryRepeatingComplexProperty( //FIXME - This won't work for vocabulary items docModel, authorityItemCommonSchemaName, getItemTermInfoGroupXPathBase(), AuthorityItemJAXBSchema.TERM_DISPLAY_NAME); String termName = - (String) getStringValueInPrimaryRepeatingComplexProperty( + (String) getStringValueInPrimaryRepeatingComplexProperty( //FIXME - This won't work for vocabulary items docModel, authorityItemCommonSchemaName, getItemTermInfoGroupXPathBase(), AuthorityItemJAXBSchema.TERM_NAME); @@ -364,7 +364,7 @@ public abstract class AuthorityItemDocumentModelHandler DocumentModel docModel = wrapDoc.getWrappedObject(); String shortIdentifier = (String) docModel.getProperty(schemaName, AuthorityItemJAXBSchema.SHORT_IDENTIFIER); String displayName = - (String) getStringValueInPrimaryRepeatingComplexProperty( + (String) getStringValueInPrimaryRepeatingComplexProperty( //FIXME - This won't work for vocabulary items docModel, authorityItemCommonSchemaName, getItemTermInfoGroupXPathBase(), AuthorityItemJAXBSchema.TERM_DISPLAY_NAME); 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 8717b8af2..95d82fb24 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 @@ -671,7 +671,7 @@ public abstract class RemoteDocumentModelHandlerImpl * @param listName The name of the scalar list property * @return first value in list, as a String, or empty string if the list is empty */ - protected String getStringValueInPrimaryRepeatingComplexProperty( + protected String getStringValueInPrimaryRepeatingComplexProperty( //FIXME - This won't work for vocabulary items DocumentModel docModel, String schema, String complexPropertyName, String fieldName) { String xpath = "/" + NuxeoUtils.getPrimaryXPathPropertyName(schema, complexPropertyName, fieldName); try { diff --git a/services/vocabulary/service/src/main/java/org/collectionspace/services/vocabulary/VocabularyResource.java b/services/vocabulary/service/src/main/java/org/collectionspace/services/vocabulary/VocabularyResource.java index cca28407f..c2f448da2 100644 --- a/services/vocabulary/service/src/main/java/org/collectionspace/services/vocabulary/VocabularyResource.java +++ b/services/vocabulary/service/src/main/java/org/collectionspace/services/vocabulary/VocabularyResource.java @@ -25,7 +25,9 @@ package org.collectionspace.services.vocabulary; import org.collectionspace.services.client.VocabularyClient; import org.collectionspace.services.common.context.ServiceBindingUtils; +import org.collectionspace.services.common.vocabulary.AuthorityItemJAXBSchema; import org.collectionspace.services.common.vocabulary.AuthorityResource; +import org.collectionspace.services.nuxeo.util.NuxeoUtils; import org.collectionspace.services.vocabulary.nuxeo.VocabularyItemDocumentModelHandler; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -74,11 +76,21 @@ public class VocabularyResource extends protected String getRefPropName() { return ServiceBindingUtils.TERM_REF_PROP; } + + protected String getQualifiedDisplayNameField() { + String result = null; + result = authorityItemCommonSchemaName + ":" + VocabularyItemJAXBSchema.DISPLAY_NAME; + + return result; + } + + /* + * The item schema for the Vocabulary service does not support a multi-valued term list. Only authorities that support + * term lists need to implement this method. + */ @Override public String getItemTermInfoGroupXPathBase() { - // TODO Auto-generated method stub - return VocabularyClient.TERM_INFO_GROUP_XPATH_BASE; + throw new UnsupportedOperationException("operation not relevant for AccountDocumentHandler"); } - } -- 2.47.3