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 orgAuthorityDisplayName, String orgAuthorityShortId,
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: \"" + orgAuthorityShortId +"\"");
72 String baseOrgAuthRefName = OrgAuthorityClientUtils.createOrgAuthRefName(orgAuthorityShortId, null);
73 MultipartOutput multipart =
74 OrgAuthorityClientUtils.createOrgAuthorityInstance(
75 orgAuthorityDisplayName, orgAuthorityShortId, client.getCommonPartName());
76 ClientResponse<Response> res = client.create(multipart);
78 int statusCode = res.getStatus();
80 if(!REQUEST_TYPE.isValidStatusCode(statusCode)) {
81 throw new RuntimeException("Could not create enumeration: \""+orgAuthorityShortId
82 +"\" "+ OrgAuthorityClientUtils.invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
84 if(statusCode != EXPECTED_STATUS_CODE) {
85 throw new RuntimeException("Unexpected Status when creating enumeration: \""
86 +orgAuthorityShortId +"\", Status:"+ statusCode);
89 // Store the ID returned from this create operation
90 // for additional tests below.
91 String newOrgAuthorityId = OrgAuthorityClientUtils.extractId(res);
92 if(logger.isDebugEnabled()){
93 logger.debug("Import: Created orgAuthorityulary: \"" + orgAuthorityShortId +"\" ID:"
96 for(Map<String,String> orgInfo : orgInfos){
97 OrgAuthorityClientUtils.createItemInAuthority(
98 newOrgAuthorityId, baseOrgAuthRefName, orgInfo, client);
102 // ---------------------------------------------------------------
103 // Utility methods used by methods above
104 // ---------------------------------------------------------------
106 public static void main(String[] args) {
108 BasicConfigurator.configure();
109 logger.info("OrgAuthorityBaseImport starting...");
111 OrgAuthorityBaseImport oabi = new OrgAuthorityBaseImport();
112 final String demoOrgAuthorityName = "Demo Org Authority";
113 final String demoOrgAuthorityShortId = "demoOrgAuth";
115 Map<String, String> mmiOrgMap = new HashMap<String,String>();
116 mmiOrgMap.put(OrganizationJAXBSchema.SHORT_IDENTIFIER, "mmi");
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_IDENTIFIER, "pahma");
124 pahmaOrgMap.put(OrganizationJAXBSchema.SHORT_NAME, "PAHMA");
125 pahmaOrgMap.put(OrganizationJAXBSchema.LONG_NAME, "Phoebe A. Hearst Museum of Anthropology");
126 pahmaOrgMap.put(OrganizationJAXBSchema.NAME_ADDITIONS, "University of California, Berkeley");
127 pahmaOrgMap.put(OrganizationJAXBSchema.CONTACT_NAME, "Michael Black");
128 pahmaOrgMap.put(OrganizationJAXBSchema.FOUNDING_DATE, "1901");
129 pahmaOrgMap.put(OrganizationJAXBSchema.FOUNDING_PLACE, "Berkeley, CA");
130 Map<String, String> savoyOrgMap = new HashMap<String,String>();
131 savoyOrgMap.put(OrganizationJAXBSchema.SHORT_IDENTIFIER, "savoyTh");
132 savoyOrgMap.put(OrganizationJAXBSchema.SHORT_NAME, "Savoy Theatre");
133 savoyOrgMap.put(OrganizationJAXBSchema.FOUNDING_DATE, "1900");
134 savoyOrgMap.put(OrganizationJAXBSchema.DISSOLUTION_DATE, "1952");
135 savoyOrgMap.put(OrganizationJAXBSchema.FOUNDING_PLACE, "New York, NY");
136 List<Map<String, String>> orgMaps =
137 Arrays.asList(mmiOrgMap, pahmaOrgMap, savoyOrgMap );
139 oabi.createOrgAuthority(demoOrgAuthorityName, demoOrgAuthorityShortId, orgMaps);
141 logger.info("OrgAuthorityBaseImport complete.");