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.HashMap;
27 import java.util.Iterator;
28 import java.util.List;
30 //import org.collectionspace.services.jaxb.AbstractCommonList;
32 import org.collectionspace.services.CollectionObjectJAXBSchema;
33 import org.collectionspace.services.CollectionObjectListItemJAXBSchema;
34 import org.collectionspace.services.collectionobject.CollectionobjectsCommon;
35 import org.collectionspace.services.collectionobject.CollectionobjectsCommonList;
36 import org.collectionspace.services.collectionobject.CollectionobjectsCommonList.CollectionObjectListItem;
37 import org.collectionspace.services.common.document.DocumentUtils;
38 import org.collectionspace.services.common.document.DocumentWrapper;
39 import org.collectionspace.services.jaxb.AbstractCommonList;
40 import org.collectionspace.services.nuxeo.client.java.RemoteDocumentModelHandlerImpl;
41 import org.collectionspace.services.nuxeo.util.NuxeoUtils;
42 import org.nuxeo.ecm.core.api.DocumentModel;
43 import org.nuxeo.ecm.core.api.DocumentModelList;
44 import org.nuxeo.ecm.core.api.model.Property;
45 import org.nuxeo.ecm.core.schema.types.ComplexType;
46 import org.slf4j.Logger;
47 import org.slf4j.LoggerFactory;
50 * CollectionObjectDocumentModelHandler
52 * $LastChangedRevision: $
55 public class CollectionObjectDocumentModelHandler
56 extends RemoteDocumentModelHandlerImpl<CollectionobjectsCommon, CollectionobjectsCommonList> {
59 private final Logger logger = LoggerFactory.getLogger(CollectionObjectDocumentModelHandler.class);
61 * collectionObject is used to stash JAXB object to use when handle is called
62 * for Action.CREATE, Action.UPDATE or Action.GET
64 private CollectionobjectsCommon collectionObject;
66 * collectionObjectList is stashed when handle is called
69 private CollectionobjectsCommonList collectionObjectList;
72 * getCommonPart get associated CollectionobjectsCommon
76 public CollectionobjectsCommon getCommonPart() {
77 return collectionObject;
81 * setCommonPart set associated collectionobject
82 * @param collectionObject
85 public void setCommonPart(CollectionobjectsCommon collectionObject) {
86 this.collectionObject = collectionObject;
90 * getCollectionobjectsCommonList get associated CollectionobjectsCommon (for index/GET_ALL)
94 public CollectionobjectsCommonList getCommonPartList() {
95 return collectionObjectList;
99 * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#setCommonPartList(java.lang.Object)
102 public void setCommonPartList(CollectionobjectsCommonList collectionObjectList) {
103 this.collectionObjectList = collectionObjectList;
107 * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#extractCommonPart(org.collectionspace.services.common.document.DocumentWrapper)
110 public CollectionobjectsCommon extractCommonPart(DocumentWrapper<DocumentModel> wrapDoc)
112 throw new UnsupportedOperationException();
116 * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#fillCommonPart(java.lang.Object, org.collectionspace.services.common.document.DocumentWrapper)
119 public void fillCommonPart(CollectionobjectsCommon co, DocumentWrapper<DocumentModel> wrapDoc) throws Exception {
120 throw new UnsupportedOperationException();
124 * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#extractCommonPartList(org.collectionspace.services.common.document.DocumentWrapper)
127 public CollectionobjectsCommonList extractCommonPartList(DocumentWrapper<DocumentModelList> wrapDoc) throws Exception {
128 CollectionobjectsCommonList coList = this.extractPagingInfo(new CollectionobjectsCommonList(),
130 AbstractCommonList commonList = (AbstractCommonList) coList;
131 commonList.setFieldsReturned("objectNumber|objectName|title|responsibleDepartment|uri|csid");
132 List<CollectionobjectsCommonList.CollectionObjectListItem> list = coList.getCollectionObjectListItem();
133 Iterator<DocumentModel> iter = wrapDoc.getWrappedObject().iterator();
134 String label = getServiceContext().getCommonPartLabel();
135 while(iter.hasNext()){
136 DocumentModel docModel = iter.next();
137 CollectionObjectListItem coListItem = new CollectionObjectListItem();
139 String objNumber = getSimpleStringProperty(docModel, label,
140 CollectionObjectListItemJAXBSchema.OBJECT_NUMBER);
141 coListItem.setObjectNumber(objNumber);
143 String primaryObjectName = getStringValueInPrimaryRepeatingComplexProperty(
144 docModel, label, CollectionObjectListItemJAXBSchema.OBJECT_NAME_LIST,
145 CollectionObjectListItemJAXBSchema.OBJECT_NAME);
146 coListItem.setObjectName(primaryObjectName);
148 String primaryTitle = getStringValueInPrimaryRepeatingComplexProperty(
149 docModel, label, CollectionObjectListItemJAXBSchema.TITLE_GROUP_LIST,
150 CollectionObjectListItemJAXBSchema.TITLE);
151 coListItem.setTitle(primaryTitle);
153 String primaryRespDept = this.getFirstRepeatingStringProperty(
154 docModel, label, CollectionObjectListItemJAXBSchema.RESPONSIBLE_DEPARTMENTS);
155 coListItem.setResponsibleDepartment(primaryRespDept);
157 String id = getCsid(docModel);
158 coListItem.setUri(getServiceContextPath() + id);
159 coListItem.setCsid(id);
160 } catch (ClassCastException cce) {
161 throw new RuntimeException("Unexpected schema structure encountered", cce);
162 } catch (Exception e) {
163 throw new RuntimeException("Problem encountered retrieving values", e);
165 list.add(coListItem);
172 * @see org.collectionspace.services.nuxeo.client.java.RemoteDocumentModelHandlerImpl#fillAllParts(org.collectionspace.services.common.document.DocumentWrapper)
175 public void fillAllParts(DocumentWrapper<DocumentModel> wrapDoc, Action action) throws Exception {
177 super.fillAllParts(wrapDoc, action);
178 fillDublinCoreObject(wrapDoc); //dublincore might not be needed in future
182 * Fill dublin core object.
184 * @param wrapDoc the wrap doc
185 * @throws Exception the exception
187 private void fillDublinCoreObject(DocumentWrapper<DocumentModel> wrapDoc) throws Exception {
188 DocumentModel docModel = wrapDoc.getWrappedObject();
189 //FIXME property setter should be dynamically set using schema inspection
190 //so it does not require hard coding
191 // a default title for the Dublin Core schema
192 docModel.setPropertyValue("dublincore:title", CollectionObjectConstants.NUXEO_DC_TITLE);
196 * @see org.collectionspace.services.common.document.AbstractMultipartDocumentHandlerImpl#getQProperty(java.lang.String)
199 public String getQProperty(String prop) {
200 return CollectionObjectConstants.NUXEO_SCHEMA_NAME + ":" + prop;