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.RemoteDocumentModelHandler;
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 RemoteDocumentModelHandler<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;
68 public void prepare(Action action) throws Exception {
69 //no specific action needed
73 * getCommonObject get associated Relation
77 public RelationsCommon getCommonPart() {
82 * setCommonObject set associated relation
86 public void setCommonPart(RelationsCommon relation) {
87 this.relation = relation;
91 * getRelationList get associated Relation (for index/GET_ALL)
95 public RelationsCommonList getCommonPartList() {
100 public void setCommonPartList(RelationsCommonList relationList) {
101 this.relationList = relationList;
105 public RelationsCommon extractCommonPart(DocumentWrapper wrapDoc)
107 throw new UnsupportedOperationException();
111 public void fillCommonPart(RelationsCommon relation, DocumentWrapper wrapDoc) throws Exception {
112 throw new UnsupportedOperationException();
116 public RelationsCommonList extractCommonPartList(DocumentWrapper wrapDoc) throws Exception {
117 DocumentModelList docList = (DocumentModelList) wrapDoc.getWrappedObject();
119 Map propsFromResource = this.getProperties();
120 String subjectCsid = (String) propsFromResource.get(IRelationsManager.SUBJECT);
121 String predicate = (String) propsFromResource.get(IRelationsManager.PREDICATE);
122 String objectCsid = (String) propsFromResource.get(IRelationsManager.OBJECT);
124 RelationsCommonList relList = new RelationsCommonList();
125 List<RelationsCommonList.RelationListItem> itemList = relList.getRelationListItem();
127 //FIXME: iterating over a long itemList of documents is not a long term
128 //strategy...need to change to more efficient iterating in future
129 Iterator<DocumentModel> iter = docList.iterator();
130 while(iter.hasNext()){
131 DocumentModel docModel = iter.next();
132 if(RelationsUtils.isQueryMatch(docModel, subjectCsid,
133 predicate, objectCsid) == true){
134 RelationListItem relListItem = RelationsUtils.getRelationListItem(
135 docModel, getServiceContextPath());
136 itemList.add(relListItem);
145 public void fillAllParts(DocumentWrapper wrapDoc) throws Exception {
146 super.fillAllParts(wrapDoc);
147 fillDublinCoreObject(wrapDoc); //dublincore might not be needed in future
150 private void fillDublinCoreObject(DocumentWrapper wrapDoc) throws Exception {
151 DocumentModel docModel = (DocumentModel) wrapDoc.getWrappedObject();
152 //FIXME property setter should be dynamically set using schema inspection
153 //so it does not require hard coding
154 // a default title for the Dublin Core schema
155 docModel.setPropertyValue("dublincore:title", RelationConstants.NUXEO_DC_TITLE);
159 public String getDocumentType() {
160 return RelationConstants.NUXEO_DOCTYPE;
164 public String getQProperty(String prop) {
165 return "/" + RelationConstants.NUXEO_SCHEMA_ROOT_ELEMENT + "/" + prop;