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.TaxonJAXBSchema;
33 import org.collectionspace.services.client.TaxonomyAuthorityClient;
34 import org.collectionspace.services.common.document.DocumentFilter;
35 import org.collectionspace.services.common.document.DocumentWrapper;
36 import org.collectionspace.services.common.service.ObjectPartType;
37 import org.collectionspace.services.common.vocabulary.AuthorityItemJAXBSchema;
38 import org.collectionspace.services.common.vocabulary.nuxeo.AuthorityItemDocumentModelHandler;
39 import org.collectionspace.services.nuxeo.client.java.RemoteDocumentModelHandlerImpl;
40 import org.collectionspace.services.nuxeo.util.NuxeoUtils;
41 import org.collectionspace.services.jaxb.AbstractCommonList;
42 import org.collectionspace.services.taxonomy.TaxonCommon;
43 import org.collectionspace.services.taxonomy.TaxonCommonList;
44 import org.collectionspace.services.taxonomy.TaxonCommonList.TaxonListItem;
45 import org.nuxeo.ecm.core.api.DocumentModel;
46 import org.nuxeo.ecm.core.api.DocumentModelList;
47 import org.slf4j.Logger;
48 import org.slf4j.LoggerFactory;
51 * TaxonomyDocumentModelHandler
53 * $LastChangedRevision$
60 public class TaxonDocumentModelHandler
61 extends AuthorityItemDocumentModelHandler<TaxonCommon, TaxonCommonList> {
64 private final Logger logger = LoggerFactory.getLogger(TaxonDocumentModelHandler.class);
66 * Common part schema label
68 private static final String COMMON_PART_LABEL = "taxon_common";
70 public TaxonDocumentModelHandler() {
71 super(COMMON_PART_LABEL);
75 public String getAuthorityServicePath(){
76 return TaxonomyAuthorityClient.SERVICE_PATH_COMPONENT; // CSPACE-3932
80 * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#handleCreate(org.collectionspace.services.common.document.DocumentWrapper)
83 public void handleCreate(DocumentWrapper<DocumentModel> wrapDoc) throws Exception {
84 // first fill all the parts of the document
85 super.handleCreate(wrapDoc);
86 handleDisplayNames(wrapDoc.getWrappedObject());
90 * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#handleUpdate(org.collectionspace.services.common.document.DocumentWrapper)
93 public void handleUpdate(DocumentWrapper<DocumentModel> wrapDoc) throws Exception {
94 super.handleUpdate(wrapDoc);
95 handleDisplayNames(wrapDoc.getWrappedObject());
99 * Handle display name.
101 * @param docModel the doc model
102 * @throws Exception the exception
104 private void handleDisplayNames(DocumentModel docModel) throws Exception {
105 String commonPartLabel = getServiceContext().getCommonPartLabel("taxon");
106 Boolean displayNameComputed = (Boolean) docModel.getProperty(commonPartLabel,
107 TaxonJAXBSchema.DISPLAY_NAME_COMPUTED);
108 Boolean shortDisplayNameComputed = (Boolean) docModel.getProperty(commonPartLabel,
109 TaxonJAXBSchema.SHORT_DISPLAY_NAME_COMPUTED);
110 if (displayNameComputed == null) {
111 displayNameComputed = true;
113 if (shortDisplayNameComputed == null) {
114 shortDisplayNameComputed = true;
116 if (displayNameComputed || shortDisplayNameComputed) {
117 String displayName = prepareDefaultDisplayName(
118 (String) docModel.getProperty(commonPartLabel, TaxonJAXBSchema.NAME));
119 if (displayNameComputed) {
120 docModel.setProperty(commonPartLabel, TaxonJAXBSchema.DISPLAY_NAME,
123 if (shortDisplayNameComputed) {
124 docModel.setProperty(commonPartLabel, TaxonJAXBSchema.SHORT_DISPLAY_NAME,
131 * Produces a default displayName from the basic name and dates fields.
132 * @see TaxonomyAuthorityClientUtils.prepareDefaultDisplayName() which
133 * duplicates this logic, until we define a service-general utils package
134 * that is neither client nor service specific.
139 private static String prepareDefaultDisplayName(
140 String name) throws Exception {
141 StringBuilder newStr = new StringBuilder();
143 return newStr.toString();
147 * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#extractCommonPartList(org.collectionspace.services.common.document.DocumentWrapper)
150 public TaxonCommonList extractCommonPartList(
151 DocumentWrapper<DocumentModelList> wrapDoc) throws Exception {
152 TaxonCommonList coList = extractPagingInfo(new TaxonCommonList(), wrapDoc);
153 AbstractCommonList commonList = (AbstractCommonList) coList;
154 commonList.setFieldsReturned("displayName|refName|shortIdentifier|uri|csid");
155 List<TaxonCommonList.TaxonListItem> list = coList.getTaxonListItem();
156 Iterator<DocumentModel> iter = wrapDoc.getWrappedObject().iterator();
157 String commonPartLabel = getServiceContext().getCommonPartLabel("taxon");
158 while (iter.hasNext()) {
159 DocumentModel docModel = iter.next();
160 TaxonListItem ilistItem = new TaxonListItem();
161 ilistItem.setDisplayName((String) docModel.getProperty(
162 commonPartLabel, AuthorityItemJAXBSchema.DISPLAY_NAME));
163 ilistItem.setShortIdentifier((String) docModel.getProperty(commonPartLabel,
164 AuthorityItemJAXBSchema.SHORT_IDENTIFIER));
165 ilistItem.setRefName((String) docModel.getProperty(commonPartLabel,
166 AuthorityItemJAXBSchema.REF_NAME));
167 String id = getCsid(docModel);//NuxeoUtils.extractId(docModel.getPathAsString());
168 ilistItem.setUri("/taxonomyauthorities/" + inAuthority + "/items/"
170 ilistItem.setCsid(id);
178 * getQProperty converts the given property to qualified schema property
183 public String getQProperty(String prop) {
184 return TaxonConstants.NUXEO_SCHEMA_NAME + ":" + prop;