From 200850012bdcb10124d143db4c9fe72d8927291d Mon Sep 17 00:00:00 2001 From: Patrick Schmitz Date: Tue, 28 Feb 2012 17:46:51 -0800 Subject: [PATCH] CSPACE-4875 More work on resoruce to support getting info on one group, and fixing client test. --- services/JaxRsServiceProvider/pom.xml | 5 + .../CollectionSpaceJaxRsApplication.java | 2 + .../src/main/resources/log4j.properties | 3 +- services/build.xml | 3 + .../tenants/tenant-bindings-proto.xml | 9 ++ services/pom.xml | 1 + services/servicegroup/client/pom.xml | 11 -- .../client/test/ServiceGroupServiceTest.java | 130 +++++++++++------- .../servicegroup/ServiceGroupResource.java | 30 ++-- 9 files changed, 125 insertions(+), 69 deletions(-) diff --git a/services/JaxRsServiceProvider/pom.xml b/services/JaxRsServiceProvider/pom.xml index 574af7305..3820527a0 100644 --- a/services/JaxRsServiceProvider/pom.xml +++ b/services/JaxRsServiceProvider/pom.xml @@ -192,6 +192,11 @@ org.collectionspace.services.dimension.service ${project.version} + + org.collectionspace.services + org.collectionspace.services.servicegroup.service + ${project.version} + org.collectionspace.services org.collectionspace.services.contact.service diff --git a/services/JaxRsServiceProvider/src/main/java/org/collectionspace/services/jaxrs/CollectionSpaceJaxRsApplication.java b/services/JaxRsServiceProvider/src/main/java/org/collectionspace/services/jaxrs/CollectionSpaceJaxRsApplication.java index 7509f2328..e09dd3c2e 100644 --- a/services/JaxRsServiceProvider/src/main/java/org/collectionspace/services/jaxrs/CollectionSpaceJaxRsApplication.java +++ b/services/JaxRsServiceProvider/src/main/java/org/collectionspace/services/jaxrs/CollectionSpaceJaxRsApplication.java @@ -42,6 +42,7 @@ import org.collectionspace.services.relation.RelationResource; import org.collectionspace.services.report.ReportResource; import org.collectionspace.services.acquisition.AcquisitionResource; import org.collectionspace.services.dimension.DimensionResource; +import org.collectionspace.services.servicegroup.ServiceGroupResource; import org.collectionspace.services.contact.ContactResource; import org.collectionspace.services.vocabulary.VocabularyResource; import org.collectionspace.services.organization.OrgAuthorityResource; @@ -97,6 +98,7 @@ public class CollectionSpaceJaxRsApplication extends Application singletons.add(new AccountResource()); singletons.add(new RoleResource()); singletons.add(new PermissionResource()); + singletons.add(new ServiceGroupResource()); addResourceToMapAndSingletons(new VocabularyResource()); addResourceToMapAndSingletons(new PersonAuthorityResource()); diff --git a/services/JaxRsServiceProvider/src/main/resources/log4j.properties b/services/JaxRsServiceProvider/src/main/resources/log4j.properties index 116cee8f7..5e169f078 100644 --- a/services/JaxRsServiceProvider/src/main/resources/log4j.properties +++ b/services/JaxRsServiceProvider/src/main/resources/log4j.properties @@ -23,8 +23,9 @@ log4j.appender.R.layout.ConversionPattern=%d %-5p [%t] [%c:%L] %m%n # # CollectionSpace log levels # -log4j.logger.org.collectionspace=INFO +log4j.logger.org.collectionspace=DEBUG #log4j.logger.org.collectionspace.services.common.vocabulary.nuxeo=TRACE +log4j.logger.org.collectionspace.services.authorization=TRACE log4j.logger.perf.collectionspace=ERROR log4j.logger.org.nuxeo=INFO diff --git a/services/build.xml b/services/build.xml index 5cb7e9be8..c298a97d9 100644 --- a/services/build.xml +++ b/services/build.xml @@ -158,6 +158,7 @@ + @@ -201,6 +202,7 @@ + @@ -233,6 +235,7 @@ + diff --git a/services/common/src/main/cspace/config/services/tenants/tenant-bindings-proto.xml b/services/common/src/main/cspace/config/services/tenants/tenant-bindings-proto.xml index 7186877de..382565066 100644 --- a/services/common/src/main/cspace/config/services/tenants/tenant-bindings-proto.xml +++ b/services/common/src/main/cspace/config/services/tenants/tenant-bindings-proto.xml @@ -63,6 +63,15 @@ + + + + + + + /collectionobjects/*/workflow/ diff --git a/services/pom.xml b/services/pom.xml index 50393361a..a4599ef50 100644 --- a/services/pom.xml +++ b/services/pom.xml @@ -50,6 +50,7 @@ person id collectionobject + servicegroup group intake loanin diff --git a/services/servicegroup/client/pom.xml b/services/servicegroup/client/pom.xml index c4ff91db4..c5c1e5676 100644 --- a/services/servicegroup/client/pom.xml +++ b/services/servicegroup/client/pom.xml @@ -26,12 +26,6 @@ test - - org.collectionspace.services - org.collectionspace.services.authority.jaxb - true - ${project.version} - org.collectionspace.services org.collectionspace.services.jaxb @@ -53,11 +47,6 @@ org.collectionspace.services.servicegroup.jaxb ${project.version} - - org.collectionspace.services - org.collectionspace.services.person.client - ${project.version} - org.testng diff --git a/services/servicegroup/client/src/test/java/org/collectionspace/services/client/test/ServiceGroupServiceTest.java b/services/servicegroup/client/src/test/java/org/collectionspace/services/client/test/ServiceGroupServiceTest.java index 26ef6c287..40f0f36a0 100644 --- a/services/servicegroup/client/src/test/java/org/collectionspace/services/client/test/ServiceGroupServiceTest.java +++ b/services/servicegroup/client/src/test/java/org/collectionspace/services/client/test/ServiceGroupServiceTest.java @@ -27,6 +27,7 @@ import javax.ws.rs.core.Response; import org.collectionspace.services.client.AbstractCommonListUtils; import org.collectionspace.services.client.CollectionSpaceClient; +import org.collectionspace.services.client.PayloadInputPart; import org.collectionspace.services.client.ServiceGroupClient; import org.collectionspace.services.client.ServiceGroupProxy; import org.collectionspace.services.client.PayloadOutputPart; @@ -48,12 +49,12 @@ import org.slf4j.LoggerFactory; * $LastChangedRevision: $ * $LastChangedDate: $ */ -public class ServiceGroupServiceTest extends AbstractPoxServiceTestImpl { +public class ServiceGroupServiceTest extends BaseServiceTest { private final String CLASS_NAME = ServiceGroupServiceTest.class.getName(); private final Logger logger = LoggerFactory.getLogger(CLASS_NAME); final String SERVICE_PATH_COMPONENT = "servicegroups"; - private String knownResourceId = null; + private String readGroupName = "procedure"; @Override public String getServicePathComponent() { @@ -74,57 +75,90 @@ public class ServiceGroupServiceTest extends AbstractPoxServiceTestImpl response) { return response.getEntity(AbstractCommonList.class); } - - // --------------------------------------------------------------- - // Utility methods used by tests above - // --------------------------------------------------------------- - @Override - protected PoxPayloadOut createInstance(String identifier) { - ServiceGroupClient client = new ServiceGroupClient(); - return createInstance(client.getCommonPartName(), identifier); - } - - @Override - protected PoxPayloadOut createInstance(String commonPartName, - String identifier) { - return createServiceGroupInstance(identifier); + public ServicegroupsCommon extractCommonPartValue(CollectionSpaceClient client, + ClientResponse res) throws Exception { + + ServicegroupsCommon result = null; + PayloadInputPart payloadInputPart = extractPart(res, client.getCommonPartName()); + if (payloadInputPart != null) { + result = (ServicegroupsCommon) payloadInputPart.getBody(); + } + Assert.assertNotNull(result, + "Part or body of part " + client.getCommonPartName() + " was unexpectedly null."); + + return result; } - - private PoxPayloadOut createServiceGroupInstance(String uid) { - String identifier = "name-" + uid; - ServicegroupsCommon servicegroup = new ServicegroupsCommon(); - servicegroup.setName(identifier); - PoxPayloadOut multipart = new PoxPayloadOut(ServiceGroupClient.SERVICE_PAYLOAD_NAME); - PayloadOutputPart commonPart = multipart.addPart(servicegroup, MediaType.APPLICATION_XML_TYPE); - commonPart.setLabel(new ServiceGroupClient().getCommonPartName()); - if (logger.isDebugEnabled()) { - logger.debug("to be created, servicegroup common"); - logger.debug(objectAsXmlString(servicegroup, ServicegroupsCommon.class)); - } - - return multipart; + protected PayloadInputPart extractPart(ClientResponse res, String partLabel) + throws Exception { + if (getLogger().isDebugEnabled()) { + getLogger().debug("Reading part " + partLabel + " ..."); + } + PoxPayloadIn input = new PoxPayloadIn(res.getEntity()); + PayloadInputPart payloadInputPart = input.getPart(partLabel); + Assert.assertNotNull(payloadInputPart, + "Part " + partLabel + " was unexpectedly null."); + return payloadInputPart; } - @Override - public void CRUDTests(String testName) { - // TODO Auto-generated method stub - - } - @Override - protected ServicegroupsCommon updateInstance(ServicegroupsCommon servicegroupsCommon) { - ServicegroupsCommon result = new ServicegroupsCommon(); - - result.setName("updated-" + servicegroupsCommon.getName()); - - return result; - } + @Test(dataProvider = "testName", dependsOnMethods = {"readList"}) + public void read(String testName) throws Exception { + // Perform setup. + setupRead(); - @Override - protected void compareUpdatedInstances(ServicegroupsCommon original, - ServicegroupsCommon updated) throws Exception { - Assert.assertEquals(updated.getName(), original.getName()); - } + // Submit the request to the service and store the response. + CollectionSpaceClient client = this.getClientInstance(); + ClientResponse res = client.read(readGroupName); + int statusCode = res.getStatus(); + + // Check the status code of the response: does it match + // the expected response(s)? + if (logger.isDebugEnabled()) { + logger.debug(testName + ": status = " + statusCode); + } + Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), + invalidStatusCodeMessage(testRequestType, statusCode)); + Assert.assertEquals(statusCode, testExpectedStatusCode); + + ServicegroupsCommon output = extractCommonPartValue(client, res); + Assert.assertNotNull(output); + + // + // Now compare with the expected field values + // + Assert.assertEquals(output.getName(), readGroupName, + "Display name in updated object did not match submitted data."); + } + + + @Test(dataProvider = "testName") + public void readList(String testName) throws Exception { + // Perform setup. + setupReadList(); + + // Submit the request to the service and store the response. + CollectionSpaceClient client = this.getClientInstance(); + ClientResponse res = client.readList(); + AbstractCommonList list = res.getEntity(); + int statusCode = res.getStatus(); + + // Check the status code of the response: does it match + // the expected response(s)? + if (logger.isDebugEnabled()) { + logger.debug(testName + ": status = " + statusCode); + } + Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), + invalidStatusCodeMessage(testRequestType, statusCode)); + Assert.assertEquals(statusCode, testExpectedStatusCode); + + // Optionally output additional data about list members for debugging. + boolean iterateThroughList = true; + if (iterateThroughList && logger.isTraceEnabled()) { + AbstractCommonListUtils.ListItemsInAbstractCommonList(list, getLogger(), testName); + } + } + + } diff --git a/services/servicegroup/service/src/main/java/org/collectionspace/services/servicegroup/ServiceGroupResource.java b/services/servicegroup/service/src/main/java/org/collectionspace/services/servicegroup/ServiceGroupResource.java index b8f7a08d6..a59bd93fa 100644 --- a/services/servicegroup/service/src/main/java/org/collectionspace/services/servicegroup/ServiceGroupResource.java +++ b/services/servicegroup/service/src/main/java/org/collectionspace/services/servicegroup/ServiceGroupResource.java @@ -33,6 +33,7 @@ import org.collectionspace.services.client.PoxPayloadOut; import org.collectionspace.services.client.ServiceGroupClient; import org.collectionspace.services.jaxb.AbstractCommonList; import org.collectionspace.services.common.AbstractCollectionSpaceResourceImpl; +import org.collectionspace.services.common.ResourceBase; import org.collectionspace.services.common.ServiceMessages; import org.collectionspace.services.common.api.Tools; import org.collectionspace.services.common.context.RemoteServiceContextFactory; @@ -68,6 +69,10 @@ public class ServiceGroupResource extends AbstractCollectionSpaceResourceImpl { return ServiceGroupClient.SERVICE_NAME; } + public String getServicePathComponent(){ + return ServiceGroupClient.SERVICE_NAME.toLowerCase(); + } + @Override protected String getVersionString() { final String lastChangeRevision = "$LastChangedRevision: 2108 $"; @@ -91,30 +96,37 @@ public class ServiceGroupResource extends AbstractCollectionSpaceResourceImpl { //======================= GET ==================================================== - /* + // NOTE that csid is not a good name for the specifier, but if we name it anything else, + // our AuthZ gets confused!!! @GET - @Path("{groupname}") + @Path("{csid}") public byte[] get( @Context UriInfo ui, - @PathParam("csid") String csid) { + @PathParam("csid") String groupname) { PoxPayloadOut result = null; - ensureCSID(csid, READ); + ensureCSID(groupname, ResourceBase.READ); try { - MultivaluedMap queryParams = ui.getQueryParameters(); - ServiceContext ctx = createServiceContext(queryParams); - result = Need to fetch info and prepare it. + ServiceContext ctx = createServiceContext(); + ServicegroupsCommon common = new ServicegroupsCommon(); + common.setName(groupname); + String uri = "/" + getServicePathComponent() + "/" + groupname; + common.setUri(uri); + result = new PoxPayloadOut(getServicePathComponent()); + result.addPart("ServicegroupsCommon", common); + + /* If we cannot get the result, then... if (result == null) { Response response = Response.status(Response.Status.NOT_FOUND).entity( ServiceMessages.READ_FAILED + ServiceMessages.resourceNotFoundMsg(csid)).type("text/plain").build(); throw new WebApplicationException(response); } + */ } catch (Exception e) { - throw bigReThrow(e, ServiceMessages.READ_FAILED, csid); + throw bigReThrow(e, ServiceMessages.READ_FAILED, groupname); } return result.getBytes(); } - */ //======================= GET without specifier: List ===================================== -- 2.47.3