2 * This document is a part of the source code and related artifacts
3 * for CollectionSpace, an open source collections management system
4 * for museums and related institutions:
6 * http://www.collectionspace.org
7 * http://wiki.collectionspace.org
9 * Copyright (c)) 2009 Regents of the University of California
11 * Licensed under the Educational Community License (ECL), Version 2.0.
12 * You may not use this file except in compliance with this License.
14 * You may obtain a copy of the ECL 2.0 License at
15 * https://source.collectionspace.org/collection-space/LICENSE.txt
17 * Unless required by applicable law or agreed to in writing, software
18 * distributed under the License is distributed on an "AS IS" BASIS,
19 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20 * See the License for the specific language governing permissions and
21 * limitations under the License.
24 package org.collectionspace.services.person.importer;
26 import java.util.ArrayList;
27 import java.util.Arrays;
28 import java.util.HashMap;
29 import java.util.List;
32 import javax.ws.rs.core.MediaType;
33 import javax.ws.rs.core.MultivaluedMap;
34 import javax.ws.rs.core.Response;
36 import org.apache.log4j.BasicConfigurator;
37 import org.collectionspace.services.PersonJAXBSchema;
38 import org.collectionspace.services.client.PersonAuthorityClient;
39 import org.collectionspace.services.client.PersonAuthorityClientUtils;
40 import org.collectionspace.services.client.PoxPayloadOut;
41 import org.collectionspace.services.client.test.ServiceRequestType;
42 import org.collectionspace.services.person.PersonauthoritiesCommon;
43 import org.collectionspace.services.person.PersonauthoritiesCommonList;
44 import org.collectionspace.services.person.PersonsCommon;
45 import org.collectionspace.services.person.PersonsCommonList;
46 import org.jboss.resteasy.client.ClientResponse;
47 import org.jboss.resteasy.plugins.providers.multipart.OutputPart;
48 import org.slf4j.Logger;
49 import org.slf4j.LoggerFactory;
52 * PersonAuthorityServiceTest, carries out tests against a
53 * deployed and running PersonAuthority Service.
55 * $LastChangedRevision: 753 $
56 * $LastChangedDate: 2009-09-23 11:03:36 -0700 (Wed, 23 Sep 2009) $
58 public class PersonAuthorityBaseImport {
59 private static final Logger logger =
60 LoggerFactory.getLogger(PersonAuthorityBaseImport.class);
62 // Instance variables specific to this test.
63 private PersonAuthorityClient client = new PersonAuthorityClient();
65 public void createPersonAuthority(String displayName, String shortId,
66 List<Map<String, String>> personMaps ) {
68 // Expected status code: 201 Created
69 int EXPECTED_STATUS_CODE = Response.Status.CREATED.getStatusCode();
70 // Type of service request being tested
71 ServiceRequestType REQUEST_TYPE = ServiceRequestType.CREATE;
73 if(logger.isDebugEnabled()){
74 logger.debug("Import: Create personAuthority: \"" + displayName +"\"");
76 String basePersonRefName =
77 PersonAuthorityClientUtils.createPersonAuthRefName(shortId, null);
78 PoxPayloadOut multipart =
79 PersonAuthorityClientUtils.createPersonAuthorityInstance(
80 displayName, shortId, client.getCommonPartName());
81 ClientResponse<Response> res = client.create(multipart);
83 int statusCode = res.getStatus();
85 if(!REQUEST_TYPE.isValidStatusCode(statusCode)) {
86 throw new RuntimeException("Could not create enumeration: \""+displayName
87 +"\" "+ PersonAuthorityClientUtils.invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
89 if(statusCode != EXPECTED_STATUS_CODE) {
90 throw new RuntimeException("Unexpected Status when creating enumeration: \""
91 +displayName +"\", Status:"+ statusCode);
94 // Store the ID returned from this create operation
95 // for additional tests below.
96 String newPersonAuthorityId = PersonAuthorityClientUtils.extractId(res);
97 if(logger.isDebugEnabled()){
98 logger.debug("Import: Created personAuthorityulary: \"" + displayName +"\" ID:"
99 +newPersonAuthorityId );
103 *TODO: Laramie20100728 this code is out of date, and needs to use the new API. Commenting out for now.
105 *for(Map<String,String> personMap : personMaps){
106 * PersonAuthorityClientUtils.createItemInAuthority(
107 * newPersonAuthorityId, basePersonRefName, personMap, client);
110 logger.error("Method PersonAuthorityBaseImport.createPersonAuthority not implemented properly.");
114 public static void main(String[] args) {
116 BasicConfigurator.configure();
117 logger.info("PersonAuthorityBaseImport starting...");
119 PersonAuthorityBaseImport pabi = new PersonAuthorityBaseImport();
120 final String demoPersonAuthorityName = "Demo Person Authority";
121 final String demoPersonAuthorityShortId = "demoPersonAuth";
124 shortName, longName, nameAdditions, contactName,
125 foundingDate, dissolutionDate, foundingPlace, function, description
127 Map<String, String> johnWayneMap = new HashMap<String,String>();
128 johnWayneMap.put(PersonJAXBSchema.SHORT_IDENTIFIER, "johnWayne_Actor");
129 johnWayneMap.put(PersonJAXBSchema.FORE_NAME, "John");
130 johnWayneMap.put(PersonJAXBSchema.SUR_NAME, "Wayne");
131 johnWayneMap.put(PersonJAXBSchema.GENDER, "male");
132 johnWayneMap.put(PersonJAXBSchema.BIRTH_DATE, "May 26, 1907");
133 johnWayneMap.put(PersonJAXBSchema.BIRTH_PLACE, "Winterset, Iowa");
134 johnWayneMap.put(PersonJAXBSchema.DEATH_DATE, "June 11, 1979");
135 johnWayneMap.put(PersonJAXBSchema.BIO_NOTE, "born Marion Robert Morrison and better" +
136 "known by his stage name John Wayne, was an American film actor, director " +
137 "and producer. He epitomized rugged masculinity and has become an enduring " +
138 "American icon. He is famous for his distinctive voice, walk and height. " +
139 "He was also known for his conservative political views and his support in " +
140 "the 1950s for anti-communist positions.");
141 Map<String, String> patrickSchmitzMap = new HashMap<String,String>();
142 patrickSchmitzMap.put(PersonJAXBSchema.SHORT_IDENTIFIER, "plSchmitz_Geek");
143 patrickSchmitzMap.put(PersonJAXBSchema.FORE_NAME, "Patrick");
144 patrickSchmitzMap.put(PersonJAXBSchema.SUR_NAME, "Schmitz");
145 patrickSchmitzMap.put(PersonJAXBSchema.GENDER, "male");
146 patrickSchmitzMap.put(PersonJAXBSchema.BIRTH_DATE, "7/15/1960");
147 patrickSchmitzMap.put(PersonJAXBSchema.BIRTH_PLACE, "MI");
148 Map<String, String> janeDoeMap = new HashMap<String,String>();
149 janeDoeMap.put(PersonJAXBSchema.FORE_NAME, "Jane");
150 janeDoeMap.put(PersonJAXBSchema.SUR_NAME, "Doe");
151 janeDoeMap.put(PersonJAXBSchema.GENDER, "female");
152 janeDoeMap.put(PersonJAXBSchema.BIRTH_DATE, "7/04/1901");
153 janeDoeMap.put(PersonJAXBSchema.DEATH_DATE, "4/01/1999");
154 janeDoeMap.put(PersonJAXBSchema.BIRTH_PLACE, "Anytown, USA");
155 janeDoeMap.put(PersonJAXBSchema.BIRTH_PLACE, "Nowheresville, USA");
156 List<Map<String, String>> personsMaps =
157 Arrays.asList(johnWayneMap, patrickSchmitzMap, janeDoeMap );
159 pabi.createPersonAuthority(demoPersonAuthorityName,
160 demoPersonAuthorityShortId, personsMaps);
162 logger.info("PersonAuthorityBaseImport complete.");