]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
6389a516425b441ffa8da5a3b207608c8ea17392
[tmp/jakarta-migration.git] /
1 /**
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:
5
6  *  http://www.collectionspace.org
7  *  http://wiki.collectionspace.org
8
9  *  Copyright 2009 University of California at Berkeley
10
11  *  Licensed under the Educational Community License (ECL), Version 2.0.
12  *  You may not use this file except in compliance with this License.
13
14  *  You may obtain a copy of the ECL 2.0 License at
15
16  *  https://source.collectionspace.org/collection-space/LICENSE.txt
17
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.
23  */
24 package org.collectionspace.services.common.vocabulary.nuxeo;
25
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;
30
31
32 /**
33  * AuthorityIdentifierUtils
34  *
35  * $LastChangedRevision: $
36  * $LastChangedDate: $
37  */
38 public class AuthorityIdentifierUtils {
39
40     private final Logger logger = LoggerFactory.getLogger(AuthorityIdentifierUtils.class);
41
42     // CSPACE-2215
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();
54         }
55         // Ensure that the short identifier consists only of word chars.
56         if (Tools.notEmpty(generatedShortIdentifier)) {
57             generatedShortIdentifier = generatedShortIdentifier.replaceAll("[^\\w]", "");
58         }
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();
62         }
63         return generatedShortIdentifier;
64     }
65
66
67 }