]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
4e6dbabd00de4c182784225deb856139a37e175c
[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.OrgAuthorityJAXBSchema;
30 import org.collectionspace.services.common.document.DocumentHandler.Action;
31 import org.collectionspace.services.common.document.DocumentFilter;
32 import org.collectionspace.services.common.document.DocumentWrapper;
33 import org.collectionspace.services.organization.OrgauthoritiesCommon;
34 import org.collectionspace.services.organization.OrgauthoritiesCommonList;
35 import org.collectionspace.services.organization.OrgauthoritiesCommonList.OrgauthorityListItem;
36
37 import org.collectionspace.services.nuxeo.client.java.RemoteDocumentModelHandlerImpl;
38 import org.collectionspace.services.nuxeo.util.NuxeoUtils;
39 import org.nuxeo.ecm.core.api.DocumentModel;
40 import org.nuxeo.ecm.core.api.DocumentModelList;
41 import org.slf4j.Logger;
42 import org.slf4j.LoggerFactory;
43
44 /**
45  * OrgAuthorityDocumentModelHandler
46  *
47  * $LastChangedRevision: $
48  * $LastChangedDate: $
49  */
50 public class OrgAuthorityDocumentModelHandler
51         extends RemoteDocumentModelHandlerImpl<OrgauthoritiesCommon, OrgauthoritiesCommonList> {
52
53     /** The logger. */
54     private final Logger logger = LoggerFactory.getLogger(OrgAuthorityDocumentModelHandler.class);
55     /**
56      * orgAuthority is used to stash JAXB object to use when handle is called
57      * for Action.CREATE, Action.UPDATE or Action.GET
58      */
59     private OrgauthoritiesCommon orgAuthority;
60     /**
61      * orgAuthorityList is stashed when handle is called
62      * for ACTION.GET_ALL
63      */
64     private OrgauthoritiesCommonList orgAuthorityList;
65
66
67     /**
68      * getCommonPart get associated orgAuthority
69      * @return
70      */
71     @Override
72     public OrgauthoritiesCommon getCommonPart() {
73         return orgAuthority;
74     }
75
76     /**
77      * setCommonPart set associated orgAuthority
78      * @param orgAuthority
79      */
80     @Override
81     public void setCommonPart(OrgauthoritiesCommon orgAuthority) {
82         this.orgAuthority = orgAuthority;
83     }
84
85     /**
86      * getCommonPartList get associated orgAuthority (for index/GET_ALL)
87      * @return
88      */
89     @Override
90     public OrgauthoritiesCommonList getCommonPartList() {
91         return orgAuthorityList;
92     }
93
94     /* (non-Javadoc)
95      * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#setCommonPartList(java.lang.Object)
96      */
97     @Override
98     public void setCommonPartList(OrgauthoritiesCommonList orgAuthorityList) {
99         this.orgAuthorityList = orgAuthorityList;
100     }
101
102     /* (non-Javadoc)
103      * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#extractCommonPart(org.collectionspace.services.common.document.DocumentWrapper)
104      */
105     @Override
106     public OrgauthoritiesCommon extractCommonPart(DocumentWrapper<DocumentModel> wrapDoc)
107             throws Exception {
108         throw new UnsupportedOperationException();
109     }
110
111     /* (non-Javadoc)
112      * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#fillCommonPart(java.lang.Object, org.collectionspace.services.common.document.DocumentWrapper)
113      */
114     @Override
115     public void fillCommonPart(OrgauthoritiesCommon orgAuthorityObject, 
116                 DocumentWrapper<DocumentModel> wrapDoc) throws Exception {
117         throw new UnsupportedOperationException();
118     }
119
120     /* (non-Javadoc)
121      * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#extractCommonPartList(org.collectionspace.services.common.document.DocumentWrapper)
122      */
123     @Override
124     public OrgauthoritiesCommonList extractCommonPartList(DocumentWrapper<DocumentModelList> wrapDoc) throws Exception {
125         OrgauthoritiesCommonList coList = this.extractPagingInfo(new OrgauthoritiesCommonList(), wrapDoc);
126         List<OrgauthoritiesCommonList.OrgauthorityListItem> list = coList.getOrgauthorityListItem();
127         Iterator<DocumentModel> iter = wrapDoc.getWrappedObject().iterator();
128         while(iter.hasNext()){
129             DocumentModel docModel = iter.next();
130             OrgauthorityListItem ilistItem = new OrgauthorityListItem();
131             ilistItem.setDisplayName((String) docModel.getProperty(getServiceContext().getCommonPartLabel(),
132                     OrgAuthorityJAXBSchema.DISPLAY_NAME));
133             ilistItem.setRefName((String) docModel.getProperty(getServiceContext().getCommonPartLabel(),
134                     OrgAuthorityJAXBSchema.REF_NAME));
135             ilistItem.setVocabType((String) docModel.getProperty(getServiceContext().getCommonPartLabel(),
136                     OrgAuthorityJAXBSchema.VOCAB_TYPE));
137             String id = NuxeoUtils.extractId(docModel.getPathAsString());
138             ilistItem.setUri(getServiceContextPath() + id);
139             ilistItem.setCsid(id);
140             list.add(ilistItem);
141         }
142
143         return coList;
144     }
145
146     /**
147      * getQProperty converts the given property to qualified schema property
148      * @param prop
149      * @return
150      */
151     @Override
152     public String getQProperty(String prop) {
153         return OrgAuthorityConstants.NUXEO_SCHEMA_NAME + ":" + prop;
154     }
155 }
156