]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
0d751ac674569e1f2142e5275a0400ecfe7935d0
[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.client.VocabularyClient;
30 import org.collectionspace.services.common.vocabulary.AuthorityItemJAXBSchema;
31 import org.collectionspace.services.common.document.DocumentWrapper;
32 import org.collectionspace.services.common.vocabulary.nuxeo.AuthorityItemDocumentModelHandler;
33 import org.collectionspace.services.nuxeo.util.NuxeoUtils;
34 import org.collectionspace.services.jaxb.AbstractCommonList;
35 import org.collectionspace.services.vocabulary.VocabularyitemsCommon;
36 import org.collectionspace.services.vocabulary.VocabularyitemsCommonList;
37 import org.collectionspace.services.vocabulary.VocabularyitemsCommonList.VocabularyitemListItem;
38 import org.nuxeo.ecm.core.api.DocumentModel;
39 import org.nuxeo.ecm.core.api.DocumentModelList;
40 import org.slf4j.Logger;
41 import org.slf4j.LoggerFactory;
42
43 /**
44  * VocabularyItemDocumentModelHandler
45  *
46  * $LastChangedRevision: $
47  * $LastChangedDate: $
48  */
49 public class VocabularyItemDocumentModelHandler
50                 extends AuthorityItemDocumentModelHandler<VocabularyitemsCommon, VocabularyitemsCommonList> {
51
52     private final Logger logger = LoggerFactory.getLogger(VocabularyItemDocumentModelHandler.class);
53     
54     private static final String COMMON_PART_LABEL = "vocabularyitems_common";   
55     
56     public VocabularyItemDocumentModelHandler() {
57         super(COMMON_PART_LABEL);
58     }
59
60     @Override
61     public String getAuthorityServicePath(){
62         return VocabularyClient.SERVICE_PATH_COMPONENT;    // CSPACE-3932
63     }
64         
65     
66     @Override
67         public VocabularyitemsCommonList extractCommonPartList(
68                         DocumentWrapper<DocumentModelList> wrapDoc) throws Exception {
69                 VocabularyitemsCommonList coList = extractPagingInfo(new VocabularyitemsCommonList(), wrapDoc);
70         AbstractCommonList commonList = (AbstractCommonList) coList;
71         commonList.setFieldsReturned("displayName|refName|shortIdentifier|uri|csid");
72                 
73                 List<VocabularyitemsCommonList.VocabularyitemListItem> list = coList.getVocabularyitemListItem();
74                 Iterator<DocumentModel> iter = wrapDoc.getWrappedObject().iterator();
75                 String commonPartLabel = getServiceContext().getCommonPartLabel("vocabularyItems");
76                 while (iter.hasNext()) {
77                         DocumentModel docModel = iter.next();
78                         VocabularyitemListItem ilistItem = new VocabularyitemListItem();
79                         ilistItem.setDisplayName((String) docModel.getProperty(commonPartLabel, 
80                                         AuthorityItemJAXBSchema.DISPLAY_NAME));
81                         ilistItem.setShortIdentifier((String) docModel.getProperty(commonPartLabel,
82                                         AuthorityItemJAXBSchema.SHORT_IDENTIFIER));
83                         ilistItem.setRefName((String) docModel.getProperty(commonPartLabel, 
84                                         AuthorityItemJAXBSchema.REF_NAME));
85                         String id = getCsid(docModel);//NuxeoUtils.extractId(docModel.getPathAsString());
86                         ilistItem.setUri("/vocabularies/" + inAuthority + "/items/" + id);
87                         ilistItem.setCsid(id);
88                         list.add(ilistItem);
89                 }
90
91                 return coList;
92     }
93
94     /**
95      * getQProperty converts the given property to qualified schema property
96      * @param prop
97      * @return
98      */
99     @Override
100     public String getQProperty(String prop) {
101         return VocabularyItemConstants.NUXEO_SCHEMA_NAME + ":" + prop;
102     }
103 }
104