]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
0d0c55355ee9105edd082f15d7201769a02cdad4
[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.intake.nuxeo;
25
26 import java.util.Iterator;
27 import java.util.List;
28
29 import org.collectionspace.services.IntakeJAXBSchema;
30 import org.collectionspace.services.common.repository.DocumentWrapper;
31 import org.collectionspace.services.intake.Intake;
32 import org.collectionspace.services.intake.IntakeList;
33 import org.collectionspace.services.intake.IntakeList.IntakeListItem;
34 import org.collectionspace.services.nuxeo.client.java.DocumentModelHandler;
35 import org.collectionspace.services.intake.nuxeo.IntakeConstants;
36
37 import org.nuxeo.ecm.core.api.DocumentModel;
38 import org.nuxeo.ecm.core.api.DocumentModelList;
39 import org.slf4j.Logger;
40 import org.slf4j.LoggerFactory;
41
42 /**
43  * IntakeDocumentModelHandler
44  *
45  * $LastChangedRevision: $
46  * $LastChangedDate: $
47  */
48 public class IntakeDocumentModelHandler
49         extends DocumentModelHandler<Intake, IntakeList> {
50
51     private final Logger logger = LoggerFactory.getLogger(IntakeDocumentModelHandler.class);
52     /**
53      * intake is used to stash JAXB object to use when handle is called
54      * for Action.CREATE, Action.UPDATE or Action.GET
55      */
56     private Intake intake;
57     /**
58      * intakeList is stashed when handle is called
59      * for ACTION.GET_ALL
60      */
61     private IntakeList intakeList;
62
63     @Override
64     public void prepare(Action action) throws Exception {
65         //no specific action needed
66     }
67
68     /**
69      * getCommonObject get associated intake
70      * @return
71      */
72     @Override
73     public Intake getCommonObject() {
74         return intake;
75     }
76
77     /**
78      * setCommonObject set associated intake
79      * @param intake
80      */
81     @Override
82     public void setCommonObject(Intake intake) {
83         this.intake = intake;
84     }
85
86     /**
87      * getIntakeList get associated intake (for index/GET_ALL)
88      * @return
89      */
90     @Override
91     public IntakeList getCommonObjectList() {
92         return intakeList;
93     }
94
95     @Override
96     public void setCommonObjectList(IntakeList intakeList) {
97         this.intakeList = intakeList;
98     }
99
100     @Override
101     public Intake extractCommonObject(DocumentWrapper wrapDoc)
102             throws Exception {
103         DocumentModel docModel = (DocumentModel) wrapDoc.getWrappedObject();
104         Intake intakeObject = new Intake();
105
106         //FIXME property get should be dynamically set using schema inspection
107         //so it does not require hard coding
108
109         // intake core values
110         intakeObject.setCurrentOwner((String)docModel.getPropertyValue(
111                 getQProperty(IntakeJAXBSchema.CURRENT_OWNER)));
112
113         intakeObject.setDepositor((String)docModel.getPropertyValue(getQProperty(
114                 IntakeJAXBSchema.DEPOSITOR)));
115
116         intakeObject.setDepositorsRequirements((String)docModel.getPropertyValue(getQProperty(
117                 IntakeJAXBSchema.DEPOSITORS_REQUIREMENTS)));
118
119         intakeObject.setEntryDate((String)docModel.getPropertyValue(getQProperty(
120                 IntakeJAXBSchema.ENTRY_DATE)));
121
122         intakeObject.setEntryMethod((String)docModel.getPropertyValue(getQProperty(
123                 IntakeJAXBSchema.ENTRY_METHOD)));
124
125         intakeObject.setEntryNote((String)docModel.getPropertyValue(getQProperty(
126                 IntakeJAXBSchema.ENTRY_NOTE)));
127
128         intakeObject.setEntryNumber((String)docModel.getPropertyValue(getQProperty(
129                 IntakeJAXBSchema.ENTRY_NUMBER)));
130
131         intakeObject.setEntryReason((String)docModel.getPropertyValue(getQProperty(
132                 IntakeJAXBSchema.ENTRY_REASON)));
133
134         intakeObject.setPackingNote((String)docModel.getPropertyValue(getQProperty(
135                 IntakeJAXBSchema.PACKING_NOTE)));
136
137         intakeObject.setReturnDate((String)docModel.getPropertyValue(getQProperty(
138                 IntakeJAXBSchema.RETURN_DATE)));
139
140         return intakeObject;
141     }
142
143     @Override
144     public void fillCommonObject(Intake intakeObject, DocumentWrapper wrapDoc) throws Exception {
145         DocumentModel docModel = (DocumentModel) wrapDoc.getWrappedObject();
146         //FIXME property setter should be dynamically set using schema inspection
147         //so it does not require hard coding
148
149         // a default title for the Dublin Core schema
150         docModel.setPropertyValue("dublincore:title", IntakeConstants.NUXEO_DC_TITLE);
151
152         // intake core values
153         if(intakeObject.getCurrentOwner() != null){
154             docModel.setPropertyValue(getQProperty(
155                     IntakeJAXBSchema.CURRENT_OWNER), intakeObject.getCurrentOwner());
156         }
157
158         if(intakeObject.getDepositor() != null){
159             docModel.setPropertyValue(getQProperty(
160                     IntakeJAXBSchema.DEPOSITOR), intakeObject.getDepositor());
161         }
162
163         if(intakeObject.getDepositorsRequirements() != null){
164             docModel.setPropertyValue(getQProperty(
165                     IntakeJAXBSchema.DEPOSITORS_REQUIREMENTS), intakeObject.getDepositorsRequirements());
166         }
167
168         if(intakeObject.getEntryDate() != null){
169             docModel.setPropertyValue(getQProperty(
170                     IntakeJAXBSchema.ENTRY_DATE), intakeObject.getEntryDate());
171         }
172
173         if(intakeObject.getEntryMethod() != null){
174             docModel.setPropertyValue(getQProperty(
175                     IntakeJAXBSchema.ENTRY_METHOD), intakeObject.getEntryMethod());
176         }
177
178         if(intakeObject.getEntryNote() != null){
179             docModel.setPropertyValue(getQProperty(
180                     IntakeJAXBSchema.ENTRY_NOTE), intakeObject.getEntryNote());
181         }
182
183         if(intakeObject.getEntryNumber() != null){
184             docModel.setPropertyValue(getQProperty(
185                     IntakeJAXBSchema.ENTRY_NUMBER), intakeObject.getEntryNumber());
186         }
187
188         if(intakeObject.getEntryReason() != null){
189             docModel.setPropertyValue(getQProperty(
190                     IntakeJAXBSchema.ENTRY_REASON), intakeObject.getEntryReason());
191         }
192
193         if(intakeObject.getPackingNote() != null){
194             docModel.setPropertyValue(getQProperty(
195                     IntakeJAXBSchema.PACKING_NOTE), intakeObject.getPackingNote());
196         }
197
198         if(intakeObject.getReturnDate() != null){
199             docModel.setPropertyValue(getQProperty(
200                     IntakeJAXBSchema.RETURN_DATE), intakeObject.getReturnDate());
201         }
202
203     }
204
205     @Override
206     public IntakeList extractCommonObjectList(DocumentWrapper wrapDoc) throws Exception {
207         DocumentModelList docList = (DocumentModelList) wrapDoc.getWrappedObject();
208
209         IntakeList coList = new IntakeList();
210         List<IntakeList.IntakeListItem> list = coList.getIntakeListItem();
211
212         //FIXME: iterating over a long list of documents is not a long term
213         //strategy...need to change to more efficient iterating in future
214         Iterator<DocumentModel> iter = docList.iterator();
215         while(iter.hasNext()){
216             DocumentModel docModel = iter.next();
217             IntakeListItem ilistItem = new IntakeListItem();
218             ilistItem.setEntryNumber((String)docModel.getPropertyValue(
219                     getQProperty(IntakeJAXBSchema.ENTRY_NUMBER)));
220             //need fully qualified context for URI
221             String id = docModel.getId();
222             ilistItem.setUri("/intakes/" + id);
223             ilistItem.setCsid(id);
224             list.add(ilistItem);
225         }
226
227         return coList;
228     }
229
230     @Override
231     public void fillCommonObjectList(IntakeList obj, DocumentWrapper wrapDoc) throws Exception {
232         throw new UnsupportedOperationException();
233     }
234
235     /* (non-Javadoc)
236      * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#getDocumentType()
237      */
238     public String getDocumentType() {
239         return IntakeConstants.NUXEO_DOCTYPE;
240     }
241     
242     /**
243      * getQProperty converts the given property to qualified schema property
244      * @param prop
245      * @return
246      */
247     private String getQProperty(String prop) {
248         return IntakeConstants.NUXEO_SCHEMA_NAME + ":" + prop;
249     }
250 }
251