]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
1e26c688056ee67cdbd82990090bada84696596c
[tmp/jakarta-migration.git] /
1 /**
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:
5  *
6  * http://www.collectionspace.org
7  * http://wiki.collectionspace.org
8  *
9  * Copyright (c)) 2009 Regents of the University of California
10  *
11  * Licensed under the Educational Community License (ECL), Version 2.0.
12  * You may not use this file except in compliance with this License.
13  *
14  * You may obtain a copy of the ECL 2.0 License at
15  * https://source.collectionspace.org/collection-space/LICENSE.txt
16  *
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.
22  */
23 package org.collectionspace.services.vocabulary.importer;
24
25 import java.util.Arrays;
26 import java.util.HashMap;
27 import java.util.List;
28
29 import javax.ws.rs.core.Response;
30
31 import org.collectionspace.services.common.vocabulary.AuthorityItemJAXBSchema;
32 import org.collectionspace.services.client.PoxPayloadOut;
33 import org.collectionspace.services.client.VocabularyClient;
34 import org.collectionspace.services.client.VocabularyClientUtils;
35 import org.collectionspace.services.client.test.ServiceRequestType;
36 import org.jboss.resteasy.client.ClientResponse;
37 import org.slf4j.Logger;
38 import org.slf4j.LoggerFactory;
39
40 /**
41  * VocabularyServiceTest, carries out tests against a
42  * deployed and running Vocabulary Service.
43  *
44  * $LastChangedRevision: 753 $
45  * $LastChangedDate: 2009-09-23 11:03:36 -0700 (Wed, 23 Sep 2009) $
46  */
47 public class VocabularyBaseImport {
48
49     private static final Logger logger =
50             LoggerFactory.getLogger(VocabularyBaseImport.class);
51     // Instance variables specific to this test.
52     private VocabularyClient client = new VocabularyClient();
53     final String SERVICE_PATH_COMPONENT = "vocabularies";
54     final String ITEM_SERVICE_PATH_COMPONENT = "items";
55
56     public void createEnumeration(String vocabDisplayName, String shortName, List<String> enumValues) {
57
58         // Expected status code: 201 Created
59         int EXPECTED_STATUS_CODE = Response.Status.CREATED.getStatusCode();
60         // Type of service request being tested
61         ServiceRequestType REQUEST_TYPE = ServiceRequestType.CREATE;
62
63         if (logger.isDebugEnabled()) {
64             logger.debug("Import: Create vocabulary: \"" + vocabDisplayName + "\"");
65         }
66         String baseVocabRefName = VocabularyClientUtils.createVocabularyRefName(shortName, null);
67         PoxPayloadOut multipart = VocabularyClientUtils.createEnumerationInstance(
68                         vocabDisplayName, shortName, client.getCommonPartName());
69         ClientResponse<Response> res = client.create(multipart);
70
71         int statusCode = res.getStatus();
72
73         if (!REQUEST_TYPE.isValidStatusCode(statusCode)) {
74             throw new RuntimeException("Could not create enumeration: \"" + vocabDisplayName
75                     + "\" " + VocabularyClientUtils.invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
76         }
77         if (statusCode != EXPECTED_STATUS_CODE) {
78             throw new RuntimeException("Unexpected Status when creating enumeration: \""
79                     + vocabDisplayName + "\", Status:" + statusCode);
80         }
81
82         // Store the ID returned from this create operation
83         // for additional tests below.
84         String newVocabId = VocabularyClientUtils.extractId(res);
85         if (logger.isDebugEnabled()) {
86             logger.debug("Import: Created vocabulary: \"" + vocabDisplayName + "\" ID:"
87                     + newVocabId);
88         }
89         for (String itemName : enumValues) {
90             HashMap<String, String> itemInfo = new HashMap<String, String>();
91             itemInfo.put(AuthorityItemJAXBSchema.DISPLAY_NAME, itemName);
92             VocabularyClientUtils.createItemInVocabulary(newVocabId,
93                     baseVocabRefName, itemInfo, client);
94         }
95     }
96
97     public static void main(String[] args) {
98
99         logger.info("VocabularyBaseImport starting...");
100
101         VocabularyBaseImport vbi = new VocabularyBaseImport();
102         final String acquisitionMethodsVocabName = "Acquisition Methods";
103         final String entryMethodsVocabName = "Entry Methods";
104         final String entryReasonsVocabName = "Entry Reasons";
105         final String responsibleDeptsVocabName = "Responsible Departments";
106         final String termStatusVocabName = "Term Status";
107         
108         final String acquisitionMethodsShortName = "acqMethods";
109         final String entryMethodsShortName = "entryMethods";
110         final String entryReasonsShortName = "entryReasons";
111         final String responsibleDeptsShortName = "responsibleDepts";
112         final String termStatusShortName = "termStatus";
113
114         List<String> acquisitionMethodsEnumValues =
115                 Arrays.asList("Gift", "Purchase", "Exchange", "Transfer", "Treasure");
116         List<String> entryMethodsEnumValues =
117                 Arrays.asList("In person", "Post", "Found on doorstep");
118         List<String> entryReasonsEnumValues =
119                 Arrays.asList("Enquiry", "Commission", "Loan");
120         List<String> respDeptNamesEnumValues =
121                 Arrays.asList("Antiquities", "Architecture and Design", "Decorative Arts",
122                 "Ethnography", "Herpetology", "Media and Performance Art",
123                 "Paintings and Sculpture", "Paleobotany", "Photographs",
124                 "Prints and Drawings");
125         List<String> termStatusEnumValues =
126                 Arrays.asList("Provisional", "Under Review", "Accepted", "Rejected");
127
128         vbi.createEnumeration(acquisitionMethodsVocabName, acquisitionMethodsShortName, acquisitionMethodsEnumValues);
129         vbi.createEnumeration(entryMethodsVocabName, entryMethodsShortName, entryMethodsEnumValues);
130         vbi.createEnumeration(entryReasonsVocabName, entryReasonsShortName, entryReasonsEnumValues);
131         vbi.createEnumeration(responsibleDeptsVocabName, responsibleDeptsShortName, respDeptNamesEnumValues);
132         vbi.createEnumeration(termStatusVocabName, termStatusShortName, termStatusEnumValues);
133
134         logger.info("VocabularyBaseImport complete.");
135     }
136 }