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.collectionobject.nuxeo;
26 import java.util.Iterator;
27 import java.util.List;
28 import org.collectionspace.services.CollectionObjectJAXBSchema;
29 import org.collectionspace.services.collectionobject.CollectionObject;
30 import org.collectionspace.services.collectionobject.CollectionObjectList;
31 import org.collectionspace.services.collectionobject.CollectionObjectList.CollectionObjectListItem;
32 import org.collectionspace.services.common.repository.DocumentWrapper;
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 * CollectionObjectDocumentModelHandler
42 * $LastChangedRevision: $
45 public class CollectionObjectDocumentModelHandler
46 extends DocumentModelHandler<CollectionObject, CollectionObjectList> {
48 private final Logger logger = LoggerFactory.getLogger(CollectionObjectDocumentModelHandler.class);
50 * collectionObject is used to stash JAXB object to use when handle is called
51 * for Action.CREATE, Action.UPDATE or Action.GET
53 private CollectionObject collectionObject;
55 * collectionObjectList is stashed when handle is called
58 private CollectionObjectList collectionObjectList;
61 public void prepare(Action action) throws Exception {
62 //no specific action needed
67 * getCommonObject get associated CollectionObject
71 public CollectionObject getCommonObject() {
72 return collectionObject;
76 * setCommonObject set associated collectionobject
77 * @param collectionObject
80 public void setCommonObject(CollectionObject collectionObject) {
81 this.collectionObject = collectionObject;
85 * getCollectionObjectList get associated CollectionObject (for index/GET_ALL)
89 public CollectionObjectList getCommonObjectList() {
90 return collectionObjectList;
94 public void setCommonObjectList(CollectionObjectList collectionObjectList) {
95 this.collectionObjectList = collectionObjectList;
99 public CollectionObject extractCommonObject(DocumentWrapper wrapDoc)
101 DocumentModel docModel = (DocumentModel) wrapDoc.getWrappedObject();
102 CollectionObject co = new CollectionObject();
104 //FIXME property get should be dynamically set using schema inspection
105 //so it does not require hard coding
107 // CollectionObject core values
108 co.setObjectNumber((String) docModel.getPropertyValue(
109 getQProperty(CollectionObjectJAXBSchema.OBJECT_NUMBER)));
110 co.setOtherNumber((String) docModel.getPropertyValue(
111 getQProperty(CollectionObjectJAXBSchema.OTHER_NUMBER)));
112 co.setBriefDescription((String) docModel.getPropertyValue(
113 getQProperty(CollectionObjectJAXBSchema.BRIEF_DESCRIPTION)));
114 co.setComments((String) docModel.getPropertyValue(
115 getQProperty(CollectionObjectJAXBSchema.COMMENTS)));
116 co.setDistFeatures((String) docModel.getPropertyValue(
117 getQProperty(CollectionObjectJAXBSchema.DIST_FEATURES)));
118 co.setObjectName((String) docModel.getPropertyValue(
119 getQProperty(CollectionObjectJAXBSchema.OBJECT_NAME)));
120 co.setResponsibleDept((String) docModel.getPropertyValue(
121 getQProperty(CollectionObjectJAXBSchema.RESPONSIBLE_DEPT)));
122 co.setTitle((String) docModel.getPropertyValue(
123 getQProperty(CollectionObjectJAXBSchema.TITLE)));
129 public void fillCommonObject(CollectionObject co, DocumentWrapper wrapDoc) throws Exception {
130 DocumentModel docModel = (DocumentModel) wrapDoc.getWrappedObject();
131 //FIXME property setter should be dynamically set using schema inspection
132 //so it does not require hard coding
134 // a default title for the Dublin Core schema
135 docModel.setPropertyValue("dublincore:title", CollectionObjectConstants.CO_NUXEO_DC_TITLE);
137 // CollectionObject core values
138 if(co.getObjectNumber() != null){
139 docModel.setPropertyValue(
140 getQProperty(CollectionObjectJAXBSchema.OBJECT_NUMBER),
141 co.getObjectNumber());
143 if(co.getOtherNumber() != null){
144 docModel.setPropertyValue(
145 getQProperty(CollectionObjectJAXBSchema.OTHER_NUMBER),
146 co.getOtherNumber());
148 if(co.getBriefDescription() != null){
149 docModel.setPropertyValue(
150 getQProperty(CollectionObjectJAXBSchema.BRIEF_DESCRIPTION),
151 co.getBriefDescription());
153 if(co.getComments() != null){
154 docModel.setPropertyValue(
155 getQProperty(CollectionObjectJAXBSchema.COMMENTS),
158 if(co.getDistFeatures() != null){
159 docModel.setPropertyValue(
160 getQProperty(CollectionObjectJAXBSchema.DIST_FEATURES),
161 co.getDistFeatures());
163 if(co.getObjectName() != null){
164 docModel.setPropertyValue(
165 getQProperty(CollectionObjectJAXBSchema.OBJECT_NAME),
168 if(co.getResponsibleDept() != null){
169 docModel.setPropertyValue(
170 getQProperty(CollectionObjectJAXBSchema.RESPONSIBLE_DEPT),
171 co.getResponsibleDept());
173 if(co.getTitle() != null){
174 docModel.setPropertyValue(
175 getQProperty(CollectionObjectJAXBSchema.TITLE),
181 public CollectionObjectList extractCommonObjectList(DocumentWrapper wrapDoc) throws Exception {
182 DocumentModelList docList = (DocumentModelList) wrapDoc.getWrappedObject();
184 CollectionObjectList coList = new CollectionObjectList();
185 List<CollectionObjectList.CollectionObjectListItem> list = coList.getCollectionObjectListItem();
187 //FIXME: iterating over a long list of documents is not a long term
188 //strategy...need to change to more efficient iterating in future
189 Iterator<DocumentModel> iter = docList.iterator();
190 while(iter.hasNext()){
191 DocumentModel docModel = iter.next();
192 CollectionObjectListItem coListItem = new CollectionObjectListItem();
193 coListItem.setObjectNumber((String) docModel.getPropertyValue(
194 getQProperty(CollectionObjectJAXBSchema.OBJECT_NUMBER)));
195 //need fully qualified context for URI
196 coListItem.setUri("/collectionobjects/" + docModel.getId());
197 coListItem.setCsid(docModel.getId());
198 list.add(coListItem);
205 public void fillCommonObjectList(CollectionObjectList obj, DocumentWrapper wrapDoc) throws Exception {
206 throw new UnsupportedOperationException();
210 * getQProperty converts the given property to qualified schema property
214 private String getQProperty(String prop) {
215 return CollectionObjectConstants.CO_NUXEO_SCHEMA_NAME + ":" + prop;