]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
1867894e0e5ffec39eaf16259b200f4eacb89b65
[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.organization.nuxeo;
25
26 import java.util.Iterator;
27 import java.util.List;
28
29 import org.collectionspace.services.common.vocabulary.AuthorityJAXBSchema;
30 import org.collectionspace.services.common.document.DocumentWrapper;
31 import org.collectionspace.services.organization.OrgauthoritiesCommon;
32 import org.collectionspace.services.organization.OrgauthoritiesCommonList;
33 import org.collectionspace.services.organization.OrgauthoritiesCommonList.OrgauthorityListItem;
34
35 import org.collectionspace.services.common.vocabulary.nuxeo.AuthorityDocumentModelHandler;
36 import org.collectionspace.services.jaxb.AbstractCommonList;
37 import org.collectionspace.services.nuxeo.util.NuxeoUtils;
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  * OrgAuthorityDocumentModelHandler
45  *
46  * $LastChangedRevision$
47  * $LastChangedDate$
48  */
49 public class OrgAuthorityDocumentModelHandler
50         extends AuthorityDocumentModelHandler<OrgauthoritiesCommon, OrgauthoritiesCommonList> {
51
52     /**
53      * Common part schema label
54      */
55     private static final String COMMON_PART_LABEL = "orgauthorities_common";   
56     
57     public OrgAuthorityDocumentModelHandler() {
58         super(COMMON_PART_LABEL);
59     }
60         
61     /* (non-Javadoc)
62      * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#extractCommonPartList(org.collectionspace.services.common.document.DocumentWrapper)
63      */
64     @Override
65     public OrgauthoritiesCommonList extractCommonPartList(DocumentWrapper<DocumentModelList> wrapDoc) throws Exception {
66         OrgauthoritiesCommonList coList = this.extractPagingInfo(new OrgauthoritiesCommonList(), wrapDoc);
67         AbstractCommonList commonList = (AbstractCommonList) coList;
68         commonList.setFieldsReturned("displayName|refName|shortIdentifier|vocabType|uri|csid");
69         List<OrgauthoritiesCommonList.OrgauthorityListItem> list = coList.getOrgauthorityListItem();
70         Iterator<DocumentModel> iter = wrapDoc.getWrappedObject().iterator();
71         String label = getServiceContext().getCommonPartLabel();
72         while(iter.hasNext()){
73             DocumentModel docModel = iter.next();
74             OrgauthorityListItem ilistItem = new OrgauthorityListItem();
75             ilistItem.setDisplayName((String) docModel.getProperty(label,
76                     AuthorityJAXBSchema.DISPLAY_NAME));
77             ilistItem.setRefName((String) docModel.getProperty(label,
78                     AuthorityJAXBSchema.REF_NAME));
79             ilistItem.setShortIdentifier((String) docModel.getProperty(label,
80                     AuthorityJAXBSchema.SHORT_IDENTIFIER));
81             ilistItem.setVocabType((String) docModel.getProperty(label,
82                     AuthorityJAXBSchema.VOCAB_TYPE));
83             String id = NuxeoUtils.extractId(docModel.getPathAsString());
84             ilistItem.setUri(getServiceContextPath() + id);
85             ilistItem.setCsid(id);
86             list.add(ilistItem);
87         }
88
89         return coList;
90     }
91
92     /**
93      * getQProperty converts the given property to qualified schema property
94      * @param prop
95      * @return
96      */
97     @Override
98     public String getQProperty(String prop) {
99         return OrgAuthorityConstants.NUXEO_SCHEMA_NAME + ":" + prop;
100     }
101 }
102