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;
28 import org.collectionspace.services.common.relation.RelationJAXBSchema;
29 //import org.collectionspace.services.common.relation.nuxeo.RelationUtilsNuxeoImpl;
30 import org.collectionspace.services.common.relation.RelationsManager;
32 import org.collectionspace.services.relation.Relation;
33 import org.collectionspace.services.relation.RelationList;
34 import org.collectionspace.services.relation.RelationList.RelationListItem;
36 import org.collectionspace.services.common.repository.DocumentWrapper;
37 import org.collectionspace.services.nuxeo.client.java.DocumentModelHandler;
38 import org.nuxeo.ecm.core.api.DocumentModel;
39 import org.nuxeo.ecm.core.api.DocumentModelList;
40 import org.slf4j.Logger;
41 import org.slf4j.LoggerFactory;
44 * RelationDocumentModelHandler
46 * $LastChangedRevision: $
49 public class RelationDocumentModelHandler
50 extends DocumentModelHandler<Relation, RelationList> {
52 private final Logger logger = LoggerFactory.getLogger(RelationDocumentModelHandler.class);
54 * relation is used to stash JAXB object to use when handle is called
55 * for Action.CREATE, Action.UPDATE or Action.GET
57 private Relation relation;
59 * relationList is stashed when handle is called
62 private RelationList relationList;
65 public void prepare(Action action) throws Exception {
66 //no specific action needed
71 * getCommonObject get associated Relation
75 public Relation getCommonObject() {
80 * setCommonObject set associated relation
84 public void setCommonObject(Relation relation) {
85 this.relation = relation;
89 * getRelationList get associated Relation (for index/GET_ALL)
93 public RelationList getCommonObjectList() {
98 public void setCommonObjectList(RelationList relationList) {
99 this.relationList = relationList;
103 public Relation extractCommonObject(DocumentWrapper wrapDoc)
105 DocumentModel docModel = (DocumentModel) wrapDoc.getWrappedObject();
106 Relation co = new Relation();
112 public void fillCommonObject(Relation co, DocumentWrapper wrapDoc) throws Exception {
113 DocumentModel docModel = (DocumentModel) wrapDoc.getWrappedObject();
114 //FIXME property setter should be dynamically set using schema inspection
115 //so it does not require hard coding
120 public RelationList extractCommonObjectList(DocumentWrapper wrapDoc) throws Exception {
121 DocumentModelList docList = (DocumentModelList) wrapDoc.getWrappedObject();
123 RelationList coList = new RelationList();
124 List<RelationList.RelationListItem> list = coList.getRelationListItem();
126 //FIXME: iterating over a long list of documents is not a long term
127 //strategy...need to change to more efficient iterating in future
128 Iterator<DocumentModel> iter = docList.iterator();
129 while(iter.hasNext()){
130 DocumentModel docModel = iter.next();
131 RelationListItem coListItem = new RelationListItem();
133 coListItem.setCsid((String) docModel.getPropertyValue(
134 getQProperty(RelationJAXBSchema.DOCUMENT_ID_1)));
136 //need fully qualified context for URI
137 coListItem.setUri("/relations/" + docModel.getId());
138 coListItem.setCsid(docModel.getId());
139 list.add(coListItem);
146 public void fillCommonObjectList(RelationList obj, DocumentWrapper wrapDoc) throws Exception {
147 throw new UnsupportedOperationException();
151 * getQProperty converts the given property to qualified schema property
155 private String getQProperty(String property) {
156 return RelationsManager.getQPropertyName(property);