]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
ff86a50ccdc4110d6fc07fb5f82cba3b6cea54e2
[tmp/jakarta-migration.git] /
1 /**
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:
5
6  *  http://www.collectionspace.org
7  *  http://wiki.collectionspace.org
8
9  *  Copyright 2009 University of California at Berkeley
10
11  *  Licensed under the Educational Community License (ECL), Version 2.0.
12  *  You may not use this file except in compliance with this License.
13
14  *  You may obtain a copy of the ECL 2.0 License at
15
16  *  https://source.collectionspace.org/collection-space/LICENSE.txt
17
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.
23  */
24 package org.collectionspace.services.relation.nuxeo;
25
26 import java.util.Iterator;
27 import java.util.List;
28
29 import org.collectionspace.services.common.relation.RelationJAXBSchema;
30 import org.collectionspace.services.common.relation.nuxeo.RelationConstants;
31 import org.collectionspace.services.common.context.ServiceContext;
32 import org.collectionspace.services.relation.RelationsCommon;
33 import org.collectionspace.services.relation.RelationsCommonList;
34 import org.collectionspace.services.relation.RelationsCommonList.RelationListItem;
35
36 import org.collectionspace.services.common.document.DocumentWrapper;
37 import org.collectionspace.services.jaxb.AbstractCommonList;
38 import org.collectionspace.services.nuxeo.client.java.RemoteDocumentModelHandlerImpl;
39 import org.collectionspace.services.nuxeo.util.NuxeoUtils;
40 import org.jboss.resteasy.plugins.providers.multipart.MultipartInput;
41 import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput;
42 import org.nuxeo.ecm.core.api.DocumentModel;
43 import org.nuxeo.ecm.core.api.DocumentModelList;
44 import org.slf4j.Logger;
45 import org.slf4j.LoggerFactory;
46
47 /**
48  * RelationDocumentModelHandler
49  *
50  * $LastChangedRevision: $
51  * $LastChangedDate: $
52  */
53 public class RelationDocumentModelHandler
54         extends RemoteDocumentModelHandlerImpl<RelationsCommon, RelationsCommonList> {
55
56     /** The logger. */
57     private final Logger logger = LoggerFactory.getLogger(RelationDocumentModelHandler.class);
58     /**
59      * relation is used to stash JAXB object to use when handle is called
60      * for Action.CREATE, Action.UPDATE or Action.GET
61      */
62     private RelationsCommon relation;
63     /**
64      * relationList is stashed when handle is called
65      * for ACTION.GET_ALL
66      */
67     private RelationsCommonList relationList;
68
69
70     /**
71      * getCommonObject get associated Relation
72      * @return relation
73      */
74     @Override
75     public RelationsCommon getCommonPart() {
76         return relation;
77     }
78
79     /**
80      * setCommonObject set associated relation
81      * @param relation
82      */
83     @Override
84     public void setCommonPart(RelationsCommon theRelation) {
85         this.relation = theRelation;
86     }
87
88     /**
89      * getRelationList get associated Relation (for index/GET_ALL)
90      * @return relationCommonList
91      */
92     @Override
93     public RelationsCommonList getCommonPartList() {
94         return relationList;
95     }
96
97     /* (non-Javadoc)
98      * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#setCommonPartList(java.lang.Object)
99      */
100     @Override
101     public void setCommonPartList(RelationsCommonList theRelationList) {
102         this.relationList = theRelationList;
103     }
104
105     /* (non-Javadoc)
106      * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#extractCommonPart(org.collectionspace.services.common.document.DocumentWrapper)
107      */
108     @Override
109     public RelationsCommon extractCommonPart(DocumentWrapper<DocumentModel> wrapDoc)
110             throws Exception {
111         throw new UnsupportedOperationException();
112     }
113
114     /* (non-Javadoc)
115      * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#fillCommonPart(java.lang.Object, org.collectionspace.services.common.document.DocumentWrapper)
116      */
117     @Override
118     public void fillCommonPart(RelationsCommon theRelation, DocumentWrapper<DocumentModel> wrapDoc) throws Exception {
119         throw new UnsupportedOperationException();
120     }
121
122     /* (non-Javadoc)
123      * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#extractCommonPartList(org.collectionspace.services.common.document.DocumentWrapper)
124      */
125     @Override
126     public RelationsCommonList extractCommonPartList(DocumentWrapper<DocumentModelList> wrapDoc) throws Exception {
127         RelationsCommonList relList = this.extractPagingInfo(new RelationsCommonList(), wrapDoc) ;
128         AbstractCommonList commonList = (AbstractCommonList) relList;
129         commonList.setFieldsReturned("subjectCsid|relationshipType|predicateDisplayName|objectCsid|uri|csid");
130         List<RelationsCommonList.RelationListItem> itemList = relList.getRelationListItem();
131         Iterator<DocumentModel> iter = wrapDoc.getWrappedObject().iterator();
132         while(iter.hasNext()){
133             DocumentModel docModel = iter.next();
134             RelationListItem relListItem = getRelationListItem(getServiceContext(),
135                     docModel, getServiceContextPath());
136             itemList.add(relListItem);
137         }
138         return relList;
139     }
140
141   
142
143     /* (non-Javadoc)
144      * @see org.collectionspace.services.nuxeo.client.java.RemoteDocumentModelHandlerImpl#fillAllParts(org.collectionspace.services.common.document.DocumentWrapper)
145     @Override
146     public void fillAllParts(DocumentWrapper<DocumentModel> wrapDoc) throws Exception {
147         super.fillAllParts(wrapDoc);
148     }
149      */
150
151     /**
152      * Gets the relation list item.
153      *
154      * @param ctx the ctx
155      * @param docModel the doc model
156      * @param serviceContextPath the service context path
157      * @return the relation list item
158      * @throws Exception the exception
159      */
160     private RelationListItem getRelationListItem(ServiceContext<MultipartInput, MultipartOutput> ctx,
161                 DocumentModel docModel,
162             String serviceContextPath) throws Exception {
163         RelationListItem relationListItem = new RelationListItem();
164         String id = getCsid(docModel);//NuxeoUtils.extractId(docModel.getPathAsString());
165         relationListItem.setCsid(id);
166         //
167         // Subject
168         //
169         relationListItem.setSubjectCsid((String) docModel.getProperty(ctx.getCommonPartLabel(),
170                         RelationJAXBSchema.DOCUMENT_ID_1));
171         //
172         // Predicate
173         //
174         relationListItem.setRelationshipType((String) docModel.getProperty(ctx.getCommonPartLabel(),
175                         RelationJAXBSchema.RELATIONSHIP_TYPE));
176         relationListItem.setPredicateDisplayName((String) docModel.getProperty(ctx.getCommonPartLabel(),
177                         RelationJAXBSchema.RELATIONSHIP_TYPE_DISPLAYNAME));
178         //
179         // Object
180         //
181         relationListItem.setObjectCsid((String) docModel.getProperty(ctx.getCommonPartLabel(),
182                         RelationJAXBSchema.DOCUMENT_ID_2));
183         
184         relationListItem.setUri(serviceContextPath + id);
185         return relationListItem;
186     }
187
188     /* (non-Javadoc)
189      * @see org.collectionspace.services.common.document.AbstractMultipartDocumentHandlerImpl#getQProperty(java.lang.String)
190      */
191     @Override
192     public String getQProperty(String prop) {
193         return "/" + RelationConstants.NUXEO_SCHEMA_ROOT_ELEMENT + "/" + prop;
194     }
195 }
196