]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
8bb95b744fbf0d2c9554d7abf13d4c65e9d5d77b
[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.taxonomy.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.jaxb.AbstractCommonList;
35 import org.collectionspace.services.taxonomy.TaxonomyauthorityCommon;
36 import org.collectionspace.services.taxonomy.TaxonomyauthorityCommonList;
37 import org.collectionspace.services.taxonomy.TaxonomyauthorityCommonList.TaxonomyauthorityListItem;
38
39 import org.collectionspace.services.nuxeo.client.java.RemoteDocumentModelHandlerImpl;
40 import org.collectionspace.services.nuxeo.util.NuxeoUtils;
41 import org.nuxeo.ecm.core.api.DocumentModel;
42 import org.nuxeo.ecm.core.api.DocumentModelList;
43 import org.slf4j.Logger;
44 import org.slf4j.LoggerFactory;
45
46 /**
47  * TaxonomyAuthorityDocumentModelHandler
48  *
49  * $LastChangedRevision$
50  * $LastChangedDate$
51  */
52 public class TaxonomyAuthorityDocumentModelHandler
53         extends AuthorityDocumentModelHandler<TaxonomyauthorityCommon, TaxonomyauthorityCommonList> {
54
55     /**
56      * Common part schema label
57      */
58     private static final String COMMON_PART_LABEL = "taxonomyauthority_common";   
59     
60     public TaxonomyAuthorityDocumentModelHandler() {
61         super(COMMON_PART_LABEL);
62     }
63     
64     public String getCommonPartLabel() {
65         return COMMON_PART_LABEL;
66     }
67         
68     @Override
69     public TaxonomyauthorityCommonList extractCommonPartList(DocumentWrapper<DocumentModelList> wrapDoc) throws Exception {
70         TaxonomyauthorityCommonList coList = extractPagingInfo(new TaxonomyauthorityCommonList(),
71                         wrapDoc);
72         AbstractCommonList commonList = (AbstractCommonList) coList;
73         commonList.setFieldsReturned("displayName|refName|shortIdentifier|vocabType|uri|csid");
74
75         //FIXME: iterating over a long list of documents is not a long term
76         //strategy...need to change to more efficient iterating in future
77         List<TaxonomyauthorityCommonList.TaxonomyauthorityListItem> list = coList.getTaxonomyauthorityListItem();
78         // FIXME: This workaround - for the discrepancy between plural service
79         // name / path ("taxonomyauthorities") and singular common part name
80         // ("taxonomyauthority ... _common") in this service might be handled
81         // in a cleaner way than below.  Absent this workaround, values of fields
82         // (other than URI and CSID) could not be obtained via the document model.
83         // Perhaps this will be moot when we switch to the model of Person, et al.,
84         // where SERVICE_PAYLOAD_NAME can be distinct from SERVICE_NAME.
85         // String label = getServiceContext().getCommonPartLabel();
86         String label = getCommonPartLabel();
87         Iterator<DocumentModel> iter = wrapDoc.getWrappedObject().iterator();
88         while(iter.hasNext()){
89             DocumentModel docModel = iter.next();
90             TaxonomyauthorityListItem ilistItem = new TaxonomyauthorityListItem();
91             ilistItem.setDisplayName((String) docModel.getProperty(label,
92                         AuthorityJAXBSchema.DISPLAY_NAME));
93             ilistItem.setRefName((String) docModel.getProperty(label,
94                         AuthorityJAXBSchema.REF_NAME));
95             ilistItem.setShortIdentifier((String) docModel.getProperty(label,
96                         AuthorityJAXBSchema.SHORT_IDENTIFIER));
97             ilistItem.setVocabType((String) docModel.getProperty(label,
98                         AuthorityJAXBSchema.VOCAB_TYPE));
99             String id = getCsid(docModel);//NuxeoUtils.extractId(docModel.getPathAsString());
100             ilistItem.setUri(getServiceContextPath() + id);
101             ilistItem.setCsid(id);
102             list.add(ilistItem);
103         }
104
105         return coList;
106     }
107
108     /**
109      * getQProperty converts the given property to qualified schema property
110      * @param prop
111      * @return
112      */
113     @Override
114     public String getQProperty(String prop) {
115         return TaxonomyAuthorityConstants.NUXEO_SCHEMA_NAME + ":" + prop;
116     }
117 }
118