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.taxonomy.nuxeo;
26 import java.util.Iterator;
27 import java.util.ArrayList;
28 import java.util.Arrays;
29 import java.util.List;
32 import org.collectionspace.services.TaxonomyJAXBSchema;
33 import org.collectionspace.services.common.document.DocumentFilter;
34 import org.collectionspace.services.common.document.DocumentWrapper;
35 import org.collectionspace.services.common.service.ObjectPartType;
36 import org.collectionspace.services.common.vocabulary.AuthorityItemJAXBSchema;
37 import org.collectionspace.services.common.vocabulary.nuxeo.AuthorityItemDocumentModelHandler;
38 import org.collectionspace.services.nuxeo.client.java.RemoteDocumentModelHandlerImpl;
39 import org.collectionspace.services.nuxeo.util.NuxeoUtils;
40 import org.collectionspace.services.jaxb.AbstractCommonList;
41 import org.collectionspace.services.taxonomy.TaxonomyCommon;
42 import org.collectionspace.services.taxonomy.TaxonomyCommonList;
43 import org.collectionspace.services.taxonomy.TaxonomyCommonList.TaxonomyListItem;
44 import org.nuxeo.ecm.core.api.DocumentModel;
45 import org.nuxeo.ecm.core.api.DocumentModelList;
46 import org.slf4j.Logger;
47 import org.slf4j.LoggerFactory;
50 * TaxonomyDocumentModelHandler
52 * $LastChangedRevision$
59 public class TaxonomyDocumentModelHandler
60 extends AuthorityItemDocumentModelHandler<TaxonomyCommon, TaxonomyCommonList> {
63 private final Logger logger = LoggerFactory.getLogger(TaxonomyDocumentModelHandler.class);
65 * Common part schema label
67 private static final String COMMON_PART_LABEL = "taxonomy_common";
69 public TaxonomyDocumentModelHandler() {
70 super(COMMON_PART_LABEL);
74 * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#handleCreate(org.collectionspace.services.common.document.DocumentWrapper)
77 public void handleCreate(DocumentWrapper<DocumentModel> wrapDoc) throws Exception {
78 // first fill all the parts of the document
79 super.handleCreate(wrapDoc);
80 handleDisplayNames(wrapDoc.getWrappedObject());
84 * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#handleUpdate(org.collectionspace.services.common.document.DocumentWrapper)
87 public void handleUpdate(DocumentWrapper<DocumentModel> wrapDoc) throws Exception {
88 super.handleUpdate(wrapDoc);
89 handleDisplayNames(wrapDoc.getWrappedObject());
93 * Handle display name.
95 * @param docModel the doc model
96 * @throws Exception the exception
98 private void handleDisplayNames(DocumentModel docModel) throws Exception {
99 String commonPartLabel = getServiceContext().getCommonPartLabel("taxonomy");
100 Boolean displayNameComputed = (Boolean) docModel.getProperty(commonPartLabel,
101 TaxonomyJAXBSchema.DISPLAY_NAME_COMPUTED);
102 Boolean shortDisplayNameComputed = (Boolean) docModel.getProperty(commonPartLabel,
103 TaxonomyJAXBSchema.SHORT_DISPLAY_NAME_COMPUTED);
104 if(displayNameComputed==null)
105 displayNameComputed = true;
106 if(shortDisplayNameComputed==null)
107 shortDisplayNameComputed = true;
108 if (displayNameComputed || shortDisplayNameComputed) {
109 String displayName = prepareDefaultDisplayName(
110 (String)docModel.getProperty(commonPartLabel, TaxonomyJAXBSchema.NAME ));
111 if (displayNameComputed) {
112 docModel.setProperty(commonPartLabel, TaxonomyJAXBSchema.DISPLAY_NAME,
115 if (shortDisplayNameComputed) {
116 docModel.setProperty(commonPartLabel, TaxonomyJAXBSchema.SHORT_DISPLAY_NAME,
123 * Produces a default displayName from the basic name and dates fields.
124 * @see TaxonomyAuthorityClientUtils.prepareDefaultDisplayName() which
125 * duplicates this logic, until we define a service-general utils package
126 * that is neither client nor service specific.
135 private static String prepareDefaultDisplayName(
136 String name ) throws Exception {
137 StringBuilder newStr = new StringBuilder();
139 return newStr.toString();
143 * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#extractCommonPartList(org.collectionspace.services.common.document.DocumentWrapper)
146 public TaxonomyCommonList extractCommonPartList(
147 DocumentWrapper<DocumentModelList> wrapDoc) throws Exception {
148 TaxonomyCommonList coList = extractPagingInfo(new TaxonomyCommonList(), wrapDoc);
149 AbstractCommonList commonList = (AbstractCommonList) coList;
150 commonList.setFieldsReturned("displayName|refName|shortIdentifier|uri|csid");
151 List<TaxonomyCommonList.TaxonomyListItem> list = coList.getTaxonomyListItem();
152 Iterator<DocumentModel> iter = wrapDoc.getWrappedObject().iterator();
153 String commonPartLabel = getServiceContext().getCommonPartLabel(
155 while (iter.hasNext()) {
156 DocumentModel docModel = iter.next();
157 TaxonomyListItem ilistItem = new TaxonomyListItem();
158 ilistItem.setDisplayName((String) docModel.getProperty(
159 commonPartLabel, AuthorityItemJAXBSchema.DISPLAY_NAME));
160 ilistItem.setShortIdentifier((String) docModel.getProperty(commonPartLabel,
161 AuthorityItemJAXBSchema.SHORT_IDENTIFIER));
162 ilistItem.setRefName((String) docModel.getProperty(commonPartLabel,
163 AuthorityItemJAXBSchema.REF_NAME));
164 String id = getCsid(docModel);//NuxeoUtils.extractId(docModel.getPathAsString());
165 ilistItem.setUri("/taxonomyauthorities/" + inAuthority + "/items/"
167 ilistItem.setCsid(id);
175 * getQProperty converts the given property to qualified schema property
180 public String getQProperty(String prop) {
181 return TaxonomyConstants.NUXEO_SCHEMA_NAME + ":" + prop;