]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
886b7ba32a39ec2603bfab5cf2638c0a5fe64b75
[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.taxonomy.nuxeo;
25
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;
31
32 /**
33  * TaxonomyDocumentModelHandler
34  *
35  * $LastChangedRevision$
36  * $LastChangedDate$
37  */
38 /**
39  * @author pschmitz
40  *
41  */
42 public class TaxonDocumentModelHandler
43         extends AuthorityItemDocumentModelHandler<TaxonCommon> {
44
45     /**
46      * Common part schema label
47      */
48     private static final String COMMON_PART_LABEL = "taxon_common";
49
50     public TaxonDocumentModelHandler() {
51         super(COMMON_PART_LABEL);
52     }
53
54     /**
55      * Handle display name.
56      *
57      * @param docModel the doc model
58      * @throws Exception the exception
59      */
60     @Override
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;
69         }
70         if (shortDisplayNameComputed == null) {
71             shortDisplayNameComputed = true;
72         }
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,
78                         displayName);
79             }
80             if (shortDisplayNameComputed) {
81                 docModel.setProperty(commonPartLabel, TaxonJAXBSchema.SHORT_DISPLAY_NAME,
82                         displayName);
83             }
84         }
85     }
86
87     /**
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.
92      * @param name
93      * @return
94      * @throws Exception
95      */
96     private static String prepareDefaultDisplayName(
97             String name) throws Exception {
98         StringBuilder newStr = new StringBuilder();
99         newStr.append(name);
100         return newStr.toString();
101     }
102
103     /**
104      * getQProperty converts the given property to qualified schema property
105      * @param prop
106      * @return
107      */
108     @Override
109     public String getQProperty(String prop) {
110         return TaxonConstants.NUXEO_SCHEMA_NAME + ":" + prop;
111     }
112 }
113