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.organization.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.MultivaluedMap;
33 import javax.ws.rs.core.Response;
35 import org.apache.log4j.BasicConfigurator;
36 import org.collectionspace.services.OrganizationJAXBSchema;
37 import org.collectionspace.services.client.OrgAuthorityClient;
38 import org.collectionspace.services.client.OrgAuthorityClientUtils;
39 import org.collectionspace.services.client.test.ServiceRequestType;
40 import org.jboss.resteasy.client.ClientResponse;
41 import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput;
42 import org.slf4j.Logger;
43 import org.slf4j.LoggerFactory;
46 * OrgAuthorityServiceTest, carries out tests against a
47 * deployed and running OrgAuthority Service.
49 * $LastChangedRevision: 753 $
50 * $LastChangedDate: 2009-09-23 11:03:36 -0700 (Wed, 23 Sep 2009) $
52 public class OrgAuthorityBaseImport {
53 private static final Logger logger =
54 LoggerFactory.getLogger(OrgAuthorityBaseImport.class);
56 // Instance variables specific to this test.
57 private OrgAuthorityClient client = new OrgAuthorityClient();
58 final String SERVICE_PATH_COMPONENT = "orgauthorities";
59 final String ITEM_SERVICE_PATH_COMPONENT = "items";
61 public void createOrgAuthority(String orgAuthorityName,
62 List<Map<String,String>> orgInfos ) {
64 // Expected status code: 201 Created
65 int EXPECTED_STATUS_CODE = Response.Status.CREATED.getStatusCode();
66 // Type of service request being tested
67 ServiceRequestType REQUEST_TYPE = ServiceRequestType.CREATE;
69 if(logger.isDebugEnabled()){
70 logger.debug("Import: Create orgAuthority: \"" + orgAuthorityName +"\"");
72 String baseOrgAuthRefName = OrgAuthorityClientUtils.createOrgAuthRefName(orgAuthorityName, false);
73 String fullOrgAuthRefName = OrgAuthorityClientUtils.createOrgAuthRefName(orgAuthorityName, true);
74 MultipartOutput multipart =
75 OrgAuthorityClientUtils.createOrgAuthorityInstance(
76 orgAuthorityName, fullOrgAuthRefName,
77 client.getCommonPartName());
78 ClientResponse<Response> res = client.create(multipart);
80 int statusCode = res.getStatus();
82 if(!REQUEST_TYPE.isValidStatusCode(statusCode)) {
83 throw new RuntimeException("Could not create enumeration: \""+orgAuthorityName
84 +"\" "+ OrgAuthorityClientUtils.invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
86 if(statusCode != EXPECTED_STATUS_CODE) {
87 throw new RuntimeException("Unexpected Status when creating enumeration: \""
88 +orgAuthorityName +"\", Status:"+ statusCode);
91 // Store the ID returned from this create operation
92 // for additional tests below.
93 String newOrgAuthorityId = OrgAuthorityClientUtils.extractId(res);
94 if(logger.isDebugEnabled()){
95 logger.debug("Import: Created orgAuthorityulary: \"" + orgAuthorityName +"\" ID:"
98 for(Map<String,String> orgInfo : orgInfos){
99 OrgAuthorityClientUtils.createItemInAuthority(
100 newOrgAuthorityId, baseOrgAuthRefName, orgInfo, client);
104 // ---------------------------------------------------------------
105 // Utility methods used by methods above
106 // ---------------------------------------------------------------
108 public static void main(String[] args) {
110 BasicConfigurator.configure();
111 logger.info("OrgAuthorityBaseImport starting...");
113 OrgAuthorityBaseImport oabi = new OrgAuthorityBaseImport();
114 final String demoOrgAuthorityName = "Demo Org Authority";
116 Map<String, String> mmiOrgMap = new HashMap<String,String>();
117 mmiOrgMap.put(OrganizationJAXBSchema.SHORT_NAME, "MMI");
118 mmiOrgMap.put(OrganizationJAXBSchema.LONG_NAME, "Museum of the Moving Image");
119 mmiOrgMap.put(OrganizationJAXBSchema.CONTACT_NAME, "Megan Forbes");
120 mmiOrgMap.put(OrganizationJAXBSchema.FOUNDING_DATE, "1984");
121 mmiOrgMap.put(OrganizationJAXBSchema.FOUNDING_PLACE, "Astoria, NY");
122 Map<String, String> pahmaOrgMap = new HashMap<String,String>();
123 pahmaOrgMap.put(OrganizationJAXBSchema.SHORT_NAME, "PAHMA");
124 pahmaOrgMap.put(OrganizationJAXBSchema.LONG_NAME, "Phoebe A. Hearst Museum of Anthropology");
125 pahmaOrgMap.put(OrganizationJAXBSchema.NAME_ADDITIONS, "University of California, Berkeley");
126 pahmaOrgMap.put(OrganizationJAXBSchema.CONTACT_NAME, "Michael Black");
127 pahmaOrgMap.put(OrganizationJAXBSchema.FOUNDING_DATE, "1901");
128 pahmaOrgMap.put(OrganizationJAXBSchema.FOUNDING_PLACE, "Berkeley, CA");
129 Map<String, String> savoyOrgMap = new HashMap<String,String>();
130 savoyOrgMap.put(OrganizationJAXBSchema.SHORT_NAME, "Savoy Theatre");
131 savoyOrgMap.put(OrganizationJAXBSchema.FOUNDING_DATE, "1900");
132 savoyOrgMap.put(OrganizationJAXBSchema.DISSOLUTION_DATE, "1952");
133 savoyOrgMap.put(OrganizationJAXBSchema.FOUNDING_PLACE, "New York, NY");
134 List<Map<String, String>> orgMaps =
135 Arrays.asList(mmiOrgMap, pahmaOrgMap, savoyOrgMap );
137 oabi.createOrgAuthority(demoOrgAuthorityName, orgMaps);
139 logger.info("OrgAuthorityBaseImport complete.");