]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
85273c21148e2f0a39b94e2487789651a1093dd4
[tmp/jakarta-migration.git] /
1 /**     \r
2  * RelationServiceNuxeoImpl.java\r
3  *\r
4  * {Purpose of This Class}\r
5  *\r
6  * {Other Notes Relating to This Class (Optional)}\r
7  *\r
8  * $LastChangedBy: $\r
9  * $LastChangedRevision: $\r
10  * $LastChangedDate: $\r
11  *\r
12  * This document is a part of the source code and related artifacts\r
13  * for CollectionSpace, an open source collections management system\r
14  * for museums and related institutions:\r
15  *\r
16  * http://www.collectionspace.org\r
17  * http://wiki.collectionspace.org\r
18  *\r
19  * Copyright © 2009 {Contributing Institution}\r
20  *\r
21  * Licensed under the Educational Community License (ECL), Version 2.0.\r
22  * You may not use this file except in compliance with this License.\r
23  *\r
24  * You may obtain a copy of the ECL 2.0 License at\r
25  * https://source.collectionspace.org/collection-space/LICENSE.txt\r
26  */\r
27 package org.collectionspace.services.relation.nuxeo;\r
28 \r
29 //import java.io.ByteArrayInputStream;\r
30 import java.io.IOException;\r
31 //import java.io.Serializable;\r
32 //import java.util.ArrayList;\r
33 //import java.util.Arrays;\r
34 //import java.util.HashMap;\r
35 import java.util.List;\r
36 //import java.util.Map;\r
37 //import java.util.Iterator;\r
38 \r
39 import org.collectionspace.services.common.repository.DocumentException;\r
40 //import org.collectionspace.services.nuxeo.NuxeoRESTClient;\r
41 import org.collectionspace.services.nuxeo.CollectionSpaceServiceNuxeoImpl;\r
42 import org.collectionspace.services.common.relation.nuxeo.RelationUtilsNuxeoImpl;\r
43 import org.collectionspace.services.relation.Relation;\r
44 import org.collectionspace.services.relation.RelationService;\r
45 //import org.collectionspace.services.relation.RelationList;\r
46 //import org.collectionspace.services.relation.RelationshipType;\r
47 //import org.collectionspace.services.RelationJAXBSchema;\r
48 import org.collectionspace.services.nuxeo.util.NuxeoUtils;\r
49 import org.collectionspace.services.common.relation.RelationsManager;\r
50 //import org.collectionspace.services.common.ServiceMain;\r
51 \r
52 import org.dom4j.Document;\r
53 //import org.dom4j.Element;\r
54 //import org.dom4j.dom.DOMDocument;\r
55 //import org.dom4j.DocumentException;\r
56 //import org.dom4j.io.SAXReader;\r
57 //import org.restlet.resource.Representation;\r
58 \r
59 import org.nuxeo.common.utils.IdUtils;\r
60 //import org.nuxeo.ecm.core.api.ClientException;\r
61 import org.nuxeo.ecm.core.api.IdRef;\r
62 import org.nuxeo.ecm.core.api.repository.RepositoryInstance;\r
63 import org.nuxeo.ecm.core.api.DocumentModel;\r
64 //import org.nuxeo.ecm.core.api.DocumentModelList;\r
65 //import org.nuxeo.ecm.core.api.model.DocumentPart;\r
66 import org.nuxeo.ecm.core.api.DocumentRef;\r
67 \r
68 \r
69 \r
70 /**\r
71  * The Class RelationServiceNuxeoImpl.\r
72  */\r
73 public class RelationServiceNuxeoImpl extends\r
74                 CollectionSpaceServiceNuxeoImpl implements RelationService {\r
75 \r
76         // replace WORKSPACE_UID for resource workspace\r
77         //      static String CS_RELATION_WORKSPACE_UID = "55f99358-5dbe-4462-8000-c5c3c2063919";\r
78 \r
79         /* (non-Javadoc)\r
80          * @see org.collectionspace.services.relation.RelationService#deleteRelation(java.lang.String)\r
81          */\r
82         public Document deleteRelation(String csid) throws DocumentException {\r
83                 Document result = null;\r
84 \r
85                 RepositoryInstance repoSession = null;\r
86                 try {\r
87                         repoSession = getRepositorySession();\r
88                         result = deleteDocument(repoSession, csid);\r
89                 } catch (Exception e) {\r
90                         if (logger.isDebugEnabled()) {\r
91                                 logger.debug("Caught exception ", e);\r
92                         }\r
93                         throw new DocumentException(e);\r
94                 } finally {\r
95                         if (repoSession != null) {\r
96                                 releaseRepositorySession(repoSession);\r
97                         }\r
98                 }\r
99 \r
100                 return result;\r
101         }\r
102         \r
103         /* (non-Javadoc)\r
104          * @see org.collectionspace.services.relation.RelationService#getRelation(java.lang.String)\r
105          */\r
106         public Document getRelation(String csid)\r
107                         throws DocumentException, IOException {\r
108                 Document result = null;\r
109                 RepositoryInstance repoSession = null;\r
110                 \r
111                 try {\r
112                         repoSession = getRepositorySession();\r
113                         result = NuxeoUtils.getDocument(repoSession, csid);\r
114                 } catch (Exception e) {\r
115                         if (logger.isDebugEnabled()) {\r
116                                 logger.debug("Caught exception ", e);\r
117                         }\r
118                         throw new DocumentException(e);\r
119                 } finally {\r
120                         if (repoSession != null) {\r
121                                 releaseRepositorySession(repoSession);\r
122                         }\r
123                 }\r
124                 \r
125                 // Dump out the contents of the result\r
126                 if (logger.isDebugEnabled() == true) {\r
127                         System.out.println(result.asXML());\r
128                 }\r
129                 \r
130                 return result;\r
131         }\r
132 \r
133         /* (non-Javadoc)\r
134          * @see org.collectionspace.services.relation.RelationService#getRelationList()\r
135          */\r
136         public Document getRelationList()\r
137                         throws DocumentException, IOException {\r
138                 Document result = null;\r
139                 RepositoryInstance repoSession = null;\r
140 \r
141                 try {\r
142                         repoSession = getRepositorySession();\r
143                         List<Relation> relationList = RelationsManager.getRelationships(repoSession);\r
144                         \r
145                         result = RelationUtilsNuxeoImpl.getDocument(relationList);\r
146                 } catch (Exception e) {\r
147                         if (logger.isDebugEnabled()) {\r
148                                 logger.debug("Caught exception ", e);\r
149                         }\r
150                         throw new DocumentException(e);\r
151                 } finally {\r
152                         if (repoSession != null) {\r
153                                 releaseRepositorySession(repoSession);\r
154                         }\r
155                 }\r
156                 \r
157                 if (logger.isDebugEnabled() == true) {\r
158                         System.out.println(result.asXML());\r
159                 }\r
160 \r
161                 return result;\r
162         }\r
163                 \r
164         /* (non-Javadoc)\r
165          * @see org.collectionspace.services.RelationService#getRelationList(java.lang.String, java.lang.String, java.lang.String)\r
166          */\r
167         public Document getRelationList(String subjectCsid,\r
168                         String predicate, String objectCsid)\r
169                                 throws DocumentException, IOException {\r
170                 Document result = null;\r
171                 RepositoryInstance repoSession = null;\r
172 \r
173                 try {\r
174                         repoSession = getRepositorySession();\r
175                         List<Relation> relationList = RelationsManager.getRelationships(repoSession,\r
176                                         subjectCsid, predicate, objectCsid);\r
177                         \r
178                         result = RelationUtilsNuxeoImpl.getDocument(relationList);\r
179                 } catch (Exception e) {\r
180                         if (logger.isDebugEnabled()) {\r
181                                 logger.debug("Caught exception ", e);\r
182                         }\r
183                         throw new DocumentException(e);\r
184                 } finally {\r
185                         if (repoSession != null) {\r
186                                 releaseRepositorySession(repoSession);\r
187                         }\r
188                 }\r
189                 \r
190                 if (logger.isDebugEnabled() == true) {\r
191                         System.out.println(result.asXML());\r
192                 }\r
193 \r
194                 return result;\r
195                 }\r
196 \r
197         // Create a new relation document\r
198         /* (non-Javadoc)\r
199          * @see org.collectionspace.services.relation.RelationService#postRelation(org.collectionspace.services.relation.Relation)\r
200          */\r
201         public Document postRelation(Relation co) throws DocumentException,\r
202                         IOException {\r
203                 Document result = null;\r
204                 RepositoryInstance repoSession = null;\r
205                 \r
206                 try {\r
207                         repoSession = getRepositorySession();\r
208             DocumentModel resultDocModel = RelationUtilsNuxeoImpl.createRelationship(repoSession, co);\r
209             repoSession.save();\r
210             result = NuxeoUtils.getDocument(repoSession, resultDocModel);\r
211                 } catch (Exception e) {\r
212                         if (logger.isDebugEnabled() == true) {\r
213                                 logger.debug("Caught exception ", e);\r
214                         }\r
215                         throw new DocumentException(e);\r
216                 } finally {\r
217                         if (repoSession != null) {\r
218                                 releaseRepositorySession(repoSession);\r
219                         }\r
220                 }\r
221 \r
222                 // Dump out the contents of the result\r
223                 if (logger.isDebugEnabled() == true) {\r
224                         System.out.println(result.asXML());\r
225                 }\r
226                 \r
227                 return result;\r
228         }\r
229         \r
230         /* (non-Javadoc)\r
231          * @see org.collectionspace.services.relation.RelationService#putRelation(java.lang.String, org.collectionspace.services.relation.Relation)\r
232          */\r
233         public Document putRelation(String csid, Relation theUpdate)\r
234                         throws DocumentException, IOException {\r
235                 \r
236                 Document result = null;\r
237         RepositoryInstance repoSession = null;\r
238         try{\r
239             repoSession = getRepositorySession();\r
240             DocumentRef documentRef = new IdRef(csid);\r
241             DocumentModel documentModel = repoSession.getDocument(documentRef);\r
242             RelationUtilsNuxeoImpl.fillDocModelFromRelation(theUpdate, documentModel);\r
243             repoSession.saveDocument(documentModel);\r
244             repoSession.save();\r
245             result = NuxeoUtils.getDocument(repoSession, documentModel);\r
246         } catch(Exception e){\r
247                         if (logger.isDebugEnabled()) {\r
248                                 logger.debug("Caught exception ", e);\r
249                         }\r
250                         throw new DocumentException(e);\r
251         } finally{\r
252             if(repoSession != null){\r
253                 releaseRepositorySession(repoSession);\r
254             }\r
255         }\r
256                 \r
257                 return result;\r
258         }       \r
259 \r
260 }\r