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