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;
// 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);
--- /dev/null
+/**
+ * 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;
+ }
+
+
+}
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;
// 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 {
// 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";
}
// 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";
}