]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
CSPACE-4460: Authority services now no longer accept client-supplied refNames; all...
authorAron Roberts <aron@socrates.berkeley.edu>
Tue, 15 Nov 2011 23:52:26 +0000 (23:52 +0000)
committerAron Roberts <aron@socrates.berkeley.edu>
Tue, 15 Nov 2011 23:52:26 +0000 (23:52 +0000)
services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/nuxeo/AuthorityDocumentModelHandler.java
services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/nuxeo/AuthorityItemDocumentModelHandler.java

index 9235008b3be17fffca8dbecc8b2474b979b960df..84cb9cfa16abf18ba6b9c473c0001cdeb4c3b527 100644 (file)
@@ -80,6 +80,10 @@ public abstract class AuthorityDocumentModelHandler<AuthCommon>
         updateRefnameForAuthority(wrapDoc, authorityCommonSchemaName);//CSPACE-3178
     }
 
+    /**
+     * If no short identifier was provided in the input payload,
+     * generate a short identifier from the display name.
+     */
     private void handleDisplayNameAsShortIdentifier(DocumentModel docModel, String schemaName) throws Exception {
         String shortIdentifier = (String) docModel.getProperty(schemaName, AuthorityJAXBSchema.SHORT_IDENTIFIER);
         String displayName = (String) docModel.getProperty(schemaName, AuthorityJAXBSchema.DISPLAY_NAME);
@@ -89,24 +93,29 @@ public abstract class AuthorityDocumentModelHandler<AuthCommon>
             docModel.setProperty(schemaName, AuthorityJAXBSchema.SHORT_IDENTIFIER, generatedShortIdentifier);
         }
     }
-    
+    /**
+     * Generate a refName for the authority from the short identifier
+     * and display name.
+     * 
+     * All refNames for authorities are generated.  If a client supplies
+     * a refName, it will be overwritten during create (per this method) 
+     * or discarded during update (per filterReadOnlyPropertiesForPart).
+     * 
+     * @see #filterReadOnlyPropertiesForPart(Map<String, Object>, org.collectionspace.services.common.service.ObjectPartType)
+     * 
+     */
     protected void updateRefnameForAuthority(DocumentWrapper<DocumentModel> wrapDoc, String schemaName) throws Exception {
         DocumentModel docModel = wrapDoc.getWrappedObject();
-        String suppliedRefName = (String) docModel.getProperty(schemaName, AuthorityJAXBSchema.REF_NAME);
-        // CSPACE-3178:
-        // Temporarily accept client-supplied refName values, rather than always generating such values,
-        // Remove the surrounding 'if' statement when clients should no longer supply refName values.
-        if (suppliedRefName == null || suppliedRefName.isEmpty()) {
-            String shortIdentifier = (String) docModel.getProperty(schemaName, AuthorityJAXBSchema.SHORT_IDENTIFIER);
-            String displayName = (String) docModel.getProperty(schemaName, AuthorityJAXBSchema.DISPLAY_NAME);
-            MultipartServiceContext ctx = (MultipartServiceContext) getServiceContext();
-            RefName.Authority authority = RefName.buildAuthority(ctx.getTenantName(),
-                    ctx.getServiceName(),
-                    shortIdentifier,
-                    displayName);
-            String refName = authority.toString();
-            docModel.setProperty(schemaName, AuthorityJAXBSchema.REF_NAME, refName);
-        }
+        String shortIdentifier = (String) docModel.getProperty(schemaName, AuthorityJAXBSchema.SHORT_IDENTIFIER);
+        String displayName = (String) docModel.getProperty(schemaName, AuthorityJAXBSchema.DISPLAY_NAME);
+        MultipartServiceContext ctx = (MultipartServiceContext) getServiceContext();
+        RefName.Authority authority = RefName.buildAuthority(ctx.getTenantName(),
+                ctx.getServiceName(),
+                shortIdentifier,
+                displayName);
+        String refName = authority.toString();
+        docModel.setProperty(schemaName, AuthorityJAXBSchema.REF_NAME, refName);
     }
 
     public String getShortIdentifier(DocumentWrapper<DocumentModel> wrapDoc, String schemaName) {
@@ -134,9 +143,7 @@ public abstract class AuthorityDocumentModelHandler<AuthCommon>
         if (partMeta.getLabel().equalsIgnoreCase(commonPartLabel)) {
             objectProps.remove(AuthorityJAXBSchema.CSID);
             objectProps.remove(AuthorityJAXBSchema.SHORT_IDENTIFIER);
-            // Enable when clients should no longer supply refName values
-            // objectProps.remove(AuthorityItemJAXBSchema.REF_NAME); // CSPACE-3178
-
+            objectProps.remove(AuthorityJAXBSchema.REF_NAME);
         }
     }
 }
index 8a74fcf9ad54a6255e60bd44978b4cf75eb9c4f8..a41a6451b53cc188c509505361069b683f46e665 100644 (file)
@@ -233,12 +233,11 @@ public abstract class AuthorityItemDocumentModelHandler<AICommon>
      * Assumes refName is already correct. Just ensures it is right.
      *
      * @param docModel the doc model
+     * @param newDisplayName the new display name
      * @throws Exception the exception
      */
     protected String handleItemRefNameUpdateForDisplayName(DocumentModel docModel,
             String newDisplayName) throws Exception {
-        //String suppliedRefName = (String) docModel.getProperty(authorityItemCommonSchemaName, 
-        //                                                                                                             AuthorityItemJAXBSchema.REF_NAME);
         RefName.AuthorityItem authItem = RefName.AuthorityItem.parse(oldRefNameOnUpdate);
         if (authItem == null) {
             String err = "Authority Item has illegal refName: " + oldRefNameOnUpdate;
@@ -266,7 +265,7 @@ public abstract class AuthorityItemDocumentModelHandler<AICommon>
             }
             ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx = getServiceContext();
             RepositoryClient repoClient = getRepositoryClient(ctx);
-            // HACK - this should be defined for each handler, as with 
+            // FIXME HACK - this should be defined for each handler, as with 
             // AuthorityResource.getRefPropName()
             String refNameProp = ServiceBindingUtils.AUTH_REF_PROP;
 
@@ -278,6 +277,10 @@ public abstract class AuthorityItemDocumentModelHandler<AICommon>
         }
     }
 
+    /**
+     * If no short identifier was provided in the input payload,
+     * generate a short identifier from the display name.
+     */
     private void handleDisplayNameAsShortIdentifier(DocumentModel docModel, String schemaName) throws Exception {
         String shortIdentifier = (String) docModel.getProperty(schemaName, AuthorityItemJAXBSchema.SHORT_IDENTIFIER);
         String displayName = (String) docModel.getProperty(schemaName, AuthorityItemJAXBSchema.DISPLAY_NAME);
@@ -288,38 +291,35 @@ public abstract class AuthorityItemDocumentModelHandler<AICommon>
             // Do nothing on exception. Some vocabulary schemas may not include a short display name.
         }
         if (Tools.isEmpty(shortIdentifier)) {
-            String generatedShortIdentifier = AuthorityIdentifierUtils.generateShortIdentifierFromDisplayName(displayName, shortDisplayName);
+            String generatedShortIdentifier =
+                    AuthorityIdentifierUtils.generateShortIdentifierFromDisplayName(displayName, shortDisplayName);
             docModel.setProperty(schemaName, AuthorityItemJAXBSchema.SHORT_IDENTIFIER, generatedShortIdentifier);
         }
     }
 
+    /**
+     * Generate a refName for the authority item from the short identifier
+     * and display name.
+     * 
+     * All refNames for authority items are generated.  If a client supplies
+     * a refName, it will be overwritten during create (per this method) 
+     * or discarded during update (per filterReadOnlyPropertiesForPart).
+     * 
+     * @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();
-        String suppliedRefName = (String) docModel.getProperty(schemaName, AuthorityItemJAXBSchema.REF_NAME);
-        // CSPACE-3178:
-        // Temporarily accept client-supplied refName values, rather than always generating such values.
-        // Remove first block and the surrounding 'if' statement when clients should no longer supply refName values.
-        if (!Tools.isEmpty(suppliedRefName)) {
-            // Supplied refName must at least be legal
-            RefName.AuthorityItem item = RefName.AuthorityItem.parse(suppliedRefName);
-            if (item == null) {
-                logger.error("Passed refName for authority item not legal: " + suppliedRefName);
-                suppliedRefName = null; // Clear this and compute a new one below.
-            }
-        }
-        // Recheck, in case we cleared it for being illegal
-        if (Tools.isEmpty(suppliedRefName)) {
-            String shortIdentifier = (String) docModel.getProperty(schemaName, AuthorityItemJAXBSchema.SHORT_IDENTIFIER);
-            String displayName = (String) docModel.getProperty(schemaName, AuthorityItemJAXBSchema.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);
+        String shortIdentifier = (String) docModel.getProperty(schemaName, AuthorityItemJAXBSchema.SHORT_IDENTIFIER);
+        String displayName = (String) docModel.getProperty(schemaName, AuthorityItemJAXBSchema.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);
     }
 
     /**
@@ -371,9 +371,7 @@ public abstract class AuthorityItemDocumentModelHandler<AICommon>
             objectProps.remove(AuthorityItemJAXBSchema.IN_AUTHORITY);
             objectProps.remove(AuthorityItemJAXBSchema.CSID);
             objectProps.remove(AuthorityJAXBSchema.SHORT_IDENTIFIER);
-            // Enable when clients should no longer supply refName values
-            // objectProps.remove(AuthorityItemJAXBSchema.REF_NAME); // CSPACE-3178
-
+            objectProps.remove(AuthorityItemJAXBSchema.REF_NAME);
         }
     }