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.CollectionObjectListItemJAXBSchema;
33 import org.collectionspace.services.collectionobject.CollectionobjectsCommon;
34 import org.collectionspace.services.collectionobject.CollectionobjectsCommonList;
35 import org.collectionspace.services.collectionobject.CollectionobjectsCommonList.CollectionObjectListItem;
36 import org.collectionspace.services.common.document.DocumentUtils;
37 import org.collectionspace.services.common.document.DocumentWrapper;
38 import org.collectionspace.services.jaxb.AbstractCommonList;
39 import org.collectionspace.services.nuxeo.client.java.RemoteDocumentModelHandlerImpl;
40 import org.collectionspace.services.nuxeo.util.NuxeoUtils;
41 import org.nuxeo.ecm.core.api.DocumentModel;
42 import org.nuxeo.ecm.core.api.DocumentModelList;
43 import org.nuxeo.ecm.core.schema.types.ComplexType;
44 import org.slf4j.Logger;
45 import org.slf4j.LoggerFactory;
48 * CollectionObjectDocumentModelHandler
50 * $LastChangedRevision: $
53 public class CollectionObjectDocumentModelHandler
54 extends RemoteDocumentModelHandlerImpl<CollectionobjectsCommon, CollectionobjectsCommonList> {
57 private final Logger logger = LoggerFactory.getLogger(CollectionObjectDocumentModelHandler.class);
59 * collectionObject is used to stash JAXB object to use when handle is called
60 * for Action.CREATE, Action.UPDATE or Action.GET
62 private CollectionobjectsCommon collectionObject;
64 * collectionObjectList is stashed when handle is called
67 private CollectionobjectsCommonList collectionObjectList;
70 * getCommonPart get associated CollectionobjectsCommon
74 public CollectionobjectsCommon getCommonPart() {
75 return collectionObject;
79 * setCommonPart set associated collectionobject
80 * @param collectionObject
83 public void setCommonPart(CollectionobjectsCommon collectionObject) {
84 this.collectionObject = collectionObject;
88 * getCollectionobjectsCommonList get associated CollectionobjectsCommon (for index/GET_ALL)
92 public CollectionobjectsCommonList getCommonPartList() {
93 return collectionObjectList;
97 * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#setCommonPartList(java.lang.Object)
100 public void setCommonPartList(CollectionobjectsCommonList collectionObjectList) {
101 this.collectionObjectList = collectionObjectList;
105 * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#extractCommonPart(org.collectionspace.services.common.document.DocumentWrapper)
108 public CollectionobjectsCommon extractCommonPart(DocumentWrapper<DocumentModel> wrapDoc)
110 throw new UnsupportedOperationException();
114 * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#fillCommonPart(java.lang.Object, org.collectionspace.services.common.document.DocumentWrapper)
117 public void fillCommonPart(CollectionobjectsCommon co, DocumentWrapper<DocumentModel> wrapDoc) throws Exception {
118 throw new UnsupportedOperationException();
122 * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#extractCommonPartList(org.collectionspace.services.common.document.DocumentWrapper)
125 public CollectionobjectsCommonList extractCommonPartList(DocumentWrapper<DocumentModelList> wrapDoc) throws Exception {
126 CollectionobjectsCommonList coList = this.extractPagingInfo(new CollectionobjectsCommonList(),
128 AbstractCommonList commonList = (AbstractCommonList) coList;
129 commonList.setFieldsReturned("objectNumber|objectName|title|responsibleDepartment|uri|csid");
130 List<CollectionobjectsCommonList.CollectionObjectListItem> list = coList.getCollectionObjectListItem();
131 Iterator<DocumentModel> iter = wrapDoc.getWrappedObject().iterator();
132 String label = getServiceContext().getCommonPartLabel();
133 while(iter.hasNext()){
134 DocumentModel docModel = iter.next();
135 CollectionObjectListItem coListItem = new CollectionObjectListItem();
137 coListItem.setObjectNumber((String) docModel.getProperty(label,
138 CollectionObjectListItemJAXBSchema.OBJECT_NUMBER));
140 List<Object> objectNames = (List<Object>) docModel.getProperty(label,
141 CollectionObjectListItemJAXBSchema.OBJECT_NAME_LIST);
142 String primaryObjectName = primaryValueFromMultivalue(objectNames,
143 CollectionObjectListItemJAXBSchema.OBJECT_NAME);
144 coListItem.setObjectName(primaryObjectName);
146 List<Object> titles =
147 (List<Object>) docModel.getProperty(label,
148 CollectionObjectListItemJAXBSchema.TITLE_GROUP_LIST);
149 String primaryTitle = primaryValueFromMultivalue(titles,
150 CollectionObjectListItemJAXBSchema.TITLE);
151 coListItem.setTitle(primaryTitle);
153 List<Object> respDepts =
154 (List<Object>) docModel.getProperty(label,
155 CollectionObjectListItemJAXBSchema.RESPONSIBLE_DEPARTMENTS);
156 coListItem.setResponsibleDepartment(DocumentUtils.getFirstString(respDepts));
158 String id = NuxeoUtils.extractId(docModel.getPathAsString());
159 coListItem.setUri(getServiceContextPath() + id);
160 coListItem.setCsid(id);
161 } catch (ClassCastException cce) {
162 throw new RuntimeException("Unexpected schema structure encountered", cce);
163 } catch (Exception e) {
164 throw new RuntimeException("Problem encountered retrieving values", e);
166 list.add(coListItem);
173 * @see org.collectionspace.services.nuxeo.client.java.RemoteDocumentModelHandlerImpl#fillAllParts(org.collectionspace.services.common.document.DocumentWrapper)
176 public void fillAllParts(DocumentWrapper<DocumentModel> wrapDoc, Action action) throws Exception {
178 super.fillAllParts(wrapDoc, action);
179 fillDublinCoreObject(wrapDoc); //dublincore might not be needed in future
183 * Fill dublin core object.
185 * @param wrapDoc the wrap doc
186 * @throws Exception the exception
188 private void fillDublinCoreObject(DocumentWrapper<DocumentModel> wrapDoc) throws Exception {
189 DocumentModel docModel = wrapDoc.getWrappedObject();
190 //FIXME property setter should be dynamically set using schema inspection
191 //so it does not require hard coding
192 // a default title for the Dublin Core schema
193 docModel.setPropertyValue("dublincore:title", CollectionObjectConstants.NUXEO_DC_TITLE);
197 * @see org.collectionspace.services.common.document.AbstractMultipartDocumentHandlerImpl#getQProperty(java.lang.String)
200 public String getQProperty(String prop) {
201 return CollectionObjectConstants.NUXEO_SCHEMA_NAME + ":" + prop;