From 97ad422002c7a08c286b03d7e9041ad80cf5e9ed Mon Sep 17 00:00:00 2001 From: Michael Ritter Date: Wed, 18 Sep 2024 11:31:34 -0600 Subject: [PATCH] DRYD-1355: Deaccession Service (#424) --- services/JaxRsServiceProvider/pom.xml | 6 + .../CollectionSpaceJaxRsApplication.java | 11 +- services/build.xml | 1 + .../db/postgresql/load_id_generators.sql | 36 ++ services/deaccession/build.xml | 122 +++++ services/deaccession/client/pom.xml | 61 +++ .../services/client/DeaccessionClient.java | 51 ++ .../services/client/DeaccessionProxy.java | 27 + .../client/DeaccessionServiceTest.java | 492 ++++++++++++++++++ services/deaccession/jaxb/pom.xml | 33 ++ .../main/resources/deaccessions_common.xsd | 68 +++ services/deaccession/pom.xml | 58 +++ services/deaccession/service/pom.xml | 89 ++++ .../deaccession/DeaccessionResource.java | 49 ++ .../DeaccessionDocumentModelHandler.java | 30 ++ .../nuxeo/DeaccessionValidatorHandler.java | 64 +++ services/pom.xml | 1 + 17 files changed, 1194 insertions(+), 5 deletions(-) create mode 100644 services/deaccession/build.xml create mode 100644 services/deaccession/client/pom.xml create mode 100644 services/deaccession/client/src/main/java/org/collectionspace/services/client/DeaccessionClient.java create mode 100644 services/deaccession/client/src/main/java/org/collectionspace/services/client/DeaccessionProxy.java create mode 100644 services/deaccession/client/src/test/java/org/collectionspace/services/client/DeaccessionServiceTest.java create mode 100644 services/deaccession/jaxb/pom.xml create mode 100644 services/deaccession/jaxb/src/main/resources/deaccessions_common.xsd create mode 100644 services/deaccession/pom.xml create mode 100644 services/deaccession/service/pom.xml create mode 100644 services/deaccession/service/src/main/java/org/collectionspace/services/deaccession/DeaccessionResource.java create mode 100644 services/deaccession/service/src/main/java/org/collectionspace/services/deaccession/nuxeo/DeaccessionDocumentModelHandler.java create mode 100644 services/deaccession/service/src/main/java/org/collectionspace/services/deaccession/nuxeo/DeaccessionValidatorHandler.java diff --git a/services/JaxRsServiceProvider/pom.xml b/services/JaxRsServiceProvider/pom.xml index f93d7ecf4..4f706a66d 100644 --- a/services/JaxRsServiceProvider/pom.xml +++ b/services/JaxRsServiceProvider/pom.xml @@ -451,6 +451,12 @@ org.collectionspace.services.consultation.service ${project.version} + + org.collectionspace.services + org.collectionspace.services.deaccession.service + ${project.version} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/services/deaccession/client/pom.xml b/services/deaccession/client/pom.xml new file mode 100644 index 000000000..fd8fa0617 --- /dev/null +++ b/services/deaccession/client/pom.xml @@ -0,0 +1,61 @@ + + + + org.collectionspace.services + org.collectionspace.services.deaccession + ${revision} + + + 4.0.0 + org.collectionspace.services.deaccession.client + services.deaccession.client + + + + + org.collectionspace.services + org.collectionspace.services.client + ${project.version} + + + org.collectionspace.services + org.collectionspace.services.deaccession.jaxb + ${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-deaccession-client + + \ No newline at end of file diff --git a/services/deaccession/client/src/main/java/org/collectionspace/services/client/DeaccessionClient.java b/services/deaccession/client/src/main/java/org/collectionspace/services/client/DeaccessionClient.java new file mode 100644 index 000000000..2011e2b6d --- /dev/null +++ b/services/deaccession/client/src/main/java/org/collectionspace/services/client/DeaccessionClient.java @@ -0,0 +1,51 @@ +/* + * 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 + */ +package org.collectionspace.services.client; + +import org.collectionspace.services.deaccession.DeaccessionsCommon; + +/** + * DeaccessionClient.java + */ +public class DeaccessionClient extends AbstractCommonListPoxServiceClientImpl { + + public static final String SERVICE_NAME = "deaccessions"; + 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 DeaccessionClient() throws Exception { + super(); + } + + public DeaccessionClient(String clientPropertiesFilename) throws Exception { + super(clientPropertiesFilename); + } + + @Override + public String getServicePathComponent() { + return SERVICE_PATH_COMPONENT; + } + + @Override + public String getServiceName() { + return SERVICE_NAME; + } + + @Override + public Class getProxyClass() { + return DeaccessionProxy.class; + } +} diff --git a/services/deaccession/client/src/main/java/org/collectionspace/services/client/DeaccessionProxy.java b/services/deaccession/client/src/main/java/org/collectionspace/services/client/DeaccessionProxy.java new file mode 100644 index 000000000..4daa5aa35 --- /dev/null +++ b/services/deaccession/client/src/main/java/org/collectionspace/services/client/DeaccessionProxy.java @@ -0,0 +1,27 @@ +/* + * 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 + */ +package org.collectionspace.services.client; + +import javax.ws.rs.Consumes; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; + +/** + * DeaccessionProxy.java + */ +@Path(DeaccessionClient.SERVICE_PATH_PROXY) +@Produces({"application/xml"}) +@Consumes({"application/xml"}) +public interface DeaccessionProxy extends CollectionSpaceCommonListPoxProxy {} diff --git a/services/deaccession/client/src/test/java/org/collectionspace/services/client/DeaccessionServiceTest.java b/services/deaccession/client/src/test/java/org/collectionspace/services/client/DeaccessionServiceTest.java new file mode 100644 index 000000000..04e2e6dcf --- /dev/null +++ b/services/deaccession/client/src/test/java/org/collectionspace/services/client/DeaccessionServiceTest.java @@ -0,0 +1,492 @@ +/* + * 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 + * + * Copyright © 2009 Regents of the University of California + * + * 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.core.Response; +import org.collectionspace.services.client.test.AbstractPoxServiceTestImpl; +import org.collectionspace.services.client.test.ServiceRequestType; +import org.collectionspace.services.deaccession.DeaccessionsCommon; +import org.collectionspace.services.jaxb.AbstractCommonList; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.testng.Assert; + +public class DeaccessionServiceTest extends AbstractPoxServiceTestImpl { + + private final Logger logger = LoggerFactory.getLogger(DeaccessionServiceTest.class); + + /** The service path component. */ + final String SERVICE_NAME = "deaccessions"; + + final String SERVICE_PATH_COMPONENT = "deaccessions"; + + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.BaseServiceTest#getClientInstance() + */ + @Override + protected CollectionSpaceClient getClientInstance() throws Exception { + return new DeaccessionClient(); + } + + @Override + protected CollectionSpaceClient getClientInstance(String clientPropertiesFilename) throws Exception { + return new DeaccessionClient(clientPropertiesFilename); + } + + /* (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 + public void create(String testName) throws Exception { + DeaccessionClient client = new DeaccessionClient(); + + // 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. + String newID; + String identifier = createIdentifier(); + PoxPayloadOut multipart = createDeaccessionInstance(identifier); + 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? + logger.debug("{}: status = {}", testName, 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; + logger.debug("{}: knownResourceId={}", testName, 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 + 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 + public void read(String testName) throws Exception { + // Perform setup. + setupRead(); + + // Submit the request to the service and store the response. + DeaccessionClient client = new DeaccessionClient(); + Response res = client.read(knownResourceId); + PoxPayloadIn input; + 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()); + DeaccessionsCommon deaccessionCommon = null; + if (payloadInputPart != null) { + deaccessionCommon = (DeaccessionsCommon) payloadInputPart.getBody(); + } + Assert.assertNotNull(deaccessionCommon); + } + + // Failure outcomes + + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readNonExistent(java.lang.String) + */ + @Override + public void readNonExistent(String testName) throws Exception { + // Perform setup. + setupReadNonExistent(); + + // Submit the request to the service and store the response. + DeaccessionClient client = new DeaccessionClient(); + 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)? + logger.debug("{}: status = {}", testName, 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 + public void readList(String testName) throws Exception { + // Perform setup. + setupReadList(); + + // Submit the request to the service and store the response. + AbstractCommonList list; + DeaccessionClient client = new DeaccessionClient(); + 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)? + logger.debug("{}: status = {}", testName, statusCode); + Assert.assertTrue( + testRequestType.isValidStatusCode(statusCode), + invalidStatusCodeMessage(testRequestType, statusCode)); + Assert.assertEquals(statusCode, testExpectedStatusCode); + + list = res.readEntity(getCommonListType()); + } finally { + res.close(); + } + + // Optionally output additional data about list members for debugging. + 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 + public void update(String testName) throws Exception { + // Perform setup. + setupRead(); + + // Retrieve the contents of a resource to update. + DeaccessionClient client = new DeaccessionClient(); + Response res = client.read(knownResourceId); + PoxPayloadIn input; + try { + assertStatusCode(res, testName); + input = new PoxPayloadIn(res.readEntity(String.class)); + 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()); + DeaccessionsCommon deaccessionCommon = null; + if (payloadInputPart != null) { + deaccessionCommon = (DeaccessionsCommon) payloadInputPart.getBody(); + } + Assert.assertNotNull(deaccessionCommon); + + // Update the content of this resource. + deaccessionCommon.setDeaccessionNote("updated-" + deaccessionCommon.getDeaccessionNumber()); + + logger.debug("to be updated object"); + logger.debug(objectAsXmlString(deaccessionCommon, DeaccessionsCommon.class)); + + setupUpdate(); + + // Submit the updated common part in an update request to the service + // and store the response. + PoxPayloadOut output = new PoxPayloadOut(this.getServicePathComponent()); + output.addPart(client.getCommonPartName(), deaccessionCommon); + 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)? + logger.debug("{}: status = {}", testName, 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()); + DeaccessionsCommon updatedDeaccessionCommon = null; + if (payloadInputPart != null) { + updatedDeaccessionCommon = (DeaccessionsCommon) payloadInputPart.getBody(); + } + Assert.assertNotNull(updatedDeaccessionCommon); + + // Check selected fields in the updated common part. + Assert.assertEquals( + updatedDeaccessionCommon.getDeaccessionNumber(), + deaccessionCommon.getDeaccessionNumber(), + "Data in updated object did not match submitted data."); + } + + @Override + 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. + DeaccessionClient client = new DeaccessionClient(); + PoxPayloadOut multipart = createDeaccessionInstance(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)? + logger.debug("{}: status = {}", testName, 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 + public void delete(String testName) throws Exception { + // Perform setup. + setupDelete(); + + // Submit the request to the service and store the response. + DeaccessionClient client = new DeaccessionClient(); + Response res = client.delete(knownResourceId); + try { + int statusCode = res.getStatus(); + + // Check the status code of the response: does it match + // the expected response(s)? + logger.debug("{}: status = {}", testName, 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 + public void deleteNonExistent(String testName) throws Exception { + // Perform setup. + setupDeleteNonExistent(); + + // Submit the request to the service and store the response. + DeaccessionClient client = new DeaccessionClient(); + 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)? + logger.debug("{}: status = {}", testName, 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. + */ + 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)? + logger.debug("testSubmitRequest: url={} status={}", url, statusCode); + Assert.assertEquals(statusCode, EXPECTED_STATUS); + } + + // --------------------------------------------------------------- + // Utility methods used by tests above + // --------------------------------------------------------------- + + @Override + public String getServiceName() { + return SERVICE_NAME; + } + + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.BaseServiceTest#getServicePathComponent() + */ + @Override + public String getServicePathComponent() { + return SERVICE_PATH_COMPONENT; + } + + @Override + protected PoxPayloadOut createInstance(String identifier) throws Exception { + return createDeaccessionInstance(identifier); + } + + /** + * Creates the deaccession instance. + * + * @param deaccessionNumber the deaccession number + * @return the multipart output + * @throws Exception + */ + private PoxPayloadOut createDeaccessionInstance(String deaccessionNumber) throws Exception { + DeaccessionsCommon deaccessionCommon = new DeaccessionsCommon(); + deaccessionCommon.setDeaccessionNumber(deaccessionNumber); + + PoxPayloadOut multipart = new PoxPayloadOut(this.getServicePathComponent()); + multipart.addPart(new DeaccessionClient().getCommonPartName(), deaccessionCommon); + + logger.debug("to be created, deaccession common"); + logger.debug(objectAsXmlString(deaccessionCommon, DeaccessionsCommon.class)); + + return multipart; + } + + @Override + public void CRUDTests(String testName) {} + + @Override + protected PoxPayloadOut createInstance(String commonPartName, String identifier) throws Exception { + return createDeaccessionInstance(identifier); + } + + @Override + protected DeaccessionsCommon updateInstance(DeaccessionsCommon commonPartObject) { + return null; + } + + @Override + protected void compareUpdatedInstances(DeaccessionsCommon original, DeaccessionsCommon updated) {} +} diff --git a/services/deaccession/jaxb/pom.xml b/services/deaccession/jaxb/pom.xml new file mode 100644 index 000000000..610d5f038 --- /dev/null +++ b/services/deaccession/jaxb/pom.xml @@ -0,0 +1,33 @@ + + + + org.collectionspace.services.deaccession + org.collectionspace.services + ${revision} + + + 4.0.0 + org.collectionspace.services.deaccession.jaxb + services.deaccession.jaxb + + + + org.collectionspace.services + org.collectionspace.services.jaxb + ${project.version} + + + + + collectionspace-services-deaccession-jaxb + install + + + org.jvnet.jaxb2.maven2 + maven-jaxb2-plugin + + + + \ No newline at end of file diff --git a/services/deaccession/jaxb/src/main/resources/deaccessions_common.xsd b/services/deaccession/jaxb/src/main/resources/deaccessions_common.xsd new file mode 100644 index 000000000..0515b1276 --- /dev/null +++ b/services/deaccession/jaxb/src/main/resources/deaccessions_common.xsd @@ -0,0 +1,68 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/services/deaccession/pom.xml b/services/deaccession/pom.xml new file mode 100644 index 000000000..2584d4cbc --- /dev/null +++ b/services/deaccession/pom.xml @@ -0,0 +1,58 @@ + + + + org.collectionspace.services + org.collectionspace.services.main + ${revision} + + + 4.0.0 + org.collectionspace.services.deaccession + services.deaccession + pom + + + + 2.30.0 + + + + + + com.diffplug.spotless + spotless-maven-plugin + ${spotless.version} + + + + + + src/main/java/**/*.java + src/test/java/**/*.java + + + + + true + 4 + + + + + + + + + + + + + + jaxb + service + client + + + \ No newline at end of file diff --git a/services/deaccession/service/pom.xml b/services/deaccession/service/pom.xml new file mode 100644 index 000000000..6d8f01e25 --- /dev/null +++ b/services/deaccession/service/pom.xml @@ -0,0 +1,89 @@ + + + + + org.collectionspace.services + org.collectionspace.services.deaccession + ${revision} + + + 4.0.0 + org.collectionspace.services.deaccession.service + services.deaccession.service + jar + + + + org.collectionspace.services + org.collectionspace.services.common + + + org.collectionspace.services + org.collectionspace.services.deaccession.jaxb + ${project.version} + + + org.collectionspace.services + org.collectionspace.services.deaccession.client + ${project.version} + + + + + junit + junit + test + + + org.testng + testng + test + + + + + 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-deaccession + + diff --git a/services/deaccession/service/src/main/java/org/collectionspace/services/deaccession/DeaccessionResource.java b/services/deaccession/service/src/main/java/org/collectionspace/services/deaccession/DeaccessionResource.java new file mode 100644 index 000000000..be32d7a75 --- /dev/null +++ b/services/deaccession/service/src/main/java/org/collectionspace/services/deaccession/DeaccessionResource.java @@ -0,0 +1,49 @@ +/* + * 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.deaccession; + +import javax.ws.rs.Consumes; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import org.collectionspace.services.client.DeaccessionClient; +import org.collectionspace.services.common.NuxeoBasedResource; + +@Path(DeaccessionClient.SERVICE_PATH) +@Consumes("application/xml") +@Produces("application/xml") +public class DeaccessionResource extends NuxeoBasedResource { + + @Override + protected String getVersionString() { + return "$LastChangedRevision$"; + } + + @Override + public String getServiceName() { + return DeaccessionClient.SERVICE_NAME; + } + + @Override + public Class getCommonPartClass() { + return DeaccessionsCommon.class; + } +} diff --git a/services/deaccession/service/src/main/java/org/collectionspace/services/deaccession/nuxeo/DeaccessionDocumentModelHandler.java b/services/deaccession/service/src/main/java/org/collectionspace/services/deaccession/nuxeo/DeaccessionDocumentModelHandler.java new file mode 100644 index 000000000..18caf794b --- /dev/null +++ b/services/deaccession/service/src/main/java/org/collectionspace/services/deaccession/nuxeo/DeaccessionDocumentModelHandler.java @@ -0,0 +1,30 @@ +/* + * 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.deaccession.nuxeo; + +import org.collectionspace.services.deaccession.DeaccessionsCommon; +import org.collectionspace.services.nuxeo.client.java.NuxeoDocumentModelHandler; + +/** + * DeaccessionDocumentModelHandler + */ +public class DeaccessionDocumentModelHandler extends NuxeoDocumentModelHandler {} diff --git a/services/deaccession/service/src/main/java/org/collectionspace/services/deaccession/nuxeo/DeaccessionValidatorHandler.java b/services/deaccession/service/src/main/java/org/collectionspace/services/deaccession/nuxeo/DeaccessionValidatorHandler.java new file mode 100644 index 000000000..39d6ff9ac --- /dev/null +++ b/services/deaccession/service/src/main/java/org/collectionspace/services/deaccession/nuxeo/DeaccessionValidatorHandler.java @@ -0,0 +1,64 @@ +/* + * 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 + */ +package org.collectionspace.services.deaccession.nuxeo; + +import org.collectionspace.services.client.PoxPayloadIn; +import org.collectionspace.services.client.PoxPayloadOut; +import org.collectionspace.services.common.document.InvalidDocumentException; +import org.collectionspace.services.common.document.ValidatorHandlerImpl; +import org.collectionspace.services.deaccession.DeaccessionsCommon; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class DeaccessionValidatorHandler extends ValidatorHandlerImpl { + + private final Logger logger = LoggerFactory.getLogger(DeaccessionValidatorHandler.class); + + private static final String COMMON_PART_MISSING = "Validation exception: deaccessions_common part is missing"; + private static final String DEACCESSION_NUMBER_MISSING = + "Validation exception: The field \"deaccessionNumber\" cannot be empty or missing"; + + @Override + protected Class getCommonPartClass() { + return DeaccessionsCommon.class; + } + + @Override + protected void handleCreate() throws InvalidDocumentException { + final DeaccessionsCommon common = (DeaccessionsCommon) getCommonPart(); + if (common == null) { + logger.error(COMMON_PART_MISSING); + throw new InvalidDocumentException(COMMON_PART_MISSING); + } + + final String deaccessionNumber = common.getDeaccessionNumber(); + if (deaccessionNumber == null || deaccessionNumber.isEmpty()) { + logger.error(DEACCESSION_NUMBER_MISSING); + throw new InvalidDocumentException(DEACCESSION_NUMBER_MISSING); + } + } + + @Override + protected void handleGet() {} + + @Override + protected void handleGetAll() {} + + @Override + protected void handleUpdate() {} + + @Override + protected void handleDelete() {} +} diff --git a/services/pom.xml b/services/pom.xml index e85ee69fc..9d8b80d38 100644 --- a/services/pom.xml +++ b/services/pom.xml @@ -104,6 +104,7 @@ summarydocumentation heldintrust consultation + deaccession IntegrationTests PerformanceTests security -- 2.47.3