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.taxonomy.nuxeo;
26 import org.collectionspace.services.TaxonJAXBSchema;
27 import org.collectionspace.services.common.document.DocumentWrapper;
28 import org.collectionspace.services.common.vocabulary.nuxeo.AuthorityItemDocumentModelHandler;
29 import org.collectionspace.services.taxonomy.TaxonCommon;
30 import org.nuxeo.ecm.core.api.DocumentModel;
33 * TaxonomyDocumentModelHandler
35 * $LastChangedRevision$
42 public class TaxonDocumentModelHandler
43 extends AuthorityItemDocumentModelHandler<TaxonCommon> {
46 * Common part schema label
48 private static final String COMMON_PART_LABEL = "taxon_common";
50 public TaxonDocumentModelHandler() {
51 super(COMMON_PART_LABEL);
55 * Handle display name.
57 * @param docModel the doc model
58 * @throws Exception the exception
61 protected void handleComputedDisplayNames(DocumentModel docModel) throws Exception {
62 String commonPartLabel = getServiceContext().getCommonPartLabel("taxon");
63 Boolean displayNameComputed = (Boolean) docModel.getProperty(commonPartLabel,
64 TaxonJAXBSchema.DISPLAY_NAME_COMPUTED);
65 Boolean shortDisplayNameComputed = (Boolean) docModel.getProperty(commonPartLabel,
66 TaxonJAXBSchema.SHORT_DISPLAY_NAME_COMPUTED);
67 if (displayNameComputed == null) {
68 displayNameComputed = true;
70 if (shortDisplayNameComputed == null) {
71 shortDisplayNameComputed = true;
73 if (displayNameComputed || shortDisplayNameComputed) {
74 String displayName = prepareDefaultDisplayName(
75 (String) docModel.getProperty(commonPartLabel, TaxonJAXBSchema.NAME));
76 if (displayNameComputed) {
77 docModel.setProperty(commonPartLabel, TaxonJAXBSchema.DISPLAY_NAME,
80 if (shortDisplayNameComputed) {
81 docModel.setProperty(commonPartLabel, TaxonJAXBSchema.SHORT_DISPLAY_NAME,
88 * Produces a default displayName from the basic name and dates fields.
89 * @see TaxonomyAuthorityClientUtils.prepareDefaultDisplayName() which
90 * duplicates this logic, until we define a service-general utils package
91 * that is neither client nor service specific.
96 private static String prepareDefaultDisplayName(
97 String name) throws Exception {
98 StringBuilder newStr = new StringBuilder();
100 return newStr.toString();
104 * getQProperty converts the given property to qualified schema property
109 public String getQProperty(String prop) {
110 return TaxonConstants.NUXEO_SCHEMA_NAME + ":" + prop;