From 0a38120b7c96c837b96f304f65c4bb3a6a62e6dd Mon Sep 17 00:00:00 2001 From: Aron Roberts Date: Fri, 23 Jul 2010 00:10:29 +0000 Subject: [PATCH] CSPACE-2534: Made four fields repeatable in Person records (records of items within a PersonAuthority), in the services layer: group, nationality, occupation, and schoolOrStyle. Changes the relevant Nuxeo document type schema, and as such requires an 'ant deploy' and a 2-server restart. --- .../main/resources/schemas/persons_common.xsd | 34 ++++++++-- .../client/PersonAuthorityClientUtils.java | 66 +++++++++++++++---- .../test/PersonAuthoritySearchTest.java | 7 +- .../test/PersonAuthorityServicePerfTest.java | 3 +- .../test/PersonAuthorityServiceTest.java | 22 ++++++- .../services/PersonJAXBSchema.java | 8 +-- .../jaxb/src/main/resources/person_common.xsd | 34 ++++++++-- 7 files changed, 143 insertions(+), 31 deletions(-) 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 6be3d6b63..c53bc976d 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 @@ -23,7 +23,7 @@ - + @@ -39,11 +39,35 @@ - - + + + + + + + + + + + + + + - - + + + + + + + + + + + + + + diff --git a/services/person/client/src/main/java/org/collectionspace/services/client/PersonAuthorityClientUtils.java b/services/person/client/src/main/java/org/collectionspace/services/client/PersonAuthorityClientUtils.java index a734425a3..f800a0ad9 100644 --- a/services/person/client/src/main/java/org/collectionspace/services/client/PersonAuthorityClientUtils.java +++ b/services/person/client/src/main/java/org/collectionspace/services/client/PersonAuthorityClientUtils.java @@ -28,6 +28,7 @@ package org.collectionspace.services.client; import java.util.ArrayList; import java.util.Arrays; +import java.util.HashMap; import java.util.List; import java.util.Map; @@ -37,8 +38,12 @@ import javax.ws.rs.core.Response; import org.collectionspace.services.PersonJAXBSchema; import org.collectionspace.services.client.test.ServiceRequestType; +import org.collectionspace.services.person.GroupList; +import org.collectionspace.services.person.NationalityList; +import org.collectionspace.services.person.OccupationList; import org.collectionspace.services.person.PersonsCommon; import org.collectionspace.services.person.PersonauthoritiesCommon; +import org.collectionspace.services.person.SchoolOrStyleList; import org.jboss.resteasy.client.ClientResponse; import org.jboss.resteasy.plugins.providers.multipart.MultipartInput; import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput; @@ -151,7 +156,7 @@ public class PersonAuthorityClientUtils { } /** - * Creates the person instance. + * Creates a person instance. * * @param inAuthority the owning authority * @param personAuthRefName the owning Authority ref name @@ -159,8 +164,28 @@ public class PersonAuthorityClientUtils { * @param headerLabel the header label * @return the multipart output */ + public static MultipartOutput createPersonInstance(String inAuthority, + String personAuthRefName, Map personInfo, + String headerLabel){ + final Map> EMPTY_PERSON_REPEATABLES_INFO = + new HashMap>(); + return createPersonInstance(inAuthority, personAuthRefName, personInfo, + EMPTY_PERSON_REPEATABLES_INFO, headerLabel); + } + + /** + * Creates a person instance. + * + * @param inAuthority the owning authority + * @param personAuthRefName the owning Authority ref name + * @param personInfo the person info + * @param personRepeatablesInfo names and values of repeatable scalar fields in the Person record + * @param headerLabel the header label + * @return the multipart output + */ public static MultipartOutput createPersonInstance(String inAuthority, - String personAuthRefName, Map personInfo, String headerLabel){ + String personAuthRefName, Map personInfo, + Map> personRepeatablesInfo, String headerLabel){ PersonsCommon person = new PersonsCommon(); person.setInAuthority(inAuthority); String shortId = personInfo.get(PersonJAXBSchema.SHORT_IDENTIFIER); @@ -190,6 +215,7 @@ public class PersonAuthorityClientUtils { person.setRefName(refName); String value; + List values = null; if((value = (String)personInfo.get(PersonJAXBSchema.FORE_NAME))!=null) //FIXME: REM - I don't think we need to check for null -null is a valid value and won't cause any problems. person.setForeName(value); if((value = (String)personInfo.get(PersonJAXBSchema.MIDDLE_NAME))!=null) @@ -212,16 +238,32 @@ public class PersonAuthorityClientUtils { person.setBirthPlace(value); if((value = (String)personInfo.get(PersonJAXBSchema.DEATH_PLACE))!=null) person.setDeathPlace(value); - if((value = (String)personInfo.get(PersonJAXBSchema.GROUP))!=null) - person.setGroup(value); - if((value = (String)personInfo.get(PersonJAXBSchema.NATIONALITY))!=null) - person.setNationality(value); + if((values = (List)personRepeatablesInfo.get(PersonJAXBSchema.GROUPS))!=null) { + GroupList groupsList = new GroupList(); + List groups = groupsList.getGroup(); + groups.addAll(values); + person.setGroups(groupsList); + } + if((values = (List)personRepeatablesInfo.get(PersonJAXBSchema.NATIONALITIES))!=null) { + NationalityList nationalitiesList = new NationalityList(); + List nationalities = nationalitiesList.getNationality(); + nationalities.addAll(values); + person.setNationalities(nationalitiesList); + } if((value = (String)personInfo.get(PersonJAXBSchema.GENDER))!=null) person.setGender(value); - if((value = (String)personInfo.get(PersonJAXBSchema.OCCUPATION))!=null) - person.setOccupation(value); - if((value = (String)personInfo.get(PersonJAXBSchema.SCHOOL_OR_STYLE))!=null) - person.setSchoolOrStyle(value); + if((values = (List)personRepeatablesInfo.get(PersonJAXBSchema.OCCUPATIONS))!=null) { + OccupationList occupationsList = new OccupationList(); + List occupations = occupationsList.getOccupation(); + occupations.addAll(values); + person.setOccupations(occupationsList); + } + if((values = (List)personRepeatablesInfo.get(PersonJAXBSchema.SCHOOLS_OR_STYLES))!=null) { + SchoolOrStyleList schoolOrStyleList = new SchoolOrStyleList(); + List schoolsOrStyles = schoolOrStyleList.getSchoolOrStyle(); + schoolsOrStyles.addAll(values); + person.setSchoolsOrStyles(schoolOrStyleList); + } if((value = (String)personInfo.get(PersonJAXBSchema.BIO_NOTE))!=null) person.setBioNote(value); if((value = (String)personInfo.get(PersonJAXBSchema.NAME_NOTE))!=null) @@ -250,7 +292,7 @@ public class PersonAuthorityClientUtils { */ public static String createItemInAuthority(String vcsid, String personAuthorityRefName, Map personMap, - PersonAuthorityClient client ) { + Map> personRepeatablesMap, PersonAuthorityClient client ) { // Expected status code: 201 Created int EXPECTED_STATUS_CODE = Response.Status.CREATED.getStatusCode(); // Type of service request being tested @@ -280,7 +322,7 @@ public class PersonAuthorityClientUtils { } MultipartOutput multipart = createPersonInstance(vcsid, personAuthorityRefName, - personMap, client.getItemCommonPartName()); + personMap, personRepeatablesMap, client.getItemCommonPartName()); String result = null; ClientResponse res = client.createItem(vcsid, multipart); diff --git a/services/person/client/src/test/java/org/collectionspace/services/client/test/PersonAuthoritySearchTest.java b/services/person/client/src/test/java/org/collectionspace/services/client/test/PersonAuthoritySearchTest.java index a8928158a..fa0105bb4 100644 --- a/services/person/client/src/test/java/org/collectionspace/services/client/test/PersonAuthoritySearchTest.java +++ b/services/person/client/src/test/java/org/collectionspace/services/client/test/PersonAuthoritySearchTest.java @@ -566,9 +566,12 @@ public class PersonAuthoritySearchTest extends BaseServiceTest { partialTermPersonMap.put(PersonJAXBSchema.SUR_NAME, TEST_PARTIAL_TERM_SUR_NAME); partialTermPersonMap.put(PersonJAXBSchema.BIRTH_PLACE, TEST_KWD_BIRTH_PLACE); partialTermPersonMap.put(PersonJAXBSchema.GENDER, "male"); + + Map> partialTermRepeatablesMap = new HashMap>(); + MultipartOutput multipart = - PersonAuthorityClientUtils.createPersonInstance(authorityCsid, authRefName, partialTermPersonMap, - client.getItemCommonPartName() ); + PersonAuthorityClientUtils.createPersonInstance(authorityCsid, authRefName, + partialTermPersonMap, partialTermRepeatablesMap, client.getItemCommonPartName() ); String newID = null; ClientResponse res = client.createItem(authorityCsid, multipart); diff --git a/services/person/client/src/test/java/org/collectionspace/services/client/test/PersonAuthorityServicePerfTest.java b/services/person/client/src/test/java/org/collectionspace/services/client/test/PersonAuthorityServicePerfTest.java index 7fcb806ad..7f5f60aea 100644 --- a/services/person/client/src/test/java/org/collectionspace/services/client/test/PersonAuthorityServicePerfTest.java +++ b/services/person/client/src/test/java/org/collectionspace/services/client/test/PersonAuthorityServicePerfTest.java @@ -200,9 +200,10 @@ public class PersonAuthorityServicePerfTest extends BaseServiceTest { personMap.put(PersonJAXBSchema.DISPLAY_NAME_COMPUTED, "true"); personMap.put(PersonJAXBSchema.FORE_NAME, firstName); personMap.put(PersonJAXBSchema.SUR_NAME, lastName); + Map> personRepeatablesMap = new HashMap>(); MultipartOutput multipart = PersonAuthorityClientUtils.createPersonInstance(authId, authRefName, - personMap, client.getItemCommonPartName() ); + personMap, personRepeatablesMap, client.getItemCommonPartName() ); String newID = null; ClientResponse res = client.createItem(authId, multipart); 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 6e14845c0..e93c4460f 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 @@ -22,6 +22,7 @@ */ package org.collectionspace.services.client.test; +import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -259,9 +260,16 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { "American icon. He is famous for his distinctive voice, walk and height. " + "He was also known for his conservative political views and his support in " + "the 1950s for anti-communist positions."); + + Map> johnWayneRepeatablesMap = new HashMap>(); + List johnWayneGroups = new ArrayList(); + johnWayneGroups.add("Irish"); + johnWayneGroups.add("Scottish"); + johnWayneRepeatablesMap.put(PersonJAXBSchema.GROUPS, johnWayneGroups); + MultipartOutput multipart = PersonAuthorityClientUtils.createPersonInstance(vcsid, authRefName, johnWayneMap, - client.getItemCommonPartName() ); + johnWayneRepeatablesMap, client.getItemCommonPartName() ); String newID = null; ClientResponse res = client.createItem(vcsid, multipart); @@ -715,7 +723,16 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { logger.debug(testName + ": returned payload:"); logger.debug(objectAsXmlString(person, PersonsCommon.class)); } + + // Check that the person item is within the expected Person Authority. Assert.assertEquals(person.getInAuthority(), knownResourceId); + + // Verify the number and contents of values in a repeatable field, + // as created in the instance record used for testing. + List groups = person.getGroups().getGroup(); + Assert.assertTrue(groups.size() > 0); + Assert.assertNotNull(groups.get(0)); + } finally { res.releaseConnection(); } @@ -1742,10 +1759,11 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { nonexMap.put(PersonJAXBSchema.FORE_NAME, "John"); nonexMap.put(PersonJAXBSchema.SUR_NAME, "Wayne"); nonexMap.put(PersonJAXBSchema.GENDER, "male"); + Map> nonexRepeatablesMap = new HashMap>(); MultipartOutput multipart = PersonAuthorityClientUtils.createPersonInstance(NON_EXISTENT_ID, PersonAuthorityClientUtils.createPersonAuthRefName(NON_EXISTENT_ID, null), - nonexMap, client.getItemCommonPartName() ); + nonexMap, nonexRepeatablesMap, client.getItemCommonPartName() ); ClientResponse res = client.updateItem(knownResourceId, NON_EXISTENT_ID, multipart); try { 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 7653c917e..bc692f032 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 @@ -22,11 +22,11 @@ public interface PersonJAXBSchema extends AuthorityJAXBSchema { final static String DEATH_DATE = "deathDate"; final static String BIRTH_PLACE = "birthPlace"; final static String DEATH_PLACE = "deathPlace"; - final static String GROUP = "group"; - final static String NATIONALITY = "nationality"; + final static String GROUPS = "groups"; + final static String NATIONALITIES = "nationalities"; final static String GENDER = "gender"; - final static String OCCUPATION = "occupation"; - final static String SCHOOL_OR_STYLE = "schoolOrStyle"; + final static String OCCUPATIONS = "occupations"; + final static String SCHOOLS_OR_STYLES = "schoolsOrStyles"; final static String BIO_NOTE = "bioNote"; final static String NAME_NOTE = "nameNote"; } diff --git a/services/person/jaxb/src/main/resources/person_common.xsd b/services/person/jaxb/src/main/resources/person_common.xsd index b095c30fc..a9b7f9651 100644 --- a/services/person/jaxb/src/main/resources/person_common.xsd +++ b/services/person/jaxb/src/main/resources/person_common.xsd @@ -33,7 +33,7 @@ - + @@ -49,16 +49,40 @@ - - + + - - + + + + + + + + + + + + + + + + + + + + + + + + + + -- 2.47.3