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> {
55 private final Logger logger = LoggerFactory.getLogger(RelationDocumentModelHandler.class);
57 * relation is used to stash JAXB object to use when handle is called
58 * for Action.CREATE, Action.UPDATE or Action.GET
60 private RelationsCommon relation;
62 * relationList is stashed when handle is called
65 private RelationsCommonList relationList;
69 * getCommonObject get associated Relation
73 public RelationsCommon getCommonPart() {
78 * setCommonObject set associated relation
82 public void setCommonPart(RelationsCommon relation) {
83 this.relation = relation;
87 * getRelationList get associated Relation (for index/GET_ALL)
91 public RelationsCommonList getCommonPartList() {
96 public void setCommonPartList(RelationsCommonList relationList) {
97 this.relationList = relationList;
101 public RelationsCommon extractCommonPart(DocumentWrapper<DocumentModel> wrapDoc)
103 throw new UnsupportedOperationException();
107 public void fillCommonPart(RelationsCommon relation, DocumentWrapper<DocumentModel> wrapDoc) throws Exception {
108 throw new UnsupportedOperationException();
112 public RelationsCommonList extractCommonPartList(DocumentWrapper<DocumentModelList> wrapDoc) throws Exception {
113 DocumentModelList docList = wrapDoc.getWrappedObject();
115 Map propsFromResource = this.getProperties();
116 String subjectCsid = (String) propsFromResource.get(IRelationsManager.SUBJECT);
117 String predicate = (String) propsFromResource.get(IRelationsManager.PREDICATE);
118 String objectCsid = (String) propsFromResource.get(IRelationsManager.OBJECT);
120 RelationsCommonList relList = new RelationsCommonList();
121 List<RelationsCommonList.RelationListItem> itemList = relList.getRelationListItem();
123 //FIXME: iterating over a long itemList of documents is not a long term
124 //strategy...need to change to more efficient iterating in future
125 Iterator<DocumentModel> iter = docList.iterator();
126 while(iter.hasNext()){
127 DocumentModel docModel = iter.next();
128 if(RelationsUtils.isQueryMatch(docModel, subjectCsid,
129 predicate, objectCsid) == true){
130 RelationListItem relListItem = RelationsUtils.getRelationListItem(getServiceContext(),
131 docModel, getServiceContextPath());
132 itemList.add(relListItem);
141 public void fillAllParts(DocumentWrapper<DocumentModel> wrapDoc) throws Exception {
142 super.fillAllParts(wrapDoc);
143 fillDublinCoreObject(wrapDoc); //dublincore might not be needed in future
146 private void fillDublinCoreObject(DocumentWrapper<DocumentModel> wrapDoc) throws Exception {
147 DocumentModel docModel = wrapDoc.getWrappedObject();
148 //FIXME property setter should be dynamically set using schema inspection
149 //so it does not require hard coding
150 // a default title for the Dublin Core schema
151 docModel.setPropertyValue("dublincore:title", RelationConstants.NUXEO_DC_TITLE);
156 public String getQProperty(String prop) {
157 return "/" + RelationConstants.NUXEO_SCHEMA_ROOT_ELEMENT + "/" + prop;