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:
6 * http://www.collectionspace.org
7 * http://wiki.collectionspace.org
9 * Copyright 2009 University of California at Berkeley
11 * Licensed under the Educational Community License (ECL), Version 2.0.
12 * You may not use this file except in compliance with this License.
14 * You may obtain a copy of the ECL 2.0 License at
16 * https://source.collectionspace.org/collection-space/LICENSE.txt
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.
24 package org.collectionspace.services.intake.nuxeo;
26 import java.util.Iterator;
27 import java.util.List;
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;
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;
43 * IntakeDocumentModelHandler
45 * $LastChangedRevision: $
48 public class IntakeDocumentModelHandler
49 extends DocumentModelHandler<Intake, IntakeList> {
51 private final Logger logger = LoggerFactory.getLogger(IntakeDocumentModelHandler.class);
53 * intake is used to stash JAXB object to use when handle is called
54 * for Action.CREATE, Action.UPDATE or Action.GET
56 private Intake intake;
58 * intakeList is stashed when handle is called
61 private IntakeList intakeList;
64 public void prepare(Action action) throws Exception {
65 //no specific action needed
69 * getCommonObject get associated intake
73 public Intake getCommonObject() {
78 * setCommonObject set associated intake
82 public void setCommonObject(Intake intake) {
87 * getIntakeList get associated intake (for index/GET_ALL)
91 public IntakeList getCommonObjectList() {
96 public void setCommonObjectList(IntakeList intakeList) {
97 this.intakeList = intakeList;
101 public Intake extractCommonObject(DocumentWrapper wrapDoc)
103 DocumentModel docModel = (DocumentModel) wrapDoc.getWrappedObject();
104 Intake intakeObject = new Intake();
106 //FIXME property get should be dynamically set using schema inspection
107 //so it does not require hard coding
109 // intake core values
110 intakeObject.setCurrentOwner((String)docModel.getPropertyValue(
111 getQProperty(IntakeJAXBSchema.CURRENT_OWNER)));
113 intakeObject.setDepositor((String)docModel.getPropertyValue(getQProperty(
114 IntakeJAXBSchema.DEPOSITOR)));
116 intakeObject.setDepositorsRequirements((String)docModel.getPropertyValue(getQProperty(
117 IntakeJAXBSchema.DEPOSITORS_REQUIREMENTS)));
119 intakeObject.setEntryDate((String)docModel.getPropertyValue(getQProperty(
120 IntakeJAXBSchema.ENTRY_DATE)));
122 intakeObject.setEntryMethod((String)docModel.getPropertyValue(getQProperty(
123 IntakeJAXBSchema.ENTRY_METHOD)));
125 intakeObject.setEntryNote((String)docModel.getPropertyValue(getQProperty(
126 IntakeJAXBSchema.ENTRY_NOTE)));
128 intakeObject.setEntryNumber((String)docModel.getPropertyValue(getQProperty(
129 IntakeJAXBSchema.ENTRY_NUMBER)));
131 intakeObject.setEntryReason((String)docModel.getPropertyValue(getQProperty(
132 IntakeJAXBSchema.ENTRY_REASON)));
134 intakeObject.setPackingNote((String)docModel.getPropertyValue(getQProperty(
135 IntakeJAXBSchema.PACKING_NOTE)));
137 intakeObject.setReturnDate((String)docModel.getPropertyValue(getQProperty(
138 IntakeJAXBSchema.RETURN_DATE)));
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
149 // a default title for the Dublin Core schema
150 docModel.setPropertyValue("dublincore:title", IntakeConstants.NUXEO_DC_TITLE);
152 // intake core values
153 if(intakeObject.getCurrentOwner() != null){
154 docModel.setPropertyValue(getQProperty(
155 IntakeJAXBSchema.CURRENT_OWNER), intakeObject.getCurrentOwner());
158 if(intakeObject.getDepositor() != null){
159 docModel.setPropertyValue(getQProperty(
160 IntakeJAXBSchema.DEPOSITOR), intakeObject.getDepositor());
163 if(intakeObject.getDepositorsRequirements() != null){
164 docModel.setPropertyValue(getQProperty(
165 IntakeJAXBSchema.DEPOSITORS_REQUIREMENTS), intakeObject.getDepositorsRequirements());
168 if(intakeObject.getEntryDate() != null){
169 docModel.setPropertyValue(getQProperty(
170 IntakeJAXBSchema.ENTRY_DATE), intakeObject.getEntryDate());
173 if(intakeObject.getEntryMethod() != null){
174 docModel.setPropertyValue(getQProperty(
175 IntakeJAXBSchema.ENTRY_METHOD), intakeObject.getEntryMethod());
178 if(intakeObject.getEntryNote() != null){
179 docModel.setPropertyValue(getQProperty(
180 IntakeJAXBSchema.ENTRY_NOTE), intakeObject.getEntryNote());
183 if(intakeObject.getEntryNumber() != null){
184 docModel.setPropertyValue(getQProperty(
185 IntakeJAXBSchema.ENTRY_NUMBER), intakeObject.getEntryNumber());
188 if(intakeObject.getEntryReason() != null){
189 docModel.setPropertyValue(getQProperty(
190 IntakeJAXBSchema.ENTRY_REASON), intakeObject.getEntryReason());
193 if(intakeObject.getPackingNote() != null){
194 docModel.setPropertyValue(getQProperty(
195 IntakeJAXBSchema.PACKING_NOTE), intakeObject.getPackingNote());
198 if(intakeObject.getReturnDate() != null){
199 docModel.setPropertyValue(getQProperty(
200 IntakeJAXBSchema.RETURN_DATE), intakeObject.getReturnDate());
206 public IntakeList extractCommonObjectList(DocumentWrapper wrapDoc) throws Exception {
207 DocumentModelList docList = (DocumentModelList) wrapDoc.getWrappedObject();
209 IntakeList coList = new IntakeList();
210 List<IntakeList.IntakeListItem> list = coList.getIntakeListItem();
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);
231 public void fillCommonObjectList(IntakeList obj, DocumentWrapper wrapDoc) throws Exception {
232 throw new UnsupportedOperationException();
236 * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#getDocumentType()
238 public String getDocumentType() {
239 return IntakeConstants.NUXEO_DOCTYPE;
243 * getQProperty converts the given property to qualified schema property
247 private String getQProperty(String prop) {
248 return IntakeConstants.NUXEO_SCHEMA_NAME + ":" + prop;