--- /dev/null
+/**\r
+ * This document is a part of the source code and related artifacts\r
+ * for CollectionSpace, an open source collections management system\r
+ * for museums and related institutions:\r
+ *\r
+ * http://www.collectionspace.org\r
+ * http://wiki.collectionspace.org\r
+ *\r
+ * Copyright (c)) 2009 Regents of the University of California\r
+ *\r
+ * Licensed under the Educational Community License (ECL), Version 2.0.\r
+ * You may not use this file except in compliance with this License.\r
+ *\r
+ * You may obtain a copy of the ECL 2.0 License at\r
+ * https://source.collectionspace.org/collection-space/LICENSE.txt\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+\r
+package org.collectionspace.services.person.client.sample;\r
+\r
+import java.util.ArrayList;\r
+import java.util.Arrays;\r
+import java.util.HashMap;\r
+import java.util.List;\r
+import java.util.Map;\r
+\r
+import javax.ws.rs.core.MediaType;\r
+import javax.ws.rs.core.MultivaluedMap;\r
+import javax.ws.rs.core.Response;\r
+\r
+import org.apache.log4j.BasicConfigurator;\r
+import org.collectionspace.services.PersonJAXBSchema;\r
+import org.collectionspace.services.client.PersonAuthorityClient;\r
+import org.collectionspace.services.client.PersonAuthorityClientUtils;\r
+import org.collectionspace.services.client.test.ServiceRequestType;\r
+import org.collectionspace.services.person.PersonauthoritiesCommon;\r
+import org.collectionspace.services.person.PersonauthoritiesCommonList;\r
+import org.collectionspace.services.person.PersonsCommon;\r
+import org.collectionspace.services.person.PersonsCommonList;\r
+import org.jboss.resteasy.client.ClientResponse;\r
+import org.jboss.resteasy.plugins.providers.multipart.MultipartInput;\r
+import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput;\r
+import org.jboss.resteasy.plugins.providers.multipart.InputPart;\r
+import org.jboss.resteasy.plugins.providers.multipart.OutputPart;\r
+import org.slf4j.Logger;\r
+import org.slf4j.LoggerFactory;\r
+\r
+/**\r
+ * PersonAuthority Sample, carries out tests against a\r
+ * deployed and running PersonAuthority Service.\r
+ *\r
+ * $LastChangedRevision: 1055 $\r
+ * $LastChangedDate: 2009-12-09 12:25:15 -0800 (Wed, 09 Dec 2009) $\r
+ */\r
+public class Sample {\r
+ private static final Logger logger =\r
+ LoggerFactory.getLogger(Sample.class);\r
+\r
+ // Instance variables specific to this test.\r
+ private PersonAuthorityClient client = new PersonAuthorityClient();\r
+ final String SERVICE_PATH_COMPONENT = "persons";\r
+ final String ITEM_SERVICE_PATH_COMPONENT = "items";\r
+\r
+\r
+ // ---------------------------------------------------------------\r
+ // Create\r
+ // ---------------------------------------------------------------\r
+\r
+ public void createPersonAuthority(String personAuthorityName, \r
+ List<Map<String, String>> personMaps ) {\r
+\r
+ // Expected status code: 201 Created\r
+ int EXPECTED_STATUS_CODE = Response.Status.CREATED.getStatusCode();\r
+ // Type of service request being tested\r
+ ServiceRequestType REQUEST_TYPE = ServiceRequestType.CREATE;\r
+\r
+ logger.info("Import: Create personAuthority: \"" + personAuthorityName +"\"");\r
+ String basePersonRefName = PersonAuthorityClientUtils.createPersonAuthRefName(personAuthorityName);\r
+ String fullPersonRefName = basePersonRefName+"'"+personAuthorityName+"'";\r
+ MultipartOutput multipart = \r
+ PersonAuthorityClientUtils.createPersonAuthorityInstance(\r
+ personAuthorityName, fullPersonRefName, client.getCommonPartName() );\r
+ ClientResponse<Response> res = client.create(multipart);\r
+\r
+ int statusCode = res.getStatus();\r
+\r
+ if(!REQUEST_TYPE.isValidStatusCode(statusCode)) {\r
+ throw new RuntimeException("Could not create enumeration: \""+personAuthorityName\r
+ +"\" "+ PersonAuthorityClientUtils.invalidStatusCodeMessage(REQUEST_TYPE, statusCode));\r
+ }\r
+ if(statusCode != EXPECTED_STATUS_CODE) {\r
+ throw new RuntimeException("Unexpected Status when creating enumeration: \""\r
+ +personAuthorityName +"\", Status:"+ statusCode);\r
+ }\r
+\r
+ // Store the ID returned from this create operation\r
+ // for additional tests below.\r
+ String newPersonAuthId = PersonAuthorityClientUtils.extractId(res);\r
+ logger.info("Import: Created personAuthority: \"" + personAuthorityName +"\" ID:"\r
+ +newPersonAuthId );\r
+ \r
+ // Add items to the personAuthority\r
+ for(Map<String,String> personMap : personMaps){\r
+ createItemInAuthority(newPersonAuthId, basePersonRefName, personMap);\r
+ }\r
+ \r
+ }\r
+ \r
+ private String createItemInAuthority(String vcsid, \r
+ String personAuthorityRefName, Map<String,String> personMap) {\r
+ // Expected status code: 201 Created\r
+ int EXPECTED_STATUS_CODE = Response.Status.CREATED.getStatusCode();\r
+ // Type of service request being tested\r
+ ServiceRequestType REQUEST_TYPE = ServiceRequestType.CREATE;\r
+ String foreName = personMap.get(PersonJAXBSchema.FORE_NAME);\r
+ String middleName = personMap.get(PersonJAXBSchema.MIDDLE_NAME);\r
+ String surName = personMap.get(PersonJAXBSchema.SUR_NAME);\r
+ String birthDate = personMap.get(PersonJAXBSchema.BIRTH_DATE);\r
+ String deathDate = personMap.get(PersonJAXBSchema.DEATH_DATE);\r
+ StringBuilder builtName = new StringBuilder();\r
+ if(foreName!=null)\r
+ builtName.append(foreName);\r
+ if(middleName!=null)\r
+ builtName.append(middleName);\r
+ if(surName!=null)\r
+ builtName.append(surName);\r
+ if(birthDate!=null)\r
+ builtName.append(birthDate);\r
+ builtName.append("-");\r
+ if(deathDate!=null)\r
+ builtName.append(deathDate);\r
+ String refName = PersonAuthorityClientUtils.createPersonRefName(personAuthorityRefName, builtName.toString());\r
+ logger.info("Import: Create Item: \""+refName+"\" in personAuthority: \"" + personAuthorityRefName +"\"");\r
+\r
+ if(logger.isDebugEnabled()){\r
+ logger.debug("Import: Create Item: \""+builtName.toString()\r
+ +"\" in personAuthorityulary: \"" + personAuthorityRefName +"\"");\r
+ }\r
+ MultipartOutput multipart = createPersonInstance( vcsid, refName,\r
+ personMap );\r
+ ClientResponse<Response> res = client.createItem(vcsid, multipart);\r
+\r
+ int statusCode = res.getStatus();\r
+\r
+ if(!REQUEST_TYPE.isValidStatusCode(statusCode)) {\r
+ throw new RuntimeException("Could not create Item: \""+refName\r
+ +"\" in personAuthority: \"" + personAuthorityRefName\r
+ +"\" "+ PersonAuthorityClientUtils.invalidStatusCodeMessage(REQUEST_TYPE, statusCode));\r
+ }\r
+ if(statusCode != EXPECTED_STATUS_CODE) {\r
+ throw new RuntimeException("Unexpected Status when creating Item: \""+refName\r
+ +"\" in personAuthority: \"" + personAuthorityRefName +"\", Status:"+ statusCode);\r
+ }\r
+\r
+ return PersonAuthorityClientUtils.extractId(res);\r
+ }\r
+\r
+\r
+ // ---------------------------------------------------------------\r
+ // Read\r
+ // ---------------------------------------------------------------\r
+\r
+ private PersonauthoritiesCommonList readPersonAuthorities() {\r
+\r
+ // Expected status code: 200 OK\r
+ int EXPECTED_STATUS_CODE = Response.Status.OK.getStatusCode();\r
+ // Type of service request being tested\r
+ ServiceRequestType REQUEST_TYPE = ServiceRequestType.READ;\r
+\r
+ // Submit the request to the service and store the response.\r
+ ClientResponse<PersonauthoritiesCommonList> res = client.readList();\r
+ PersonauthoritiesCommonList list = res.getEntity();\r
+\r
+ int statusCode = res.getStatus();\r
+ if(!REQUEST_TYPE.isValidStatusCode(statusCode)) {\r
+ throw new RuntimeException("Could not read list of personAuthorities: "\r
+ + PersonAuthorityClientUtils.invalidStatusCodeMessage(REQUEST_TYPE, statusCode));\r
+ }\r
+ if(statusCode != EXPECTED_STATUS_CODE) {\r
+ throw new RuntimeException("Unexpected Status when reading " +\r
+ "list of personAuthorities, Status:"+ statusCode);\r
+ }\r
+\r
+ return list;\r
+ }\r
+\r
+ private List<String> readPersonAuthorityIds(PersonauthoritiesCommonList list) {\r
+\r
+ List<String> ids = new ArrayList<String>();\r
+ List<PersonauthoritiesCommonList.PersonauthorityListItem> personAuthorities =\r
+ list.getPersonauthorityListItem();\r
+ for (PersonauthoritiesCommonList.PersonauthorityListItem personAuthority : personAuthorities) {\r
+ ids.add(personAuthority.getCsid());\r
+ }\r
+ return ids;\r
+ }\r
+ \r
+ private PersonauthoritiesCommon readPersonAuthority(String personAuthId) {\r
+\r
+ // Expected status code: 200 OK\r
+ int EXPECTED_STATUS_CODE = Response.Status.OK.getStatusCode();\r
+ // Type of service request being tested\r
+ ServiceRequestType REQUEST_TYPE = ServiceRequestType.READ;\r
+\r
+ // Submit the request to the service and store the response.\r
+ PersonauthoritiesCommon personAuthority = null;\r
+ try {\r
+ ClientResponse<MultipartInput> res = client.read(personAuthId);\r
+ int statusCode = res.getStatus();\r
+ if(!REQUEST_TYPE.isValidStatusCode(statusCode)) {\r
+ throw new RuntimeException("Could not read personAuthority"\r
+ + PersonAuthorityClientUtils.invalidStatusCodeMessage(REQUEST_TYPE, statusCode));\r
+ }\r
+ if(statusCode != EXPECTED_STATUS_CODE) {\r
+ throw new RuntimeException("Unexpected Status when reading " +\r
+ "personAuthority, Status:"+ statusCode);\r
+ }\r
+ MultipartInput input = (MultipartInput) res.getEntity();\r
+ personAuthority = (PersonauthoritiesCommon) extractPart(input,\r
+ client.getCommonPartName(), PersonauthoritiesCommon.class);\r
+ } catch (Exception e) {\r
+ throw new RuntimeException("Could not read personAuthority: ", e);\r
+ }\r
+\r
+ return personAuthority;\r
+ }\r
+\r
+ private PersonsCommonList readItemsInPersonAuth(String personAuthId) {\r
+\r
+ // Expected status code: 200 OK\r
+ int EXPECTED_STATUS_CODE = Response.Status.OK.getStatusCode();\r
+ // Type of service request being tested\r
+ ServiceRequestType REQUEST_TYPE = ServiceRequestType.READ;\r
+\r
+ // Submit the request to the service and store the response.\r
+ ClientResponse<PersonsCommonList> res =\r
+ client.readItemList(personAuthId);\r
+ PersonsCommonList list = res.getEntity();\r
+\r
+ int statusCode = res.getStatus();\r
+\r
+ if(!REQUEST_TYPE.isValidStatusCode(statusCode)) {\r
+ throw new RuntimeException("Could not read items in personAuthority: "\r
+ + PersonAuthorityClientUtils.invalidStatusCodeMessage(REQUEST_TYPE, statusCode));\r
+ }\r
+ if(statusCode != EXPECTED_STATUS_CODE) {\r
+ throw new RuntimeException("Unexpected Status when reading " +\r
+ "items in personAuthority, Status:"+ statusCode);\r
+ }\r
+\r
+ return list;\r
+ }\r
+\r
+ private List<String> readPersonIds(PersonsCommonList list) {\r
+\r
+ List<String> ids = new ArrayList<String>();\r
+ List<PersonsCommonList.PersonListItem> items =\r
+ list.getPersonListItem();\r
+ for (PersonsCommonList.PersonListItem item : items) {\r
+ ids.add(item.getCsid());\r
+ }\r
+ return ids;\r
+ }\r
+\r
+ // ---------------------------------------------------------------\r
+ // Delete\r
+ // ---------------------------------------------------------------\r
+\r
+ private void deletePersonAuthority(String vcsid) {\r
+ // Expected status code: 200 OK\r
+ int EXPECTED_STATUS_CODE = Response.Status.OK.getStatusCode();\r
+ // Type of service request being tested\r
+ ServiceRequestType REQUEST_TYPE = ServiceRequestType.DELETE;\r
+\r
+ ClientResponse<Response> res = client.delete(vcsid);\r
+ int statusCode = res.getStatus();\r
+\r
+ if(!REQUEST_TYPE.isValidStatusCode(statusCode)) {\r
+ throw new RuntimeException("Could not delete personAuthority: "\r
+ + PersonAuthorityClientUtils.invalidStatusCodeMessage(REQUEST_TYPE, statusCode));\r
+ }\r
+ if(statusCode != EXPECTED_STATUS_CODE) {\r
+ throw new RuntimeException("Unexpected Status when deleting " +\r
+ "personAuthority, Status:"+ statusCode);\r
+ }\r
+ }\r
+\r
+ private void deleteAllPersonAuthorities() {\r
+ List<String> ids = readPersonAuthorityIds(readPersonAuthorities());\r
+ for (String id : ids) {\r
+ deletePersonAuthority(id);\r
+ }\r
+ }\r
+\r
+ private void deletePerson(String vcsid, String itemcsid) {\r
+ // Expected status code: 200 OK\r
+ int EXPECTED_STATUS_CODE = Response.Status.OK.getStatusCode();\r
+ // Type of service request being tested\r
+ ServiceRequestType REQUEST_TYPE = ServiceRequestType.DELETE;\r
+\r
+ ClientResponse<Response> res = client.deleteItem(vcsid, itemcsid);\r
+ int statusCode = res.getStatus();\r
+\r
+ if(!REQUEST_TYPE.isValidStatusCode(statusCode)) {\r
+ throw new RuntimeException("Could not delete personAuthority item: "\r
+ + PersonAuthorityClientUtils.invalidStatusCodeMessage(REQUEST_TYPE, statusCode));\r
+ }\r
+ if(statusCode != EXPECTED_STATUS_CODE) {\r
+ throw new RuntimeException("Unexpected Status when deleting " +\r
+ "personAuthority item, Status:"+ statusCode);\r
+ }\r
+ }\r
+\r
+ private void deleteAllItemsForPersonAuth(String personAuthId) {\r
+ List<String> itemIds = readPersonIds(readItemsInPersonAuth(personAuthId));\r
+ for (String itemId : itemIds) {\r
+ deletePerson(personAuthId, itemId);\r
+ }\r
+ }\r
+\r
+ // ---------------------------------------------------------------\r
+ // Utility methods used by tests above\r
+ // ---------------------------------------------------------------\r
+\r
+ /*\r
+ private MultipartOutput createPersonAuthorityInstance(\r
+ String displayName, String refName ) {\r
+ PersonauthoritiesCommon personAuthority = new PersonauthoritiesCommon();\r
+ personAuthority.setDisplayName(displayName);\r
+ personAuthority.setRefName(refName);\r
+ personAuthority.setVocabType("PersonAuthority");\r
+ MultipartOutput multipart = new MultipartOutput();\r
+ OutputPart commonPart = multipart.addPart(personAuthority, MediaType.APPLICATION_XML_TYPE);\r
+ commonPart.getHeaders().add("label", client.getCommonPartName());\r
+\r
+ if(logger.isDebugEnabled()){\r
+ logger.debug("to be created, personAuthority common ",\r
+ personAuthority, PersonauthoritiesCommon.class);\r
+ }\r
+\r
+ return multipart;\r
+ }\r
+ */\r
+\r
+ private MultipartOutput createPersonInstance(String inAuthority, \r
+ String refName, Map<String, String> personInfo ) {\r
+ PersonsCommon person = new PersonsCommon();\r
+ person.setInAuthority(inAuthority);\r
+ person.setRefName(refName);\r
+ String value = null;\r
+ if((value = (String)personInfo.get(PersonJAXBSchema.FORE_NAME))!=null)\r
+ person.setForeName(value);\r
+ if((value = (String)personInfo.get(PersonJAXBSchema.MIDDLE_NAME))!=null)\r
+ person.setMiddleName(value);\r
+ if((value = (String)personInfo.get(PersonJAXBSchema.SUR_NAME))!=null)\r
+ person.setSurName(value);\r
+ if((value = (String)personInfo.get(PersonJAXBSchema.INITIALS))!=null)\r
+ person.setInitials(value);\r
+ if((value = (String)personInfo.get(PersonJAXBSchema.SALUTATIONS))!=null)\r
+ person.setSalutation(value);\r
+ if((value = (String)personInfo.get(PersonJAXBSchema.TITLE))!=null)\r
+ person.setTitle(value);\r
+ if((value = (String)personInfo.get(PersonJAXBSchema.NAME_ADDITIONS))!=null)\r
+ person.setNameAdditions(value);\r
+ if((value = (String)personInfo.get(PersonJAXBSchema.BIRTH_DATE))!=null)\r
+ person.setBirthDate(value);\r
+ if((value = (String)personInfo.get(PersonJAXBSchema.DEATH_DATE))!=null)\r
+ person.setDeathDate(value);\r
+ if((value = (String)personInfo.get(PersonJAXBSchema.BIRTH_PLACE))!=null)\r
+ person.setBirthPlace(value);\r
+ if((value = (String)personInfo.get(PersonJAXBSchema.DEATH_PLACE))!=null)\r
+ person.setDeathPlace(value);\r
+ if((value = (String)personInfo.get(PersonJAXBSchema.GROUP))!=null)\r
+ person.setGroup(value);\r
+ if((value = (String)personInfo.get(PersonJAXBSchema.NATIONALITY))!=null)\r
+ person.setNationality(value);\r
+ if((value = (String)personInfo.get(PersonJAXBSchema.GENDER))!=null)\r
+ person.setGender(value);\r
+ if((value = (String)personInfo.get(PersonJAXBSchema.OCCUPATION))!=null)\r
+ person.setOccupation(value);\r
+ if((value = (String)personInfo.get(PersonJAXBSchema.SCHOOL_OR_STYLE))!=null)\r
+ person.setSchoolOrStyle(value);\r
+ if((value = (String)personInfo.get(PersonJAXBSchema.BIO_NOTE))!=null)\r
+ person.setBioNote(value);\r
+ if((value = (String)personInfo.get(PersonJAXBSchema.NAME_NOTE))!=null)\r
+ person.setNameNote(value);\r
+ MultipartOutput multipart = new MultipartOutput();\r
+ OutputPart commonPart = multipart.addPart(person,\r
+ MediaType.APPLICATION_XML_TYPE);\r
+ commonPart.getHeaders().add("label", client.getItemCommonPartName());\r
+\r
+ if(logger.isDebugEnabled()){\r
+ logger.debug("to be created, person common"+person);\r
+ }\r
+\r
+ return multipart;\r
+ }\r
+\r
+ // Retrieve individual fields of personAuthority records.\r
+\r
+ private String displayAllPersonAuthorities(PersonauthoritiesCommonList list) {\r
+ StringBuffer sb = new StringBuffer();\r
+ List<PersonauthoritiesCommonList.PersonauthorityListItem> personAuthorities =\r
+ list.getPersonauthorityListItem();\r
+ int i = 0;\r
+ for (PersonauthoritiesCommonList.PersonauthorityListItem personAuthority : personAuthorities) {\r
+ sb.append("personAuthority [" + i + "]" + "\n");\r
+ sb.append(displayPersonAuthorityDetails(personAuthority));\r
+ i++;\r
+ }\r
+ return sb.toString();\r
+ }\r
+\r
+ private String displayPersonAuthorityDetails(\r
+ PersonauthoritiesCommonList.PersonauthorityListItem personAuthority) {\r
+ StringBuffer sb = new StringBuffer();\r
+ sb.append("displayName=" + personAuthority.getDisplayName() + "\n");\r
+ sb.append("vocabType=" + personAuthority.getVocabType() + "\n");\r
+ // sb.append("csid=" + personAuthority.getCsid() + "\n");\r
+ sb.append("URI=" + personAuthority.getUri() + "\n");\r
+ return sb.toString();\r
+ }\r
+\r
+ // Retrieve individual fields of person records.\r
+\r
+ private String displayAllPersons(PersonsCommonList list) {\r
+ StringBuffer sb = new StringBuffer();\r
+ List<PersonsCommonList.PersonListItem> items =\r
+ list.getPersonListItem();\r
+ int i = 0;\r
+ for (PersonsCommonList.PersonListItem item : items) {\r
+ sb.append("person [" + i + "]" + "\n");\r
+ sb.append(displayPersonDetails(item));\r
+ i++;\r
+ }\r
+ return sb.toString();\r
+ }\r
+\r
+ private String displayPersonDetails(\r
+ PersonsCommonList.PersonListItem item) {\r
+ StringBuffer sb = new StringBuffer();\r
+ sb.append("csid=" + item.getCsid() + "\n");\r
+ sb.append("displayName=" + item.getDisplayName() + "\n");\r
+ // sb.append("URI=" + item.getUri() + "\n");\r
+ return sb.toString();\r
+ }\r
+\r
+ private Object extractPart(MultipartInput input, String label,\r
+ Class clazz) throws Exception {\r
+ Object obj = null;\r
+ for(InputPart part : input.getParts()){\r
+ String partLabel = part.getHeaders().getFirst("label");\r
+ if(label.equalsIgnoreCase(partLabel)){\r
+ String partStr = part.getBodyAsString();\r
+ if(logger.isDebugEnabled()){\r
+ logger.debug("extracted part str=\n" + partStr);\r
+ }\r
+ obj = part.getBody(clazz, null);\r
+ if(logger.isDebugEnabled()){\r
+ logger.debug("extracted part obj=\n", obj, clazz);\r
+ }\r
+ break;\r
+ }\r
+ }\r
+ return obj;\r
+ }\r
+\r
+ /**\r
+ * Returns an error message indicating that the status code returned by a\r
+ * specific call to a service does not fall within a set of valid status\r
+ * codes for that service.\r
+ *\r
+ * @param serviceRequestType A type of service request (e.g. CREATE, DELETE).\r
+ *\r
+ * @param statusCode The invalid status code that was returned in the response,\r
+ * from submitting that type of request to the service.\r
+ *\r
+ * @return An error message.\r
+ */\r
+ /*\r
+ protected String invalidStatusCodeMessage(ServiceRequestType requestType, int statusCode) {\r
+ return "Status code '" + statusCode + "' in response is NOT within the expected set: " +\r
+ requestType.validStatusCodesAsString();\r
+ }\r
+\r
+ protected String extractId(ClientResponse<Response> res) {\r
+ MultivaluedMap<String, Object> mvm = res.getMetadata();\r
+ String uri = (String) ((ArrayList<Object>) mvm.get("Location")).get(0);\r
+ if(logger.isDebugEnabled()){\r
+ logger.info("extractId:uri=" + uri);\r
+ }\r
+ String[] segments = uri.split("/");\r
+ String id = segments[segments.length - 1];\r
+ if(logger.isDebugEnabled()){\r
+ logger.debug("id=" + id);\r
+ }\r
+ return id;\r
+ }\r
+ \r
+ protected String createPersonAuthRefName(String personAuthorityName) {\r
+ return "urn:cspace:org.collectionspace.demo:personauthority:name("\r
+ +personAuthorityName+")";\r
+ }\r
+\r
+ protected String createPersonRefName(\r
+ String personAuthRefName, String personName) {\r
+ return personAuthRefName+":person:name("+personName+")";\r
+ }\r
+ */\r
+\r
+ public static void main(String[] args) {\r
+\r
+ // Configure logging.\r
+ BasicConfigurator.configure();\r
+\r
+ logger.info("PersonAuthority Sample starting...");\r
+\r
+ Sample sample = new Sample();\r
+ PersonauthoritiesCommonList personAuthorities;\r
+ List<String> personAuthIds;\r
+ String details = "";\r
+\r
+ // Optionally delete all personAuthorities and persons.\r
+\r
+ boolean ENABLE_DELETE_ALL = false;\r
+ if (ENABLE_DELETE_ALL) {\r
+\r
+ logger.info("Deleting all persons and personAuthorities ...");\r
+\r
+ // For each personAuthority ...\r
+ personAuthorities = sample.readPersonAuthorities();\r
+ personAuthIds = sample.readPersonAuthorityIds(personAuthorities);\r
+ for (String personAuthId : personAuthIds) {\r
+ logger.info("Deleting all persons for personAuthority ...");\r
+ sample.deleteAllItemsForPersonAuth(personAuthId);\r
+ logger.info("Deleting personAuthority ...");\r
+ sample.deletePersonAuthority(personAuthId);\r
+ }\r
+\r
+ logger.info("Reading personAuthorities after deletion ...");\r
+ personAuthorities = sample.readPersonAuthorities();\r
+ details = sample.displayAllPersonAuthorities(personAuthorities);\r
+ logger.info(details);\r
+\r
+ logger.info("Reading items in each personAuthority after deletion ...");\r
+ personAuthIds = sample.readPersonAuthorityIds(personAuthorities);\r
+ for (String personAuthId : personAuthIds) {\r
+ PersonsCommonList items = sample.readItemsInPersonAuth(personAuthId);\r
+ details = sample.displayAllPersons(items);\r
+ logger.info(details);\r
+ }\r
+\r
+ }\r
+\r
+ // Create new authorities, each populated with persons.\r
+\r
+ Map<String, String> johnWayneMap = new HashMap<String,String>();\r
+ johnWayneMap.put(PersonJAXBSchema.FORE_NAME, "John");\r
+ johnWayneMap.put(PersonJAXBSchema.SUR_NAME, "Wayne");\r
+ johnWayneMap.put(PersonJAXBSchema.GENDER, "male");\r
+ Map<String, String> patrickSchmitzMap = new HashMap<String,String>();\r
+ patrickSchmitzMap.put(PersonJAXBSchema.FORE_NAME, "Patrick");\r
+ patrickSchmitzMap.put(PersonJAXBSchema.SUR_NAME, "Schmitz");\r
+ patrickSchmitzMap.put(PersonJAXBSchema.GENDER, "male");\r
+ Map<String, String> janeDoeMap = new HashMap<String,String>();\r
+ janeDoeMap.put(PersonJAXBSchema.FORE_NAME, "Jane");\r
+ janeDoeMap.put(PersonJAXBSchema.SUR_NAME, "Doe");\r
+ janeDoeMap.put(PersonJAXBSchema.GENDER, "female");\r
+ List<Map<String, String>> personsMaps = \r
+ Arrays.asList(johnWayneMap, patrickSchmitzMap, janeDoeMap );\r
+ \r
+ sample.createPersonAuthority("Sample Person Auth", personsMaps);\r
+\r
+ logger.info("PersonAuthority Sample complete.");\r
+\r
+ logger.info("Reading personAuthorities and items ...");\r
+ // Get a list of personAuthorities.\r
+ personAuthorities = sample.readPersonAuthorities();\r
+ // For each personAuthority ...\r
+ for (PersonauthoritiesCommonList.PersonauthorityListItem\r
+ personAuthority : personAuthorities.getPersonauthorityListItem()) {\r
+ // Get its display name.\r
+ logger.info(personAuthority.getDisplayName());\r
+ // Get a list of the persons in this personAuthority.\r
+ PersonsCommonList items =\r
+ sample.readItemsInPersonAuth(personAuthority.getCsid());\r
+ // For each person ...\r
+ for (PersonsCommonList.PersonListItem\r
+ item : items.getPersonListItem()) {\r
+ // Get its short name.\r
+ logger.info(" " + item.getDisplayName());\r
+ }\r
+ }\r
+\r
+ // Sample alternate methods of reading all personAuthorities and\r
+ // persons separately.\r
+ boolean RUN_ADDITIONAL_SAMPLES = false;\r
+ if (RUN_ADDITIONAL_SAMPLES) {\r
+\r
+ logger.info("Reading all personAuthorities ...");\r
+ details = sample.displayAllPersonAuthorities(personAuthorities);\r
+ logger.info(details);\r
+\r
+ logger.info("Reading all persons ...");\r
+ personAuthIds = sample.readPersonAuthorityIds(personAuthorities);\r
+ for (String personAuthId : personAuthIds) {\r
+ PersonsCommonList items = sample.readItemsInPersonAuth(personAuthId);\r
+ details = sample.displayAllPersons(items);\r
+ logger.info(details);\r
+ }\r
+\r
+ }\r
+\r
+ }\r
+\r
+}\r