]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
be7e699281d749e00c4cb661b53fed80f1efe246
[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.person.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.jaxb.AbstractCommonList;
32 import org.collectionspace.services.person.PersonauthoritiesCommon;
33 import org.collectionspace.services.person.PersonauthoritiesCommonList;
34 import org.collectionspace.services.person.PersonauthoritiesCommonList.PersonauthorityListItem;
35 import org.collectionspace.services.common.vocabulary.nuxeo.AuthorityDocumentModelHandler;
36
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  * PersonAuthorityDocumentModelHandler
45  *
46  * $LastChangedRevision: $
47  * $LastChangedDate: $
48  */
49 public class PersonAuthorityDocumentModelHandler
50                 extends AuthorityDocumentModelHandler<PersonauthoritiesCommon, PersonauthoritiesCommonList> {
51
52     /**
53      * Common part schema label
54      */
55     private static final String COMMON_PART_LABEL = "personauthorities_common";   
56     
57     public PersonAuthorityDocumentModelHandler() {
58         super(COMMON_PART_LABEL);
59     }
60         
61     @Override
62     public PersonauthoritiesCommonList extractCommonPartList(DocumentWrapper<DocumentModelList> wrapDoc) throws Exception {
63         PersonauthoritiesCommonList coList = extractPagingInfo(new PersonauthoritiesCommonList(),
64                         wrapDoc);
65         AbstractCommonList commonList = (AbstractCommonList) coList;
66         commonList.setFieldsReturned("displayName|refName|shortIdentifier|vocabType|uri|csid");
67
68         //FIXME: iterating over a long list of documents is not a long term
69         //strategy...need to change to more efficient iterating in future
70         List<PersonauthoritiesCommonList.PersonauthorityListItem> list = coList.getPersonauthorityListItem();
71         Iterator<DocumentModel> iter = wrapDoc.getWrappedObject().iterator();
72         String label = getServiceContext().getCommonPartLabel();
73         while(iter.hasNext()){
74             DocumentModel docModel = iter.next();
75             PersonauthorityListItem ilistItem = new PersonauthorityListItem();
76             ilistItem.setDisplayName((String) docModel.getProperty(label,
77                         AuthorityJAXBSchema.DISPLAY_NAME));
78             ilistItem.setRefName((String) docModel.getProperty(label,
79                         AuthorityJAXBSchema.REF_NAME));
80             ilistItem.setShortIdentifier((String) docModel.getProperty(label,
81                         AuthorityJAXBSchema.SHORT_IDENTIFIER));
82             ilistItem.setVocabType((String) docModel.getProperty(label,
83                         AuthorityJAXBSchema.VOCAB_TYPE));
84             String id = getCsid(docModel);//NuxeoUtils.extractId(docModel.getPathAsString());
85             ilistItem.setUri(getServiceContextPath() + id);
86             ilistItem.setCsid(id);
87             list.add(ilistItem);
88         }
89
90         return coList;
91     }
92
93     /**
94      * getQProperty converts the given property to qualified schema property
95      * @param prop
96      * @return
97      */
98     @Override
99     public String getQProperty(String prop) {
100         return PersonAuthorityConstants.NUXEO_SCHEMA_NAME + ":" + prop;
101     }
102 }
103