From 188aa20f76d3e59b7711d1f4a3d5dc9e33ee248c Mon Sep 17 00:00:00 2001 From: Aron Roberts Date: Mon, 8 Nov 2010 21:38:20 +0000 Subject: [PATCH] CSPACE-2932: Implement the Main Body group of three fields as a repeatable group in Organization item records, in the services layer. Complications include a short display name computed from one of those three fields, shortName; a missing shortName field in the UI layer reflecting possible confusion with the shortIdentifier field; and a change in the summary field for app layer mini-records to the displayName field, from the longName field. Although all services and app layer tests pass, and behavior in the UI appears appropriate, we should remain vigilant for any unexpected side effects that may crop up from this change. --- .../schemas/organizations_common.xsd | 43 +++++++++------ .../schemas/orgauthorities_common.xsd | 4 +- .../services/client/OrgAuthorityClient.java | 4 +- .../client/OrgAuthorityClientUtils.java | 24 ++++----- .../services/client/OrgAuthorityProxy.java | 2 +- .../client/test/OrgAuthorityAuthRefsTest.java | 18 ++++--- .../client/test/OrgAuthorityServiceTest.java | 52 +++++++++++++++---- .../services/OrganizationJAXBSchema.java | 3 +- .../main/resources/organization_common.xsd | 52 ++++++++++++------- .../main/resources/orgauthority_common.xsd | 4 +- .../OrgAuthorityDocumentModelHandler.java | 4 +- .../OrganizationDocumentModelHandler.java | 47 +++++++++++++++-- 12 files changed, 177 insertions(+), 80 deletions(-) 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 1fe19f124..05d3d2f03 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 @@ -2,23 +2,23 @@ - + xmlns:xs="http://www.w3.org/2001/XMLSchema" + xmlns:ns="http://collectionspace.org/services/organization" + xmlns="http://collectionspace.org/services/organization" + targetNamespace="http://collectionspace.org/services/organization" + version="0.1" + > + @@ -31,12 +31,7 @@ - - - - - - + @@ -77,5 +72,19 @@ + + + + + + + + + + + + + + diff --git a/services/organization/3rdparty/nuxeo-platform-cs-organization/src/main/resources/schemas/orgauthorities_common.xsd b/services/organization/3rdparty/nuxeo-platform-cs-organization/src/main/resources/schemas/orgauthorities_common.xsd index 02b47f2a4..d8e3cbda9 100644 --- a/services/organization/3rdparty/nuxeo-platform-cs-organization/src/main/resources/schemas/orgauthorities_common.xsd +++ b/services/organization/3rdparty/nuxeo-platform-cs-organization/src/main/resources/schemas/orgauthorities_common.xsd @@ -7,8 +7,8 @@ Part : Common Used for: Nuxeo EP core document type - $LastChangedRevision: 928 $ - $LastChangedDate: 2009-11-10 12:25:58 -0800 (Tue, 10 Nov 2009) $ + $LastChangedRevision$ + $LastChangedDate$ --> orgInfo, - Map> orgRepeatablesInfo, OrgAuthorityClient client) { + Map> orgRepeatablesInfo, MainBodyGroupList mainBodyList, OrgAuthorityClient client) { // Expected status code: 201 Created int EXPECTED_STATUS_CODE = Response.Status.CREATED.getStatusCode(); // Type of service request being tested @@ -183,7 +184,7 @@ public class OrgAuthorityClientUtils { } MultipartOutput multipart = createOrganizationInstance(orgAuthorityRefName, - orgInfo, orgRepeatablesInfo, client.getItemCommonPartName()); + orgInfo, orgRepeatablesInfo, mainBodyList, client.getItemCommonPartName()); ClientResponse res = client.createItem(inAuthority, multipart); String result; @@ -220,8 +221,9 @@ public class OrgAuthorityClientUtils { String orgAuthRefName, Map orgInfo, String headerLabel){ final Map> EMPTY_ORG_REPEATABLES_INFO = new HashMap>(); + final MainBodyGroupList EMPTY_MAIN_BODY_LIST = new MainBodyGroupList(); return createOrganizationInstance(orgAuthRefName, - orgInfo, EMPTY_ORG_REPEATABLES_INFO, headerLabel); + orgInfo, EMPTY_ORG_REPEATABLES_INFO, EMPTY_MAIN_BODY_LIST, headerLabel); } @@ -237,7 +239,7 @@ public class OrgAuthorityClientUtils { */ public static MultipartOutput createOrganizationInstance( String orgAuthRefName, Map orgInfo, - Map> orgRepeatablesInfo, String headerLabel){ + Map> orgRepeatablesInfo, MainBodyGroupList mainBodyList, String headerLabel){ OrganizationsCommon organization = new OrganizationsCommon(); String shortId = orgInfo.get(OrganizationJAXBSchema.SHORT_IDENTIFIER); if (shortId == null || shortId.isEmpty()) { @@ -261,12 +263,10 @@ public class OrgAuthorityClientUtils { String refName = createOrganizationRefName(orgAuthRefName, shortId, value); organization.setRefName(refName); - if((value = (String)orgInfo.get(OrganizationJAXBSchema.SHORT_NAME))!=null) - organization.setShortName(value); - if((value = (String)orgInfo.get(OrganizationJAXBSchema.LONG_NAME))!=null) - organization.setLongName(value); - if((value = (String)orgInfo.get(OrganizationJAXBSchema.NAME_ADDITIONS))!=null) - organization.setNameAdditions(value); + if (mainBodyList != null) { + organization.setMainBodyGroupList(mainBodyList); + } + if((values = (List)orgRepeatablesInfo.get(OrganizationJAXBSchema.CONTACT_NAMES))!=null) { ContactNameList contactsList = new ContactNameList(); List contactNames = contactsList.getContactName(); diff --git a/services/organization/client/src/main/java/org/collectionspace/services/client/OrgAuthorityProxy.java b/services/organization/client/src/main/java/org/collectionspace/services/client/OrgAuthorityProxy.java index 3b2f939b2..d7d30b095 100644 --- a/services/organization/client/src/main/java/org/collectionspace/services/client/OrgAuthorityProxy.java +++ b/services/organization/client/src/main/java/org/collectionspace/services/client/OrgAuthorityProxy.java @@ -23,7 +23,7 @@ import org.jboss.resteasy.plugins.providers.multipart.MultipartInput; import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput; /** - * @version $Revision:$ + * @version $Revision$ */ @Path("/orgauthorities/") @Produces({"multipart/mixed"}) 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 435ca0b59..9aae6506f 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 @@ -38,6 +38,8 @@ import org.collectionspace.services.client.PersonAuthorityClient; import org.collectionspace.services.client.PersonAuthorityClientUtils; import org.collectionspace.services.common.authorityref.AuthorityRefList; import org.collectionspace.services.jaxb.AbstractCommonList; +import org.collectionspace.services.organization.MainBodyGroup; +import org.collectionspace.services.organization.MainBodyGroupList; import org.collectionspace.services.organization.OrganizationsCommon; import org.jboss.resteasy.client.ClientResponse; @@ -55,8 +57,8 @@ import org.slf4j.LoggerFactory; * LoaninAuthRefsTest, carries out Authority References tests against a * deployed and running Loanin (aka Loans In) Service. * - * $LastChangedRevision: 1327 $ - * $LastChangedDate: 2010-02-12 10:35:11 -0800 (Fri, 12 Feb 2010) $ + * $LastChangedRevision$ + * $LastChangedDate$ */ public class OrgAuthorityAuthRefsTest extends BaseServiceTest { @@ -192,9 +194,6 @@ public class OrgAuthorityAuthRefsTest extends BaseServiceTest { // per the initialization(s) below. Map testOrgMap = new HashMap(); testOrgMap.put(OrganizationJAXBSchema.SHORT_IDENTIFIER, shortId); - testOrgMap.put(OrganizationJAXBSchema.SHORT_NAME, - "Test Organization-" + shortId); - testOrgMap.put(OrganizationJAXBSchema.LONG_NAME, "Test Organization Name"); testOrgMap.put(OrganizationJAXBSchema.FOUNDING_PLACE, "Anytown, USA"); Map> testOrgRepeatablesMap = new HashMap>(); @@ -206,11 +205,18 @@ public class OrgAuthorityAuthRefsTest extends BaseServiceTest { testOrgSubBodies.add(subBodyRefName); testOrgRepeatablesMap.put(OrganizationJAXBSchema.SUB_BODIES, testOrgSubBodies); + MainBodyGroupList mainBodyList = new MainBodyGroupList(); + List mainBodyGroups = mainBodyList.getMainBodyGroup(); + MainBodyGroup mainBodyGroup = new MainBodyGroup(); + mainBodyGroup.setShortName("Test Organization-" + shortId); + mainBodyGroup.setLongName("Test Organization Name"); + mainBodyGroups.add(mainBodyGroup); + // Finishing creating the new Organization item, then // submit the request to the service and store the response. knownItemResourceId = OrgAuthorityClientUtils.createItemInAuthority( knownResourceId, knownResourceRefName, testOrgMap, - testOrgRepeatablesMap, orgAuthClient); + testOrgRepeatablesMap, mainBodyList, orgAuthClient); // Store the IDs from every item created by tests, // so they can be deleted after tests have been run. 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 0aa1b2ad7..b4eabd96c 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 @@ -38,6 +38,8 @@ import org.collectionspace.services.contact.ContactsCommonList; import org.collectionspace.services.client.OrgAuthorityClient; import org.collectionspace.services.client.OrgAuthorityClientUtils; import org.collectionspace.services.jaxb.AbstractCommonList; +import org.collectionspace.services.organization.MainBodyGroup; +import org.collectionspace.services.organization.MainBodyGroupList; import org.collectionspace.services.organization.OrgauthoritiesCommon; import org.collectionspace.services.organization.OrgauthoritiesCommonList; import org.collectionspace.services.organization.OrganizationsCommon; @@ -57,8 +59,8 @@ import org.testng.annotations.Test; * OrgAuthorityServiceTest, carries out tests against a * deployed and running OrgAuthority Service. * - * $LastChangedRevision: 753 $ - * $LastChangedDate: 2009-09-23 11:03:36 -0700 (Wed, 23 Sep 2009) $ + * $LastChangedRevision$ + * $LastChangedDate$ */ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { @@ -238,9 +240,16 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { testOrgContactNames.add("joe@example.org"); testOrgContactNames.add("sally@example.org"); testOrgRepeatablesMap.put(OrganizationJAXBSchema.CONTACT_NAMES, testOrgContactNames); + + MainBodyGroupList mainBodyList = new MainBodyGroupList(); + List mainBodyGroups = mainBodyList.getMainBodyGroup(); + MainBodyGroup mainBodyGroup = new MainBodyGroup(); + mainBodyGroup.setShortName(TEST_ORG_SHORTNAME); + mainBodyGroup.setLongName("The real official test organization"); + mainBodyGroups.add(mainBodyGroup); String newID = OrgAuthorityClientUtils.createItemInAuthority( - vcsid, authRefName, testOrgMap, testOrgRepeatablesMap, client); + vcsid, authRefName, testOrgMap, testOrgRepeatablesMap, mainBodyList, client); // Store the ID returned from the first item resource created // for additional tests below. @@ -732,10 +741,18 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { // Update the shortName and verify the computed name is updated. organization.setCsid(null); organization.setDisplayNameComputed(true); - organization.setShortName("updated-" + TEST_ORG_SHORTNAME); + + MainBodyGroupList mainBodyList = organization.getMainBodyGroupList(); + List mainBodyGroups = mainBodyList.getMainBodyGroup(); + MainBodyGroup mainBodyGroup = new MainBodyGroup(); + String updatedShortName = "updated-" + TEST_ORG_SHORTNAME; + mainBodyGroup.setShortName(updatedShortName); + mainBodyGroups.add(mainBodyGroup); + organization.setMainBodyGroupList(mainBodyList); + expectedDisplayName = OrgAuthorityClientUtils.prepareDefaultDisplayName( - "updated-" + TEST_ORG_SHORTNAME, TEST_ORG_FOUNDING_PLACE); + updatedShortName, TEST_ORG_FOUNDING_PLACE); // Submit the updated resource to the service and store the response. MultipartOutput output = new MultipartOutput(); @@ -765,8 +782,12 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { Assert.assertNotNull(updatedOrganization); // Verify that the updated resource received the correct data. - Assert.assertEquals(updatedOrganization.getShortName(), organization.getShortName(), - "Updated ShortName in Organization did not match submitted data."); + mainBodyList = organization.getMainBodyGroupList(); + Assert.assertNotNull(mainBodyList); + Assert.assertTrue(mainBodyList.getMainBodyGroup().size() > 0); + Assert.assertEquals(updatedOrganization.getMainBodyGroupList().getMainBodyGroup().get(0).getShortName(), + updatedShortName, "Updated ShortName in Organization did not match submitted data."); + // Verify that the updated resource computes the right displayName. Assert.assertEquals(updatedOrganization.getDisplayName(), expectedDisplayName, "Updated ShortName in Organization not reflected in computed DisplayName."); @@ -1371,7 +1392,14 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { // Update the contents of this resource. organization.setCsid(null); - organization.setShortName("updated-" + organization.getShortName()); + + MainBodyGroupList mainBodyList = organization.getMainBodyGroupList(); + Assert.assertNotNull(mainBodyList); + List mainBodyGroups = mainBodyList.getMainBodyGroup(); + Assert.assertTrue(mainBodyList.getMainBodyGroup().size() > 0); + String updatedShortName = "updated-" + mainBodyGroups.get(0).getShortName(); + mainBodyGroups.get(0).setShortName(updatedShortName); + if(logger.isDebugEnabled()){ logger.debug("to be updated Organization"); logger.debug(objectAsXmlString(organization, @@ -1402,9 +1430,11 @@ public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { 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."); + mainBodyList = organization.getMainBodyGroupList(); + Assert.assertNotNull(mainBodyList); + Assert.assertTrue(mainBodyList.getMainBodyGroup().size() > 0); + Assert.assertEquals(updatedOrganization.getMainBodyGroupList().getMainBodyGroup().get(0).getShortName(), + updatedShortName, "Data in updated Organization did not match submitted data."); } 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 2191ee012..28e48a7c7 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 @@ -12,8 +12,9 @@ import org.collectionspace.services.common.vocabulary.AuthorityItemJAXBSchema; public interface OrganizationJAXBSchema extends AuthorityItemJAXBSchema { final static String ORGANIZATIONS_COMMON = "organizations_common"; - final static String SHORT_NAME = "shortName"; + final static String MAIN_BODY_GROUP_LIST = "mainBodyGroupList"; final static String LONG_NAME = "longName"; + final static String SHORT_NAME = "shortName"; final static String NAME_ADDITIONS = "nameAdditions"; final static String CONTACT_NAMES = "contactNames"; final static String FOUNDING_DATE = "foundingDate"; diff --git a/services/organization/jaxb/src/main/resources/organization_common.xsd b/services/organization/jaxb/src/main/resources/organization_common.xsd index 20cda416a..ccc8c865c 100644 --- a/services/organization/jaxb/src/main/resources/organization_common.xsd +++ b/services/organization/jaxb/src/main/resources/organization_common.xsd @@ -7,30 +7,28 @@ xmlns="http://collectionspace.org/services/organization" targetNamespace="http://collectionspace.org/services/organization" version="0.1"> - + - + - + - + - + - - - + @@ -43,6 +41,20 @@ + + + + + + + + + + + + + + @@ -55,7 +67,7 @@ - + @@ -72,7 +84,7 @@ - + @@ -81,35 +93,35 @@ - + - + - + minOccurs="1" /> + + minOccurs="1" /> + minOccurs="1" /> + minOccurs="1" /> - + - + diff --git a/services/organization/jaxb/src/main/resources/orgauthority_common.xsd b/services/organization/jaxb/src/main/resources/orgauthority_common.xsd index 7077ed9cf..d727e8f60 100644 --- a/services/organization/jaxb/src/main/resources/orgauthority_common.xsd +++ b/services/organization/jaxb/src/main/resources/orgauthority_common.xsd @@ -7,8 +7,8 @@ Part : Common Used for: JAXB binding between XML and Java objects - $LastChangedRevision: 1055 $ - $LastChangedDate: 2009-12-09 12:25:15 -0800 (Wed, 09 Dec 2009) $ + $LastChangedRevision$ + $LastChangedDate$ --> { diff --git a/services/organization/service/src/main/java/org/collectionspace/services/organization/nuxeo/OrganizationDocumentModelHandler.java b/services/organization/service/src/main/java/org/collectionspace/services/organization/nuxeo/OrganizationDocumentModelHandler.java index 1989df666..10d70b1bb 100644 --- a/services/organization/service/src/main/java/org/collectionspace/services/organization/nuxeo/OrganizationDocumentModelHandler.java +++ b/services/organization/service/src/main/java/org/collectionspace/services/organization/nuxeo/OrganizationDocumentModelHandler.java @@ -44,8 +44,8 @@ import org.slf4j.LoggerFactory; /** * OrganizationDocumentModelHandler * - * $LastChangedRevision: $ - * $LastChangedDate: $ + * $LastChangedRevision$ + * $LastChangedDate$ */ public class OrganizationDocumentModelHandler extends AuthorityItemDocumentModelHandler { @@ -98,8 +98,11 @@ public class OrganizationDocumentModelHandler if(shortDisplayNameComputed==null) shortDisplayNameComputed = true; if (displayNameComputed || shortDisplayNameComputed) { - String shortName = (String) docModel.getProperty(commonPartLabel, - OrganizationJAXBSchema.SHORT_NAME); + List mainBodyGroupList = (List) docModel.getProperty(commonPartLabel, + OrganizationJAXBSchema.MAIN_BODY_GROUP_LIST); + // FIXME: Determine how to handle cases where primary short name is null or empty. + String shortName = primaryValueFromMultivalue(mainBodyGroupList, + OrganizationJAXBSchema.SHORT_NAME); if(shortDisplayNameComputed) { String displayName = prepareDefaultDisplayName(shortName, null); docModel.setProperty(commonPartLabel, OrganizationJAXBSchema.SHORT_DISPLAY_NAME, @@ -183,5 +186,41 @@ public class OrganizationDocumentModelHandler public String getQProperty(String prop) { return OrganizationConstants.NUXEO_SCHEMA_NAME + ":" + prop; } + + /** + * Returns the primary value from a list of values. + * + * Assumes that the first value is the primary value. + * This assumption may change when and if the primary value + * is identified explicitly. + * + * @param values a list of values. + * @param propertyName the name of a property through + * which the value can be extracted. + * @return the primary value. + */ + private String primaryValueFromMultivalue(List values, String propertyName) { + String primaryValue = ""; + if (values == null || values.size() == 0) { + return primaryValue; + } + Object value = values.get(0); + if (value instanceof String) { + if (value != null) { + primaryValue = (String) value; + } + // Multivalue group of fields + } else if (value instanceof Map) { + if (value != null) { + Map map = (Map) value; + if (map.values().size() > 0) { + if (map.get(propertyName) != null) { + primaryValue = (String) map.get(propertyName); + } + } + } + } + return primaryValue; + } } -- 2.47.3