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.acquisition.nuxeo;
26 import java.util.Iterator;
27 import java.util.List;
29 import org.collectionspace.services.AcquisitionJAXBSchema;
30 import org.collectionspace.services.common.repository.DocumentWrapper;
31 import org.collectionspace.services.acquisition.Acquisition;
32 import org.collectionspace.services.acquisition.AcquisitionList;
33 import org.collectionspace.services.acquisition.AcquisitionList.AcquisitionListItem;
34 import org.collectionspace.services.nuxeo.client.java.DocumentModelHandler;
35 import org.collectionspace.services.acquisition.nuxeo.AcquisitionConstants;
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 * AcquisitionDocumentModelHandler
45 * $LastChangedRevision: $
48 public class AcquisitionDocumentModelHandler
49 extends DocumentModelHandler<Acquisition, AcquisitionList> {
51 private final Logger logger = LoggerFactory.getLogger(AcquisitionDocumentModelHandler.class);
53 * acquisition is used to stash JAXB object to use when handle is called
54 * for Action.CREATE, Action.UPDATE or Action.GET
56 private Acquisition acquisition;
58 * acquisitionList is stashed when handle is called
61 private AcquisitionList acquisitionList;
64 public void prepare(Action action) throws Exception {
65 //no specific action needed
69 * getCommonObject get associated acquisition
73 public Acquisition getCommonObject() {
78 * setCommonObject set associated acquisition
82 public void setCommonObject(Acquisition acquisition) {
83 this.acquisition = acquisition;
87 * getAcquisitionList get associated acquisition (for index/GET_ALL)
91 public AcquisitionList getCommonObjectList() {
92 return acquisitionList;
96 public void setCommonObjectList(AcquisitionList acquisitionList) {
97 this.acquisitionList = acquisitionList;
101 public Acquisition extractCommonObject(DocumentWrapper wrapDoc)
103 DocumentModel docModel = (DocumentModel) wrapDoc.getWrappedObject();
104 Acquisition acquisitionObject = new Acquisition();
106 //FIXME property get should be dynamically set using schema inspection
107 //so it does not require hard coding
109 // acquisition core values
110 acquisitionObject.setAccessiondate((String)docModel.getPropertyValue(
111 getQProperty(AcquisitionJAXBSchema.ACCESSIONDATE)));
113 return acquisitionObject;
117 public void fillCommonObject(Acquisition acquisitionObject, DocumentWrapper wrapDoc) throws Exception {
118 DocumentModel docModel = (DocumentModel) wrapDoc.getWrappedObject();
119 //FIXME property setter should be dynamically set using schema inspection
120 //so it does not require hard coding
122 // a default title for the Dublin Core schema
123 docModel.setPropertyValue("dublincore:title", AcquisitionConstants.NUXEO_DC_TITLE);
125 // acquisition core values
126 if(acquisitionObject.getAccessiondate() != null){
127 docModel.setPropertyValue(getQProperty(
128 AcquisitionJAXBSchema.ACCESSIONDATE), acquisitionObject.getAccessiondate());
133 public AcquisitionList extractCommonObjectList(DocumentWrapper wrapDoc) throws Exception {
134 DocumentModelList docList = (DocumentModelList) wrapDoc.getWrappedObject();
136 AcquisitionList coList = new AcquisitionList();
137 List<AcquisitionList.AcquisitionListItem> list = coList.getAcquisitionListItem();
139 //FIXME: iterating over a long list of documents is not a long term
140 //strategy...need to change to more efficient iterating in future
141 Iterator<DocumentModel> iter = docList.iterator();
142 while(iter.hasNext()){
143 DocumentModel docModel = iter.next();
144 AcquisitionListItem listItem = new AcquisitionListItem();
145 listItem.setAccessiondate((String)docModel.getPropertyValue(
146 getQProperty(AcquisitionJAXBSchema.ACCESSIONDATE)));
147 //need fully qualified context for URI
148 String id = docModel.getId();
149 listItem.setUri("/acquisitions/" + id);
150 listItem.setCsid(id);
158 public void fillCommonObjectList(AcquisitionList obj, DocumentWrapper wrapDoc) throws Exception {
159 throw new UnsupportedOperationException();
163 * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#getDocumentType()
165 public String getDocumentType() {
166 return AcquisitionConstants.NUXEO_DOCTYPE;
170 * getQProperty converts the given property to qualified schema property
174 private String getQProperty(String prop) {
175 return AcquisitionConstants.NUXEO_SCHEMA_NAME + ":" + prop;