// Next, create a part object
PoxPayloadOut multipart = new PoxPayloadOut(CollectionObjectClient.SERVICE_PAYLOAD_NAME);
- PayloadOutputPart commonPart = multipart.addPart(co, MediaType.APPLICATION_XML_TYPE);
- commonPart.setLabel(collectionObjectClient.getCommonPartName());
+ PayloadOutputPart commonPart = multipart.addPart(collectionObjectClient.getCommonPartName(), co);
// Make the create call and check the response
ClientResponse<Response> response = collectionObjectClient.create(multipart);
response.releaseConnection();
}
- //Next, create a Dimension record to relate the collection object to
+ //Next, create a two Dimension records to relate the collection object to
multipart = this.createDimensionInstance(createIdentifier());
// Make the call to create and check the response
response = dimensionClient.create(multipart);
- String dimensionCsid = null;
+ String dimensionCsid1 = null;
try {
Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode());
- dimensionCsid = extractId(response);
+ dimensionCsid1 = extractId(response);
+ } finally {
+ response.releaseConnection();
+ }
+ //Next, create a the second Dimension record
+ multipart = this.createDimensionInstance(createIdentifier());
+ // Make the call to create and check the response
+ response = dimensionClient.create(multipart);
+ String dimensionCsid2 = null;
+ try {
+ Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode());
+ dimensionCsid2 = extractId(response);
} finally {
response.releaseConnection();
}
- // Relate the two entities, by creating a new relation object
+
+ // Relate the entities, by creating a new relation object
RelationsCommon relation = new RelationsCommon();
fillRelation(relation, collectionObjectCsid, CollectionobjectsCommon.class.getSimpleName(),
- dimensionCsid, DimensionsCommon.class.getSimpleName(),
+ dimensionCsid1, DimensionsCommon.class.getSimpleName(),
"collectionobject-dimension");
// Create the part and fill it with the relation object
multipart = new PoxPayloadOut(RelationClient.SERVICE_PAYLOAD_NAME);
- commonPart = multipart.addPart(relation, MediaType.APPLICATION_XML_TYPE);
- commonPart.setLabel(relationClient.getCommonPartName());
-
+ commonPart = multipart.addPart(relationClient.getCommonPartName(), relation);
+ // Create the relationship
+ response = relationClient.create(multipart);
+ String relationCsid1 = null;
+ try {
+ Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode());
+ relationCsid1 = extractId(response);
+ } finally {
+ response.releaseConnection();
+ }
+ // Create the second relationship
+ relation = new RelationsCommon();
+ fillRelation(relation, collectionObjectCsid, CollectionobjectsCommon.class.getSimpleName(),
+ dimensionCsid2, DimensionsCommon.class.getSimpleName(),
+ "collectionobject-dimension");
+ // Create the part and fill it with the relation object
+ multipart = new PoxPayloadOut(RelationClient.SERVICE_PAYLOAD_NAME);
+ commonPart = multipart.addPart(relationClient.getCommonPartName(), relation);
// Create the relationship
response = relationClient.create(multipart);
@SuppressWarnings("unused")
- String relationCsid = null;
+ String relationCsid2 = null;
try {
Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode());
- relationCsid = extractId(response);
+ relationCsid2 = extractId(response);
} finally {
response.releaseConnection();
}
+
// Now lock the dimension record.
@SuppressWarnings("unused")
- ClientResponse<String> workflowResponse = dimensionClient.updateWorkflowWithTransition(dimensionCsid, WorkflowClient.WORKFLOWTRANSITION_LOCK);
- System.out.println("Locked dimension record with CSID=" + dimensionCsid);
+ ClientResponse<String> workflowResponse = dimensionClient.updateWorkflowWithTransition(dimensionCsid1, WorkflowClient.WORKFLOWTRANSITION_LOCK);
+ System.out.println("Locked dimension record with CSID=" + dimensionCsid1);
// Finally, try to delete the relationship
// Try to delete the relationship -should fail because we don't allow delete if one of the sides is locked.
- response = relationClient.delete(relationCsid);
+ response = relationClient.delete(relationCsid1);
try {
Assert.assertEquals(response.getStatus(), Response.Status.BAD_REQUEST.getStatusCode());
} finally {
}
// Also, try to soft-delete. This should also fail.
- workflowResponse = dimensionClient.updateWorkflowWithTransition(dimensionCsid, WorkflowClient.WORKFLOWTRANSITION_DELETE);
- System.out.println("Locked dimension record with CSID=" + dimensionCsid);
+ workflowResponse = dimensionClient.updateWorkflowWithTransition(dimensionCsid1, WorkflowClient.WORKFLOWTRANSITION_DELETE);
+ System.out.println("Locked dimension record with CSID=" + dimensionCsid1);
}
/*
* See CSPACE-5036 - How to make CMISQL queries from Nuxeo
*/
- private void makeCMISQLQuery(RepositoryInstance repoSession, String query) {
- // the NuxeoRepository should be constructed only once, then cached
- // (its construction is expensive)
- try {
- NuxeoRepository repo = new NuxeoRepository(repoSession.getRepositoryName(),
- repoSession.getRootDocument().getId());
- logger.debug("Repository ID:" + repo.getId() + " Root folder:" + repo.getRootFolderId());
-
- CallContextImpl callContext = new CallContextImpl(CallContext.BINDING_LOCAL,
- repo.getId(), false);
- callContext.put(CallContext.USERNAME, repoSession.getPrincipal().getName());
- NuxeoCmisService cmisService = new NuxeoCmisService(repo, callContext, repoSession);
-
- IterableQueryResult result = repoSession.queryAndFetch(query, "CMISQL", cmisService);
- for (Map<String, Serializable> row : result) {
- logger.debug(
-// "dc:title is: " + (String)row.get("dc:title")
- "" + " Hierarchy Table ID is:" + row.get("cmis:objectId")
- + " cmis:name is: " + row.get("cmis:name")
-// + " nuxeo:lifecycleState is: " + row.get("nuxeo:lifecycleState")
- );
- }
+ private void makeCMISQLQuery(RepositoryInstance repoSession, String query) {
+ // the NuxeoRepository should be constructed only once, then cached
+ // (its construction is expensive)
+ try {
+ NuxeoRepository repo = new NuxeoRepository(
+ repoSession.getRepositoryName(), repoSession
+ .getRootDocument().getId());
+ logger.debug("Repository ID:" + repo.getId() + " Root folder:"
+ + repo.getRootFolderId());
+
+ CallContextImpl callContext = new CallContextImpl(
+ CallContext.BINDING_LOCAL, repo.getId(), false);
+ callContext.put(CallContext.USERNAME, repoSession.getPrincipal()
+ .getName());
+ NuxeoCmisService cmisService = new NuxeoCmisService(repo,
+ callContext, repoSession);
+
+ IterableQueryResult result = repoSession.queryAndFetch(query,
+ "CMISQL", cmisService);
+ for (Map<String, Serializable> row : result) {
+ logger.debug(
+ // "dc:title is: " + (String)row.get("dc:title")
+ "" + " Hierarchy Table ID is:" + row.get("cmis:objectId")
+ + " cmis:name is: " + row.get("cmis:name")
+ // + " nuxeo:lifecycleState is: " +
+ // row.get("nuxeo:lifecycleState")
+ );
+ }
} catch (ClientException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
- }
+ }
/**
* getFiltered get all documents for an entity service from the Document repository,
// CSPACE-5036 - How to make CMISQL queries from Nuxeo
//
- // do a query
+ /*
+ * Find all the Dimension records related to record X with csid = aa93c38d-43a1-42cc-ad2a where X is the subject of the relationship and
+ * the dimension records are the 'object' of the relationship
+ */
+ String targetCsid = "0b5fd53a-41ff-478f-9ed8";
+ String query0 = "SELECT D.cmis:name, D.dc:title, R.dc:title, R.relations_common:subjectCsid FROM Dimension D JOIN Relation R ON R.relations_common:objectCsid = D.cmis:name WHERE R.relations_common:subjectCsid = '0b5fd53a-41ff-478f-9ed8'";
+ makeCMISQLQuery(repoSession, query0); //SHOULD return two dimension records
+
String query1 = "SELECT A.intakes_common:entryReason FROM Intake A"; // try eaee111c-a8d8-48c7-95cb
makeCMISQLQuery(repoSession, query1);
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>\r
\r
-<!--\r
- Relation schema (XSD)\r
- \r
- Entity : Relation\r
- Part : Common\r
- Used for: Nuxeo EP core document type\r
-\r
- $LastChangedRevision$\r
- $LastChangedDate$\r
--->\r
-\r
-<xs:schema \r
- xmlns:xs="http://www.w3.org/2001/XMLSchema"\r
- xmlns="http://collectionspace.org/relation/"\r
- xmlns:rel="http://collectionspace.org/relation/"\r
- targetNamespace="http://collectionspace.org/relation/"\r
- version="0.1">\r
-\r
- <!-- Note: nuxeo ecm types does not support xs:anyURI type -->\r
- <!-- if xs:anyURI is used, it fails to register that doctype -->\r
-\r
- <!-- conventions for describing relationships -->\r
- <!-- 1. left to right in alphabetical order for the association relations -->\r
- <!-- e.g. for association between collectionobject and intake entities -->\r
- <!-- document-id-1 would be the id of the collectionobject -->\r
- <!-- document-type-1 would be the doc-type of the collectionobject -->\r
- <!-- document-id-2 would be the id of the intake -->\r
-` <!-- document-type-2 would be the doc-type of the intake -->\r
- <!-- 2. left to right container and containee or children -->\r
- <!-- e.g. for collectionobject containing other collectionobjects -->\r
- <!-- document-id-1 would be the id of the container collectionobject -->\r
- <!-- document-type-1 would be the doc-type of the container collectionobject -->\r
- <!-- document-id-2 would be the id of the contained (or child) collectionobject -->\r
- <!-- document-type-2 would be the doc-type of the collectionobejct -->\r
- <xs:element name="subjectCsid" type="xs:string" minOccurs="1" maxOccurs="1"/> <!-- new name for documentId1 -->\r
- <xs:element name="subjectDocumentType" type="xs:string" minOccurs="1" maxOccurs="1"/> <!-- new name for documentType1 -->\r
-\r
- <xs:element name="objectCsid" type="xs:string" minOccurs="1" maxOccurs="1"/> <!-- new name for documentId2 -->\r
- <xs:element name="objectDocumentType" type="xs:string" minOccurs="1" maxOccurs="1"/> <!-- new name for documentType2 -->\r
-\r
- <!-- type of relationship between two entities -->\r
- <xs:element name="relationshipType" type="rel:RelationshipType" minOccurs="1" maxOccurs="1"/>\r
- <xs:element name="predicate" type="rel:RelationshipType" minOccurs="1" maxOccurs="1"/> <!-- new name for relationshipType -->\r
- <xs:element name="predicateDisplayName" type="xs:string" minOccurs="1"/>\r
-\r
- <xs:element name="subjectUri" type="xs:string"/>\r
- <xs:element name="objectUri" type="xs:string"/>\r
- \r
- <xs:element name="subjectRefName" type="xs:string"/>\r
- <xs:element name="objectRefName" type="xs:string"/> \r
-\r
- <!-- enumeration defining the type of relationship between two entities -->\r
- <xs:simpleType name="RelationshipType">\r
- <xs:restriction base="xs:string">\r
- <!-- document with id as document-id-1 is associated with document with id as document-id-2 -->\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 has parent document with id as document-id-2 -->\r
- <xs:enumeration value="hasBroader" />\r
- </xs:restriction>\r
- </xs:simpleType>\r
-\r
+<!-- Relation schema (XSD) Entity : Relation Part : Common Used for: Nuxeo \r
+ EP core document type $LastChangedRevision$ $LastChangedDate$ -->\r
+\r
+<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://collectionspace.org/relation/"\r
+ xmlns:rel="http://collectionspace.org/relation/" targetNamespace="http://collectionspace.org/relation/"\r
+ version="0.1">\r
+\r
+ <!-- Note: nuxeo ecm types does not support xs:anyURI type -->\r
+ <!-- if xs:anyURI is used, it fails to register that doctype -->\r
+\r
+ <!-- conventions for describing relationships -->\r
+ <!-- 1. left to right in alphabetical order for the association relations -->\r
+ <!-- e.g. for association between collectionobject and intake entities -->\r
+ <!-- document-id-1 would be the id of the collectionobject -->\r
+ <!-- document-type-1 would be the doc-type of the collectionobject -->\r
+ <!-- document-id-2 would be the id of the intake -->\r
+ <!-- document-type-2 would be the doc-type of the intake -->\r
+ <!-- 2. left to right container and containee or children -->\r
+ <!-- e.g. for collectionobject containing other collectionobjects -->\r
+ <!-- document-id-1 would be the id of the container collectionobject -->\r
+ <!-- document-type-1 would be the doc-type of the container collectionobject -->\r
+ <!-- document-id-2 would be the id of the contained (or child) collectionobject -->\r
+ <!-- document-type-2 would be the doc-type of the collectionobejct -->\r
+ \r
+ <xs:element name="subjectCsid" type="xs:string" minOccurs="1"\r
+ maxOccurs="1" /> <!-- new name for documentId1 -->\r
+ <xs:element name="subjectDocumentType" type="xs:string"\r
+ minOccurs="1" maxOccurs="1" /> <!-- new name for documentType1 -->\r
+\r
+ <xs:element name="objectCsid" type="xs:string" minOccurs="1"\r
+ maxOccurs="1" /> <!-- new name for documentId2 -->\r
+ <xs:element name="objectDocumentType" type="xs:string"\r
+ minOccurs="1" maxOccurs="1" /> <!-- new name for documentType2 -->\r
+\r
+ <!-- type of relationship between two entities -->\r
+ <xs:element name="relationshipType" type="rel:RelationshipType"\r
+ minOccurs="1" maxOccurs="1" />\r
+ <xs:element name="predicate" type="rel:RelationshipType"\r
+ minOccurs="1" maxOccurs="1" /> <!-- new name for relationshipType -->\r
+ <xs:element name="predicateDisplayName" type="xs:string"\r
+ minOccurs="1" />\r
+\r
+ <xs:element name="subjectUri" type="xs:string" />\r
+ <xs:element name="objectUri" type="xs:string" />\r
+\r
+ <xs:element name="subjectRefName" type="xs:string" />\r
+ <xs:element name="objectRefName" type="xs:string" />\r
+\r
+ <!-- enumeration defining the type of relationship between two entities -->\r
+ <xs:simpleType name="RelationshipType">\r
+ <xs:restriction base="xs:string">\r
+ <!-- document with id as document-id-1 is associated with document with \r
+ id as document-id-2 -->\r
+ <xs:enumeration value="association" />\r
+ <!-- document with id as document-id-1 contains one or more document with \r
+ id as document-id-2 -->\r
+ <xs:enumeration value="contains" />\r
+ <!-- document with id as document-id-1 has parent document with id as \r
+ document-id-2 -->\r
+ <xs:enumeration value="hasBroader" />\r
+ </xs:restriction>\r
+ </xs:simpleType>\r
\r
</xs:schema>\r
\r