From 823dfb848f5e0129f85a164235f520167c0e3d5b Mon Sep 17 00:00:00 2001 From: Patrick Schmitz Date: Wed, 6 Jan 2010 07:31:41 +0000 Subject: [PATCH] NOJIRA - fixed support for additional schema fields in the nuxeo layout, in the tests, and in the import support. Reflected reversion of pattern service (Vocabulary) to pass the inAuthority value in the organization_common schema. Updated the tests to detect when the inAuthority is not being set correctly on create. --- .../resources/OSGI-INF/layouts-contrib.xml | 119 +++++++++++++++++- .../client/test/OrgAuthorityServiceTest.java | 31 +++-- .../importer/OrgAuthorityBaseImport.java | 113 ++++++++++------- .../services/OrganizationJAXBSchema.java | 11 +- .../OrganizationListItemJAXBSchema.java | 2 +- .../main/resources/organization_common.xsd | 3 +- .../organization/client/sample/Sample.java | 11 +- .../OrganizationDocumentModelHandler.java | 4 +- 8 files changed, 226 insertions(+), 68 deletions(-) diff --git a/services/organization/3rdparty/nuxeo-platform-cs-organization/src/main/resources/OSGI-INF/layouts-contrib.xml b/services/organization/3rdparty/nuxeo-platform-cs-organization/src/main/resources/OSGI-INF/layouts-contrib.xml index daacbfd75..e0db2b20e 100644 --- a/services/organization/3rdparty/nuxeo-platform-cs-organization/src/main/resources/OSGI-INF/layouts-contrib.xml +++ b/services/organization/3rdparty/nuxeo-platform-cs-organization/src/main/resources/OSGI-INF/layouts-contrib.xml @@ -64,18 +64,26 @@ - displayName + shortName refName inAuthority + longName + nameAdditions + contactName + foundingDate + dissolutionDate + foundingPlace + function + description - + true - displayName + shortName dataInputText @@ -107,6 +115,111 @@ dataInputText + + + + + + true + + longName + + + dataInputText + + + + + + + + true + + nameAdditions + + + dataInputText + + + + + + + + true + + contactName + + + dataInputText + + + + + + + + true + + foundingDate + + + dataInputText + + + + + + + + true + + dissolutionDate + + + dataInputText + + + + + + + + true + + foundingPlace + + + dataInputText + + + + + + + + true + + function + + + dataInputText + + + + + + + + true + + description + + + dataInputText + + + 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 830a642c1..6d6f5026c 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 @@ -62,8 +62,10 @@ public class OrgAuthorityServiceTest extends AbstractServiceTest { final String SERVICE_PATH_COMPONENT = "orgauthorities"; final String ITEM_SERVICE_PATH_COMPONENT = "items"; private String knownResourceId = null; + private String lastOrgAuthId = null; private String knownResourceRefName = null; private String knownItemResourceId = null; + private int nItemsToCreateInList = 3; private List allResourceIdsCreated = new ArrayList(); private Map allResourceItemIdsCreated = new HashMap(); @@ -112,10 +114,11 @@ public class OrgAuthorityServiceTest extends AbstractServiceTest { // for additional tests below. knownResourceRefName = refName; + lastOrgAuthId = extractId(res); // Store the ID returned from the first resource created // for additional tests below. if (knownResourceId == null){ - knownResourceId = extractId(res); + knownResourceId = lastOrgAuthId; if (logger.isDebugEnabled()) { logger.debug(testName + ": knownResourceId=" + knownResourceId); } @@ -131,7 +134,7 @@ public class OrgAuthorityServiceTest extends AbstractServiceTest { public void createItem(String testName) { setupCreate(testName); - knownItemResourceId = createItemInAuthority(knownResourceId); + knownItemResourceId = createItemInAuthority(lastOrgAuthId); if(logger.isDebugEnabled()){ logger.debug(testName + ": knownItemResourceId=" + knownItemResourceId); } @@ -189,8 +192,12 @@ public class OrgAuthorityServiceTest extends AbstractServiceTest { public void createList(String testName) throws Exception { for (int i = 0; i < 3; i++) { create(testName); - // Add 3 items to each orgauthority - for (int j = 0; j < 3; j++) { + knownResourceId = lastOrgAuthId; + if (logger.isDebugEnabled()) { + logger.debug(testName + ": Resetting knownResourceId to" + knownResourceId); + } + // Add nItemsToCreateInList items to each orgauthority + for (int j = 0; j < nItemsToCreateInList; j++) { createItem(testName); } } @@ -503,17 +510,24 @@ public class OrgAuthorityServiceTest extends AbstractServiceTest { invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + List items = + list.getOrganizationListItem(); + int nItemsReturned = items.size(); + if(logger.isDebugEnabled()){ + logger.debug(" " + testName + ": Expected " + + nItemsToCreateInList+" items; got: "+nItemsReturned); + } + Assert.assertEquals( nItemsReturned, nItemsToCreateInList); + // Optionally output additional data about list members for debugging. boolean iterateThroughList = false; if (iterateThroughList && logger.isDebugEnabled()) { - List items = - list.getOrganizationListItem(); int i = 0; for (OrganizationsCommonList.OrganizationListItem item : items) { logger.debug(" " + testName + ": list-item[" + i + "] csid=" + item.getCsid()); - logger.debug(" " + testName + ": list-item[" + i + "] displayName=" + - item.getDisplayName()); + logger.debug(" " + testName + ": list-item[" + i + "] shortName=" + + item.getShortName()); logger.debug(" " + testName + ": list-item[" + i + "] URI=" + item.getUri()); i++; @@ -1044,6 +1058,7 @@ public class OrgAuthorityServiceTest extends AbstractServiceTest { String foundingDate, String dissolutionDate, String foundingPlace, String function, String description ) { OrganizationsCommon organization = new OrganizationsCommon(); + organization.setInAuthority(inAuthority); organization.setShortName(shortName); if(refName!=null) organization.setRefName(refName); diff --git a/services/organization/import/src/main/java/org/collectionspace/services/organization/importer/OrgAuthorityBaseImport.java b/services/organization/import/src/main/java/org/collectionspace/services/organization/importer/OrgAuthorityBaseImport.java index e6b1832d4..6e513de50 100644 --- a/services/organization/import/src/main/java/org/collectionspace/services/organization/importer/OrgAuthorityBaseImport.java +++ b/services/organization/import/src/main/java/org/collectionspace/services/organization/importer/OrgAuthorityBaseImport.java @@ -58,7 +58,8 @@ public class OrgAuthorityBaseImport { final String SERVICE_PATH_COMPONENT = "orgauthorities"; final String ITEM_SERVICE_PATH_COMPONENT = "items"; - public void createOrgAuthority(String orgAuthorityName, List enumValues ) { + public void createOrgAuthority(String orgAuthorityName, + List> orgInfo ) { // Expected status code: 201 Created int EXPECTED_STATUS_CODE = Response.Status.CREATED.getStatusCode(); @@ -68,8 +69,10 @@ public class OrgAuthorityBaseImport { if(logger.isDebugEnabled()){ logger.debug("Import: Create orgAuthority: \"" + orgAuthorityName +"\""); } + String baseOrgRefName = createOrgAuthRefName(orgAuthorityName); + String fullOrgRefName = baseOrgRefName+"'"+orgAuthorityName+"'"; MultipartOutput multipart = createOrgAuthorityInstance(orgAuthorityName, - createRefName(orgAuthorityName), "enum"); + fullOrgRefName); ClientResponse res = client.create(multipart); int statusCode = res.getStatus(); @@ -90,49 +93,57 @@ public class OrgAuthorityBaseImport { logger.debug("Import: Created orgAuthorityulary: \"" + orgAuthorityName +"\" ID:" +newOrgAuthorityId ); } - for(String itemName : enumValues){ - createItemInAuthority(newOrgAuthorityId, orgAuthorityName, itemName, createRefName(itemName)); + for(List orgStrings : orgInfo){ + createItemInAuthority(newOrgAuthorityId, baseOrgRefName, orgStrings); } } - private String createItemInAuthority(String vcsid, String orgAuthorityName, String itemName, String refName) { + private String createItemInAuthority(String vcsid, + String orgAuthorityRefName, List orgStrings) { // Expected status code: 201 Created int EXPECTED_STATUS_CODE = Response.Status.CREATED.getStatusCode(); // Type of service request being tested ServiceRequestType REQUEST_TYPE = ServiceRequestType.CREATE; + /* Strings are: + shortName, longName, nameAdditions, contactName, + foundingDate, dissolutionDate, foundingPlace, function, description + */ + String shortName = orgStrings.get(0); + String refName = createOrganizationRefName(orgAuthorityRefName, shortName); if(logger.isDebugEnabled()){ - logger.debug("Import: Create Item: \""+itemName+"\" in orgAuthorityulary: \"" + orgAuthorityName +"\""); + logger.debug("Import: Create Item: \""+shortName + +"\" in orgAuthorityulary: \"" + orgAuthorityRefName +"\""); } - MultipartOutput multipart = createOrganizationInstance(itemName, refName, - null, null, null, null, null, null, null, null, null ); + MultipartOutput multipart = createOrganizationInstance( vcsid, refName, + orgStrings ); ClientResponse res = client.createItem(vcsid, multipart); int statusCode = res.getStatus(); if(!REQUEST_TYPE.isValidStatusCode(statusCode)) { - throw new RuntimeException("Could not create Item: \""+itemName - +"\" in orgAuthority: \"" + orgAuthorityName + throw new RuntimeException("Could not create Item: \""+shortName + +"\" in orgAuthority: \"" + orgAuthorityRefName +"\" "+ invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); } if(statusCode != EXPECTED_STATUS_CODE) { - throw new RuntimeException("Unexpected Status when creating Item: \""+itemName - +"\" in orgAuthority: \"" + orgAuthorityName +"\", Status:"+ statusCode); + throw new RuntimeException("Unexpected Status when creating Item: \""+shortName + +"\" in orgAuthority: \"" + orgAuthorityRefName +"\", Status:"+ statusCode); } return extractId(res); } // --------------------------------------------------------------- - // Utility methods used by tests above + // Utility methods used by methods above // --------------------------------------------------------------- private MultipartOutput createOrgAuthorityInstance( - String displayName, String refName, String vocabType) { + String displayName, String refName ) { OrgauthoritiesCommon orgAuthority = new OrgauthoritiesCommon(); orgAuthority.setDisplayName(displayName); orgAuthority.setRefName(refName); - orgAuthority.setVocabType(vocabType); + orgAuthority.setVocabType("OrgAuthority"); MultipartOutput multipart = new MultipartOutput(); OutputPart commonPart = multipart.addPart(orgAuthority, MediaType.APPLICATION_XML_TYPE); commonPart.getHeaders().add("label", client.getCommonPartName()); @@ -145,29 +156,34 @@ public class OrgAuthorityBaseImport { return multipart; } - private MultipartOutput createOrganizationInstance(String inAuthority, - String shortName, String refName, String longName, - String nameAdditions, String contactName, - String foundingDate, String dissolutionDate, String foundingPlace, - String function, String description ) { + private MultipartOutput createOrganizationInstance(String inAuthority, + String orgRefName, List orgStrings){ OrganizationsCommon organization = new OrganizationsCommon(); - organization.setShortName(shortName); - if(refName!=null) - organization.setRefName(refName); + organization.setInAuthority(inAuthority); + organization.setShortName(orgStrings.get(0)); + organization.setRefName(orgRefName); + String longName = orgStrings.get(1); if(longName!=null) organization.setLongName(longName); + String nameAdditions = orgStrings.get(2); if(nameAdditions!=null) organization.setNameAdditions(nameAdditions); + String contactName = orgStrings.get(3); if(contactName!=null) organization.setContactName(contactName); + String foundingDate = orgStrings.get(4); if(foundingDate!=null) organization.setFoundingDate(foundingDate); + String dissolutionDate = orgStrings.get(5); if(dissolutionDate!=null) organization.setDissolutionDate(dissolutionDate); + String foundingPlace = orgStrings.get(6); if(foundingPlace!=null) organization.setFoundingPlace(foundingPlace); + String function = orgStrings.get(7); if(function!=null) organization.setFunction(function); + String description = orgStrings.get(8); if(description!=null) organization.setDescription(description); MultipartOutput multipart = new MultipartOutput(); @@ -214,8 +230,14 @@ public class OrgAuthorityBaseImport { return id; } - protected String createRefName(String displayName) { - return displayName.replaceAll("\\W", ""); + protected String createOrgAuthRefName(String orgAuthorityName) { + return "urn:cspace:org.collectionspace.demo:personauthority:name(" + +orgAuthorityName+")"; + } + + protected String createOrganizationRefName( + String orgAuthRefName, String orgName) { + return orgAuthRefName+":organization:name("+orgName+")"; } public static void main(String[] args) { @@ -224,27 +246,26 @@ public class OrgAuthorityBaseImport { logger.info("OrgAuthorityBaseImport starting..."); OrgAuthorityBaseImport oabi = new OrgAuthorityBaseImport(); - final String acquisitionMethodsOrgAuthorityName = "Acquisition Methods"; - final String entryMethodsOrgAuthorityName = "Entry Methods"; - final String entryReasonsOrgAuthorityName = "Entry Reasons"; - final String responsibleDeptsOrgAuthorityName = "Responsible Departments"; - - List acquisitionMethodsEnumValues = - Arrays.asList("Gift","Purchase","Exchange","Transfer","Treasure"); - List entryMethodsEnumValues = - Arrays.asList("In person","Post","Found on doorstep"); - List entryReasonsEnumValues = - Arrays.asList("Enquiry","Commission","Loan"); - List respDeptNamesEnumValues = - Arrays.asList("Antiquities","Architecture and Design","Decorative Arts", - "Ethnography","Herpetology","Media and Performance Art", - "Paintings and Sculpture","Paleobotany","Photographs", - "Prints and Drawings"); - - oabi.createOrgAuthority(acquisitionMethodsOrgAuthorityName, acquisitionMethodsEnumValues); - oabi.createOrgAuthority(entryMethodsOrgAuthorityName, entryMethodsEnumValues); - oabi.createOrgAuthority(entryReasonsOrgAuthorityName, entryReasonsEnumValues); - oabi.createOrgAuthority(responsibleDeptsOrgAuthorityName, respDeptNamesEnumValues); + final String demoOrgAuthorityName = "Demo Org Authority"; + + /* Strings are: + shortName, longName, nameAdditions, contactName, + foundingDate, dissolutionDate, foundingPlace, function, description + */ + List mmiOrgStrings = + Arrays.asList("MMI","Museum of the Moving Image",null,"Megan Forbes", + "1984", null, "Astoria, NY", null, null); + List pahmaOrgStrings = + Arrays.asList("PAHMA","Phoebe A. Hearst Museum of Anthropology", + "University of California, Berkeley","Michael Black", + "1901", null, "Berkeley, CA", null, null); + List savoyOrgStrings = + Arrays.asList("Savoy Theatre",null,null,null, + "1900", "1952", "New York, NY", null, null); + List> orgsStrings = + Arrays.asList(mmiOrgStrings, pahmaOrgStrings, savoyOrgStrings ); + + oabi.createOrgAuthority(demoOrgAuthorityName, orgsStrings); logger.info("OrgAuthorityBaseImport complete."); } 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 67ae42287..11ff58d10 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 @@ -8,10 +8,17 @@ package org.collectionspace.services; * */ public interface OrganizationJAXBSchema { - final static String DISPLAY_NAME = "displayName"; - final static String REF_NAME = "refName"; final static String CSID = "csid"; + final static String IN_AUTHORITY = "inAuthority"; + final static String SHORT_NAME = "shortName"; + final static String REF_NAME = "refName"; final static String LONG_NAME = "longName"; + final static String NAME_ADDITIONS = "nameAdditions"; + final static String CONTACT_NAME = "contactName"; + final static String FOUNDING_DATE = "foundingDate"; + final static String DISSOLUTION_DATE = "dissolutionDate"; + final static String FOUNDING_PLACE = "foundingPlace"; + final static String FUNCTION = "function"; final static String DESCRIPTION = "description"; } diff --git a/services/organization/jaxb/src/main/java/org/collectionspace/services/OrganizationListItemJAXBSchema.java b/services/organization/jaxb/src/main/java/org/collectionspace/services/OrganizationListItemJAXBSchema.java index 86653cf18..e661607a5 100644 --- a/services/organization/jaxb/src/main/java/org/collectionspace/services/OrganizationListItemJAXBSchema.java +++ b/services/organization/jaxb/src/main/java/org/collectionspace/services/OrganizationListItemJAXBSchema.java @@ -1,7 +1,7 @@ package org.collectionspace.services; public interface OrganizationListItemJAXBSchema { - final static String DISPLAY_NAME = "displayName"; + final static String SHORT_NAME = "shortName"; final static String REF_NAME = "refName"; final static String CSID = "csid"; final static String URI = "url"; diff --git a/services/organization/jaxb/src/main/resources/organization_common.xsd b/services/organization/jaxb/src/main/resources/organization_common.xsd index 23ef6fe98..9a3232672 100644 --- a/services/organization/jaxb/src/main/resources/organization_common.xsd +++ b/services/organization/jaxb/src/main/resources/organization_common.xsd @@ -19,6 +19,7 @@ + @@ -40,7 +41,7 @@ - res = client.createItem(vcsid, multipart); int statusCode = res.getStatus(); @@ -314,8 +314,9 @@ public class Sample { } private MultipartOutput createOrganizationInstance( - String displayName, String refName) { + String inAuthority, String displayName, String refName) { OrganizationsCommon organization = new OrganizationsCommon(); + organization.setInAuthority(inAuthority); organization.setShortName(displayName); organization.setRefName(refName); MultipartOutput multipart = new MultipartOutput(); @@ -373,7 +374,7 @@ public class Sample { OrganizationsCommonList.OrganizationListItem item) { StringBuffer sb = new StringBuffer(); sb.append("csid=" + item.getCsid() + "\n"); - sb.append("displayName=" + item.getDisplayName() + "\n"); + sb.append("shortName=" + item.getShortName() + "\n"); // sb.append("URI=" + item.getUri() + "\n"); return sb.toString(); } @@ -519,8 +520,8 @@ public class Sample { // For each organization ... for (OrganizationsCommonList.OrganizationListItem item : items.getOrganizationListItem()) { - // Get its display name. - logger.info(" " + item.getDisplayName()); + // Get its short name. + logger.info(" " + item.getShortName()); } } 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 10937af34..41fbfa8d8 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 @@ -136,9 +136,9 @@ public class OrganizationDocumentModelHandler while(iter.hasNext()){ DocumentModel docModel = iter.next(); OrganizationListItem ilistItem = new OrganizationListItem(); - ilistItem.setDisplayName( + ilistItem.setShortName( (String) docModel.getProperty(getServiceContext().getCommonPartLabel("organizations"), - OrganizationJAXBSchema.DISPLAY_NAME)); + OrganizationJAXBSchema.SHORT_NAME)); ilistItem.setRefName( (String) docModel.getProperty(getServiceContext().getCommonPartLabel("organizations"), OrganizationJAXBSchema.REF_NAME)); -- 2.47.3