]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
8b703b12540886d7b4ddebf9ad700eb39f39ddd6
[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.person.nuxeo;
25
26 import java.util.Arrays;
27 import java.util.List;
28
29 import org.collectionspace.services.client.PersonAuthorityClient;
30 import org.collectionspace.services.common.vocabulary.nuxeo.AuthorityItemDocumentModelHandler;
31 import org.collectionspace.services.PersonJAXBSchema;
32 import org.collectionspace.services.person.PersonsCommon;
33 import org.nuxeo.ecm.core.api.DocumentModel;
34
35 /**
36  * PersonDocumentModelHandler
37  *
38  * $LastChangedRevision: $
39  * $LastChangedDate: $
40  */
41 /**
42  * @author pschmitz
43  *
44  */
45 public class PersonDocumentModelHandler
46         extends AuthorityItemDocumentModelHandler<PersonsCommon> {
47
48     /** The logger. */
49     //private final Logger logger = LoggerFactory.getLogger(PersonDocumentModelHandler.class);
50     /**
51      * Common part schema label
52      */
53     private static final String COMMON_PART_LABEL = "persons_common";
54     
55     public PersonDocumentModelHandler() {
56         super(COMMON_PART_LABEL);
57     }
58
59     @Override
60     public String getAuthorityServicePath(){
61         return PersonAuthorityClient.SERVICE_PATH_COMPONENT;    // CSPACE-3932
62     }
63         
64     /**
65      * Handle display names.
66      *
67      * @param docModel the doc model
68      * @throws Exception the exception
69      */
70     /*
71     @Override
72     protected void handleComputedDisplayNames(DocumentModel docModel) throws Exception {
73         String commonPartLabel = getServiceContext().getCommonPartLabel("persons");
74         Boolean displayNameComputed = (Boolean) docModel.getProperty(commonPartLabel,
75                         PersonJAXBSchema.DISPLAY_NAME_COMPUTED);
76         Boolean shortDisplayNameComputed = (Boolean) docModel.getProperty(commonPartLabel,
77                         PersonJAXBSchema.SHORT_DISPLAY_NAME_COMPUTED);
78         if(displayNameComputed==null)
79                 displayNameComputed = true;
80         if(shortDisplayNameComputed==null)
81                 shortDisplayNameComputed = true;
82         if (displayNameComputed || shortDisplayNameComputed) {
83                 String forename = 
84                                 (String)docModel.getProperty(commonPartLabel, PersonJAXBSchema.FORE_NAME);
85                 String lastname = 
86                                 (String)docModel.getProperty(commonPartLabel, PersonJAXBSchema.SUR_NAME);
87                 if(shortDisplayNameComputed) {
88                         String displayName = prepareDefaultDisplayName(forename, null, lastname,
89                                         null, null);
90                         docModel.setProperty(commonPartLabel, PersonJAXBSchema.SHORT_DISPLAY_NAME,
91                                         displayName);
92                 }
93                 if(displayNameComputed) {
94                         String midname = 
95                                         (String)docModel.getProperty(commonPartLabel, PersonJAXBSchema.MIDDLE_NAME);                            
96                         String birthdate = 
97                                         (String)docModel.getProperty(commonPartLabel, PersonJAXBSchema.BIRTH_DATE);
98                         String deathdate = 
99                                         (String)docModel.getProperty(commonPartLabel, PersonJAXBSchema.DEATH_DATE);
100                         String displayName = prepareDefaultDisplayName(forename, midname, lastname,
101                                         birthdate, deathdate);
102                         docModel.setProperty(commonPartLabel, PersonJAXBSchema.DISPLAY_NAME,
103                                         displayName);
104                 }
105         }
106     }
107     * 
108     */
109         
110         
111     /**
112      * Produces a default displayName from the basic name and dates fields.
113      * see PersonAuthorityClientUtils.prepareDefaultDisplayName(String,String,String,String,String) which
114      * duplicates this logic, until we define a service-general utils package
115      * that is neither client nor service specific.
116      * @param foreName  
117      * @param middleName
118      * @param surName
119      * @param birthDate
120      * @param deathDate
121      * @return
122      * @throws Exception
123      */
124     /*
125     private static String prepareDefaultDisplayName(
126                 String foreName, String middleName, String surName,
127                 String birthDate, String deathDate ) throws Exception {
128                 final String SEP = " ";
129                 final String DATE_SEP = "-";
130
131                 StringBuilder newStr = new StringBuilder();
132                 List<String> nameStrings = 
133                         Arrays.asList(foreName, middleName, surName);
134                 boolean firstAdded = false;
135         for (String partStr : nameStrings ){
136                         if (partStr != null) {
137                                 if (firstAdded == true) {
138                                         newStr.append(SEP);
139                                 }
140                                 newStr.append(partStr);
141                                 firstAdded = true;
142                         }
143         }
144         // Now we add the dates. In theory could have dates with no name, but that is their problem.
145         boolean foundBirth = false;
146                 if (birthDate != null) {
147                         if (firstAdded) {
148                                 newStr.append(SEP);
149                         }
150                         newStr.append(birthDate);
151                 newStr.append(DATE_SEP);                // Put this in whether there is a death date or not
152                         foundBirth = true;
153                 }
154                 if (deathDate != null) {
155                         if (!foundBirth) {
156                                 if (firstAdded == true) {
157                                         newStr.append(SEP);
158                                 }
159                         newStr.append(DATE_SEP);
160                         }
161                         newStr.append(deathDate);
162                 }
163                 
164                 return newStr.toString();
165     }
166     * 
167     */
168     
169     /**
170      * getQProperty converts the given property to qualified schema property
171      * @param prop
172      * @return
173      */
174     @Override
175     public String getQProperty(String prop) {
176         return PersonConstants.NUXEO_SCHEMA_NAME + ":" + prop;
177     }
178 }
179