]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
4e593f19d042016e7e456e3d85ce273fba63fbc2
[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.collectionobject.nuxeo;
25
26 import java.util.Iterator;
27 import java.util.List;
28
29 import org.collectionspace.services.collectionobject.nuxeo.CollectionObjectConstants;
30 import org.collectionspace.services.CollectionObjectJAXBSchema;
31 import org.collectionspace.services.collectionobject.CollectionObject;
32 import org.collectionspace.services.collectionobject.CollectionObjectList;
33 import org.collectionspace.services.collectionobject.CollectionObjectList.CollectionObjectListItem;
34 import org.collectionspace.services.common.repository.DocumentWrapper;
35 import org.collectionspace.services.nuxeo.client.java.DocumentModelHandler;
36 import org.nuxeo.ecm.core.api.DocumentModel;
37 import org.nuxeo.ecm.core.api.DocumentModelList;
38 import org.slf4j.Logger;
39 import org.slf4j.LoggerFactory;
40
41 /**
42  * CollectionObjectDocumentModelHandler
43  *
44  * $LastChangedRevision: $
45  * $LastChangedDate: $
46  */
47 public class CollectionObjectDocumentModelHandler
48         extends DocumentModelHandler<CollectionObject, CollectionObjectList> {
49
50     private final Logger logger = LoggerFactory.getLogger(CollectionObjectDocumentModelHandler.class);
51     /**
52      * collectionObject is used to stash JAXB object to use when handle is called
53      * for Action.CREATE, Action.UPDATE or Action.GET
54      */
55     private CollectionObject collectionObject;
56     /**
57      * collectionObjectList is stashed when handle is called
58      * for ACTION.GET_ALL
59      */
60     private CollectionObjectList collectionObjectList;
61
62     @Override
63     public void prepare(Action action) throws Exception {
64         //no specific action needed
65     }
66
67
68     /**
69      * getCommonObject get associated CollectionObject
70      * @return
71      */
72     @Override
73     public CollectionObject getCommonObject() {
74         return collectionObject;
75     }
76
77     /**
78      * setCommonObject set associated collectionobject
79      * @param collectionObject
80      */
81     @Override
82     public void setCommonObject(CollectionObject collectionObject) {
83         this.collectionObject = collectionObject;
84     }
85
86     /**
87      * getCollectionObjectList get associated CollectionObject (for index/GET_ALL)
88      * @return
89      */
90     @Override
91     public CollectionObjectList getCommonObjectList() {
92         return collectionObjectList;
93     }
94
95     @Override
96     public void setCommonObjectList(CollectionObjectList collectionObjectList) {
97         this.collectionObjectList = collectionObjectList;
98     }
99
100     @Override
101     public CollectionObject extractCommonObject(DocumentWrapper wrapDoc)
102             throws Exception {
103         DocumentModel docModel = (DocumentModel) wrapDoc.getWrappedObject();
104         CollectionObject co = new CollectionObject();
105
106         //FIXME property get should be dynamically set using schema inspection
107         //so it does not require hard coding
108
109         // CollectionObject core values
110         co.setObjectNumber((String) docModel.getPropertyValue(
111                 getQProperty(CollectionObjectJAXBSchema.OBJECT_NUMBER)));
112         co.setOtherNumber((String) docModel.getPropertyValue(
113                 getQProperty(CollectionObjectJAXBSchema.OTHER_NUMBER)));
114         co.setBriefDescription((String) docModel.getPropertyValue(
115                 getQProperty(CollectionObjectJAXBSchema.BRIEF_DESCRIPTION)));
116         co.setComments((String) docModel.getPropertyValue(
117                 getQProperty(CollectionObjectJAXBSchema.COMMENTS)));
118         co.setDistFeatures((String) docModel.getPropertyValue(
119                 getQProperty(CollectionObjectJAXBSchema.DIST_FEATURES)));
120         co.setObjectName((String) docModel.getPropertyValue(
121                 getQProperty(CollectionObjectJAXBSchema.OBJECT_NAME)));
122         co.setResponsibleDept((String) docModel.getPropertyValue(
123                 getQProperty(CollectionObjectJAXBSchema.RESPONSIBLE_DEPT)));
124         co.setTitle((String) docModel.getPropertyValue(
125                 getQProperty(CollectionObjectJAXBSchema.TITLE)));
126
127         return co;
128     }
129
130     @Override
131     public void fillCommonObject(CollectionObject co, DocumentWrapper wrapDoc) throws Exception {
132         DocumentModel docModel = (DocumentModel) wrapDoc.getWrappedObject();
133         //FIXME property setter should be dynamically set using schema inspection
134         //so it does not require hard coding
135
136         // a default title for the Dublin Core schema
137         docModel.setPropertyValue("dublincore:title", CollectionObjectConstants.NUXEO_DC_TITLE);
138
139         // CollectionObject core values
140         if(co.getObjectNumber() != null){
141             docModel.setPropertyValue(
142                     getQProperty(CollectionObjectJAXBSchema.OBJECT_NUMBER),
143                     co.getObjectNumber());
144         }
145         if(co.getOtherNumber() != null){
146             docModel.setPropertyValue(
147                     getQProperty(CollectionObjectJAXBSchema.OTHER_NUMBER),
148                     co.getOtherNumber());
149         }
150         if(co.getBriefDescription() != null){
151             docModel.setPropertyValue(
152                     getQProperty(CollectionObjectJAXBSchema.BRIEF_DESCRIPTION),
153                     co.getBriefDescription());
154         }
155         if(co.getComments() != null){
156             docModel.setPropertyValue(
157                     getQProperty(CollectionObjectJAXBSchema.COMMENTS),
158                     co.getComments());
159         }
160         if(co.getDistFeatures() != null){
161             docModel.setPropertyValue(
162                     getQProperty(CollectionObjectJAXBSchema.DIST_FEATURES),
163                     co.getDistFeatures());
164         }
165         if(co.getObjectName() != null){
166             docModel.setPropertyValue(
167                     getQProperty(CollectionObjectJAXBSchema.OBJECT_NAME),
168                     co.getObjectName());
169         }
170         if(co.getResponsibleDept() != null){
171             docModel.setPropertyValue(
172                     getQProperty(CollectionObjectJAXBSchema.RESPONSIBLE_DEPT),
173                     co.getResponsibleDept());
174         }
175         if(co.getTitle() != null){
176             docModel.setPropertyValue(
177                     getQProperty(CollectionObjectJAXBSchema.TITLE),
178                     co.getTitle());
179         }
180     }
181
182     @Override
183     public CollectionObjectList extractCommonObjectList(DocumentWrapper wrapDoc) throws Exception {
184         DocumentModelList docList = (DocumentModelList) wrapDoc.getWrappedObject();
185
186         CollectionObjectList coList = new CollectionObjectList();
187         List<CollectionObjectList.CollectionObjectListItem> list = coList.getCollectionObjectListItem();
188
189         //FIXME: iterating over a long list of documents is not a long term
190         //strategy...need to change to more efficient iterating in future
191         Iterator<DocumentModel> iter = docList.iterator();
192         while(iter.hasNext()){
193             DocumentModel docModel = iter.next();
194             CollectionObjectListItem coListItem = new CollectionObjectListItem();
195             coListItem.setObjectNumber((String) docModel.getPropertyValue(
196                     getQProperty(CollectionObjectJAXBSchema.OBJECT_NUMBER)));
197             //need fully qualified context for URI
198             coListItem.setUri("/collectionobjects/" + docModel.getId());
199             coListItem.setCsid(docModel.getId());
200             list.add(coListItem);
201         }
202
203         return coList;
204     }
205
206     @Override
207     public void fillCommonObjectList(CollectionObjectList obj, DocumentWrapper wrapDoc) throws Exception {
208         throw new UnsupportedOperationException();
209     }
210     
211     public String getDocumentType() {
212         return CollectionObjectConstants.NUXEO_DOCTYPE;
213     }
214
215     /**
216      * getQProperty converts the given property to qualified schema property
217      * @param prop
218      * @return
219      */
220     private String getQProperty(String prop) {
221         return CollectionObjectConstants.NUXEO_SCHEMA_NAME + ":" + prop;
222     }
223 }
224