package org.collectionspace.services.common.vocabulary.nuxeo;
import org.collectionspace.services.client.AuthorityClient;
+import org.collectionspace.services.client.CollectionSpaceClient;
import org.collectionspace.services.client.IQueryManager;
import org.collectionspace.services.client.PoxPayloadIn;
import org.collectionspace.services.client.PoxPayloadOut;
}
/*
- * Before calling this method, be sure that the 'this.handleCreate()' was called and was successful.
+ * After calling this method successfully, the document model will contain an updated refname and short ID
* (non-Javadoc)
* @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#getRefName(org.collectionspace.services.common.context.ServiceContext, org.nuxeo.ecm.core.api.DocumentModel)
*/
RefName.RefNameInterface refname = null;
try {
- String shortIdentifier = (String) docModel.getProperty(authorityItemCommonSchemaName, AuthorityItemJAXBSchema.SHORT_IDENTIFIER);
- if (Tools.isEmpty(shortIdentifier)) {
- throw new Exception("The shortIdentifier for this authority term was empty or not set.");
- }
-
String displayName = getPrimaryDisplayName(docModel, authorityItemCommonSchemaName,
- getItemTermInfoGroupXPathBase(), AuthorityItemJAXBSchema.TERM_DISPLAY_NAME);
+ getItemTermInfoGroupXPathBase(), AuthorityItemJAXBSchema.TERM_DISPLAY_NAME);
if (Tools.isEmpty(displayName)) {
throw new Exception("The displayName for this authority term was empty or not set.");
}
+
+ String shortIdentifier = (String) docModel.getProperty(authorityItemCommonSchemaName, AuthorityItemJAXBSchema.SHORT_IDENTIFIER);
+ if (Tools.isEmpty(shortIdentifier)) {
+ // We didn't find a short ID in the payload request, so we need to synthesize one.
+ shortIdentifier = handleDisplayNameAsShortIdentifier(docModel); // updates the document model with the new short ID as a side-effect
+ }
String authorityRefBaseName = getAuthorityRefNameBase();
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.");
}
+ // Create the items refname using the parent's as a base
RefName.Authority parentsRefName = RefName.Authority.parse(authorityRefBaseName);
refname = RefName.buildAuthorityItem(parentsRefName, shortIdentifier, displayName);
+ // Now update the document model with the refname value
+ String refNameStr = refname.toString();
+ docModel.setProperty(authorityItemCommonSchemaName, AuthorityItemJAXBSchema.REF_NAME, refNameStr);
+
} catch (Exception e) {
logger.error(e.getMessage(), e);
}
*/
@Override
public void handleCreate(DocumentWrapper<DocumentModel> wrapDoc) throws Exception {
- // first fill all the parts of the document
+ // first fill all the parts of the document, refname and short ID get set as well
super.handleCreate(wrapDoc);
// Ensure we have required fields set properly
- handleInAuthority(wrapDoc.getWrappedObject());
-
- // FIXME: This call to synthesize a shortIdentifier from the termDisplayName
- // of the preferred term may have been commented out, in the course of
- // adding support for preferred / non-preferred terms, in CSPACE-4813
- // and linked issues. Revisit this to determine whether we want to
- // re-enable it.
- //
- // CSPACE-3178:
- handleDisplayNameAsShortIdentifier(wrapDoc.getWrappedObject(), authorityItemCommonSchemaName);
- // refName includes displayName, so we force a correct value here.
- updateRefnameForAuthorityItem(wrapDoc, authorityItemCommonSchemaName, getAuthorityRefNameBase());
+ handleInAuthority(wrapDoc.getWrappedObject());
}
/*
* 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,
+ private String handleDisplayNameAsShortIdentifier(DocumentModel docModel) throws Exception {
+ String result = (String) docModel.getProperty(authorityItemCommonSchemaName,
AuthorityItemJAXBSchema.SHORT_IDENTIFIER);
- if (Tools.isEmpty(shortIdentifier)) {
+ if (Tools.isEmpty(result)) {
String termDisplayName = getPrimaryDisplayName(
docModel, authorityItemCommonSchemaName,
getItemTermInfoGroupXPathBase(),
String generatedShortIdentifier = AuthorityIdentifierUtils.generateShortIdentifierFromDisplayName(termDisplayName,
termName);
- docModel.setProperty(schemaName, AuthorityItemJAXBSchema.SHORT_IDENTIFIER,
+ docModel.setProperty(authorityItemCommonSchemaName, AuthorityItemJAXBSchema.SHORT_IDENTIFIER,
generatedShortIdentifier);
+ result = generatedShortIdentifier;
}
+
+ return result;
}
/**
* @see #filterReadOnlyPropertiesForPart(Map<String, Object>, org.collectionspace.services.common.service.ObjectPartType)
*
*/
- protected void updateRefnameForAuthorityItem(DocumentWrapper<DocumentModel> wrapDoc,
- String schemaName,
- String authorityRefBaseName) throws Exception {
- DocumentModel docModel = wrapDoc.getWrappedObject();
- RefName.RefNameInterface refname = getRefName(this.getServiceContext(), docModel);
+ protected String updateRefnameForAuthorityItem(DocumentModel docModel,
+ String schemaName) throws Exception {
+ String result = null;
+
+ RefName.RefNameInterface refname = getRefName(getServiceContext(), docModel);
String refNameStr = refname.toString();
docModel.setProperty(schemaName, AuthorityItemJAXBSchema.REF_NAME, refNameStr);
+ result = refNameStr;
+
+ return result;
}
/**
import org.collectionspace.services.client.PoxPayloadOut;
import org.collectionspace.services.common.api.GregorianCalendarDateTimeUtils;
import org.collectionspace.services.common.api.RefName;
+import org.collectionspace.services.common.api.RefName.RefNameInterface;
import org.collectionspace.services.common.authorityref.AuthorityRefList;
import org.collectionspace.services.common.context.ServiceContext;
import org.collectionspace.services.common.document.AbstractMultipartDocumentHandlerImpl;
/*
* Subclasses should override this method if they need to customize their refname generation
*/
- public RefName.RefNameInterface getRefName(ServiceContext ctx,
+ protected RefName.RefNameInterface getRefName(ServiceContext ctx,
DocumentModel docModel) {
return getRefName(new DocumentWrapperImpl<DocumentModel>(docModel), ctx.getTenantName(), ctx.getServiceName());
}
+ /*
+ * By default, we'll use the CSID as the short ID. Sub-classes can override this method if they want to use
+ * something else for a short ID.
+ *
+ * (non-Javadoc)
+ * @see org.collectionspace.services.common.document.AbstractDocumentHandlerImpl#getRefName(org.collectionspace.services.common.document.DocumentWrapper, java.lang.String, java.lang.String)
+ */
@Override
- public RefName.RefNameInterface getRefName(DocumentWrapper<DocumentModel> docWrapper,
+ protected RefName.RefNameInterface getRefName(DocumentWrapper<DocumentModel> docWrapper,
String tenantName, String serviceName) {
- DocumentModel docModel = docWrapper.getWrappedObject();
- String csid = docModel.getName();
- String refnameDisplayName = this.getRefnameDisplayName(docWrapper);
+ String csid = docWrapper.getWrappedObject().getName();
+ String refnameDisplayName = getRefnameDisplayName(docWrapper);
RefName.RefNameInterface refname = RefName.Authority.buildAuthority(tenantName, serviceName,
csid, refnameDisplayName);
return refname;
//
// Add the resource's refname
//
- String refname = getRefName(ctx, documentModel).toString();
- documentModel.setProperty(CollectionSpaceClient.COLLECTIONSPACE_CORE_SCHEMA,
- CollectionSpaceClient.COLLECTIONSPACE_CORE_REFNAME, refname);
+ RefNameInterface refname = getRefName(ctx, documentModel); // Sub-classes may override the getRefName() method called here.
+ if (refname != null) {
+ String refnameStr = refname.toString();
+ documentModel.setProperty(CollectionSpaceClient.COLLECTIONSPACE_CORE_SCHEMA,
+ CollectionSpaceClient.COLLECTIONSPACE_CORE_REFNAME, refnameStr);
+ }
//
// Add the CSID to the DublinCore title so we can see the CSID in the default
// Nuxeo webapp.