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.relation.nuxeo;
26 import java.util.Iterator;
27 import java.util.List;
31 import org.collectionspace.services.common.relation.IRelationsManager;
32 import org.collectionspace.services.common.relation.nuxeo.RelationConstants;
33 import org.collectionspace.services.common.relation.nuxeo.RelationsUtils;
34 import org.collectionspace.services.common.document.DocumentHandler.Action;
35 import org.collectionspace.services.relation.RelationsCommon;
36 import org.collectionspace.services.relation.RelationsCommonList;
37 import org.collectionspace.services.relation.RelationsCommonList.RelationListItem;
39 import org.collectionspace.services.common.document.DocumentWrapper;
40 import org.collectionspace.services.nuxeo.client.java.RemoteDocumentModelHandlerImpl;
41 import org.nuxeo.ecm.core.api.DocumentModel;
42 import org.nuxeo.ecm.core.api.DocumentModelList;
43 import org.slf4j.Logger;
44 import org.slf4j.LoggerFactory;
47 * RelationDocumentModelHandler
49 * $LastChangedRevision: $
52 public class RelationDocumentModelHandler
53 extends RemoteDocumentModelHandlerImpl<RelationsCommon, RelationsCommonList> {
56 private final Logger logger = LoggerFactory.getLogger(RelationDocumentModelHandler.class);
58 * relation is used to stash JAXB object to use when handle is called
59 * for Action.CREATE, Action.UPDATE or Action.GET
61 private RelationsCommon relation;
63 * relationList is stashed when handle is called
66 private RelationsCommonList relationList;
70 * getCommonObject get associated Relation
74 public RelationsCommon getCommonPart() {
79 * setCommonObject set associated relation
83 public void setCommonPart(RelationsCommon relation) {
84 this.relation = relation;
88 * getRelationList get associated Relation (for index/GET_ALL)
92 public RelationsCommonList getCommonPartList() {
97 * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#setCommonPartList(java.lang.Object)
100 public void setCommonPartList(RelationsCommonList relationList) {
101 this.relationList = relationList;
105 * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#extractCommonPart(org.collectionspace.services.common.document.DocumentWrapper)
108 public RelationsCommon 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(RelationsCommon relation, 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 RelationsCommonList extractCommonPartList(DocumentWrapper<DocumentModelList> wrapDoc) throws Exception {
126 Map propsFromResource = this.getProperties();
127 String subjectCsid = (String) propsFromResource.get(IRelationsManager.SUBJECT);
128 String predicate = (String) propsFromResource.get(IRelationsManager.PREDICATE);
129 String objectCsid = (String) propsFromResource.get(IRelationsManager.OBJECT);
131 //FIXME - Need to change this into a NXQL on subject, predicate, object terms. Currently,
132 //FIXME - we're performing a post query filter which is far from ideal and not scalable.
133 RelationsCommonList relList = this.extractPagingInfo(new RelationsCommonList(), wrapDoc) ;
134 List<RelationsCommonList.RelationListItem> itemList = relList.getRelationListItem();
135 Iterator<DocumentModel> iter = wrapDoc.getWrappedObject().iterator();
136 while(iter.hasNext()){
137 DocumentModel docModel = iter.next();
138 if (RelationsUtils.isQueryMatch(docModel, subjectCsid,
139 predicate, objectCsid) == true){
140 RelationListItem relListItem = RelationsUtils.getRelationListItem(getServiceContext(),
141 docModel, getServiceContextPath());
142 itemList.add(relListItem);
151 * @see org.collectionspace.services.nuxeo.client.java.RemoteDocumentModelHandlerImpl#fillAllParts(org.collectionspace.services.common.document.DocumentWrapper)
154 public void fillAllParts(DocumentWrapper<DocumentModel> wrapDoc) throws Exception {
155 super.fillAllParts(wrapDoc);
156 fillDublinCoreObject(wrapDoc); //dublincore might not be needed in future
160 * Fill dublin core object.
162 * @param wrapDoc the wrap doc
163 * @throws Exception the exception
165 private void fillDublinCoreObject(DocumentWrapper<DocumentModel> wrapDoc) throws Exception {
166 DocumentModel docModel = wrapDoc.getWrappedObject();
167 //FIXME property setter should be dynamically set using schema inspection
168 //so it does not require hard coding
169 // a default title for the Dublin Core schema
170 docModel.setPropertyValue("dublincore:title", RelationConstants.NUXEO_DC_TITLE);
175 * @see org.collectionspace.services.common.document.AbstractMultipartDocumentHandlerImpl#getQProperty(java.lang.String)
178 public String getQProperty(String prop) {
179 return "/" + RelationConstants.NUXEO_SCHEMA_ROOT_ELEMENT + "/" + prop;