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.VocabularyJAXBSchema;
30 import org.collectionspace.services.common.document.DocumentHandler.Action;
31 import org.collectionspace.services.common.document.DocumentFilter;
32 import org.collectionspace.services.common.document.DocumentWrapper;
33 import org.collectionspace.services.vocabulary.VocabulariesCommon;
34 import org.collectionspace.services.vocabulary.VocabulariesCommonList;
35 import org.collectionspace.services.vocabulary.VocabulariesCommonList.VocabularyListItem;
37 import org.collectionspace.services.nuxeo.client.java.RemoteDocumentModelHandlerImpl;
38 import org.collectionspace.services.nuxeo.util.NuxeoUtils;
39 import org.nuxeo.ecm.core.api.DocumentModel;
40 import org.nuxeo.ecm.core.api.DocumentModelList;
41 import org.slf4j.Logger;
42 import org.slf4j.LoggerFactory;
45 * VocabularyDocumentModelHandler
47 * $LastChangedRevision: $
50 public class VocabularyDocumentModelHandler
51 extends RemoteDocumentModelHandlerImpl<VocabulariesCommon, VocabulariesCommonList> {
54 private final Logger logger = LoggerFactory.getLogger(VocabularyDocumentModelHandler.class);
56 * vocabulary is used to stash JAXB object to use when handle is called
57 * for Action.CREATE, Action.UPDATE or Action.GET
59 private VocabulariesCommon vocabulary;
61 * vocabularyList is stashed when handle is called
64 private VocabulariesCommonList vocabularyList;
68 * getCommonPart get associated vocabulary
72 public VocabulariesCommon getCommonPart() {
77 * setCommonPart set associated vocabulary
81 public void setCommonPart(VocabulariesCommon vocabulary) {
82 this.vocabulary = vocabulary;
86 * getCommonPartList get associated vocabulary (for index/GET_ALL)
90 public VocabulariesCommonList getCommonPartList() {
91 return vocabularyList;
95 * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#setCommonPartList(java.lang.Object)
98 public void setCommonPartList(VocabulariesCommonList vocabularyList) {
99 this.vocabularyList = vocabularyList;
103 * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#extractCommonPart(org.collectionspace.services.common.document.DocumentWrapper)
106 public VocabulariesCommon extractCommonPart(DocumentWrapper<DocumentModel> wrapDoc)
108 throw new UnsupportedOperationException();
112 * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#fillCommonPart(java.lang.Object, org.collectionspace.services.common.document.DocumentWrapper)
115 public void fillCommonPart(VocabulariesCommon vocabularyObject, DocumentWrapper<DocumentModel> wrapDoc) throws Exception {
116 throw new UnsupportedOperationException();
120 * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#extractCommonPartList(org.collectionspace.services.common.document.DocumentWrapper)
123 public VocabulariesCommonList extractCommonPartList(
124 DocumentWrapper<DocumentModelList> wrapDoc) throws Exception {
125 VocabulariesCommonList coList = extractPagingInfo(new VocabulariesCommonList(), wrapDoc);
126 List<VocabulariesCommonList.VocabularyListItem> list = coList.getVocabularyListItem();
127 Iterator<DocumentModel> iter = wrapDoc.getWrappedObject().iterator();
128 while(iter.hasNext()){
129 DocumentModel docModel = iter.next();
130 VocabularyListItem ilistItem = new VocabularyListItem();
131 ilistItem.setDisplayName((String) docModel.getProperty(getServiceContext().getCommonPartLabel(),
132 VocabularyJAXBSchema.DISPLAY_NAME));
133 ilistItem.setRefName((String) docModel.getProperty(getServiceContext().getCommonPartLabel(),
134 VocabularyJAXBSchema.REF_NAME));
135 ilistItem.setShortIdentifier((String) docModel.getProperty(getServiceContext().getCommonPartLabel(),
136 VocabularyJAXBSchema.SHORT_IDENTIFIER));
137 ilistItem.setVocabType((String) docModel.getProperty(getServiceContext().getCommonPartLabel(),
138 VocabularyJAXBSchema.VOCAB_TYPE));
139 String id = NuxeoUtils.extractId(docModel.getPathAsString());
140 ilistItem.setUri(getServiceContextPath() + id);
141 ilistItem.setCsid(id);
149 * getQProperty converts the given property to qualified schema property
154 public String getQProperty(String prop) {
155 return VocabularyConstants.NUXEO_SCHEMA_NAME + ":" + prop;