]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
2b22d6bdec7693f05c74a740211d39ace40ff051
[tmp/jakarta-migration.git] /
1 /**
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:
5
6  *  http://www.collectionspace.org
7  *  http://wiki.collectionspace.org
8
9  *  Copyright 2009 University of California at Berkeley
10
11  *  Licensed under the Educational Community License (ECL), Version 2.0.
12  *  You may not use this file except in compliance with this License.
13
14  *  You may obtain a copy of the ECL 2.0 License at
15
16  *  https://source.collectionspace.org/collection-space/LICENSE.txt
17
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.
23  */
24 package org.collectionspace.services.vocabulary.nuxeo;
25
26 import java.util.Iterator;
27 import java.util.List;
28
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;
36
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;
43
44 /**
45  * VocabularyDocumentModelHandler
46  *
47  * $LastChangedRevision: $
48  * $LastChangedDate: $
49  */
50 public class VocabularyDocumentModelHandler
51         extends RemoteDocumentModelHandlerImpl<VocabulariesCommon, VocabulariesCommonList> {
52
53     /** The logger. */
54     private final Logger logger = LoggerFactory.getLogger(VocabularyDocumentModelHandler.class);
55     /**
56      * vocabulary is used to stash JAXB object to use when handle is called
57      * for Action.CREATE, Action.UPDATE or Action.GET
58      */
59     private VocabulariesCommon vocabulary;
60     /**
61      * vocabularyList is stashed when handle is called
62      * for ACTION.GET_ALL
63      */
64     private VocabulariesCommonList vocabularyList;
65
66
67     /**
68      * getCommonPart get associated vocabulary
69      * @return
70      */
71     @Override
72     public VocabulariesCommon getCommonPart() {
73         return vocabulary;
74     }
75
76     /**
77      * setCommonPart set associated vocabulary
78      * @param vocabulary
79      */
80     @Override
81     public void setCommonPart(VocabulariesCommon vocabulary) {
82         this.vocabulary = vocabulary;
83     }
84
85     /**
86      * getCommonPartList get associated vocabulary (for index/GET_ALL)
87      * @return
88      */
89     @Override
90     public VocabulariesCommonList getCommonPartList() {
91         return vocabularyList;
92     }
93
94     /* (non-Javadoc)
95      * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#setCommonPartList(java.lang.Object)
96      */
97     @Override
98     public void setCommonPartList(VocabulariesCommonList vocabularyList) {
99         this.vocabularyList = vocabularyList;
100     }
101
102     /* (non-Javadoc)
103      * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#extractCommonPart(org.collectionspace.services.common.document.DocumentWrapper)
104      */
105     @Override
106     public VocabulariesCommon extractCommonPart(DocumentWrapper<DocumentModel> wrapDoc)
107             throws Exception {
108         throw new UnsupportedOperationException();
109     }
110
111     /* (non-Javadoc)
112      * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#fillCommonPart(java.lang.Object, org.collectionspace.services.common.document.DocumentWrapper)
113      */
114     @Override
115     public void fillCommonPart(VocabulariesCommon vocabularyObject, DocumentWrapper<DocumentModel> wrapDoc) throws Exception {
116         throw new UnsupportedOperationException();
117     }
118
119     /* (non-Javadoc)
120      * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#extractCommonPartList(org.collectionspace.services.common.document.DocumentWrapper)
121      */
122     @Override
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.setVocabType((String) docModel.getProperty(getServiceContext().getCommonPartLabel(),
136                     VocabularyJAXBSchema.VOCAB_TYPE));
137             String id = NuxeoUtils.extractId(docModel.getPathAsString());
138             ilistItem.setUri(getServiceContextPath() + id);
139             ilistItem.setCsid(id);
140             list.add(ilistItem);
141         }
142
143         return coList;
144     }
145
146     /**
147      * getQProperty converts the given property to qualified schema property
148      * @param prop
149      * @return
150      */
151     @Override
152     public String getQProperty(String prop) {
153         return VocabularyConstants.NUXEO_SCHEMA_NAME + ":" + prop;
154     }
155 }
156