From 986d3b2443054dad88e395d1e1193131955852a5 Mon Sep 17 00:00:00 2001 From: Aron Roberts Date: Tue, 22 Jun 2010 04:05:55 +0000 Subject: [PATCH] CSPACE-2183: The sub-body field is now an authority reference field in Organization item records. --- .../main/config/services/tenant-bindings.xml | 2 + .../client/OrgAuthorityClientUtils.java | 29 +++-- .../client/test/OrgAuthorityAuthRefsTest.java | 113 +++++++++++++----- 3 files changed, 101 insertions(+), 43 deletions(-) diff --git a/services/common/src/main/config/services/tenant-bindings.xml b/services/common/src/main/config/services/tenant-bindings.xml index 57aa34d80..e36d28c28 100644 --- a/services/common/src/main/config/services/tenant-bindings.xml +++ b/services/common/src/main/config/services/tenant-bindings.xml @@ -439,6 +439,7 @@ label="organizations_common" updated="" order="1"> authRefcontactName + authRefsubBody @@ -1482,6 +1483,7 @@ label="organizations_common" updated="" order="1"> authRefcontactName + authRefsubBody diff --git a/services/organization/client/src/main/java/org/collectionspace/services/client/OrgAuthorityClientUtils.java b/services/organization/client/src/main/java/org/collectionspace/services/client/OrgAuthorityClientUtils.java index c08152880..68036c182 100644 --- a/services/organization/client/src/main/java/org/collectionspace/services/client/OrgAuthorityClientUtils.java +++ b/services/organization/client/src/main/java/org/collectionspace/services/client/OrgAuthorityClientUtils.java @@ -94,18 +94,7 @@ public class OrgAuthorityClientUtils { int EXPECTED_STATUS_CODE = Response.Status.CREATED.getStatusCode(); // Type of service request being tested ServiceRequestType REQUEST_TYPE = ServiceRequestType.CREATE; - String displayName = orgInfo.get(OrganizationJAXBSchema.DISPLAY_NAME); - String displayNameComputedStr = orgInfo.get(OrganizationJAXBSchema.DISPLAY_NAME_COMPUTED); - boolean displayNameComputed = (displayNameComputedStr==null) || displayNameComputedStr.equalsIgnoreCase("true"); - if( displayName == null ) { - if(!displayNameComputed) { - throw new RuntimeException( - "CreateItem: Must supply a displayName if displayNameComputed is set to false."); - } - displayName = prepareDefaultDisplayName( - orgInfo.get(OrganizationJAXBSchema.SHORT_NAME ), - orgInfo.get(OrganizationJAXBSchema.FOUNDING_PLACE )); - } + String displayName = createDisplayName(orgInfo); String refName = createOrganizationRefName(orgAuthorityRefName, displayName, true); if(logger.isDebugEnabled()){ @@ -289,5 +278,21 @@ public class OrgAuthorityClientUtils { } return newStr.toString(); } + + public static String createDisplayName(Map orgInfo) { + String displayName = orgInfo.get(OrganizationJAXBSchema.DISPLAY_NAME); + String displayNameComputedStr = orgInfo.get(OrganizationJAXBSchema.DISPLAY_NAME_COMPUTED); + boolean displayNameComputed = (displayNameComputedStr==null) || displayNameComputedStr.equalsIgnoreCase("true"); + if( displayName == null ) { + if(!displayNameComputed) { + throw new RuntimeException( + "CreateItem: Must supply a displayName if displayNameComputed is set to false."); + } + displayName = prepareDefaultDisplayName( + orgInfo.get(OrganizationJAXBSchema.SHORT_NAME ), + orgInfo.get(OrganizationJAXBSchema.FOUNDING_PLACE )); + } + return displayName; + } } diff --git a/services/organization/client/src/test/java/org/collectionspace/services/client/test/OrgAuthorityAuthRefsTest.java b/services/organization/client/src/test/java/org/collectionspace/services/client/test/OrgAuthorityAuthRefsTest.java index af7e80070..7ab612d5d 100644 --- a/services/organization/client/src/test/java/org/collectionspace/services/client/test/OrgAuthorityAuthRefsTest.java +++ b/services/organization/client/src/test/java/org/collectionspace/services/client/test/OrgAuthorityAuthRefsTest.java @@ -68,8 +68,9 @@ public class OrgAuthorityAuthRefsTest extends BaseServiceTest { /** The SERVIC e_ pat h_ component. */ final String SERVICE_PATH_COMPONENT = "orgauthorities"; - /** The PERSO n_ authorit y_ name. */ + // Temporary Person and Organization Authority names, used for test purposes. final String PERSON_AUTHORITY_NAME = "TestPersonAuth"; + final String ORG_AUTHORITY_NAME = "TestOrgAuth"; /** The known resource ref name. */ private String knownResourceRefName = null; @@ -90,14 +91,19 @@ public class OrgAuthorityAuthRefsTest extends BaseServiceTest { /** The person ids created. */ private List personIdsCreated = new ArrayList(); - /** The person auth csid. */ + // CSID for the instance of the test Person authority + // created during testing. private String personAuthCSID = null; /** The organization contact person ref name. */ private String organizationContactPersonRefName = null; + + // The refName of an Organization item that represents + // the sub-body organization of a second Organization item. + private String subBodyRefName = null; /** The number of authorityreferences expected. */ - private final int NUM_AUTH_REFS_EXPECTED = 1; + private final int NUM_AUTH_REFS_EXPECTED = 2; /* (non-Javadoc) * @see org.collectionspace.services.client.test.BaseServiceTest#getClientInstance() @@ -148,31 +154,34 @@ public class OrgAuthorityAuthRefsTest extends BaseServiceTest { // Submit the request to the service and store the response. ClientResponse res = orgAuthClient.create(multipart); try { - int statusCode = res.getStatus(); - // Check the status code of the response: does it match - // the expected response(s)? - // - // Specifically: - // Does it fall within the set of valid status codes? - // Does it exactly match the expected status code? - if(logger.isDebugEnabled()){ - logger.debug(testName + ": status = " + statusCode); - } - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); - - // Store the IDs from every resource created by tests, - // so they can be deleted after tests have been run. - knownAuthResourceId = extractId(res); + 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(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + + // Store the IDs from every resource created by tests, + // so they can be deleted after tests have been run. + knownAuthResourceId = extractId(res); } finally { - res.releaseConnection(); + res.releaseConnection(); } allResourceIdsCreated.add(knownAuthResourceId); // Create all the person refs and entities createPersonRefs(); + // Create all the organization sub-body refs and entities + createSubBodyOrgRefs(); + // Initialize values for a new Organization item, to be created within // the newly-created Organization Authority resource. // @@ -185,6 +194,7 @@ public class OrgAuthorityAuthRefsTest extends BaseServiceTest { testOrgMap.put(OrganizationJAXBSchema.LONG_NAME, "Test Organization Name"); testOrgMap.put(OrganizationJAXBSchema.FOUNDING_PLACE, "Anytown, USA"); testOrgMap.put(OrganizationJAXBSchema.CONTACT_NAME, organizationContactPersonRefName); + testOrgMap.put(OrganizationJAXBSchema.SUB_BODY, subBodyRefName); // Finishing creating the new Organization item, then // submit the request to the service and store the response. @@ -203,26 +213,26 @@ public class OrgAuthorityAuthRefsTest extends BaseServiceTest { PersonAuthorityClient personAuthClient = new PersonAuthorityClient(); // Create a temporary PersonAuthority resource, and its corresponding // refName by which it can be identified. - String authRefName = + String personAuthRefName = PersonAuthorityClientUtils.createPersonAuthRefName(PERSON_AUTHORITY_NAME, false); MultipartOutput multipart = PersonAuthorityClientUtils.createPersonAuthorityInstance( - PERSON_AUTHORITY_NAME, authRefName, personAuthClient.getCommonPartName()); + PERSON_AUTHORITY_NAME, personAuthRefName, personAuthClient.getCommonPartName()); ClientResponse res = personAuthClient.create(multipart); try { - int statusCode = res.getStatus(); - Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), - invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); - Assert.assertEquals(statusCode, STATUS_CREATED); - personAuthCSID = extractId(res); + int statusCode = res.getStatus(); + Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, STATUS_CREATED); + personAuthCSID = extractId(res); } finally { - res.releaseConnection(); + res.releaseConnection(); } // Create a temporary Person resource, and its corresponding refName // by which it can be identified. organizationContactPersonRefName = - PersonAuthorityClientUtils.createPersonRefName(authRefName, "Charlie Orgcontact", true); + PersonAuthorityClientUtils.createPersonRefName(personAuthRefName, "Charlie Orgcontact", true); personIdsCreated.add(createPerson("Charlie", "Orgcontact", organizationContactPersonRefName)); } @@ -260,6 +270,46 @@ public class OrgAuthorityAuthRefsTest extends BaseServiceTest { return result; } + private void createSubBodyOrgRefs() { + // Create a temporary sub-body Organization resource, and its corresponding refName + // by which it can be identified. + // + // This sub-body Organization resource will be created in the same + // Organization authority as its parent Organization resource. + + String subBodyResourceId = createSubBodyOrganization("Test SubBody Organization", subBodyRefName); + allItemResourceIdsCreated.put(subBodyResourceId, knownAuthResourceId); + } + + protected String createSubBodyOrganization(String subBodyName, String refName) { + OrgAuthorityClient orgAuthClient = new OrgAuthorityClient(); + Map subBodyOrgMap = new HashMap(); + subBodyOrgMap.put(OrganizationJAXBSchema.SHORT_NAME, + subBodyName + "-" + createIdentifier()); + subBodyOrgMap.put(OrganizationJAXBSchema.LONG_NAME, subBodyName + " Long Name"); + subBodyOrgMap.put(OrganizationJAXBSchema.FOUNDING_PLACE, subBodyName + " Founding Place"); + String subBodyDisplayName = OrgAuthorityClientUtils.createDisplayName(subBodyOrgMap); + subBodyRefName = + OrgAuthorityClientUtils.createOrganizationRefName(knownResourceRefName, subBodyDisplayName, true); + MultipartOutput multipart = + OrgAuthorityClientUtils.createOrganizationInstance(knownAuthResourceId, + subBodyRefName, subBodyOrgMap, orgAuthClient.getItemCommonPartName()); + + String result = null; + ClientResponse res = orgAuthClient.createItem(knownAuthResourceId, multipart); + try { + int statusCode = res.getStatus(); + Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, STATUS_CREATED); + result = extractId(res); + } finally { + res.releaseConnection(); + } + + return result; + } + // Success outcomes /** * Read and check auth refs. @@ -301,7 +351,8 @@ public class OrgAuthorityAuthRefsTest extends BaseServiceTest { } // Check one or more of the authority fields in the Organization item Assert.assertEquals(organization.getContactName(), organizationContactPersonRefName); - + Assert.assertEquals(organization.getSubBody(), subBodyRefName); + // Get the auth refs and check them // FIXME - need to create this method in the client // and get the ID for the organization item -- 2.47.3