From 8e77d1b51581958bec795c60fb54e07f1e2961d7 Mon Sep 17 00:00:00 2001 From: Patrick Schmitz Date: Sat, 3 Jul 2010 19:24:50 +0000 Subject: [PATCH] NOJIRA - Ported Authority cleanup to Location. This also addresses a number of missing elements in Location, around authRefs, named access, etc. Also cleaned up some inconsistent naming on the field that tracks term status, across all the authorities. Finally, added in more checks in test code across the authorities to ensure that ClientResponse instances are cleanly released. --- .../vocabulary/AuthorityJAXBSchema.java | 1 + .../resources/schemas/locations_common.xsd | 2 +- .../client/LocationAuthorityClientUtils.java | 70 +- .../test/LocationAuthorityServiceTest.java | 990 ++++++++++-------- services/location/jaxb/pom.xml | 5 + .../services/LocationAuthorityJAXBSchema.java | 19 - .../LocationAuthorityListItemJAXBSchema.java | 10 - .../services/LocationJAXBSchema.java | 9 +- .../services/LocationListItemJAXBSchema.java | 8 - .../src/main/resources/location_common.xsd | 2 +- .../location/LocationAuthorityResource.java | 759 +------------- ...LocationAuthorityDocumentModelHandler.java | 78 +- .../nuxeo/LocationDocumentModelHandler.java | 109 +- .../schemas/organizations_common.xsd | 2 +- .../client/test/OrgAuthorityServiceTest.java | 945 +++++++++-------- .../services/OrganizationJAXBSchema.java | 1 - .../main/resources/organization_common.xsd | 2 +- .../organization/OrgAuthorityResource.java | 6 - .../main/resources/schemas/persons_common.xsd | 2 +- .../test/PersonAuthorityServiceTest.java | 150 +-- .../services/PersonJAXBSchema.java | 1 - .../jaxb/src/main/resources/person_common.xsd | 2 +- .../schemas/vocabularyitems_common.xsd | 2 +- .../main/resources/vocabularyitem_common.xsd | 2 +- 24 files changed, 1217 insertions(+), 1960 deletions(-) delete mode 100644 services/location/jaxb/src/main/java/org/collectionspace/services/LocationAuthorityJAXBSchema.java delete mode 100644 services/location/jaxb/src/main/java/org/collectionspace/services/LocationAuthorityListItemJAXBSchema.java delete mode 100644 services/location/jaxb/src/main/java/org/collectionspace/services/LocationListItemJAXBSchema.java diff --git a/services/common/src/main/java/org/collectionspace/services/common/vocabulary/AuthorityJAXBSchema.java b/services/common/src/main/java/org/collectionspace/services/common/vocabulary/AuthorityJAXBSchema.java index 456ea65e0..edbe2ef95 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/vocabulary/AuthorityJAXBSchema.java +++ b/services/common/src/main/java/org/collectionspace/services/common/vocabulary/AuthorityJAXBSchema.java @@ -33,6 +33,7 @@ public interface AuthorityJAXBSchema { final static String REF_NAME = "refName"; final static String VOCAB_TYPE = "vocabType"; final static String CSID = "csid"; + final static String TERM_STATUS = "termStatus"; } diff --git a/services/location/3rdparty/nuxeo-platform-cs-location/src/main/resources/schemas/locations_common.xsd b/services/location/3rdparty/nuxeo-platform-cs-location/src/main/resources/schemas/locations_common.xsd index 0bc24ef76..54e76a1c9 100644 --- a/services/location/3rdparty/nuxeo-platform-cs-location/src/main/resources/schemas/locations_common.xsd +++ b/services/location/3rdparty/nuxeo-platform-cs-location/src/main/resources/schemas/locations_common.xsd @@ -25,6 +25,7 @@ + @@ -32,7 +33,6 @@ - diff --git a/services/location/client/src/main/java/org/collectionspace/services/client/LocationAuthorityClientUtils.java b/services/location/client/src/main/java/org/collectionspace/services/client/LocationAuthorityClientUtils.java index 09ca4808e..ae878daa8 100644 --- a/services/location/client/src/main/java/org/collectionspace/services/client/LocationAuthorityClientUtils.java +++ b/services/location/client/src/main/java/org/collectionspace/services/client/LocationAuthorityClientUtils.java @@ -83,8 +83,8 @@ public class LocationAuthorityClientUtils { location.setSecurityNote(value); if((value = (String)locationInfo.get(LocationJAXBSchema.LOCATION_TYPE))!=null) location.setLocationType(value); - if((value = (String)locationInfo.get(LocationJAXBSchema.STATUS))!=null) - location.setStatus(value); + if((value = (String)locationInfo.get(LocationJAXBSchema.TERM_STATUS))!=null) + location.setTermStatus(value); MultipartOutput multipart = new MultipartOutput(); OutputPart commonPart = multipart.addPart(location, MediaType.APPLICATION_XML_TYPE); @@ -132,23 +132,28 @@ public class LocationAuthorityClientUtils { MultipartOutput multipart = createLocationInstance( vcsid, locationAuthorityRefName, locationMap, client.getItemCommonPartName() ); + String newID = null; ClientResponse res = client.createItem(vcsid, multipart); + try { + int statusCode = res.getStatus(); + + if(!REQUEST_TYPE.isValidStatusCode(statusCode)) { + throw new RuntimeException("Could not create Item: \"" + +locationMap.get(LocationJAXBSchema.SHORT_IDENTIFIER) + +"\" in locationAuthority: \"" + locationAuthorityRefName + +"\" "+ invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + } + if(statusCode != EXPECTED_STATUS_CODE) { + throw new RuntimeException("Unexpected Status when creating Item: \"" + +locationMap.get(LocationJAXBSchema.SHORT_IDENTIFIER) + +"\" in locationAuthority: \"" + locationAuthorityRefName +"\", Status:"+ statusCode); + } + newID = extractId(res); + } finally { + res.releaseConnection(); + } - int statusCode = res.getStatus(); - - if(!REQUEST_TYPE.isValidStatusCode(statusCode)) { - throw new RuntimeException("Could not create Item: \"" - +locationMap.get(LocationJAXBSchema.SHORT_IDENTIFIER) - +"\" in locationAuthority: \"" + locationAuthorityRefName - +"\" "+ invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - } - if(statusCode != EXPECTED_STATUS_CODE) { - throw new RuntimeException("Unexpected Status when creating Item: \"" - +locationMap.get(LocationJAXBSchema.SHORT_IDENTIFIER) - +"\" in locationAuthority: \"" + locationAuthorityRefName +"\", Status:"+ statusCode); - } - - return extractId(res); + return newID; } public static MultipartOutput createLocationInstance( @@ -175,21 +180,26 @@ public class LocationAuthorityClientUtils { MultipartOutput multipart = createLocationInstance( commonPartXML, client.getItemCommonPartName() ); + String newID = null; ClientResponse res = client.createItem(vcsid, multipart); + try { + int statusCode = res.getStatus(); + + if(!REQUEST_TYPE.isValidStatusCode(statusCode)) { + throw new RuntimeException("Could not create Item: \""+commonPartXML + +"\" in locationAuthority: \"" + vcsid + +"\" "+ invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + } + if(statusCode != EXPECTED_STATUS_CODE) { + throw new RuntimeException("Unexpected Status when creating Item: \""+commonPartXML + +"\" in locationAuthority: \"" + vcsid +"\", Status:"+ statusCode); + } + newID = extractId(res); + } finally { + res.releaseConnection(); + } - int statusCode = res.getStatus(); - - if(!REQUEST_TYPE.isValidStatusCode(statusCode)) { - throw new RuntimeException("Could not create Item: \""+commonPartXML - +"\" in locationAuthority: \"" + vcsid - +"\" "+ invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - } - if(statusCode != EXPECTED_STATUS_CODE) { - throw new RuntimeException("Unexpected Status when creating Item: \""+commonPartXML - +"\" in locationAuthority: \"" + vcsid +"\", Status:"+ statusCode); - } - - return extractId(res); + return newID; } /** diff --git a/services/location/client/src/test/java/org/collectionspace/services/client/test/LocationAuthorityServiceTest.java b/services/location/client/src/test/java/org/collectionspace/services/client/test/LocationAuthorityServiceTest.java index 776d270ef..e6de389dd 100644 --- a/services/location/client/src/test/java/org/collectionspace/services/client/test/LocationAuthorityServiceTest.java +++ b/services/location/client/src/test/java/org/collectionspace/services/client/test/LocationAuthorityServiceTest.java @@ -162,23 +162,28 @@ public class LocationAuthorityServiceTest extends AbstractServiceTestImpl { MultipartOutput multipart = LocationAuthorityClientUtils.createLocationAuthorityInstance( displayName, shortId, client.getCommonPartName()); + String newID = null; ClientResponse res = client.create(multipart); - 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); + 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(this.REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(this.REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, this.EXPECTED_STATUS_CODE); + + newID = LocationAuthorityClientUtils.extractId(res); + } finally { + res.releaseConnection(); } - Assert.assertTrue(this.REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(this.REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, this.EXPECTED_STATUS_CODE); - - String newID = LocationAuthorityClientUtils.extractId(res); // Store the ID returned from the first resource created // for additional tests below. if (knownResourceId == null){ @@ -231,7 +236,7 @@ public class LocationAuthorityServiceTest extends AbstractServiceTestImpl { shelf1Map.put(LocationJAXBSchema.CONDITION_NOTE_DATE, TEST_CONDITION_NOTE_DATE); shelf1Map.put(LocationJAXBSchema.SECURITY_NOTE, TEST_SECURITY_NOTE); shelf1Map.put(LocationJAXBSchema.LOCATION_TYPE, TEST_LOCATION_TYPE); - shelf1Map.put(LocationJAXBSchema.STATUS, TEST_STATUS); + shelf1Map.put(LocationJAXBSchema.TERM_STATUS, TEST_STATUS); String newID = LocationAuthorityClientUtils.createItemInAuthority(vcsid, authRefName, shelf1Map, client ); @@ -332,25 +337,31 @@ public class LocationAuthorityServiceTest extends AbstractServiceTestImpl { // Submit the request to the service and store the response. LocationAuthorityClient client = new LocationAuthorityClient(); + String newID = null; ClientResponse res = client.read(knownResourceId); - 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(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); - //FIXME: remove the following try catch once Aron fixes signatures try { - MultipartInput input = (MultipartInput) res.getEntity(); - LocationauthoritiesCommon locationAuthority = (LocationauthoritiesCommon) extractPart(input, - client.getCommonPartName(), LocationauthoritiesCommon.class); - Assert.assertNotNull(locationAuthority); - } catch (Exception e) { - throw new RuntimeException(e); + 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(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + //FIXME: remove the following try catch once Aron fixes signatures + try { + MultipartInput input = (MultipartInput) res.getEntity(); + LocationauthoritiesCommon locationAuthority = + (LocationauthoritiesCommon) extractPart(input, + client.getCommonPartName(), LocationauthoritiesCommon.class); + Assert.assertNotNull(locationAuthority); + } catch (Exception e) { + throw new RuntimeException(e); + } + } finally { + res.releaseConnection(); } } @@ -373,24 +384,28 @@ public class LocationAuthorityServiceTest extends AbstractServiceTestImpl { // Submit the request to the service and store the response. LocationAuthorityClient client = new LocationAuthorityClient(); ClientResponse res = client.readByName(knownResourceShortIdentifer); - 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(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); - //FIXME: remove the following try catch once Aron fixes signatures try { - MultipartInput input = (MultipartInput) res.getEntity(); - LocationauthoritiesCommon locationAuthority = (LocationauthoritiesCommon) extractPart(input, - client.getCommonPartName(), LocationauthoritiesCommon.class); - Assert.assertNotNull(locationAuthority); - } catch (Exception e) { - throw new RuntimeException(e); + 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(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + //FIXME: remove the following try catch once Aron fixes signatures + try { + MultipartInput input = (MultipartInput) res.getEntity(); + LocationauthoritiesCommon locationAuthority = (LocationauthoritiesCommon) extractPart(input, + client.getCommonPartName(), LocationauthoritiesCommon.class); + Assert.assertNotNull(locationAuthority); + } catch (Exception e) { + throw new RuntimeException(e); + } + } finally { + res.releaseConnection(); } } @@ -414,28 +429,32 @@ public class LocationAuthorityServiceTest extends AbstractServiceTestImpl { // Submit the request to the service and store the response. LocationAuthorityClient client = new LocationAuthorityClient(); ClientResponse res = client.readItem(knownResourceId, knownItemResourceId); - 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(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); - - // Check whether we've received a location. - MultipartInput input = (MultipartInput) res.getEntity(); - LocationsCommon location = (LocationsCommon) extractPart(input, - client.getItemCommonPartName(), LocationsCommon.class); - Assert.assertNotNull(location); - boolean showFull = true; - if(showFull && logger.isDebugEnabled()){ - logger.debug(testName + ": returned payload:"); - logger.debug(objectAsXmlString(location, LocationsCommon.class)); - } - Assert.assertEquals(location.getInAuthority(), 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(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + + // Check whether we've received a location. + MultipartInput input = (MultipartInput) res.getEntity(); + LocationsCommon location = (LocationsCommon) extractPart(input, + client.getItemCommonPartName(), LocationsCommon.class); + Assert.assertNotNull(location); + boolean showFull = true; + if(showFull && logger.isDebugEnabled()){ + logger.debug(testName + ": returned payload:"); + logger.debug(objectAsXmlString(location, LocationsCommon.class)); + } + Assert.assertEquals(location.getInAuthority(), knownResourceId); + } finally { + res.releaseConnection(); + } } @@ -458,98 +477,104 @@ public class LocationAuthorityServiceTest extends AbstractServiceTestImpl { // Submit the request to the service and store the response. LocationAuthorityClient client = new LocationAuthorityClient(); ClientResponse res = client.readItem(knownResourceId, knownItemResourceId); - 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(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); - - // Check whether location has expected displayName. - MultipartInput input = (MultipartInput) res.getEntity(); - LocationsCommon location = (LocationsCommon) extractPart(input, - client.getItemCommonPartName(), LocationsCommon.class); - Assert.assertNotNull(location); - String displayName = location.getDisplayName(); - // Make sure displayName matches computed form - String expectedDisplayName = - LocationAuthorityClientUtils.prepareDefaultDisplayName(TEST_NAME); - Assert.assertNotNull(displayName, expectedDisplayName); - - // Update the shortName and verify the computed name is updated. - location.setCsid(null); - location.setDisplayNameComputed(true); - location.setName("updated-" + TEST_NAME); - expectedDisplayName = - LocationAuthorityClientUtils.prepareDefaultDisplayName("updated-" + TEST_NAME); - - // Submit the updated resource to the service and store the response. - MultipartOutput output = new MultipartOutput(); - OutputPart commonPart = output.addPart(location, MediaType.APPLICATION_XML_TYPE); - commonPart.getHeaders().add("label", client.getItemCommonPartName()); - res = client.updateItem(knownResourceId, knownItemResourceId, output); - statusCode = res.getStatus(); - - // Check the status code of the response: does it match the expected response(s)? - if(logger.isDebugEnabled()){ - logger.debug("updateItem: status = " + statusCode); - } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); - - // Retrieve the updated resource and verify that its contents exist. - input = (MultipartInput) res.getEntity(); - LocationsCommon updatedLocation = - (LocationsCommon) extractPart(input, - client.getItemCommonPartName(), LocationsCommon.class); - Assert.assertNotNull(updatedLocation); - - // Verify that the updated resource received the correct data. - Assert.assertEquals(updatedLocation.getName(), location.getName(), - "Updated ForeName in Location did not match submitted data."); - // Verify that the updated resource computes the right displayName. - Assert.assertEquals(updatedLocation.getDisplayName(), expectedDisplayName, - "Updated ForeName in Location not reflected in computed DisplayName."); - - // Now Update the displayName, not computed and verify the computed name is overriden. - location.setDisplayNameComputed(false); - expectedDisplayName = "TestName"; - location.setDisplayName(expectedDisplayName); - - // Submit the updated resource to the service and store the response. - output = new MultipartOutput(); - commonPart = output.addPart(location, MediaType.APPLICATION_XML_TYPE); - commonPart.getHeaders().add("label", client.getItemCommonPartName()); - res = client.updateItem(knownResourceId, knownItemResourceId, output); - statusCode = res.getStatus(); - - // Check the status code of the response: does it match the expected response(s)? - if(logger.isDebugEnabled()){ - logger.debug("updateItem: status = " + statusCode); - } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); - - // Retrieve the updated resource and verify that its contents exist. - input = (MultipartInput) res.getEntity(); - updatedLocation = - (LocationsCommon) extractPart(input, - client.getItemCommonPartName(), LocationsCommon.class); - Assert.assertNotNull(updatedLocation); - - // Verify that the updated resource received the correct data. - Assert.assertEquals(updatedLocation.isDisplayNameComputed(), false, - "Updated displayNameComputed in Location did not match submitted data."); - // Verify that the updated resource computes the right displayName. - Assert.assertEquals(updatedLocation.getDisplayName(), - expectedDisplayName, - "Updated DisplayName (not computed) in Location not stored."); + 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(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + + // Check whether location has expected displayName. + MultipartInput input = (MultipartInput) res.getEntity(); + LocationsCommon location = (LocationsCommon) extractPart(input, + client.getItemCommonPartName(), LocationsCommon.class); + Assert.assertNotNull(location); + String displayName = location.getDisplayName(); + // Make sure displayName matches computed form + String expectedDisplayName = + LocationAuthorityClientUtils.prepareDefaultDisplayName(TEST_NAME); + Assert.assertNotNull(displayName, expectedDisplayName); + + // Update the shortName and verify the computed name is updated. + location.setCsid(null); + location.setDisplayNameComputed(true); + location.setName("updated-" + TEST_NAME); + expectedDisplayName = + LocationAuthorityClientUtils.prepareDefaultDisplayName("updated-" + TEST_NAME); + + // Submit the updated resource to the service and store the response. + MultipartOutput output = new MultipartOutput(); + OutputPart commonPart = output.addPart(location, MediaType.APPLICATION_XML_TYPE); + commonPart.getHeaders().add("label", client.getItemCommonPartName()); + res.releaseConnection(); + res = client.updateItem(knownResourceId, knownItemResourceId, output); + statusCode = res.getStatus(); + + // Check the status code of the response: does it match the expected response(s)? + if(logger.isDebugEnabled()){ + logger.debug("updateItem: status = " + statusCode); + } + Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + + // Retrieve the updated resource and verify that its contents exist. + input = (MultipartInput) res.getEntity(); + LocationsCommon updatedLocation = + (LocationsCommon) extractPart(input, + client.getItemCommonPartName(), LocationsCommon.class); + Assert.assertNotNull(updatedLocation); + + // Verify that the updated resource received the correct data. + Assert.assertEquals(updatedLocation.getName(), location.getName(), + "Updated ForeName in Location did not match submitted data."); + // Verify that the updated resource computes the right displayName. + Assert.assertEquals(updatedLocation.getDisplayName(), expectedDisplayName, + "Updated ForeName in Location not reflected in computed DisplayName."); + + // Now Update the displayName, not computed and verify the computed name is overriden. + location.setDisplayNameComputed(false); + expectedDisplayName = "TestName"; + location.setDisplayName(expectedDisplayName); + + // Submit the updated resource to the service and store the response. + output = new MultipartOutput(); + commonPart = output.addPart(location, MediaType.APPLICATION_XML_TYPE); + commonPart.getHeaders().add("label", client.getItemCommonPartName()); + res.releaseConnection(); + res = client.updateItem(knownResourceId, knownItemResourceId, output); + statusCode = res.getStatus(); + + // Check the status code of the response: does it match the expected response(s)? + if(logger.isDebugEnabled()){ + logger.debug("updateItem: status = " + statusCode); + } + Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + + // Retrieve the updated resource and verify that its contents exist. + input = (MultipartInput) res.getEntity(); + updatedLocation = + (LocationsCommon) extractPart(input, + client.getItemCommonPartName(), LocationsCommon.class); + Assert.assertNotNull(updatedLocation); + + // Verify that the updated resource received the correct data. + Assert.assertEquals(updatedLocation.isDisplayNameComputed(), false, + "Updated displayNameComputed in Location did not match submitted data."); + // Verify that the updated resource computes the right displayName. + Assert.assertEquals(updatedLocation.getDisplayName(), + expectedDisplayName, + "Updated DisplayName (not computed) in Location not stored."); + } finally { + res.releaseConnection(); + } } /** @@ -572,40 +597,45 @@ public class LocationAuthorityServiceTest extends AbstractServiceTestImpl { // Submit the request to the service and store the response. LocationAuthorityClient client = new LocationAuthorityClient(); ClientResponse res = client.readItem(knownResourceId, knownItemResourceId); - 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(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, Response.Status.OK.getStatusCode()); - - // Check whether Location has expected displayName. - MultipartInput input = (MultipartInput) res.getEntity(); - LocationsCommon location = (LocationsCommon) extractPart(input, - client.getItemCommonPartName(), LocationsCommon.class); - Assert.assertNotNull(location); - // Try to Update with computed false and no displayName - location.setDisplayNameComputed(false); - location.setDisplayName(null); - - // Submit the updated resource to the service and store the response. - MultipartOutput output = new MultipartOutput(); - OutputPart commonPart = output.addPart(location, MediaType.APPLICATION_XML_TYPE); - commonPart.getHeaders().add("label", client.getItemCommonPartName()); - res = client.updateItem(knownResourceId, knownItemResourceId, output); - statusCode = res.getStatus(); - - // Check the status code of the response: does it match the expected response(s)? - if(logger.isDebugEnabled()){ - logger.debug("updateItem: status = " + statusCode); - } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + 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(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, Response.Status.OK.getStatusCode()); + + // Check whether Location has expected displayName. + MultipartInput input = (MultipartInput) res.getEntity(); + LocationsCommon location = (LocationsCommon) extractPart(input, + client.getItemCommonPartName(), LocationsCommon.class); + Assert.assertNotNull(location); + // Try to Update with computed false and no displayName + location.setDisplayNameComputed(false); + location.setDisplayName(null); + + // Submit the updated resource to the service and store the response. + MultipartOutput output = new MultipartOutput(); + OutputPart commonPart = output.addPart(location, MediaType.APPLICATION_XML_TYPE); + commonPart.getHeaders().add("label", client.getItemCommonPartName()); + res.releaseConnection(); + res = client.updateItem(knownResourceId, knownItemResourceId, output); + statusCode = res.getStatus(); + + // Check the status code of the response: does it match the expected response(s)? + if(logger.isDebugEnabled()){ + logger.debug("updateItem: status = " + statusCode); + } + Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + } finally { + res.releaseConnection(); + } } @@ -627,16 +657,20 @@ public class LocationAuthorityServiceTest extends AbstractServiceTestImpl { // Submit the request to the service and store the response. LocationAuthorityClient client = new LocationAuthorityClient(); ClientResponse res = client.read(NON_EXISTENT_ID); - 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(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + 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(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + } finally { + res.releaseConnection(); + } } /** @@ -657,16 +691,20 @@ public class LocationAuthorityServiceTest extends AbstractServiceTestImpl { // Submit the request to the service and store the response. LocationAuthorityClient client = new LocationAuthorityClient(); ClientResponse res = client.readItem(knownResourceId, NON_EXISTENT_ID); - 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(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + 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(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + } finally { + res.releaseConnection(); + } } @@ -692,36 +730,40 @@ public class LocationAuthorityServiceTest extends AbstractServiceTestImpl { // Submit the request to the service and store the response. LocationAuthorityClient client = new LocationAuthorityClient(); ClientResponse res = client.readList(); - LocationauthoritiesCommonList 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(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); - - // Optionally output additional data about list members for debugging. - boolean iterateThroughList = false; - if (iterateThroughList && logger.isDebugEnabled()) { - List items = - list.getLocationauthorityListItem(); - int i = 0; - for (LocationauthoritiesCommonList.LocationauthorityListItem item : items) { - String csid = item.getCsid(); - logger.debug(testName + ": list-item[" + i + "] csid=" + - csid); - logger.debug(testName + ": list-item[" + i + "] displayName=" + - item.getDisplayName()); - logger.debug(testName + ": list-item[" + i + "] URI=" + - item.getUri()); - readItemList(csid, null); - i++; - } - } + try { + LocationauthoritiesCommonList 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(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + + // Optionally output additional data about list members for debugging. + boolean iterateThroughList = false; + if (iterateThroughList && logger.isDebugEnabled()) { + List items = + list.getLocationauthorityListItem(); + int i = 0; + for (LocationauthoritiesCommonList.LocationauthorityListItem item : items) { + String csid = item.getCsid(); + logger.debug(testName + ": list-item[" + i + "] csid=" + + csid); + logger.debug(testName + ": list-item[" + i + "] displayName=" + + item.getDisplayName()); + logger.debug(testName + ": list-item[" + i + "] URI=" + + item.getUri()); + readItemList(csid, null); + i++; + } + } + } finally { + res.releaseConnection(); + } } /** @@ -771,52 +813,56 @@ public class LocationAuthorityServiceTest extends AbstractServiceTestImpl { } else { Assert.fail("readItemList passed null csid and name!"); } - LocationsCommonList 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(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); - - List items = - list.getLocationListItem(); - int nItemsReturned = items.size(); - // There will be one item created, associated with a - // known parent resource, by the createItem test. - // - // In addition, there will be 'nItemsToCreateInList' - // additional items created by the createItemList test, - // all associated with the same parent resource. - int nExpectedItems = nItemsToCreateInList + 1; - if(logger.isDebugEnabled()){ - logger.debug(testName + ": Expected " - + nExpectedItems +" items; got: "+nItemsReturned); - } - Assert.assertEquals(nItemsReturned, nExpectedItems); - - int i = 0; - for (LocationsCommonList.LocationListItem item : items) { - Assert.assertTrue((null != item.getRefName()), "Item refName is null!"); - Assert.assertTrue((null != item.getDisplayName()), "Item displayName is null!"); - // Optionally output additional data about list members for debugging. - boolean showDetails = true; - if (showDetails && logger.isDebugEnabled()) { - logger.debug(" " + testName + ": list-item[" + i + "] csid=" + - item.getCsid()); - logger.debug(" " + testName + ": list-item[" + i + "] refName=" + - item.getRefName()); - logger.debug(" " + testName + ": list-item[" + i + "] displayName=" + - item.getDisplayName()); - logger.debug(" " + testName + ": list-item[" + i + "] URI=" + - item.getUri()); - } - i++; - } + try { + LocationsCommonList 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(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + + List items = + list.getLocationListItem(); + int nItemsReturned = items.size(); + // There will be one item created, associated with a + // known parent resource, by the createItem test. + // + // In addition, there will be 'nItemsToCreateInList' + // additional items created by the createItemList test, + // all associated with the same parent resource. + int nExpectedItems = nItemsToCreateInList + 1; + if(logger.isDebugEnabled()){ + logger.debug(testName + ": Expected " + + nExpectedItems +" items; got: "+nItemsReturned); + } + Assert.assertEquals(nItemsReturned, nExpectedItems); + + int i = 0; + for (LocationsCommonList.LocationListItem item : items) { + Assert.assertTrue((null != item.getRefName()), "Item refName is null!"); + Assert.assertTrue((null != item.getDisplayName()), "Item displayName is null!"); + // Optionally output additional data about list members for debugging. + boolean showDetails = true; + if (showDetails && logger.isDebugEnabled()) { + logger.debug(" " + testName + ": list-item[" + i + "] csid=" + + item.getCsid()); + logger.debug(" " + testName + ": list-item[" + i + "] refName=" + + item.getRefName()); + logger.debug(" " + testName + ": list-item[" + i + "] displayName=" + + item.getDisplayName()); + logger.debug(" " + testName + ": list-item[" + i + "] URI=" + + item.getUri()); + } + i++; + } + } finally { + res.releaseConnection(); + } } @@ -843,55 +889,59 @@ public class LocationAuthorityServiceTest extends AbstractServiceTestImpl { // Retrieve the contents of a resource to update. LocationAuthorityClient client = new LocationAuthorityClient(); - ClientResponse res = - client.read(knownResourceId); - if(logger.isDebugEnabled()){ - logger.debug(testName + ": read status = " + res.getStatus()); - } - Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE); - - if(logger.isDebugEnabled()){ - logger.debug("got LocationAuthority to update with ID: " + knownResourceId); - } - MultipartInput input = (MultipartInput) res.getEntity(); - LocationauthoritiesCommon locationAuthority = (LocationauthoritiesCommon) extractPart(input, - client.getCommonPartName(), LocationauthoritiesCommon.class); - Assert.assertNotNull(locationAuthority); - - // Update the contents of this resource. - locationAuthority.setDisplayName("updated-" + locationAuthority.getDisplayName()); - locationAuthority.setVocabType("updated-" + locationAuthority.getVocabType()); - if(logger.isDebugEnabled()){ - logger.debug("to be updated LocationAuthority"); - logger.debug(objectAsXmlString(locationAuthority, LocationauthoritiesCommon.class)); - } - - // Submit the updated resource to the service and store the response. - MultipartOutput output = new MultipartOutput(); - OutputPart commonPart = output.addPart(locationAuthority, MediaType.APPLICATION_XML_TYPE); - commonPart.getHeaders().add("label", client.getCommonPartName()); - res = client.update(knownResourceId, output); - 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(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); - - // Retrieve the updated resource and verify that its contents exist. - input = (MultipartInput) res.getEntity(); - LocationauthoritiesCommon updatedLocationAuthority = - (LocationauthoritiesCommon) extractPart(input, - client.getCommonPartName(), LocationauthoritiesCommon.class); - Assert.assertNotNull(updatedLocationAuthority); - - // Verify that the updated resource received the correct data. - Assert.assertEquals(updatedLocationAuthority.getDisplayName(), - locationAuthority.getDisplayName(), - "Data in updated object did not match submitted data."); + ClientResponse res = client.read(knownResourceId); + try { + if(logger.isDebugEnabled()){ + logger.debug(testName + ": read status = " + res.getStatus()); + } + Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE); + + if(logger.isDebugEnabled()){ + logger.debug("got LocationAuthority to update with ID: " + knownResourceId); + } + MultipartInput input = (MultipartInput) res.getEntity(); + LocationauthoritiesCommon locationAuthority = (LocationauthoritiesCommon) extractPart(input, + client.getCommonPartName(), LocationauthoritiesCommon.class); + Assert.assertNotNull(locationAuthority); + + // Update the contents of this resource. + locationAuthority.setDisplayName("updated-" + locationAuthority.getDisplayName()); + locationAuthority.setVocabType("updated-" + locationAuthority.getVocabType()); + if(logger.isDebugEnabled()){ + logger.debug("to be updated LocationAuthority"); + logger.debug(objectAsXmlString(locationAuthority, LocationauthoritiesCommon.class)); + } + + // Submit the updated resource to the service and store the response. + MultipartOutput output = new MultipartOutput(); + OutputPart commonPart = output.addPart(locationAuthority, MediaType.APPLICATION_XML_TYPE); + commonPart.getHeaders().add("label", client.getCommonPartName()); + res.releaseConnection(); + res = client.update(knownResourceId, output); + 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(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + + // Retrieve the updated resource and verify that its contents exist. + input = (MultipartInput) res.getEntity(); + LocationauthoritiesCommon updatedLocationAuthority = + (LocationauthoritiesCommon) extractPart(input, + client.getCommonPartName(), LocationauthoritiesCommon.class); + Assert.assertNotNull(updatedLocationAuthority); + + // Verify that the updated resource received the correct data. + Assert.assertEquals(updatedLocationAuthority.getDisplayName(), + locationAuthority.getDisplayName(), + "Data in updated object did not match submitted data."); + } finally { + res.releaseConnection(); + } } /** @@ -914,55 +964,60 @@ public class LocationAuthorityServiceTest extends AbstractServiceTestImpl { LocationAuthorityClient client = new LocationAuthorityClient(); ClientResponse res = client.readItem(knownResourceId, knownItemResourceId); - if(logger.isDebugEnabled()){ - logger.debug(testName + ": read status = " + res.getStatus()); - } - Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE); - - if(logger.isDebugEnabled()){ - logger.debug("got Location to update with ID: " + - knownItemResourceId + - " in LocationAuthority: " + knownResourceId ); - } - MultipartInput input = (MultipartInput) res.getEntity(); - LocationsCommon location = (LocationsCommon) extractPart(input, - client.getItemCommonPartName(), LocationsCommon.class); - Assert.assertNotNull(location); - - // Update the contents of this resource. - location.setCsid(null); - location.setName("updated-" + location.getName()); - if(logger.isDebugEnabled()){ - logger.debug("to be updated Location"); - logger.debug(objectAsXmlString(location, - LocationsCommon.class)); - } - - // Submit the updated resource to the service and store the response. - MultipartOutput output = new MultipartOutput(); - OutputPart commonPart = output.addPart(location, MediaType.APPLICATION_XML_TYPE); - commonPart.getHeaders().add("label", client.getItemCommonPartName()); - res = client.updateItem(knownResourceId, knownItemResourceId, output); - 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(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); - - // Retrieve the updated resource and verify that its contents exist. - input = (MultipartInput) res.getEntity(); - LocationsCommon updatedLocation = - (LocationsCommon) extractPart(input, - client.getItemCommonPartName(), LocationsCommon.class); - Assert.assertNotNull(updatedLocation); - - // Verify that the updated resource received the correct data. - Assert.assertEquals(updatedLocation.getName(), location.getName(), - "Data in updated Location did not match submitted data."); + try { + if(logger.isDebugEnabled()){ + logger.debug(testName + ": read status = " + res.getStatus()); + } + Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE); + + if(logger.isDebugEnabled()){ + logger.debug("got Location to update with ID: " + + knownItemResourceId + + " in LocationAuthority: " + knownResourceId ); + } + MultipartInput input = (MultipartInput) res.getEntity(); + LocationsCommon location = (LocationsCommon) extractPart(input, + client.getItemCommonPartName(), LocationsCommon.class); + Assert.assertNotNull(location); + + // Update the contents of this resource. + location.setCsid(null); + location.setName("updated-" + location.getName()); + if(logger.isDebugEnabled()){ + logger.debug("to be updated Location"); + logger.debug(objectAsXmlString(location, + LocationsCommon.class)); + } + + // Submit the updated resource to the service and store the response. + MultipartOutput output = new MultipartOutput(); + OutputPart commonPart = output.addPart(location, MediaType.APPLICATION_XML_TYPE); + commonPart.getHeaders().add("label", client.getItemCommonPartName()); + res.releaseConnection(); + res = client.updateItem(knownResourceId, knownItemResourceId, output); + 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(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + + // Retrieve the updated resource and verify that its contents exist. + input = (MultipartInput) res.getEntity(); + LocationsCommon updatedLocation = + (LocationsCommon) extractPart(input, + client.getItemCommonPartName(), LocationsCommon.class); + Assert.assertNotNull(updatedLocation); + + // Verify that the updated resource received the correct data. + Assert.assertEquals(updatedLocation.getName(), location.getName(), + "Data in updated Location did not match submitted data."); + } finally { + res.releaseConnection(); + } } // Failure outcomes @@ -1013,16 +1068,20 @@ public class LocationAuthorityServiceTest extends AbstractServiceTestImpl { displayName, "nonEx", client.getCommonPartName()); ClientResponse res = client.update(NON_EXISTENT_ID, multipart); - 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(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + 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(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + } finally { + res.releaseConnection(); + } } /** @@ -1049,23 +1108,27 @@ public class LocationAuthorityServiceTest extends AbstractServiceTestImpl { nonexMap.put(LocationJAXBSchema.NAME, TEST_NAME); nonexMap.put(LocationJAXBSchema.SHORT_IDENTIFIER, "nonEx"); nonexMap.put(LocationJAXBSchema.LOCATION_TYPE, TEST_LOCATION_TYPE); - nonexMap.put(LocationJAXBSchema.STATUS, TEST_STATUS); + nonexMap.put(LocationJAXBSchema.TERM_STATUS, TEST_STATUS); MultipartOutput multipart = LocationAuthorityClientUtils.createLocationInstance(NON_EXISTENT_ID, LocationAuthorityClientUtils.createLocationRefName(knownResourceRefName, "nonEx", "Non Existent"), nonexMap, client.getItemCommonPartName() ); ClientResponse res = client.updateItem(knownResourceId, NON_EXISTENT_ID, multipart); - 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(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + 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(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + } finally { + res.releaseConnection(); + } } // --------------------------------------------------------------- @@ -1100,17 +1163,22 @@ public class LocationAuthorityServiceTest extends AbstractServiceTestImpl { // Submit the request to the service and store the response. LocationAuthorityClient client = new LocationAuthorityClient(); - ClientResponse res = client.deleteItem(knownResourceId, knownItemResourceId); - 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(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + ClientResponse res = + client.deleteItem(knownResourceId, knownItemResourceId); + 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(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + } finally { + res.releaseConnection(); + } } /* (non-Javadoc) @@ -1134,16 +1202,20 @@ public class LocationAuthorityServiceTest extends AbstractServiceTestImpl { // Submit the request to the service and store the response. LocationAuthorityClient client = new LocationAuthorityClient(); ClientResponse res = client.delete(knownResourceId); - 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(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + 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(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + } finally { + res.releaseConnection(); + } } // Failure outcomes @@ -1164,16 +1236,20 @@ public class LocationAuthorityServiceTest extends AbstractServiceTestImpl { // Submit the request to the service and store the response. LocationAuthorityClient client = new LocationAuthorityClient(); ClientResponse res = client.delete(NON_EXISTENT_ID); - 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(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + 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(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + } finally { + res.releaseConnection(); + } } /** @@ -1194,16 +1270,20 @@ public class LocationAuthorityServiceTest extends AbstractServiceTestImpl { // Submit the request to the service and store the response. LocationAuthorityClient client = new LocationAuthorityClient(); ClientResponse res = client.deleteItem(knownResourceId, NON_EXISTENT_ID); - 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(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + 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(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + } finally { + res.releaseConnection(); + } } // --------------------------------------------------------------- @@ -1296,12 +1376,14 @@ public class LocationAuthorityServiceTest extends AbstractServiceTestImpl { // below are ignored and not reported. ClientResponse res = client.deleteItem(parentResourceId, itemResourceId); + res.releaseConnection(); } // Clean up parent resources. for (String resourceId : allResourceIdsCreated) { // Note: Any non-success responses from the delete operation // below are ignored and not reported. ClientResponse res = client.delete(resourceId); + res.releaseConnection(); } } diff --git a/services/location/jaxb/pom.xml b/services/location/jaxb/pom.xml index 32483affe..dc2d5f671 100644 --- a/services/location/jaxb/pom.xml +++ b/services/location/jaxb/pom.xml @@ -14,6 +14,11 @@ services.location.jaxb + + org.collectionspace.services + org.collectionspace.services.common + ${project.version} + com.sun.xml.bind jaxb-impl diff --git a/services/location/jaxb/src/main/java/org/collectionspace/services/LocationAuthorityJAXBSchema.java b/services/location/jaxb/src/main/java/org/collectionspace/services/LocationAuthorityJAXBSchema.java deleted file mode 100644 index c699bf846..000000000 --- a/services/location/jaxb/src/main/java/org/collectionspace/services/LocationAuthorityJAXBSchema.java +++ /dev/null @@ -1,19 +0,0 @@ -/** - * - */ -package org.collectionspace.services; - -/** - * @author pschmitz - * - */ -public interface LocationAuthorityJAXBSchema { - final static String LOCATIONAUTHORITIES_COMMON = "locationauthorities_common"; - final static String DISPLAY_NAME = "displayName"; - final static String REF_NAME = "refName"; - final static String SHORT_IDENTIFIER = "shortIdentifier"; - final static String VOCAB_TYPE = "vocabType"; - final static String CSID = "csid"; -} - - diff --git a/services/location/jaxb/src/main/java/org/collectionspace/services/LocationAuthorityListItemJAXBSchema.java b/services/location/jaxb/src/main/java/org/collectionspace/services/LocationAuthorityListItemJAXBSchema.java deleted file mode 100644 index 3e301e484..000000000 --- a/services/location/jaxb/src/main/java/org/collectionspace/services/LocationAuthorityListItemJAXBSchema.java +++ /dev/null @@ -1,10 +0,0 @@ -package org.collectionspace.services; - -public interface LocationAuthorityListItemJAXBSchema { - final static String DISPLAY_NAME = "displayName"; - final static String REF_NAME = "refName"; - final static String SHORT_IDENTIFIER = "shortIdentifier"; - final static String VOCAB_TYPE = "vocabType"; - final static String CSID = "csid"; - final static String URI = "url"; -} diff --git a/services/location/jaxb/src/main/java/org/collectionspace/services/LocationJAXBSchema.java b/services/location/jaxb/src/main/java/org/collectionspace/services/LocationJAXBSchema.java index 01205e6f9..dbbe74acb 100644 --- a/services/location/jaxb/src/main/java/org/collectionspace/services/LocationJAXBSchema.java +++ b/services/location/jaxb/src/main/java/org/collectionspace/services/LocationJAXBSchema.java @@ -2,24 +2,19 @@ * */ package org.collectionspace.services; +import org.collectionspace.services.common.vocabulary.AuthorityJAXBSchema; /** * @author pschmitz * */ -public interface LocationJAXBSchema { +public interface LocationJAXBSchema extends AuthorityJAXBSchema { final static String LOCATIONS_COMMON = "locations_common"; - final static String CSID = "csid"; - final static String SHORT_IDENTIFIER = "shortIdentifier"; - final static String IN_AUTHORITY = "inAuthority"; - final static String REF_NAME = "refName"; - final static String DISPLAY_NAME = "displayName"; final static String DISPLAY_NAME_COMPUTED = "displayNameComputed"; final static String NAME = "name"; final static String CONDITION_NOTE = "conditionNote"; final static String CONDITION_NOTE_DATE = "conditionNoteDate"; final static String SECURITY_NOTE = "securityNote"; final static String LOCATION_TYPE = "locationType"; - final static String STATUS = "status"; } diff --git a/services/location/jaxb/src/main/java/org/collectionspace/services/LocationListItemJAXBSchema.java b/services/location/jaxb/src/main/java/org/collectionspace/services/LocationListItemJAXBSchema.java deleted file mode 100644 index 75d494f63..000000000 --- a/services/location/jaxb/src/main/java/org/collectionspace/services/LocationListItemJAXBSchema.java +++ /dev/null @@ -1,8 +0,0 @@ -package org.collectionspace.services; - -public interface LocationListItemJAXBSchema { - final static String DISPLAY_NAME = "displayName"; - final static String REF_NAME = "refName"; - final static String CSID = "csid"; - final static String URI = "url"; -} diff --git a/services/location/jaxb/src/main/resources/location_common.xsd b/services/location/jaxb/src/main/resources/location_common.xsd index 4ed013b46..9b02b2acf 100644 --- a/services/location/jaxb/src/main/resources/location_common.xsd +++ b/services/location/jaxb/src/main/resources/location_common.xsd @@ -24,6 +24,7 @@ + @@ -31,7 +32,6 @@ - diff --git a/services/location/service/src/main/java/org/collectionspace/services/location/LocationAuthorityResource.java b/services/location/service/src/main/java/org/collectionspace/services/location/LocationAuthorityResource.java index 868518917..4c76be778 100644 --- a/services/location/service/src/main/java/org/collectionspace/services/location/LocationAuthorityResource.java +++ b/services/location/service/src/main/java/org/collectionspace/services/location/LocationAuthorityResource.java @@ -41,7 +41,7 @@ import javax.ws.rs.core.Response; import javax.ws.rs.core.UriBuilder; import javax.ws.rs.core.UriInfo; -import org.collectionspace.services.LocationAuthorityJAXBSchema; +import org.collectionspace.services.common.vocabulary.AuthorityJAXBSchema; import org.collectionspace.services.LocationJAXBSchema; import org.collectionspace.services.common.AbstractMultiPartCollectionSpaceResourceImpl; import org.collectionspace.services.common.ClientType; @@ -61,14 +61,10 @@ import org.collectionspace.services.common.document.DocumentNotFoundException; import org.collectionspace.services.common.document.DocumentWrapper; import org.collectionspace.services.common.repository.RepositoryClient; import org.collectionspace.services.common.security.UnauthorizedException; +import org.collectionspace.services.common.vocabulary.AuthorityResource; import org.collectionspace.services.common.vocabulary.RefNameServiceUtils; import org.collectionspace.services.common.vocabulary.RefNameUtils; import org.collectionspace.services.common.query.IQueryManager; -import org.collectionspace.services.contact.ContactResource; -import org.collectionspace.services.contact.ContactsCommon; -import org.collectionspace.services.contact.ContactsCommonList; -import org.collectionspace.services.contact.ContactJAXBSchema; -import org.collectionspace.services.contact.nuxeo.ContactDocumentModelHandler; import org.collectionspace.services.nuxeo.client.java.RemoteDocumentModelHandlerImpl; import org.collectionspace.services.location.nuxeo.LocationDocumentModelHandler; import org.jboss.resteasy.plugins.providers.multipart.MultipartInput; @@ -84,14 +80,15 @@ import org.slf4j.LoggerFactory; @Path("/locationauthorities") @Consumes("multipart/mixed") @Produces("multipart/mixed") -public class LocationAuthorityResource extends - AbstractMultiPartCollectionSpaceResourceImpl { +public class LocationAuthorityResource + extends AuthorityResource { - /** The Constant locationAuthorityServiceName. */ private final static String locationAuthorityServiceName = "locationauthorities"; + private final static String LOCATIONAUTHORITIES_COMMON = "locationauthorities_common"; - /** The Constant locationServiceName. */ private final static String locationServiceName = "locations"; + private final static String LOCATIONS_COMMON = "locations_common"; /** The logger. */ final Logger logger = LoggerFactory.getLogger(LocationAuthorityResource.class); @@ -103,19 +100,10 @@ public class LocationAuthorityResource extends * Instantiates a new location authority resource. */ public LocationAuthorityResource() { - // do nothing + super(LocationauthoritiesCommon.class, LocationAuthorityResource.class, + LOCATIONAUTHORITIES_COMMON, LOCATIONS_COMMON); } - /* (non-Javadoc) - * @see org.collectionspace.services.common.AbstractCollectionSpaceResourceImpl#getVersionString() - */ - @Override - protected String getVersionString() { - /** The last change revision. */ - final String lastChangeRevision = "$LastChangedRevision: 1850 $"; - return lastChangeRevision; - } - /* (non-Javadoc) * @see org.collectionspace.services.common.AbstractCollectionSpaceResourceImpl#getServiceName() */ @@ -124,11 +112,6 @@ public class LocationAuthorityResource extends return locationAuthorityServiceName; } - @Override - public Class getCommonPartClass() { - return LocationauthoritiesCommon.class; - } - /** * Gets the item service name. * @@ -138,726 +121,8 @@ public class LocationAuthorityResource extends return locationServiceName; } - /** - * Creates the item document handler. - * - * @param ctx the ctx - * @param inAuthority the in authority - * - * @return the document handler - * - * @throws Exception the exception - */ - private DocumentHandler createItemDocumentHandler(ServiceContext ctx, - String inAuthority) throws Exception { - LocationDocumentModelHandler docHandler = (LocationDocumentModelHandler)createDocumentHandler(ctx, - ctx.getCommonPartLabel(getItemServiceName()), - LocationsCommon.class); - docHandler.setInAuthority(inAuthority); - - return docHandler; - } - - /** - * Creates the location authority. - * - * @param input the input - * - * @return the response - */ - @POST - public Response createLocationAuthority(MultipartInput input) { - try { - ServiceContext ctx = createServiceContext(input); - DocumentHandler handler = createDocumentHandler(ctx); - String csid = getRepositoryClient(ctx).create(ctx, handler); - //locationAuthorityObject.setCsid(csid); - UriBuilder path = UriBuilder.fromResource(LocationAuthorityResource.class); - path.path("" + csid); - Response response = Response.created(path.build()).build(); - return response; - } catch (BadRequestException bre) { - Response response = Response.status( - Response.Status.BAD_REQUEST).entity("Create failed reason " + bre.getErrorReason()).type("text/plain").build(); - throw new WebApplicationException(response); - } catch (UnauthorizedException ue) { - Response response = Response.status( - Response.Status.UNAUTHORIZED).entity("Create failed reason " + ue.getErrorReason()).type("text/plain").build(); - throw new WebApplicationException(response); - } catch (Exception e) { - if (logger.isDebugEnabled()) { - logger.debug("Caught exception in createLocationAuthority", e); - } - Response response = Response.status( - Response.Status.INTERNAL_SERVER_ERROR).entity("Create failed").type("text/plain").build(); - throw new WebApplicationException(response); - } - } - - /** - * Gets the location authority by name. - * - * @param specifier the specifier - * - * @return the location authority by name - */ - @GET - @Path("urn:cspace:name({specifier})") - public MultipartOutput getLocationAuthorityByName(@PathParam("specifier") String specifier) { - if (specifier == null) { - logger.error("getLocationAuthority: missing name!"); - Response response = Response.status(Response.Status.BAD_REQUEST).entity( - "get failed on LocationAuthority (missing specifier)").type( - "text/plain").build(); - throw new WebApplicationException(response); - } - String whereClause = - LocationAuthorityJAXBSchema.LOCATIONAUTHORITIES_COMMON+ - ":"+LocationAuthorityJAXBSchema.SHORT_IDENTIFIER+ - "='"+specifier+"'"; - // We only get a single doc - if there are multiple, - // it is an error in use. - - if (logger.isDebugEnabled()) { - logger.debug("getLocationAuthority with name=" + specifier); - } - MultipartOutput result = null; - try { - ServiceContext ctx = createServiceContext(); - DocumentHandler handler = createDocumentHandler(ctx); - DocumentFilter myFilter = new DocumentFilter(whereClause, 0, 1); - handler.setDocumentFilter(myFilter); - getRepositoryClient(ctx).get(ctx, handler); - result = (MultipartOutput) ctx.getOutput(); - } catch (UnauthorizedException ue) { - Response response = Response.status( - Response.Status.UNAUTHORIZED).entity("Get failed reason " + ue.getErrorReason()).type("text/plain").build(); - throw new WebApplicationException(response); - } catch (DocumentNotFoundException dnfe) { - if (logger.isDebugEnabled()) { - logger.debug("getLocationAuthority", dnfe); - } - Response response = Response.status(Response.Status.NOT_FOUND).entity( - "Get failed on LocationAuthority spec=" + specifier).type( - "text/plain").build(); - throw new WebApplicationException(response); - } catch (Exception e) { - if (logger.isDebugEnabled()) { - logger.debug("getLocationAuthority", e); - } - Response response = Response.status( - Response.Status.INTERNAL_SERVER_ERROR).entity("Get failed").type("text/plain").build(); - throw new WebApplicationException(response); - } - if (result == null) { - Response response = Response.status(Response.Status.NOT_FOUND).entity( - "Get failed, the requested LocationAuthority spec:" + specifier + ": was not found.").type( - "text/plain").build(); - throw new WebApplicationException(response); - } - return result; - } - - /** - * Gets the entities referencing this Location instance. The service type - * can be passed as a query param "type", and must match a configured type - * for the service bindings. If not set, the type defaults to - * ServiceBindingUtils.SERVICE_TYPE_PROCEDURE. - * - * @param csid the parent csid - * @param itemcsid the location csid - * @param ui the ui - * - * @return the info for the referencing objects - */ - @GET - @Path("{csid}/items/{itemcsid}/refObjs") - @Produces("application/xml") - public AuthorityRefDocList getReferencingObjects( - @PathParam("csid") String parentcsid, - @PathParam("itemcsid") String itemcsid, - @Context UriInfo ui) { - AuthorityRefDocList authRefDocList = null; - if (logger.isDebugEnabled()) { - logger.debug("getReferencingObjects with parentcsid=" - + parentcsid + " and itemcsid=" + itemcsid); - } - if (parentcsid == null || "".equals(parentcsid) - || itemcsid == null || "".equals(itemcsid)) { - logger.error("getLocation: missing parentcsid or itemcsid!"); - Response response = Response.status(Response.Status.BAD_REQUEST).entity( - "get failed on Location with parentcsid=" - + parentcsid + " and itemcsid=" + itemcsid).type( - "text/plain").build(); - throw new WebApplicationException(response); - } - try { - // Note that we have to create the service context for the Items, not the main service - ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(getItemServiceName()); - DocumentHandler handler = createItemDocumentHandler(ctx, parentcsid); - RepositoryClient repoClient = getRepositoryClient(ctx); - DocumentFilter myFilter = handler.createDocumentFilter(); - MultivaluedMap queryParams = ui.getQueryParameters(); - myFilter.setPagination(queryParams); - String serviceType = ServiceBindingUtils.SERVICE_TYPE_PROCEDURE; - List list = queryParams.remove(ServiceBindingUtils.SERVICE_TYPE_PROP); - if (list != null) { - serviceType = list.get(0); - } - DocumentWrapper docWrapper = repoClient.getDoc(ctx, itemcsid); - DocumentModel docModel = docWrapper.getWrappedObject(); - String refName = (String)docModel.getPropertyValue(LocationJAXBSchema.REF_NAME); - - authRefDocList = RefNameServiceUtils.getAuthorityRefDocs(ctx, repoClient, - serviceType, refName, - myFilter.getPageSize(), myFilter.getStartPage(), true ); - } catch (UnauthorizedException ue) { - Response response = Response.status( - Response.Status.UNAUTHORIZED).entity("Get failed reason " + ue.getErrorReason()).type("text/plain").build(); - throw new WebApplicationException(response); - } catch (DocumentNotFoundException dnfe) { - if (logger.isDebugEnabled()) { - logger.debug("getReferencingObjects", dnfe); - } - Response response = Response.status(Response.Status.NOT_FOUND).entity( - "GetReferencingObjects failed with parentcsid=" - + parentcsid + " and itemcsid=" + itemcsid).type( - "text/plain").build(); - throw new WebApplicationException(response); - } catch (Exception e) { // Includes DocumentException - if (logger.isDebugEnabled()) { - logger.debug("GetReferencingObjects", e); - } - Response response = Response.status( - Response.Status.INTERNAL_SERVER_ERROR).entity("Get failed").type("text/plain").build(); - throw new WebApplicationException(response); - } - if (authRefDocList == null) { - Response response = Response.status(Response.Status.NOT_FOUND).entity( - "Get failed, the requested Location CSID:" + itemcsid + ": was not found.").type( - "text/plain").build(); - throw new WebApplicationException(response); - } - return authRefDocList; - } - - @GET - @Path("{csid}") - public MultipartOutput getLocationAuthority(@PathParam("csid") String csid) { - if (csid == null) { - logger.error("getLocationAuthority: missing csid!"); - Response response = Response.status(Response.Status.BAD_REQUEST).entity( - "get failed on LocationAuthority csid=" + csid).type( - "text/plain").build(); - throw new WebApplicationException(response); - } - if (logger.isDebugEnabled()) { - logger.debug("getLocationAuthority with path(id)=" + csid); - } - MultipartOutput result = null; - try { - ServiceContext ctx = createServiceContext(); - DocumentHandler handler = createDocumentHandler(ctx); - getRepositoryClient(ctx).get(ctx, csid, handler); - result = (MultipartOutput) ctx.getOutput(); - } catch (UnauthorizedException ue) { - Response response = Response.status( - Response.Status.UNAUTHORIZED).entity("Get failed reason " + ue.getErrorReason()).type("text/plain").build(); - throw new WebApplicationException(response); - } catch (DocumentNotFoundException dnfe) { - if (logger.isDebugEnabled()) { - logger.debug("getLocationAuthority", dnfe); - } - Response response = Response.status(Response.Status.NOT_FOUND).entity( - "Get failed on LocationAuthority csid=" + csid).type( - "text/plain").build(); - throw new WebApplicationException(response); - } catch (Exception e) { - if (logger.isDebugEnabled()) { - logger.debug("getLocationAuthority", e); - } - Response response = Response.status( - Response.Status.INTERNAL_SERVER_ERROR).entity("Get failed").type("text/plain").build(); - throw new WebApplicationException(response); - } - if (result == null) { - Response response = Response.status(Response.Status.NOT_FOUND).entity( - "Get failed, the requested LocationAuthority CSID:" + csid + ": was not found.").type( - "text/plain").build(); - throw new WebApplicationException(response); - } - return result; - } - - /** - * Gets the location authority list. - * - * @param ui the ui - * - * @return the location authority list - */ - @GET - @Produces("application/xml") - public LocationauthoritiesCommonList getLocationAuthorityList(@Context UriInfo ui) { - LocationauthoritiesCommonList locationAuthorityObjectList = new LocationauthoritiesCommonList(); - try { - ServiceContext ctx = createServiceContext(); - MultivaluedMap queryParams = ui.getQueryParameters(); - DocumentHandler handler = createDocumentHandler(ctx); - DocumentFilter myFilter = handler.createDocumentFilter(); //new DocumentFilter(); - myFilter.setPagination(queryParams); //FIXME - String nameQ = queryParams.getFirst("refName"); - if (nameQ != null) { - myFilter.setWhereClause("locationauthorities_common:refName='" + nameQ + "'"); - } - handler.setDocumentFilter(myFilter); - getRepositoryClient(ctx).getFiltered(ctx, handler); - locationAuthorityObjectList = (LocationauthoritiesCommonList) handler.getCommonPartList(); - } catch (UnauthorizedException ue) { - Response response = Response.status( - Response.Status.UNAUTHORIZED).entity("Index failed reason " + ue.getErrorReason()).type("text/plain").build(); - throw new WebApplicationException(response); - } catch (Exception e) { - if (logger.isDebugEnabled()) { - logger.debug("Caught exception in getLocationAuthorityList", e); - } - Response response = Response.status( - Response.Status.INTERNAL_SERVER_ERROR).entity("Index failed").type("text/plain").build(); - throw new WebApplicationException(response); - } - return locationAuthorityObjectList; - } - - /** - * Update location authority. - * - * @param csid the csid - * @param theUpdate the the update - * - * @return the multipart output - */ - @PUT - @Path("{csid}") - public MultipartOutput updateLocationAuthority( - @PathParam("csid") String csid, - MultipartInput theUpdate) { - if (logger.isDebugEnabled()) { - logger.debug("updateLocationAuthority with csid=" + csid); - } - if (csid == null || "".equals(csid)) { - logger.error("updateLocationAuthority: missing csid!"); - Response response = Response.status(Response.Status.BAD_REQUEST).entity( - "update failed on LocationAuthority csid=" + csid).type( - "text/plain").build(); - throw new WebApplicationException(response); - } - MultipartOutput result = null; - try { - ServiceContext ctx = createServiceContext(theUpdate); - DocumentHandler handler = createDocumentHandler(ctx); - getRepositoryClient(ctx).update(ctx, csid, handler); - result = (MultipartOutput) ctx.getOutput(); - } catch (BadRequestException bre) { - Response response = Response.status( - Response.Status.BAD_REQUEST).entity("Create failed reason " + bre.getErrorReason()).type("text/plain").build(); - throw new WebApplicationException(response); - } catch (UnauthorizedException ue) { - Response response = Response.status( - Response.Status.UNAUTHORIZED).entity("Update failed reason " + ue.getErrorReason()).type("text/plain").build(); - throw new WebApplicationException(response); - } catch (DocumentNotFoundException dnfe) { - if (logger.isDebugEnabled()) { - logger.debug("caugth exception in updateLocationAuthority", dnfe); - } - Response response = Response.status(Response.Status.NOT_FOUND).entity( - "Update failed on LocationAuthority csid=" + csid).type( - "text/plain").build(); - throw new WebApplicationException(response); - } catch (Exception e) { - Response response = Response.status( - Response.Status.INTERNAL_SERVER_ERROR).entity("Update failed").type("text/plain").build(); - throw new WebApplicationException(response); - } - return result; - } - - /** - * Delete location authority. - * - * @param csid the csid - * - * @return the response - */ - @DELETE - @Path("{csid}") - public Response deleteLocationAuthority(@PathParam("csid") String csid) { - - if (logger.isDebugEnabled()) { - logger.debug("deleteLocationAuthority with csid=" + csid); - } - if (csid == null || "".equals(csid)) { - logger.error("deleteLocationAuthority: missing csid!"); - Response response = Response.status(Response.Status.BAD_REQUEST).entity( - "delete failed on LocationAuthority csid=" + csid).type( - "text/plain").build(); - throw new WebApplicationException(response); - } - try { - ServiceContext ctx = createServiceContext(); - getRepositoryClient(ctx).delete(ctx, csid); - return Response.status(HttpResponseCodes.SC_OK).build(); - } catch (UnauthorizedException ue) { - Response response = Response.status( - Response.Status.UNAUTHORIZED).entity("Delete failed reason " + ue.getErrorReason()).type("text/plain").build(); - throw new WebApplicationException(response); - } catch (DocumentNotFoundException dnfe) { - if (logger.isDebugEnabled()) { - logger.debug("caught exception in deleteLocationAuthority", dnfe); - } - Response response = Response.status(Response.Status.NOT_FOUND).entity( - "Delete failed on LocationAuthority csid=" + csid).type( - "text/plain").build(); - throw new WebApplicationException(response); - } catch (Exception e) { - Response response = Response.status( - Response.Status.INTERNAL_SERVER_ERROR).entity("Delete failed").type("text/plain").build(); - throw new WebApplicationException(response); - } - - } - - /************************************************************************* - * Location parts - this is a sub-resource of LocationAuthority - *************************************************************************/ - @POST - @Path("{csid}/items") - public Response createLocation(@PathParam("csid") String parentcsid, MultipartInput input) { - try { - ServiceContext ctx = createServiceContext(getItemServiceName(), input); - DocumentHandler handler = createItemDocumentHandler(ctx, parentcsid); - String itemcsid = getRepositoryClient(ctx).create(ctx, handler); - UriBuilder path = UriBuilder.fromResource(LocationAuthorityResource.class); - path.path(parentcsid + "/items/" + itemcsid); - Response response = Response.created(path.build()).build(); - return response; - } catch (BadRequestException bre) { - Response response = Response.status( - Response.Status.BAD_REQUEST).entity("Create failed reason " + bre.getErrorReason()).type("text/plain").build(); - throw new WebApplicationException(response); - } catch (UnauthorizedException ue) { - Response response = Response.status( - Response.Status.UNAUTHORIZED).entity("Create failed reason " + ue.getErrorReason()).type("text/plain").build(); - throw new WebApplicationException(response); - } catch (Exception e) { - if (logger.isDebugEnabled()) { - logger.debug("Caught exception in createLocation", e); - } - Response response = Response.status( - Response.Status.INTERNAL_SERVER_ERROR).entity("Create failed").type("text/plain").build(); - throw new WebApplicationException(response); - } - } - - /** - * Gets the location. - * - * @param parentcsid the parentcsid - * @param itemcsid the itemcsid - * - * @return the location - */ - @GET - @Path("{csid}/items/{itemcsid}") - public MultipartOutput getLocation( - @PathParam("csid") String parentcsid, - @PathParam("itemcsid") String itemcsid) { - if (logger.isDebugEnabled()) { - logger.debug("getLocation with parentcsid=" + parentcsid + " and itemcsid=" + itemcsid); - } - if (parentcsid == null || "".equals(parentcsid) - || itemcsid == null || "".equals(itemcsid)) { - logger.error("getLocation: missing parentcsid or itemcsid!"); - Response response = Response.status(Response.Status.BAD_REQUEST).entity( - "get failed on Location with parentcsid=" - + parentcsid + " and itemcsid=" + itemcsid).type( - "text/plain").build(); - throw new WebApplicationException(response); - } - MultipartOutput result = null; - try { - // Note that we have to create the service context for the Items, not the main service - ServiceContext ctx = createServiceContext(getItemServiceName()); - DocumentHandler handler = createItemDocumentHandler(ctx, parentcsid); - getRepositoryClient(ctx).get(ctx, itemcsid, handler); - // TODO should we assert that the item is in the passed locationAuthority? - result = (MultipartOutput) ctx.getOutput(); - } catch (UnauthorizedException ue) { - Response response = Response.status( - Response.Status.UNAUTHORIZED).entity("Get failed reason " + ue.getErrorReason()).type("text/plain").build(); - throw new WebApplicationException(response); - } catch (DocumentNotFoundException dnfe) { - if (logger.isDebugEnabled()) { - logger.debug("getLocation", dnfe); - } - Response response = Response.status(Response.Status.NOT_FOUND).entity( - "Get failed on Location csid=" + itemcsid).type( - "text/plain").build(); - throw new WebApplicationException(response); - } catch (Exception e) { - if (logger.isDebugEnabled()) { - logger.debug("getLocation", e); - } - Response response = Response.status( - Response.Status.INTERNAL_SERVER_ERROR).entity("Get failed").type("text/plain").build(); - throw new WebApplicationException(response); - } - if (result == null) { - Response response = Response.status(Response.Status.NOT_FOUND).entity( - "Get failed, the requested Location CSID:" + itemcsid + ": was not found.").type( - "text/plain").build(); - throw new WebApplicationException(response); - } - return result; - } - - /** - * Gets the location list. - * - * @param parentcsid the parentcsid - * @param partialTerm the partial term - * @param ui the ui - * - * @return the location list - */ - @GET - @Path("{csid}/items") - @Produces("application/xml") - public LocationsCommonList getLocationList( - @PathParam("csid") String parentcsid, - @QueryParam (IQueryManager.SEARCH_TYPE_PARTIALTERM) String partialTerm, - @Context UriInfo ui) { - LocationsCommonList locationObjectList = new LocationsCommonList(); - try { - // Note that docType defaults to the ServiceName, so we're fine with that. - MultivaluedMap queryParams = ui.getQueryParameters(); - ServiceContext ctx = createServiceContext(getItemServiceName(), - queryParams); - DocumentHandler handler = createItemDocumentHandler(ctx, parentcsid); - DocumentFilter myFilter = handler.getDocumentFilter(); - - // Add the where clause "locations_common:inAuthority='" + parentcsid + "'" - myFilter.setWhereClause(LocationJAXBSchema.LOCATIONS_COMMON + ":" + - LocationJAXBSchema.IN_AUTHORITY + "='" + parentcsid + "'"); - - // AND locations_common:displayName LIKE '%partialTerm%' - if (partialTerm != null && !partialTerm.isEmpty()) { - String ptClause = - LocationJAXBSchema.LOCATIONS_COMMON + ":" + - LocationJAXBSchema.DISPLAY_NAME + - " LIKE " + - "'%" + partialTerm + "%'"; - myFilter.appendWhereClause(ptClause, IQueryManager.SEARCH_QUALIFIER_AND); - } - getRepositoryClient(ctx).getFiltered(ctx, handler); - locationObjectList = (LocationsCommonList) handler.getCommonPartList(); - } catch (UnauthorizedException ue) { - Response response = Response.status( - Response.Status.UNAUTHORIZED).entity("Index failed reason " + ue.getErrorReason()).type("text/plain").build(); - throw new WebApplicationException(response); - } catch (Exception e) { - if (logger.isDebugEnabled()) { - logger.debug("Caught exception in getLocationList", e); - } - Response response = Response.status( - Response.Status.INTERNAL_SERVER_ERROR).entity("Index failed").type("text/plain").build(); - throw new WebApplicationException(response); - } - return locationObjectList; - } - - - /** - * Gets the location list by auth name. - * - * @param parentSpecifier the parent specifier - * @param partialTerm the partial term - * @param ui the ui - * - * @return the location list by auth name - */ - @GET - @Path("urn:cspace:name({specifier})/items") - @Produces("application/xml") - public LocationsCommonList getLocationListByAuthName( - @PathParam("specifier") String parentSpecifier, - @QueryParam (IQueryManager.SEARCH_TYPE_PARTIALTERM) String partialTerm, - @Context UriInfo ui) { - LocationsCommonList locationObjectList = new LocationsCommonList(); - try { - MultivaluedMap queryParams = ui.getQueryParameters(); - String whereClause = - LocationAuthorityJAXBSchema.LOCATIONAUTHORITIES_COMMON+ - ":"+LocationAuthorityJAXBSchema.SHORT_IDENTIFIER+ - "='"+parentSpecifier+"'"; - // Need to get an Authority by name - ServiceContext ctx = createServiceContext(queryParams); - String parentcsid = - getRepositoryClient(ctx).findDocCSID(ctx, whereClause); - - ctx = createServiceContext(getItemServiceName(), queryParams); - DocumentHandler handler = createItemDocumentHandler(ctx, parentcsid); - DocumentFilter myFilter = handler.createDocumentFilter(); //new DocumentFilter(); - myFilter.setPagination(queryParams); //FIXME - - // Add the where clause "locations_common:inAuthority='" + parentcsid + "'" - myFilter.setWhereClause(LocationJAXBSchema.LOCATIONS_COMMON + ":" + - LocationJAXBSchema.IN_AUTHORITY + "='" + parentcsid + "'"); - - // AND locations_common:displayName LIKE '%partialTerm%' - if (partialTerm != null && !partialTerm.isEmpty()) { - String ptClause = // "AND " + - LocationJAXBSchema.LOCATIONS_COMMON + ":" + - LocationJAXBSchema.DISPLAY_NAME + - " LIKE " + - "'%" + partialTerm + "%'"; - myFilter.appendWhereClause(ptClause, "AND"); - } - - handler.setDocumentFilter(myFilter); - getRepositoryClient(ctx).getFiltered(ctx, handler); - locationObjectList = (LocationsCommonList) handler.getCommonPartList(); - } catch (UnauthorizedException ue) { - Response response = Response.status( - Response.Status.UNAUTHORIZED).entity("Index failed reason " + ue.getErrorReason()).type("text/plain").build(); - throw new WebApplicationException(response); - } catch (Exception e) { - if (logger.isDebugEnabled()) { - logger.debug("Caught exception in getLocationList", e); - } - Response response = Response.status( - Response.Status.INTERNAL_SERVER_ERROR).entity("Index failed").type("text/plain").build(); - throw new WebApplicationException(response); - } - return locationObjectList; - } - - /** - * Update location. - * - * @param parentcsid the parentcsid - * @param itemcsid the itemcsid - * @param theUpdate the the update - * - * @return the multipart output - */ - @PUT - @Path("{csid}/items/{itemcsid}") - public MultipartOutput updateLocation( - @PathParam("csid") String parentcsid, - @PathParam("itemcsid") String itemcsid, - MultipartInput theUpdate) { - if (logger.isDebugEnabled()) { - logger.debug("updateLocation with parentcsid=" + parentcsid + " and itemcsid=" + itemcsid); - } - if (parentcsid == null || "".equals(parentcsid)) { - logger.error("updateLocation: missing csid!"); - Response response = Response.status(Response.Status.BAD_REQUEST).entity( - "update failed on Location parentcsid=" + parentcsid).type( - "text/plain").build(); - throw new WebApplicationException(response); - } - if (itemcsid == null || "".equals(itemcsid)) { - logger.error("updateLocation: missing itemcsid!"); - Response response = Response.status(Response.Status.BAD_REQUEST).entity( - "update failed on Location=" + itemcsid).type( - "text/plain").build(); - throw new WebApplicationException(response); - } - MultipartOutput result = null; - try { - // Note that we have to create the service context for the Items, not the main service - ServiceContext ctx = createServiceContext(getItemServiceName(), - theUpdate); - DocumentHandler handler = createItemDocumentHandler(ctx, parentcsid); - getRepositoryClient(ctx).update(ctx, itemcsid, handler); - result = (MultipartOutput) ctx.getOutput(); - } catch (BadRequestException bre) { - Response response = Response.status( - Response.Status.BAD_REQUEST).entity("Create failed reason " + bre.getErrorReason()).type("text/plain").build(); - throw new WebApplicationException(response); - } catch (UnauthorizedException ue) { - Response response = Response.status( - Response.Status.UNAUTHORIZED).entity("Update failed reason " + ue.getErrorReason()).type("text/plain").build(); - throw new WebApplicationException(response); - } catch (DocumentNotFoundException dnfe) { - if (logger.isDebugEnabled()) { - logger.debug("caught exception in updateLocation", dnfe); - } - Response response = Response.status(Response.Status.NOT_FOUND).entity( - "Update failed on Location csid=" + itemcsid).type( - "text/plain").build(); - throw new WebApplicationException(response); - } catch (Exception e) { - Response response = Response.status( - Response.Status.INTERNAL_SERVER_ERROR).entity("Update failed").type("text/plain").build(); - throw new WebApplicationException(response); - } - return result; - } - - /** - * Delete location. - * - * @param parentcsid the parentcsid - * @param itemcsid the itemcsid - * - * @return the response - */ - @DELETE - @Path("{csid}/items/{itemcsid}") - public Response deleteLocation( - @PathParam("csid") String parentcsid, - @PathParam("itemcsid") String itemcsid) { - if (logger.isDebugEnabled()) { - logger.debug("deleteLocation with parentcsid=" + parentcsid + " and itemcsid=" + itemcsid); - } - if (parentcsid == null || "".equals(parentcsid)) { - logger.error("deleteLocation: missing csid!"); - Response response = Response.status(Response.Status.BAD_REQUEST).entity( - "delete failed on Location parentcsid=" + parentcsid).type( - "text/plain").build(); - throw new WebApplicationException(response); - } - if (itemcsid == null || "".equals(itemcsid)) { - logger.error("deleteLocation: missing itemcsid!"); - Response response = Response.status(Response.Status.BAD_REQUEST).entity( - "delete failed on Location=" + itemcsid).type( - "text/plain").build(); - throw new WebApplicationException(response); - } - try { - // Note that we have to create the service context for the Items, not the main service - ServiceContext ctx = createServiceContext(getItemServiceName()); - getRepositoryClient(ctx).delete(ctx, itemcsid); - return Response.status(HttpResponseCodes.SC_OK).build(); - } catch (UnauthorizedException ue) { - Response response = Response.status( - Response.Status.UNAUTHORIZED).entity("Delete failed reason " + ue.getErrorReason()).type("text/plain").build(); - throw new WebApplicationException(response); - } catch (DocumentNotFoundException dnfe) { - if (logger.isDebugEnabled()) { - logger.debug("caught exception in deleteLocation", dnfe); - } - Response response = Response.status(Response.Status.NOT_FOUND).entity( - "Delete failed on Location itemcsid=" + itemcsid).type( - "text/plain").build(); - throw new WebApplicationException(response); - } catch (Exception e) { - Response response = Response.status( - Response.Status.INTERNAL_SERVER_ERROR).entity("Delete failed").type("text/plain").build(); - throw new WebApplicationException(response); - } - + @Override + public Class getCommonPartClass() { + return LocationauthoritiesCommon.class; } - } diff --git a/services/location/service/src/main/java/org/collectionspace/services/location/nuxeo/LocationAuthorityDocumentModelHandler.java b/services/location/service/src/main/java/org/collectionspace/services/location/nuxeo/LocationAuthorityDocumentModelHandler.java index 8990eb7ab..9917dff16 100644 --- a/services/location/service/src/main/java/org/collectionspace/services/location/nuxeo/LocationAuthorityDocumentModelHandler.java +++ b/services/location/service/src/main/java/org/collectionspace/services/location/nuxeo/LocationAuthorityDocumentModelHandler.java @@ -26,10 +26,11 @@ package org.collectionspace.services.location.nuxeo; import java.util.Iterator; import java.util.List; -import org.collectionspace.services.LocationAuthorityJAXBSchema; import org.collectionspace.services.common.document.DocumentHandler.Action; import org.collectionspace.services.common.document.DocumentFilter; import org.collectionspace.services.common.document.DocumentWrapper; +import org.collectionspace.services.common.vocabulary.AuthorityJAXBSchema; +import org.collectionspace.services.common.vocabulary.nuxeo.AuthorityDocumentModelHandler; import org.collectionspace.services.location.LocationauthoritiesCommon; import org.collectionspace.services.location.LocationauthoritiesCommonList; import org.collectionspace.services.location.LocationauthoritiesCommonList.LocationauthorityListItem; @@ -48,63 +49,7 @@ import org.slf4j.LoggerFactory; * $LastChangedDate: $ */ public class LocationAuthorityDocumentModelHandler - extends RemoteDocumentModelHandlerImpl { - - private final Logger logger = LoggerFactory.getLogger(LocationAuthorityDocumentModelHandler.class); - /** - * locationAuthority is used to stash JAXB object to use when handle is called - * for Action.CREATE, Action.UPDATE or Action.GET - */ - private LocationauthoritiesCommon locationAuthority; - /** - * locationAuthorityList is stashed when handle is called - * for ACTION.GET_ALL - */ - private LocationauthoritiesCommonList locationAuthorityList; - - - /** - * getCommonPart get associated locationAuthority - * @return - */ - @Override - public LocationauthoritiesCommon getCommonPart() { - return locationAuthority; - } - - /** - * setCommonPart set associated locationAuthority - * @param locationAuthority - */ - @Override - public void setCommonPart(LocationauthoritiesCommon locationAuthority) { - this.locationAuthority = locationAuthority; - } - - /** - * getCommonPartList get associated locationAuthority (for index/GET_ALL) - * @return - */ - @Override - public LocationauthoritiesCommonList getCommonPartList() { - return locationAuthorityList; - } - - @Override - public void setCommonPartList(LocationauthoritiesCommonList locationAuthorityList) { - this.locationAuthorityList = locationAuthorityList; - } - - @Override - public LocationauthoritiesCommon extractCommonPart(DocumentWrapper wrapDoc) - throws Exception { - throw new UnsupportedOperationException(); - } - - @Override - public void fillCommonPart(LocationauthoritiesCommon locationAuthorityObject, DocumentWrapper wrapDoc) throws Exception { - throw new UnsupportedOperationException(); - } + extends AuthorityDocumentModelHandler { @Override public LocationauthoritiesCommonList extractCommonPartList(DocumentWrapper wrapDoc) throws Exception { @@ -114,18 +59,19 @@ public class LocationAuthorityDocumentModelHandler //FIXME: iterating over a long list of documents is not a long term //strategy...need to change to more efficient iterating in future List list = coList.getLocationauthorityListItem(); + String label = getServiceContext().getCommonPartLabel(); Iterator iter = wrapDoc.getWrappedObject().iterator(); while(iter.hasNext()){ DocumentModel docModel = iter.next(); LocationauthorityListItem ilistItem = new LocationauthorityListItem(); - ilistItem.setDisplayName((String) docModel.getProperty(getServiceContext().getCommonPartLabel(), - LocationAuthorityJAXBSchema.DISPLAY_NAME)); - ilistItem.setRefName((String) docModel.getProperty(getServiceContext().getCommonPartLabel(), - LocationAuthorityJAXBSchema.REF_NAME)); - ilistItem.setShortIdentifier((String) docModel.getProperty(getServiceContext().getCommonPartLabel(), - LocationAuthorityJAXBSchema.SHORT_IDENTIFIER)); - ilistItem.setVocabType((String) docModel.getProperty(getServiceContext().getCommonPartLabel(), - LocationAuthorityJAXBSchema.VOCAB_TYPE)); + ilistItem.setDisplayName((String) docModel.getProperty(label, + AuthorityJAXBSchema.DISPLAY_NAME)); + ilistItem.setRefName((String) docModel.getProperty(label, + AuthorityJAXBSchema.REF_NAME)); + ilistItem.setShortIdentifier((String) docModel.getProperty(label, + AuthorityJAXBSchema.SHORT_IDENTIFIER)); + ilistItem.setVocabType((String) docModel.getProperty(label, + AuthorityJAXBSchema.VOCAB_TYPE)); String id = NuxeoUtils.extractId(docModel.getPathAsString()); ilistItem.setUri(getServiceContextPath() + id); ilistItem.setCsid(id); diff --git a/services/location/service/src/main/java/org/collectionspace/services/location/nuxeo/LocationDocumentModelHandler.java b/services/location/service/src/main/java/org/collectionspace/services/location/nuxeo/LocationDocumentModelHandler.java index 53de3e74a..4dcccdf27 100644 --- a/services/location/service/src/main/java/org/collectionspace/services/location/nuxeo/LocationDocumentModelHandler.java +++ b/services/location/service/src/main/java/org/collectionspace/services/location/nuxeo/LocationDocumentModelHandler.java @@ -33,6 +33,7 @@ import org.collectionspace.services.LocationJAXBSchema; import org.collectionspace.services.common.document.DocumentFilter; import org.collectionspace.services.common.document.DocumentWrapper; import org.collectionspace.services.common.service.ObjectPartType; +import org.collectionspace.services.common.vocabulary.nuxeo.AuthorityItemDocumentModelHandler; import org.collectionspace.services.nuxeo.client.java.RemoteDocumentModelHandlerImpl; import org.collectionspace.services.nuxeo.util.NuxeoUtils; import org.collectionspace.services.location.LocationsCommon; @@ -54,7 +55,7 @@ import org.slf4j.LoggerFactory; * */ public class LocationDocumentModelHandler - extends RemoteDocumentModelHandlerImpl { + extends AuthorityItemDocumentModelHandler { /** The logger. */ private final Logger logger = LoggerFactory.getLogger(LocationDocumentModelHandler.class); @@ -63,40 +64,9 @@ public class LocationDocumentModelHandler */ private static final String COMMON_PART_LABEL = "locations_common"; - /** - * location is used to stash JAXB object to use when handle is called - * for Action.CREATE, Action.UPDATE or Action.GET - */ - private LocationsCommon location; - /** - * locationList is stashed when handle is called - * for ACTION.GET_ALL - */ - private LocationsCommonList locationList; - - /** - * inAuthority is the parent OrgAuthority for this context - */ - private String inAuthority; - - /** - * Gets the in authority. - * - * @return the in authority - */ - public String getInAuthority() { - return inAuthority; - } - - /** - * Sets the in authority. - * - * @param inAuthority the new in authority - */ - public void setInAuthority(String inAuthority) { - this.inAuthority = inAuthority; - } - + public LocationDocumentModelHandler() { + super(COMMON_PART_LABEL); + } /* (non-Javadoc) * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#handleCreate(org.collectionspace.services.common.document.DocumentWrapper) @@ -155,75 +125,6 @@ public class LocationDocumentModelHandler return newStr.toString(); } - /** - * getCommonPart get associated location - * @return - */ - @Override - public LocationsCommon getCommonPart() { - return location; - } - - /** - * setCommonPart set associated location - * @param location - */ - @Override - public void setCommonPart(LocationsCommon location) { - this.location = location; - } - - /** - * getCommonPartList get associated location (for index/GET_ALL) - * @return - */ - @Override - public LocationsCommonList getCommonPartList() { - return locationList; - } - - /* (non-Javadoc) - * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#setCommonPartList(java.lang.Object) - */ - @Override - public void setCommonPartList(LocationsCommonList locationList) { - this.locationList = locationList; - } - - /* (non-Javadoc) - * @see org.collectionspace.services.nuxeo.client.java.RemoteDocumentModelHandlerImpl#extractPart(org.nuxeo.ecm.core.api.DocumentModel, java.lang.String, org.collectionspace.services.common.service.ObjectPartType) - */ - @Override - protected Map extractPart(DocumentModel docModel, String schema, ObjectPartType partMeta) - throws Exception { - Map unQObjectProperties = super.extractPart(docModel, schema, partMeta); - - // Add the CSID to the common part - if (partMeta.getLabel().equalsIgnoreCase(COMMON_PART_LABEL)) { - String csid = NuxeoUtils.extractId(docModel.getPathAsString()); - unQObjectProperties.put("csid", csid); - } - - return unQObjectProperties; - } - - /* (non-Javadoc) - * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#extractCommonPart(org.collectionspace.services.common.document.DocumentWrapper) - */ - @Override - public LocationsCommon extractCommonPart(DocumentWrapper wrapDoc) - throws Exception { - throw new UnsupportedOperationException(); - } - - /* (non-Javadoc) - * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#fillCommonPart(java.lang.Object, org.collectionspace.services.common.document.DocumentWrapper) - */ - @Override - public void fillCommonPart(LocationsCommon locationObject, DocumentWrapper wrapDoc) throws Exception { - throw new UnsupportedOperationException(); - } - /* (non-Javadoc) * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#extractCommonPartList(org.collectionspace.services.common.document.DocumentWrapper) */ diff --git a/services/organization/3rdparty/nuxeo-platform-cs-organization/src/main/resources/schemas/organizations_common.xsd b/services/organization/3rdparty/nuxeo-platform-cs-organization/src/main/resources/schemas/organizations_common.xsd index 1d234996a..8c10c5452 100644 --- a/services/organization/3rdparty/nuxeo-platform-cs-organization/src/main/resources/schemas/organizations_common.xsd +++ b/services/organization/3rdparty/nuxeo-platform-cs-organization/src/main/resources/schemas/organizations_common.xsd @@ -26,6 +26,7 @@ + @@ -39,7 +40,6 @@ - diff --git a/services/organization/client/src/test/java/org/collectionspace/services/client/test/OrgAuthorityServiceTest.java b/services/organization/client/src/test/java/org/collectionspace/services/client/test/OrgAuthorityServiceTest.java index 4ee853c5d..5f29214fa 100644 --- a/services/organization/client/src/test/java/org/collectionspace/services/client/test/OrgAuthorityServiceTest.java +++ b/services/organization/client/src/test/java/org/collectionspace/services/client/test/OrgAuthorityServiceTest.java @@ -816,40 +816,45 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { // Submit the request to the service and store the response. OrgAuthorityClient client = new OrgAuthorityClient(); ClientResponse res = client.readItem(knownResourceId, knownItemResourceId); - 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(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, Response.Status.OK.getStatusCode()); - - // Check whether organization has expected displayName. - MultipartInput input = (MultipartInput) res.getEntity(); - OrganizationsCommon organization = (OrganizationsCommon) extractPart(input, - client.getItemCommonPartName(), OrganizationsCommon.class); - Assert.assertNotNull(organization); - // Try to Update with computed false and no displayName - organization.setDisplayNameComputed(false); - organization.setDisplayName(null); - - // Submit the updated resource to the service and store the response. - MultipartOutput output = new MultipartOutput(); - OutputPart commonPart = output.addPart(organization, MediaType.APPLICATION_XML_TYPE); - commonPart.getHeaders().add("label", client.getItemCommonPartName()); - res = client.updateItem(knownResourceId, knownItemResourceId, output); - statusCode = res.getStatus(); - - // Check the status code of the response: does it match the expected response(s)? - if(logger.isDebugEnabled()){ - logger.debug("updateItem: status = " + statusCode); - } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + 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(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, Response.Status.OK.getStatusCode()); + + // Check whether organization has expected displayName. + MultipartInput input = (MultipartInput) res.getEntity(); + OrganizationsCommon organization = (OrganizationsCommon) extractPart(input, + client.getItemCommonPartName(), OrganizationsCommon.class); + Assert.assertNotNull(organization); + // Try to Update with computed false and no displayName + organization.setDisplayNameComputed(false); + organization.setDisplayName(null); + + // Submit the updated resource to the service and store the response. + MultipartOutput output = new MultipartOutput(); + OutputPart commonPart = output.addPart(organization, MediaType.APPLICATION_XML_TYPE); + commonPart.getHeaders().add("label", client.getItemCommonPartName()); + res.releaseConnection(); + res = client.updateItem(knownResourceId, knownItemResourceId, output); + statusCode = res.getStatus(); + + // Check the status code of the response: does it match the expected response(s)? + if(logger.isDebugEnabled()){ + logger.debug("updateItem: status = " + statusCode); + } + Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + } finally { + res.releaseConnection(); + } } /** @@ -873,30 +878,33 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { ClientResponse res = client.readContact(knownResourceId, knownItemResourceId, knownContactResourceId); - 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(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); - - // Check whether we've received a contact. - MultipartInput input = (MultipartInput) res.getEntity(); - ContactsCommon contact = (ContactsCommon) extractPart(input, - new ContactClient().getCommonPartName(), ContactsCommon.class); - Assert.assertNotNull(contact); - boolean showFull = true; - if(showFull && logger.isDebugEnabled()){ - logger.debug(testName + ": returned payload:"); - logger.debug(objectAsXmlString(contact, ContactsCommon.class)); - } - Assert.assertEquals(contact.getInAuthority(), knownResourceId); - Assert.assertEquals(contact.getInItem(), knownItemResourceId); - + 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(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + + // Check whether we've received a contact. + MultipartInput input = (MultipartInput) res.getEntity(); + ContactsCommon contact = (ContactsCommon) extractPart(input, + new ContactClient().getCommonPartName(), ContactsCommon.class); + Assert.assertNotNull(contact); + boolean showFull = true; + if(showFull && logger.isDebugEnabled()){ + logger.debug(testName + ": returned payload:"); + logger.debug(objectAsXmlString(contact, ContactsCommon.class)); + } + Assert.assertEquals(contact.getInAuthority(), knownResourceId); + Assert.assertEquals(contact.getInItem(), knownItemResourceId); + } finally { + res.releaseConnection(); + } } // Failure outcomes @@ -917,16 +925,20 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { // Submit the request to the service and store the response. OrgAuthorityClient client = new OrgAuthorityClient(); ClientResponse res = client.read(NON_EXISTENT_ID); - 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(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + 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(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + } finally { + res.releaseConnection(); + } } /** @@ -947,16 +959,20 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { // Submit the request to the service and store the response. OrgAuthorityClient client = new OrgAuthorityClient(); ClientResponse res = client.readItem(knownResourceId, NON_EXISTENT_ID); - 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(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + 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(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + } finally { + res.releaseConnection(); + } } /** @@ -978,16 +994,20 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { OrgAuthorityClient client = new OrgAuthorityClient(); ClientResponse res = client.readContact(knownResourceId, knownItemResourceId, NON_EXISTENT_ID); - 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(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + 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(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + } finally { + res.releaseConnection(); + } } // --------------------------------------------------------------- @@ -1012,36 +1032,40 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { // Submit the request to the service and store the response. OrgAuthorityClient client = new OrgAuthorityClient(); ClientResponse res = client.readList(); - OrgauthoritiesCommonList 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(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); - - // Optionally output additional data about list members for debugging. - boolean iterateThroughList = false; - if (iterateThroughList && logger.isDebugEnabled()) { - List items = - list.getOrgauthorityListItem(); - int i = 0; - for (OrgauthoritiesCommonList.OrgauthorityListItem item : items) { - String csid = item.getCsid(); - logger.debug(testName + ": list-item[" + i + "] csid=" + - csid); - logger.debug(testName + ": list-item[" + i + "] displayName=" + - item.getDisplayName()); - logger.debug(testName + ": list-item[" + i + "] URI=" + - item.getUri()); - readItemList(csid, null); - i++; - } - } + try { + OrgauthoritiesCommonList 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(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + + // Optionally output additional data about list members for debugging. + boolean iterateThroughList = false; + if (iterateThroughList && logger.isDebugEnabled()) { + List items = + list.getOrgauthorityListItem(); + int i = 0; + for (OrgauthoritiesCommonList.OrgauthorityListItem item : items) { + String csid = item.getCsid(); + logger.debug(testName + ": list-item[" + i + "] csid=" + + csid); + logger.debug(testName + ": list-item[" + i + "] displayName=" + + item.getDisplayName()); + logger.debug(testName + ": list-item[" + i + "] URI=" + + item.getUri()); + readItemList(csid, null); + i++; + } + } + } finally { + res.releaseConnection(); + } } /** @@ -1086,52 +1110,56 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { } else { Assert.fail("readItemList passed null csid and name!"); } - OrganizationsCommonList 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(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); - - List items = - list.getOrganizationListItem(); - int nItemsReturned = items.size(); - // There will be one item created, associated with a - // known parent resource, by the createItem test. - // - // In addition, there will be 'nItemsToCreateInList' - // additional items created by the createItemList test, - // all associated with the same parent resource. - int nExpectedItems = nItemsToCreateInList + 1; - if(logger.isDebugEnabled()){ - logger.debug(testName + ": Expected " - + nExpectedItems +" items; got: "+nItemsReturned); - } - Assert.assertEquals(nItemsReturned, nExpectedItems); - - int i = 0; - for (OrganizationsCommonList.OrganizationListItem item : items) { - Assert.assertTrue((null != item.getRefName()), "Item refName is null!"); - Assert.assertTrue((null != item.getDisplayName()), "Item displayName is null!"); - // Optionally output additional data about list members for debugging. - boolean showDetails = true; - if (showDetails && logger.isDebugEnabled()) { - logger.debug(" " + testName + ": list-item[" + i + "] csid=" + - item.getCsid()); - logger.debug(" " + testName + ": list-item[" + i + "] refName=" + - item.getRefName()); - logger.debug(" " + testName + ": list-item[" + i + "] displayName=" + - item.getDisplayName()); - logger.debug(" " + testName + ": list-item[" + i + "] URI=" + - item.getUri()); - } - i++; - } + try { + OrganizationsCommonList 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(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + + List items = + list.getOrganizationListItem(); + int nItemsReturned = items.size(); + // There will be one item created, associated with a + // known parent resource, by the createItem test. + // + // In addition, there will be 'nItemsToCreateInList' + // additional items created by the createItemList test, + // all associated with the same parent resource. + int nExpectedItems = nItemsToCreateInList + 1; + if(logger.isDebugEnabled()){ + logger.debug(testName + ": Expected " + + nExpectedItems +" items; got: "+nItemsReturned); + } + Assert.assertEquals(nItemsReturned, nExpectedItems); + + int i = 0; + for (OrganizationsCommonList.OrganizationListItem item : items) { + Assert.assertTrue((null != item.getRefName()), "Item refName is null!"); + Assert.assertTrue((null != item.getDisplayName()), "Item displayName is null!"); + // Optionally output additional data about list members for debugging. + boolean showDetails = true; + if (showDetails && logger.isDebugEnabled()) { + logger.debug(" " + testName + ": list-item[" + i + "] csid=" + + item.getCsid()); + logger.debug(" " + testName + ": list-item[" + i + "] refName=" + + item.getRefName()); + logger.debug(" " + testName + ": list-item[" + i + "] displayName=" + + item.getDisplayName()); + logger.debug(" " + testName + ": list-item[" + i + "] URI=" + + item.getUri()); + } + i++; + } + } finally { + res.releaseConnection(); + } } /** @@ -1162,48 +1190,52 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { ContactsCommonList list = null; ClientResponse res = client.readContactList(parentcsid, itemcsid); - 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(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); - - List listitems = - list.getContactListItem(); - int nItemsReturned = listitems.size(); - // There will be one item created, associated with a - // known parent resource, by the createItem test. - // - // In addition, there will be 'nItemsToCreateInList' - // additional items created by the createItemList test, - // all associated with the same parent resource. - int nExpectedItems = nItemsToCreateInList + 1; - if(logger.isDebugEnabled()){ - logger.debug(testName + ": Expected " - + nExpectedItems +" items; got: "+nItemsReturned); - } - Assert.assertEquals(nItemsReturned, nExpectedItems); - - int i = 0; - for (ContactsCommonList.ContactListItem listitem : listitems) { - // Optionally output additional data about list members for debugging. - boolean showDetails = false; - if (showDetails && logger.isDebugEnabled()) { - logger.debug(" " + testName + ": list-item[" + i + "] csid=" + - listitem.getCsid()); - logger.debug(" " + testName + ": list-item[" + i + "] addressPlace=" + - listitem.getAddressPlace()); - logger.debug(" " + testName + ": list-item[" + i + "] URI=" + - listitem.getUri()); - } - i++; - } + try { + 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(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + + List listitems = + list.getContactListItem(); + int nItemsReturned = listitems.size(); + // There will be one item created, associated with a + // known parent resource, by the createItem test. + // + // In addition, there will be 'nItemsToCreateInList' + // additional items created by the createItemList test, + // all associated with the same parent resource. + int nExpectedItems = nItemsToCreateInList + 1; + if(logger.isDebugEnabled()){ + logger.debug(testName + ": Expected " + + nExpectedItems +" items; got: "+nItemsReturned); + } + Assert.assertEquals(nItemsReturned, nExpectedItems); + + int i = 0; + for (ContactsCommonList.ContactListItem listitem : listitems) { + // Optionally output additional data about list members for debugging. + boolean showDetails = false; + if (showDetails && logger.isDebugEnabled()) { + logger.debug(" " + testName + ": list-item[" + i + "] csid=" + + listitem.getCsid()); + logger.debug(" " + testName + ": list-item[" + i + "] addressPlace=" + + listitem.getAddressPlace()); + logger.debug(" " + testName + ": list-item[" + i + "] URI=" + + listitem.getUri()); + } + i++; + } + } finally { + res.releaseConnection(); + } } // Failure outcomes @@ -1231,53 +1263,58 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { OrgAuthorityClient client = new OrgAuthorityClient(); ClientResponse res = client.read(knownResourceId); - if(logger.isDebugEnabled()){ - logger.debug(testName + ": read status = " + res.getStatus()); - } - Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE); - - if(logger.isDebugEnabled()){ - logger.debug("got OrgAuthority to update with ID: " + knownResourceId); - } - MultipartInput input = (MultipartInput) res.getEntity(); - OrgauthoritiesCommon orgAuthority = (OrgauthoritiesCommon) extractPart(input, - client.getCommonPartName(), OrgauthoritiesCommon.class); - Assert.assertNotNull(orgAuthority); - - // Update the contents of this resource. - orgAuthority.setDisplayName("updated-" + orgAuthority.getDisplayName()); - orgAuthority.setVocabType("updated-" + orgAuthority.getVocabType()); - if(logger.isDebugEnabled()){ - logger.debug("to be updated OrgAuthority"); - logger.debug(objectAsXmlString(orgAuthority, OrgauthoritiesCommon.class)); - } - - // Submit the updated resource to the service and store the response. - MultipartOutput output = new MultipartOutput(); - OutputPart commonPart = output.addPart(orgAuthority, MediaType.APPLICATION_XML_TYPE); - commonPart.getHeaders().add("label", client.getCommonPartName()); - res = client.update(knownResourceId, output); - 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(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); - - // Retrieve the updated resource and verify that its contents exist. - input = (MultipartInput) res.getEntity(); - OrgauthoritiesCommon updatedOrgAuthority = - (OrgauthoritiesCommon) extractPart(input, - client.getCommonPartName(), OrgauthoritiesCommon.class); - Assert.assertNotNull(updatedOrgAuthority); - - // Verify that the updated resource received the correct data. - Assert.assertEquals(updatedOrgAuthority.getDisplayName(), - orgAuthority.getDisplayName(), - "Data in updated object did not match submitted data."); + try { + if(logger.isDebugEnabled()){ + logger.debug(testName + ": read status = " + res.getStatus()); + } + Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE); + + if(logger.isDebugEnabled()){ + logger.debug("got OrgAuthority to update with ID: " + knownResourceId); + } + MultipartInput input = (MultipartInput) res.getEntity(); + OrgauthoritiesCommon orgAuthority = (OrgauthoritiesCommon) extractPart(input, + client.getCommonPartName(), OrgauthoritiesCommon.class); + Assert.assertNotNull(orgAuthority); + + // Update the contents of this resource. + orgAuthority.setDisplayName("updated-" + orgAuthority.getDisplayName()); + orgAuthority.setVocabType("updated-" + orgAuthority.getVocabType()); + if(logger.isDebugEnabled()){ + logger.debug("to be updated OrgAuthority"); + logger.debug(objectAsXmlString(orgAuthority, OrgauthoritiesCommon.class)); + } + + // Submit the updated resource to the service and store the response. + MultipartOutput output = new MultipartOutput(); + OutputPart commonPart = output.addPart(orgAuthority, MediaType.APPLICATION_XML_TYPE); + commonPart.getHeaders().add("label", client.getCommonPartName()); + res.releaseConnection(); + res = client.update(knownResourceId, output); + 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(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + + // Retrieve the updated resource and verify that its contents exist. + input = (MultipartInput) res.getEntity(); + OrgauthoritiesCommon updatedOrgAuthority = + (OrgauthoritiesCommon) extractPart(input, + client.getCommonPartName(), OrgauthoritiesCommon.class); + Assert.assertNotNull(updatedOrgAuthority); + + // Verify that the updated resource received the correct data. + Assert.assertEquals(updatedOrgAuthority.getDisplayName(), + orgAuthority.getDisplayName(), + "Data in updated object did not match submitted data."); + } finally { + res.releaseConnection(); + } } /** @@ -1300,56 +1337,61 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { OrgAuthorityClient client = new OrgAuthorityClient(); ClientResponse res = client.readItem(knownResourceId, knownItemResourceId); - if(logger.isDebugEnabled()){ - logger.debug(testName + ": read status = " + res.getStatus()); - } - Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE); - - if(logger.isDebugEnabled()){ - logger.debug("got Organization to update with ID: " + - knownItemResourceId + - " in OrgAuthority: " + knownResourceId ); - } - MultipartInput input = (MultipartInput) res.getEntity(); - OrganizationsCommon organization = (OrganizationsCommon) extractPart(input, - client.getItemCommonPartName(), OrganizationsCommon.class); - Assert.assertNotNull(organization); - - // Update the contents of this resource. - organization.setCsid(null); - organization.setShortName("updated-" + organization.getShortName()); - if(logger.isDebugEnabled()){ - logger.debug("to be updated Organization"); - logger.debug(objectAsXmlString(organization, - OrganizationsCommon.class)); - } - - // Submit the updated resource to the service and store the response. - MultipartOutput output = new MultipartOutput(); - OutputPart commonPart = output.addPart(organization, MediaType.APPLICATION_XML_TYPE); - commonPart.getHeaders().add("label", client.getItemCommonPartName()); - res = client.updateItem(knownResourceId, knownItemResourceId, output); - 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(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); - - // Retrieve the updated resource and verify that its contents exist. - input = (MultipartInput) res.getEntity(); - OrganizationsCommon updatedOrganization = - (OrganizationsCommon) extractPart(input, - client.getItemCommonPartName(), OrganizationsCommon.class); - Assert.assertNotNull(updatedOrganization); - - // Verify that the updated resource received the correct data. - Assert.assertEquals(updatedOrganization.getShortName(), - organization.getShortName(), - "Data in updated Organization did not match submitted data."); + try { + if(logger.isDebugEnabled()){ + logger.debug(testName + ": read status = " + res.getStatus()); + } + Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE); + + if(logger.isDebugEnabled()){ + logger.debug("got Organization to update with ID: " + + knownItemResourceId + + " in OrgAuthority: " + knownResourceId ); + } + MultipartInput input = (MultipartInput) res.getEntity(); + OrganizationsCommon organization = (OrganizationsCommon) extractPart(input, + client.getItemCommonPartName(), OrganizationsCommon.class); + Assert.assertNotNull(organization); + + // Update the contents of this resource. + organization.setCsid(null); + organization.setShortName("updated-" + organization.getShortName()); + if(logger.isDebugEnabled()){ + logger.debug("to be updated Organization"); + logger.debug(objectAsXmlString(organization, + OrganizationsCommon.class)); + } + + // Submit the updated resource to the service and store the response. + MultipartOutput output = new MultipartOutput(); + OutputPart commonPart = output.addPart(organization, MediaType.APPLICATION_XML_TYPE); + commonPart.getHeaders().add("label", client.getItemCommonPartName()); + res.releaseConnection(); + res = client.updateItem(knownResourceId, knownItemResourceId, output); + 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(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + + // Retrieve the updated resource and verify that its contents exist. + input = (MultipartInput) res.getEntity(); + OrganizationsCommon updatedOrganization = + (OrganizationsCommon) extractPart(input, + client.getItemCommonPartName(), OrganizationsCommon.class); + Assert.assertNotNull(updatedOrganization); + + // Verify that the updated resource received the correct data. + Assert.assertEquals(updatedOrganization.getShortName(), + organization.getShortName(), + "Data in updated Organization did not match submitted data."); + } finally { + res.releaseConnection(); + } } /** @@ -1372,56 +1414,61 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { OrgAuthorityClient client = new OrgAuthorityClient(); ClientResponse res = client.readContact(knownResourceId, knownItemResourceId, knownContactResourceId); - if(logger.isDebugEnabled()){ - logger.debug(testName + ": read status = " + res.getStatus()); - } - Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE); - - if(logger.isDebugEnabled()){ - logger.debug("got Contact to update with ID: " + - knownContactResourceId + - " in item: " + knownItemResourceId + - " in parent: " + knownResourceId ); - } - MultipartInput input = (MultipartInput) res.getEntity(); - ContactsCommon contact = (ContactsCommon) extractPart(input, - new ContactClient().getCommonPartName(), ContactsCommon.class); - Assert.assertNotNull(contact); - - // Update the contents of this resource. - contact.setAddressPlace("updated-" + contact.getAddressPlace()); - if(logger.isDebugEnabled()){ - logger.debug("to be updated Contact"); - logger.debug(objectAsXmlString(contact, - ContactsCommon.class)); - } - - // Submit the updated resource to the service and store the response. - MultipartOutput output = new MultipartOutput(); - OutputPart commonPart = output.addPart(contact, MediaType.APPLICATION_XML_TYPE); - commonPart.getHeaders().add("label", new ContactClient().getCommonPartName()); - res = client.updateContact(knownResourceId, knownItemResourceId, knownContactResourceId, output); - 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(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); - - // Retrieve the updated resource and verify that its contents exist. - input = (MultipartInput) res.getEntity(); - ContactsCommon updatedContact = - (ContactsCommon) extractPart(input, - new ContactClient().getCommonPartName(), ContactsCommon.class); - Assert.assertNotNull(updatedContact); - - // Verify that the updated resource received the correct data. - Assert.assertEquals(updatedContact.getAddressPlace(), - contact.getAddressPlace(), - "Data in updated Contact did not match submitted data."); + try { + if(logger.isDebugEnabled()){ + logger.debug(testName + ": read status = " + res.getStatus()); + } + Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE); + + if(logger.isDebugEnabled()){ + logger.debug("got Contact to update with ID: " + + knownContactResourceId + + " in item: " + knownItemResourceId + + " in parent: " + knownResourceId ); + } + MultipartInput input = (MultipartInput) res.getEntity(); + ContactsCommon contact = (ContactsCommon) extractPart(input, + new ContactClient().getCommonPartName(), ContactsCommon.class); + Assert.assertNotNull(contact); + + // Update the contents of this resource. + contact.setAddressPlace("updated-" + contact.getAddressPlace()); + if(logger.isDebugEnabled()){ + logger.debug("to be updated Contact"); + logger.debug(objectAsXmlString(contact, + ContactsCommon.class)); + } + + // Submit the updated resource to the service and store the response. + MultipartOutput output = new MultipartOutput(); + OutputPart commonPart = output.addPart(contact, MediaType.APPLICATION_XML_TYPE); + commonPart.getHeaders().add("label", new ContactClient().getCommonPartName()); + res.releaseConnection(); + res = client.updateContact(knownResourceId, knownItemResourceId, knownContactResourceId, output); + 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(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + + // Retrieve the updated resource and verify that its contents exist. + input = (MultipartInput) res.getEntity(); + ContactsCommon updatedContact = + (ContactsCommon) extractPart(input, + new ContactClient().getCommonPartName(), ContactsCommon.class); + Assert.assertNotNull(updatedContact); + + // Verify that the updated resource received the correct data. + Assert.assertEquals(updatedContact.getAddressPlace(), + contact.getAddressPlace(), + "Data in updated Contact did not match submitted data."); + } finally { + res.releaseConnection(); + } } // Failure outcomes @@ -1560,16 +1607,20 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { new OrgAuthorityClient().getCommonPartName()); ClientResponse res = client.update(NON_EXISTENT_ID, multipart); - 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(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + 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(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + } finally { + res.releaseConnection(); + } } /** @@ -1601,16 +1652,20 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { nonexOrgMap, client.getItemCommonPartName() ); ClientResponse res = client.updateItem(knownResourceId, NON_EXISTENT_ID, multipart); - 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(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + 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(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + } finally { + res.releaseConnection(); + } } /** @@ -1659,16 +1714,20 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { OrgAuthorityClient client = new OrgAuthorityClient(); ClientResponse res = client.deleteContact(knownResourceId, knownItemResourceId, knownContactResourceId); - 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(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + 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(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + } finally { + res.releaseConnection(); + } } /** @@ -1695,16 +1754,20 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { // Submit the request to the service and store the response. OrgAuthorityClient client = new OrgAuthorityClient(); ClientResponse res = client.deleteItem(knownResourceId, knownItemResourceId); - 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(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + 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(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + } finally { + res.releaseConnection(); + } } /* (non-Javadoc) @@ -1728,16 +1791,20 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { // Submit the request to the service and store the response. OrgAuthorityClient client = new OrgAuthorityClient(); ClientResponse res = client.delete(knownResourceId); - 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(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + 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(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + } finally { + res.releaseConnection(); + } } // Failure outcomes @@ -1758,16 +1825,20 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { // Submit the request to the service and store the response. OrgAuthorityClient client = new OrgAuthorityClient(); ClientResponse res = client.delete(NON_EXISTENT_ID); - 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(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + 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(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + } finally { + res.releaseConnection(); + } } /** @@ -1788,16 +1859,20 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { // Submit the request to the service and store the response. OrgAuthorityClient client = new OrgAuthorityClient(); ClientResponse res = client.deleteItem(knownResourceId, NON_EXISTENT_ID); - 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(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + 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(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + } finally { + res.releaseConnection(); + } } /** @@ -1819,16 +1894,20 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { OrgAuthorityClient client = new OrgAuthorityClient(); ClientResponse res = client.deleteContact(knownResourceId, knownItemResourceId, NON_EXISTENT_ID); - 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(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + 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(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + } finally { + res.releaseConnection(); + } } // --------------------------------------------------------------- diff --git a/services/organization/jaxb/src/main/java/org/collectionspace/services/OrganizationJAXBSchema.java b/services/organization/jaxb/src/main/java/org/collectionspace/services/OrganizationJAXBSchema.java index 08e6f88ec..8dd893c62 100644 --- a/services/organization/jaxb/src/main/java/org/collectionspace/services/OrganizationJAXBSchema.java +++ b/services/organization/jaxb/src/main/java/org/collectionspace/services/OrganizationJAXBSchema.java @@ -22,7 +22,6 @@ public interface OrganizationJAXBSchema extends AuthorityJAXBSchema { final static String FUNCTION = "function"; final static String SUB_BODY = "subBody"; final static String HISTORY = "history"; - final static String TERM_STATUS = "termStatus"; } diff --git a/services/organization/jaxb/src/main/resources/organization_common.xsd b/services/organization/jaxb/src/main/resources/organization_common.xsd index 1f6738c97..5288b135d 100644 --- a/services/organization/jaxb/src/main/resources/organization_common.xsd +++ b/services/organization/jaxb/src/main/resources/organization_common.xsd @@ -23,6 +23,7 @@ + @@ -36,7 +37,6 @@ - diff --git a/services/organization/service/src/main/java/org/collectionspace/services/organization/OrgAuthorityResource.java b/services/organization/service/src/main/java/org/collectionspace/services/organization/OrgAuthorityResource.java index 41c8ad9c3..8c418b21a 100644 --- a/services/organization/service/src/main/java/org/collectionspace/services/organization/OrgAuthorityResource.java +++ b/services/organization/service/src/main/java/org/collectionspace/services/organization/OrgAuthorityResource.java @@ -80,19 +80,13 @@ public class OrgAuthorityResource extends AuthorityResource { - /** The Constant orgAuthorityServiceName. */ private final static String orgAuthorityServiceName = "orgauthorities"; private final static String ORGAUTHORITIES_COMMON = "orgauthorities_common"; - /** The Constant organizationServiceName. */ private final static String organizationServiceName = "organizations"; private final static String ORGANIZATIONS_COMMON = "organizations_common"; - /** The logger. */ final Logger logger = LoggerFactory.getLogger(OrgAuthorityResource.class); - //FIXME retrieve client type from configuration - /** The Constant CLIENT_TYPE. */ - //final static ClientType CLIENT_TYPE = ServiceMain.getInstance().getClientType(); /** The contact resource. */ private ContactResource contactResource = new ContactResource(); diff --git a/services/person/3rdparty/nuxeo-platform-cs-person/src/main/resources/schemas/persons_common.xsd b/services/person/3rdparty/nuxeo-platform-cs-person/src/main/resources/schemas/persons_common.xsd index dfe77455b..6be3d6b63 100644 --- a/services/person/3rdparty/nuxeo-platform-cs-person/src/main/resources/schemas/persons_common.xsd +++ b/services/person/3rdparty/nuxeo-platform-cs-person/src/main/resources/schemas/persons_common.xsd @@ -25,6 +25,7 @@ + @@ -45,7 +46,6 @@ - diff --git a/services/person/client/src/test/java/org/collectionspace/services/client/test/PersonAuthorityServiceTest.java b/services/person/client/src/test/java/org/collectionspace/services/client/test/PersonAuthorityServiceTest.java index 47ded8b7c..ae1ac0636 100644 --- a/services/person/client/src/test/java/org/collectionspace/services/client/test/PersonAuthorityServiceTest.java +++ b/services/person/client/src/test/java/org/collectionspace/services/client/test/PersonAuthorityServiceTest.java @@ -1805,17 +1805,20 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { PersonAuthorityClient client = new PersonAuthorityClient(); ClientResponse res = client.deleteContact(knownResourceId, knownItemResourceId, knownContactResourceId); - int statusCode = res.getStatus(); - res.releaseConnection(); - - // Check the status code of the response: does it match - // the expected response(s)? - if(logger.isDebugEnabled()){ - logger.debug(testName + ": status = " + statusCode); - } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + 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(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + } finally { + res.releaseConnection(); + } } /** @@ -1842,17 +1845,20 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { // Submit the request to the service and store the response. PersonAuthorityClient client = new PersonAuthorityClient(); ClientResponse res = client.deleteItem(knownResourceId, knownItemResourceId); - int statusCode = res.getStatus(); - res.releaseConnection(); - - // Check the status code of the response: does it match - // the expected response(s)? - if(logger.isDebugEnabled()){ - logger.debug(testName + ": status = " + statusCode); - } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + 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(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + } finally { + res.releaseConnection(); + } } /* (non-Javadoc) @@ -1876,17 +1882,20 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { // Submit the request to the service and store the response. PersonAuthorityClient client = new PersonAuthorityClient(); ClientResponse res = client.delete(knownResourceId); - int statusCode = res.getStatus(); - res.releaseConnection(); - - // Check the status code of the response: does it match - // the expected response(s)? - if(logger.isDebugEnabled()){ - logger.debug(testName + ": status = " + statusCode); - } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + 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(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + } finally { + res.releaseConnection(); + } } // Failure outcomes @@ -1907,17 +1916,20 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { // Submit the request to the service and store the response. PersonAuthorityClient client = new PersonAuthorityClient(); ClientResponse res = client.delete(NON_EXISTENT_ID); - int statusCode = res.getStatus(); - res.releaseConnection(); - - // Check the status code of the response: does it match - // the expected response(s)? - if(logger.isDebugEnabled()){ - logger.debug(testName + ": status = " + statusCode); - } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + 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(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + } finally { + res.releaseConnection(); + } } /** @@ -1938,17 +1950,20 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { // Submit the request to the service and store the response. PersonAuthorityClient client = new PersonAuthorityClient(); ClientResponse res = client.deleteItem(knownResourceId, NON_EXISTENT_ID); - int statusCode = res.getStatus(); - res.releaseConnection(); - - // Check the status code of the response: does it match - // the expected response(s)? - if(logger.isDebugEnabled()){ - logger.debug(testName + ": status = " + statusCode); - } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + 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(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + } finally { + res.releaseConnection(); + } } /** @@ -1970,17 +1985,20 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { PersonAuthorityClient client = new PersonAuthorityClient(); ClientResponse res = client.deleteContact(knownResourceId, knownItemResourceId, NON_EXISTENT_ID); - int statusCode = res.getStatus(); - res.releaseConnection(); - - // Check the status code of the response: does it match - // the expected response(s)? - if(logger.isDebugEnabled()){ - logger.debug(testName + ": status = " + statusCode); - } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + 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(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + } finally { + res.releaseConnection(); + } } // --------------------------------------------------------------- diff --git a/services/person/jaxb/src/main/java/org/collectionspace/services/PersonJAXBSchema.java b/services/person/jaxb/src/main/java/org/collectionspace/services/PersonJAXBSchema.java index 353ea4d2b..7653c917e 100644 --- a/services/person/jaxb/src/main/java/org/collectionspace/services/PersonJAXBSchema.java +++ b/services/person/jaxb/src/main/java/org/collectionspace/services/PersonJAXBSchema.java @@ -29,6 +29,5 @@ public interface PersonJAXBSchema extends AuthorityJAXBSchema { final static String SCHOOL_OR_STYLE = "schoolOrStyle"; final static String BIO_NOTE = "bioNote"; final static String NAME_NOTE = "nameNote"; - final static String TERM_STATUS = "termStatus"; } diff --git a/services/person/jaxb/src/main/resources/person_common.xsd b/services/person/jaxb/src/main/resources/person_common.xsd index a41450d88..b095c30fc 100644 --- a/services/person/jaxb/src/main/resources/person_common.xsd +++ b/services/person/jaxb/src/main/resources/person_common.xsd @@ -35,6 +35,7 @@ + @@ -55,7 +56,6 @@ - diff --git a/services/vocabulary/3rdparty/nuxeo-platform-cs-vocabulary/src/main/resources/schemas/vocabularyitems_common.xsd b/services/vocabulary/3rdparty/nuxeo-platform-cs-vocabulary/src/main/resources/schemas/vocabularyitems_common.xsd index 0f920f111..7202c731e 100644 --- a/services/vocabulary/3rdparty/nuxeo-platform-cs-vocabulary/src/main/resources/schemas/vocabularyitems_common.xsd +++ b/services/vocabulary/3rdparty/nuxeo-platform-cs-vocabulary/src/main/resources/schemas/vocabularyitems_common.xsd @@ -25,8 +25,8 @@ + - diff --git a/services/vocabulary/jaxb/src/main/resources/vocabularyitem_common.xsd b/services/vocabulary/jaxb/src/main/resources/vocabularyitem_common.xsd index 77211d048..4e7af77c0 100644 --- a/services/vocabulary/jaxb/src/main/resources/vocabularyitem_common.xsd +++ b/services/vocabulary/jaxb/src/main/resources/vocabularyitem_common.xsd @@ -25,7 +25,7 @@ - + -- 2.47.3