]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
2f0c0326874e0d81ebc79c08086f9f46612644d4
[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.location.nuxeo;
25
26 import org.collectionspace.services.LocationJAXBSchema;
27 import org.collectionspace.services.client.LocationAuthorityClient;
28 import org.collectionspace.services.common.document.DocumentWrapper;
29 import org.collectionspace.services.common.vocabulary.nuxeo.AuthorityItemDocumentModelHandler;
30 import org.collectionspace.services.location.LocationsCommon;
31 import org.nuxeo.ecm.core.api.DocumentModel;
32
33 /**
34  * LocationDocumentModelHandler
35  *
36  * $LastChangedRevision: $
37  * $LastChangedDate: $
38  */
39 /**
40  * @author pschmitz
41  *
42  */
43 public class LocationDocumentModelHandler
44         extends AuthorityItemDocumentModelHandler<LocationsCommon> {
45
46     /**
47      * Common part schema label
48      */
49     private static final String COMMON_PART_LABEL = "locations_common";
50     
51     public LocationDocumentModelHandler() {
52         super(COMMON_PART_LABEL);
53     }
54
55     @Override
56     public String getAuthorityServicePath(){
57         return LocationAuthorityClient.SERVICE_PATH_COMPONENT;    //  CSPACE-3932
58     }
59         
60     /* (non-Javadoc)
61      * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#handleCreate(org.collectionspace.services.common.document.DocumentWrapper)
62      */
63     @Override
64     public void handleCreate(DocumentWrapper<DocumentModel> wrapDoc) throws Exception {
65         // first fill all the parts of the document
66         super.handleCreate(wrapDoc);            
67         handleDisplayNames(wrapDoc.getWrappedObject());
68     }
69     
70     /* (non-Javadoc)
71      * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#handleUpdate(org.collectionspace.services.common.document.DocumentWrapper)
72      */
73     @Override
74     public void handleUpdate(DocumentWrapper<DocumentModel> wrapDoc) throws Exception {
75         super.handleUpdate(wrapDoc);
76         handleDisplayNames(wrapDoc.getWrappedObject());
77     }
78
79     /**
80      * Handle display name.
81      *
82      * @param docModel the doc model
83      * @throws Exception the exception
84      */
85     private void handleDisplayNames(DocumentModel docModel) throws Exception {
86         String commonPartLabel = getServiceContext().getCommonPartLabel("locations");
87         Boolean displayNameComputed = (Boolean) docModel.getProperty(commonPartLabel,
88                         LocationJAXBSchema.DISPLAY_NAME_COMPUTED);
89         Boolean shortDisplayNameComputed = (Boolean) docModel.getProperty(commonPartLabel,
90                         LocationJAXBSchema.SHORT_DISPLAY_NAME_COMPUTED);
91         if(displayNameComputed==null)
92                 displayNameComputed = true;
93         if(shortDisplayNameComputed==null)
94                 shortDisplayNameComputed = true;
95         if (displayNameComputed || shortDisplayNameComputed) {
96                 String displayName = prepareDefaultDisplayName(
97                         (String)docModel.getProperty(commonPartLabel, LocationJAXBSchema.NAME ));
98                 if (displayNameComputed) {
99                         docModel.setProperty(commonPartLabel, LocationJAXBSchema.DISPLAY_NAME,
100                                         displayName);
101                 }
102                 if (shortDisplayNameComputed) {
103                         docModel.setProperty(commonPartLabel, LocationJAXBSchema.SHORT_DISPLAY_NAME,
104                                         displayName);
105                 }
106         }
107     }
108         
109     /**
110      * Produces a default displayName from the basic name and dates fields.
111      * @see LocationAuthorityClientUtils.prepareDefaultDisplayName() which
112      * duplicates this logic, until we define a service-general utils package
113      * that is neither client nor service specific.
114      * @param foreName  
115      * @param middleName
116      * @param surName
117      * @param birthDate
118      * @param deathDate
119      * @return
120      * @throws Exception
121      */
122     private static String prepareDefaultDisplayName(
123                 String name ) throws Exception {
124         StringBuilder newStr = new StringBuilder();
125                         newStr.append(name);
126                         return newStr.toString();
127     }
128     
129     /**
130      * getQProperty converts the given property to qualified schema property
131      * @param prop
132      * @return
133      */
134     @Override
135     public String getQProperty(String prop) {
136         return LocationConstants.NUXEO_SCHEMA_NAME + ":" + prop;
137     }
138 }
139