]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
b7c5ba99ed21ae149c5d105bbf6912ad008c9350
[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.client.TaxonomyAuthorityClient;
27 import org.collectionspace.services.TaxonJAXBSchema;
28 import org.collectionspace.services.common.document.DocumentWrapper;
29 import org.collectionspace.services.common.vocabulary.nuxeo.AuthorityItemDocumentModelHandler;
30 import org.collectionspace.services.taxonomy.TaxonCommon;
31 import org.nuxeo.ecm.core.api.DocumentModel;
32
33 /**
34  * TaxonomyDocumentModelHandler
35  *
36  * $LastChangedRevision$
37  * $LastChangedDate$
38  */
39 /**
40  * @author pschmitz
41  *
42  */
43 public class TaxonDocumentModelHandler
44         extends AuthorityItemDocumentModelHandler<TaxonCommon> {
45
46     /**
47      * Common part schema label
48      */
49     private static final String COMMON_PART_LABEL = "taxon_common";
50
51     public TaxonDocumentModelHandler() {
52         super(COMMON_PART_LABEL);
53     }
54     
55     public String getAuthorityServicePath(){
56         return TaxonomyAuthorityClient.SERVICE_PATH_COMPONENT;
57     }
58
59     /**
60      * Handle display name.
61      *
62      * @param docModel the doc model
63      * @throws Exception the exception
64      */
65     @Override
66     protected void handleComputedDisplayNames(DocumentModel docModel) throws Exception {
67         String commonPartLabel = getServiceContext().getCommonPartLabel("taxon");
68         Boolean displayNameComputed = (Boolean) docModel.getProperty(commonPartLabel,
69                 TaxonJAXBSchema.DISPLAY_NAME_COMPUTED);
70         Boolean shortDisplayNameComputed = (Boolean) docModel.getProperty(commonPartLabel,
71                 TaxonJAXBSchema.SHORT_DISPLAY_NAME_COMPUTED);
72         if (displayNameComputed == null) {
73             displayNameComputed = true;
74         }
75         if (shortDisplayNameComputed == null) {
76             shortDisplayNameComputed = true;
77         }
78         if (displayNameComputed || shortDisplayNameComputed) {
79             String displayName = prepareDefaultDisplayName(
80                     (String) docModel.getProperty(commonPartLabel, TaxonJAXBSchema.NAME));
81             if (displayNameComputed) {
82                 docModel.setProperty(commonPartLabel, TaxonJAXBSchema.DISPLAY_NAME,
83                         displayName);
84             }
85             if (shortDisplayNameComputed) {
86                 docModel.setProperty(commonPartLabel, TaxonJAXBSchema.SHORT_DISPLAY_NAME,
87                         displayName);
88             }
89         }
90     }
91
92     /**
93      * Produces a default displayName from the basic name and dates fields.
94      * @see TaxonomyAuthorityClientUtils.prepareDefaultDisplayName() which
95      * duplicates this logic, until we define a service-general utils package
96      * that is neither client nor service specific.
97      * @param name
98      * @return
99      * @throws Exception
100      */
101     private static String prepareDefaultDisplayName(
102             String name) throws Exception {
103         StringBuilder newStr = new StringBuilder();
104         newStr.append(name);
105         return newStr.toString();
106     }
107
108     /**
109      * getQProperty converts the given property to qualified schema property
110      * @param prop
111      * @return
112      */
113     @Override
114     public String getQProperty(String prop) {
115         return TaxonConstants.NUXEO_SCHEMA_NAME + ":" + prop;
116     }
117 }
118