]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
dafee918147f57d62ab2164f25660f8b306dfcb2
[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.nuxeo.client.java.RemoteDocumentModelHandlerImpl;
38 import org.collectionspace.services.nuxeo.util.NuxeoUtils;
39 import org.jboss.resteasy.plugins.providers.multipart.MultipartInput;
40 import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput;
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;
45
46 /**
47  * RelationDocumentModelHandler
48  *
49  * $LastChangedRevision: $
50  * $LastChangedDate: $
51  */
52 public class RelationDocumentModelHandler
53         extends RemoteDocumentModelHandlerImpl<RelationsCommon, RelationsCommonList> {
54
55     /** The logger. */
56     private final Logger logger = LoggerFactory.getLogger(RelationDocumentModelHandler.class);
57     /**
58      * relation is used to stash JAXB object to use when handle is called
59      * for Action.CREATE, Action.UPDATE or Action.GET
60      */
61     private RelationsCommon relation;
62     /**
63      * relationList is stashed when handle is called
64      * for ACTION.GET_ALL
65      */
66     private RelationsCommonList relationList;
67
68
69     /**
70      * getCommonObject get associated Relation
71      * @return relation
72      */
73     @Override
74     public RelationsCommon getCommonPart() {
75         return relation;
76     }
77
78     /**
79      * setCommonObject set associated relation
80      * @param relation
81      */
82     @Override
83     public void setCommonPart(RelationsCommon theRelation) {
84         this.relation = theRelation;
85     }
86
87     /**
88      * getRelationList get associated Relation (for index/GET_ALL)
89      * @return relationCommonList
90      */
91     @Override
92     public RelationsCommonList getCommonPartList() {
93         return relationList;
94     }
95
96     /* (non-Javadoc)
97      * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#setCommonPartList(java.lang.Object)
98      */
99     @Override
100     public void setCommonPartList(RelationsCommonList theRelationList) {
101         this.relationList = theRelationList;
102     }
103
104     /* (non-Javadoc)
105      * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#extractCommonPart(org.collectionspace.services.common.document.DocumentWrapper)
106      */
107     @Override
108     public RelationsCommon extractCommonPart(DocumentWrapper<DocumentModel> wrapDoc)
109             throws Exception {
110         throw new UnsupportedOperationException();
111     }
112
113     /* (non-Javadoc)
114      * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#fillCommonPart(java.lang.Object, org.collectionspace.services.common.document.DocumentWrapper)
115      */
116     @Override
117     public void fillCommonPart(RelationsCommon theRelation, DocumentWrapper<DocumentModel> wrapDoc) throws Exception {
118         throw new UnsupportedOperationException();
119     }
120
121     /* (non-Javadoc)
122      * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#extractCommonPartList(org.collectionspace.services.common.document.DocumentWrapper)
123      */
124     @Override
125     public RelationsCommonList extractCommonPartList(DocumentWrapper<DocumentModelList> wrapDoc) throws Exception {
126         RelationsCommonList relList = this.extractPagingInfo(new RelationsCommonList(), wrapDoc) ;
127         List<RelationsCommonList.RelationListItem> itemList = relList.getRelationListItem();
128         Iterator<DocumentModel> iter = wrapDoc.getWrappedObject().iterator();
129         while(iter.hasNext()){
130             DocumentModel docModel = iter.next();
131             RelationListItem relListItem = getRelationListItem(getServiceContext(),
132                     docModel, getServiceContextPath());
133             itemList.add(relListItem);
134         }
135         return relList;
136     }
137
138   
139
140     /* (non-Javadoc)
141      * @see org.collectionspace.services.nuxeo.client.java.RemoteDocumentModelHandlerImpl#fillAllParts(org.collectionspace.services.common.document.DocumentWrapper)
142      */
143     @Override
144     public void fillAllParts(DocumentWrapper<DocumentModel> wrapDoc) throws Exception {
145         super.fillAllParts(wrapDoc);
146     }
147
148     /**
149      * Gets the relation list item.
150      *
151      * @param ctx the ctx
152      * @param docModel the doc model
153      * @param serviceContextPath the service context path
154      * @return the relation list item
155      * @throws Exception the exception
156      */
157     private RelationListItem getRelationListItem(ServiceContext<MultipartInput, MultipartOutput> ctx,
158                 DocumentModel docModel,
159             String serviceContextPath) throws Exception {
160         RelationListItem relationListItem = new RelationListItem();
161         String id = NuxeoUtils.extractId(docModel.getPathAsString());
162         relationListItem.setCsid(id);
163         //
164         // Subject
165         //
166         relationListItem.setSubjectCsid((String) docModel.getProperty(ctx.getCommonPartLabel(),
167                         RelationJAXBSchema.DOCUMENT_ID_1));
168         //
169         // Predicate
170         //
171         relationListItem.setRelationshipType((String) docModel.getProperty(ctx.getCommonPartLabel(),
172                         RelationJAXBSchema.RELATIONSHIP_TYPE));
173         //
174         // Object
175         //
176         relationListItem.setObjectCsid((String) docModel.getProperty(ctx.getCommonPartLabel(),
177                         RelationJAXBSchema.DOCUMENT_ID_2));
178         
179         relationListItem.setUri(serviceContextPath + id);
180         return relationListItem;
181     }
182
183     /* (non-Javadoc)
184      * @see org.collectionspace.services.common.document.AbstractMultipartDocumentHandlerImpl#getQProperty(java.lang.String)
185      */
186     @Override
187     public String getQProperty(String prop) {
188         return "/" + RelationConstants.NUXEO_SCHEMA_ROOT_ELEMENT + "/" + prop;
189     }
190 }
191