]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
1e09bc184655dbfdcc17b2fc5b926d12b8353a3c
[tmp/jakarta-migration.git] /
1 /**\r
2  * This document is a part of the source code and related artifacts\r
3  * for CollectionSpace, an open source collections management system\r
4  * for museums and related institutions:\r
5  *\r
6  * http://www.collectionspace.org\r
7  * http://wiki.collectionspace.org\r
8  *\r
9  * Copyright (c)) 2009 Regents of the University of California\r
10  *\r
11  * Licensed under the Educational Community License (ECL), Version 2.0.\r
12  * You may not use this file except in compliance with this License.\r
13  *\r
14  * You may obtain a copy of the ECL 2.0 License at\r
15  * https://source.collectionspace.org/collection-space/LICENSE.txt\r
16  *\r
17  * Unless required by applicable law or agreed to in writing, software\r
18  * distributed under the License is distributed on an "AS IS" BASIS,\r
19  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
20  * See the License for the specific language governing permissions and\r
21  * limitations under the License.\r
22  */\r
23 \r
24 package org.collectionspace.services.person.client.sample;\r
25 \r
26 import java.util.ArrayList;\r
27 import java.util.Arrays;\r
28 import java.util.HashMap;\r
29 import java.util.List;\r
30 import java.util.Map;\r
31 \r
32 import javax.ws.rs.core.MediaType;\r
33 import javax.ws.rs.core.MultivaluedMap;\r
34 import javax.ws.rs.core.Response;\r
35 \r
36 import org.apache.log4j.BasicConfigurator;\r
37 import org.collectionspace.services.PersonJAXBSchema;\r
38 import org.collectionspace.services.client.PersonAuthorityClient;\r
39 import org.collectionspace.services.client.PersonAuthorityClientUtils;\r
40 import org.collectionspace.services.client.PoxPayloadIn;\r
41 import org.collectionspace.services.client.PoxPayloadOut;\r
42 import org.collectionspace.services.client.test.ServiceRequestType;\r
43 import org.collectionspace.services.person.PersonauthoritiesCommon;\r
44 import org.collectionspace.services.person.PersonauthoritiesCommonList;\r
45 import org.collectionspace.services.person.PersonsCommon;\r
46 import org.collectionspace.services.person.PersonsCommonList;\r
47 import org.jboss.resteasy.client.ClientResponse;\r
48 import org.jboss.resteasy.plugins.providers.multipart.InputPart;\r
49 import org.jboss.resteasy.plugins.providers.multipart.OutputPart;\r
50 import org.slf4j.Logger;\r
51 import org.slf4j.LoggerFactory;\r
52 \r
53 /**\r
54  * PersonAuthority Sample, carries out tests against a\r
55  * deployed and running PersonAuthority Service.\r
56  *\r
57  * $LastChangedRevision: 1055 $\r
58  * $LastChangedDate: 2009-12-09 12:25:15 -0800 (Wed, 09 Dec 2009) $\r
59  */\r
60 public class Sample {\r
61     private static final Logger logger =\r
62         LoggerFactory.getLogger(Sample.class);\r
63 \r
64     // Instance variables specific to this test.\r
65     private PersonAuthorityClient client = new PersonAuthorityClient();\r
66     final String SERVICE_PATH_COMPONENT = "persons";\r
67     final String ITEM_SERVICE_PATH_COMPONENT = "items";\r
68 \r
69 \r
70     // ---------------------------------------------------------------\r
71     // Create\r
72     // ---------------------------------------------------------------\r
73 \r
74     public void createPersonAuthority(String personAuthorityName, \r
75                 List<Map<String, String>> personMaps ) {\r
76 \r
77         // Expected status code: 201 Created\r
78         int EXPECTED_STATUS_CODE = Response.Status.CREATED.getStatusCode();\r
79         // Type of service request being tested\r
80         ServiceRequestType REQUEST_TYPE = ServiceRequestType.CREATE;\r
81 \r
82         logger.info("Import: Create personAuthority: \"" + personAuthorityName +"\"");\r
83 \r
84 \r
85         String displaySuffix = "displayName-" + System.currentTimeMillis(); //TODO: Laramie20100728 temp fix, made-up displaySuffix.\r
86         String basePersonRefName = PersonAuthorityClientUtils.createPersonAuthRefName(personAuthorityName, displaySuffix);//TODO: Laramie20100728 temp fix  was personAuthorityName, false\r
87         String fullPersonRefName = PersonAuthorityClientUtils.createPersonAuthRefName(personAuthorityName, displaySuffix); //TODO: Laramie20100728 temp fix  was personAuthorityName, true\r
88         PoxPayloadOut multipart = \r
89                 PersonAuthorityClientUtils.createPersonAuthorityInstance(\r
90                                 personAuthorityName, fullPersonRefName, client.getCommonPartName() );\r
91         ClientResponse<Response> res = client.create(multipart);\r
92 \r
93         int statusCode = res.getStatus();\r
94 \r
95         if(!REQUEST_TYPE.isValidStatusCode(statusCode)) {\r
96                 throw new RuntimeException("Could not create enumeration: \""+personAuthorityName\r
97                                 +"\" "+ PersonAuthorityClientUtils.invalidStatusCodeMessage(REQUEST_TYPE, statusCode));\r
98         }\r
99         if(statusCode != EXPECTED_STATUS_CODE) {\r
100                 throw new RuntimeException("Unexpected Status when creating enumeration: \""\r
101                                 +personAuthorityName +"\", Status:"+ statusCode);\r
102         }\r
103 \r
104         // Store the ID returned from this create operation\r
105         // for additional tests below.\r
106         String newPersonAuthId = PersonAuthorityClientUtils.extractId(res);\r
107         logger.info("Import: Created personAuthority: \"" + personAuthorityName +"\" ID:"\r
108                                 +newPersonAuthId );\r
109         \r
110         // Add items to the personAuthority\r
111         for(Map<String,String> personMap : personMaps){\r
112                 createItemInAuthority(newPersonAuthId, basePersonRefName, personMap);\r
113         }\r
114         \r
115     }\r
116     \r
117     private String createItemInAuthority(String vcsid, \r
118                 String personAuthorityRefName, Map<String,String> personMap) {\r
119         // Expected status code: 201 Created\r
120         int EXPECTED_STATUS_CODE = Response.Status.CREATED.getStatusCode();\r
121         // Type of service request being tested\r
122         ServiceRequestType REQUEST_TYPE = ServiceRequestType.CREATE;\r
123         String foreName = personMap.get(PersonJAXBSchema.FORE_NAME);\r
124         String middleName = personMap.get(PersonJAXBSchema.MIDDLE_NAME);\r
125         String surName = personMap.get(PersonJAXBSchema.SUR_NAME);\r
126         String birthDate = personMap.get(PersonJAXBSchema.BIRTH_DATE);\r
127         String deathDate = personMap.get(PersonJAXBSchema.DEATH_DATE);\r
128         StringBuilder builtName = new StringBuilder();\r
129         if(foreName!=null)\r
130                 builtName.append(foreName);\r
131         if(middleName!=null)\r
132                 builtName.append(middleName);\r
133         if(surName!=null)\r
134                 builtName.append(surName);\r
135         if(birthDate!=null)\r
136              builtName.append(birthDate);\r
137         builtName.append("-");\r
138         if(deathDate!=null)\r
139              builtName.append(deathDate);\r
140 \r
141         String displaySuffix = "displayName-" + System.currentTimeMillis(); //TODO: Laramie20100728 temp fix, made-up displaySuffix.\r
142 \r
143         String refName = PersonAuthorityClientUtils.createPersonRefName(personAuthorityRefName, builtName.toString(), displaySuffix); //TODO was ...,true);\r
144         logger.info("Import: Create Item: \""+refName+"\" in personAuthority: \"" + personAuthorityRefName +"\"");\r
145 \r
146         if(logger.isDebugEnabled()){\r
147                 logger.debug("Import: Create Item: \""+builtName.toString()\r
148                                 +"\" in personAuthorityulary: \"" + personAuthorityRefName +"\"");\r
149         }\r
150         PoxPayloadOut multipart = createPersonInstance( vcsid, refName,\r
151                         personMap );\r
152         ClientResponse<Response> res = client.createItem(vcsid, multipart);\r
153 \r
154         int statusCode = res.getStatus();\r
155 \r
156         if(!REQUEST_TYPE.isValidStatusCode(statusCode)) {\r
157                 throw new RuntimeException("Could not create Item: \""+refName\r
158                                 +"\" in personAuthority: \"" + personAuthorityRefName\r
159                                 +"\" "+ PersonAuthorityClientUtils.invalidStatusCodeMessage(REQUEST_TYPE, statusCode));\r
160         }\r
161         if(statusCode != EXPECTED_STATUS_CODE) {\r
162                 throw new RuntimeException("Unexpected Status when creating Item: \""+refName\r
163                                 +"\" in personAuthority: \"" + personAuthorityRefName +"\", Status:"+ statusCode);\r
164         }\r
165 \r
166         return PersonAuthorityClientUtils.extractId(res);\r
167     }\r
168 \r
169 \r
170    // ---------------------------------------------------------------\r
171    // Read\r
172    // ---------------------------------------------------------------\r
173 \r
174    private PersonauthoritiesCommonList readPersonAuthorities() {\r
175 \r
176         // Expected status code: 200 OK\r
177         int EXPECTED_STATUS_CODE = Response.Status.OK.getStatusCode();\r
178         // Type of service request being tested\r
179         ServiceRequestType REQUEST_TYPE = ServiceRequestType.READ;\r
180 \r
181         // Submit the request to the service and store the response.\r
182         ClientResponse<PersonauthoritiesCommonList> res = client.readList();\r
183         PersonauthoritiesCommonList list = res.getEntity();\r
184 \r
185         int statusCode = res.getStatus();\r
186         if(!REQUEST_TYPE.isValidStatusCode(statusCode)) {\r
187                 throw new RuntimeException("Could not read list of personAuthorities: "\r
188                 + PersonAuthorityClientUtils.invalidStatusCodeMessage(REQUEST_TYPE, statusCode));\r
189         }\r
190         if(statusCode != EXPECTED_STATUS_CODE) {\r
191                 throw new RuntimeException("Unexpected Status when reading " +\r
192                 "list of personAuthorities, Status:"+ statusCode);\r
193         }\r
194 \r
195         return list;\r
196    }\r
197 \r
198     private List<String> readPersonAuthorityIds(PersonauthoritiesCommonList list) {\r
199 \r
200         List<String> ids = new ArrayList<String>();\r
201         List<PersonauthoritiesCommonList.PersonauthorityListItem> personAuthorities =\r
202             list.getPersonauthorityListItem();\r
203         for (PersonauthoritiesCommonList.PersonauthorityListItem personAuthority : personAuthorities) {\r
204             ids.add(personAuthority.getCsid());\r
205         }\r
206         return ids;\r
207    }\r
208     \r
209    private PersonauthoritiesCommon readPersonAuthority(String personAuthId) {\r
210 \r
211         // Expected status code: 200 OK\r
212         int EXPECTED_STATUS_CODE = Response.Status.OK.getStatusCode();\r
213         // Type of service request being tested\r
214         ServiceRequestType REQUEST_TYPE = ServiceRequestType.READ;\r
215 \r
216         // Submit the request to the service and store the response.\r
217         PersonauthoritiesCommon personAuthority = null;\r
218         try {\r
219             ClientResponse<String> res = client.read(personAuthId);\r
220             int statusCode = res.getStatus();\r
221             if(!REQUEST_TYPE.isValidStatusCode(statusCode)) {\r
222                 throw new RuntimeException("Could not read personAuthority"\r
223                     + PersonAuthorityClientUtils.invalidStatusCodeMessage(REQUEST_TYPE, statusCode));\r
224             }\r
225             if(statusCode != EXPECTED_STATUS_CODE) {\r
226                 throw new RuntimeException("Unexpected Status when reading " +\r
227                     "personAuthority, Status:"+ statusCode);\r
228             }\r
229             PoxPayloadIn input = new PoxPayloadIn(res.getEntity());\r
230             personAuthority = (PersonauthoritiesCommon) extractPart(input,\r
231                     client.getCommonPartName(), PersonauthoritiesCommon.class);\r
232         } catch (Exception e) {\r
233             throw new RuntimeException("Could not read personAuthority: ", e);\r
234         }\r
235 \r
236         return personAuthority;\r
237     }\r
238 \r
239     private PersonsCommonList readItemsInPersonAuth(String personAuthId) {\r
240 \r
241         // Expected status code: 200 OK\r
242         int EXPECTED_STATUS_CODE = Response.Status.OK.getStatusCode();\r
243         // Type of service request being tested\r
244         ServiceRequestType REQUEST_TYPE = ServiceRequestType.READ;\r
245 \r
246         // Submit the request to the service and store the response.\r
247         ClientResponse<PersonsCommonList> res = client.readItemList(personAuthId, "", ""); //TODO: Laramie201007289  added empty strings to satisfy api\r
248         PersonsCommonList list = res.getEntity();\r
249 \r
250         int statusCode = res.getStatus();\r
251 \r
252         if(!REQUEST_TYPE.isValidStatusCode(statusCode)) {\r
253                 throw new RuntimeException("Could not read items in personAuthority: "\r
254                 + PersonAuthorityClientUtils.invalidStatusCodeMessage(REQUEST_TYPE, statusCode));\r
255         }\r
256         if(statusCode != EXPECTED_STATUS_CODE) {\r
257                 throw new RuntimeException("Unexpected Status when reading " +\r
258                 "items in personAuthority, Status:"+ statusCode);\r
259         }\r
260 \r
261         return list;\r
262     }\r
263 \r
264     private List<String> readPersonIds(PersonsCommonList list) {\r
265 \r
266         List<String> ids = new ArrayList<String>();\r
267         List<PersonsCommonList.PersonListItem> items =\r
268             list.getPersonListItem();\r
269         for (PersonsCommonList.PersonListItem item : items) {\r
270             ids.add(item.getCsid());\r
271         }\r
272         return ids;\r
273    }\r
274 \r
275     // ---------------------------------------------------------------\r
276     // Delete\r
277     // ---------------------------------------------------------------\r
278 \r
279     private void deletePersonAuthority(String vcsid) {\r
280          // Expected status code: 200 OK\r
281         int EXPECTED_STATUS_CODE = Response.Status.OK.getStatusCode();\r
282         // Type of service request being tested\r
283         ServiceRequestType REQUEST_TYPE = ServiceRequestType.DELETE;\r
284 \r
285         ClientResponse<Response> res = client.delete(vcsid);\r
286         int statusCode = res.getStatus();\r
287 \r
288         if(!REQUEST_TYPE.isValidStatusCode(statusCode)) {\r
289                 throw new RuntimeException("Could not delete personAuthority: "\r
290                 + PersonAuthorityClientUtils.invalidStatusCodeMessage(REQUEST_TYPE, statusCode));\r
291         }\r
292         if(statusCode != EXPECTED_STATUS_CODE) {\r
293                 throw new RuntimeException("Unexpected Status when deleting " +\r
294                 "personAuthority, Status:"+ statusCode);\r
295         }\r
296     }\r
297 \r
298     private void deleteAllPersonAuthorities() {\r
299         List<String> ids = readPersonAuthorityIds(readPersonAuthorities());\r
300         for (String id : ids) {\r
301             deletePersonAuthority(id);\r
302         }\r
303     }\r
304 \r
305         private void deletePerson(String vcsid, String itemcsid) {\r
306          // Expected status code: 200 OK\r
307         int EXPECTED_STATUS_CODE = Response.Status.OK.getStatusCode();\r
308         // Type of service request being tested\r
309         ServiceRequestType REQUEST_TYPE = ServiceRequestType.DELETE;\r
310 \r
311         ClientResponse<Response> res = client.deleteItem(vcsid, itemcsid);\r
312         int statusCode = res.getStatus();\r
313 \r
314         if(!REQUEST_TYPE.isValidStatusCode(statusCode)) {\r
315                 throw new RuntimeException("Could not delete personAuthority item: "\r
316                 + PersonAuthorityClientUtils.invalidStatusCodeMessage(REQUEST_TYPE, statusCode));\r
317         }\r
318         if(statusCode != EXPECTED_STATUS_CODE) {\r
319                 throw new RuntimeException("Unexpected Status when deleting " +\r
320                 "personAuthority item, Status:"+ statusCode);\r
321         }\r
322     }\r
323 \r
324     private void deleteAllItemsForPersonAuth(String personAuthId) {\r
325         List<String> itemIds = readPersonIds(readItemsInPersonAuth(personAuthId));\r
326         for (String itemId : itemIds) {\r
327             deletePerson(personAuthId, itemId);\r
328         }\r
329     }\r
330 \r
331     // ---------------------------------------------------------------\r
332     // Utility methods used by tests above\r
333     // ---------------------------------------------------------------\r
334 \r
335     /*\r
336     private PoxPayloadOut createPersonAuthorityInstance(\r
337                 String displayName, String refName ) {\r
338         PersonauthoritiesCommon personAuthority = new PersonauthoritiesCommon();\r
339         personAuthority.setDisplayName(displayName);\r
340         personAuthority.setRefName(refName);\r
341         personAuthority.setVocabType("PersonAuthority");\r
342         PoxPayloadOut multipart = new PoxPayloadOut();\r
343         OutputPart commonPart = multipart.addPart(personAuthority, MediaType.APPLICATION_XML_TYPE);\r
344         commonPart.getHeaders().add("label", client.getCommonPartName());\r
345 \r
346         if(logger.isDebugEnabled()){\r
347                 logger.debug("to be created, personAuthority common ",\r
348                                         personAuthority, PersonauthoritiesCommon.class);\r
349         }\r
350 \r
351         return multipart;\r
352     }\r
353     */\r
354 \r
355     private PoxPayloadOut createPersonInstance(String inAuthority, \r
356                 String refName, Map<String, String> personInfo ) {\r
357             PersonsCommon person = new PersonsCommon();\r
358             person.setInAuthority(inAuthority);\r
359                 person.setRefName(refName);\r
360                 String value = null;\r
361             if((value = (String)personInfo.get(PersonJAXBSchema.FORE_NAME))!=null)\r
362                 person.setForeName(value);\r
363             if((value = (String)personInfo.get(PersonJAXBSchema.MIDDLE_NAME))!=null)\r
364                 person.setMiddleName(value);\r
365             if((value = (String)personInfo.get(PersonJAXBSchema.SUR_NAME))!=null)\r
366                 person.setSurName(value);\r
367             if((value = (String)personInfo.get(PersonJAXBSchema.INITIALS))!=null)\r
368                 person.setInitials(value);\r
369             if((value = (String)personInfo.get(PersonJAXBSchema.SALUTATIONS))!=null)\r
370                 person.setSalutation(value);\r
371             if((value = (String)personInfo.get(PersonJAXBSchema.TITLE))!=null)\r
372                 person.setTitle(value);\r
373             if((value = (String)personInfo.get(PersonJAXBSchema.NAME_ADDITIONS))!=null)\r
374                 person.setNameAdditions(value);\r
375             if((value = (String)personInfo.get(PersonJAXBSchema.BIRTH_DATE))!=null) {\r
376                 StructuredDateGroup birthDate = new StructuredDateGroup();\r
377                 birthDate.setDateDisplayDate(value);\r
378                 person.setBirthDateGroup(birthDate);\r
379             }\r
380             if((value = (String)personInfo.get(PersonJAXBSchema.DEATH_DATE))!=null) {\r
381                 StructuredDateGroup deathDate = new StructuredDateGroup();\r
382                 deathDate.setDateDisplayDate(value);\r
383                 person.setDeathDateGroup(deathDate);\r
384             }\r
385             if((value = (String)personInfo.get(PersonJAXBSchema.BIRTH_PLACE))!=null)\r
386                 person.setBirthPlace(value);\r
387             if((value = (String)personInfo.get(PersonJAXBSchema.DEATH_PLACE))!=null)\r
388                 person.setDeathPlace(value);\r
389 \r
390             /* TODO: Laramie20100728  removed missing member calls\r
391             if((value = (String)personInfo.get(PersonJAXBSchema.GROUP))!=null)\r
392                 person.setGroup(value);\r
393             if((value = (String)personInfo.get(PersonJAXBSchema.NATIONALITY))!=null)\r
394                 person.setNationality(value);\r
395             if((value = (String)personInfo.get(PersonJAXBSchema.OCCUPATION))!=null)\r
396                 person.setOccupation(value);\r
397             if((value = (String)personInfo.get(PersonJAXBSchema.SCHOOL_OR_STYLE))!=null)\r
398                 person.setSchoolOrStyle(value);\r
399             */\r
400         \r
401             if((value = (String)personInfo.get(PersonJAXBSchema.GENDER))!=null)\r
402                         person.setGender(value);\r
403             if((value = (String)personInfo.get(PersonJAXBSchema.BIO_NOTE))!=null)\r
404                 person.setBioNote(value);\r
405             if((value = (String)personInfo.get(PersonJAXBSchema.NAME_NOTE))!=null)\r
406                 person.setNameNote(value);\r
407             PoxPayloadOut multipart = new PoxPayloadOut();\r
408             OutputPart commonPart = multipart.addPart(person,\r
409                 MediaType.APPLICATION_XML_TYPE);\r
410             commonPart.getHeaders().add("label", client.getItemCommonPartName());\r
411 \r
412             if(logger.isDebugEnabled()){\r
413                 logger.debug("to be created, person common"+person);\r
414             }\r
415 \r
416             return multipart;\r
417         }\r
418 \r
419     // Retrieve individual fields of personAuthority records.\r
420 \r
421     private String displayAllPersonAuthorities(PersonauthoritiesCommonList list) {\r
422         StringBuffer sb = new StringBuffer();\r
423             List<PersonauthoritiesCommonList.PersonauthorityListItem> personAuthorities =\r
424                     list.getPersonauthorityListItem();\r
425             int i = 0;\r
426         for (PersonauthoritiesCommonList.PersonauthorityListItem personAuthority : personAuthorities) {\r
427             sb.append("personAuthority [" + i + "]" + "\n");\r
428             sb.append(displayPersonAuthorityDetails(personAuthority));\r
429             i++;\r
430         }\r
431         return sb.toString();\r
432     }\r
433 \r
434     private String displayPersonAuthorityDetails(\r
435         PersonauthoritiesCommonList.PersonauthorityListItem personAuthority) {\r
436             StringBuffer sb = new StringBuffer();\r
437             sb.append("displayName=" + personAuthority.getDisplayName() + "\n");\r
438             sb.append("vocabType=" + personAuthority.getVocabType() + "\n");\r
439             // sb.append("csid=" + personAuthority.getCsid() + "\n");\r
440             sb.append("URI=" + personAuthority.getUri() + "\n");\r
441         return sb.toString();\r
442     }\r
443 \r
444     // Retrieve individual fields of person records.\r
445 \r
446     private String displayAllPersons(PersonsCommonList list) {\r
447         StringBuffer sb = new StringBuffer();\r
448         List<PersonsCommonList.PersonListItem> items =\r
449                 list.getPersonListItem();\r
450         int i = 0;\r
451         for (PersonsCommonList.PersonListItem item : items) {\r
452             sb.append("person [" + i + "]" + "\n");\r
453             sb.append(displayPersonDetails(item));\r
454             i++;\r
455         }\r
456         return sb.toString();\r
457     }\r
458 \r
459     private String displayPersonDetails(\r
460         PersonsCommonList.PersonListItem item) {\r
461             StringBuffer sb = new StringBuffer();\r
462             sb.append("csid=" + item.getCsid() + "\n");\r
463             sb.append("displayName=" + item.getDisplayName() + "\n");\r
464             // sb.append("URI=" + item.getUri() + "\n");\r
465         return sb.toString();\r
466     }\r
467 \r
468     private Object extractPart(PoxPayloadIn input, String label,\r
469         Class clazz) throws Exception {\r
470         Object obj = null;\r
471         for(InputPart part : input.getParts()){\r
472             String partLabel = part.getHeaders().getFirst("label");\r
473             if(label.equalsIgnoreCase(partLabel)){\r
474                 String partStr = part.getBodyAsString();\r
475                 if(logger.isDebugEnabled()){\r
476                     logger.debug("extracted part str=\n" + partStr);\r
477                 }\r
478                 obj = part.getBody(clazz, null);\r
479                 if(logger.isDebugEnabled()){\r
480                     logger.debug("extracted part obj=\n", obj, clazz);\r
481                 }\r
482                 break;\r
483             }\r
484         }\r
485         return obj;\r
486     }\r
487 \r
488         public static void main(String[] args) {\r
489 \r
490         // Configure logging.\r
491                 BasicConfigurator.configure();\r
492 \r
493         logger.info("PersonAuthority Sample starting...");\r
494 \r
495                 Sample sample = new Sample();\r
496         PersonauthoritiesCommonList personAuthorities;\r
497         List<String> personAuthIds;\r
498         String details = "";\r
499 \r
500         // Optionally delete all personAuthorities and persons.\r
501 \r
502         boolean ENABLE_DELETE_ALL = false;\r
503         if (ENABLE_DELETE_ALL) {\r
504 \r
505             logger.info("Deleting all persons and personAuthorities ...");\r
506 \r
507             // For each personAuthority ...\r
508             personAuthorities = sample.readPersonAuthorities();\r
509             personAuthIds = sample.readPersonAuthorityIds(personAuthorities);\r
510             for (String personAuthId : personAuthIds) {\r
511                 logger.info("Deleting all persons for personAuthority ...");\r
512                 sample.deleteAllItemsForPersonAuth(personAuthId);\r
513                 logger.info("Deleting personAuthority ...");\r
514                 sample.deletePersonAuthority(personAuthId);\r
515             }\r
516 \r
517             logger.info("Reading personAuthorities after deletion ...");\r
518             personAuthorities = sample.readPersonAuthorities();\r
519             details = sample.displayAllPersonAuthorities(personAuthorities);\r
520             logger.info(details);\r
521 \r
522             logger.info("Reading items in each personAuthority after deletion ...");\r
523             personAuthIds = sample.readPersonAuthorityIds(personAuthorities);\r
524             for (String personAuthId : personAuthIds) {\r
525                 PersonsCommonList items = sample.readItemsInPersonAuth(personAuthId);\r
526                 details = sample.displayAllPersons(items);\r
527                 logger.info(details);\r
528             }\r
529 \r
530         }\r
531 \r
532         // Create new authorities, each populated with persons.\r
533 \r
534         Map<String, String> johnWayneMap = new HashMap<String,String>();\r
535         johnWayneMap.put(PersonJAXBSchema.FORE_NAME, "John");\r
536         johnWayneMap.put(PersonJAXBSchema.SUR_NAME, "Wayne");\r
537         johnWayneMap.put(PersonJAXBSchema.GENDER, "male");\r
538         Map<String, String> patrickSchmitzMap = new HashMap<String,String>();\r
539         patrickSchmitzMap.put(PersonJAXBSchema.FORE_NAME, "Patrick");\r
540         patrickSchmitzMap.put(PersonJAXBSchema.SUR_NAME, "Schmitz");\r
541         patrickSchmitzMap.put(PersonJAXBSchema.GENDER, "male");\r
542         Map<String, String> janeDoeMap = new HashMap<String,String>();\r
543         janeDoeMap.put(PersonJAXBSchema.FORE_NAME, "Jane");\r
544         janeDoeMap.put(PersonJAXBSchema.SUR_NAME, "Doe");\r
545         janeDoeMap.put(PersonJAXBSchema.GENDER, "female");\r
546         List<Map<String, String>> personsMaps = \r
547                 Arrays.asList(johnWayneMap, patrickSchmitzMap, janeDoeMap );\r
548         \r
549         sample.createPersonAuthority("Sample Person Auth", personsMaps);\r
550 \r
551                 logger.info("PersonAuthority Sample complete.");\r
552 \r
553         logger.info("Reading personAuthorities and items ...");\r
554         // Get a list of personAuthorities.\r
555         personAuthorities = sample.readPersonAuthorities();\r
556         // For each personAuthority ...\r
557         for (PersonauthoritiesCommonList.PersonauthorityListItem\r
558             personAuthority : personAuthorities.getPersonauthorityListItem()) {\r
559             // Get its display name.\r
560             logger.info(personAuthority.getDisplayName());\r
561             // Get a list of the persons in this personAuthority.\r
562             PersonsCommonList items =\r
563                 sample.readItemsInPersonAuth(personAuthority.getCsid());\r
564             // For each person ...\r
565             for (PersonsCommonList.PersonListItem\r
566                 item : items.getPersonListItem()) {\r
567                 // Get its short name.\r
568                 logger.info(" " + item.getDisplayName());\r
569             }\r
570         }\r
571 \r
572         // Sample alternate methods of reading all personAuthorities and\r
573         // persons separately.\r
574         boolean RUN_ADDITIONAL_SAMPLES = false;\r
575         if (RUN_ADDITIONAL_SAMPLES) {\r
576 \r
577             logger.info("Reading all personAuthorities ...");\r
578             details = sample.displayAllPersonAuthorities(personAuthorities);\r
579             logger.info(details);\r
580 \r
581             logger.info("Reading all persons ...");\r
582             personAuthIds = sample.readPersonAuthorityIds(personAuthorities);\r
583             for (String personAuthId : personAuthIds) {\r
584                 PersonsCommonList items = sample.readItemsInPersonAuth(personAuthId);\r
585                 details = sample.displayAllPersons(items);\r
586                 logger.info(details);\r
587             }\r
588 \r
589         }\r
590 \r
591         }\r
592 \r
593 }\r