From 999942140b52fa15a3d667852b7901d52cee475b Mon Sep 17 00:00:00 2001 From: Michael Ritter Date: Wed, 10 Feb 2021 12:24:05 -0700 Subject: [PATCH] DRYD-943: Add Transport Procedure --- services/JaxRsServiceProvider/pom.xml | 5 + .../CollectionSpaceJaxRsApplication.java | 2 + services/build.xml | 3 + .../db/postgresql/load_id_generators.sql | 36 ++ services/pom.xml | 1 + services/transport/3rdparty/build.xml | 129 ++++ .../nuxeo-platform-cs-transport/build.xml | 159 +++++ .../nuxeo-platform-cs-transport/pom.xml | 54 ++ .../src/main/resources/OSGI-INF/README.txt | 16 + .../src/main/resources/schemas/README.txt | 16 + services/transport/3rdparty/pom.xml | 24 + services/transport/build.xml | 123 ++++ services/transport/client/pom.xml | 81 +++ .../services/client/TransportClient.java | 63 ++ .../services/client/TransportProxy.java | 33 ++ .../client/test/TransportServiceTest.java | 553 ++++++++++++++++++ services/transport/jaxb/pom.xml | 33 ++ .../services/TransportJAXBSchema.java | 26 + .../services/TransportListItemJAXBSchema.java | 28 + .../src/main/resources/transports-common.xsd | 34 ++ services/transport/pom.xml | 23 + services/transport/service/pom.xml | 96 +++ .../services/transport/TransportResource.java | 55 ++ .../transport/nuxeo/TransportConstants.java | 34 ++ .../nuxeo/TransportDocumentModelHandler.java | 28 + .../nuxeo/TransportValidatorHandler.java | 39 ++ .../services/test/TransportServiceTest.java | 29 + 27 files changed, 1723 insertions(+) create mode 100644 services/transport/3rdparty/build.xml create mode 100644 services/transport/3rdparty/nuxeo-platform-cs-transport/build.xml create mode 100644 services/transport/3rdparty/nuxeo-platform-cs-transport/pom.xml create mode 100644 services/transport/3rdparty/nuxeo-platform-cs-transport/src/main/resources/OSGI-INF/README.txt create mode 100644 services/transport/3rdparty/nuxeo-platform-cs-transport/src/main/resources/schemas/README.txt create mode 100644 services/transport/3rdparty/pom.xml create mode 100644 services/transport/build.xml create mode 100644 services/transport/client/pom.xml create mode 100644 services/transport/client/src/main/java/org/collectionspace/services/client/TransportClient.java create mode 100644 services/transport/client/src/main/java/org/collectionspace/services/client/TransportProxy.java create mode 100644 services/transport/client/src/test/java/org/collectionspace/services/client/test/TransportServiceTest.java create mode 100644 services/transport/jaxb/pom.xml create mode 100644 services/transport/jaxb/src/main/java/org/collectionspace/services/TransportJAXBSchema.java create mode 100644 services/transport/jaxb/src/main/java/org/collectionspace/services/TransportListItemJAXBSchema.java create mode 100644 services/transport/jaxb/src/main/resources/transports-common.xsd create mode 100644 services/transport/pom.xml create mode 100644 services/transport/service/pom.xml create mode 100644 services/transport/service/src/main/java/org/collectionspace/services/transport/TransportResource.java create mode 100644 services/transport/service/src/main/java/org/collectionspace/services/transport/nuxeo/TransportConstants.java create mode 100644 services/transport/service/src/main/java/org/collectionspace/services/transport/nuxeo/TransportDocumentModelHandler.java create mode 100644 services/transport/service/src/main/java/org/collectionspace/services/transport/nuxeo/TransportValidatorHandler.java create mode 100644 services/transport/service/src/test/java/org/collectionspace/services/test/TransportServiceTest.java diff --git a/services/JaxRsServiceProvider/pom.xml b/services/JaxRsServiceProvider/pom.xml index 0b7fc1da6..5347caf72 100644 --- a/services/JaxRsServiceProvider/pom.xml +++ b/services/JaxRsServiceProvider/pom.xml @@ -203,6 +203,11 @@ org.collectionspace.services.loanout.service ${project.version} + + org.collectionspace.services + org.collectionspace.services.transport.service + ${project.version} + org.collectionspace.services org.collectionspace.services.uoc.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 e675a2f75..414eab9e8 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 @@ -33,6 +33,7 @@ import org.collectionspace.services.intake.IntakeResource; import org.collectionspace.services.index.IndexResource; import org.collectionspace.services.loanin.LoaninResource; import org.collectionspace.services.loanout.LoanoutResource; +import org.collectionspace.services.transport.TransportResource; import org.collectionspace.services.uoc.UocResource; import org.collectionspace.services.valuationcontrol.ValuationcontrolResource; import org.collectionspace.services.objectexit.ObjectExitResource; @@ -152,6 +153,7 @@ public class CollectionSpaceJaxRsApplication extends Application addResourceToMapAndSingletons(new ClaimResource()); addResourceToMapAndSingletons(new ReportResource()); addResourceToMapAndSingletons(new PublicItemResource()); + addResourceToMapAndSingletons(new TransportResource()); singletons.add(new IDResource()); diff --git a/services/build.xml b/services/build.xml index 0e2e2c478..067d84b9b 100644 --- a/services/build.xml +++ b/services/build.xml @@ -199,6 +199,7 @@ + @@ -210,6 +211,7 @@ + @@ -289,6 +291,7 @@ + diff --git a/services/common/src/main/resources/db/postgresql/load_id_generators.sql b/services/common/src/main/resources/db/postgresql/load_id_generators.sql index 0ada35056..22bc96f55 100644 --- a/services/common/src/main/resources/db/postgresql/load_id_generators.sql +++ b/services/common/src/main/resources/db/postgresql/load_id_generators.sql @@ -947,3 +947,39 @@ INSERT INTO id_generators SELECT csid FROM id_generators ); + +-- TRANSPORT_REFERENCE_NUMBER + +INSERT INTO id_generators + (csid, displayname, description, priority, last_generated_id, id_generator_state) + SELECT + 'cc92bbc1-014a-4673-a81d-0c14375375d0', + 'Transport Reference Number', + 'Identifies a Transport.', + '9', + '', + ' + + + TR + TR + + + + + + . + . + + + 6 + 1 + -1 + + + ' + WHERE 'cc92bbc1-014a-4673-a81d-0c14375375d0' NOT IN + ( + SELECT csid + FROM id_generators + ); \ No newline at end of file diff --git a/services/pom.xml b/services/pom.xml index 51a78354f..01fb2e2f4 100644 --- a/services/pom.xml +++ b/services/pom.xml @@ -69,6 +69,7 @@ claim exhibition osteology + transport conditioncheck conservation valuationcontrol diff --git a/services/transport/3rdparty/build.xml b/services/transport/3rdparty/build.xml new file mode 100644 index 000000000..66ecf1a19 --- /dev/null +++ b/services/transport/3rdparty/build.xml @@ -0,0 +1,129 @@ + + + transport service 3rdparty + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/services/transport/3rdparty/nuxeo-platform-cs-transport/build.xml b/services/transport/3rdparty/nuxeo-platform-cs-transport/build.xml new file mode 100644 index 000000000..8ee78eb08 --- /dev/null +++ b/services/transport/3rdparty/nuxeo-platform-cs-transport/build.xml @@ -0,0 +1,159 @@ + + + + transport nuxeo document type + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/services/transport/3rdparty/nuxeo-platform-cs-transport/pom.xml b/services/transport/3rdparty/nuxeo-platform-cs-transport/pom.xml new file mode 100644 index 000000000..c0bcd4a75 --- /dev/null +++ b/services/transport/3rdparty/nuxeo-platform-cs-transport/pom.xml @@ -0,0 +1,54 @@ + + + + org.collectionspace.services + org.collectionspace.services.transport.3rdparty + ${revision} + + + 4.0.0 + org.collectionspace.services.transport.3rdparty.nuxeo + services.transport.3rdparty.nuxeo + jar + + Transport Nuxeo Document Type + + + + transport + Transport + transports_common + cs_default + + + + + + src/main/resources + true + + + ../../../../3rdparty/nuxeo/nuxeo-doctype/src/main/resources + true + + + + + org.apache.maven.plugins + maven-jar-plugin + + + target/classes/META-INF/MANIFEST.MF + + ${eclipseVersion} + 2 + + + + + + + + diff --git a/services/transport/3rdparty/nuxeo-platform-cs-transport/src/main/resources/OSGI-INF/README.txt b/services/transport/3rdparty/nuxeo-platform-cs-transport/src/main/resources/OSGI-INF/README.txt new file mode 100644 index 000000000..5f304de86 --- /dev/null +++ b/services/transport/3rdparty/nuxeo-platform-cs-transport/src/main/resources/OSGI-INF/README.txt @@ -0,0 +1,16 @@ +Files formerly located in this directory are no longer needed +------------------------------------------------------------- + +In CollectionSpace versions 4.0 and higher, changes were introduced +which streamline and simplify the process through which you configure +fields in CollectionSpace's main record types. + +In most cases now, you will typically change the behavior of existing fields, +or create extension schemas to add new fields specific to your museum and/or +community of practice, merely by editing simpler XML-based configuration +files within CollectionSpace's Application layer. + +Services layer files that were formerly located in this directory and +other, similar directories - which you previously needed to manually +create or edit - are now generated automatically from your configuration +in the Application layer. diff --git a/services/transport/3rdparty/nuxeo-platform-cs-transport/src/main/resources/schemas/README.txt b/services/transport/3rdparty/nuxeo-platform-cs-transport/src/main/resources/schemas/README.txt new file mode 100644 index 000000000..5f304de86 --- /dev/null +++ b/services/transport/3rdparty/nuxeo-platform-cs-transport/src/main/resources/schemas/README.txt @@ -0,0 +1,16 @@ +Files formerly located in this directory are no longer needed +------------------------------------------------------------- + +In CollectionSpace versions 4.0 and higher, changes were introduced +which streamline and simplify the process through which you configure +fields in CollectionSpace's main record types. + +In most cases now, you will typically change the behavior of existing fields, +or create extension schemas to add new fields specific to your museum and/or +community of practice, merely by editing simpler XML-based configuration +files within CollectionSpace's Application layer. + +Services layer files that were formerly located in this directory and +other, similar directories - which you previously needed to manually +create or edit - are now generated automatically from your configuration +in the Application layer. diff --git a/services/transport/3rdparty/pom.xml b/services/transport/3rdparty/pom.xml new file mode 100644 index 000000000..f3b4d5bfd --- /dev/null +++ b/services/transport/3rdparty/pom.xml @@ -0,0 +1,24 @@ + + + org.collectionspace.services.transport + org.collectionspace.services + ${revision} + + + 4.0.0 + org.collectionspace.services.transport.3rdparty + services.transport.3rdparty + pom + + + 3rd party build for transport service + + + + + + diff --git a/services/transport/build.xml b/services/transport/build.xml new file mode 100644 index 000000000..c7d183485 --- /dev/null +++ b/services/transport/build.xml @@ -0,0 +1,123 @@ + + + transport service + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/services/transport/client/pom.xml b/services/transport/client/pom.xml new file mode 100644 index 000000000..4a72870df --- /dev/null +++ b/services/transport/client/pom.xml @@ -0,0 +1,81 @@ + + + + org.collectionspace.services + org.collectionspace.services.transport + ${revision} + + + 4.0.0 + org.collectionspace.services.transport.client + services.transport.client + + + + + org.collectionspace.services + org.collectionspace.services.authority.jaxb + true + ${project.version} + + + org.collectionspace.services + org.collectionspace.services.jaxb + ${project.version} + + + org.collectionspace.services + org.collectionspace.services.common + true + + + org.collectionspace.services + org.collectionspace.services.client + ${project.version} + + + org.collectionspace.services + org.collectionspace.services.transport.jaxb + ${project.version} + + + org.collectionspace.services + org.collectionspace.services.person.client + ${project.version} + + + + org.testng + testng + + + org.jboss.resteasy + resteasy-jaxrs + + + + tjws + webserver + + + + + org.jboss.resteasy + resteasy-jaxb-provider + + + org.jboss.resteasy + resteasy-multipart-provider + + + commons-httpclient + commons-httpclient + + + + + collectionspace-services-transport-client + + diff --git a/services/transport/client/src/main/java/org/collectionspace/services/client/TransportClient.java b/services/transport/client/src/main/java/org/collectionspace/services/client/TransportClient.java new file mode 100644 index 000000000..a585184af --- /dev/null +++ b/services/transport/client/src/main/java/org/collectionspace/services/client/TransportClient.java @@ -0,0 +1,63 @@ +/* + * 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 + + * 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 + + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.collectionspace.services.client; + +import org.collectionspace.services.transport.TransportsCommon; + +/** + * TransportClient.java + */ +public class TransportClient extends AbstractCommonListPoxServiceClientImpl { + + public static final String SERVICE_NAME = "transports"; + public static final String SERVICE_PATH_COMPONENT = SERVICE_NAME; + public static final String SERVICE_PATH = "/" + SERVICE_PATH_COMPONENT; + public static final String SERVICE_PATH_PROXY = SERVICE_PATH + "/"; + public static final String SERVICE_PAYLOAD_NAME = SERVICE_NAME; + + public TransportClient() throws Exception { + super(); + } + + public TransportClient(String clientPropertiesFilename) throws Exception { + super(clientPropertiesFilename); + } + + /* (non-Javadoc) + * @see org.collectionspace.services.client.AbstractServiceClientImpl#getServicePathComponent() + */ + @Override + public String getServicePathComponent() { + return SERVICE_PATH_COMPONENT; + } + + @Override + public String getServiceName() { + return SERVICE_NAME; + } + + @Override + public Class getProxyClass() { + return TransportProxy.class; + } + +} diff --git a/services/transport/client/src/main/java/org/collectionspace/services/client/TransportProxy.java b/services/transport/client/src/main/java/org/collectionspace/services/client/TransportProxy.java new file mode 100644 index 000000000..67694c0f0 --- /dev/null +++ b/services/transport/client/src/main/java/org/collectionspace/services/client/TransportProxy.java @@ -0,0 +1,33 @@ +/* + * 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 + + * 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 + + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.collectionspace.services.client; + +import javax.ws.rs.Consumes; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; + + +@Path(TransportClient.SERVICE_PATH_PROXY) +@Produces({"application/xml"}) +@Consumes({"application/xml"}) +public interface TransportProxy extends CollectionSpaceCommonListPoxProxy { +} diff --git a/services/transport/client/src/test/java/org/collectionspace/services/client/test/TransportServiceTest.java b/services/transport/client/src/test/java/org/collectionspace/services/client/test/TransportServiceTest.java new file mode 100644 index 000000000..833b51e2a --- /dev/null +++ b/services/transport/client/src/test/java/org/collectionspace/services/client/test/TransportServiceTest.java @@ -0,0 +1,553 @@ +/* + * 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 + + * 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 + + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.collectionspace.services.client.test; + +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.PayloadOutputPart; +import org.collectionspace.services.client.PoxPayloadIn; +import org.collectionspace.services.client.PoxPayloadOut; +import org.collectionspace.services.client.TransportClient; +import org.collectionspace.services.jaxb.AbstractCommonList; +import org.collectionspace.services.transport.TransportsCommon; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.testng.Assert; + +public class TransportServiceTest extends AbstractPoxServiceTestImpl { + + /** The logger. */ + private final String CLASS_NAME = TransportServiceTest.class.getName(); + private final Logger logger = LoggerFactory.getLogger(CLASS_NAME); + // Instance variables specific to this test. + /** The service path component. */ + final String SERVICE_NAME = "transports"; + final String SERVICE_PATH_COMPONENT = "transports"; + + + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.BaseServiceTest#getAbstractCommonList(org.jboss.resteasy.client.ClientResponse) + */ + @Override + protected AbstractCommonList getCommonList(Response response) { + return response.readEntity(AbstractCommonList.class); + } + + // --------------------------------------------------------------- + // CRUD tests : CREATE tests + // --------------------------------------------------------------- + + // Success outcomes + + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.ServiceTest#create(java.lang.String) + */ + @Override + // @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class) + public void create(String testName) throws Exception { + // Perform setup, such as initializing the type of service request + // (e.g. CREATE, DELETE), its valid and expected status codes, and + // its associated HTTP method name (e.g. POST, DELETE). + setupCreate(); + + // Submit the request to the service and store the response. + TransportClient client = new TransportClient(); + String identifier = createIdentifier(); + PoxPayloadOut multipart = createTransportInstance(identifier); + String newID = null; + Response res = client.create(multipart); + try { + int statusCode = res.getStatus(); + + // Check the status code of the response: does it match + // the expected response(s)? + // + // Specifically: + // Does it fall within the set of valid status codes? + // Does it exactly match the expected status code? + if (logger.isDebugEnabled()) { + logger.debug(testName + ": status = " + statusCode); + } + Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), + invalidStatusCodeMessage(testRequestType, statusCode)); + Assert.assertEquals(statusCode, testExpectedStatusCode); + + newID = extractId(res); + } finally { + if (res != null) { + res.close(); + } + } + + // Store the ID returned from the first resource created + // for additional tests below. + if (knownResourceId == null) { + knownResourceId = newID; + if (logger.isDebugEnabled()) { + logger.debug(testName + ": knownResourceId=" + knownResourceId); + } + } + + // Store the IDs from every resource created by tests, + // so they can be deleted after tests have been run. + allResourceIdsCreated.add(newID); + } + + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createList(java.lang.String) + */ + @Override + // @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, + // dependsOnMethods = {"create"}) + public void createList(String testName) throws Exception { + for (int i = 0; i < 3; i++) { + create(testName); + } + } + + // --------------------------------------------------------------- + // CRUD tests : READ tests + // --------------------------------------------------------------- + + // Success outcomes + + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#read(java.lang.String) + */ + @Override + // @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, + // dependsOnMethods = {"create"}) + public void read(String testName) throws Exception { + // Perform setup. + setupRead(); + + // Submit the request to the service and store the response. + TransportClient client = new TransportClient(); + Response res = client.read(knownResourceId); + PoxPayloadIn input = null; + try { + assertStatusCode(res, testName); + input = new PoxPayloadIn(res.readEntity(String.class)); + } finally { + if (res != null) { + res.close(); + } + } + + // Get the common part of the response and verify that it is not null. + PayloadInputPart payloadInputPart = input.getPart(client.getCommonPartName()); + TransportsCommon transportCommon = null; + if (payloadInputPart != null) { + transportCommon = (TransportsCommon) payloadInputPart.getBody(); + } + Assert.assertNotNull(transportCommon); + } + + // Failure outcomes + + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readNonExistent(java.lang.String) + */ + @Override + // @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, + // dependsOnMethods = {"read"}) + public void readNonExistent(String testName) throws Exception { + // Perform setup. + setupReadNonExistent(); + + // Submit the request to the service and store the response. + TransportClient client = new TransportClient(); + Response res = client.read(NON_EXISTENT_ID); + try { + 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); + } finally { + if (res != null) { + res.close(); + } + } + } + + // --------------------------------------------------------------- + // CRUD tests : READ_LIST tests + // --------------------------------------------------------------- + + // Success outcomes + + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readList(java.lang.String) + */ + @Override + // @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, + // dependsOnMethods = {"createList", "read"}) + public void readList(String testName) throws Exception { + // Perform setup. + setupReadList(); + + // Submit the request to the service and store the response. + AbstractCommonList list = null; + TransportClient client = new TransportClient(); + Response res = client.readList(); + assertStatusCode(res, testName); + try { + 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); + + list = res.readEntity(getCommonListType()); + } finally { + if (res != null) { + res.close(); + } + } + + // Optionally output additional data about list members for debugging. + boolean iterateThroughList = true; + if(iterateThroughList && logger.isDebugEnabled()){ + AbstractCommonListUtils.ListItemsInAbstractCommonList(list, logger, testName); + } + + } + + // Failure outcomes + // None at present. + + // --------------------------------------------------------------- + // CRUD tests : UPDATE tests + // --------------------------------------------------------------- + + // Success outcomes + + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#update(java.lang.String) + */ + @Override + // @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, + // dependsOnMethods = {"read"}) + public void update(String testName) throws Exception { + // Perform setup. + setupRead(); + + // Retrieve the contents of a resource to update. + TransportClient client = new TransportClient(); + Response res = client.read(knownResourceId); + PoxPayloadIn input = null; + try { + assertStatusCode(res, testName); + input = new PoxPayloadIn(res.readEntity(String.class)); + if (logger.isDebugEnabled()) { + logger.debug("got object to update with ID: " + knownResourceId); + } + } finally { + if (res != null) { + res.close(); + } + } + + // Extract the common part from the response. + PayloadInputPart payloadInputPart = input.getPart(client.getCommonPartName()); + TransportsCommon transportCommon = null; + if (payloadInputPart != null) { + transportCommon = (TransportsCommon) payloadInputPart.getBody(); + } + Assert.assertNotNull(transportCommon); + + // Update the content of this resource. + transportCommon.setTransportReferenceNumber("updated-" + transportCommon.getTransportReferenceNumber()); + + if (logger.isDebugEnabled()) { + logger.debug("to be updated object"); + logger.debug(objectAsXmlString(transportCommon, TransportsCommon.class)); + } + + setupUpdate(); + + // Submit the updated common part in an update request to the service + // and store the response. + PoxPayloadOut output = new PoxPayloadOut(this.getServicePathComponent()); + PayloadOutputPart commonPart = output.addPart(client.getCommonPartName(), transportCommon); + res = client.update(knownResourceId, output); + try { + assertStatusCode(res, testName); + 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); + input = new PoxPayloadIn(res.readEntity(String.class)); + } finally { + if (res != null) { + res.close(); + } + } + + // Extract the updated common part from the response. + payloadInputPart = input.getPart(client.getCommonPartName()); + TransportsCommon updatedTransportCommon = null; + if (payloadInputPart != null) { + updatedTransportCommon = (TransportsCommon) payloadInputPart.getBody(); + } + Assert.assertNotNull(updatedTransportCommon); + + // Check selected fields in the updated common part. + Assert.assertEquals(updatedTransportCommon.getTransportReferenceNumber(), + transportCommon.getTransportReferenceNumber(), + "Data in updated object did not match submitted data."); + } + + @Override + // @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, + // dependsOnMethods = {"update", "testSubmitRequest"}) + public void updateNonExistent(String testName) throws Exception { + // Perform setup. + setupUpdateNonExistent(); + + // Submit the request to the service and store the response. + // Note: The ID used in this 'create' call may be arbitrary. + // The only relevant ID may be the one used in update(), below. + TransportClient client = new TransportClient(); + PoxPayloadOut multipart = createTransportInstance(NON_EXISTENT_ID); + Response res = client.update(NON_EXISTENT_ID, multipart); + try { + 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); + } finally { + if (res != null) { + res.close(); + } + } + } + + // --------------------------------------------------------------- + // CRUD tests : DELETE tests + // --------------------------------------------------------------- + + // Success outcomes + + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#delete(java.lang.String) + */ + @Override + // @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, + // dependsOnMethods = {"create", "readList", "testSubmitRequest", "update"}) + public void delete(String testName) throws Exception { + // Perform setup. + setupDelete(); + + // Submit the request to the service and store the response. + TransportClient client = new TransportClient(); + Response res = client.delete(knownResourceId); + try { + 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); + } finally { + if (res != null) { + res.close(); + } + } + } + + // Failure outcomes + + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#deleteNonExistent(java.lang.String) + */ + @Override + // @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, + // dependsOnMethods = {"delete"}) + public void deleteNonExistent(String testName) throws Exception { + // Perform setup. + setupDeleteNonExistent(); + + // Submit the request to the service and store the response. + TransportClient client = new TransportClient(); + Response res = client.delete(NON_EXISTENT_ID); + try { + 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); + } finally { + if (res != null) { + res.close(); + } + } + } + + // --------------------------------------------------------------- + // Utility tests : tests of code used in tests above + // --------------------------------------------------------------- + + /** + * Tests the code for manually submitting data that is used by several + * of the methods above. + */ + // @Test(dependsOnMethods = {"create", "read"}) + public void testSubmitRequest() { + + // Expected status code: 200 OK + final int EXPECTED_STATUS = Response.Status.OK.getStatusCode(); + + // Submit the request to the service and store the response. + String method = ServiceRequestType.READ.httpMethodName(); + String url = getResourceURL(knownResourceId); + int statusCode = submitRequest(method, url); + + // Check the status code of the response: does it match + // the expected response(s)? + if (logger.isDebugEnabled()) { + logger.debug("testSubmitRequest: url=" + url + + " status=" + statusCode); + } + Assert.assertEquals(statusCode, EXPECTED_STATUS); + + } + + // --------------------------------------------------------------- + // Utility methods used by tests above + // --------------------------------------------------------------- + + @Override + protected PoxPayloadOut createInstance(String identifier) throws Exception { + return createTransportInstance(identifier); + } + + /** + * Creates the transport instance. + * + * @param transportNumber the transport number + * @return the multipart output + * @throws Exception + */ + private PoxPayloadOut createTransportInstance(String transportNumber) throws Exception { + + TransportsCommon transportCommon = new TransportsCommon(); + transportCommon.setTransportReferenceNumber(transportNumber); + // transportCommon.setDestination(getUTF8DataFragment()); + + PoxPayloadOut multipart = new PoxPayloadOut(this.getServicePathComponent()); + PayloadOutputPart commonPart = + multipart.addPart(new TransportClient().getCommonPartName(), transportCommon); + + if (logger.isDebugEnabled()) { + logger.debug("to be created, transport common"); + logger.debug(objectAsXmlString(transportCommon, TransportsCommon.class)); + } + + return multipart; + } + + @Override + public void CRUDTests(String testName) { + // TODO Auto-generated method stub + + } + + @Override + protected PoxPayloadOut createInstance(String commonPartName, + String identifier) throws Exception { + PoxPayloadOut result = createTransportInstance(identifier); + return result; + } + + @Override + protected TransportsCommon updateInstance(TransportsCommon commonPartObject) { + // TODO Auto-generated method stub + return null; + } + + @Override + protected void compareUpdatedInstances(TransportsCommon original, + TransportsCommon updated) throws Exception { + // TODO Auto-generated method stub + + } + + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.BaseServiceTest#getClientInstance() + */ + @Override + protected CollectionSpaceClient getClientInstance() throws Exception { + return new TransportClient(); + } + + @Override + protected CollectionSpaceClient getClientInstance(String clientPropertiesFilename) throws Exception { + return new TransportClient(clientPropertiesFilename); + } + + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.BaseServiceTest#getServicePathComponent() + */ + @Override + protected String getServicePathComponent() throws Exception { + return SERVICE_PATH_COMPONENT; + } + + @Override + protected String getServiceName() { + return SERVICE_NAME; + } +} diff --git a/services/transport/jaxb/pom.xml b/services/transport/jaxb/pom.xml new file mode 100644 index 000000000..ba80ae541 --- /dev/null +++ b/services/transport/jaxb/pom.xml @@ -0,0 +1,33 @@ + + + + org.collectionspace.services.transport + org.collectionspace.services + ${revision} + + + 4.0.0 + org.collectionspace.services.transport.jaxb + services.transport.jaxb + + + + org.collectionspace.services + org.collectionspace.services.jaxb + ${project.version} + + + + + collectionspace-services-transport-jaxb + install + + + org.jvnet.jaxb2.maven2 + maven-jaxb2-plugin + + + + diff --git a/services/transport/jaxb/src/main/java/org/collectionspace/services/TransportJAXBSchema.java b/services/transport/jaxb/src/main/java/org/collectionspace/services/TransportJAXBSchema.java new file mode 100644 index 000000000..39142badc --- /dev/null +++ b/services/transport/jaxb/src/main/java/org/collectionspace/services/TransportJAXBSchema.java @@ -0,0 +1,26 @@ +/* + * 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 + + * 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 + + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.collectionspace.services; + +public interface TransportJAXBSchema { + String TRANSPORT_REFERENCE_NUMBER = "transportReferenceNumber"; +} diff --git a/services/transport/jaxb/src/main/java/org/collectionspace/services/TransportListItemJAXBSchema.java b/services/transport/jaxb/src/main/java/org/collectionspace/services/TransportListItemJAXBSchema.java new file mode 100644 index 000000000..1c3ac7912 --- /dev/null +++ b/services/transport/jaxb/src/main/java/org/collectionspace/services/TransportListItemJAXBSchema.java @@ -0,0 +1,28 @@ +/* + * 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 + + * 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 + + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.collectionspace.services; + +public interface TransportListItemJAXBSchema { + String TRANSPORT_REFERENCE_NUMBER = "transportReferenceNumber"; + String CSID = "csid"; + String URI = "url"; +} diff --git a/services/transport/jaxb/src/main/resources/transports-common.xsd b/services/transport/jaxb/src/main/resources/transports-common.xsd new file mode 100644 index 000000000..5084ed8c5 --- /dev/null +++ b/services/transport/jaxb/src/main/resources/transports-common.xsd @@ -0,0 +1,34 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/services/transport/pom.xml b/services/transport/pom.xml new file mode 100644 index 000000000..5e348b453 --- /dev/null +++ b/services/transport/pom.xml @@ -0,0 +1,23 @@ + + + + org.collectionspace.services + org.collectionspace.services.main + ${revision} + + + 4.0.0 + org.collectionspace.services.transport + services.transport + pom + + + jaxb + service + 3rdparty + client + + + diff --git a/services/transport/service/pom.xml b/services/transport/service/pom.xml new file mode 100644 index 000000000..e5993e163 --- /dev/null +++ b/services/transport/service/pom.xml @@ -0,0 +1,96 @@ + + + + + org.collectionspace.services + org.collectionspace.services.transport + ${revision} + + + 4.0.0 + org.collectionspace.services.transport.service + services.transport.service + jar + + + + org.collectionspace.services + org.collectionspace.services.common + + + org.collectionspace.services + org.collectionspace.services.transport.jaxb + ${project.version} + + + org.collectionspace.services + org.collectionspace.services.transport.client + ${project.version} + + + org.collectionspace.services + org.collectionspace.services.collectionobject.jaxb + ${project.version} + + + + junit + junit + test + + + org.testng + testng + + + + + + javax.security + jaas + 1.0.01 + provided + + + + + + org.jboss.resteasy + resteasy-jaxrs + + + tjws + webserver + + + + + org.jboss.resteasy + resteasy-jaxb-provider + + + org.jboss.resteasy + resteasy-multipart-provider + + + + + + org.nuxeo.ecm.core + nuxeo-core-api + + + jboss-remoting + jboss + + + + + + + + collectionspace-services-transport + + diff --git a/services/transport/service/src/main/java/org/collectionspace/services/transport/TransportResource.java b/services/transport/service/src/main/java/org/collectionspace/services/transport/TransportResource.java new file mode 100644 index 000000000..82088a59c --- /dev/null +++ b/services/transport/service/src/main/java/org/collectionspace/services/transport/TransportResource.java @@ -0,0 +1,55 @@ +/* + * 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 + + * 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 + + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.collectionspace.services.transport; + +import javax.ws.rs.Consumes; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; + +import org.collectionspace.services.client.TransportClient; +import org.collectionspace.services.common.NuxeoBasedResource; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +@Path(TransportClient.SERVICE_PATH) +@Consumes({"application/xml"}) +@Produces({"application/xml"}) +public class TransportResource extends NuxeoBasedResource { + + final Logger logger = LoggerFactory.getLogger(TransportResource.class); + + @Override + public String getServiceName() { + return TransportClient.SERVICE_NAME; + } + + @Override + public Class getCommonPartClass() { + return TransportsCommon.class; + } + + @Override + protected String getVersionString() { + final String lastChangeRevision = "$LastChangedRevision$"; + return lastChangeRevision; + } +} diff --git a/services/transport/service/src/main/java/org/collectionspace/services/transport/nuxeo/TransportConstants.java b/services/transport/service/src/main/java/org/collectionspace/services/transport/nuxeo/TransportConstants.java new file mode 100644 index 000000000..f778b921b --- /dev/null +++ b/services/transport/service/src/main/java/org/collectionspace/services/transport/nuxeo/TransportConstants.java @@ -0,0 +1,34 @@ +/* + * 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 + + * 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 + + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.collectionspace.services.transport.nuxeo; + +/** + * TransportConstants specifies constants for the Use of Collections service + * + */ +public class TransportConstants { + + public final static String NUXEO_DOCTYPE = "Transport"; + public final static String NUXEO_SCHEMA_NAME = "transport"; + public final static String NUXEO_DC_TITLE = "CollectionSpace-Transport"; + +} diff --git a/services/transport/service/src/main/java/org/collectionspace/services/transport/nuxeo/TransportDocumentModelHandler.java b/services/transport/service/src/main/java/org/collectionspace/services/transport/nuxeo/TransportDocumentModelHandler.java new file mode 100644 index 000000000..34b82cef2 --- /dev/null +++ b/services/transport/service/src/main/java/org/collectionspace/services/transport/nuxeo/TransportDocumentModelHandler.java @@ -0,0 +1,28 @@ +/* + * 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 + + * 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 + + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.collectionspace.services.transport.nuxeo; + +import org.collectionspace.services.nuxeo.client.java.NuxeoDocumentModelHandler; +import org.collectionspace.services.transport.TransportsCommon; + +public class TransportDocumentModelHandler extends NuxeoDocumentModelHandler { +} diff --git a/services/transport/service/src/main/java/org/collectionspace/services/transport/nuxeo/TransportValidatorHandler.java b/services/transport/service/src/main/java/org/collectionspace/services/transport/nuxeo/TransportValidatorHandler.java new file mode 100644 index 000000000..c261ecafe --- /dev/null +++ b/services/transport/service/src/main/java/org/collectionspace/services/transport/nuxeo/TransportValidatorHandler.java @@ -0,0 +1,39 @@ +/* + * 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 + + * 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 + + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.collectionspace.services.transport.nuxeo; + +import org.collectionspace.services.common.context.ServiceContext; +import org.collectionspace.services.common.document.DocumentHandler.Action; +import org.collectionspace.services.common.document.InvalidDocumentException; +import org.collectionspace.services.common.document.ValidatorHandler; + +public class TransportValidatorHandler implements ValidatorHandler { + + @Override + public void validate(Action action, ServiceContext ctx) + throws InvalidDocumentException { + // TODO Auto-generated method stub + System.out.println("TransportValidatorHandler executed."); + + } + +} diff --git a/services/transport/service/src/test/java/org/collectionspace/services/test/TransportServiceTest.java b/services/transport/service/src/test/java/org/collectionspace/services/test/TransportServiceTest.java new file mode 100644 index 000000000..07b089e75 --- /dev/null +++ b/services/transport/service/src/test/java/org/collectionspace/services/test/TransportServiceTest.java @@ -0,0 +1,29 @@ +/* + * 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 + + * 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 + + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.collectionspace.services.test; + +/** + * Placeholder for server-side testing of Transport service cod + */ +public class TransportServiceTest { + // empty +} -- 2.47.3