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;
29 import org.collectionspace.services.client.PoxPayloadIn;
30 import org.collectionspace.services.client.PoxPayloadOut;
31 import org.collectionspace.services.common.relation.RelationJAXBSchema;
32 import org.collectionspace.services.common.relation.nuxeo.RelationConstants;
33 import org.collectionspace.services.common.context.ServiceContext;
34 import org.collectionspace.services.relation.RelationsCommon;
35 import org.collectionspace.services.relation.RelationsCommonList;
36 import org.collectionspace.services.relation.RelationsCommonList.RelationListItem;
38 import org.collectionspace.services.common.document.DocumentWrapper;
39 import org.collectionspace.services.jaxb.AbstractCommonList;
40 import org.collectionspace.services.nuxeo.client.java.RemoteDocumentModelHandlerImpl;
41 import org.collectionspace.services.nuxeo.util.NuxeoUtils;
42 import org.jboss.resteasy.plugins.providers.multipart.MultipartInput;
43 import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput;
44 import org.nuxeo.ecm.core.api.DocumentModel;
45 import org.nuxeo.ecm.core.api.DocumentModelList;
46 import org.slf4j.Logger;
47 import org.slf4j.LoggerFactory;
50 * RelationDocumentModelHandler
52 * $LastChangedRevision: $
55 public class RelationDocumentModelHandler
56 extends RemoteDocumentModelHandlerImpl<RelationsCommon, RelationsCommonList> {
59 private final Logger logger = LoggerFactory.getLogger(RelationDocumentModelHandler.class);
61 * relation is used to stash JAXB object to use when handle is called
62 * for Action.CREATE, Action.UPDATE or Action.GET
64 private RelationsCommon relation;
66 * relationList is stashed when handle is called
69 private RelationsCommonList relationList;
73 * getCommonObject get associated Relation
77 public RelationsCommon getCommonPart() {
82 * setCommonObject set associated relation
86 public void setCommonPart(RelationsCommon theRelation) {
87 this.relation = theRelation;
91 * getRelationList get associated Relation (for index/GET_ALL)
92 * @return relationCommonList
95 public RelationsCommonList getCommonPartList() {
100 * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#setCommonPartList(java.lang.Object)
103 public void setCommonPartList(RelationsCommonList theRelationList) {
104 this.relationList = theRelationList;
108 * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#extractCommonPart(org.collectionspace.services.common.document.DocumentWrapper)
111 public RelationsCommon extractCommonPart(DocumentWrapper<DocumentModel> wrapDoc)
113 throw new UnsupportedOperationException();
117 * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#fillCommonPart(java.lang.Object, org.collectionspace.services.common.document.DocumentWrapper)
120 public void fillCommonPart(RelationsCommon theRelation, DocumentWrapper<DocumentModel> wrapDoc) throws Exception {
121 throw new UnsupportedOperationException();
125 * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#extractCommonPartList(org.collectionspace.services.common.document.DocumentWrapper)
128 public RelationsCommonList extractCommonPartList(DocumentWrapper<DocumentModelList> wrapDoc) throws Exception {
129 RelationsCommonList relList = this.extractPagingInfo(new RelationsCommonList(), wrapDoc) ;
130 AbstractCommonList commonList = (AbstractCommonList) relList;
131 commonList.setFieldsReturned("subjectCsid|relationshipType|predicateDisplayName|objectCsid|uri|csid");
132 List<RelationsCommonList.RelationListItem> itemList = relList.getRelationListItem();
133 Iterator<DocumentModel> iter = wrapDoc.getWrappedObject().iterator();
134 while(iter.hasNext()){
135 DocumentModel docModel = iter.next();
136 RelationListItem relListItem = getRelationListItem(getServiceContext(),
137 docModel, getServiceContextPath());
138 itemList.add(relListItem);
146 * @see org.collectionspace.services.nuxeo.client.java.RemoteDocumentModelHandlerImpl#fillAllParts(org.collectionspace.services.common.document.DocumentWrapper)
148 public void fillAllParts(DocumentWrapper<DocumentModel> wrapDoc) throws Exception {
149 super.fillAllParts(wrapDoc);
154 * Gets the relation list item.
157 * @param docModel the doc model
158 * @param serviceContextPath the service context path
159 * @return the relation list item
160 * @throws Exception the exception
162 private RelationListItem getRelationListItem(ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx,
163 DocumentModel docModel,
164 String serviceContextPath) throws Exception {
165 RelationListItem relationListItem = new RelationListItem();
166 String id = getCsid(docModel);//NuxeoUtils.extractId(docModel.getPathAsString());
167 relationListItem.setCsid(id);
171 relationListItem.setSubjectCsid((String) docModel.getProperty(ctx.getCommonPartLabel(),
172 RelationJAXBSchema.DOCUMENT_ID_1));
176 relationListItem.setRelationshipType((String) docModel.getProperty(ctx.getCommonPartLabel(),
177 RelationJAXBSchema.RELATIONSHIP_TYPE));
178 relationListItem.setPredicateDisplayName((String) docModel.getProperty(ctx.getCommonPartLabel(),
179 RelationJAXBSchema.RELATIONSHIP_TYPE_DISPLAYNAME));
183 relationListItem.setObjectCsid((String) docModel.getProperty(ctx.getCommonPartLabel(),
184 RelationJAXBSchema.DOCUMENT_ID_2));
186 relationListItem.setUri(serviceContextPath + id);
187 return relationListItem;
191 * @see org.collectionspace.services.common.document.AbstractMultipartDocumentHandlerImpl#getQProperty(java.lang.String)
194 public String getQProperty(String prop) {
195 return "/" + RelationConstants.NUXEO_SCHEMA_ROOT_ELEMENT + "/" + prop;