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.vocabulary.nuxeo;
26 import java.util.Iterator;
27 import java.util.List;
29 import org.collectionspace.services.common.vocabulary.AuthorityItemJAXBSchema;
30 import org.collectionspace.services.common.document.DocumentWrapper;
31 import org.collectionspace.services.common.vocabulary.nuxeo.AuthorityItemDocumentModelHandler;
32 import org.collectionspace.services.nuxeo.util.NuxeoUtils;
33 import org.collectionspace.services.jaxb.AbstractCommonList;
34 import org.collectionspace.services.vocabulary.VocabularyitemsCommon;
35 import org.collectionspace.services.vocabulary.VocabularyitemsCommonList;
36 import org.collectionspace.services.vocabulary.VocabularyitemsCommonList.VocabularyitemListItem;
37 import org.nuxeo.ecm.core.api.DocumentModel;
38 import org.nuxeo.ecm.core.api.DocumentModelList;
39 import org.slf4j.Logger;
40 import org.slf4j.LoggerFactory;
43 * VocabularyItemDocumentModelHandler
45 * $LastChangedRevision: $
48 public class VocabularyItemDocumentModelHandler
49 extends AuthorityItemDocumentModelHandler<VocabularyitemsCommon, VocabularyitemsCommonList> {
51 private final Logger logger = LoggerFactory.getLogger(VocabularyItemDocumentModelHandler.class);
53 private static final String COMMON_PART_LABEL = "vocabularyitems_common";
55 public VocabularyItemDocumentModelHandler() {
56 super(COMMON_PART_LABEL);
61 public VocabularyitemsCommonList extractCommonPartList(
62 DocumentWrapper<DocumentModelList> wrapDoc) throws Exception {
63 VocabularyitemsCommonList coList = extractPagingInfo(new VocabularyitemsCommonList(), wrapDoc);
64 AbstractCommonList commonList = (AbstractCommonList) coList;
65 commonList.setFieldsReturned("displayName|refName|shortIdentifier|uri|csid");
67 List<VocabularyitemsCommonList.VocabularyitemListItem> list = coList.getVocabularyitemListItem();
68 Iterator<DocumentModel> iter = wrapDoc.getWrappedObject().iterator();
69 String commonPartLabel = getServiceContext().getCommonPartLabel("vocabularyItems");
70 while (iter.hasNext()) {
71 DocumentModel docModel = iter.next();
72 VocabularyitemListItem ilistItem = new VocabularyitemListItem();
73 ilistItem.setDisplayName((String) docModel.getProperty(commonPartLabel,
74 AuthorityItemJAXBSchema.DISPLAY_NAME));
75 ilistItem.setShortIdentifier((String) docModel.getProperty(commonPartLabel,
76 AuthorityItemJAXBSchema.SHORT_IDENTIFIER));
77 ilistItem.setRefName((String) docModel.getProperty(commonPartLabel,
78 AuthorityItemJAXBSchema.REF_NAME));
79 String id = getCsid(docModel);//NuxeoUtils.extractId(docModel.getPathAsString());
80 ilistItem.setUri("/vocabularies/" + inAuthority + "/items/" + id);
81 ilistItem.setCsid(id);
89 * getQProperty converts the given property to qualified schema property
94 public String getQProperty(String prop) {
95 return VocabularyItemConstants.NUXEO_SCHEMA_NAME + ":" + prop;