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));
139 List names = (List) docModel.getProperty(label,
140 CollectionObjectListItemJAXBSchema.OBJECT_NAME_LIST);
141 if(names!=null && !names.isEmpty()) {
142 HashMap<String,Object> firstNameInfo = (HashMap<String,Object>)names.get(0);
143 coListItem.setObjectName((String)firstNameInfo.get(
144 CollectionObjectListItemJAXBSchema.OBJECT_NAME) );
146 coListItem.setTitle((String) docModel.getProperty(label,
147 CollectionObjectListItemJAXBSchema.TITLE));
148 Object respDepts = docModel.getProperty(label,
149 CollectionObjectListItemJAXBSchema.RESPONSIBLE_DEPARTMENTS);
150 coListItem.setResponsibleDepartment(DocumentUtils.getFirstString(respDepts));
152 String id = NuxeoUtils.extractId(docModel.getPathAsString());
153 coListItem.setUri(getServiceContextPath() + id);
154 coListItem.setCsid(id);
155 } catch (ClassCastException cce) {
156 throw new RuntimeException("Unexpected schema structure encountered", cce);
157 } catch (Exception e) {
158 throw new RuntimeException("Problem encountered retrieving values", e);
160 list.add(coListItem);
167 * @see org.collectionspace.services.nuxeo.client.java.RemoteDocumentModelHandlerImpl#fillAllParts(org.collectionspace.services.common.document.DocumentWrapper)
170 public void fillAllParts(DocumentWrapper<DocumentModel> wrapDoc, Action action) throws Exception {
172 super.fillAllParts(wrapDoc, action);
173 fillDublinCoreObject(wrapDoc); //dublincore might not be needed in future
177 * Fill dublin core object.
179 * @param wrapDoc the wrap doc
180 * @throws Exception the exception
182 private void fillDublinCoreObject(DocumentWrapper<DocumentModel> wrapDoc) throws Exception {
183 DocumentModel docModel = wrapDoc.getWrappedObject();
184 //FIXME property setter should be dynamically set using schema inspection
185 //so it does not require hard coding
186 // a default title for the Dublin Core schema
187 docModel.setPropertyValue("dublincore:title", CollectionObjectConstants.NUXEO_DC_TITLE);
191 * @see org.collectionspace.services.common.document.AbstractMultipartDocumentHandlerImpl#getQProperty(java.lang.String)
194 public String getQProperty(String prop) {
195 return CollectionObjectConstants.NUXEO_SCHEMA_NAME + ":" + prop;