2 * RelationServiceNuxeoImpl.java
\r
4 * {Purpose of This Class}
\r
6 * {Other Notes Relating to This Class (Optional)}
\r
9 * $LastChangedRevision: $
\r
10 * $LastChangedDate: $
\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
16 * http://www.collectionspace.org
\r
17 * http://wiki.collectionspace.org
\r
19 * Copyright © 2009 {Contributing Institution}
\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
24 * You may obtain a copy of the ECL 2.0 License at
\r
25 * https://source.collectionspace.org/collection-space/LICENSE.txt
\r
27 package org.collectionspace.services.relation.nuxeo;
\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
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
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
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
74 public class RelationServiceNuxeoImpl extends
\r
75 CollectionSpaceServiceNuxeoImpl implements RelationService {
\r
77 // replace WORKSPACE_UID for resource workspace
\r
78 // static String CS_RELATION_WORKSPACE_UID = "55f99358-5dbe-4462-8000-c5c3c2063919";
\r
83 * @param csid the csid
\r
85 * @return the document
\r
87 * @throws DocumentException the document exception
\r
88 * @throws IOException Signals that an I/O exception has occurred.
\r
90 public Document deleteRelation(String csid) throws DocumentException {
\r
91 Document result = null;
\r
93 RepositoryInstance repoSession = null;
\r
95 repoSession = getRepositorySession();
\r
96 result = deleteDocument(repoSession, csid);
\r
97 } catch (Exception e) {
\r
98 if (logger.isDebugEnabled()) {
\r
99 logger.debug("Caught exception ", e);
\r
101 throw new DocumentException(e);
\r
103 if (repoSession != null) {
\r
104 releaseRepositorySession(repoSession);
\r
112 * Gets the relation.
\r
114 * @param csid the csid
\r
116 * @return the relation
\r
118 * @throws DocumentException the document exception
\r
119 * @throws IOException Signals that an I/O exception has occurred.
\r
121 public Document getRelation(String csid)
\r
122 throws DocumentException, IOException {
\r
123 Document result = null;
\r
124 RepositoryInstance repoSession = null;
\r
127 repoSession = getRepositorySession();
\r
128 result = NuxeoUtils.getDocument(repoSession, csid);
\r
129 } catch (Exception e) {
\r
130 if (logger.isDebugEnabled()) {
\r
131 logger.debug("Caught exception ", e);
\r
133 throw new DocumentException(e);
\r
135 if (repoSession != null) {
\r
136 releaseRepositorySession(repoSession);
\r
140 // Dump out the contents of the result
\r
141 if (logger.isDebugEnabled() == true) {
\r
142 System.out.println(result.asXML());
\r
149 * Gets the relation list.
\r
151 * @return the relation list
\r
153 * @throws DocumentException the document exception
\r
154 * @throws IOException Signals that an I/O exception has occurred.
\r
156 public Document getRelationList()
\r
157 throws DocumentException, IOException {
\r
158 Document result = null;
\r
159 RepositoryInstance repoSession = null;
\r
162 repoSession = getRepositorySession();
\r
163 List<Relation> relationList = RelationsManager.getRelationships(repoSession);
\r
165 result = RelationUtilsNuxeoImpl.getDocument(relationList);
\r
166 } catch (Exception e) {
\r
167 if (logger.isDebugEnabled()) {
\r
168 logger.debug("Caught exception ", e);
\r
170 throw new DocumentException(e);
\r
172 if (repoSession != null) {
\r
173 releaseRepositorySession(repoSession);
\r
177 if (logger.isDebugEnabled() == true) {
\r
178 System.out.println(result.asXML());
\r
185 * @see org.collectionspace.services.RelationService#getRelationList(java.lang.String, java.lang.String, java.lang.String)
\r
187 public Document getRelationList(String subjectCsid,
\r
188 String predicate, String objectCsid)
\r
189 throws DocumentException, IOException {
\r
190 Document result = null;
\r
191 RepositoryInstance repoSession = null;
\r
194 repoSession = getRepositorySession();
\r
195 List<Relation> relationList = RelationsManager.getRelationships(repoSession,
\r
196 subjectCsid, predicate, objectCsid);
\r
198 result = RelationUtilsNuxeoImpl.getDocument(relationList);
\r
199 } catch (Exception e) {
\r
200 if (logger.isDebugEnabled()) {
\r
201 logger.debug("Caught exception ", e);
\r
203 throw new DocumentException(e);
\r
205 if (repoSession != null) {
\r
206 releaseRepositorySession(repoSession);
\r
210 if (logger.isDebugEnabled() == true) {
\r
211 System.out.println(result.asXML());
\r
217 // Create a new relation document
\r
223 * @return the document
\r
225 * @throws DocumentException the document exception
\r
226 * @throws IOException Signals that an I/O exception has occurred.
\r
228 public Document postRelation(Relation co) throws DocumentException,
\r
230 Document result = null;
\r
231 RepositoryInstance repoSession = null;
\r
234 repoSession = getRepositorySession();
\r
235 DocumentModel resultDocModel = RelationUtilsNuxeoImpl.createRelationship(repoSession, co);
\r
236 repoSession.save();
\r
237 result = NuxeoUtils.getDocument(repoSession, resultDocModel);
\r
238 } catch (Exception e) {
\r
239 if (logger.isDebugEnabled() == true) {
\r
240 logger.debug("Caught exception ", e);
\r
242 throw new DocumentException(e);
\r
244 if (repoSession != null) {
\r
245 releaseRepositorySession(repoSession);
\r
249 // Dump out the contents of the result
\r
250 if (logger.isDebugEnabled() == true) {
\r
251 System.out.println(result.asXML());
\r
260 * @param csid the csid
\r
261 * @param theUpdate the the update
\r
263 * @return the document
\r
265 * @throws DocumentException the document exception
\r
266 * @throws IOException Signals that an I/O exception has occurred.
\r
268 public Document putRelation(String csid, Relation theUpdate)
\r
269 throws DocumentException, IOException {
\r
271 Document result = null;
\r
272 RepositoryInstance repoSession = null;
\r
274 repoSession = getRepositorySession();
\r
275 DocumentRef documentRef = new IdRef(csid);
\r
276 DocumentModel documentModel = repoSession.getDocument(documentRef);
\r
277 RelationUtilsNuxeoImpl.fillDocModelFromRelation(theUpdate, documentModel);
\r
278 repoSession.saveDocument(documentModel);
\r
279 repoSession.save();
\r
280 result = NuxeoUtils.getDocument(repoSession, documentModel);
\r
281 } catch(Exception e){
\r
282 if (logger.isDebugEnabled()) {
\r
283 logger.debug("Caught exception ", e);
\r
285 throw new DocumentException(e);
\r
287 if(repoSession != null){
\r
288 releaseRepositorySession(repoSession);
\r