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