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