From 2ff57425211169195846b236eca54e2ddc831056 Mon Sep 17 00:00:00 2001 From: Patrick Schmitz Date: Tue, 12 Jan 2010 01:07:41 +0000 Subject: [PATCH] CSPACE-725 - Refactored instance creation methods into a shared utility class. --- .../client/OrgAuthorityClientUtils.java | 74 ++++++++ .../client/test/OrgAuthorityServiceTest.java | 94 +++------- .../importer/OrgAuthorityBaseImport.java | 138 +++++---------- .../organization/client/sample/Sample.java | 163 +++++++++--------- 4 files changed, 217 insertions(+), 252 deletions(-) create mode 100644 services/organization/client/src/main/java/org/collectionspace/services/client/OrgAuthorityClientUtils.java 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 new file mode 100644 index 000000000..246917e43 --- /dev/null +++ b/services/organization/client/src/main/java/org/collectionspace/services/client/OrgAuthorityClientUtils.java @@ -0,0 +1,74 @@ +package org.collectionspace.services.client; + +import java.util.List; +import java.util.Map; + +import javax.ws.rs.core.MediaType; + +import org.collectionspace.services.OrganizationJAXBSchema; +import org.collectionspace.services.organization.OrganizationsCommon; +import org.collectionspace.services.organization.OrgauthoritiesCommon; +import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput; +import org.jboss.resteasy.plugins.providers.multipart.OutputPart; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class OrgAuthorityClientUtils { + private static final Logger logger = + LoggerFactory.getLogger(OrgAuthorityClientUtils.class); + + public static MultipartOutput createOrgAuthorityInstance( + String displayName, String refName, String headerLabel ) { + OrgauthoritiesCommon orgAuthority = new OrgauthoritiesCommon(); + orgAuthority.setDisplayName(displayName); + orgAuthority.setRefName(refName); + orgAuthority.setVocabType("OrgAuthority"); + MultipartOutput multipart = new MultipartOutput(); + OutputPart commonPart = multipart.addPart(orgAuthority, MediaType.APPLICATION_XML_TYPE); + commonPart.getHeaders().add("label", headerLabel); + + if(logger.isDebugEnabled()){ + logger.debug("to be created, orgAuthority common ", + orgAuthority, OrgauthoritiesCommon.class); + } + + return multipart; + } + + public static MultipartOutput createOrganizationInstance(String inAuthority, + String orgRefName, Map orgInfo, String headerLabel){ + OrganizationsCommon organization = new OrganizationsCommon(); + organization.setInAuthority(inAuthority); + organization.setRefName(orgRefName); + String value = null; + 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((value = (String)orgInfo.get(OrganizationJAXBSchema.CONTACT_NAME))!=null) + organization.setContactName(value); + if((value = (String)orgInfo.get(OrganizationJAXBSchema.FOUNDING_DATE))!=null) + organization.setFoundingDate(value); + if((value = (String)orgInfo.get(OrganizationJAXBSchema.DISSOLUTION_DATE))!=null) + organization.setDissolutionDate(value); + if((value = (String)orgInfo.get(OrganizationJAXBSchema.FOUNDING_PLACE))!=null) + organization.setFoundingPlace(value); + if((value = (String)orgInfo.get(OrganizationJAXBSchema.FUNCTION))!=null) + organization.setFunction(value); + if((value = (String)orgInfo.get(OrganizationJAXBSchema.DESCRIPTION))!=null) + organization.setDescription(value); + MultipartOutput multipart = new MultipartOutput(); + OutputPart commonPart = multipart.addPart(organization, + MediaType.APPLICATION_XML_TYPE); + commonPart.getHeaders().add("label", headerLabel); + + if(logger.isDebugEnabled()){ + logger.debug("to be created, organization common ", organization, OrganizationsCommon.class); + } + + return multipart; + } + +} 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 930505300..bbb1f9a93 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 @@ -29,7 +29,9 @@ import java.util.Map; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; +import org.collectionspace.services.OrganizationJAXBSchema; import org.collectionspace.services.client.OrgAuthorityClient; +import org.collectionspace.services.client.OrgAuthorityClientUtils; import org.collectionspace.services.organization.OrgauthoritiesCommon; import org.collectionspace.services.organization.OrgauthoritiesCommonList; import org.collectionspace.services.organization.OrganizationsCommon; @@ -91,9 +93,10 @@ public class OrgAuthorityServiceTest extends AbstractServiceTest { String identifier = createIdentifier(); String displayName = "displayName-" + identifier; String refName = createRefName(displayName); - String typeName = "vocabType-" + identifier; MultipartOutput multipart = - createOrgAuthorityInstance(displayName, refName, typeName); + OrgAuthorityClientUtils.createOrgAuthorityInstance( + displayName, refName, + client.getCommonPartName()); ClientResponse res = client.create(multipart); int statusCode = res.getStatus(); @@ -150,10 +153,16 @@ public class OrgAuthorityServiceTest extends AbstractServiceTest { // Submit the request to the service and store the response. String identifier = createIdentifier(); String refName = createRefName(identifier); - MultipartOutput multipart = createOrganizationInstance(vcsid, - identifier, refName, "Longer Name for "+identifier, - null, "joe@org.org", "1910", null, "Anytown, USA", "testing", - "This is a fake organization that was created by a test method." ); + Map testOrgMap = new HashMap(); + testOrgMap.put(OrganizationJAXBSchema.SHORT_NAME, "Test Org"); + testOrgMap.put(OrganizationJAXBSchema.LONG_NAME, "The real official test organization"); + testOrgMap.put(OrganizationJAXBSchema.CONTACT_NAME, "joe@test.org"); + testOrgMap.put(OrganizationJAXBSchema.FOUNDING_DATE, "May 26, 1907"); + testOrgMap.put(OrganizationJAXBSchema.FOUNDING_PLACE, "Anytown, USA"); + testOrgMap.put(OrganizationJAXBSchema.FUNCTION, "For testing"); + MultipartOutput multipart = + OrgAuthorityClientUtils.createOrganizationInstance(vcsid, + refName, testOrgMap, client.getItemCommonPartName() ); ClientResponse res = client.createItem(vcsid, multipart); int statusCode = res.getStatus(); @@ -797,9 +806,12 @@ public class OrgAuthorityServiceTest extends AbstractServiceTest { // The only relevant ID may be the one used in update(), below. // The only relevant ID may be the one used in update(), below. - MultipartOutput multipart = createOrganizationInstance( - knownResourceId, NON_EXISTENT_ID, createRefName(NON_EXISTENT_ID), - null, null, null, null, null, null, null, null); + Map nonexOrgMap = new HashMap(); + nonexOrgMap.put(OrganizationJAXBSchema.SHORT_NAME, "Non-existent"); + MultipartOutput multipart = + OrgAuthorityClientUtils.createOrganizationInstance( + knownResourceId, createRefName(NON_EXISTENT_ID), + nonexOrgMap, client.getCommonPartName() ); ClientResponse res = client.updateItem(knownResourceId, NON_EXISTENT_ID, multipart); int statusCode = res.getStatus(); @@ -1029,66 +1041,8 @@ public class OrgAuthorityServiceTest extends AbstractServiceTest { private MultipartOutput createOrgAuthorityInstance(String identifier) { String displayName = "displayName-" + identifier; String refName = createRefName(displayName); - String typeName = "vocabType-" + identifier; - return createOrgAuthorityInstance( - displayName, refName,typeName ); - } - - private MultipartOutput createOrgAuthorityInstance( - String displayName, String refName, String vocabType) { - OrgauthoritiesCommon orgAuthority = new OrgauthoritiesCommon(); - orgAuthority.setDisplayName(displayName); - if(refName!=null) - orgAuthority.setRefName(refName); - orgAuthority.setVocabType(vocabType); - MultipartOutput multipart = new MultipartOutput(); - OutputPart commonPart = multipart.addPart(orgAuthority, MediaType.APPLICATION_XML_TYPE); - commonPart.getHeaders().add("label", client.getCommonPartName()); - - if(logger.isDebugEnabled()) { - logger.debug("to be created, orgAuthority common"); - logger.debug(objectAsXmlString(orgAuthority, OrgauthoritiesCommon.class)); - } - 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 ) { - OrganizationsCommon organization = new OrganizationsCommon(); - organization.setInAuthority(inAuthority); - organization.setShortName(shortName); - if(refName!=null) - organization.setRefName(refName); - if(longName!=null) - organization.setLongName(longName); - if(nameAdditions!=null) - organization.setNameAdditions(nameAdditions); - if(contactName!=null) - organization.setContactName(contactName); - if(foundingDate!=null) - organization.setFoundingDate(foundingDate); - if(dissolutionDate!=null) - organization.setDissolutionDate(dissolutionDate); - if(foundingPlace!=null) - organization.setFoundingPlace(foundingPlace); - if(function!=null) - organization.setFunction(function); - if(description!=null) - organization.setDescription(description); - MultipartOutput multipart = new MultipartOutput(); - OutputPart commonPart = multipart.addPart(organization, - MediaType.APPLICATION_XML_TYPE); - commonPart.getHeaders().add("label", client.getItemCommonPartName()); - - if(logger.isDebugEnabled()){ - logger.debug("to be created, organization common"); - logger.debug(objectAsXmlString(organization, - OrganizationsCommon.class)); - } - - return multipart; + return OrgAuthorityClientUtils.createOrgAuthorityInstance( + displayName, refName, + client.getCommonPartName()); } } 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 af7c71409..49d570dea 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 @@ -25,20 +25,20 @@ package org.collectionspace.services.organization.importer; import java.util.ArrayList; import java.util.Arrays; +import java.util.HashMap; import java.util.List; +import java.util.Map; -import javax.ws.rs.core.MediaType; import javax.ws.rs.core.MultivaluedMap; import javax.ws.rs.core.Response; import org.apache.log4j.BasicConfigurator; +import org.collectionspace.services.OrganizationJAXBSchema; import org.collectionspace.services.client.OrgAuthorityClient; +import org.collectionspace.services.client.OrgAuthorityClientUtils; import org.collectionspace.services.client.test.ServiceRequestType; -import org.collectionspace.services.organization.OrgauthoritiesCommon; -import org.collectionspace.services.organization.OrganizationsCommon; import org.jboss.resteasy.client.ClientResponse; import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput; -import org.jboss.resteasy.plugins.providers.multipart.OutputPart; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -59,7 +59,7 @@ public class OrgAuthorityBaseImport { final String ITEM_SERVICE_PATH_COMPONENT = "items"; public void createOrgAuthority(String orgAuthorityName, - List> orgInfo ) { + List> orgInfos ) { // Expected status code: 201 Created int EXPECTED_STATUS_CODE = Response.Status.CREATED.getStatusCode(); @@ -71,8 +71,10 @@ public class OrgAuthorityBaseImport { } String baseOrgAuthRefName = createOrgAuthRefName(orgAuthorityName); String fullOrgAuthRefName = baseOrgAuthRefName+"'"+orgAuthorityName+"'"; - MultipartOutput multipart = createOrgAuthorityInstance(orgAuthorityName, - fullOrgAuthRefName); + MultipartOutput multipart = + OrgAuthorityClientUtils.createOrgAuthorityInstance( + orgAuthorityName, fullOrgAuthRefName, + client.getCommonPartName()); ClientResponse res = client.create(multipart); int statusCode = res.getStatus(); @@ -93,30 +95,29 @@ public class OrgAuthorityBaseImport { logger.debug("Import: Created orgAuthorityulary: \"" + orgAuthorityName +"\" ID:" +newOrgAuthorityId ); } - for(List orgStrings : orgInfo){ - createItemInAuthority(newOrgAuthorityId, baseOrgAuthRefName, orgStrings); + for(Map orgInfo : orgInfos){ + createItemInAuthority(newOrgAuthorityId, + baseOrgAuthRefName, orgInfo ); } } private String createItemInAuthority(String vcsid, - String orgAuthorityRefName, List orgStrings) { + String orgAuthorityRefName, Map orgInfo) { // 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)+"'"+shortName+"'"; + String shortName = orgInfo.get(OrganizationJAXBSchema.SHORT_NAME); + String refName = createOrganizationRefName( + orgAuthorityRefName, shortName)+"'"+shortName+"'"; if(logger.isDebugEnabled()){ logger.debug("Import: Create Item: \""+shortName +"\" in orgAuthorityulary: \"" + orgAuthorityRefName +"\""); } - MultipartOutput multipart = createOrganizationInstance( vcsid, refName, - orgStrings ); + MultipartOutput multipart = + OrgAuthorityClientUtils.createOrganizationInstance( vcsid, + refName, orgInfo, client.getCommonPartName() ); ClientResponse res = client.createItem(vcsid, multipart); int statusCode = res.getStatus(); @@ -138,67 +139,6 @@ public class OrgAuthorityBaseImport { // Utility methods used by methods above // --------------------------------------------------------------- - private MultipartOutput createOrgAuthorityInstance( - String displayName, String refName ) { - OrgauthoritiesCommon orgAuthority = new OrgauthoritiesCommon(); - orgAuthority.setDisplayName(displayName); - orgAuthority.setRefName(refName); - orgAuthority.setVocabType("OrgAuthority"); - MultipartOutput multipart = new MultipartOutput(); - OutputPart commonPart = multipart.addPart(orgAuthority, MediaType.APPLICATION_XML_TYPE); - commonPart.getHeaders().add("label", client.getCommonPartName()); - - if(logger.isDebugEnabled()){ - logger.debug("to be created, orgAuthority common ", - orgAuthority, OrgauthoritiesCommon.class); - } - - return multipart; - } - - private MultipartOutput createOrganizationInstance(String inAuthority, - String orgRefName, List orgStrings){ - OrganizationsCommon organization = new OrganizationsCommon(); - 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(); - OutputPart commonPart = multipart.addPart(organization, - MediaType.APPLICATION_XML_TYPE); - commonPart.getHeaders().add("label", client.getItemCommonPartName()); - - if(logger.isDebugEnabled()){ - logger.debug("to be created, organization common ", organization, OrganizationsCommon.class); - } - - return multipart; - } - - /** * Returns an error message indicating that the status code returned by a * specific call to a service does not fall within a set of valid status @@ -248,24 +188,28 @@ public class OrgAuthorityBaseImport { OrgAuthorityBaseImport oabi = new OrgAuthorityBaseImport(); 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); + Map mmiOrgMap = new HashMap(); + mmiOrgMap.put(OrganizationJAXBSchema.SHORT_NAME, "MMI"); + mmiOrgMap.put(OrganizationJAXBSchema.LONG_NAME, "Museum of the Moving Image"); + mmiOrgMap.put(OrganizationJAXBSchema.CONTACT_NAME, "Megan Forbes"); + mmiOrgMap.put(OrganizationJAXBSchema.FOUNDING_DATE, "1984"); + mmiOrgMap.put(OrganizationJAXBSchema.FOUNDING_PLACE, "Astoria, NY"); + Map pahmaOrgMap = new HashMap(); + pahmaOrgMap.put(OrganizationJAXBSchema.SHORT_NAME, "PAHMA"); + pahmaOrgMap.put(OrganizationJAXBSchema.LONG_NAME, "Phoebe A. Hearst Museum of Anthropology"); + pahmaOrgMap.put(OrganizationJAXBSchema.NAME_ADDITIONS, "University of California, Berkeley"); + pahmaOrgMap.put(OrganizationJAXBSchema.CONTACT_NAME, "Michael Black"); + pahmaOrgMap.put(OrganizationJAXBSchema.FOUNDING_DATE, "1901"); + pahmaOrgMap.put(OrganizationJAXBSchema.FOUNDING_PLACE, "Berkeley, CA"); + Map savoyOrgMap = new HashMap(); + savoyOrgMap.put(OrganizationJAXBSchema.SHORT_NAME, "Savoy Theatre"); + savoyOrgMap.put(OrganizationJAXBSchema.FOUNDING_DATE, "1900"); + savoyOrgMap.put(OrganizationJAXBSchema.DISSOLUTION_DATE, "1952"); + savoyOrgMap.put(OrganizationJAXBSchema.FOUNDING_PLACE, "New York, NY"); + List> orgMaps = + Arrays.asList(mmiOrgMap, pahmaOrgMap, savoyOrgMap ); + + oabi.createOrgAuthority(demoOrgAuthorityName, orgMaps); logger.info("OrgAuthorityBaseImport complete."); } diff --git a/services/organization/sample/sample/src/main/java/org/collectionspace/services/organization/client/sample/Sample.java b/services/organization/sample/sample/src/main/java/org/collectionspace/services/organization/client/sample/Sample.java index c64a25eac..b5ec7e342 100644 --- a/services/organization/sample/sample/src/main/java/org/collectionspace/services/organization/client/sample/Sample.java +++ b/services/organization/sample/sample/src/main/java/org/collectionspace/services/organization/client/sample/Sample.java @@ -25,14 +25,18 @@ package org.collectionspace.services.organization.client.sample; import java.util.ArrayList; import java.util.Arrays; +import java.util.HashMap; import java.util.List; +import java.util.Map; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.MultivaluedMap; import javax.ws.rs.core.Response; import org.apache.log4j.BasicConfigurator; +import org.collectionspace.services.OrganizationJAXBSchema; import org.collectionspace.services.client.OrgAuthorityClient; +import org.collectionspace.services.client.OrgAuthorityClientUtils; import org.collectionspace.services.client.test.ServiceRequestType; import org.collectionspace.services.organization.OrgauthoritiesCommon; import org.collectionspace.services.organization.OrgauthoritiesCommonList; @@ -66,8 +70,19 @@ public class Sample { // --------------------------------------------------------------- // Create // --------------------------------------------------------------- + protected String createOrgAuthRefName(String orgAuthorityName) { + return "urn:cspace:org.collectionspace.demo:orgauthority:name(" + +orgAuthorityName+")"; + } + + protected String createOrganizationRefName( + String orgAuthRefName, String orgName) { + return orgAuthRefName+":organization:name("+orgName+")"; + } + + - public void createEnumeration(String orgAuthName, List enumValues ) { + public void createOrgAuthority(String orgAuthName, List> orgInfos ) { // Expected status code: 201 Created int EXPECTED_STATUS_CODE = Response.Status.CREATED.getStatusCode(); @@ -75,8 +90,12 @@ public class Sample { ServiceRequestType REQUEST_TYPE = ServiceRequestType.CREATE; logger.info("Import: Create orgAuthority: \"" + orgAuthName +"\""); - MultipartOutput multipart = createOrgAuthorityInstance(orgAuthName, - createRefName(orgAuthName), "enum"); + String baseOrgAuthRefName = createOrgAuthRefName(orgAuthName); + String fullOrgAuthRefName = baseOrgAuthRefName+"'"+orgAuthName+"'"; + MultipartOutput multipart = + OrgAuthorityClientUtils.createOrgAuthorityInstance( + orgAuthName, fullOrgAuthRefName, + client.getCommonPartName()); ClientResponse res = client.create(multipart); int statusCode = res.getStatus(); @@ -97,32 +116,42 @@ public class Sample { +newOrgAuthId ); // Add items to the orgAuthority - for(String itemName : enumValues){ - createItemInOrgAuth(newOrgAuthId, orgAuthName, itemName, createRefName(itemName)); + for(Map orgInfo : orgInfos){ + createItemInOrgAuth(newOrgAuthId, baseOrgAuthRefName, orgInfo); } } - private String createItemInOrgAuth(String vcsid, String orgAuthName, String itemName, String refName) { + private String createItemInOrgAuth(String vcsid, + String orgAuthorityRefName, Map orgInfo) { // Expected status code: 201 Created int EXPECTED_STATUS_CODE = Response.Status.CREATED.getStatusCode(); // Type of service request being tested ServiceRequestType REQUEST_TYPE = ServiceRequestType.CREATE; + String shortName = orgInfo.get(OrganizationJAXBSchema.SHORT_NAME); + String refName = createOrganizationRefName( + orgAuthorityRefName, shortName)+"'"+shortName+"'"; + + + logger.info("Import: Create Item: \""+shortName+ + "\" in orgAuthority: \"" + orgAuthorityRefName +"\""); + MultipartOutput multipart = + OrgAuthorityClientUtils.createOrganizationInstance( vcsid, + refName, orgInfo, client.getCommonPartName() ); - logger.info("Import: Create Item: \""+itemName+"\" in orgAuthority: \"" + orgAuthName +"\""); - MultipartOutput multipart = createOrganizationInstance(vcsid, itemName, refName); 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: \"" + orgAuthName + 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: \"" + orgAuthName +"\", Status:"+ statusCode); + throw new RuntimeException("Unexpected Status when creating Item: \""+shortName + +"\" in orgAuthority: \"" + orgAuthorityRefName + + "\", Status:"+ statusCode); } return extractId(res); @@ -295,40 +324,6 @@ public class Sample { // Utility methods used by tests above // --------------------------------------------------------------- - private MultipartOutput createOrgAuthorityInstance( - String displayName, String refName, String vocabType) { - OrgauthoritiesCommon orgAuthority = new OrgauthoritiesCommon(); - orgAuthority.setDisplayName(displayName); - orgAuthority.setRefName(refName); - orgAuthority.setVocabType(vocabType); - MultipartOutput multipart = new MultipartOutput(); - OutputPart commonPart = multipart.addPart(orgAuthority, MediaType.APPLICATION_XML_TYPE); - commonPart.getHeaders().add("label", client.getCommonPartName()); - - if(logger.isDebugEnabled()){ - logger.debug("to be created, orgAuthority common ", - orgAuthority, OrgauthoritiesCommon.class); - } - - return multipart; - } - - private MultipartOutput createOrganizationInstance( - String inAuthority, String displayName, String refName) { - OrganizationsCommon organization = new OrganizationsCommon(); - organization.setInAuthority(inAuthority); - organization.setShortName(displayName); - organization.setRefName(refName); - MultipartOutput multipart = new MultipartOutput(); - OutputPart commonPart = multipart.addPart(organization, MediaType.APPLICATION_XML_TYPE); - commonPart.getHeaders().add("label", client.getItemCommonPartName()); - - if(logger.isDebugEnabled()){ - logger.debug("to be created, organization common ", organization, OrganizationsCommon.class); - } - - return multipart; - } // Retrieve individual fields of orgAuthority records. @@ -441,7 +436,7 @@ public class Sample { logger.info("OrgAuthority Sample starting..."); - Sample vbi = new Sample(); + Sample sample = new Sample(); OrgauthoritiesCommonList orgAuthorities; List orgAuthIds; String details = ""; @@ -454,61 +449,59 @@ public class Sample { logger.info("Deleting all organizations and orgAuthorities ..."); // For each orgAuthority ... - orgAuthorities = vbi.readOrgAuthorities(); - orgAuthIds = vbi.readOrgAuthorityIds(orgAuthorities); + orgAuthorities = sample.readOrgAuthorities(); + orgAuthIds = sample.readOrgAuthorityIds(orgAuthorities); for (String orgAuthId : orgAuthIds) { logger.info("Deleting all organizations for orgAuthority ..."); - vbi.deleteAllItemsForOrgAuth(orgAuthId); + sample.deleteAllItemsForOrgAuth(orgAuthId); logger.info("Deleting orgAuthority ..."); - vbi.deleteOrgAuthority(orgAuthId); + sample.deleteOrgAuthority(orgAuthId); } logger.info("Reading orgAuthorities after deletion ..."); - orgAuthorities = vbi.readOrgAuthorities(); - details = vbi.displayAllOrgAuthorities(orgAuthorities); + orgAuthorities = sample.readOrgAuthorities(); + details = sample.displayAllOrgAuthorities(orgAuthorities); logger.info(details); logger.info("Reading items in each orgAuthority after deletion ..."); - orgAuthIds = vbi.readOrgAuthorityIds(orgAuthorities); + orgAuthIds = sample.readOrgAuthorityIds(orgAuthorities); for (String orgAuthId : orgAuthIds) { - OrganizationsCommonList items = vbi.readItemsInOrgAuth(orgAuthId); - details = vbi.displayAllOrganizations(items); + OrganizationsCommonList items = sample.readItemsInOrgAuth(orgAuthId); + details = sample.displayAllOrganizations(items); logger.info(details); } } // Create new authorities, each populated with organizations. - - /* - final String acquisitionMethodsVocabName = "Acquisition Methods"; - final String entryMethodsVocabName = "Entry Methods"; - final String entryReasonsVocabName = "Entry Reasons"; - final String responsibleDeptsVocabName = "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"); + Map mmiOrgMap = new HashMap(); + mmiOrgMap.put(OrganizationJAXBSchema.SHORT_NAME, "MMI"); + mmiOrgMap.put(OrganizationJAXBSchema.LONG_NAME, "Museum of the Moving Image"); + mmiOrgMap.put(OrganizationJAXBSchema.CONTACT_NAME, "Megan Forbes"); + mmiOrgMap.put(OrganizationJAXBSchema.FOUNDING_DATE, "1984"); + mmiOrgMap.put(OrganizationJAXBSchema.FOUNDING_PLACE, "Astoria, NY"); + Map pahmaOrgMap = new HashMap(); + pahmaOrgMap.put(OrganizationJAXBSchema.SHORT_NAME, "PAHMA"); + pahmaOrgMap.put(OrganizationJAXBSchema.LONG_NAME, "Phoebe A. Hearst Museum of Anthropology"); + pahmaOrgMap.put(OrganizationJAXBSchema.NAME_ADDITIONS, "University of California, Berkeley"); + pahmaOrgMap.put(OrganizationJAXBSchema.CONTACT_NAME, "Michael Black"); + pahmaOrgMap.put(OrganizationJAXBSchema.FOUNDING_DATE, "1901"); + pahmaOrgMap.put(OrganizationJAXBSchema.FOUNDING_PLACE, "Berkeley, CA"); + Map savoyOrgMap = new HashMap(); + savoyOrgMap.put(OrganizationJAXBSchema.SHORT_NAME, "Savoy Theatre"); + savoyOrgMap.put(OrganizationJAXBSchema.FOUNDING_DATE, "1900"); + savoyOrgMap.put(OrganizationJAXBSchema.DISSOLUTION_DATE, "1952"); + savoyOrgMap.put(OrganizationJAXBSchema.FOUNDING_PLACE, "New York, NY"); + List> orgMaps = + Arrays.asList(mmiOrgMap, pahmaOrgMap, savoyOrgMap ); - vbi.createEnumeration(acquisitionMethodsVocabName, acquisitionMethodsEnumValues); - vbi.createEnumeration(entryMethodsVocabName, entryMethodsEnumValues); - vbi.createEnumeration(entryReasonsVocabName, entryReasonsEnumValues); - vbi.createEnumeration(responsibleDeptsVocabName, respDeptNamesEnumValues); - */ + sample.createOrgAuthority("Sample Org Authority", orgMaps); logger.info("OrgAuthority Sample complete."); logger.info("Reading orgAuthorities and items ..."); // Get a list of orgAuthorities. - orgAuthorities = vbi.readOrgAuthorities(); + orgAuthorities = sample.readOrgAuthorities(); // For each orgAuthority ... for (OrgauthoritiesCommonList.OrgauthorityListItem orgAuthority : orgAuthorities.getOrgauthorityListItem()) { @@ -516,7 +509,7 @@ public class Sample { logger.info(orgAuthority.getDisplayName()); // Get a list of the organizations in this orgAuthority. OrganizationsCommonList items = - vbi.readItemsInOrgAuth(orgAuthority.getCsid()); + sample.readItemsInOrgAuth(orgAuthority.getCsid()); // For each organization ... for (OrganizationsCommonList.OrganizationListItem item : items.getOrganizationListItem()) { @@ -531,14 +524,14 @@ public class Sample { if (RUN_ADDITIONAL_SAMPLES) { logger.info("Reading all orgAuthorities ..."); - details = vbi.displayAllOrgAuthorities(orgAuthorities); + details = sample.displayAllOrgAuthorities(orgAuthorities); logger.info(details); logger.info("Reading all organizations ..."); - orgAuthIds = vbi.readOrgAuthorityIds(orgAuthorities); + orgAuthIds = sample.readOrgAuthorityIds(orgAuthorities); for (String orgAuthId : orgAuthIds) { - OrganizationsCommonList items = vbi.readItemsInOrgAuth(orgAuthId); - details = vbi.displayAllOrganizations(items); + OrganizationsCommonList items = sample.readItemsInOrgAuth(orgAuthId); + details = sample.displayAllOrganizations(items); logger.info(details); } -- 2.47.3