]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
CSPACE-3178,CSPACE-2215: Payloads to create authority or voculabulary resources now...
authorAron Roberts <aron@socrates.berkeley.edu>
Tue, 4 Oct 2011 16:56:51 +0000 (16:56 +0000)
committerAron Roberts <aron@socrates.berkeley.edu>
Tue, 4 Oct 2011 16:56:51 +0000 (16:56 +0000)
services/authority/src/main/java/org/collectionspace/services/common/vocabulary/nuxeo/AuthorityDocumentModelHandler.java
services/authority/src/main/java/org/collectionspace/services/common/vocabulary/nuxeo/AuthorityIdentifierUtils.java [new file with mode: 0644]
services/authority/src/main/java/org/collectionspace/services/common/vocabulary/nuxeo/AuthorityItemDocumentModelHandler.java
services/organization/service/src/main/java/org/collectionspace/services/organization/nuxeo/OrgAuthorityValidatorHandler.java
services/person/service/src/main/java/org/collectionspace/services/person/nuxeo/PersonAuthorityValidatorHandler.java

index 8d923fd103bb6e0166bdd790a758572e50203a3e..9235008b3be17fffca8dbecc8b2474b979b960df 100644 (file)
@@ -26,6 +26,7 @@ package org.collectionspace.services.common.vocabulary.nuxeo;
 import java.util.Map;
 
 import org.collectionspace.services.common.api.RefName;
+import org.collectionspace.services.common.api.Tools;
 import org.collectionspace.services.common.context.MultipartServiceContext;
 import org.collectionspace.services.common.document.DocumentWrapper;
 import org.collectionspace.services.common.service.ObjectPartType;
@@ -75,9 +76,20 @@ public abstract class AuthorityDocumentModelHandler<AuthCommon>
         // CSPACE-3178:
         // Uncomment once debugged and App layer is read to integrate
         // Experimenting with this uncommented now ...
+        handleDisplayNameAsShortIdentifier(wrapDoc.getWrappedObject(), authorityCommonSchemaName);
         updateRefnameForAuthority(wrapDoc, authorityCommonSchemaName);//CSPACE-3178
     }
 
+    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);
+        String shortDisplayName = "";
+        if (Tools.isEmpty(shortIdentifier)) {
+            String generatedShortIdentifier = AuthorityIdentifierUtils.generateShortIdentifierFromDisplayName(displayName, shortDisplayName);
+            docModel.setProperty(schemaName, AuthorityJAXBSchema.SHORT_IDENTIFIER, generatedShortIdentifier);
+        }
+    }
+    
     protected void updateRefnameForAuthority(DocumentWrapper<DocumentModel> wrapDoc, String schemaName) throws Exception {
         DocumentModel docModel = wrapDoc.getWrappedObject();
         String suppliedRefName = (String) docModel.getProperty(schemaName, AuthorityJAXBSchema.REF_NAME);
diff --git a/services/authority/src/main/java/org/collectionspace/services/common/vocabulary/nuxeo/AuthorityIdentifierUtils.java b/services/authority/src/main/java/org/collectionspace/services/common/vocabulary/nuxeo/AuthorityIdentifierUtils.java
new file mode 100644 (file)
index 0000000..6389a51
--- /dev/null
@@ -0,0 +1,67 @@
+/**
+ *  This document is a part of the source code and related artifacts
+ *  for CollectionSpace, an open source collections management system
+ *  for museums and related institutions:
+
+ *  http://www.collectionspace.org
+ *  http://wiki.collectionspace.org
+
+ *  Copyright 2009 University of California at Berkeley
+
+ *  Licensed under the Educational Community License (ECL), Version 2.0.
+ *  You may not use this file except in compliance with this License.
+
+ *  You may obtain a copy of the ECL 2.0 License at
+
+ *  https://source.collectionspace.org/collection-space/LICENSE.txt
+
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.collectionspace.services.common.vocabulary.nuxeo;
+
+import org.collectionspace.services.common.api.Tools;
+import org.collectionspace.services.common.api.Tools;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * AuthorityIdentifierUtils
+ *
+ * $LastChangedRevision: $
+ * $LastChangedDate: $
+ */
+public class AuthorityIdentifierUtils {
+
+    private final Logger logger = LoggerFactory.getLogger(AuthorityIdentifierUtils.class);
+
+    // CSPACE-2215
+    // FIXME: Consider replacing this with a different algorithm, perhaps one
+    // that combines stems of each word token in the displayname.
+    // FIXME: Verify uniqueness before returning the generated short identifier.
+    // FIXME: Consider using a hash of the display name, rather than a timestamp,
+    // when it is necessary to add a suffix for uniqueness.
+    protected static String generateShortIdentifierFromDisplayName(String displayName, String shortDisplayName) {
+        String generatedShortIdentifier = "";
+        if (Tools.notEmpty(displayName)) {
+            generatedShortIdentifier = displayName + '-' + Tools.now().toString();
+        } else if (Tools.notEmpty(shortDisplayName)) {
+            generatedShortIdentifier = shortDisplayName + '-' + Tools.now().toString();
+        }
+        // Ensure that the short identifier consists only of word chars.
+        if (Tools.notEmpty(generatedShortIdentifier)) {
+            generatedShortIdentifier = generatedShortIdentifier.replaceAll("[^\\w]", "");
+        }
+        // Fallback if we can't generate a short identifier from the displayname(s).
+        if (generatedShortIdentifier.isEmpty()) {
+            generatedShortIdentifier = java.util.UUID.randomUUID().toString();
+        }
+        return generatedShortIdentifier;
+    }
+
+
+}
index 4a8ea3ad47343752630dee7effe389fc50f8515f..8696ea6f07699c520c3bb93eabe6bfa8a93efae2 100644 (file)
@@ -42,7 +42,6 @@ import org.collectionspace.services.common.repository.RepositoryClientFactory;
 import org.collectionspace.services.common.service.ObjectPartType;
 import org.collectionspace.services.common.vocabulary.AuthorityJAXBSchema;
 import org.collectionspace.services.common.vocabulary.AuthorityItemJAXBSchema;
-import org.collectionspace.services.common.vocabulary.AuthorityResource;
 import org.collectionspace.services.nuxeo.client.java.DocHandlerBase;
 import org.collectionspace.services.nuxeo.util.NuxeoUtils;
 import org.collectionspace.services.relation.RelationResource;
@@ -138,35 +137,11 @@ 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 = generateShortIdentifierFromDisplayName(displayName, shortDisplayName);
+            String generatedShortIdentifier = AuthorityIdentifierUtils.generateShortIdentifierFromDisplayName(displayName, shortDisplayName);
             docModel.setProperty(schemaName, AuthorityItemJAXBSchema.SHORT_IDENTIFIER, generatedShortIdentifier);
         }
     }
 
-    // CSPACE-2215
-    // FIXME: Consider replacing this with a different algorithm, perhaps one
-    // that combines stems of each word token in the displayname.
-    // FIXME: Verify uniqueness before returning the generated short identifier.
-    // FIXME: Consider using a hash of the display name, rather than a timestamp,
-    // when it is necessary to add a suffix for uniqueness.
-    private String generateShortIdentifierFromDisplayName(String displayName, String shortDisplayName) {
-        String generatedShortIdentifier = "";
-        if (Tools.notEmpty(displayName)) {
-            generatedShortIdentifier = displayName + '-' + Tools.now().toString();
-        } else if (Tools.notEmpty(shortDisplayName)) {
-            generatedShortIdentifier = shortDisplayName + '-' + Tools.now().toString();
-        }
-        // Ensure that the short identifier consists only of word chars.
-        if (Tools.notEmpty(generatedShortIdentifier)) {
-            generatedShortIdentifier = generatedShortIdentifier.replaceAll("[^\\w]", "");
-        }
-        // Fallback if we can't generate a short identifier from the displayname(s).
-        if (generatedShortIdentifier.isEmpty()) {
-            generatedShortIdentifier = java.util.UUID.randomUUID().toString();
-        }
-        return generatedShortIdentifier;
-    }
-
     protected void updateRefnameForAuthorityItem(DocumentWrapper<DocumentModel> wrapDoc,
             String schemaName,
             String authorityRefBaseName) throws Exception {
index 09a4aa0bc342fb6bbd48259ce68093cc2cc7c083..867baf1ab8f8e773541b1bf8ab07fd29787b1732 100644 (file)
@@ -63,13 +63,11 @@ public class OrgAuthorityValidatorHandler implements ValidatorHandler {
             // Create-specific validation here
             if (action.equals(Action.CREATE)) {
                 String shortId = organizationAuth.getShortIdentifier();
-                if (shortId == null) {
-                    invalid = true;
-                    msg += "shortIdentifier must be non-null";
-                } else if (shortId.trim().isEmpty()) {
-                    invalid = true;
-                    msg += "shortIdentifier must have a non-empty value";
-                } else if (shortIdBadPattern.matcher(shortId).find()) {
+                // Per CSPACE-2215, shortIdentifier values that are null (missing)
+                // oe the empty string are now legally accepted in create payloads.
+                // In either of those cases, a short identifier will be synthesized from
+                // a display name or supplied in another manner.
+                if ((shortId != null) && (shortIdBadPattern.matcher(shortId).find())) {
                     invalid = true;
                     msg += "shortIdentifier must only contain standard word characters";
                 }
index 48c4ff7c634fac213429e93d8198843cd12c852d..6fb6ac67d0d5603170251a23df943cbb3972fd7b 100644 (file)
@@ -64,13 +64,11 @@ public class PersonAuthorityValidatorHandler implements ValidatorHandler {
             // Validation specific to creates or updates
             if (action.equals(Action.CREATE)) {
                 String shortId = personAuth.getShortIdentifier();
-                if (shortId == null) {
-                    invalid = true;
-                    msg += "shortIdentifier must be non-null";
-                } else if (shortId.trim().isEmpty()) {
-                    invalid = true;
-                    msg += "shortIdentifier must have a non-empty value";
-                } else if (shortIdBadPattern.matcher(shortId).find()) {
+                // Per CSPACE-2215, shortIdentifier values that are null (missing)
+                // oe the empty string are now legally accepted in create payloads.
+                // In either of those cases, a short identifier will be synthesized from
+                // a display name or supplied in another manner.
+                if ((shortId != null) && (shortIdBadPattern.matcher(shortId).find())) {
                     invalid = true;
                     msg += "shortIdentifier must only contain standard word characters";
                 }