]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
17ab12de09386195979b6f750e0fd14167e7ad0f
[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.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;
37
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;
48
49 /**
50  * RelationDocumentModelHandler
51  *
52  * $LastChangedRevision: $
53  * $LastChangedDate: $
54  */
55 public class RelationDocumentModelHandler
56         extends RemoteDocumentModelHandlerImpl<RelationsCommon, RelationsCommonList> {
57
58     /** The logger. */
59     private final Logger logger = LoggerFactory.getLogger(RelationDocumentModelHandler.class);
60     /**
61      * relation is used to stash JAXB object to use when handle is called
62      * for Action.CREATE, Action.UPDATE or Action.GET
63      */
64     private RelationsCommon relation;
65     /**
66      * relationList is stashed when handle is called
67      * for ACTION.GET_ALL
68      */
69     private RelationsCommonList relationList;
70
71
72     /**
73      * getCommonObject get associated Relation
74      * @return relation
75      */
76     @Override
77     public RelationsCommon getCommonPart() {
78         return relation;
79     }
80
81     /**
82      * setCommonObject set associated relation
83      * @param relation
84      */
85     @Override
86     public void setCommonPart(RelationsCommon theRelation) {
87         this.relation = theRelation;
88     }
89
90     /**
91      * getRelationList get associated Relation (for index/GET_ALL)
92      * @return relationCommonList
93      */
94     @Override
95     public RelationsCommonList getCommonPartList() {
96         return relationList;
97     }
98
99     /* (non-Javadoc)
100      * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#setCommonPartList(java.lang.Object)
101      */
102     @Override
103     public void setCommonPartList(RelationsCommonList theRelationList) {
104         this.relationList = theRelationList;
105     }
106
107     /* (non-Javadoc)
108      * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#extractCommonPart(org.collectionspace.services.common.document.DocumentWrapper)
109      */
110     @Override
111     public RelationsCommon extractCommonPart(DocumentWrapper<DocumentModel> wrapDoc)
112             throws Exception {
113         throw new UnsupportedOperationException();
114     }
115
116     /* (non-Javadoc)
117      * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#fillCommonPart(java.lang.Object, org.collectionspace.services.common.document.DocumentWrapper)
118      */
119     @Override
120     public void fillCommonPart(RelationsCommon theRelation, DocumentWrapper<DocumentModel> wrapDoc) throws Exception {
121         throw new UnsupportedOperationException();
122     }
123
124     /* (non-Javadoc)
125      * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#extractCommonPartList(org.collectionspace.services.common.document.DocumentWrapper)
126      */
127     @Override
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);
139         }
140         return relList;
141     }
142
143   
144
145     /* (non-Javadoc)
146      * @see org.collectionspace.services.nuxeo.client.java.RemoteDocumentModelHandlerImpl#fillAllParts(org.collectionspace.services.common.document.DocumentWrapper)
147     @Override
148     public void fillAllParts(DocumentWrapper<DocumentModel> wrapDoc) throws Exception {
149         super.fillAllParts(wrapDoc);
150     }
151      */
152
153     /**
154      * Gets the relation list item.
155      *
156      * @param ctx the ctx
157      * @param docModel the doc model
158      * @param serviceContextPath the service context path
159      * @return the relation list item
160      * @throws Exception the exception
161      */
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);
168         //
169         // Subject
170         //
171         relationListItem.setSubjectCsid((String) docModel.getProperty(ctx.getCommonPartLabel(),
172                         RelationJAXBSchema.DOCUMENT_ID_1));
173         //
174         // Predicate
175         //
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));
180         //
181         // Object
182         //
183         relationListItem.setObjectCsid((String) docModel.getProperty(ctx.getCommonPartLabel(),
184                         RelationJAXBSchema.DOCUMENT_ID_2));
185         
186         relationListItem.setUri(serviceContextPath + id);
187         return relationListItem;
188     }
189
190     /* (non-Javadoc)
191      * @see org.collectionspace.services.common.document.AbstractMultipartDocumentHandlerImpl#getQProperty(java.lang.String)
192      */
193     @Override
194     public String getQProperty(String prop) {
195         return "/" + RelationConstants.NUXEO_SCHEMA_ROOT_ELEMENT + "/" + prop;
196     }
197 }
198