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;
29 import org.collectionspace.services.collectionobject.nuxeo.CollectionObjectConstants;
30 import org.collectionspace.services.CollectionObjectJAXBSchema;
31 import org.collectionspace.services.collectionobject.CollectionObject;
32 import org.collectionspace.services.collectionobject.CollectionObjectList;
33 import org.collectionspace.services.collectionobject.CollectionObjectList.CollectionObjectListItem;
34 import org.collectionspace.services.common.repository.DocumentWrapper;
35 import org.collectionspace.services.nuxeo.client.java.DocumentModelHandler;
36 import org.nuxeo.ecm.core.api.DocumentModel;
37 import org.nuxeo.ecm.core.api.DocumentModelList;
38 import org.slf4j.Logger;
39 import org.slf4j.LoggerFactory;
42 * CollectionObjectDocumentModelHandler
44 * $LastChangedRevision: $
47 public class CollectionObjectDocumentModelHandler
48 extends DocumentModelHandler<CollectionObject, CollectionObjectList> {
50 private final Logger logger = LoggerFactory.getLogger(CollectionObjectDocumentModelHandler.class);
52 * collectionObject is used to stash JAXB object to use when handle is called
53 * for Action.CREATE, Action.UPDATE or Action.GET
55 private CollectionObject collectionObject;
57 * collectionObjectList is stashed when handle is called
60 private CollectionObjectList collectionObjectList;
63 public void prepare(Action action) throws Exception {
64 //no specific action needed
69 * getCommonObject get associated CollectionObject
73 public CollectionObject getCommonObject() {
74 return collectionObject;
78 * setCommonObject set associated collectionobject
79 * @param collectionObject
82 public void setCommonObject(CollectionObject collectionObject) {
83 this.collectionObject = collectionObject;
87 * getCollectionObjectList get associated CollectionObject (for index/GET_ALL)
91 public CollectionObjectList getCommonObjectList() {
92 return collectionObjectList;
96 public void setCommonObjectList(CollectionObjectList collectionObjectList) {
97 this.collectionObjectList = collectionObjectList;
101 public CollectionObject extractCommonObject(DocumentWrapper wrapDoc)
103 DocumentModel docModel = (DocumentModel) wrapDoc.getWrappedObject();
104 CollectionObject co = new CollectionObject();
106 //FIXME property get should be dynamically set using schema inspection
107 //so it does not require hard coding
109 // CollectionObject core values
110 co.setObjectNumber((String) docModel.getPropertyValue(
111 getQProperty(CollectionObjectJAXBSchema.OBJECT_NUMBER)));
112 co.setOtherNumber((String) docModel.getPropertyValue(
113 getQProperty(CollectionObjectJAXBSchema.OTHER_NUMBER)));
114 co.setBriefDescription((String) docModel.getPropertyValue(
115 getQProperty(CollectionObjectJAXBSchema.BRIEF_DESCRIPTION)));
116 co.setComments((String) docModel.getPropertyValue(
117 getQProperty(CollectionObjectJAXBSchema.COMMENTS)));
118 co.setDistFeatures((String) docModel.getPropertyValue(
119 getQProperty(CollectionObjectJAXBSchema.DIST_FEATURES)));
120 co.setObjectName((String) docModel.getPropertyValue(
121 getQProperty(CollectionObjectJAXBSchema.OBJECT_NAME)));
122 co.setResponsibleDept((String) docModel.getPropertyValue(
123 getQProperty(CollectionObjectJAXBSchema.RESPONSIBLE_DEPT)));
124 co.setTitle((String) docModel.getPropertyValue(
125 getQProperty(CollectionObjectJAXBSchema.TITLE)));
131 public void fillCommonObject(CollectionObject co, DocumentWrapper wrapDoc) throws Exception {
132 DocumentModel docModel = (DocumentModel) wrapDoc.getWrappedObject();
133 //FIXME property setter should be dynamically set using schema inspection
134 //so it does not require hard coding
136 // a default title for the Dublin Core schema
137 docModel.setPropertyValue("dublincore:title", CollectionObjectConstants.NUXEO_DC_TITLE);
139 // CollectionObject core values
140 if(co.getObjectNumber() != null){
141 docModel.setPropertyValue(
142 getQProperty(CollectionObjectJAXBSchema.OBJECT_NUMBER),
143 co.getObjectNumber());
145 if(co.getOtherNumber() != null){
146 docModel.setPropertyValue(
147 getQProperty(CollectionObjectJAXBSchema.OTHER_NUMBER),
148 co.getOtherNumber());
150 if(co.getBriefDescription() != null){
151 docModel.setPropertyValue(
152 getQProperty(CollectionObjectJAXBSchema.BRIEF_DESCRIPTION),
153 co.getBriefDescription());
155 if(co.getComments() != null){
156 docModel.setPropertyValue(
157 getQProperty(CollectionObjectJAXBSchema.COMMENTS),
160 if(co.getDistFeatures() != null){
161 docModel.setPropertyValue(
162 getQProperty(CollectionObjectJAXBSchema.DIST_FEATURES),
163 co.getDistFeatures());
165 if(co.getObjectName() != null){
166 docModel.setPropertyValue(
167 getQProperty(CollectionObjectJAXBSchema.OBJECT_NAME),
170 if(co.getResponsibleDept() != null){
171 docModel.setPropertyValue(
172 getQProperty(CollectionObjectJAXBSchema.RESPONSIBLE_DEPT),
173 co.getResponsibleDept());
175 if(co.getTitle() != null){
176 docModel.setPropertyValue(
177 getQProperty(CollectionObjectJAXBSchema.TITLE),
183 public CollectionObjectList extractCommonObjectList(DocumentWrapper wrapDoc) throws Exception {
184 DocumentModelList docList = (DocumentModelList) wrapDoc.getWrappedObject();
186 CollectionObjectList coList = new CollectionObjectList();
187 List<CollectionObjectList.CollectionObjectListItem> list = coList.getCollectionObjectListItem();
189 //FIXME: iterating over a long list of documents is not a long term
190 //strategy...need to change to more efficient iterating in future
191 Iterator<DocumentModel> iter = docList.iterator();
192 while(iter.hasNext()){
193 DocumentModel docModel = iter.next();
194 CollectionObjectListItem coListItem = new CollectionObjectListItem();
195 coListItem.setObjectNumber((String) docModel.getPropertyValue(
196 getQProperty(CollectionObjectJAXBSchema.OBJECT_NUMBER)));
197 //need fully qualified context for URI
198 coListItem.setUri("/collectionobjects/" + docModel.getId());
199 coListItem.setCsid(docModel.getId());
200 list.add(coListItem);
207 public void fillCommonObjectList(CollectionObjectList obj, DocumentWrapper wrapDoc) throws Exception {
208 throw new UnsupportedOperationException();
211 public String getDocumentType() {
212 return CollectionObjectConstants.NUXEO_DOCTYPE;
216 * getQProperty converts the given property to qualified schema property
220 private String getQProperty(String prop) {
221 return CollectionObjectConstants.NUXEO_SCHEMA_NAME + ":" + prop;