]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
9917dff163118b0dbb0331aef85184a281a15ca6
[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.location.nuxeo;
25
26 import java.util.Iterator;
27 import java.util.List;
28
29 import org.collectionspace.services.common.document.DocumentHandler.Action;
30 import org.collectionspace.services.common.document.DocumentFilter;
31 import org.collectionspace.services.common.document.DocumentWrapper;
32 import org.collectionspace.services.common.vocabulary.AuthorityJAXBSchema;
33 import org.collectionspace.services.common.vocabulary.nuxeo.AuthorityDocumentModelHandler;
34 import org.collectionspace.services.location.LocationauthoritiesCommon;
35 import org.collectionspace.services.location.LocationauthoritiesCommonList;
36 import org.collectionspace.services.location.LocationauthoritiesCommonList.LocationauthorityListItem;
37
38 import org.collectionspace.services.nuxeo.client.java.RemoteDocumentModelHandlerImpl;
39 import org.collectionspace.services.nuxeo.util.NuxeoUtils;
40 import org.nuxeo.ecm.core.api.DocumentModel;
41 import org.nuxeo.ecm.core.api.DocumentModelList;
42 import org.slf4j.Logger;
43 import org.slf4j.LoggerFactory;
44
45 /**
46  * LocationAuthorityDocumentModelHandler
47  *
48  * $LastChangedRevision: $
49  * $LastChangedDate: $
50  */
51 public class LocationAuthorityDocumentModelHandler
52         extends AuthorityDocumentModelHandler<LocationauthoritiesCommon, LocationauthoritiesCommonList> {
53
54     @Override
55     public LocationauthoritiesCommonList extractCommonPartList(DocumentWrapper<DocumentModelList> wrapDoc) throws Exception {
56         LocationauthoritiesCommonList coList = extractPagingInfo(new LocationauthoritiesCommonList(),
57                         wrapDoc);
58
59         //FIXME: iterating over a long list of documents is not a long term
60         //strategy...need to change to more efficient iterating in future
61         List<LocationauthoritiesCommonList.LocationauthorityListItem> list = coList.getLocationauthorityListItem();
62         String label = getServiceContext().getCommonPartLabel();
63         Iterator<DocumentModel> iter = wrapDoc.getWrappedObject().iterator();
64         while(iter.hasNext()){
65             DocumentModel docModel = iter.next();
66             LocationauthorityListItem ilistItem = new LocationauthorityListItem();
67             ilistItem.setDisplayName((String) docModel.getProperty(label,
68                         AuthorityJAXBSchema.DISPLAY_NAME));
69             ilistItem.setRefName((String) docModel.getProperty(label,
70                         AuthorityJAXBSchema.REF_NAME));
71             ilistItem.setShortIdentifier((String) docModel.getProperty(label,
72                         AuthorityJAXBSchema.SHORT_IDENTIFIER));
73             ilistItem.setVocabType((String) docModel.getProperty(label,
74                         AuthorityJAXBSchema.VOCAB_TYPE));
75             String id = NuxeoUtils.extractId(docModel.getPathAsString());
76             ilistItem.setUri(getServiceContextPath() + id);
77             ilistItem.setCsid(id);
78             list.add(ilistItem);
79         }
80
81         return coList;
82     }
83
84     /**
85      * getQProperty converts the given property to qualified schema property
86      * @param prop
87      * @return
88      */
89     @Override
90     public String getQProperty(String prop) {
91         return LocationAuthorityConstants.NUXEO_SCHEMA_NAME + ":" + prop;
92     }
93 }
94