From cda61bde976e7209ecd30d14112221c5733baf64 Mon Sep 17 00:00:00 2001 From: Richard Millet Date: Wed, 5 Sep 2012 23:38:21 -0700 Subject: [PATCH] CSPACE-5488: More changes to get authority item handlers working correctly with gereral PT refactor. --- .../xmlreplay/location/location-hierarchy.xml | 4 +- .../vocabulary/res/GetVocabularyItems.res.xml | 2 +- .../common/vocabulary/AuthorityResource.java | 2 +- .../AuthorityItemDocumentModelHandler.java | 61 ++++++++++--------- .../services/common/ResourceBase.java | 6 +- .../document/AbstractDocumentHandlerImpl.java | 2 +- .../client/java/DocumentModelHandler.java | 26 +++++--- 7 files changed, 59 insertions(+), 44 deletions(-) diff --git a/services/IntegrationTests/src/test/resources/test-data/xmlreplay/location/location-hierarchy.xml b/services/IntegrationTests/src/test/resources/test-data/xmlreplay/location/location-hierarchy.xml index fa2bc51ea..d7096af35 100644 --- a/services/IntegrationTests/src/test/resources/test-data/xmlreplay/location/location-hierarchy.xml +++ b/services/IntegrationTests/src/test/resources/test-data/xmlreplay/location/location-hierarchy.xml @@ -62,12 +62,12 @@ - + POST /cspace-services/locationauthorities/urn:cspace:name(CSPACE3739LocationAuthority)/items/ location/hierarchy/3-locations_w_relations_CSID.xml - Cabinet 1 + Cabinet 1 ${LocationParent.CSID} ${LocationChild1.CSID} ${LocationChild2.CSID} diff --git a/services/IntegrationTests/src/test/resources/test-data/xmlreplay/vocabulary/res/GetVocabularyItems.res.xml b/services/IntegrationTests/src/test/resources/test-data/xmlreplay/vocabulary/res/GetVocabularyItems.res.xml index 64430e34f..8a0c08878 100644 --- a/services/IntegrationTests/src/test/resources/test-data/xmlreplay/vocabulary/res/GetVocabularyItems.res.xml +++ b/services/IntegrationTests/src/test/resources/test-data/xmlreplay/vocabulary/res/GetVocabularyItems.res.xml @@ -6,7 +6,7 @@ 0 3 3 - csid|uri|updatedAt|workflowState|order|displayName|shortIdentifier|refName|termStatus + csid|uri|refname|updatedAt|workflowState|order|displayName|shortIdentifier|refName|termStatus ${Item1.displayName} ${Item1.itemID} 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 9342cce0d..c6176062e 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 @@ -517,7 +517,7 @@ public abstract class AuthorityResource PoxPayloadIn input = new PoxPayloadIn(xmlPayload); ServiceContext ctx = createServiceContext(getItemServiceName(), input); ctx.setResourceMap(resourceMap); - ctx.setUriInfo(ui); //Laramie + ctx.setUriInfo(ui); // Note: must have the parentShortId, to do the create. CsidAndShortIdentifier parent = lookupParentCSIDAndShortIdentifer(specifier, "createAuthorityItem", "CREATE_ITEM", 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 7f3db3f3e..0afa3dc0f 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 @@ -24,6 +24,7 @@ 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; @@ -109,7 +110,7 @@ public abstract class AuthorityItemDocumentModelHandler } /* - * 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) */ @@ -119,24 +120,30 @@ public abstract class AuthorityItemDocumentModelHandler 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); } @@ -293,21 +300,10 @@ public abstract class AuthorityItemDocumentModelHandler */ @Override public void handleCreate(DocumentWrapper 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()); } /* @@ -376,12 +372,11 @@ public abstract class AuthorityItemDocumentModelHandler * 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(), @@ -394,9 +389,12 @@ public abstract class AuthorityItemDocumentModelHandler String generatedShortIdentifier = AuthorityIdentifierUtils.generateShortIdentifierFromDisplayName(termDisplayName, termName); - docModel.setProperty(schemaName, AuthorityItemJAXBSchema.SHORT_IDENTIFIER, + docModel.setProperty(authorityItemCommonSchemaName, AuthorityItemJAXBSchema.SHORT_IDENTIFIER, generatedShortIdentifier); + result = generatedShortIdentifier; } + + return result; } /** @@ -410,13 +408,16 @@ public abstract class AuthorityItemDocumentModelHandler * @see #filterReadOnlyPropertiesForPart(Map, org.collectionspace.services.common.service.ObjectPartType) * */ - protected void updateRefnameForAuthorityItem(DocumentWrapper 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; } /** 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 dc113ace2..44ff6c814 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 @@ -443,7 +443,11 @@ public abstract class ResourceBase try { params = ServiceConfigUtils.getDocHandlerParams(ctx); ListResultField field = params.getRefnameDisplayNameField(); - result = field.getSchema() + ":" + field.getXpath(); + String schema = field.getSchema(); + if (schema == null || schema.trim().isEmpty()) { + schema = ctx.getCommonPartLabel(); + } + result = schema + ":" + field.getXpath(); } catch (Exception e) { if (logger.isWarnEnabled()) { logger.warn(String.format("Call failed to getPartialTermMatchField() for class %s", this.getClass().getName())); 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 aba1a6dbc..8000de612 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 @@ -73,7 +73,7 @@ public abstract class AbstractDocumentHandlerImpl /* * Should return a reference name for the wrapper object */ - abstract public RefName.RefNameInterface getRefName(DocumentWrapper docWrapper, String tenantName, String serviceName); + abstract protected RefName.RefNameInterface getRefName(DocumentWrapper docWrapper, String tenantName, String serviceName); /* (non-Javadoc) * @see org.collectionspace.services.common.document.DocumentHandler#getServiceContext() diff --git a/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/DocumentModelHandler.java b/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/DocumentModelHandler.java index e0b92cd1f..94bfe6977 100644 --- a/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/DocumentModelHandler.java +++ b/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/DocumentModelHandler.java @@ -36,6 +36,7 @@ import org.collectionspace.services.client.PoxPayloadIn; 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; @@ -304,17 +305,23 @@ public abstract class DocumentModelHandler /* * 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(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 docWrapper, + protected RefName.RefNameInterface getRefName(DocumentWrapper 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; @@ -341,9 +348,12 @@ public abstract class DocumentModelHandler // // 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. -- 2.47.3