]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
95b1688f429aa8450bdfae1209497a18230e3cbe
[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     /* (non-Javadoc)
55      * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#handleCreate(org.collectionspace.services.common.document.DocumentWrapper)
56      */
57     @Override
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());
62     }
63
64     /* (non-Javadoc)
65      * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#handleUpdate(org.collectionspace.services.common.document.DocumentWrapper)
66      */
67     @Override
68     public void handleUpdate(DocumentWrapper<DocumentModel> wrapDoc) throws Exception {
69         super.handleUpdate(wrapDoc);
70         handleDisplayNames(wrapDoc.getWrappedObject());
71     }
72
73     /**
74      * Handle display name.
75      *
76      * @param docModel the doc model
77      * @throws Exception the exception
78      */
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;
87         }
88         if (shortDisplayNameComputed == null) {
89             shortDisplayNameComputed = true;
90         }
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,
96                         displayName);
97             }
98             if (shortDisplayNameComputed) {
99                 docModel.setProperty(commonPartLabel, TaxonJAXBSchema.SHORT_DISPLAY_NAME,
100                         displayName);
101             }
102         }
103     }
104
105     /**
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.
110      * @param name
111      * @return
112      * @throws Exception
113      */
114     private static String prepareDefaultDisplayName(
115             String name) throws Exception {
116         StringBuilder newStr = new StringBuilder();
117         newStr.append(name);
118         return newStr.toString();
119     }
120
121     /**
122      * getQProperty converts the given property to qualified schema property
123      * @param prop
124      * @return
125      */
126     @Override
127     public String getQProperty(String prop) {
128         return TaxonConstants.NUXEO_SCHEMA_NAME + ":" + prop;
129     }
130 }
131