this.authorityRefNameBase = value;
}
+ /*
+ * Note that the Vocabulary service's item-documentmodel-handler will override this method.
+ */
+ protected ListResultField getListResultField() {
+ ListResultField result = new ListResultField();
+ // Per CSPACE-5132, the name of this element remains 'displayName'
+ // for backwards compatibility, although its value is obtained
+ // from the termDisplayName field.
+ //
+ // In CSPACE-5134, these list results will change substantially
+ // to return display names for both the preferred term and for
+ // each non-preferred term (if any).
+ result.setElement(AuthorityItemJAXBSchema.DISPLAY_NAME);
+ result.setXpath(NuxeoUtils.getPrimaryXPathPropertyName(
+ authorityItemCommonSchemaName, getItemTermInfoGroupXPathBase(), AuthorityItemJAXBSchema.TERM_DISPLAY_NAME));
+
+ return result;
+ }
+
@Override
public List<ListResultField> getListItemsArray() throws DocumentException {
List<ListResultField> list = super.getListItemsArray();
for (int i = 0; i < nFields; i++) {
ListResultField field = list.get(i);
String elName = field.getElement();
- if (AuthorityItemJAXBSchema.TERM_DISPLAY_NAME.equals(elName)) { //FIXME: Add a special if-case for Vocabulary item's displayName
+ if (AuthorityItemJAXBSchema.TERM_DISPLAY_NAME.equals(elName) || AuthorityItemJAXBSchema.DISPLAY_NAME.equals(elName)) {
hasDisplayName = true;
} else if (AuthorityItemJAXBSchema.SHORT_IDENTIFIER.equals(elName)) {
hasShortId = true;
}
ListResultField field;
if (!hasDisplayName) {
- field = new ListResultField();
- // 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.
- //
- // In CSPACE-5134, these list results will change substantially
- // to return display names for both the preferred term and for
- // each non-preferred term (if any).
- field.setElement(AuthorityItemJAXBSchema.DISPLAY_NAME);
- field.setXpath(NuxeoUtils.getPrimaryXPathPropertyName(
- authorityItemCommonSchemaName, getItemTermInfoGroupXPathBase(), AuthorityItemJAXBSchema.TERM_DISPLAY_NAME));
+ field = getListResultField();
list.add(field);
}
if (!hasShortId) {
authorityItemCommonSchemaName, getItemTermInfoGroupXPathBase(), AuthorityItemJAXBSchema.TERM_STATUS));
list.add(field);
}
+
return list;
-
}
super.handleCreate(wrapDoc);
// Ensure we have required fields set properly
handleInAuthority(wrapDoc.getWrappedObject());
-
- // CSPACE-4813
- /*
- handleComputedDisplayNames(wrapDoc.getWrappedObject());
- String displayName = (String) wrapDoc.getWrappedObject().getProperty(authorityItemCommonSchemaName,
- AuthorityItemJAXBSchema.DISPLAY_NAME);
- if (Tools.isEmpty(displayName)) {
- logger.warn("Creating Authority Item with no displayName!");
- }
- *
- */
// CSPACE-3178:
// handleDisplayNameAsShortIdentifier(wrapDoc.getWrappedObject(), authorityItemCommonSchemaName);
updateRefnameForAuthorityItem(wrapDoc, authorityItemCommonSchemaName, getAuthorityRefNameBase());
}
+ /*
+ * Note that the Vocabulary service's document-model for items overrides this method.
+ */
+ protected String getPrimaryDisplayName(DocumentModel docModel, String schema,
+ String complexPropertyName, String fieldName) {
+ String result = null;
+
+ result = getStringValueInPrimaryRepeatingComplexProperty(docModel, schema, complexPropertyName, fieldName);
+
+ return result;
+ }
+
/* (non-Javadoc)
* @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#handleUpdate(org.collectionspace.services.common.document.DocumentWrapper)
*/
// First, get a copy of the old displayName
// oldDisplayNameOnUpdate = (String) wrapDoc.getWrappedObject().getProperty(authorityItemCommonSchemaName,
// AuthorityItemJAXBSchema.DISPLAY_NAME);
- oldDisplayNameOnUpdate = (String) getStringValueInPrimaryRepeatingComplexProperty( //FIXME - This won't work for vocabulary items
- wrapDoc.getWrappedObject(), authorityItemCommonSchemaName,
- getItemTermInfoGroupXPathBase(),
- AuthorityItemJAXBSchema.TERM_DISPLAY_NAME);
+ oldDisplayNameOnUpdate = getPrimaryDisplayName(wrapDoc.getWrappedObject(), authorityItemCommonSchemaName,
+ getItemTermInfoGroupXPathBase(), AuthorityItemJAXBSchema.TERM_DISPLAY_NAME);
oldRefNameOnUpdate = (String) wrapDoc.getWrappedObject().getProperty(authorityItemCommonSchemaName,
AuthorityItemJAXBSchema.REF_NAME);
super.handleUpdate(wrapDoc);
- // handleComputedDisplayNames(wrapDoc.getWrappedObject());
- // String newDisplayName = (String) wrapDoc.getWrappedObject().getProperty(authorityItemCommonSchemaName,
- // AuthorityItemJAXBSchema.DISPLAY_NAME);
- String newDisplayName = (String) getStringValueInPrimaryRepeatingComplexProperty( //FIXME - This won't work for vocabulary items
- wrapDoc.getWrappedObject(), authorityItemCommonSchemaName,
+
+ // Now, check the new display and handle the refname update.
+ String newDisplayName = (String) getPrimaryDisplayName(wrapDoc.getWrappedObject(), authorityItemCommonSchemaName,
this.authorityItemTermGroupXPathBase,
AuthorityItemJAXBSchema.TERM_DISPLAY_NAME);
if (newDisplayName != null && !newDisplayName.equals(oldDisplayNameOnUpdate)) {
* If no short identifier was provided in the input payload, generate a
* short identifier from the preferred term display name or term name.
*/
- private void handleDisplayNameAsShortIdentifier(DocumentModel docModel, String schemaName) throws Exception {
- String shortIdentifier = (String) docModel.getProperty(schemaName, AuthorityItemJAXBSchema.SHORT_IDENTIFIER);
- String termDisplayName =
- (String) getStringValueInPrimaryRepeatingComplexProperty( //FIXME - This won't work for vocabulary items
- docModel, authorityItemCommonSchemaName,
- getItemTermInfoGroupXPathBase(),
- AuthorityItemJAXBSchema.TERM_DISPLAY_NAME);
- String termName =
- (String) getStringValueInPrimaryRepeatingComplexProperty( //FIXME - This won't work for vocabulary items
- docModel, authorityItemCommonSchemaName,
- getItemTermInfoGroupXPathBase(),
- AuthorityItemJAXBSchema.TERM_NAME);
- if (Tools.isEmpty(shortIdentifier)) {
- String generatedShortIdentifier =
- AuthorityIdentifierUtils.generateShortIdentifierFromDisplayName(termDisplayName, termName);
- docModel.setProperty(schemaName, AuthorityItemJAXBSchema.SHORT_IDENTIFIER, generatedShortIdentifier);
- }
- }
+ private void handleDisplayNameAsShortIdentifier(DocumentModel docModel,
+ String schemaName) throws Exception {
+ String shortIdentifier = (String) docModel.getProperty(schemaName,
+ AuthorityItemJAXBSchema.SHORT_IDENTIFIER);
+
+ String termDisplayName = getPrimaryDisplayName(
+ docModel, authorityItemCommonSchemaName,
+ getItemTermInfoGroupXPathBase(),
+ AuthorityItemJAXBSchema.TERM_DISPLAY_NAME);
+
+ String termName = getPrimaryDisplayName(
+ docModel, authorityItemCommonSchemaName,
+ getItemTermInfoGroupXPathBase(),
+ AuthorityItemJAXBSchema.TERM_NAME);
+
+ if (Tools.isEmpty(shortIdentifier)) {
+ String generatedShortIdentifier = AuthorityIdentifierUtils.generateShortIdentifierFromDisplayName(termDisplayName,
+ termName);
+ docModel.setProperty(schemaName, AuthorityItemJAXBSchema.SHORT_IDENTIFIER,
+ generatedShortIdentifier);
+ }
+ }
/**
* Generate a refName for the authority item from the short identifier
String authorityRefBaseName) throws Exception {
DocumentModel docModel = wrapDoc.getWrappedObject();
String shortIdentifier = (String) docModel.getProperty(schemaName, AuthorityItemJAXBSchema.SHORT_IDENTIFIER);
- String displayName =
- (String) getStringValueInPrimaryRepeatingComplexProperty( //FIXME - This won't work for vocabulary items
- docModel, authorityItemCommonSchemaName,
- getItemTermInfoGroupXPathBase(),
- AuthorityItemJAXBSchema.TERM_DISPLAY_NAME);
+ String displayName = getPrimaryDisplayName(docModel, authorityItemCommonSchemaName,
+ getItemTermInfoGroupXPathBase(), AuthorityItemJAXBSchema.TERM_DISPLAY_NAME);
+
if (Tools.isEmpty(authorityRefBaseName)) {
throw new Exception("Could not create the refName for this authority term, because the refName for its authority parent was empty.");
}
+
RefName.Authority authority = RefName.Authority.parse(authorityRefBaseName);
String refName = RefName.buildAuthorityItem(authority, shortIdentifier, displayName).toString();
docModel.setProperty(schemaName, AuthorityItemJAXBSchema.REF_NAME, refName);
public void setItemTermInfoGroupXPathBase(String itemTermInfoGroupXPathBase) {
this.authorityItemTermGroupXPathBase = itemTermInfoGroupXPathBase;
}
+
+ protected String getAuthorityItemCommonSchemaName() {
+ return authorityItemCommonSchemaName;
+ }
}
* @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( //FIXME - This won't work for vocabulary items
- DocumentModel docModel, String schema, String complexPropertyName, String fieldName) {
+ protected String getStringValueInPrimaryRepeatingComplexProperty(
+ DocumentModel docModel, String schema, String complexPropertyName, String fieldName) {
+ String result = null;
+
String xpath = "/" + NuxeoUtils.getPrimaryXPathPropertyName(schema, complexPropertyName, fieldName);
try {
- return (String)docModel.getPropertyValue(xpath);
+ result = (String)docModel.getPropertyValue(xpath);
} catch(PropertyException pe) {
throw new RuntimeException("Problem retrieving property {"+xpath+"}. Bad propertyNames?"
+pe.getLocalizedMessage());
} catch(IndexOutOfBoundsException ioobe) {
// Nuxeo sometimes handles missing sub, and sometimes does not. Odd.
- return ""; // gracefully handle missing elements
+ result = ""; // gracefully handle missing elements
} catch(ClassCastException cce) {
throw new RuntimeException("Problem retrieving property {"+xpath+"} as String. Not a String property?"
+cce.getLocalizedMessage());
throw new RuntimeException("Unknown problem retrieving property {"+xpath+"}."
+e.getLocalizedMessage());
}
+
+ return result;
}
/**
* @param xpath The XPath expression (without schema prefix)
* @return value the indicated property value as a String
*/
- protected static String getXPathStringValue(DocumentModel docModel, String schema, String xpath) {
- xpath = schema+":"+xpath;
- try {
- Object value = docModel.getPropertyValue(xpath);
- String returnVal = null;
- if(value==null) {
- // Nothing to do - leave returnVal null
- } else if(value instanceof GregorianCalendar) {
- returnVal = DateTimeFormatUtils.formatAsISO8601Timestamp((GregorianCalendar)value);
- } else {
- returnVal = value.toString();
- }
- return returnVal;
- } catch(PropertyException pe) {
- throw new RuntimeException("Problem retrieving property {"+xpath+"}. Bad XPath spec?"
- +pe.getLocalizedMessage());
- } catch(ClassCastException cce) {
- throw new RuntimeException("Problem retrieving property {"+xpath+"} as String. Not a String property?"
- +cce.getLocalizedMessage());
- } catch(IndexOutOfBoundsException ioobe) {
- // Nuxeo seems to handle foo/[0]/bar when it is missing,
- // but not foo/bar[0] (for repeating scalars).
- if(xpath.endsWith("[0]")) { // gracefully handle missing elements
- return "";
- } else {
- String msg = ioobe.getMessage();
- if(msg!=null && msg.equals("Index: 0, Size: 0")) {
- // Some other variant on a missing sub-field; quietly absorb.
- return "";
- } // Otherwise, e.g., for true OOB indices, propagate the exception.
- }
- throw new RuntimeException("Problem retrieving property {"+xpath+"}:"
- +ioobe.getLocalizedMessage());
- } catch(Exception e) {
- throw new RuntimeException("Unknown problem retrieving property {"+xpath+"}."
- +e.getLocalizedMessage());
- }
- }
+ protected static String getXPathStringValue(DocumentModel docModel,
+ String schema, String xpath) {
+ String result = null;
+
+ xpath = schema + ":" + xpath;
+ try {
+ Object value = docModel.getPropertyValue(xpath);
+ String returnVal = null;
+ if (value == null) {
+ // Nothing to do - leave returnVal null
+ } else if (value instanceof GregorianCalendar) {
+ returnVal = DateTimeFormatUtils.formatAsISO8601Timestamp((GregorianCalendar) value);
+ } else {
+ returnVal = value.toString();
+ }
+ result = returnVal;
+ } catch (PropertyException pe) {
+ throw new RuntimeException("Problem retrieving property {" + xpath
+ + "}. Bad XPath spec?" + pe.getLocalizedMessage());
+ } catch (ClassCastException cce) {
+ throw new RuntimeException("Problem retrieving property {" + xpath
+ + "} as String. Not a String property?"
+ + cce.getLocalizedMessage());
+ } catch (IndexOutOfBoundsException ioobe) {
+ // Nuxeo seems to handle foo/[0]/bar when it is missing,
+ // but not foo/bar[0] (for repeating scalars).
+ if (xpath.endsWith("[0]")) { // gracefully handle missing elements
+ result = "";
+ } else {
+ String msg = ioobe.getMessage();
+ if (msg != null && msg.equals("Index: 0, Size: 0")) {
+ // Some other variant on a missing sub-field; quietly
+ // absorb.
+ result = "";
+ } // Otherwise, e.g., for true OOB indices, propagate the
+ // exception.
+ }
+ throw new RuntimeException("Problem retrieving property {" + xpath
+ + "}:" + ioobe.getLocalizedMessage());
+ } catch (Exception e) {
+ throw new RuntimeException("Unknown problem retrieving property {"
+ + xpath + "}." + e.getLocalizedMessage());
+ }
+
+ return result;
+ }
}
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.nuxeo.AuthorityItemDocumentModelHandler;
+import org.collectionspace.services.config.service.ListResultField;
+import org.collectionspace.services.nuxeo.util.NuxeoUtils;
import org.collectionspace.services.vocabulary.VocabularyitemsCommon;
+import org.nuxeo.ecm.core.api.ClientException;
+import org.nuxeo.ecm.core.api.DocumentModel;
/**
* VocabularyItemDocumentModelHandler
public String getQProperty(String prop) {
return VocabularyItemConstants.NUXEO_SCHEMA_NAME + ":" + prop;
}
+
+ /*
+ * Because the Vocabulary service's item schema is not standard, we need to override the default authority item schema behavior.
+ * (non-Javadoc)
+ * @see org.collectionspace.services.common.vocabulary.nuxeo.AuthorityItemDocumentModelHandler#getPrimaryDisplayName(org.nuxeo.ecm.core.api.DocumentModel, java.lang.String, java.lang.String, java.lang.String)
+ */
+ @Override
+ protected String getPrimaryDisplayName(DocumentModel docModel,
+ String schema, String complexPropertyName, String fieldName) {
+ String result = null;
+
+ try {
+ result = (String) docModel.getProperty(schema, AuthorityItemJAXBSchema.DISPLAY_NAME);
+ } catch (Exception e) {
+ throw new RuntimeException("Unknown problem retrieving property {"
+ + schema + ":" + fieldName + "}." + e.getLocalizedMessage());
+ }
+
+ return result;
+ }
+
+ /*
+ * Because the Vocabulary service's item schema is not standard, we need to override this method.
+ */
+ @Override
+ protected ListResultField getListResultField() {
+ ListResultField result = new ListResultField();
+
+ result.setElement(AuthorityItemJAXBSchema.DISPLAY_NAME);
+ result.setXpath(NuxeoUtils.getPrimaryXPathPropertyName(this.getAuthorityItemCommonSchemaName(),
+ getItemTermInfoGroupXPathBase(),
+ AuthorityItemJAXBSchema.TERM_DISPLAY_NAME));
+
+ return result;
+ }
+
}