From a24df5897de357219657cf0d88d1ce4db5612838 Mon Sep 17 00:00:00 2001 From: Richard Millet Date: Fri, 4 May 2012 18:46:27 -0700 Subject: [PATCH] CSPACE-5036 --- .../test/RelationIntegrationTest.java | 61 ++++++--- .../client/java/RepositoryJavaClientImpl.java | 61 +++++---- .../resources/schemas/relations_common.xsd | 125 +++++++++--------- 3 files changed, 143 insertions(+), 104 deletions(-) diff --git a/services/IntegrationTests/src/test/java/org/collectionspace/services/IntegrationTests/test/RelationIntegrationTest.java b/services/IntegrationTests/src/test/java/org/collectionspace/services/IntegrationTests/test/RelationIntegrationTest.java index 1e7a46faa..523a23ae4 100644 --- a/services/IntegrationTests/src/test/java/org/collectionspace/services/IntegrationTests/test/RelationIntegrationTest.java +++ b/services/IntegrationTests/src/test/java/org/collectionspace/services/IntegrationTests/test/RelationIntegrationTest.java @@ -145,8 +145,7 @@ public class RelationIntegrationTest extends CollectionSpaceIntegrationTest { // 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 = collectionObjectClient.create(multipart); @@ -159,49 +158,77 @@ public class RelationIntegrationTest extends CollectionSpaceIntegrationTest { 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 workflowResponse = dimensionClient.updateWorkflowWithTransition(dimensionCsid, WorkflowClient.WORKFLOWTRANSITION_LOCK); - System.out.println("Locked dimension record with CSID=" + dimensionCsid); + ClientResponse 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 { @@ -209,8 +236,8 @@ public class RelationIntegrationTest extends CollectionSpaceIntegrationTest { } // 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); } diff --git a/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RepositoryJavaClientImpl.java b/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RepositoryJavaClientImpl.java index de843e1bd..945509705 100644 --- a/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RepositoryJavaClientImpl.java +++ b/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RepositoryJavaClientImpl.java @@ -699,33 +699,39 @@ public class RepositoryJavaClientImpl implements RepositoryClient 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 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, @@ -754,7 +760,14 @@ public class RepositoryJavaClientImpl implements RepositoryClient - - - - - - - - - - - - - -` - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + -- 2.47.3