]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
dcd7f2bf6f641ebfa7b92abfc596b37ffb233657
[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.vocabulary.nuxeo;
25
26 import org.collectionspace.services.client.VocabularyClient;
27 import org.collectionspace.services.common.context.ServiceBindingUtils;
28 import org.collectionspace.services.common.vocabulary.AuthorityItemJAXBSchema;
29 import org.collectionspace.services.common.vocabulary.nuxeo.AuthorityItemDocumentModelHandler;
30 import org.collectionspace.services.config.service.ListResultField;
31 import org.collectionspace.services.nuxeo.util.NuxeoUtils;
32 import org.collectionspace.services.vocabulary.VocabularyitemsCommon;
33 import org.nuxeo.ecm.core.api.ClientException;
34 import org.nuxeo.ecm.core.api.DocumentModel;
35
36 /**
37  * VocabularyItemDocumentModelHandler
38  *
39  * $LastChangedRevision: $
40  * $LastChangedDate: $
41  */
42 public class VocabularyItemDocumentModelHandler
43                 extends AuthorityItemDocumentModelHandler<VocabularyitemsCommon> {
44
45     private static final String COMMON_PART_LABEL = "vocabularyitems_common";   
46     
47     public VocabularyItemDocumentModelHandler() {
48         super(COMMON_PART_LABEL);
49     }
50
51     @Override
52     public String getAuthorityServicePath(){
53         return VocabularyClient.SERVICE_PATH_COMPONENT;    // CSPACE-3932
54     }
55     
56     @Override
57     protected String getRefPropName() {
58         return ServiceBindingUtils.TERM_REF_PROP;
59     }
60
61     /**
62      * getQProperty converts the given property to qualified schema property
63      * @param prop
64      * @return
65      */
66     @Override
67     public String getQProperty(String prop) {
68         return VocabularyItemConstants.NUXEO_SCHEMA_NAME + ":" + prop;
69     }
70     
71     /*
72      * Because the Vocabulary service's item schema is not standard, we need to override the default authority item schema behavior.
73      * (non-Javadoc)
74      * @see org.collectionspace.services.common.vocabulary.nuxeo.AuthorityItemDocumentModelHandler#getPrimaryDisplayName(org.nuxeo.ecm.core.api.DocumentModel, java.lang.String, java.lang.String, java.lang.String)
75      */
76         @Override
77         protected String getPrimaryDisplayName(DocumentModel docModel,
78                         String schema, String complexPropertyName, String fieldName) {
79                 String result = null;
80
81                 try {
82                         result = (String) docModel.getProperty(schema, AuthorityItemJAXBSchema.DISPLAY_NAME);
83                 } catch (Exception e) {
84                         throw new RuntimeException("Unknown problem retrieving property {"
85                                         + schema + ":" + fieldName + "}." + e.getLocalizedMessage());
86                 }
87
88                 return result;
89         }
90     
91     /*
92      * Because the Vocabulary service's item schema is not standard, we need to override this method.
93      */
94     @Override
95         protected ListResultField getListResultField() {
96                 ListResultField result = new ListResultField();
97
98                 result.setElement(AuthorityItemJAXBSchema.DISPLAY_NAME);
99                 result.setXpath(NuxeoUtils.getPrimaryXPathPropertyName(this.getAuthorityItemCommonSchemaName(),
100                                 getItemTermInfoGroupXPathBase(),
101                                 AuthorityItemJAXBSchema.TERM_DISPLAY_NAME));
102
103                 return result;
104         }
105     
106 }
107