<port>8180</port>\r
</configuration>\r
<executions>\r
- <execution>\r
+<!-- <execution>\r
<id>jboss-undeploy</id>\r
<goals>\r
<goal>undeploy</goal>\r
<param>${project.build.directory}/${project.build.finalName}.war</param>\r
</fileNames>\r
</configuration>\r
- </execution>\r
+ </execution> -->\r
</executions>\r
</plugin>\r
\r
-/**\r
- * \r
+/** \r
+ * RelationJAXBSchema.java\r
+ *\r
+ * {Purpose of This Class}\r
+ *\r
+ * {Other Notes Relating to This Class (Optional)}\r
+ *\r
+ * $LastChangedBy: $\r
+ * $LastChangedRevision: $\r
+ * $LastChangedDate: $\r
+ *\r
+ * This document is a part of the source code and related artifacts\r
+ * for CollectionSpace, an open source collections management system\r
+ * for museums and related institutions:\r
+ *\r
+ * http://www.collectionspace.org\r
+ * http://wiki.collectionspace.org\r
+ *\r
+ * Copyright © 2009 {Contributing Institution}\r
+ *\r
+ * Licensed under the Educational Community License (ECL), Version 2.0.\r
+ * You may not use this file except in compliance with this License.\r
+ *\r
+ * You may obtain a copy of the ECL 2.0 License at\r
+ * https://source.collectionspace.org/collection-space/LICENSE.txt\r
*/\r
package org.collectionspace.services;\r
\r
/**\r
- * @author Richard Millet\r
- *\r
+ * The Interface RelationJAXBSchema.\r
*/\r
public interface RelationJAXBSchema {\r
\r
final static String REL_ROOT_ELEM_NAME = "relationtype";\r
// Need to fix conflict between the Nuxeo XSD and the JAX-B XSD for the "relation" entity\r
\r
+ /** The Constant CSID. */\r
+ final static String CSID = "csid";\r
+ \r
/** The Constant DOCUMENT_ID_1. */\r
final static String DOCUMENT_ID_1 = "documentId1";\r
\r
/** The Constant RELATIONSHIP_TYPE. */\r
final static String RELATIONSHIP_TYPE = "relationshipType";\r
\r
+ /*\r
+ * Relation Types/Predicates Enumerations\r
+ */\r
+ \r
/** The Constant ENUM_RELATIONSHIP_TYPE_ASSOC. */\r
- final static String ENUM_RELATIONSHIP_TYPE_ASSOC = "association";\r
+ final static String ENUM_REL_TYPE_ASSOC = "association";\r
\r
/** The Constant ENUM_RELATIONSHIP_TYPE_CONTAINS. */\r
- final static String ENUM_RELATIONSHIP_TYPE_CONTAINS = "contains";\r
+ final static String ENUM_REL_TYPE_CONTAINS = "contains";\r
+ \r
+ /** The Constant ENUM_RELATIONSHIP_TYPE_COLLECTIONOBJECT_INTAKE. */\r
+ final static String ENUM_REL_TYPE_COLLECTIONOBJECT_INTAKE = "collectionobject-intake";\r
+ \r
}\r
\r
\r
+/** \r
+ * RelationListItemJAXBSchema.java\r
+ *\r
+ * {Purpose of This Class}\r
+ *\r
+ * {Other Notes Relating to This Class (Optional)}\r
+ *\r
+ * $LastChangedBy: $\r
+ * $LastChangedRevision: $\r
+ * $LastChangedDate: $\r
+ *\r
+ * This document is a part of the source code and related artifacts\r
+ * for CollectionSpace, an open source collections management system\r
+ * for museums and related institutions:\r
+ *\r
+ * http://www.collectionspace.org\r
+ * http://wiki.collectionspace.org\r
+ *\r
+ * Copyright © 2009 {Contributing Institution}\r
+ *\r
+ * Licensed under the Educational Community License (ECL), Version 2.0.\r
+ * You may not use this file except in compliance with this License.\r
+ *\r
+ * You may obtain a copy of the ECL 2.0 License at\r
+ * https://source.collectionspace.org/collection-space/LICENSE.txt\r
+ */\r
package org.collectionspace.services;\r
\r
/**\r
*/\r
public interface RelationListItemJAXBSchema {\r
\r
+ /** The Constant REL_ROOT_ELEM_NAME. */\r
+ final static String REL_ROOT_ELEM_NAME = "relation-list";\r
+ \r
/** The Constant CSID. */\r
final static String CSID = "csid";\r
\r
*/\r
package org.collectionspace.services.common;\r
\r
+import java.io.IOException;\r
+import java.util.List;\r
+\r
+import org.collectionspace.services.common.repository.DocumentException;\r
+import org.collectionspace.services.relation.Relation;\r
+import org.dom4j.Document;\r
+\r
/**\r
* The Interface RelationUtils.\r
*/\r
public interface RelationUtils {\r
\r
-}\r
+ /**\r
+ * Gets the relationships.\r
+ * \r
+ * @param repoSession the repo session\r
+ * \r
+ * @return the relationships\r
+ * \r
+ * @throws DocumentException the document exception\r
+ */\r
+ public List<Relation> getRelationships(Object repoSession)\r
+ throws DocumentException;\r
+\r
+ /**\r
+ * Gets the relationships for the entity corresponding to the CSID=csid.\r
+ * The csid refers to either the subject *OR* the object.\r
+ * \r
+ * @param nuxeoRepoSession the nuxeo repo session\r
+ * @param csid the csid\r
+ * \r
+ * @return the relationships\r
+ * \r
+ * @throws DocumentException the document exception\r
+ */\r
+ public List<Relation> getRelationships(Object nuxeoRepoSession, String csid)\r
+ throws DocumentException;\r
+ \r
+ /**\r
+ * Gets the relationships.\r
+ * \r
+ * @param repoSession the repo session\r
+ * @param subjectCsid the subject csid\r
+ * @param relationType the relation type\r
+ * @param objectCsid the object csid\r
+ * \r
+ * @return the relationships\r
+ * \r
+ * @throws DocumentException the document exception\r
+ */\r
+ public List<Relation> getRelationships(Object repoSession,\r
+ String subjectCsid, \r
+ String relationType, \r
+ String objectCsid)\r
+ throws DocumentException;\r
+\r
+ /**\r
+ * Creates the relationship.\r
+ * \r
+ * @param repoSession the repo session\r
+ * @param subjectCsid the subject csid\r
+ * @param predicate the predicate\r
+ * @param objectCsid the object csid\r
+ * \r
+ * @return the relation\r
+ * \r
+ * @throws DocumentException the document exception\r
+ */\r
+ public Relation createRelationship(Object repoSession, String subjectCsid,\r
+ String predicate, String objectCsid) throws DocumentException;\r
+}
\ No newline at end of file
*/\r
package org.collectionspace.services.common;\r
\r
+import java.io.IOException;\r
+import java.util.List;\r
+\r
+import org.collectionspace.services.common.repository.DocumentException;\r
+import org.collectionspace.services.nuxeo.RelationUtilsNuxeoImpl;\r
+import org.collectionspace.services.relation.Relation;\r
+import org.dom4j.Document;\r
+\r
/**\r
* The Class RelationsManager.\r
+ * \r
+ * This class loosely uses the RDF terms subject, predicate, object to describe\r
+ * relationships between entity objects. For example, if a CollectionObject entity named\r
+ * CO#1 is related to a Intake entity named IN#1 then the corresponding\r
+ * RDF-like term would be: (Subject) CO#1 (Predicate) has-intake (Object) IN#1.\r
+ * \r
+ * Many of the methods below, refer to RDF-like terms such as "Subject" and "Object" and\r
+ * "Predicate."\r
+ * \r
*/\r
public class RelationsManager {\r
- \r
+\r
/** The relation utils. */\r
- private RelationUtils relationUtils = null;\r
- \r
- // FIXME: Add singleton patter here.\r
+ static private RelationUtils relationUtils = new RelationUtilsNuxeoImpl();\r
+\r
+ /**\r
+ * Gets the ALL relationships in the system.\r
+ * \r
+ * @param repoSession\r
+ * the repo session\r
+ * \r
+ * @return the relationships\r
+ * \r
+ * @throws DocumentException\r
+ * the document exception\r
+ */\r
+ static public List<Relation> getRelationships(Object repoSession)\r
+ throws DocumentException {\r
+ return relationUtils.getRelationships(repoSession);\r
+ }\r
+ \r
/**\r
- * Sets the utils.\r
+ * Gets the relationships. Null values act as wild card and match everything.\r
+ * \r
+ * @param repoSession the repo session\r
+ * @param subjectCsid the subject csid\r
+ * @param predicate the predicate\r
+ * @param objectCsid the object csid\r
+ * \r
+ * @return the relationships\r
* \r
- * @param utils the new utils\r
+ * @throws DocumentException the document exception\r
*/\r
- public void setUtils(RelationUtils utils) {\r
- relationUtils = utils;\r
+ static public List<Relation> getRelationships(Object repoSession, String subjectCsid, String predicate, String objectCsid)\r
+ throws DocumentException {\r
+ return relationUtils.getRelationships(repoSession, subjectCsid, predicate, objectCsid);\r
}\r
\r
/**\r
- * Gets the relation utils.\r
+ * Gets the relationships for the entity corresponding to the CSID=csid.\r
+ * The csid refers to either the subject OR the object\r
+ * \r
+ * @param repoSession\r
+ * the repo session\r
+ * @param csid\r
+ * the csid\r
+ * \r
+ * @return the relationships\r
+ * \r
+ * @throws DocumentException\r
+ * the document exception\r
+ */\r
+ static public List<Relation> getRelationships(Object repoSession,\r
+ String csid) throws DocumentException {\r
+ return relationUtils.getRelationships(repoSession, csid);\r
+ }\r
+ \r
+ /**\r
+ * Creates the relationship.\r
+ * \r
+ * @param repoSession the repo session\r
+ * @param subjectCsid the subject csid\r
+ * @param predicate the predicate\r
+ * @param objectCsid the object csid\r
+ * \r
+ * @return the relation\r
* \r
- * @return the relation utils\r
+ * @throws DocumentException the document exception\r
*/\r
- public RelationUtils getRelationUtils() {\r
- return relationUtils;\r
+ static public Relation createRelationship(Object repoSession,\r
+ String subjectCsid,\r
+ String predicate,\r
+ String objectCsid) throws DocumentException {\r
+ return relationUtils.createRelationship(repoSession, subjectCsid,\r
+ predicate, objectCsid);\r
}\r
\r
}\r
import java.io.IOException;\r
\r
import org.collectionspace.services.common.ServiceMain;\r
+import org.collectionspace.services.common.repository.DocumentNotFoundException;\r
import org.collectionspace.services.nuxeo.client.rest.NuxeoRESTClient;\r
import org.collectionspace.services.nuxeo.client.java.NuxeoConnector;\r
import org.collectionspace.services.nuxeo.util.NuxeoUtils;\r
return nuxeoConnector.getRepositorySession();\r
}\r
\r
- protected Document deleteDocument(RepositoryInstance repoSession, String csid) throws DocumentException,\r
- IOException {\r
+ protected Document deleteDocument(RepositoryInstance repoSession, String csid)\r
+ throws DocumentException, IOException {\r
Document result = null;\r
\r
try {\r
repoSession = getRepositorySession();\r
DocumentRef relDocumentRef = new IdRef(csid);\r
- repoSession.removeDocument(relDocumentRef);\r
- repoSession.save();\r
- result = new DOMDocument(); // set to non-null to indicate success\r
+ \r
+ try{\r
+ repoSession.removeDocument(relDocumentRef);\r
+ }catch(ClientException ce){\r
+ String msg = "could not find document to delete with id=" + csid;\r
+ logger.error(msg, ce);\r
+ throw new DocumentNotFoundException(msg, ce);\r
+ }\r
+ repoSession.save(); \r
} catch (Exception e) {\r
e.printStackTrace();\r
}\r
return result;\r
}\r
\r
- protected Document browseWorkspace(RepositoryInstance repoSession,\r
+ protected Document listWorkspaceContent(RepositoryInstance repoSession,\r
String workspaceName) {\r
\r
DOMDocumentFactory domfactory = new DOMDocumentFactory();\r
+/** \r
+ * RelationUtilsNuxeoImpl.java\r
+ *\r
+ * {Purpose of This Class}\r
+ *\r
+ * {Other Notes Relating to This Class (Optional)}\r
+ *\r
+ * $LastChangedBy: $\r
+ * $LastChangedRevision: $\r
+ * $LastChangedDate: $\r
+ *\r
+ * This document is a part of the source code and related artifacts\r
+ * for CollectionSpace, an open source collections management system\r
+ * for museums and related institutions:\r
+ *\r
+ * http://www.collectionspace.org\r
+ * http://wiki.collectionspace.org\r
+ *\r
+ * Copyright © 2009 {Contributing Institution}\r
+ *\r
+ * Licensed under the Educational Community License (ECL), Version 2.0.\r
+ * You may not use this file except in compliance with this License.\r
+ *\r
+ * You may obtain a copy of the ECL 2.0 License at\r
+ * https://source.collectionspace.org/collection-space/LICENSE.txt\r
+ */\r
package org.collectionspace.services.nuxeo;\r
\r
import java.io.IOException;\r
import java.util.Map;\r
\r
import org.collectionspace.services.RelationJAXBSchema;\r
+import org.collectionspace.services.RelationListItemJAXBSchema;\r
+\r
import org.collectionspace.services.common.RelationUtils;\r
import org.collectionspace.services.relation.Relation;\r
import org.collectionspace.services.relation.RelationshipType;\r
import org.collectionspace.services.nuxeo.util.NuxeoUtils;\r
import org.collectionspace.services.common.repository.DocumentException;\r
\r
+import org.dom4j.Document;\r
+import org.dom4j.Element;\r
+import org.dom4j.dom.DOMElement;\r
+import org.dom4j.dom.DOMDocument;\r
+import org.dom4j.dom.DOMDocumentFactory;\r
//import org.dom4j.DocumentException;\r
+\r
+import org.nuxeo.common.utils.IdUtils;\r
import org.nuxeo.ecm.core.api.ClientException;\r
import org.nuxeo.ecm.core.api.DocumentModel;\r
import org.nuxeo.ecm.core.api.DocumentModelList;\r
import org.nuxeo.ecm.core.api.repository.RepositoryInstance;\r
import org.slf4j.Logger;\r
import org.slf4j.LoggerFactory;\r
+//import org.w3c.dom.DOMException;\r
+//import org.w3c.dom.Element;\r
\r
+/**\r
+ * The Class RelationUtilsNuxeoImpl.\r
+ */\r
public class RelationUtilsNuxeoImpl implements RelationUtils {\r
\r
+ /** The C s_ relatio n_ servic e_ name. */\r
static public String CS_RELATION_SERVICE_NAME = "relations";\r
+ static public String CS_EMPTY_STRING = "";\r
\r
+ /** The Constant REL_NUXEO_DOCTYPE. */\r
final public static String REL_NUXEO_DOCTYPE = "Relation";\r
+ \r
+ /** The Constant REL_NUXEO_SCHEMA_NAME. */\r
final public static String REL_NUXEO_SCHEMA_NAME = "relation";\r
+ \r
+ /** The Constant REL_NUXEO_SCHEMA_ROOT_ELEMENT. */\r
final public static String REL_NUXEO_SCHEMA_ROOT_ELEMENT = "relationtype";\r
+ \r
+ /** The Constant REL_NUXEO_DC_TITLE. */\r
final public static String REL_NUXEO_DC_TITLE = "CollectionSpace-Relation";\r
\r
+ /** The logger. */\r
private static Logger logger = LoggerFactory\r
.getLogger(RelationUtilsNuxeoImpl.class); \r
\r
\r
+ /**\r
+ * Fill relation from doc model.\r
+ * \r
+ * @param relation the relation\r
+ * @param relDocModel the rel doc model\r
+ * \r
+ * @throws ClientException the client exception\r
+ */\r
static public void fillRelationFromDocModel(Relation relation, DocumentModel relDocModel)\r
throws ClientException {\r
String xpathRoot = "/" + REL_NUXEO_SCHEMA_ROOT_ELEMENT + "/";\r
Object valueObject = null;\r
\r
+ relation.setCsid(relDocModel.getId());\r
+\r
valueObject = relDocModel.getProperty(REL_NUXEO_SCHEMA_NAME, xpathRoot\r
+ RelationJAXBSchema.DOCUMENT_ID_1);\r
relation.setDocumentId1((String) valueObject);\r
}\r
}\r
\r
+ /**\r
+ * Fill doc model from relation.\r
+ * \r
+ * @param p the p\r
+ * @param relDocModel the rel doc model\r
+ * \r
+ * @throws Exception the exception\r
+ */\r
static public void fillDocModelFromRelation(Relation p, DocumentModel relDocModel)\r
throws Exception {\r
\r
}\r
}\r
\r
+ /**\r
+ * Prints the document model.\r
+ * \r
+ * @param documentModel the document model\r
+ */\r
static public void printDocumentModel(DocumentModel documentModel) {\r
System.out.println(documentModel);\r
}\r
\r
+ /**\r
+ * Describe document model.\r
+ * \r
+ * @param docModel the doc model\r
+ * \r
+ * @throws Exception the exception\r
+ */\r
static private void describeDocumentModel(DocumentModel docModel) throws Exception {\r
String[] schemas = docModel.getDeclaredSchemas();\r
for (int i = 0; schemas != null && i < schemas.length; i++) {\r
\r
}\r
\r
- static public List<Relation> getRelationships(RepositoryInstance repoSession)\r
- throws DocumentException, IOException, ClientException {\r
- List<Relation> result = new ArrayList<Relation>();\r
+ /**\r
+ * Creates the relationship.\r
+ * \r
+ * @param nuxeoRepoSession the nuxeo repo session\r
+ * @param newRelation the new relation\r
+ * \r
+ * @return the document model\r
+ * \r
+ * @throws DocumentException the document exception\r
+ */\r
+ static public DocumentModel createRelationship(Object nuxeoRepoSession, Relation newRelation)\r
+ throws DocumentException {\r
+ DocumentModel result = null;\r
+ RepositoryInstance repoSession = (RepositoryInstance)nuxeoRepoSession;\r
+ \r
+ try {\r
+ // get the Nuxeo 'Relations' workspace\r
+ DocumentModel workspaceModel = NuxeoUtils.getWorkspaceModel(repoSession,\r
+ CS_RELATION_SERVICE_NAME);\r
+ \r
+ String docType = REL_NUXEO_DOCTYPE;\r
+ String id = IdUtils.generateId("New " + docType);\r
+ \r
+ //create document model\r
+ String workspacePath = workspaceModel.getPathAsString(); \r
+ DocumentModel newRelDocModel = repoSession.createDocumentModel(workspacePath, id, docType);\r
+ \r
+ newRelation.setCsid(newRelDocModel.getId());\r
+ fillDocModelFromRelation(newRelation, newRelDocModel);\r
+ \r
+ //create document with the new DocumentModel\r
+ result = repoSession.createDocument(newRelDocModel);\r
+ repoSession.save();\r
+ } catch (Exception e) {\r
+ e.printStackTrace();\r
+ throw new DocumentException(e);\r
+ }\r
+ \r
+ return result;\r
+ }\r
+ \r
+ /* (non-Javadoc)\r
+ * @see org.collectionspace.services.common.RelationUtils#createRelationship(java.lang.Object, java.lang.String, java.lang.String, java.lang.String)\r
+ */\r
+ public Relation createRelationship(Object nuxeoRepoSession, String subjectCsid, String predicate,\r
+ String objectCsid) throws DocumentException {\r
+ Relation result = null;\r
+ RepositoryInstance repoSession = (RepositoryInstance)nuxeoRepoSession;\r
+ \r
+ Relation temp = new Relation();\r
+ temp.setDocumentId1(subjectCsid);\r
+ temp.setRelationshipType(null);\r
+ temp.setDocumentId2(objectCsid);\r
+ createRelationship(repoSession, temp);\r
+ \r
+ return result;\r
+ }\r
+ \r
+ /* (non-Javadoc)\r
+ * @see org.collectionspace.services.common.RelationUtils#getRelationships(java.lang.Object)\r
+ */\r
+ public List<Relation> getRelationships(Object nuxeoRepoSession)\r
+ throws DocumentException {\r
+ List<Relation> result = null;\r
+ RepositoryInstance repoSession = (RepositoryInstance)nuxeoRepoSession;\r
+\r
+ try {\r
+ DocumentModel relationWorkspace = NuxeoUtils.getWorkspaceModel(\r
+ repoSession, CS_RELATION_SERVICE_NAME);\r
+ DocumentModelList children = repoSession.getChildren(relationWorkspace\r
+ .getRef());\r
+ \r
+ result = new ArrayList<Relation>();\r
+ Relation relation = null;\r
+ for (DocumentModel child : children) {\r
+ relation = new Relation();\r
+ fillRelationFromDocModel(relation, child);\r
+ result.add(relation);\r
+ }\r
+ } catch (Exception e) {\r
+ e.printStackTrace();\r
+ throw new DocumentException(e);\r
+ }\r
\r
- DocumentModel relationWorkspace = NuxeoUtils.getWorkspaceModel(\r
- repoSession, CS_RELATION_SERVICE_NAME);\r
- DocumentModelList children = repoSession.getChildren(relationWorkspace\r
- .getRef());\r
- Relation relation = null;\r
- for (DocumentModel child : children) {\r
- relation = new Relation();\r
- fillRelationFromDocModel(relation, child);\r
- result.add(relation);\r
+ return result;\r
+ }\r
+ \r
+ /* (non-Javadoc)\r
+ * @see org.collectionspace.services.common.RelationUtils#getRelationships(java.lang.Object, java.lang.String)\r
+ */\r
+ public List<Relation> getRelationships(Object nuxeoRepoSession, String csid)\r
+ throws DocumentException {\r
+ List<Relation> result = null;\r
+ RepositoryInstance repoSession = (RepositoryInstance)nuxeoRepoSession;\r
+ \r
+ try {\r
+ DocumentModel relationWorkspace = NuxeoUtils.getWorkspaceModel(\r
+ repoSession, CS_RELATION_SERVICE_NAME);\r
+ DocumentModelList children = repoSession.getChildren(relationWorkspace\r
+ .getRef());\r
+ \r
+ result = new ArrayList<Relation>();\r
+ Relation relation = null;\r
+ for (DocumentModel child : children) {\r
+ if ((isSubjectOfRelation(csid, child) == true) ||\r
+ (isObjectOfRelation(csid, child) == true)) {\r
+ relation = new Relation();\r
+ fillRelationFromDocModel(relation, child);\r
+ result.add(relation);\r
+ }\r
+ }\r
+ } catch (Exception e) {\r
+ e.printStackTrace();\r
+ throw new DocumentException(e);\r
+ }\r
+ \r
+ return result;\r
+ }\r
+ \r
+ \r
+ /* (non-Javadoc)\r
+ * @see org.collectionspace.services.common.RelationUtils#getRelationships(java.lang.Object, java.lang.String, java.lang.String, java.lang.String)\r
+ */\r
+ public List<Relation> getRelationships(Object nuxeoRepoSession,\r
+ String subjectCsid, \r
+ String predicate, \r
+ String objectCsid) throws DocumentException {\r
+ List<Relation> result = null;\r
+ RepositoryInstance repoSession = (RepositoryInstance)nuxeoRepoSession;\r
+ \r
+ try {\r
+ DocumentModel relationWorkspace = NuxeoUtils.getWorkspaceModel(\r
+ repoSession, CS_RELATION_SERVICE_NAME);\r
+ DocumentModelList children = repoSession.getChildren(relationWorkspace\r
+ .getRef());\r
+ \r
+ result = new ArrayList<Relation>();\r
+ Relation relation = null;\r
+ for (DocumentModel child : children) {\r
+ if (isQueryMatch(child, subjectCsid, predicate, objectCsid) == true) {\r
+ relation = new Relation();\r
+ fillRelationFromDocModel(relation, child);\r
+ result.add(relation); }\r
+ }\r
+ } catch (Exception e) {\r
+ e.printStackTrace();\r
+ throw new DocumentException(e);\r
}\r
+ \r
+ return result;\r
+ }\r
+ \r
+ /**\r
+ * Checks if is subject of relation.\r
+ * \r
+ * @param csid the csid\r
+ * @param documentModel the document model\r
+ * \r
+ * @return true, if is subject of relation\r
+ * \r
+ * @throws ClientException the client exception\r
+ */\r
+ private boolean isSubjectOfRelation(String csid, DocumentModel documentModel)\r
+ throws ClientException {\r
+ boolean result = false;\r
+ String xpathRoot = "/" + REL_NUXEO_SCHEMA_ROOT_ELEMENT + "/";\r
\r
+ Object valueObject = documentModel.getProperty(REL_NUXEO_SCHEMA_NAME, xpathRoot\r
+ + RelationJAXBSchema.DOCUMENT_ID_1);\r
+ if (valueObject != null && csid != null) {\r
+ String subjectID = (String) valueObject;\r
+ result = subjectID.equals(csid);\r
+ }\r
+ \r
return result;\r
}\r
\r
+ /**\r
+ * Checks if is object of relation.\r
+ * \r
+ * @param csid the csid\r
+ * @param documentModel the document model\r
+ * \r
+ * @return true, if is object of relation\r
+ * \r
+ * @throws ClientException the client exception\r
+ */\r
+ private boolean isObjectOfRelation(String csid, DocumentModel documentModel)\r
+ throws ClientException {\r
+ boolean result = false;\r
+ String xpathRoot = "/" + REL_NUXEO_SCHEMA_ROOT_ELEMENT + "/";\r
+\r
+ Object valueObject = documentModel.getProperty(REL_NUXEO_SCHEMA_NAME,\r
+ xpathRoot + RelationJAXBSchema.DOCUMENT_ID_2);\r
+ if (valueObject != null && csid != null) {\r
+ String subjectID = (String) valueObject;\r
+ result = subjectID.equals(csid);\r
+ }\r
+\r
+ return result;\r
+ }\r
+ \r
+ private boolean isPredicateOfRelation(String predicate,\r
+ DocumentModel documentModel) throws ClientException {\r
+ boolean result = false;\r
+ String xpathRoot = "/" + REL_NUXEO_SCHEMA_ROOT_ELEMENT + "/";\r
+\r
+ Object valueObject = documentModel.getProperty(REL_NUXEO_SCHEMA_NAME,\r
+ xpathRoot + RelationJAXBSchema.RELATIONSHIP_TYPE);\r
+ if (valueObject != null && predicate != null) {\r
+ String relationType = (String) valueObject;\r
+ result = predicate.equalsIgnoreCase(relationType);\r
+ }\r
+\r
+ return result;\r
+ }\r
+\r
+ /**\r
+ * Gets the object ID from of the (Subject-Predicate-Object) relationship.\r
+ * \r
+ * @param csid the ID of the 'Subject' (Subject-Predicate-Object)\r
+ * @param documentModel represents the relation entry.\r
+ * \r
+ * @return the object csid of the relationship\r
+ * \r
+ * @throws ClientException the client exception\r
+ */\r
+ private String getObjectFromSubject(String csid, DocumentModel documentModel)\r
+ throws ClientException {\r
+ String result = null;\r
+ String xpathRoot = "/" + REL_NUXEO_SCHEMA_ROOT_ELEMENT + "/";\r
+\r
+ Object valueObject = documentModel.getProperty(REL_NUXEO_SCHEMA_NAME,\r
+ xpathRoot + RelationJAXBSchema.DOCUMENT_ID_1);\r
+ if (valueObject != null) {\r
+ String subjectID = (String) valueObject;\r
+ if (subjectID.equals(csid) == true) {\r
+ valueObject = documentModel.getProperty(REL_NUXEO_SCHEMA_NAME,\r
+ xpathRoot + RelationJAXBSchema.DOCUMENT_ID_2);\r
+ if (valueObject != null) {\r
+ result = (String) valueObject;\r
+ }\r
+ }\r
+ }\r
+\r
+ return result;\r
+ }\r
+ \r
+ static public Document getDocument(List<Relation> relationList)\r
+ throws DocumentException {\r
+ DOMDocumentFactory domfactory = new DOMDocumentFactory();\r
+ DOMDocument result = (DOMDocument) domfactory.createDocument();\r
+\r
+ try {\r
+ // setup the root element\r
+ DOMElement root = (DOMElement) result\r
+ .createElement(RelationListItemJAXBSchema.REL_ROOT_ELEM_NAME);\r
+ result.setRootElement((org.dom4j.Element) root);\r
+\r
+ // populate the document with child elements\r
+ for (Relation child : relationList) {\r
+ DOMElement el = (DOMElement) result.createElement(RelationJAXBSchema.REL_ROOT_ELEM_NAME);\r
+ el.setAttribute(RelationListItemJAXBSchema.CSID, child\r
+ .getCsid());\r
+ el.setAttribute(RelationListItemJAXBSchema.URI, getRelURL(\r
+ CS_RELATION_SERVICE_NAME, child.getCsid()));\r
+\r
+ if (logger.isDebugEnabled() == true) {\r
+ System.out.println(el.asXML());\r
+ }\r
+ \r
+ root.appendChild(el);\r
+ }\r
+ } catch (Exception e) {\r
+ if (logger.isDebugEnabled()) {\r
+ logger.debug("Caught exception ", e);\r
+ }\r
+ throw new DocumentException(e);\r
+ }\r
+\r
+ if (logger.isDebugEnabled() == true) {\r
+ System.out.println(result.asXML());\r
+ }\r
+\r
+ return result;\r
+ }\r
+ \r
+ private boolean isQueryMatch(DocumentModel documentModel,\r
+ String subjectCsid,\r
+ String predicate,\r
+ String objectCsid) throws ClientException {\r
+ boolean result = true;\r
+ \r
+ block: {\r
+ if (subjectCsid != null) {\r
+ if (isSubjectOfRelation(subjectCsid, documentModel) == false) {\r
+ result = false;\r
+ break block;\r
+ }\r
+ }\r
+ if (predicate != null) {\r
+ if (isPredicateOfRelation(predicate, documentModel) == false) {\r
+ result = false;\r
+ break block;\r
+ }\r
+ }\r
+ if (objectCsid != null) {\r
+ if (isObjectOfRelation(objectCsid, documentModel) == false) {\r
+ result = false;\r
+ break block;\r
+ }\r
+ }\r
+ }\r
+ \r
+ return result;\r
+ }\r
+ private static String getRelURL(String repo, String uuid) {\r
+ return '/' + repo + '/' + uuid;\r
+ } \r
+ \r
}\r
<xs:enumeration value="association"/>\r
<!-- document with id as document-id-1 contains one or more document with id as document-id-2 -->\r
<xs:enumeration value="contains"/>\r
+ <!-- document with id as document-id-1 contains one or more document with id as document-id-2 -->\r
+ <xs:enumeration value="collectionobject-intake"/>\r
</xs:restriction>\r
</xs:simpleType>\r
\r
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;
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. */
}
/**
- * 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<RelationList.RelationListItem> 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;
}
/**
* Gets the relation.
*
- * @param csid the csid
+ * @param csid
+ * the csid
*
* @return the relation
*/
Iterator<Element> relIter = schemaElement
.elementIterator(RelationJAXBSchema.REL_ROOT_ELEM_NAME);
Iterator<Element> relIter2 = schemaElement
- .elementIterator("rel:" + RelationJAXBSchema.REL_ROOT_ELEM_NAME);
-
+ .elementIterator("rel:"
+ + RelationJAXBSchema.REL_ROOT_ELEM_NAME);
+
while (relIter.hasNext()) {
Element relElement = relIter.next();
}
}
} 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) {
.build();
throw new WebApplicationException(response);
}
- verbose("getRelation: ", co);
+
+ if (logger.isDebugEnabled() == true) {
+ verbose("getRelation: ", co);
+ }
return co;
}
/**
* 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 {
}
}
} 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);
}
/**
* Delete relation.
*
- * @param csid the csid
+ * @param csid
+ * the csid
*/
@DELETE
@Path("{csid}")
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<RelationList.RelationListItem> 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 {
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);
\r
import java.io.IOException;\r
import org.dom4j.Document;\r
-import org.dom4j.DocumentException;\r
+//import org.dom4j.DocumentException;\r
+import org.collectionspace.services.common.repository.DocumentException;\r
+\r
\r
import org.collectionspace.services.relation.Relation;\r
\r
* @throws IOException Signals that an I/O exception has occurred.\r
*/\r
Document getRelationList() throws DocumentException, IOException;\r
+ \r
+ /**\r
+ * Gets the relation list of type.\r
+ * \r
+ * @param subjectCsid the subject csid\r
+ * @param predicate the predicate\r
+ * @param objectCsid the object csid\r
+ * \r
+ * @return the relation list of type\r
+ * \r
+ * @throws DocumentException the document exception\r
+ * @throws IOException Signals that an I/O exception has occurred.\r
+ */\r
+ Document getRelationList(String subjectCsid,\r
+ String predicate, String objectCsid)\r
+ throws DocumentException, IOException;\r
\r
// Update\r
/**\r
//import java.util.ArrayList;\r
//import java.util.Arrays;\r
//import java.util.HashMap;\r
-//import java.util.List;\r
+import java.util.List;\r
//import java.util.Map;\r
//import java.util.Iterator;\r
\r
+import org.collectionspace.services.common.repository.DocumentException;\r
//import org.collectionspace.services.nuxeo.NuxeoRESTClient;\r
import org.collectionspace.services.nuxeo.CollectionSpaceServiceNuxeoImpl;\r
import org.collectionspace.services.nuxeo.RelationUtilsNuxeoImpl;\r
//import org.collectionspace.services.relation.RelationshipType;\r
//import org.collectionspace.services.RelationJAXBSchema;\r
import org.collectionspace.services.nuxeo.util.NuxeoUtils;\r
+import org.collectionspace.services.common.RelationsManager;\r
//import org.collectionspace.services.common.ServiceMain;\r
\r
import org.dom4j.Document;\r
//import org.dom4j.Element;\r
//import org.dom4j.dom.DOMDocument;\r
-import org.dom4j.DocumentException;\r
+//import org.dom4j.DocumentException;\r
//import org.dom4j.io.SAXReader;\r
//import org.restlet.resource.Representation;\r
\r
* @throws DocumentException the document exception\r
* @throws IOException Signals that an I/O exception has occurred.\r
*/\r
- public Document deleteRelation(String csid)\r
- throws DocumentException, IOException {\r
+ public Document deleteRelation(String csid) throws DocumentException {\r
Document result = null;\r
- \r
- RepositoryInstance repoSession = null;\r
- try {\r
- repoSession = getRepositorySession();\r
- result = deleteDocument(repoSession, csid);\r
- } catch (Exception e) {\r
- e.printStackTrace();\r
- } finally {\r
- if(repoSession != null) {\r
- releaseRepositorySession(repoSession);\r
- }\r
- }\r
+\r
+ RepositoryInstance repoSession = null;\r
+ try {\r
+ repoSession = getRepositorySession();\r
+ result = deleteDocument(repoSession, csid);\r
+ } catch (Exception e) {\r
+ if (logger.isDebugEnabled()) {\r
+ logger.debug("Caught exception ", e);\r
+ }\r
+ throw new DocumentException(e);\r
+ } finally {\r
+ if (repoSession != null) {\r
+ releaseRepositorySession(repoSession);\r
+ }\r
+ }\r
\r
return result;\r
}\r
repoSession = getRepositorySession();\r
result = NuxeoUtils.getDocument(repoSession, csid);\r
} catch (Exception e) {\r
- e.printStackTrace();\r
+ if (logger.isDebugEnabled()) {\r
+ logger.debug("Caught exception ", e);\r
+ }\r
+ throw new DocumentException(e);\r
} finally {\r
if (repoSession != null) {\r
releaseRepositorySession(repoSession);\r
* @throws DocumentException the document exception\r
* @throws IOException Signals that an I/O exception has occurred.\r
*/\r
- public Document getRelationList() throws DocumentException, IOException {\r
+ public Document getRelationList()\r
+ throws DocumentException, IOException {\r
Document result = null;\r
RepositoryInstance repoSession = null;\r
\r
try {\r
repoSession = getRepositorySession();\r
- RelationUtilsNuxeoImpl.getRelationships(repoSession);\r
+ List<Relation> relationList = RelationsManager.getRelationships(repoSession);\r
\r
- result = this.browseWorkspace(repoSession, RelationUtilsNuxeoImpl.CS_RELATION_SERVICE_NAME);\r
+ result = RelationUtilsNuxeoImpl.getDocument(relationList);\r
} catch (Exception e) {\r
- e.printStackTrace();\r
+ if (logger.isDebugEnabled()) {\r
+ logger.debug("Caught exception ", e);\r
+ }\r
+ throw new DocumentException(e);\r
} finally {\r
if (repoSession != null) {\r
releaseRepositorySession(repoSession);\r
\r
return result;\r
}\r
+ \r
+ /* (non-Javadoc)\r
+ * @see org.collectionspace.services.RelationService#getRelationList(java.lang.String, java.lang.String, java.lang.String)\r
+ */\r
+ public Document getRelationList(String subjectCsid,\r
+ String predicate, String objectCsid)\r
+ throws DocumentException, IOException {\r
+ Document result = null;\r
+ RepositoryInstance repoSession = null;\r
+\r
+ try {\r
+ repoSession = getRepositorySession();\r
+ List<Relation> relationList = RelationsManager.getRelationships(repoSession,\r
+ subjectCsid, predicate, objectCsid);\r
+ \r
+ result = RelationUtilsNuxeoImpl.getDocument(relationList);\r
+ } catch (Exception e) {\r
+ if (logger.isDebugEnabled()) {\r
+ logger.debug("Caught exception ", e);\r
+ }\r
+ throw new DocumentException(e);\r
+ } finally {\r
+ if (repoSession != null) {\r
+ releaseRepositorySession(repoSession);\r
+ }\r
+ }\r
+ \r
+ if (logger.isDebugEnabled() == true) {\r
+ System.out.println(result.asXML());\r
+ }\r
+\r
+ return result;\r
+ }\r
\r
// Create a new relation document\r
/**\r
\r
try {\r
repoSession = getRepositorySession();\r
- \r
- // get the Nuxeo 'Relations' workspace\r
- DocumentModel workspaceModel = NuxeoUtils.getWorkspaceModel(repoSession,\r
- RelationUtilsNuxeoImpl.CS_RELATION_SERVICE_NAME);\r
- \r
- String docType = RelationUtilsNuxeoImpl.REL_NUXEO_DOCTYPE;\r
- String id = IdUtils.generateId("New " + docType);\r
- \r
- //create document model\r
- String workspacePath = workspaceModel.getPathAsString(); \r
- DocumentModel newRelDocModel = repoSession.createDocumentModel(workspacePath, id, docType);\r
-\r
- //debug\r
- if (logger.isDebugEnabled() == true) {\r
- RelationUtilsNuxeoImpl.printDocumentModel(newRelDocModel);\r
- }\r
- RelationUtilsNuxeoImpl.fillDocModelFromRelation(co, newRelDocModel);\r
- \r
- //create document with the new DocumentModel\r
- DocumentModel resultDocModel = repoSession.createDocument(newRelDocModel);\r
+ DocumentModel resultDocModel = RelationUtilsNuxeoImpl.createRelationship(repoSession, co);\r
repoSession.save();\r
-\r
result = NuxeoUtils.getDocument(repoSession, resultDocModel);\r
-\r
} catch (Exception e) {\r
- e.printStackTrace();\r
+ if (logger.isDebugEnabled() == true) {\r
+ logger.debug("Caught exception ", e);\r
+ }\r
+ throw new DocumentException(e);\r
} finally {\r
if (repoSession != null) {\r
releaseRepositorySession(repoSession);\r
repoSession.save();\r
result = NuxeoUtils.getDocument(repoSession, documentModel);\r
} catch(Exception e){\r
- e.printStackTrace();\r
+ if (logger.isDebugEnabled()) {\r
+ logger.debug("Caught exception ", e);\r
+ }\r
+ throw new DocumentException(e);\r
} finally{\r
if(repoSession != null){\r
releaseRepositorySession(repoSession);\r