From: Richard Millet Date: Fri, 7 Aug 2009 19:22:55 +0000 (+0000) Subject: CSPACE-332: A working snapshot set of Relation manager sources before checking in... X-Git-Url: https://git.aero2k.de/?a=commitdiff_plain;h=7d651bad909a22d654854eeabd24de6d9ab1dd28;p=tmp%2Fjakarta-migration.git CSPACE-332: A working snapshot set of Relation manager sources before checking in other major changes. --- diff --git a/services/JaxRsServiceProvider/pom.xml b/services/JaxRsServiceProvider/pom.xml index a3edaf321..df50b2273 100644 --- a/services/JaxRsServiceProvider/pom.xml +++ b/services/JaxRsServiceProvider/pom.xml @@ -172,7 +172,7 @@ 8180 - + diff --git a/services/common/src/main/java/org/collectionspace/services/RelationJAXBSchema.java b/services/common/src/main/java/org/collectionspace/services/RelationJAXBSchema.java index 66a1a20d5..74c58e3c5 100644 --- a/services/common/src/main/java/org/collectionspace/services/RelationJAXBSchema.java +++ b/services/common/src/main/java/org/collectionspace/services/RelationJAXBSchema.java @@ -1,11 +1,33 @@ -/** - * +/** + * RelationJAXBSchema.java + * + * {Purpose of This Class} + * + * {Other Notes Relating to This Class (Optional)} + * + * $LastChangedBy: $ + * $LastChangedRevision: $ + * $LastChangedDate: $ + * + * This document is a part of the source code and related artifacts + * for CollectionSpace, an open source collections management system + * for museums and related institutions: + * + * http://www.collectionspace.org + * http://wiki.collectionspace.org + * + * Copyright © 2009 {Contributing Institution} + * + * Licensed under the Educational Community License (ECL), Version 2.0. + * You may not use this file except in compliance with this License. + * + * You may obtain a copy of the ECL 2.0 License at + * https://source.collectionspace.org/collection-space/LICENSE.txt */ package org.collectionspace.services; /** - * @author Richard Millet - * + * The Interface RelationJAXBSchema. */ public interface RelationJAXBSchema { @@ -14,6 +36,9 @@ public interface RelationJAXBSchema { final static String REL_ROOT_ELEM_NAME = "relationtype"; // Need to fix conflict between the Nuxeo XSD and the JAX-B XSD for the "relation" entity + /** The Constant CSID. */ + final static String CSID = "csid"; + /** The Constant DOCUMENT_ID_1. */ final static String DOCUMENT_ID_1 = "documentId1"; @@ -29,11 +54,19 @@ public interface RelationJAXBSchema { /** The Constant RELATIONSHIP_TYPE. */ final static String RELATIONSHIP_TYPE = "relationshipType"; + /* + * Relation Types/Predicates Enumerations + */ + /** The Constant ENUM_RELATIONSHIP_TYPE_ASSOC. */ - final static String ENUM_RELATIONSHIP_TYPE_ASSOC = "association"; + final static String ENUM_REL_TYPE_ASSOC = "association"; /** The Constant ENUM_RELATIONSHIP_TYPE_CONTAINS. */ - final static String ENUM_RELATIONSHIP_TYPE_CONTAINS = "contains"; + final static String ENUM_REL_TYPE_CONTAINS = "contains"; + + /** The Constant ENUM_RELATIONSHIP_TYPE_COLLECTIONOBJECT_INTAKE. */ + final static String ENUM_REL_TYPE_COLLECTIONOBJECT_INTAKE = "collectionobject-intake"; + } diff --git a/services/common/src/main/java/org/collectionspace/services/RelationListItemJAXBSchema.java b/services/common/src/main/java/org/collectionspace/services/RelationListItemJAXBSchema.java index 6212c7cc0..7e500529c 100644 --- a/services/common/src/main/java/org/collectionspace/services/RelationListItemJAXBSchema.java +++ b/services/common/src/main/java/org/collectionspace/services/RelationListItemJAXBSchema.java @@ -1,3 +1,29 @@ +/** + * RelationListItemJAXBSchema.java + * + * {Purpose of This Class} + * + * {Other Notes Relating to This Class (Optional)} + * + * $LastChangedBy: $ + * $LastChangedRevision: $ + * $LastChangedDate: $ + * + * This document is a part of the source code and related artifacts + * for CollectionSpace, an open source collections management system + * for museums and related institutions: + * + * http://www.collectionspace.org + * http://wiki.collectionspace.org + * + * Copyright © 2009 {Contributing Institution} + * + * Licensed under the Educational Community License (ECL), Version 2.0. + * You may not use this file except in compliance with this License. + * + * You may obtain a copy of the ECL 2.0 License at + * https://source.collectionspace.org/collection-space/LICENSE.txt + */ package org.collectionspace.services; /** @@ -5,6 +31,9 @@ package org.collectionspace.services; */ public interface RelationListItemJAXBSchema { + /** The Constant REL_ROOT_ELEM_NAME. */ + final static String REL_ROOT_ELEM_NAME = "relation-list"; + /** The Constant CSID. */ final static String CSID = "csid"; diff --git a/services/common/src/main/java/org/collectionspace/services/common/RelationUtils.java b/services/common/src/main/java/org/collectionspace/services/common/RelationUtils.java index d49babaf0..cc4797ae8 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/RelationUtils.java +++ b/services/common/src/main/java/org/collectionspace/services/common/RelationUtils.java @@ -26,9 +26,74 @@ */ package org.collectionspace.services.common; +import java.io.IOException; +import java.util.List; + +import org.collectionspace.services.common.repository.DocumentException; +import org.collectionspace.services.relation.Relation; +import org.dom4j.Document; + /** * The Interface RelationUtils. */ public interface RelationUtils { -} + /** + * Gets the relationships. + * + * @param repoSession the repo session + * + * @return the relationships + * + * @throws DocumentException the document exception + */ + public List getRelationships(Object repoSession) + throws DocumentException; + + /** + * Gets the relationships for the entity corresponding to the CSID=csid. + * The csid refers to either the subject *OR* the object. + * + * @param nuxeoRepoSession the nuxeo repo session + * @param csid the csid + * + * @return the relationships + * + * @throws DocumentException the document exception + */ + public List getRelationships(Object nuxeoRepoSession, String csid) + throws DocumentException; + + /** + * Gets the relationships. + * + * @param repoSession the repo session + * @param subjectCsid the subject csid + * @param relationType the relation type + * @param objectCsid the object csid + * + * @return the relationships + * + * @throws DocumentException the document exception + */ + public List getRelationships(Object repoSession, + String subjectCsid, + String relationType, + String objectCsid) + throws DocumentException; + + /** + * Creates the relationship. + * + * @param repoSession the repo session + * @param subjectCsid the subject csid + * @param predicate the predicate + * @param objectCsid the object csid + * + * @return the relation + * + * @throws DocumentException the document exception + */ + public Relation createRelationship(Object repoSession, String subjectCsid, + String predicate, String objectCsid) throws DocumentException; +} \ No newline at end of file diff --git a/services/common/src/main/java/org/collectionspace/services/common/RelationsManager.java b/services/common/src/main/java/org/collectionspace/services/common/RelationsManager.java index c381db51e..85135af64 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/RelationsManager.java +++ b/services/common/src/main/java/org/collectionspace/services/common/RelationsManager.java @@ -26,31 +26,101 @@ */ package org.collectionspace.services.common; +import java.io.IOException; +import java.util.List; + +import org.collectionspace.services.common.repository.DocumentException; +import org.collectionspace.services.nuxeo.RelationUtilsNuxeoImpl; +import org.collectionspace.services.relation.Relation; +import org.dom4j.Document; + /** * The Class RelationsManager. + * + * This class loosely uses the RDF terms subject, predicate, object to describe + * relationships between entity objects. For example, if a CollectionObject entity named + * CO#1 is related to a Intake entity named IN#1 then the corresponding + * RDF-like term would be: (Subject) CO#1 (Predicate) has-intake (Object) IN#1. + * + * Many of the methods below, refer to RDF-like terms such as "Subject" and "Object" and + * "Predicate." + * */ public class RelationsManager { - + /** The relation utils. */ - private RelationUtils relationUtils = null; - - // FIXME: Add singleton patter here. + static private RelationUtils relationUtils = new RelationUtilsNuxeoImpl(); + + /** + * Gets the ALL relationships in the system. + * + * @param repoSession + * the repo session + * + * @return the relationships + * + * @throws DocumentException + * the document exception + */ + static public List getRelationships(Object repoSession) + throws DocumentException { + return relationUtils.getRelationships(repoSession); + } + /** - * Sets the utils. + * Gets the relationships. Null values act as wild card and match everything. + * + * @param repoSession the repo session + * @param subjectCsid the subject csid + * @param predicate the predicate + * @param objectCsid the object csid + * + * @return the relationships * - * @param utils the new utils + * @throws DocumentException the document exception */ - public void setUtils(RelationUtils utils) { - relationUtils = utils; + static public List getRelationships(Object repoSession, String subjectCsid, String predicate, String objectCsid) + throws DocumentException { + return relationUtils.getRelationships(repoSession, subjectCsid, predicate, objectCsid); } /** - * Gets the relation utils. + * Gets the relationships for the entity corresponding to the CSID=csid. + * The csid refers to either the subject OR the object + * + * @param repoSession + * the repo session + * @param csid + * the csid + * + * @return the relationships + * + * @throws DocumentException + * the document exception + */ + static public List getRelationships(Object repoSession, + String csid) throws DocumentException { + return relationUtils.getRelationships(repoSession, csid); + } + + /** + * Creates the relationship. + * + * @param repoSession the repo session + * @param subjectCsid the subject csid + * @param predicate the predicate + * @param objectCsid the object csid + * + * @return the relation * - * @return the relation utils + * @throws DocumentException the document exception */ - public RelationUtils getRelationUtils() { - return relationUtils; + static public Relation createRelationship(Object repoSession, + String subjectCsid, + String predicate, + String objectCsid) throws DocumentException { + return relationUtils.createRelationship(repoSession, subjectCsid, + predicate, objectCsid); } } diff --git a/services/common/src/main/java/org/collectionspace/services/nuxeo/CollectionSpaceServiceNuxeoImpl.java b/services/common/src/main/java/org/collectionspace/services/nuxeo/CollectionSpaceServiceNuxeoImpl.java index 89bbd7c55..bcad5ee34 100644 --- a/services/common/src/main/java/org/collectionspace/services/nuxeo/CollectionSpaceServiceNuxeoImpl.java +++ b/services/common/src/main/java/org/collectionspace/services/nuxeo/CollectionSpaceServiceNuxeoImpl.java @@ -6,6 +6,7 @@ package org.collectionspace.services.nuxeo; import java.io.IOException; import org.collectionspace.services.common.ServiceMain; +import org.collectionspace.services.common.repository.DocumentNotFoundException; import org.collectionspace.services.nuxeo.client.rest.NuxeoRESTClient; import org.collectionspace.services.nuxeo.client.java.NuxeoConnector; import org.collectionspace.services.nuxeo.util.NuxeoUtils; @@ -60,16 +61,22 @@ public abstract class CollectionSpaceServiceNuxeoImpl { return nuxeoConnector.getRepositorySession(); } - protected Document deleteDocument(RepositoryInstance repoSession, String csid) throws DocumentException, - IOException { + protected Document deleteDocument(RepositoryInstance repoSession, String csid) + throws DocumentException, IOException { Document result = null; try { repoSession = getRepositorySession(); DocumentRef relDocumentRef = new IdRef(csid); - repoSession.removeDocument(relDocumentRef); - repoSession.save(); - result = new DOMDocument(); // set to non-null to indicate success + + try{ + repoSession.removeDocument(relDocumentRef); + }catch(ClientException ce){ + String msg = "could not find document to delete with id=" + csid; + logger.error(msg, ce); + throw new DocumentNotFoundException(msg, ce); + } + repoSession.save(); } catch (Exception e) { e.printStackTrace(); } @@ -77,7 +84,7 @@ public abstract class CollectionSpaceServiceNuxeoImpl { return result; } - protected Document browseWorkspace(RepositoryInstance repoSession, + protected Document listWorkspaceContent(RepositoryInstance repoSession, String workspaceName) { DOMDocumentFactory domfactory = new DOMDocumentFactory(); diff --git a/services/common/src/main/java/org/collectionspace/services/nuxeo/RelationUtilsNuxeoImpl.java b/services/common/src/main/java/org/collectionspace/services/nuxeo/RelationUtilsNuxeoImpl.java index 2a355df05..b94c549ad 100644 --- a/services/common/src/main/java/org/collectionspace/services/nuxeo/RelationUtilsNuxeoImpl.java +++ b/services/common/src/main/java/org/collectionspace/services/nuxeo/RelationUtilsNuxeoImpl.java @@ -1,3 +1,29 @@ +/** + * RelationUtilsNuxeoImpl.java + * + * {Purpose of This Class} + * + * {Other Notes Relating to This Class (Optional)} + * + * $LastChangedBy: $ + * $LastChangedRevision: $ + * $LastChangedDate: $ + * + * This document is a part of the source code and related artifacts + * for CollectionSpace, an open source collections management system + * for museums and related institutions: + * + * http://www.collectionspace.org + * http://wiki.collectionspace.org + * + * Copyright © 2009 {Contributing Institution} + * + * Licensed under the Educational Community License (ECL), Version 2.0. + * You may not use this file except in compliance with this License. + * + * You may obtain a copy of the ECL 2.0 License at + * https://source.collectionspace.org/collection-space/LICENSE.txt + */ package org.collectionspace.services.nuxeo; import java.io.IOException; @@ -7,13 +33,22 @@ import java.util.List; import java.util.Map; import org.collectionspace.services.RelationJAXBSchema; +import org.collectionspace.services.RelationListItemJAXBSchema; + import org.collectionspace.services.common.RelationUtils; import org.collectionspace.services.relation.Relation; import org.collectionspace.services.relation.RelationshipType; import org.collectionspace.services.nuxeo.util.NuxeoUtils; import org.collectionspace.services.common.repository.DocumentException; +import org.dom4j.Document; +import org.dom4j.Element; +import org.dom4j.dom.DOMElement; +import org.dom4j.dom.DOMDocument; +import org.dom4j.dom.DOMDocumentFactory; //import org.dom4j.DocumentException; + +import org.nuxeo.common.utils.IdUtils; import org.nuxeo.ecm.core.api.ClientException; import org.nuxeo.ecm.core.api.DocumentModel; import org.nuxeo.ecm.core.api.DocumentModelList; @@ -21,25 +56,50 @@ import org.nuxeo.ecm.core.api.model.DocumentPart; import org.nuxeo.ecm.core.api.repository.RepositoryInstance; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +//import org.w3c.dom.DOMException; +//import org.w3c.dom.Element; +/** + * The Class RelationUtilsNuxeoImpl. + */ public class RelationUtilsNuxeoImpl implements RelationUtils { + /** The C s_ relatio n_ servic e_ name. */ static public String CS_RELATION_SERVICE_NAME = "relations"; + static public String CS_EMPTY_STRING = ""; + /** The Constant REL_NUXEO_DOCTYPE. */ final public static String REL_NUXEO_DOCTYPE = "Relation"; + + /** The Constant REL_NUXEO_SCHEMA_NAME. */ final public static String REL_NUXEO_SCHEMA_NAME = "relation"; + + /** The Constant REL_NUXEO_SCHEMA_ROOT_ELEMENT. */ final public static String REL_NUXEO_SCHEMA_ROOT_ELEMENT = "relationtype"; + + /** The Constant REL_NUXEO_DC_TITLE. */ final public static String REL_NUXEO_DC_TITLE = "CollectionSpace-Relation"; + /** The logger. */ private static Logger logger = LoggerFactory .getLogger(RelationUtilsNuxeoImpl.class); + /** + * Fill relation from doc model. + * + * @param relation the relation + * @param relDocModel the rel doc model + * + * @throws ClientException the client exception + */ static public void fillRelationFromDocModel(Relation relation, DocumentModel relDocModel) throws ClientException { String xpathRoot = "/" + REL_NUXEO_SCHEMA_ROOT_ELEMENT + "/"; Object valueObject = null; + relation.setCsid(relDocModel.getId()); + valueObject = relDocModel.getProperty(REL_NUXEO_SCHEMA_NAME, xpathRoot + RelationJAXBSchema.DOCUMENT_ID_1); relation.setDocumentId1((String) valueObject); @@ -68,6 +128,14 @@ public class RelationUtilsNuxeoImpl implements RelationUtils { } } + /** + * Fill doc model from relation. + * + * @param p the p + * @param relDocModel the rel doc model + * + * @throws Exception the exception + */ static public void fillDocModelFromRelation(Relation p, DocumentModel relDocModel) throws Exception { @@ -112,10 +180,22 @@ public class RelationUtilsNuxeoImpl implements RelationUtils { } } + /** + * Prints the document model. + * + * @param documentModel the document model + */ static public void printDocumentModel(DocumentModel documentModel) { System.out.println(documentModel); } + /** + * Describe document model. + * + * @param docModel the doc model + * + * @throws Exception the exception + */ static private void describeDocumentModel(DocumentModel docModel) throws Exception { String[] schemas = docModel.getDeclaredSchemas(); for (int i = 0; schemas != null && i < schemas.length; i++) { @@ -133,22 +213,324 @@ public class RelationUtilsNuxeoImpl implements RelationUtils { } - static public List getRelationships(RepositoryInstance repoSession) - throws DocumentException, IOException, ClientException { - List result = new ArrayList(); + /** + * Creates the relationship. + * + * @param nuxeoRepoSession the nuxeo repo session + * @param newRelation the new relation + * + * @return the document model + * + * @throws DocumentException the document exception + */ + static public DocumentModel createRelationship(Object nuxeoRepoSession, Relation newRelation) + throws DocumentException { + DocumentModel result = null; + RepositoryInstance repoSession = (RepositoryInstance)nuxeoRepoSession; + + try { + // get the Nuxeo 'Relations' workspace + DocumentModel workspaceModel = NuxeoUtils.getWorkspaceModel(repoSession, + CS_RELATION_SERVICE_NAME); + + String docType = REL_NUXEO_DOCTYPE; + String id = IdUtils.generateId("New " + docType); + + //create document model + String workspacePath = workspaceModel.getPathAsString(); + DocumentModel newRelDocModel = repoSession.createDocumentModel(workspacePath, id, docType); + + newRelation.setCsid(newRelDocModel.getId()); + fillDocModelFromRelation(newRelation, newRelDocModel); + + //create document with the new DocumentModel + result = repoSession.createDocument(newRelDocModel); + repoSession.save(); + } catch (Exception e) { + e.printStackTrace(); + throw new DocumentException(e); + } + + return result; + } + + /* (non-Javadoc) + * @see org.collectionspace.services.common.RelationUtils#createRelationship(java.lang.Object, java.lang.String, java.lang.String, java.lang.String) + */ + public Relation createRelationship(Object nuxeoRepoSession, String subjectCsid, String predicate, + String objectCsid) throws DocumentException { + Relation result = null; + RepositoryInstance repoSession = (RepositoryInstance)nuxeoRepoSession; + + Relation temp = new Relation(); + temp.setDocumentId1(subjectCsid); + temp.setRelationshipType(null); + temp.setDocumentId2(objectCsid); + createRelationship(repoSession, temp); + + return result; + } + + /* (non-Javadoc) + * @see org.collectionspace.services.common.RelationUtils#getRelationships(java.lang.Object) + */ + public List getRelationships(Object nuxeoRepoSession) + throws DocumentException { + List result = null; + RepositoryInstance repoSession = (RepositoryInstance)nuxeoRepoSession; + + try { + DocumentModel relationWorkspace = NuxeoUtils.getWorkspaceModel( + repoSession, CS_RELATION_SERVICE_NAME); + DocumentModelList children = repoSession.getChildren(relationWorkspace + .getRef()); + + result = new ArrayList(); + Relation relation = null; + for (DocumentModel child : children) { + relation = new Relation(); + fillRelationFromDocModel(relation, child); + result.add(relation); + } + } catch (Exception e) { + e.printStackTrace(); + throw new DocumentException(e); + } - DocumentModel relationWorkspace = NuxeoUtils.getWorkspaceModel( - repoSession, CS_RELATION_SERVICE_NAME); - DocumentModelList children = repoSession.getChildren(relationWorkspace - .getRef()); - Relation relation = null; - for (DocumentModel child : children) { - relation = new Relation(); - fillRelationFromDocModel(relation, child); - result.add(relation); + return result; + } + + /* (non-Javadoc) + * @see org.collectionspace.services.common.RelationUtils#getRelationships(java.lang.Object, java.lang.String) + */ + public List getRelationships(Object nuxeoRepoSession, String csid) + throws DocumentException { + List result = null; + RepositoryInstance repoSession = (RepositoryInstance)nuxeoRepoSession; + + try { + DocumentModel relationWorkspace = NuxeoUtils.getWorkspaceModel( + repoSession, CS_RELATION_SERVICE_NAME); + DocumentModelList children = repoSession.getChildren(relationWorkspace + .getRef()); + + result = new ArrayList(); + Relation relation = null; + for (DocumentModel child : children) { + if ((isSubjectOfRelation(csid, child) == true) || + (isObjectOfRelation(csid, child) == true)) { + relation = new Relation(); + fillRelationFromDocModel(relation, child); + result.add(relation); + } + } + } catch (Exception e) { + e.printStackTrace(); + throw new DocumentException(e); + } + + return result; + } + + + /* (non-Javadoc) + * @see org.collectionspace.services.common.RelationUtils#getRelationships(java.lang.Object, java.lang.String, java.lang.String, java.lang.String) + */ + public List getRelationships(Object nuxeoRepoSession, + String subjectCsid, + String predicate, + String objectCsid) throws DocumentException { + List result = null; + RepositoryInstance repoSession = (RepositoryInstance)nuxeoRepoSession; + + try { + DocumentModel relationWorkspace = NuxeoUtils.getWorkspaceModel( + repoSession, CS_RELATION_SERVICE_NAME); + DocumentModelList children = repoSession.getChildren(relationWorkspace + .getRef()); + + result = new ArrayList(); + Relation relation = null; + for (DocumentModel child : children) { + if (isQueryMatch(child, subjectCsid, predicate, objectCsid) == true) { + relation = new Relation(); + fillRelationFromDocModel(relation, child); + result.add(relation); } + } + } catch (Exception e) { + e.printStackTrace(); + throw new DocumentException(e); } + + return result; + } + + /** + * Checks if is subject of relation. + * + * @param csid the csid + * @param documentModel the document model + * + * @return true, if is subject of relation + * + * @throws ClientException the client exception + */ + private boolean isSubjectOfRelation(String csid, DocumentModel documentModel) + throws ClientException { + boolean result = false; + String xpathRoot = "/" + REL_NUXEO_SCHEMA_ROOT_ELEMENT + "/"; + Object valueObject = documentModel.getProperty(REL_NUXEO_SCHEMA_NAME, xpathRoot + + RelationJAXBSchema.DOCUMENT_ID_1); + if (valueObject != null && csid != null) { + String subjectID = (String) valueObject; + result = subjectID.equals(csid); + } + return result; } + /** + * Checks if is object of relation. + * + * @param csid the csid + * @param documentModel the document model + * + * @return true, if is object of relation + * + * @throws ClientException the client exception + */ + private boolean isObjectOfRelation(String csid, DocumentModel documentModel) + throws ClientException { + boolean result = false; + String xpathRoot = "/" + REL_NUXEO_SCHEMA_ROOT_ELEMENT + "/"; + + Object valueObject = documentModel.getProperty(REL_NUXEO_SCHEMA_NAME, + xpathRoot + RelationJAXBSchema.DOCUMENT_ID_2); + if (valueObject != null && csid != null) { + String subjectID = (String) valueObject; + result = subjectID.equals(csid); + } + + return result; + } + + private boolean isPredicateOfRelation(String predicate, + DocumentModel documentModel) throws ClientException { + boolean result = false; + String xpathRoot = "/" + REL_NUXEO_SCHEMA_ROOT_ELEMENT + "/"; + + Object valueObject = documentModel.getProperty(REL_NUXEO_SCHEMA_NAME, + xpathRoot + RelationJAXBSchema.RELATIONSHIP_TYPE); + if (valueObject != null && predicate != null) { + String relationType = (String) valueObject; + result = predicate.equalsIgnoreCase(relationType); + } + + return result; + } + + /** + * Gets the object ID from of the (Subject-Predicate-Object) relationship. + * + * @param csid the ID of the 'Subject' (Subject-Predicate-Object) + * @param documentModel represents the relation entry. + * + * @return the object csid of the relationship + * + * @throws ClientException the client exception + */ + private String getObjectFromSubject(String csid, DocumentModel documentModel) + throws ClientException { + String result = null; + String xpathRoot = "/" + REL_NUXEO_SCHEMA_ROOT_ELEMENT + "/"; + + Object valueObject = documentModel.getProperty(REL_NUXEO_SCHEMA_NAME, + xpathRoot + RelationJAXBSchema.DOCUMENT_ID_1); + if (valueObject != null) { + String subjectID = (String) valueObject; + if (subjectID.equals(csid) == true) { + valueObject = documentModel.getProperty(REL_NUXEO_SCHEMA_NAME, + xpathRoot + RelationJAXBSchema.DOCUMENT_ID_2); + if (valueObject != null) { + result = (String) valueObject; + } + } + } + + return result; + } + + static public Document getDocument(List relationList) + throws DocumentException { + DOMDocumentFactory domfactory = new DOMDocumentFactory(); + DOMDocument result = (DOMDocument) domfactory.createDocument(); + + try { + // setup the root element + DOMElement root = (DOMElement) result + .createElement(RelationListItemJAXBSchema.REL_ROOT_ELEM_NAME); + result.setRootElement((org.dom4j.Element) root); + + // populate the document with child elements + for (Relation child : relationList) { + DOMElement el = (DOMElement) result.createElement(RelationJAXBSchema.REL_ROOT_ELEM_NAME); + el.setAttribute(RelationListItemJAXBSchema.CSID, child + .getCsid()); + el.setAttribute(RelationListItemJAXBSchema.URI, getRelURL( + CS_RELATION_SERVICE_NAME, child.getCsid())); + + if (logger.isDebugEnabled() == true) { + System.out.println(el.asXML()); + } + + root.appendChild(el); + } + } catch (Exception e) { + if (logger.isDebugEnabled()) { + logger.debug("Caught exception ", e); + } + throw new DocumentException(e); + } + + if (logger.isDebugEnabled() == true) { + System.out.println(result.asXML()); + } + + return result; + } + + private boolean isQueryMatch(DocumentModel documentModel, + String subjectCsid, + String predicate, + String objectCsid) throws ClientException { + boolean result = true; + + block: { + if (subjectCsid != null) { + if (isSubjectOfRelation(subjectCsid, documentModel) == false) { + result = false; + break block; + } + } + if (predicate != null) { + if (isPredicateOfRelation(predicate, documentModel) == false) { + result = false; + break block; + } + } + if (objectCsid != null) { + if (isObjectOfRelation(objectCsid, documentModel) == false) { + result = false; + break block; + } + } + } + + return result; + } + private static String getRelURL(String repo, String uuid) { + return '/' + repo + '/' + uuid; + } + } diff --git a/services/common/src/main/resources/relation.xsd b/services/common/src/main/resources/relation.xsd index 0aea06634..4c65bc96d 100644 --- a/services/common/src/main/resources/relation.xsd +++ b/services/common/src/main/resources/relation.xsd @@ -42,6 +42,8 @@ + + diff --git a/services/relation/service/src/main/java/org/collectionspace/services/RelationResource.java b/services/relation/service/src/main/java/org/collectionspace/services/RelationResource.java index 0cb9d5408..31ff7b4b4 100644 --- a/services/relation/service/src/main/java/org/collectionspace/services/RelationResource.java +++ b/services/relation/service/src/main/java/org/collectionspace/services/RelationResource.java @@ -49,8 +49,13 @@ import javax.xml.bind.Marshaller; import org.collectionspace.services.RelationService; import org.collectionspace.services.relation.*; import org.collectionspace.services.relation.RelationList.*; + import org.collectionspace.services.RelationJAXBSchema; +import org.collectionspace.services.RelationListItemJAXBSchema; + import org.collectionspace.services.common.ServiceMain; +import org.collectionspace.services.common.repository.DocumentException; +import org.collectionspace.services.common.repository.DocumentNotFoundException; import org.dom4j.Document; import org.dom4j.Element; @@ -67,8 +72,7 @@ import org.slf4j.LoggerFactory; public class RelationResource { /** The logger. */ - final Logger logger = LoggerFactory - .getLogger(RelationResource.class); + final Logger logger = LoggerFactory.getLogger(RelationResource.class); // This should be a DI wired by a container like Spring, Seam, or EJB3 /** The Constant service. */ @@ -82,81 +86,264 @@ public class RelationResource { } /** - * Gets the relation list. + * Returns a list of *all* relation entities. * - * @param ui the ui + * @param ui + * the ui * * @return the relation list */ @GET public RelationList getRelationList(@Context UriInfo ui) { - - URI absoluteURI = ui.getAbsolutePath(); - String uriString = absoluteURI.toString(); - - RelationList p = new RelationList(); - try { - Document document = service.getRelationList(); - Element root = document.getRootElement(); + RelationList relationList = this.getRequestedRelationList(ui, null, + null, null); - // debug - System.err.println(document.asXML()); + return relationList; + } - List list = p - .getRelationListItem(); - for (Iterator i = root.elementIterator(); i.hasNext();) { - Element element = (Element) i.next(); - // debug - System.err.println(); - element.asXML(); + /** + * Gets a list of relations with the subject= + * + * @param ui + * the ui + * @param subjectCsid + * the subject == subjectCsid + * + * @return the relation list_ s + */ + @GET + @Path("subject/{subjectCsid}") + public RelationList getRelationList_S(@Context UriInfo ui, + @PathParam("subjectCsid") String subjectCsid) { + RelationList relationList = this.getRequestedRelationList(ui, + subjectCsid, null, null); - // set the Relation list item entity elements - RelationListItem pli = new RelationListItem(); - pli.setUri(element.attributeValue("url")); - pli.setCsid(element.attributeValue("id")); - list.add(pli); - } + return relationList; + } - } catch (Exception e) { - e.printStackTrace(); - } + /** + * Gets a list of relations with predicate == predicate. + * + * @param ui + * the ui + * @param predicate + * the predicate + * + * @return the relation list of type + */ + @GET + @Path("type/{predicate}") + public RelationList getRelationList_P(@Context UriInfo ui, + @PathParam("predicate") String predicate) { + RelationList relationList = this.getRequestedRelationList(ui, null, + predicate, null); + + return relationList; + } - return p; + /** + * Gets a list of relations with object == objectCsid + * + * @param ui + * the ui + * @param objectCsid + * the object csid + * + * @return the relation list_ o + */ + @GET + @Path("object/{objectCsid}") + public RelationList getRelationList_O(@Context UriInfo ui, + @PathParam("objectCsid") String objectCsid) { + RelationList relationList = this.getRequestedRelationList(ui, null, + null, objectCsid); + + return relationList; + } + + /** + * Gets a list of relations with predicate == predicate *and* subject == + * subjectCsid + * + * @param ui + * the ui + * @param predicate + * the predicate + * @param subjectCsid + * the subject subjectCsid + * + * @return the relation list of type with subject + */ + @GET + @Path("type/{predicate}/subject/{subjectCsid}") + public RelationList getRelationList_PS(@Context UriInfo ui, + @PathParam("predicate") String predicate, + @PathParam("subjectCsid") String subjectCsid) { + RelationList relationList = this.getRequestedRelationList(ui, + subjectCsid, predicate, null); + + return relationList; + } + + /** + * Gets a list of relations with subject == subjectCsid *and* predicate == + * predicate + * + * @param ui + * the ui + * @param subjectCsid + * the subject csid + * @param predicate + * the predicate + * + * @return the relation list_ sp + */ + @GET + @Path("subject/{subjectCsid}/type/{predicate}") + public RelationList getRelationList_SP(@Context UriInfo ui, + @PathParam("subjectCsid") String subjectCsid, + @PathParam("predicate") String predicate) { + RelationList relationList = this.getRequestedRelationList(ui, + subjectCsid, predicate, null); + + return relationList; + } + + /** + * Gets a list of relations with predicate == predicate *and* object == + * objectCsid + * + * @param ui + * the ui + * @param predicate + * the predicate + * @param objectCsid + * the object csid + * + * @return the relation list of type with object + */ + @GET + @Path("type/{predicate}/object/{objectCsid}") + public RelationList getRelationList_PO(@Context UriInfo ui, + @PathParam("predicate") String predicate, + @PathParam("objectCsid") String objectCsid) { + RelationList relationList = this.getRequestedRelationList(ui, null, + predicate, objectCsid); + + return relationList; + } + + /** + * Gets a list of relations with object == objectCsid *and* predicate == + * predicate + * + * @param ui + * the ui + * @param objectCsid + * the object csid + * @param predicate + * the predicate + * + * @return the relation list_ op + */ + @GET + @Path("object/{objectCsid}/type/{predicate}") + public RelationList getRelationList_OP(@Context UriInfo ui, + @PathParam("objectCsid") String objectCsid, + @PathParam("predicate") String predicate) { + RelationList relationList = this.getRequestedRelationList(ui, null, + predicate, objectCsid); + + return relationList; + } + + /** + * Gets a list of relations with predicate == predicate *and* subject == + * subjectCsid *and* object == objectCsid + * + * @param ui + * the ui + * @param predicate + * the predicate + * @param subjectCsid + * the subject csid + * @param objectCsid + * the object csid + * + * @return the relation list + */ + @GET + @Path("type/{predicate}/subject/{subjectCsid}/object/{objectCsid}") + public RelationList getRelationList_PSO(@Context UriInfo ui, + @PathParam("predicate") String predicate, + @PathParam("subjectCsid") String subjectCsid, + @PathParam("objectCsid") String objectCsid) { + RelationList relationList = this.getRequestedRelationList(ui, + predicate, subjectCsid, objectCsid); + + return relationList; + } + + /** + * Gets a list of relations with subject == subjectCsid *and* predicate == + * predicate *and* object == objectCsid + * + * @param ui + * the ui + * @param subjectCsid + * the subject csid + * @param predicate + * the predicate + * @param objectCsid + * the object csid + * + * @return the relation list_ spo + */ + @GET + @Path("subject/{subjectCsid}/type/{predicate}/object/{objectCsid}") + public RelationList getRelationList_SPO(@Context UriInfo ui, + @PathParam("subjectCsid") String subjectCsid, + @PathParam("predicate") String predicate, + @PathParam("objectCsid") String objectCsid) { + RelationList relationList = this.getRequestedRelationList(ui, + subjectCsid, predicate, objectCsid); + + return relationList; } /** * Creates the relation. * - * @param ui the ui - * @param co the co + * @param ui + * the ui + * @param co + * the co * * @return the response */ @POST public Response createRelation(@Context UriInfo ui, Relation co) { String csid = null; - + try { Document document = service.postRelation(co); Element root = document.getRootElement(); csid = root.attributeValue("id"); co.setCsid(csid); } catch (Exception e) { - Response response = Response.status(Response.Status.NOT_FOUND) - .entity("Create failed").type("text/plain").build(); + if (logger.isDebugEnabled()) { + logger.debug("Caught exception in createRelation", e); + } + Response response = Response.status( + Response.Status.INTERNAL_SERVER_ERROR).entity( + "Index failed").type("text/plain").build(); throw new WebApplicationException(response); } - //debug - verbose("createRelation: ", co); - UriBuilder uriBuilder = ui.getAbsolutePathBuilder(); uriBuilder.path(csid); URI uri = uriBuilder.build(); - - //debug - System.out.println(uri.toString()); - + Response response = Response.created(uri).build(); return response; } @@ -164,7 +351,8 @@ public class RelationResource { /** * Gets the relation. * - * @param csid the csid + * @param csid + * the csid * * @return the relation */ @@ -193,8 +381,9 @@ public class RelationResource { Iterator relIter = schemaElement .elementIterator(RelationJAXBSchema.REL_ROOT_ELEM_NAME); Iterator relIter2 = schemaElement - .elementIterator("rel:" + RelationJAXBSchema.REL_ROOT_ELEM_NAME); - + .elementIterator("rel:" + + RelationJAXBSchema.REL_ROOT_ELEM_NAME); + while (relIter.hasNext()) { Element relElement = relIter.next(); @@ -229,10 +418,12 @@ public class RelationResource { } } } catch (Exception e) { - e.printStackTrace(); + if (logger.isDebugEnabled()) { + logger.debug("Caught exception in getRelation", e); + } Response response = Response.status( - Response.Status.INTERNAL_SERVER_ERROR).entity("Get failed") - .type("text/plain").build(); + Response.Status.INTERNAL_SERVER_ERROR).entity( + "Index failed").type("text/plain").build(); throw new WebApplicationException(response); } if (co == null) { @@ -243,7 +434,10 @@ public class RelationResource { .build(); throw new WebApplicationException(response); } - verbose("getRelation: ", co); + + if (logger.isDebugEnabled() == true) { + verbose("getRelation: ", co); + } return co; } @@ -251,17 +445,21 @@ public class RelationResource { /** * Update relation. * - * @param csid the csid - * @param theUpdate the the update + * @param csid + * the csid + * @param theUpdate + * the the update * * @return the relation */ @PUT @Path("{csid}") - public Relation updateRelation( - @PathParam("csid") String csid, Relation theUpdate) { + public Relation updateRelation(@PathParam("csid") String csid, + Relation theUpdate) { - verbose("updateRelation with input: ", theUpdate); + if (logger.isDebugEnabled() == true) { + verbose("updateRelation with input: ", theUpdate); + } String status = null; try { @@ -276,9 +474,12 @@ public class RelationResource { } } } catch (Exception e) { - // FIXME: NOT_FOUND? - Response response = Response.status(Response.Status.NOT_FOUND) - .entity("Update failed ").type("text/plain").build(); + if (logger.isDebugEnabled()) { + logger.debug("Caught exception in updateRelation", e); + } + Response response = Response.status( + Response.Status.INTERNAL_SERVER_ERROR).entity( + "Index failed").type("text/plain").build(); throw new WebApplicationException(response); } @@ -288,7 +489,8 @@ public class RelationResource { /** * Delete relation. * - * @param csid the csid + * @param csid + * the csid */ @DELETE @Path("{csid}") @@ -296,30 +498,133 @@ public class RelationResource { verbose("deleteRelation with csid=" + csid); try { - - Document document = service.deleteRelation(csid); + service.deleteRelation(csid); + } catch (DocumentNotFoundException dnfe) { + if (logger.isDebugEnabled()) { + logger.debug("caught exception in deleteRelation", dnfe); + } + Response response = Response.status(Response.Status.NOT_FOUND) + .entity("Delete failed on Relation csid=" + csid) + .type("text/plain").build(); + throw new WebApplicationException(response); + } catch (Exception e) { + if (logger.isDebugEnabled()) { + logger.debug("Caught exception in deleteRelation", e); + } + Response response = Response.status( + Response.Status.INTERNAL_SERVER_ERROR).entity( + "Index failed").type("text/plain").build(); + throw new WebApplicationException(response); + } + } + + /* + * Private Methods + */ + + /** + * Gets the relation list common. + * + * @param ui + * the ui + * @param subjectCsid + * the subject csid + * @param predicate + * the predicate + * @param objectCsid + * the object csid + * + * @return the relation list common + * + * @throws WebApplicationException + * the web application exception + */ + private RelationList getRequestedRelationList(@Context UriInfo ui, + String subjectCsid, String predicate, String objectCsid) + throws WebApplicationException { + + URI absoluteURI = ui.getAbsolutePath(); + String uriString = absoluteURI.toString(); + + RelationList relationList = null; + try { + relationList = this.getRelationList(subjectCsid, predicate, + objectCsid); + } catch (Exception e) { + if (logger.isDebugEnabled()) { + logger.debug("Caught exception in getRelationList", e); + } + Response response = Response.status( + Response.Status.INTERNAL_SERVER_ERROR).entity( + "Index failed").type("text/plain").build(); + throw new WebApplicationException(response); + } + + return relationList; + } + + /** + * Gets the relation list. + * + * @param subjectCsid + * the subject csid + * @param predicate + * the predicate + * @param objectCsid + * the object csid + * + * @return the relation list + * + * @throws DocumentException + * the document exception + */ + private RelationList getRelationList(String subjectCsid, String predicate, + String objectCsid) throws DocumentException { + RelationList relationList = new RelationList(); + try { + Document document = service.getRelationList(subjectCsid, predicate, + objectCsid); + if (logger.isDebugEnabled() == true) { + System.err.println(document.asXML()); + } + Element root = document.getRootElement(); + List list = relationList + .getRelationListItem(); + Element node = null; for (Iterator i = root.elementIterator(); i.hasNext();) { - Element element = (Element) i.next(); - if ("docRef".equals(element.getName())) { - String status = (String) element.getData(); - verbose("deleteRelationt response: " + status); + node = (Element) i.next(); + if (logger.isDebugEnabled() == true) { + System.out.println(); + node.asXML(); } + + // set the Relation list item entity elements + RelationListItem listItem = new RelationListItem(); + listItem.setUri(node + .attributeValue(RelationListItemJAXBSchema.URI)); + listItem.setCsid(node + .attributeValue(RelationListItemJAXBSchema.CSID)); + list.add(listItem); } + } catch (Exception e) { - // FIXME: NOT_FOUND? - Response response = Response.status(Response.Status.NOT_FOUND) - .entity("Delete failed ").type("text/plain").build(); - throw new WebApplicationException(response); + if (logger.isDebugEnabled()) { + logger.debug("Caught exception in getRelationListOfType", e); + } + throw new DocumentException(e); } + return relationList; } - + /** * Verbose. * - * @param msg the msg - * @param co the co + * @param msg + * the msg + * @param co + * the co */ private void verbose(String msg, Relation co) { try { @@ -331,13 +636,14 @@ public class RelationResource { m.marshal(co, System.out); } catch (Exception e) { e.printStackTrace(); - } + } } /** * Verbose. * - * @param msg the msg + * @param msg + * the msg */ private void verbose(String msg) { System.out.println("RelationResource. " + msg); diff --git a/services/relation/service/src/main/java/org/collectionspace/services/RelationService.java b/services/relation/service/src/main/java/org/collectionspace/services/RelationService.java index f9f857b56..1b7d98913 100644 --- a/services/relation/service/src/main/java/org/collectionspace/services/RelationService.java +++ b/services/relation/service/src/main/java/org/collectionspace/services/RelationService.java @@ -28,7 +28,9 @@ package org.collectionspace.services; import java.io.IOException; import org.dom4j.Document; -import org.dom4j.DocumentException; +//import org.dom4j.DocumentException; +import org.collectionspace.services.common.repository.DocumentException; + import org.collectionspace.services.relation.Relation; @@ -79,6 +81,22 @@ public interface RelationService { * @throws IOException Signals that an I/O exception has occurred. */ Document getRelationList() throws DocumentException, IOException; + + /** + * Gets the relation list of type. + * + * @param subjectCsid the subject csid + * @param predicate the predicate + * @param objectCsid the object csid + * + * @return the relation list of type + * + * @throws DocumentException the document exception + * @throws IOException Signals that an I/O exception has occurred. + */ + Document getRelationList(String subjectCsid, + String predicate, String objectCsid) + throws DocumentException, IOException; // Update /** diff --git a/services/relation/service/src/main/java/org/collectionspace/services/RelationServiceNuxeoImpl.java b/services/relation/service/src/main/java/org/collectionspace/services/RelationServiceNuxeoImpl.java index 95821949e..1b729f3ef 100644 --- a/services/relation/service/src/main/java/org/collectionspace/services/RelationServiceNuxeoImpl.java +++ b/services/relation/service/src/main/java/org/collectionspace/services/RelationServiceNuxeoImpl.java @@ -32,10 +32,11 @@ import java.io.IOException; //import java.util.ArrayList; //import java.util.Arrays; //import java.util.HashMap; -//import java.util.List; +import java.util.List; //import java.util.Map; //import java.util.Iterator; +import org.collectionspace.services.common.repository.DocumentException; //import org.collectionspace.services.nuxeo.NuxeoRESTClient; import org.collectionspace.services.nuxeo.CollectionSpaceServiceNuxeoImpl; import org.collectionspace.services.nuxeo.RelationUtilsNuxeoImpl; @@ -44,12 +45,13 @@ import org.collectionspace.services.relation.Relation; //import org.collectionspace.services.relation.RelationshipType; //import org.collectionspace.services.RelationJAXBSchema; import org.collectionspace.services.nuxeo.util.NuxeoUtils; +import org.collectionspace.services.common.RelationsManager; //import org.collectionspace.services.common.ServiceMain; import org.dom4j.Document; //import org.dom4j.Element; //import org.dom4j.dom.DOMDocument; -import org.dom4j.DocumentException; +//import org.dom4j.DocumentException; //import org.dom4j.io.SAXReader; //import org.restlet.resource.Representation; @@ -84,21 +86,23 @@ public class RelationServiceNuxeoImpl extends * @throws DocumentException the document exception * @throws IOException Signals that an I/O exception has occurred. */ - public Document deleteRelation(String csid) - throws DocumentException, IOException { + public Document deleteRelation(String csid) throws DocumentException { Document result = null; - - RepositoryInstance repoSession = null; - try { - repoSession = getRepositorySession(); - result = deleteDocument(repoSession, csid); - } catch (Exception e) { - e.printStackTrace(); - } finally { - if(repoSession != null) { - releaseRepositorySession(repoSession); - } - } + + RepositoryInstance repoSession = null; + try { + repoSession = getRepositorySession(); + result = deleteDocument(repoSession, csid); + } catch (Exception e) { + if (logger.isDebugEnabled()) { + logger.debug("Caught exception ", e); + } + throw new DocumentException(e); + } finally { + if (repoSession != null) { + releaseRepositorySession(repoSession); + } + } return result; } @@ -122,7 +126,10 @@ public class RelationServiceNuxeoImpl extends repoSession = getRepositorySession(); result = NuxeoUtils.getDocument(repoSession, csid); } catch (Exception e) { - e.printStackTrace(); + if (logger.isDebugEnabled()) { + logger.debug("Caught exception ", e); + } + throw new DocumentException(e); } finally { if (repoSession != null) { releaseRepositorySession(repoSession); @@ -145,17 +152,21 @@ public class RelationServiceNuxeoImpl extends * @throws DocumentException the document exception * @throws IOException Signals that an I/O exception has occurred. */ - public Document getRelationList() throws DocumentException, IOException { + public Document getRelationList() + throws DocumentException, IOException { Document result = null; RepositoryInstance repoSession = null; try { repoSession = getRepositorySession(); - RelationUtilsNuxeoImpl.getRelationships(repoSession); + List relationList = RelationsManager.getRelationships(repoSession); - result = this.browseWorkspace(repoSession, RelationUtilsNuxeoImpl.CS_RELATION_SERVICE_NAME); + result = RelationUtilsNuxeoImpl.getDocument(relationList); } catch (Exception e) { - e.printStackTrace(); + if (logger.isDebugEnabled()) { + logger.debug("Caught exception ", e); + } + throw new DocumentException(e); } finally { if (repoSession != null) { releaseRepositorySession(repoSession); @@ -168,6 +179,39 @@ public class RelationServiceNuxeoImpl extends return result; } + + /* (non-Javadoc) + * @see org.collectionspace.services.RelationService#getRelationList(java.lang.String, java.lang.String, java.lang.String) + */ + public Document getRelationList(String subjectCsid, + String predicate, String objectCsid) + throws DocumentException, IOException { + Document result = null; + RepositoryInstance repoSession = null; + + try { + repoSession = getRepositorySession(); + List relationList = RelationsManager.getRelationships(repoSession, + subjectCsid, predicate, objectCsid); + + result = RelationUtilsNuxeoImpl.getDocument(relationList); + } catch (Exception e) { + if (logger.isDebugEnabled()) { + logger.debug("Caught exception ", e); + } + throw new DocumentException(e); + } finally { + if (repoSession != null) { + releaseRepositorySession(repoSession); + } + } + + if (logger.isDebugEnabled() == true) { + System.out.println(result.asXML()); + } + + return result; + } // Create a new relation document /** @@ -187,32 +231,14 @@ public class RelationServiceNuxeoImpl extends try { repoSession = getRepositorySession(); - - // get the Nuxeo 'Relations' workspace - DocumentModel workspaceModel = NuxeoUtils.getWorkspaceModel(repoSession, - RelationUtilsNuxeoImpl.CS_RELATION_SERVICE_NAME); - - String docType = RelationUtilsNuxeoImpl.REL_NUXEO_DOCTYPE; - String id = IdUtils.generateId("New " + docType); - - //create document model - String workspacePath = workspaceModel.getPathAsString(); - DocumentModel newRelDocModel = repoSession.createDocumentModel(workspacePath, id, docType); - - //debug - if (logger.isDebugEnabled() == true) { - RelationUtilsNuxeoImpl.printDocumentModel(newRelDocModel); - } - RelationUtilsNuxeoImpl.fillDocModelFromRelation(co, newRelDocModel); - - //create document with the new DocumentModel - DocumentModel resultDocModel = repoSession.createDocument(newRelDocModel); + DocumentModel resultDocModel = RelationUtilsNuxeoImpl.createRelationship(repoSession, co); repoSession.save(); - result = NuxeoUtils.getDocument(repoSession, resultDocModel); - } catch (Exception e) { - e.printStackTrace(); + if (logger.isDebugEnabled() == true) { + logger.debug("Caught exception ", e); + } + throw new DocumentException(e); } finally { if (repoSession != null) { releaseRepositorySession(repoSession); @@ -252,7 +278,10 @@ public class RelationServiceNuxeoImpl extends repoSession.save(); result = NuxeoUtils.getDocument(repoSession, documentModel); } catch(Exception e){ - e.printStackTrace(); + if (logger.isDebugEnabled()) { + logger.debug("Caught exception ", e); + } + throw new DocumentException(e); } finally{ if(repoSession != null){ releaseRepositorySession(repoSession);