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 * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#handleCreate(org.collectionspace.services.common.document.DocumentWrapper)
58 public void handleCreate(DocumentWrapper<DocumentModel> wrapDoc) throws Exception {
59 // first fill all the parts of the document
60 super.handleCreate(wrapDoc);
61 handleDisplayNames(wrapDoc.getWrappedObject());
65 * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#handleUpdate(org.collectionspace.services.common.document.DocumentWrapper)
68 public void handleUpdate(DocumentWrapper<DocumentModel> wrapDoc) throws Exception {
69 super.handleUpdate(wrapDoc);
70 handleDisplayNames(wrapDoc.getWrappedObject());
74 * Handle display name.
76 * @param docModel the doc model
77 * @throws Exception the exception
79 private void handleDisplayNames(DocumentModel docModel) throws Exception {
80 String commonPartLabel = getServiceContext().getCommonPartLabel("taxon");
81 Boolean displayNameComputed = (Boolean) docModel.getProperty(commonPartLabel,
82 TaxonJAXBSchema.DISPLAY_NAME_COMPUTED);
83 Boolean shortDisplayNameComputed = (Boolean) docModel.getProperty(commonPartLabel,
84 TaxonJAXBSchema.SHORT_DISPLAY_NAME_COMPUTED);
85 if (displayNameComputed == null) {
86 displayNameComputed = true;
88 if (shortDisplayNameComputed == null) {
89 shortDisplayNameComputed = true;
91 if (displayNameComputed || shortDisplayNameComputed) {
92 String displayName = prepareDefaultDisplayName(
93 (String) docModel.getProperty(commonPartLabel, TaxonJAXBSchema.NAME));
94 if (displayNameComputed) {
95 docModel.setProperty(commonPartLabel, TaxonJAXBSchema.DISPLAY_NAME,
98 if (shortDisplayNameComputed) {
99 docModel.setProperty(commonPartLabel, TaxonJAXBSchema.SHORT_DISPLAY_NAME,
106 * Produces a default displayName from the basic name and dates fields.
107 * @see TaxonomyAuthorityClientUtils.prepareDefaultDisplayName() which
108 * duplicates this logic, until we define a service-general utils package
109 * that is neither client nor service specific.
114 private static String prepareDefaultDisplayName(
115 String name) throws Exception {
116 StringBuilder newStr = new StringBuilder();
118 return newStr.toString();
122 * getQProperty converts the given property to qualified schema property
127 public String getQProperty(String prop) {
128 return TaxonConstants.NUXEO_SCHEMA_NAME + ":" + prop;