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.RelationsManagerNuxeoImpl;
\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
71 * The Class RelationServiceNuxeoImpl.
\r
73 public class RelationServiceNuxeoImpl extends
\r
74 CollectionSpaceServiceNuxeoImpl implements RelationService {
\r
76 // replace WORKSPACE_UID for resource workspace
\r
77 // static String CS_RELATION_WORKSPACE_UID = "55f99358-5dbe-4462-8000-c5c3c2063919";
\r
80 * @see org.collectionspace.services.relation.RelationService#deleteRelation(java.lang.String)
\r
82 public Document deleteRelation(String csid) throws DocumentException {
\r
83 Document result = null;
\r
85 // RepositoryInstance repoSession = null;
\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
93 // throw new DocumentException(e);
\r
95 // if (repoSession != null) {
\r
96 // releaseRepositorySession(repoSession);
\r
104 * @see org.collectionspace.services.relation.RelationService#getRelation(java.lang.String)
\r
106 public Document getRelation(String csid)
\r
107 throws DocumentException, IOException {
\r
108 Document result = null;
\r
109 RepositoryInstance repoSession = null;
\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
118 throw new DocumentException(e);
\r
120 if (repoSession != null) {
\r
121 releaseRepositorySession(repoSession);
\r
125 // Dump out the contents of the result
\r
126 if (logger.isDebugEnabled() == true) {
\r
127 System.out.println(result.asXML());
\r
134 * @see org.collectionspace.services.relation.RelationService#getRelationList()
\r
136 public Document getRelationList()
\r
137 throws DocumentException, IOException {
\r
138 Document result = null;
\r
139 RepositoryInstance repoSession = null;
\r
142 repoSession = getRepositorySession();
\r
143 List<Relation> relationList = RelationsManager.getRelationships(repoSession);
\r
145 result = RelationsManagerNuxeoImpl.getDocument(relationList);
\r
146 } catch (Exception e) {
\r
147 if (logger.isDebugEnabled()) {
\r
148 logger.debug("Caught exception ", e);
\r
150 throw new DocumentException(e);
\r
152 if (repoSession != null) {
\r
153 releaseRepositorySession(repoSession);
\r
157 if (logger.isDebugEnabled() == true) {
\r
158 System.out.println(result.asXML());
\r
165 * @see org.collectionspace.services.RelationService#getRelationList(java.lang.String, java.lang.String, java.lang.String)
\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
174 repoSession = getRepositorySession();
\r
175 List<Relation> relationList = RelationsManager.getRelationships(repoSession,
\r
176 subjectCsid, predicate, objectCsid);
\r
178 result = RelationsManagerNuxeoImpl.getDocument(relationList);
\r
179 } catch (Exception e) {
\r
180 if (logger.isDebugEnabled()) {
\r
181 logger.debug("Caught exception ", e);
\r
183 throw new DocumentException(e);
\r
185 if (repoSession != null) {
\r
186 releaseRepositorySession(repoSession);
\r
190 if (logger.isDebugEnabled() == true) {
\r
191 System.out.println(result.asXML());
\r
197 // Create a new relation document
\r
199 * @see org.collectionspace.services.relation.RelationService#postRelation(org.collectionspace.services.relation.Relation)
\r
201 public Document postRelation(Relation co) throws DocumentException,
\r
203 Document result = null;
\r
204 RepositoryInstance repoSession = null;
\r
207 repoSession = getRepositorySession();
\r
208 DocumentModel resultDocModel = RelationsManagerNuxeoImpl.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
215 throw new DocumentException(e);
\r
217 if (repoSession != null) {
\r
218 releaseRepositorySession(repoSession);
\r
222 // Dump out the contents of the result
\r
223 if (logger.isDebugEnabled() == true) {
\r
224 System.out.println(result.asXML());
\r
231 * @see org.collectionspace.services.relation.RelationService#putRelation(java.lang.String, org.collectionspace.services.relation.Relation)
\r
233 public Document putRelation(String csid, Relation theUpdate)
\r
234 throws DocumentException, IOException {
\r
236 Document result = null;
\r
237 RepositoryInstance repoSession = null;
\r
239 repoSession = getRepositorySession();
\r
240 DocumentRef documentRef = new IdRef(csid);
\r
241 DocumentModel documentModel = repoSession.getDocument(documentRef);
\r
242 RelationsManagerNuxeoImpl.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
250 throw new DocumentException(e);
\r
252 if(repoSession != null){
\r
253 releaseRepositorySession(repoSession);
\r