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;
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;
40 * IntakeDocumentModelHandler
42 * $LastChangedRevision: $
45 public class IntakeDocumentModelHandler
46 extends DocumentModelHandler<Intake, IntakeList> {
48 private final Logger logger = LoggerFactory.getLogger(IntakeDocumentModelHandler.class);
50 * intake is used to stash JAXB object to use when handle is called
51 * for Action.CREATE, Action.UPDATE or Action.GET
53 private Intake intake;
55 * intakeList is stashed when handle is called
58 private IntakeList intakeList;
61 public void prepare(Action action) throws Exception {
62 //no specific action needed
66 * getCommonObject get associated intake
70 public Intake getCommonObject() {
75 * setCommonObject set associated intake
79 public void setCommonObject(Intake intake) {
84 * getIntakeList get associated intake (for index/GET_ALL)
88 public IntakeList getCommonObjectList() {
93 public void setCommonObjectList(IntakeList intakeList) {
94 this.intakeList = intakeList;
98 public Intake extractCommonObject(DocumentWrapper wrapDoc)
100 DocumentModel docModel = (DocumentModel) wrapDoc.getWrappedObject();
101 Intake intakeObject = new Intake();
103 //FIXME property get should be dynamically set using schema inspection
104 //so it does not require hard coding
106 // intake core values
107 intakeObject.setCurrentOwner((String)docModel.getPropertyValue(
108 getQProperty(IntakeJAXBSchema.CURRENT_OWNER)));
110 intakeObject.setDepositor((String)docModel.getPropertyValue(getQProperty(
111 IntakeJAXBSchema.DEPOSITOR)));
113 intakeObject.setDepositorsRequirements((String)docModel.getPropertyValue(getQProperty(
114 IntakeJAXBSchema.DEPOSITORS_REQUIREMENTS)));
116 intakeObject.setEntryDate((String)docModel.getPropertyValue(getQProperty(
117 IntakeJAXBSchema.ENTRY_DATE)));
119 intakeObject.setEntryMethod((String)docModel.getPropertyValue(getQProperty(
120 IntakeJAXBSchema.ENTRY_METHOD)));
122 intakeObject.setEntryNote((String)docModel.getPropertyValue(getQProperty(
123 IntakeJAXBSchema.ENTRY_NOTE)));
125 intakeObject.setEntryNumber((String)docModel.getPropertyValue(getQProperty(
126 IntakeJAXBSchema.ENTRY_NUMBER)));
128 intakeObject.setEntryReason((String)docModel.getPropertyValue(getQProperty(
129 IntakeJAXBSchema.ENTRY_REASON)));
131 intakeObject.setPackingNote((String)docModel.getPropertyValue(getQProperty(
132 IntakeJAXBSchema.PACKING_NOTE)));
134 intakeObject.setReturnDate((String)docModel.getPropertyValue(getQProperty(
135 IntakeJAXBSchema.RETURN_DATE)));
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
146 // a default title for the Dublin Core schema
147 docModel.setPropertyValue("dublincore:title", IntakeConstants.INTAKE_NUXEO_DC_TITLE);
149 // intake core values
150 if(intakeObject.getCurrentOwner() != null){
151 docModel.setPropertyValue(getQProperty(
152 IntakeJAXBSchema.CURRENT_OWNER), intakeObject.getCurrentOwner());
155 if(intakeObject.getDepositor() != null){
156 docModel.setPropertyValue(getQProperty(
157 IntakeJAXBSchema.DEPOSITOR), intakeObject.getDepositor());
160 if(intakeObject.getDepositorsRequirements() != null){
161 docModel.setPropertyValue(getQProperty(
162 IntakeJAXBSchema.DEPOSITORS_REQUIREMENTS), intakeObject.getDepositorsRequirements());
165 if(intakeObject.getEntryDate() != null){
166 docModel.setPropertyValue(getQProperty(
167 IntakeJAXBSchema.ENTRY_DATE), intakeObject.getEntryDate());
170 if(intakeObject.getEntryMethod() != null){
171 docModel.setPropertyValue(getQProperty(
172 IntakeJAXBSchema.ENTRY_METHOD), intakeObject.getEntryMethod());
175 if(intakeObject.getEntryNote() != null){
176 docModel.setPropertyValue(getQProperty(
177 IntakeJAXBSchema.ENTRY_NOTE), intakeObject.getEntryNote());
180 if(intakeObject.getEntryNumber() != null){
181 docModel.setPropertyValue(getQProperty(
182 IntakeJAXBSchema.ENTRY_NUMBER), intakeObject.getEntryNumber());
185 if(intakeObject.getEntryReason() != null){
186 docModel.setPropertyValue(getQProperty(
187 IntakeJAXBSchema.ENTRY_REASON), intakeObject.getEntryReason());
190 if(intakeObject.getPackingNote() != null){
191 docModel.setPropertyValue(getQProperty(
192 IntakeJAXBSchema.PACKING_NOTE), intakeObject.getPackingNote());
195 if(intakeObject.getReturnDate() != null){
196 docModel.setPropertyValue(getQProperty(
197 IntakeJAXBSchema.RETURN_DATE), intakeObject.getReturnDate());
203 public IntakeList extractCommonObjectList(DocumentWrapper wrapDoc) throws Exception {
204 DocumentModelList docList = (DocumentModelList) wrapDoc.getWrappedObject();
206 IntakeList coList = new IntakeList();
207 List<IntakeList.IntakeListItem> list = coList.getIntakeListItem();
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);
228 public void fillCommonObjectList(IntakeList obj, DocumentWrapper wrapDoc) throws Exception {
229 throw new UnsupportedOperationException();
233 * getQProperty converts the given property to qualified schema property
237 private String getQProperty(String prop) {
238 return IntakeConstants.INTAKE_NUXEO_SCHEMA_NAME + ":" + prop;