]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
CSPACE-5488: More changes to get authority item handlers working correctly with gerer...
authorRichard Millet <richard.millet@berkeley.edu>
Thu, 6 Sep 2012 06:38:21 +0000 (23:38 -0700)
committerRichard Millet <richard.millet@berkeley.edu>
Thu, 6 Sep 2012 06:38:21 +0000 (23:38 -0700)
services/IntegrationTests/src/test/resources/test-data/xmlreplay/location/location-hierarchy.xml
services/IntegrationTests/src/test/resources/test-data/xmlreplay/vocabulary/res/GetVocabularyItems.res.xml
services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/AuthorityResource.java
services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/nuxeo/AuthorityItemDocumentModelHandler.java
services/common/src/main/java/org/collectionspace/services/common/ResourceBase.java
services/common/src/main/java/org/collectionspace/services/common/document/AbstractDocumentHandlerImpl.java
services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/DocumentModelHandler.java

index fa2bc51ea5602c73ee621a319ba2f2081a59d41d..d7096af3588193749bafa278fb8992d81a1eb3cc 100644 (file)
             </vars>
         </test>
 
-                               <test ID="Location1_old">
+               <test ID="Location1_old">
             <method>POST</method>
             <uri>/cspace-services/locationauthorities/urn:cspace:name(CSPACE3739LocationAuthority)/items/</uri>
             <filename>location/hierarchy/3-locations_w_relations_CSID.xml</filename>
             <vars>
-                                                       <var ID="name">Cabinet 1</var>
+                               <var ID="name">Cabinet 1</var>
                <var ID="parentCSID">${LocationParent.CSID}</var>
                <var ID="childCSID">${LocationChild1.CSID}</var>
                <var ID="child2CSID">${LocationChild2.CSID}</var>
index 64430e34ff1fbb4ddfc1f244173ad55bd67dfdb2..8a0c0887810c43d7d09a658fcc7bbf7e6ab6c768 100644 (file)
@@ -6,7 +6,7 @@
        <pageNum>0</pageNum>
     <itemsInPage>3</itemsInPage>
     <totalItems>3</totalItems>
-    <fieldsReturned>csid|uri|updatedAt|workflowState|order|displayName|shortIdentifier|refName|termStatus</fieldsReturned>
+    <fieldsReturned>csid|uri|refname|updatedAt|workflowState|order|displayName|shortIdentifier|refName|termStatus</fieldsReturned>
     <list-item>
         <displayName>${Item1.displayName}</displayName>
         <shortIdentifier>${Item1.itemID}</shortIdentifier>
index 9342cce0d305e9da9b373dcc9d2ce6f8ee2ae028..c6176062ef102eef73843ed23d4cffff207bee9a 100644 (file)
@@ -517,7 +517,7 @@ public abstract class AuthorityResource<AuthCommon, AuthItemHandler>
             PoxPayloadIn input = new PoxPayloadIn(xmlPayload);
             ServiceContext<PoxPayloadIn, PoxPayloadOut> 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);
index 7f3db3f3e1473314d5559dfb5e812a5d370b3ae4..0afa3dc0faf539ed002dd532bb8f7383e728f8c1 100644 (file)
@@ -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<AICommon>
     }
     
     /*
-     * 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<AICommon>
        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<AICommon>
      */
     @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());        
     }
 
     /*
@@ -376,12 +372,11 @@ public abstract class AuthorityItemDocumentModelHandler<AICommon>
      * 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<AICommon>
 
                        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<AICommon>
      * @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;
     }
 
     /**
index dc113ace2c9ca5a47394f716dd8e94503dddfdc2..44ff6c814fb6c5d2b93b0903723a03a225bd811f 100644 (file)
@@ -443,7 +443,11 @@ public abstract class ResourceBase
        try {\r
                        params = ServiceConfigUtils.getDocHandlerParams(ctx);\r
                        ListResultField field = params.getRefnameDisplayNameField();\r
-                       result = field.getSchema() + ":" + field.getXpath();\r
+                       String schema = field.getSchema();\r
+                       if (schema == null || schema.trim().isEmpty()) {\r
+                               schema = ctx.getCommonPartLabel();\r
+                       }\r
+                       result = schema + ":" + field.getXpath();\r
        } catch (Exception e) {\r
                        if (logger.isWarnEnabled()) {\r
                                logger.warn(String.format("Call failed to getPartialTermMatchField() for class %s", this.getClass().getName()));\r
index aba1a6dbc7b926e00c630553a18281d77ff22368..8000de612703343aaed579e6bc5f93d158f7c6ce 100644 (file)
@@ -73,7 +73,7 @@ public abstract class AbstractDocumentHandlerImpl<T, TL, WT, WTL>
     /*
      * Should return a reference name for the wrapper object
      */
-    abstract public RefName.RefNameInterface getRefName(DocumentWrapper<WT> docWrapper, String tenantName, String serviceName);
+    abstract protected RefName.RefNameInterface getRefName(DocumentWrapper<WT> docWrapper, String tenantName, String serviceName);
     
     /* (non-Javadoc)
      * @see org.collectionspace.services.common.document.DocumentHandler#getServiceContext()
index e0b92cd1f0a268e1aae795c4de4b0f5b40e5b341..94bfe6977bff88b481448618e0c9443252e583e7 100644 (file)
@@ -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<T, TL>
     /*
      * 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;
@@ -341,9 +348,12 @@ public abstract class DocumentModelHandler<T, TL>
             //
             // 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.