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;
30 import org.collectionspace.services.client.PersonAuthorityClient;
31 import org.collectionspace.services.common.vocabulary.nuxeo.AuthorityItemDocumentModelHandler;
32 import org.collectionspace.services.PersonJAXBSchema;
33 import org.collectionspace.services.common.document.DocumentWrapper;
34 import org.collectionspace.services.common.service.ObjectPartType;
35 import org.collectionspace.services.person.PersonsCommon;
36 import org.nuxeo.ecm.core.api.DocumentModel;
39 * PersonDocumentModelHandler
41 * $LastChangedRevision: $
48 public class PersonDocumentModelHandler
49 extends AuthorityItemDocumentModelHandler<PersonsCommon> {
52 //private final Logger logger = LoggerFactory.getLogger(PersonDocumentModelHandler.class);
54 * Common part schema label
56 private static final String COMMON_PART_LABEL = "persons_common";
58 public PersonDocumentModelHandler() {
59 super(COMMON_PART_LABEL);
63 public String getAuthorityServicePath(){
64 return PersonAuthorityClient.SERVICE_PATH_COMPONENT; // CSPACE-3932
68 * Handle display names.
70 * @param docModel the doc model
71 * @throws Exception the exception
74 protected void handleComputedDisplayNames(DocumentModel docModel) throws Exception {
75 String commonPartLabel = getServiceContext().getCommonPartLabel("persons");
76 Boolean displayNameComputed = (Boolean) docModel.getProperty(commonPartLabel,
77 PersonJAXBSchema.DISPLAY_NAME_COMPUTED);
78 Boolean shortDisplayNameComputed = (Boolean) docModel.getProperty(commonPartLabel,
79 PersonJAXBSchema.SHORT_DISPLAY_NAME_COMPUTED);
80 if(displayNameComputed==null)
81 displayNameComputed = true;
82 if(shortDisplayNameComputed==null)
83 shortDisplayNameComputed = true;
84 if (displayNameComputed || shortDisplayNameComputed) {
86 (String)docModel.getProperty(commonPartLabel, PersonJAXBSchema.FORE_NAME);
88 (String)docModel.getProperty(commonPartLabel, PersonJAXBSchema.SUR_NAME);
89 if(shortDisplayNameComputed) {
90 String displayName = prepareDefaultDisplayName(forename, null, lastname,
92 docModel.setProperty(commonPartLabel, PersonJAXBSchema.SHORT_DISPLAY_NAME,
95 if(displayNameComputed) {
97 (String)docModel.getProperty(commonPartLabel, PersonJAXBSchema.MIDDLE_NAME);
99 (String)docModel.getProperty(commonPartLabel, PersonJAXBSchema.BIRTH_DATE);
101 (String)docModel.getProperty(commonPartLabel, PersonJAXBSchema.DEATH_DATE);
102 String displayName = prepareDefaultDisplayName(forename, midname, lastname,
103 birthdate, deathdate);
104 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.
124 private static String prepareDefaultDisplayName(
125 String foreName, String middleName, String surName,
126 String birthDate, String deathDate ) throws Exception {
127 final String SEP = " ";
128 final String DATE_SEP = "-";
130 StringBuilder newStr = new StringBuilder();
131 List<String> nameStrings =
132 Arrays.asList(foreName, middleName, surName);
133 boolean firstAdded = false;
134 for (String partStr : nameStrings ){
135 if (partStr != null) {
136 if (firstAdded == true) {
139 newStr.append(partStr);
143 // Now we add the dates. In theory could have dates with no name, but that is their problem.
144 boolean foundBirth = false;
145 if (birthDate != null) {
149 newStr.append(birthDate);
150 newStr.append(DATE_SEP); // Put this in whether there is a death date or not
153 if (deathDate != null) {
155 if (firstAdded == true) {
158 newStr.append(DATE_SEP);
160 newStr.append(deathDate);
163 return newStr.toString();
168 * @see org.collectionspace.services.nuxeo.client.java.RemoteDocumentModelHandlerImpl#extractPart(org.nuxeo.ecm.core.api.DocumentModel, java.lang.String, org.collectionspace.services.common.service.ObjectPartType)
171 protected Map<String, Object> extractPart(DocumentModel docModel, String schema, ObjectPartType partMeta)
173 Map<String, Object> unQObjectProperties = super.extractPart(docModel, schema, partMeta);
175 // Add the CSID to the common part
176 if (partMeta.getLabel().equalsIgnoreCase(COMMON_PART_LABEL)) {
177 String csid = getCsid(docModel);//NuxeoUtils.extractId(docModel.getPathAsString());
178 unQObjectProperties.put("csid", csid);
181 return unQObjectProperties;
185 * getQProperty converts the given property to qualified schema property
190 public String getQProperty(String prop) {
191 return PersonConstants.NUXEO_SCHEMA_NAME + ":" + prop;