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.organization.nuxeo;
26 import org.collectionspace.services.client.OrgAuthorityClient;
27 import org.collectionspace.services.common.vocabulary.nuxeo.AuthorityItemDocumentModelHandler;
28 import org.collectionspace.services.OrganizationJAXBSchema;
29 import org.collectionspace.services.common.document.DocumentWrapper;
30 import org.collectionspace.services.organization.OrganizationsCommon;
31 import org.nuxeo.ecm.core.api.DocumentModel;
32 import org.slf4j.Logger;
33 import org.slf4j.LoggerFactory;
36 * OrganizationDocumentModelHandler
38 * $LastChangedRevision$
41 public class OrganizationDocumentModelHandler
42 extends AuthorityItemDocumentModelHandler<OrganizationsCommon> {
45 private final Logger logger = LoggerFactory.getLogger(OrganizationDocumentModelHandler.class);
47 * Common part schema label
49 private static final String COMMON_PART_LABEL = "organizations_common";
51 public OrganizationDocumentModelHandler() {
52 super(COMMON_PART_LABEL);
56 public String getAuthorityServicePath(){
57 return OrgAuthorityClient.SERVICE_PATH_COMPONENT; // CSPACE-3932
61 * Check the logic around the computed displayName
65 * @throws Exception the exception
68 // protected void handleComputedDisplayNames(DocumentModel docModel) throws Exception {
69 // String commonPartLabel = getServiceContext().getCommonPartLabel("organizations");
70 // Boolean displayNameComputed = (Boolean) docModel.getProperty(commonPartLabel,
71 // OrganizationJAXBSchema.DISPLAY_NAME_COMPUTED);
72 // Boolean shortDisplayNameComputed = (Boolean) docModel.getProperty(commonPartLabel,
73 // OrganizationJAXBSchema.SHORT_DISPLAY_NAME_COMPUTED);
74 // if(displayNameComputed==null)
75 // displayNameComputed = Boolean.TRUE;
76 // if(shortDisplayNameComputed==null)
77 // shortDisplayNameComputed = Boolean.TRUE;
78 // if (displayNameComputed.booleanValue() || shortDisplayNameComputed.booleanValue()) {
79 // String shortName = getStringValueInPrimaryRepeatingComplexProperty(
80 // docModel, commonPartLabel, OrganizationJAXBSchema.MAIN_BODY_GROUP_LIST,
81 // OrganizationJAXBSchema.SHORT_NAME);
82 // // FIXME: Determine how to handle cases where primary short name is null or empty.
83 // if(shortDisplayNameComputed.booleanValue()) {
84 // String displayName = prepareDefaultDisplayName(shortName, null);
85 // docModel.setProperty(commonPartLabel, OrganizationJAXBSchema.SHORT_DISPLAY_NAME,
88 // if(displayNameComputed.booleanValue()) {
89 // String foundingPlace = (String) docModel.getProperty(commonPartLabel,
90 // OrganizationJAXBSchema.FOUNDING_PLACE);
91 // String displayName = prepareDefaultDisplayName(shortName, foundingPlace);
92 // docModel.setProperty(commonPartLabel, OrganizationJAXBSchema.DISPLAY_NAME,
99 * Produces a default displayName from the basic name and foundingPlace fields.
100 * @see OrgAuthorityClientUtils.prepareDefaultDisplayName() which
101 * duplicates this logic, until we define a service-general utils package
102 * that is neither client nor service specific.
104 * @param foundingPlace
108 private static String prepareDefaultDisplayName(
109 String shortName, String foundingPlace ) throws Exception {
110 StringBuilder newStr = new StringBuilder();
111 final String sep = " ";
112 boolean firstAdded = false;
113 if(null != shortName ) {
114 newStr.append(shortName);
117 // Now we add the place
118 if(null != foundingPlace ) {
122 newStr.append(foundingPlace);
124 return newStr.toString();
128 * getQProperty converts the given property to qualified schema property
133 public String getQProperty(String prop) {
134 return OrganizationConstants.NUXEO_SCHEMA_NAME + ":" + prop;