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.PoxPayloadOut;
40 import org.collectionspace.services.client.test.ServiceRequestType;
41 import org.jboss.resteasy.client.ClientResponse;
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 PoxPayloadOut 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:"
99 *TODO: Laramie20100728 this code is out of date, and needs to use the new API. Commenting out for now.
101 *orgRepeatablesInfo is undefined;
102 *for(Map<String,String> orgInfo : orgInfos){
103 * OrgAuthorityClientUtils.createItemInAuthority(newOrgAuthorityId, baseOrgAuthRefName, orgInfo, orgRepeatablesInfo, client);
106 logger.error("MethodcreateOrgAuthority(String orgAuthorityDisplayName, String orgAuthorityShortId,List<Map<String,String>> orgInfos ) not implemented properly.");
109 // ---------------------------------------------------------------
110 // Utility methods used by methods above
111 // ---------------------------------------------------------------
113 public static void main(String[] args) {
115 BasicConfigurator.configure();
116 logger.info("OrgAuthorityBaseImport starting...");
118 OrgAuthorityBaseImport oabi = new OrgAuthorityBaseImport();
119 final String demoOrgAuthorityName = "Demo Org Authority";
120 final String demoOrgAuthorityShortId = "demoOrgAuth";
122 Map<String, String> mmiOrgMap = new HashMap<String,String>();
123 mmiOrgMap.put(OrganizationJAXBSchema.SHORT_IDENTIFIER, "mmi");
124 mmiOrgMap.put(OrganizationJAXBSchema.SHORT_NAME, "MMI");
125 mmiOrgMap.put(OrganizationJAXBSchema.LONG_NAME, "Museum of the Moving Image");
126 //TODO: CONTACT_NAME is not in API any more. mmiOrgMap.put(OrganizationJAXBSchema.CONTACT_NAME, "Megan Forbes");
127 mmiOrgMap.put(OrganizationJAXBSchema.FOUNDING_DATE, "1984");
128 mmiOrgMap.put(OrganizationJAXBSchema.FOUNDING_PLACE, "Astoria, NY");
129 Map<String, String> pahmaOrgMap = new HashMap<String,String>();
130 pahmaOrgMap.put(OrganizationJAXBSchema.SHORT_IDENTIFIER, "pahma");
131 pahmaOrgMap.put(OrganizationJAXBSchema.SHORT_NAME, "PAHMA");
132 pahmaOrgMap.put(OrganizationJAXBSchema.LONG_NAME, "Phoebe A. Hearst Museum of Anthropology");
133 pahmaOrgMap.put(OrganizationJAXBSchema.NAME_ADDITIONS, "University of California, Berkeley");
134 //TODO: CONTACT_NAME is not in API any more. pahmaOrgMap.put(OrganizationJAXBSchema.CONTACT_NAME, "Michael Black");
135 pahmaOrgMap.put(OrganizationJAXBSchema.FOUNDING_DATE, "1901");
136 pahmaOrgMap.put(OrganizationJAXBSchema.FOUNDING_PLACE, "Berkeley, CA");
137 Map<String, String> savoyOrgMap = new HashMap<String,String>();
138 savoyOrgMap.put(OrganizationJAXBSchema.SHORT_IDENTIFIER, "savoyTh");
139 savoyOrgMap.put(OrganizationJAXBSchema.SHORT_NAME, "Savoy Theatre");
140 savoyOrgMap.put(OrganizationJAXBSchema.FOUNDING_DATE, "1900");
141 savoyOrgMap.put(OrganizationJAXBSchema.DISSOLUTION_DATE, "1952");
142 savoyOrgMap.put(OrganizationJAXBSchema.FOUNDING_PLACE, "New York, NY");
143 List<Map<String, String>> orgMaps =
144 Arrays.asList(mmiOrgMap, pahmaOrgMap, savoyOrgMap );
146 oabi.createOrgAuthority(demoOrgAuthorityName, demoOrgAuthorityShortId, orgMaps);
148 logger.info("OrgAuthorityBaseImport complete.");