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;
30 import org.collectionspace.services.common.relation.RelationJAXBSchema;
31 import org.collectionspace.services.common.relation.nuxeo.RelationsManagerNuxeoImpl;
32 import org.collectionspace.services.common.relation.RelationsManager;
34 import org.collectionspace.services.relation.Relation;
35 import org.collectionspace.services.relation.RelationList;
36 import org.collectionspace.services.relation.RelationList.RelationListItem;
38 import org.collectionspace.services.relation.nuxeo.RelationNuxeoConstants;
39 import org.collectionspace.services.common.repository.DocumentWrapper;
40 import org.collectionspace.services.nuxeo.client.java.DocumentModelHandler;
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 DocumentModelHandler<Relation, RelationList> {
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 Relation relation;
62 * relationList is stashed when handle is called
65 private RelationList relationList;
68 public void prepare(Action action) throws Exception {
69 //no specific action needed
74 * getCommonObject get associated Relation
78 public Relation getCommonObject() {
83 * setCommonObject set associated relation
87 public void setCommonObject(Relation relation) {
88 this.relation = relation;
92 * getRelationList get associated Relation (for index/GET_ALL)
96 public RelationList getCommonObjectList() {
101 public void setCommonObjectList(RelationList relationList) {
102 this.relationList = relationList;
106 public Relation extractCommonObject(DocumentWrapper wrapDoc)
108 DocumentModel docModel = (DocumentModel) wrapDoc.getWrappedObject();
109 Relation theRelation = new Relation();
111 RelationsManagerNuxeoImpl.fillRelationFromDocModel(theRelation, docModel);
117 public void fillCommonObject(Relation relation, DocumentWrapper wrapDoc) throws Exception {
118 DocumentModel docModel = (DocumentModel) wrapDoc.getWrappedObject();
120 RelationsManagerNuxeoImpl.fillDocModelFromRelation(relation, docModel);
124 public RelationList extractCommonObjectList(DocumentWrapper wrapDoc) throws Exception {
125 DocumentModelList docList = (DocumentModelList) wrapDoc.getWrappedObject();
127 Map propsFromResource = this.getProperties();
128 String subjectCsid = (String)propsFromResource.get(RelationsManager.SUBJECT);
129 String predicate = (String)propsFromResource.get(RelationsManager.PREDICATE);
130 String objectCsid = (String)propsFromResource.get(RelationsManager.OBJECT);
132 RelationList coList = new RelationList();
133 List<RelationList.RelationListItem> list = coList.getRelationListItem();
135 //FIXME: iterating over a long list of documents is not a long term
136 //strategy...need to change to more efficient iterating in future
137 Iterator<DocumentModel> iter = docList.iterator();
138 while(iter.hasNext()){
139 DocumentModel docModel = iter.next();
140 if (RelationsManager.isQueryMatch(docModel, subjectCsid,
141 predicate, objectCsid) == true) {
142 RelationListItem coListItem = new RelationListItem();
143 RelationsManagerNuxeoImpl.fillRelationListItemFromDocModel(
144 coListItem, docModel);
145 list.add(coListItem);
152 public String getDocumentType() {
153 return RelationNuxeoConstants.NUXEO_DOCTYPE;
157 public void fillCommonObjectList(RelationList obj, DocumentWrapper wrapDoc) throws Exception {
158 throw new UnsupportedOperationException();
162 * getQProperty converts the given property to qualified schema property
166 private String getQProperty(String property) {
167 return RelationsManager.getQPropertyName(property);