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.VocabularyItemJAXBSchema;
30 import org.collectionspace.services.common.repository.DocumentWrapper;
31 import org.collectionspace.services.nuxeo.client.java.RemoteDocumentModelHandler;
32 import org.collectionspace.services.vocabulary.VocabularyitemsCommon;
33 import org.collectionspace.services.vocabulary.VocabularyitemsCommonList;
34 import org.collectionspace.services.vocabulary.VocabularyitemsCommonList.VocabularyitemListItem;
35 import org.nuxeo.ecm.core.api.DocumentModel;
36 import org.nuxeo.ecm.core.api.DocumentModelList;
37 import org.slf4j.Logger;
38 import org.slf4j.LoggerFactory;
41 * VocabularyItemDocumentModelHandler
43 * $LastChangedRevision: $
46 public class VocabularyItemDocumentModelHandler
47 extends RemoteDocumentModelHandler<VocabularyitemsCommon, VocabularyitemsCommonList> {
49 private final Logger logger = LoggerFactory.getLogger(VocabularyItemDocumentModelHandler.class);
51 * vocabularyItem is used to stash JAXB object to use when handle is called
52 * for Action.CREATE, Action.UPDATE or Action.GET
54 private VocabularyitemsCommon vocabularyItem;
56 * vocabularyItemList is stashed when handle is called
59 private VocabularyitemsCommonList vocabularyItemList;
62 * inVocabulary is the parent vocabulary for this context
64 private String inVocabulary;
66 public String getInVocabulary() {
70 public void setInVocabulary(String inVocabulary) {
71 this.inVocabulary = inVocabulary;
75 public void prepare(Action action) throws Exception {
76 //no specific action needed
80 * getCommonPart get associated vocabularyItem
84 public VocabularyitemsCommon getCommonPart() {
85 return vocabularyItem;
89 * setCommonPart set associated vocabularyItem
90 * @param vocabularyItem
93 public void setCommonPart(VocabularyitemsCommon vocabularyItem) {
94 this.vocabularyItem = vocabularyItem;
98 * getCommonPartList get associated vocabularyItem (for index/GET_ALL)
102 public VocabularyitemsCommonList getCommonPartList() {
103 return vocabularyItemList;
107 public void setCommonPartList(VocabularyitemsCommonList vocabularyItemList) {
108 this.vocabularyItemList = vocabularyItemList;
112 public VocabularyitemsCommon extractCommonPart(DocumentWrapper wrapDoc)
114 throw new UnsupportedOperationException();
118 public void fillCommonPart(VocabularyitemsCommon vocabularyItemObject, DocumentWrapper wrapDoc) throws Exception {
119 throw new UnsupportedOperationException();
123 public VocabularyitemsCommonList extractCommonPartList(DocumentWrapper wrapDoc)
125 VocabularyitemsCommonList coList = new VocabularyitemsCommonList();
127 DocumentModelList docList = (DocumentModelList) wrapDoc.getWrappedObject();
129 List<VocabularyitemsCommonList.VocabularyitemListItem> list =
130 coList.getVocabularyitemListItem();
132 //FIXME: iterating over a long list of documents is not a long term
133 //strategy...need to change to more efficient iterating in future
134 Iterator<DocumentModel> iter = docList.iterator();
135 while(iter.hasNext()){
136 DocumentModel docModel = iter.next();
137 String parentVocab = (String)docModel.getProperty(getServiceContext().getCommonPartLabel("vocabularyItems"),
138 VocabularyItemJAXBSchema.IN_VOCABULARY);
139 if( !inVocabulary.equals(parentVocab))
141 VocabularyitemListItem ilistItem = new VocabularyitemListItem();
142 ilistItem.setDisplayName((String) docModel.getProperty(getServiceContext().getCommonPartLabel("vocabularyItems"),
143 VocabularyItemJAXBSchema.DISPLAY_NAME));
144 String id = docModel.getId();
145 ilistItem.setUri("/vocabularies/"+inVocabulary+"/items/" + id);
146 ilistItem.setCsid(id);
150 if(logger.isDebugEnabled()){
151 logger.debug("Caught exception in extractCommonPartList", e);
160 * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#getDocumentType()
163 public String getDocumentType() {
164 return VocabularyItemConstants.NUXEO_DOCTYPE;
168 * getQProperty converts the given property to qualified schema property
173 public String getQProperty(String prop) {
174 return VocabularyItemConstants.NUXEO_SCHEMA_NAME + ":" + prop;