2 * This document is a part of the source code and related artifacts
3 * for CollectionSpace, an open source collections management system
4 * for museums and related institutions:
6 * http://www.collectionspace.org
7 * http://wiki.collectionspace.org
9 * Copyright 2009 University of California at Berkeley
11 * Licensed under the Educational Community License (ECL), Version 2.0.
12 * You may not use this file except in compliance with this License.
14 * You may obtain a copy of the ECL 2.0 License at
16 * https://source.collectionspace.org/collection-space/LICENSE.txt
18 * Unless required by applicable law or agreed to in writing, software
19 * distributed under the License is distributed on an "AS IS" BASIS,
20 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21 * See the License for the specific language governing permissions and
22 * limitations under the License.
24 package org.collectionspace.services.common.vocabulary.nuxeo;
26 import org.collectionspace.services.common.api.Tools;
27 import org.collectionspace.services.common.api.Tools;
28 import org.slf4j.Logger;
29 import org.slf4j.LoggerFactory;
33 * AuthorityIdentifierUtils
35 * $LastChangedRevision: $
38 public class AuthorityIdentifierUtils {
40 private final Logger logger = LoggerFactory.getLogger(AuthorityIdentifierUtils.class);
43 // FIXME: Consider replacing this with a different algorithm, perhaps one
44 // that combines stems of each word token in the displayname.
45 // FIXME: Verify uniqueness before returning the generated short identifier.
46 // FIXME: Consider using a hash of the display name, rather than a timestamp,
47 // when it is necessary to add a suffix for uniqueness.
48 protected static String generateShortIdentifierFromDisplayName(String displayName, String shortDisplayName) {
49 String generatedShortIdentifier = "";
50 if (Tools.notEmpty(displayName)) {
51 generatedShortIdentifier = displayName + '-' + Tools.now().toString();
52 } else if (Tools.notEmpty(shortDisplayName)) {
53 generatedShortIdentifier = shortDisplayName + '-' + Tools.now().toString();
55 // Ensure that the short identifier consists only of word chars.
56 if (Tools.notEmpty(generatedShortIdentifier)) {
57 generatedShortIdentifier = generatedShortIdentifier.replaceAll("[^\\w]", "");
59 // Fallback if we can't generate a short identifier from the displayname(s).
60 if (generatedShortIdentifier.isEmpty()) {
61 generatedShortIdentifier = java.util.UUID.randomUUID().toString();
63 return generatedShortIdentifier;