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:
6 * http://www.collectionspace.org
7 * http://wiki.collectionspace.org
9 * Copyright 2009 University of California at Berkeley
11 * Licensed under the Educational Community License (ECL), Version 2.0.
12 * You may not use this file except in compliance with this License.
14 * You may obtain a copy of the ECL 2.0 License at
16 * https://source.collectionspace.org/collection-space/LICENSE.txt
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.
24 package org.collectionspace.services.person.nuxeo;
26 import java.util.Arrays;
27 import java.util.List;
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;
36 * PersonDocumentModelHandler
38 * $LastChangedRevision: $
45 public class PersonDocumentModelHandler
46 extends AuthorityItemDocumentModelHandler<PersonsCommon> {
49 //private final Logger logger = LoggerFactory.getLogger(PersonDocumentModelHandler.class);
51 * Common part schema label
53 private static final String COMMON_PART_LABEL = "persons_common";
55 public PersonDocumentModelHandler() {
56 super(COMMON_PART_LABEL);
60 public String getAuthorityServicePath(){
61 return PersonAuthorityClient.SERVICE_PATH_COMPONENT; // CSPACE-3932
65 * Handle display names.
67 * @param docModel the doc model
68 * @throws Exception the exception
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) {
84 (String)docModel.getProperty(commonPartLabel, PersonJAXBSchema.FORE_NAME);
86 (String)docModel.getProperty(commonPartLabel, PersonJAXBSchema.SUR_NAME);
87 if(shortDisplayNameComputed) {
88 String displayName = prepareDefaultDisplayName(forename, null, lastname,
90 docModel.setProperty(commonPartLabel, PersonJAXBSchema.SHORT_DISPLAY_NAME,
93 if(displayNameComputed) {
95 (String)docModel.getProperty(commonPartLabel, PersonJAXBSchema.MIDDLE_NAME);
97 (String)docModel.getProperty(commonPartLabel, PersonJAXBSchema.BIRTH_DATE);
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,
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.
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 = "-";
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) {
140 newStr.append(partStr);
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) {
150 newStr.append(birthDate);
151 newStr.append(DATE_SEP); // Put this in whether there is a death date or not
154 if (deathDate != null) {
156 if (firstAdded == true) {
159 newStr.append(DATE_SEP);
161 newStr.append(deathDate);
164 return newStr.toString();
170 * getQProperty converts the given property to qualified schema property
175 public String getQProperty(String prop) {
176 return PersonConstants.NUXEO_SCHEMA_NAME + ":" + prop;