]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
eb8828dbe188239b7218b0259ae53067ff98f1ae
[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.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;
41
42 /**
43  * VocabularyItemDocumentModelHandler
44  *
45  * $LastChangedRevision: $
46  * $LastChangedDate: $
47  */
48 public class VocabularyItemDocumentModelHandler
49                 extends AuthorityItemDocumentModelHandler<VocabularyitemsCommon, VocabularyitemsCommonList> {
50
51     private final Logger logger = LoggerFactory.getLogger(VocabularyItemDocumentModelHandler.class);
52     
53     private static final String COMMON_PART_LABEL = "vocabularyitems_common";   
54     
55     public VocabularyItemDocumentModelHandler() {
56         super(COMMON_PART_LABEL);
57     }
58         
59     
60     @Override
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");
66                 
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);
82                         list.add(ilistItem);
83                 }
84
85                 return coList;
86     }
87
88     /**
89      * getQProperty converts the given property to qualified schema property
90      * @param prop
91      * @return
92      */
93     @Override
94     public String getQProperty(String prop) {
95         return VocabularyItemConstants.NUXEO_SCHEMA_NAME + ":" + prop;
96     }
97 }
98