1 package org.kuali.ole.ncip.servlet;
2
3 import org.kuali.ole.ncip.bo.OLECirculationErrorMessage;
4 import org.kuali.ole.ncip.bo.OLENCIPConstants;
5 import org.kuali.ole.ncip.bo.OLENCIPErrorResponse;
6 import org.kuali.ole.ncip.converter.*;
7 import org.kuali.ole.ncip.service.OLECirculationService;
8 import org.kuali.ole.ncip.service.impl.NonSip2CheckoutItemService;
9 import org.kuali.ole.ncip.service.impl.OLECirculationServiceImpl;
10 import org.apache.log4j.Logger;
11
12 import javax.servlet.ServletException;
13 import javax.servlet.http.HttpServlet;
14 import javax.servlet.http.HttpServletRequest;
15 import javax.servlet.http.HttpServletResponse;
16 import java.io.IOException;
17 import java.io.PrintWriter;
18 import java.util.HashMap;
19 import java.util.Map;
20
21
22
23
24
25
26
27
28 public class OLECirculationServlet extends HttpServlet {
29 final Logger LOG = Logger.getLogger(OLECirculationServlet.class);
30
31
32 public void doPost(HttpServletRequest request, HttpServletResponse response)
33 throws ServletException, IOException {
34 OLECirculationService oleCirculationService=new OLECirculationServiceImpl();
35 boolean doProcess=true;
36 String responseString="";
37 Map<String,String[]> parameterMap=new HashMap<String,String[]>();
38 String outputFormat=OLENCIPConstants.XML_FORMAT;
39
40 parameterMap=request.getParameterMap();
41
42 if(parameterMap.containsKey(OLENCIPConstants.FORMAT)){
43 if(parameterMap.get(OLENCIPConstants.FORMAT)[0].equalsIgnoreCase(OLENCIPConstants.XML_FORMAT) || parameterMap.get(OLENCIPConstants.FORMAT)[0].equalsIgnoreCase(OLENCIPConstants.JSON_FORMAT)){
44 outputFormat=parameterMap.get(OLENCIPConstants.FORMAT)[0];
45 }
46 else{
47 doProcess=false;
48 }
49 }
50
51 String service=parameterMap.get(OLENCIPConstants.OLE_CIRCULATION_SERVICE)[0];
52 if(service!=null){
53 if(doProcess){
54 switch (service){
55 case OLENCIPConstants.PLACEREQUEST_SERVICE:
56 if(parameterMap.containsKey(OLENCIPConstants.PATRON_BARCODE) &&
57 parameterMap.containsKey(OLENCIPConstants.OPERATOR_ID) &&
58 parameterMap.containsKey(OLENCIPConstants.ITEM_BARCODE) &&
59 parameterMap.containsKey(OLENCIPConstants.REQUEST_TYPE)){
60 int size=5;
61 if(parameterMap.containsKey(OLENCIPConstants.FORMAT)){
62 size++;
63 }
64 if(parameterMap.containsKey(OLENCIPConstants.PICKUP_LOCATION))
65 {
66 size++;
67 }
68 if(parameterMap.size()==size){
69 String pickupLocation=null;
70 if(parameterMap.containsKey(OLENCIPConstants.PICKUP_LOCATION)) {
71 pickupLocation=parameterMap.get(OLENCIPConstants.PICKUP_LOCATION)[0];
72 }
73 responseString=oleCirculationService.placeRequest(parameterMap.get(OLENCIPConstants.PATRON_BARCODE)[0],parameterMap.get(OLENCIPConstants.OPERATOR_ID)[0],parameterMap.get(OLENCIPConstants.ITEM_BARCODE)[0],parameterMap.get(OLENCIPConstants.REQUEST_TYPE)[0],pickupLocation,null,null,"Item Level",null);
74 if(outputFormat.equalsIgnoreCase(OLENCIPConstants.JSON_FORMAT)){
75 responseString=new OLEPlaceRequestConverter().generatePlaceRequestJson(responseString);
76 }
77 if(responseString==null){
78 OLENCIPErrorResponse olencipErrorResponse=new OLENCIPErrorResponse();
79 olencipErrorResponse.getErrorMap().put(OLENCIPConstants.PATRON_BARCODE,parameterMap.get(OLENCIPConstants.PATRON_BARCODE)[0]);
80 olencipErrorResponse.getErrorMap().put(OLENCIPConstants.OPERATOR_ID,parameterMap.get(OLENCIPConstants.OPERATOR_ID)[0]);
81 olencipErrorResponse.getErrorMap().put(OLENCIPConstants.MESSAGE,OLENCIPConstants.INVALID_INPUT);
82 responseString=olencipErrorResponse.getErrorXml(service);
83 }
84 }else{
85 responseString=getCirculationErrorMessage(service,OLENCIPConstants.INVALID_PARAMETERS,"501", OLENCIPConstants.PLACEREQUEST,outputFormat);
86 }
87 }else{
88 responseString=getCirculationErrorMessage(service,OLENCIPConstants.PARAMETER_MISSING,"502",OLENCIPConstants.PLACEREQUEST,outputFormat);
89 }
90 break;
91 case OLENCIPConstants.CANCELREQUEST_SERVICE:
92 if(parameterMap.containsKey(OLENCIPConstants.OPERATOR_ID) &&
93 parameterMap.containsKey(OLENCIPConstants.REQUEST_ID)){
94 if(parameterMap.size()==3 || parameterMap.size()==4){
95 responseString=oleCirculationService.cancelRequests(parameterMap.get(OLENCIPConstants.OPERATOR_ID)[0],parameterMap.get(OLENCIPConstants.REQUEST_ID)[0]);
96 if(outputFormat.equalsIgnoreCase(OLENCIPConstants.JSON_FORMAT)){
97 responseString=new OLECancelRequestConverter().generateCancelRequestJson(responseString);
98 }
99 if(responseString==null){
100 OLENCIPErrorResponse olencipErrorResponse=new OLENCIPErrorResponse();
101 olencipErrorResponse.getErrorMap().put(OLENCIPConstants.OPERATOR_ID,parameterMap.get(OLENCIPConstants.OPERATOR_ID)[0]);
102 olencipErrorResponse.getErrorMap().put(OLENCIPConstants.REQUEST_ID,parameterMap.get(OLENCIPConstants.REQUEST_ID)[0]);
103 olencipErrorResponse.getErrorMap().put(OLENCIPConstants.MESSAGE,OLENCIPConstants.INVALID_INPUT);
104 responseString=olencipErrorResponse.getErrorXml(service);
105 }
106 }else{
107 responseString=getCirculationErrorMessage(service,OLENCIPConstants.INVALID_PARAMETERS,"501",OLENCIPConstants.CANCELREQUEST,outputFormat);
108 }
109 }else{
110 responseString=getCirculationErrorMessage(service,OLENCIPConstants.PARAMETER_MISSING,"502",OLENCIPConstants.CANCELREQUEST,outputFormat);
111 }
112 break;
113 case OLENCIPConstants.RENEWITEM_SERVICE:
114 if(parameterMap.containsKey(OLENCIPConstants.PATRON_BARCODE) &&
115 parameterMap.containsKey(OLENCIPConstants.OPERATOR_ID) &&
116 parameterMap.containsKey(OLENCIPConstants.ITEM_BARCODE)){
117 if(parameterMap.size()==4 || parameterMap.size()==5){
118 responseString=oleCirculationService.renewItem(parameterMap.get(OLENCIPConstants.PATRON_BARCODE)[0],parameterMap.get(OLENCIPConstants.OPERATOR_ID)[0],parameterMap.get(OLENCIPConstants.ITEM_BARCODE)[0],false);
119 if(outputFormat.equalsIgnoreCase(OLENCIPConstants.JSON_FORMAT)){
120 responseString=new OLERenewItemConverter().generateRenewItemJson(responseString);
121 }
122 if(responseString==null){
123 OLENCIPErrorResponse olencipErrorResponse=new OLENCIPErrorResponse();
124 olencipErrorResponse.getErrorMap().put(OLENCIPConstants.PATRON_BARCODE,parameterMap.get(OLENCIPConstants.PATRON_BARCODE)[0]);
125 olencipErrorResponse.getErrorMap().put(OLENCIPConstants.OPERATOR_ID,parameterMap.get(OLENCIPConstants.OPERATOR_ID)[0]);
126 olencipErrorResponse.getErrorMap().put(OLENCIPConstants.MESSAGE,responseString);
127 responseString=olencipErrorResponse.getErrorXml(service);
128 }
129 }else{
130 responseString=getCirculationErrorMessage(service,OLENCIPConstants.INVALID_PARAMETERS,"501",OLENCIPConstants.RENEWITEM,outputFormat);
131 }
132 }else{
133 responseString=getCirculationErrorMessage(service,OLENCIPConstants.PARAMETER_MISSING,"502",OLENCIPConstants.RENEWITEM,outputFormat);
134 }
135 break;
136 case OLENCIPConstants.RENEWITEMLIST_SERVICE:
137 if(parameterMap.containsKey(OLENCIPConstants.PATRON_BARCODE) &&
138 parameterMap.containsKey(OLENCIPConstants.OPERATOR_ID) &&
139 parameterMap.containsKey(OLENCIPConstants.ITEM_BARCODE)){
140 if(parameterMap.size()==4 || parameterMap.size()==5){
141 Long startingTime = System.currentTimeMillis();
142 responseString=oleCirculationService.renewItemList(parameterMap.get(OLENCIPConstants.PATRON_BARCODE)[0], parameterMap.get(OLENCIPConstants.OPERATOR_ID)[0], parameterMap.get(OLENCIPConstants.ITEM_BARCODE)[0], false);
143 Long endTimme = System.currentTimeMillis();
144 Long timeTakenForRenewAll = endTimme-startingTime;
145 LOG.info("The Time Taken for RenewAll : "+timeTakenForRenewAll);
146 if(outputFormat.equalsIgnoreCase(OLENCIPConstants.JSON_FORMAT)){
147 responseString=new OLERenewItemConverter().generateRenewItemListJson(responseString);
148 }
149 if(responseString==null){
150 OLENCIPErrorResponse olencipErrorResponse=new OLENCIPErrorResponse();
151 olencipErrorResponse.getErrorMap().put(OLENCIPConstants.PATRON_BARCODE,parameterMap.get(OLENCIPConstants.PATRON_BARCODE)[0]);
152 olencipErrorResponse.getErrorMap().put(OLENCIPConstants.OPERATOR_ID,parameterMap.get(OLENCIPConstants.OPERATOR_ID)[0]);
153 olencipErrorResponse.getErrorMap().put(OLENCIPConstants.MESSAGE,responseString);
154 responseString=olencipErrorResponse.getErrorXml(service);
155 }
156 }else{
157 responseString=getCirculationErrorMessage(service,OLENCIPConstants.INVALID_PARAMETERS,"501",OLENCIPConstants.RENEWITEM,outputFormat);
158 }
159 }else{
160 responseString=getCirculationErrorMessage(service,OLENCIPConstants.PARAMETER_MISSING,"502",OLENCIPConstants.RENEWITEM,outputFormat);
161 }
162 break;
163 case OLENCIPConstants.ACCEPTITEM_SERVICE:
164 if(parameterMap.containsKey(OLENCIPConstants.PATRON_BARCODE) &&
165 parameterMap.containsKey(OLENCIPConstants.OPERATOR_ID) &&
166 parameterMap.containsKey(OLENCIPConstants.ITEM_BARCODE) &&
167 parameterMap.containsKey(OLENCIPConstants.CALLNUMBER) &&
168 parameterMap.containsKey(OLENCIPConstants.TITLE) &&
169 parameterMap.containsKey(OLENCIPConstants.AUTHOR) &&
170 parameterMap.containsKey(OLENCIPConstants.ITEM_TYPE) &&
171 parameterMap.containsKey(OLENCIPConstants.ITEM_LOCATION) &&
172 parameterMap.containsKey(OLENCIPConstants.DATE_EXPIRES) &&
173 parameterMap.containsKey(OLENCIPConstants.REQUEST_TYPE)){
174 int size=11;
175 if(parameterMap.containsKey(OLENCIPConstants.FORMAT)){
176 size++;
177 }
178 if(parameterMap.containsKey(OLENCIPConstants.PICKUP_LOCATION))
179 {
180 size++;
181 }
182
183 if(parameterMap.size()==size){
184 String pickupLocation=null;
185 if(parameterMap.containsKey(OLENCIPConstants.PICKUP_LOCATION)) {
186 pickupLocation=parameterMap.get(OLENCIPConstants.PICKUP_LOCATION)[0];
187 }
188 responseString=oleCirculationService.acceptItem(parameterMap.get(OLENCIPConstants.PATRON_BARCODE)[0],parameterMap.get(OLENCIPConstants.OPERATOR_ID)[0],parameterMap.get(OLENCIPConstants.ITEM_BARCODE)[0],parameterMap.get(OLENCIPConstants.CALLNUMBER)[0],parameterMap.get(OLENCIPConstants.TITLE)[0],parameterMap.get(OLENCIPConstants.AUTHOR)[0],parameterMap.get(OLENCIPConstants.ITEM_TYPE)[0],parameterMap.get(OLENCIPConstants.ITEM_LOCATION)[0],parameterMap.get(OLENCIPConstants.DATE_EXPIRES)[0],parameterMap.get(OLENCIPConstants.REQUEST_TYPE)[0],pickupLocation);
189 if(outputFormat.equalsIgnoreCase(OLENCIPConstants.JSON_FORMAT)){
190 responseString=new OLEAcceptItemConverter().generateAcceptItemJson(responseString);
191 }
192 if(responseString==null){
193 OLENCIPErrorResponse olencipErrorResponse=new OLENCIPErrorResponse();
194 olencipErrorResponse.getErrorMap().put(OLENCIPConstants.PATRON_BARCODE,parameterMap.get(OLENCIPConstants.PATRON_BARCODE)[0]);
195 olencipErrorResponse.getErrorMap().put(OLENCIPConstants.OPERATOR_ID,parameterMap.get(OLENCIPConstants.OPERATOR_ID)[0]);
196 olencipErrorResponse.getErrorMap().put(OLENCIPConstants.MESSAGE,OLENCIPConstants.INVALID_INPUT);
197 responseString=olencipErrorResponse.getErrorXml(service);
198 }
199 }else{
200 responseString=getCirculationErrorMessage(service,OLENCIPConstants.INVALID_PARAMETERS,"501",OLENCIPConstants.ACCEPTITEM,outputFormat);
201 }
202 }else{
203 responseString=getCirculationErrorMessage(service,OLENCIPConstants.PARAMETER_MISSING,"502",OLENCIPConstants.ACCEPTITEM,outputFormat);
204 }
205 break;
206 case OLENCIPConstants.CHECKINITEM_SERVICE:
207 if(parameterMap.containsKey(OLENCIPConstants.PATRON_BARCODE) &&
208 parameterMap.containsKey(OLENCIPConstants.OPERATOR_ID) &&
209 parameterMap.containsKey(OLENCIPConstants.ITEM_BARCODE) &&
210 parameterMap.containsKey(OLENCIPConstants.DELETE_INDICATOR)){
211 if(parameterMap.size()==5 || parameterMap.size()==6){
212 responseString=oleCirculationService.checkInItem(parameterMap.get(OLENCIPConstants.PATRON_BARCODE)[0],parameterMap.get(OLENCIPConstants.OPERATOR_ID)[0],parameterMap.get(OLENCIPConstants.ITEM_BARCODE)[0],parameterMap.get(OLENCIPConstants.DELETE_INDICATOR)[0],false);
213 if(outputFormat.equalsIgnoreCase(OLENCIPConstants.JSON_FORMAT)){
214 responseString=new OLECheckInItemConverter().generateCheckInItemJson(responseString);
215 }
216 if(responseString==null){
217 OLENCIPErrorResponse olencipErrorResponse=new OLENCIPErrorResponse();
218 olencipErrorResponse.getErrorMap().put(OLENCIPConstants.PATRON_BARCODE,parameterMap.get(OLENCIPConstants.PATRON_BARCODE)[0]);
219 olencipErrorResponse.getErrorMap().put(OLENCIPConstants.OPERATOR_ID,parameterMap.get(OLENCIPConstants.OPERATOR_ID)[0]);
220 olencipErrorResponse.getErrorMap().put(OLENCIPConstants.MESSAGE,OLENCIPConstants.INVALID_INPUT);
221 responseString=olencipErrorResponse.getErrorXml(service);
222 }
223 }else{
224 responseString=getCirculationErrorMessage(service,OLENCIPConstants.INVALID_PARAMETERS,"501",OLENCIPConstants.CHECKINITEM,outputFormat);
225
226 }
227 }else{
228 responseString=getCirculationErrorMessage(service,OLENCIPConstants.PARAMETER_MISSING,"502",OLENCIPConstants.CHECKINITEM,outputFormat);
229 }
230 break;
231 case OLENCIPConstants.CHECKOUTITEM_SERVICE:
232 if(parameterMap.containsKey(OLENCIPConstants.PATRON_BARCODE) &&
233 parameterMap.containsKey(OLENCIPConstants.OPERATOR_ID) &&
234 parameterMap.containsKey(OLENCIPConstants.ITEM_BARCODE)){
235 if(parameterMap.size()==4 || parameterMap.size()==5){
236
237 Map checoutParameters = new HashMap();
238 checoutParameters.put("patronBarcode", parameterMap.get(OLENCIPConstants.PATRON_BARCODE)[0]);
239 checoutParameters.put("operatorId", parameterMap.get(OLENCIPConstants.OPERATOR_ID)[0]);
240 checoutParameters.put("itemBarcode", parameterMap.get(OLENCIPConstants.ITEM_BARCODE)[0]);
241 checoutParameters.put("responseFormatType", outputFormat);
242 responseString = new NonSip2CheckoutItemService().checkoutItem(checoutParameters);
243
244 if(responseString==null){
245 OLENCIPErrorResponse olencipErrorResponse=new OLENCIPErrorResponse();
246 olencipErrorResponse.getErrorMap().put(OLENCIPConstants.PATRON_BARCODE,parameterMap.get(OLENCIPConstants.PATRON_BARCODE)[0]);
247 olencipErrorResponse.getErrorMap().put(OLENCIPConstants.OPERATOR_ID,parameterMap.get(OLENCIPConstants.OPERATOR_ID)[0]);
248 olencipErrorResponse.getErrorMap().put(OLENCIPConstants.MESSAGE,OLENCIPConstants.INVALID_INPUT);
249 responseString=olencipErrorResponse.getErrorXml(service);
250 }
251 }else{
252 responseString=getCirculationErrorMessage(service,OLENCIPConstants.INVALID_PARAMETERS,"501",OLENCIPConstants.CHECKOUTITEM,outputFormat);
253 }
254 }else{
255 responseString=getCirculationErrorMessage(service,OLENCIPConstants.PARAMETER_MISSING,"502",OLENCIPConstants.CHECKOUTITEM,outputFormat);
256 }
257
258 break;
259 default:
260 LOG.info("Unknown Service Name: "+service+" Parameter is missing");
261 responseString=getCirculationErrorMessage(service,OLENCIPConstants.UNKNOWN_SERVICE,"503",null,outputFormat);
262 response.sendError(405,"Method Not Supported");
263 }
264 }else{
265 responseString=getCirculationErrorMessage(service,OLENCIPConstants.INVALID_FORMAT,"504",null,outputFormat);
266 }
267 }
268 else{
269 responseString=OLENCIPConstants.NULL_SERVICE;
270 }
271
272 LOG.info("Response :"+responseString);
273 if(responseString==null){
274 responseString=OLENCIPConstants.INVALID_DATA;
275 }
276 if(responseString!=null){
277 responseString=responseString.replaceAll("errorMessage",OLENCIPConstants.MESSAGE);
278 responseString=responseString.replaceAll("<br/>","");
279 }
280 responseString=responseString.replaceAll("errorMessage",OLENCIPConstants.MESSAGE);
281 PrintWriter out=response.getWriter();
282 response.setContentType(OLENCIPConstants.XML_CONTENT_TYPE);
283 response.setCharacterEncoding(OLENCIPConstants.XML_CHAR_ENCODING);
284 if(responseString.contains(OLENCIPConstants.INVALID_FORMAT)){
285 response.setStatus(406);
286 } else if(responseString.contains(OLENCIPConstants.PARAMETER_MISSING)){
287 response.setStatus(422);
288 }else{
289 response.setStatus(200);
290 }
291 out.write(responseString);
292 }
293
294 public void doGet(HttpServletRequest request, HttpServletResponse response)
295 throws ServletException, IOException {
296 OLECirculationService oleCirculationService=new OLECirculationServiceImpl();
297
298 String responseString="";
299 boolean doProcess=true;
300 Map<String,String[]> parameterMap=new HashMap<String,String[]>();
301 String outputFormat=OLENCIPConstants.XML_FORMAT;
302 String service=null;
303
304 parameterMap=request.getParameterMap();
305 if(parameterMap.containsKey(OLENCIPConstants.FORMAT)){
306 if(parameterMap.get(OLENCIPConstants.FORMAT)[0].equalsIgnoreCase(OLENCIPConstants.XML_FORMAT) || parameterMap.get(OLENCIPConstants.FORMAT)[0].equalsIgnoreCase(OLENCIPConstants.JSON_FORMAT)){
307 outputFormat=parameterMap.get(OLENCIPConstants.FORMAT)[0];
308 }
309 else{
310 doProcess=false;
311 }
312 }
313 if(parameterMap.containsKey(OLENCIPConstants.OLE_CIRCULATION_SERVICE)){
314 service=parameterMap.get(OLENCIPConstants.OLE_CIRCULATION_SERVICE)[0];
315 }
316
317 if(service!=null){
318 if(doProcess){
319 if(service.equals(OLENCIPConstants.LOOKUPUSER_SERVICE)){
320 if(parameterMap.containsKey(OLENCIPConstants.PATRON_BARCODE) &&
321 parameterMap.containsKey(OLENCIPConstants.OPERATOR_ID)){
322 if(parameterMap.size()==3 || parameterMap.size()==4){
323 responseString=oleCirculationService.lookupUser(parameterMap.get(OLENCIPConstants.PATRON_BARCODE)[0],parameterMap.get(OLENCIPConstants.OPERATOR_ID)[0],null, false);
324 if(outputFormat.equalsIgnoreCase(OLENCIPConstants.JSON_FORMAT)){
325 responseString=new OLELookupUserConverter().generateLookupUserJson(responseString);
326 }
327 if(responseString==null){
328 OLENCIPErrorResponse olencipErrorResponse=new OLENCIPErrorResponse();
329 olencipErrorResponse.getErrorMap().put(OLENCIPConstants.PATRON_BARCODE,parameterMap.get(OLENCIPConstants.PATRON_BARCODE)[0]);
330 olencipErrorResponse.getErrorMap().put(OLENCIPConstants.OPERATOR_ID,parameterMap.get(OLENCIPConstants.OPERATOR_ID)[0]);
331 responseString=olencipErrorResponse.getErrorXml(service);
332 }
333
334 }else{
335 responseString=getCirculationErrorMessage(service,OLENCIPConstants.INVALID_PARAMETERS,"501",OLENCIPConstants.LOOKUPUSER,outputFormat);
336 }
337
338
339 }else{
340 responseString=getCirculationErrorMessage(service,OLENCIPConstants.PARAMETER_MISSING,"502",OLENCIPConstants.LOOKUPUSER,outputFormat);
341 }
342 }
343 else if(service.equals(OLENCIPConstants.GETCHECKEDOUTITEM_SERVICE)){
344 if(parameterMap.containsKey(OLENCIPConstants.PATRON_BARCODE) &&
345 parameterMap.containsKey(OLENCIPConstants.OPERATOR_ID)){
346 if(parameterMap.size()==3 || parameterMap.size()==4){
347 try {
348 responseString=oleCirculationService.getCheckedOutItems(parameterMap.get(OLENCIPConstants.PATRON_BARCODE)[0],parameterMap.get(OLENCIPConstants.OPERATOR_ID)[0]);
349 if(outputFormat.equalsIgnoreCase(OLENCIPConstants.JSON_FORMAT)){
350 responseString=new OLECheckoutItemsConverter().generateGetCheckedOutItemsJson(responseString);
351 System.out.println(responseString);
352 }
353 if(responseString==null){
354 OLENCIPErrorResponse olencipErrorResponse=new OLENCIPErrorResponse();
355 olencipErrorResponse.getErrorMap().put(OLENCIPConstants.PATRON_BARCODE,parameterMap.get(OLENCIPConstants.PATRON_BARCODE)[0]);
356 olencipErrorResponse.getErrorMap().put(OLENCIPConstants.OPERATOR_ID,parameterMap.get(OLENCIPConstants.OPERATOR_ID)[0]);
357 olencipErrorResponse.getErrorMap().put(OLENCIPConstants.MESSAGE,OLENCIPConstants.INVALID_INPUT);
358 responseString=olencipErrorResponse.getErrorXml(service);
359 }
360 } catch (Exception e) {
361 LOG.error(e,e);
362 }
363 }else{
364 responseString=getCirculationErrorMessage(service,OLENCIPConstants.INVALID_PARAMETERS,"501",OLENCIPConstants.GETCHECKOUTITEMS,outputFormat);
365 }
366 }else{
367 responseString=getCirculationErrorMessage(service,OLENCIPConstants.PARAMETER_MISSING,"502",OLENCIPConstants.GETCHECKOUTITEMS,outputFormat);
368 }
369 }
370 else if(service.equals(OLENCIPConstants.FINE_SERVICE)){
371 if(parameterMap.containsKey(OLENCIPConstants.PATRON_BARCODE) &&
372 parameterMap.containsKey(OLENCIPConstants.OPERATOR_ID)){
373 if(parameterMap.size()==3 || parameterMap.size()==4){
374 try {
375 responseString=oleCirculationService.getFine(parameterMap.get(OLENCIPConstants.PATRON_BARCODE)[0], parameterMap.get(OLENCIPConstants.OPERATOR_ID)[0]);
376 if(outputFormat.equalsIgnoreCase(OLENCIPConstants.JSON_FORMAT)){
377 responseString=new OLEItemFineConverter().generateFineJson(responseString);
378 System.out.println(responseString);
379 }
380 if(responseString==null){
381 OLENCIPErrorResponse olencipErrorResponse=new OLENCIPErrorResponse();
382 olencipErrorResponse.getErrorMap().put(OLENCIPConstants.PATRON_BARCODE,parameterMap.get(OLENCIPConstants.PATRON_BARCODE)[0]);
383 olencipErrorResponse.getErrorMap().put(OLENCIPConstants.OPERATOR_ID,parameterMap.get(OLENCIPConstants.OPERATOR_ID)[0]);
384 olencipErrorResponse.getErrorMap().put(OLENCIPConstants.MESSAGE,OLENCIPConstants.INVALID_INPUT);
385 responseString=olencipErrorResponse.getErrorXml(service);
386 }
387 } catch (Exception e) {
388 LOG.error(e,e);
389 }
390 }else{
391 responseString=getCirculationErrorMessage(service,OLENCIPConstants.INVALID_PARAMETERS,"501",OLENCIPConstants.FINE,outputFormat);
392 }
393 }else{
394 responseString=getCirculationErrorMessage(service,OLENCIPConstants.PARAMETER_MISSING,"502",OLENCIPConstants.FINE,outputFormat);
395 }
396 }
397 else if(service.equals(OLENCIPConstants.HOLDS_SERVICE)){
398 if(parameterMap.containsKey(OLENCIPConstants.PATRON_BARCODE) &&
399 parameterMap.containsKey(OLENCIPConstants.OPERATOR_ID)){
400 if(parameterMap.size()==3 || parameterMap.size()==4){
401 try {
402 responseString=oleCirculationService.getHolds(parameterMap.get(OLENCIPConstants.PATRON_BARCODE)[0], parameterMap.get(OLENCIPConstants.OPERATOR_ID)[0]);
403 if(outputFormat.equalsIgnoreCase(OLENCIPConstants.JSON_FORMAT)){
404 responseString=new OLEHoldsConverter().generateHoldsJson(responseString);
405 System.out.println(responseString);
406 }
407 if(responseString==null){
408 OLENCIPErrorResponse olencipErrorResponse=new OLENCIPErrorResponse();
409 olencipErrorResponse.getErrorMap().put(OLENCIPConstants.PATRON_BARCODE,parameterMap.get(OLENCIPConstants.PATRON_BARCODE)[0]);
410 olencipErrorResponse.getErrorMap().put(OLENCIPConstants.OPERATOR_ID,parameterMap.get(OLENCIPConstants.OPERATOR_ID)[0]);
411 olencipErrorResponse.getErrorMap().put(OLENCIPConstants.MESSAGE,OLENCIPConstants.INVALID_INPUT);
412 responseString=olencipErrorResponse.getErrorXml(service);
413 }
414 } catch (Exception e) {
415 LOG.error(e,e);
416 }
417 }else{
418 responseString=getCirculationErrorMessage(service,OLENCIPConstants.INVALID_PARAMETERS,"501",OLENCIPConstants.HOLDS,outputFormat);
419 }
420 }else{
421 responseString=getCirculationErrorMessage(service,OLENCIPConstants.PARAMETER_MISSING,"502",OLENCIPConstants.HOLDS,outputFormat);
422 }
423 }
424 else{
425 LOG.info("Unknown Service Name: "+service+" Parameter is missing");
426 responseString=getCirculationErrorMessage(service,OLENCIPConstants.UNKNOWN_SERVICE,"503",null,outputFormat);
427 response.sendError(405,"Method Not Supported");
428 }
429 }
430 else{
431 responseString=getCirculationErrorMessage(service,OLENCIPConstants.INVALID_FORMAT,"504",null,outputFormat);
432 }
433 }
434 else{
435 responseString=OLENCIPConstants.NULL_SERVICE;
436 }
437 if(responseString!=null){
438 responseString=responseString.replaceAll("errorMessage",OLENCIPConstants.MESSAGE);
439 responseString=responseString.replaceAll("<br/>","");
440 }
441 PrintWriter out=response.getWriter();
442 if(outputFormat.equalsIgnoreCase(OLENCIPConstants.XML_FORMAT)){
443 response.setContentType(OLENCIPConstants.XML_CONTENT_TYPE);
444 response.setCharacterEncoding(OLENCIPConstants.XML_CHAR_ENCODING);
445
446 }
447 if(responseString.contains(OLENCIPConstants.INVALID_FORMAT)){
448 response.setStatus(406);
449 } else if(responseString.contains(OLENCIPConstants.PARAMETER_MISSING)){
450 response.setStatus(422);
451 }else{
452 response.setStatus(200);
453 }
454
455
456 out.write(responseString);
457
458 }
459
460
461 private String getCirculationErrorMessage(String service,String message,String code,String requiredParameters,String outputFormat){
462 OLECirculationErrorMessage oleCirculationErrorMessage=new OLECirculationErrorMessage();
463 OLECirculationErrorMessageConverter oleCirculationErrorMessageConverter=new OLECirculationErrorMessageConverter();
464 oleCirculationErrorMessage.setMessage(message);
465 oleCirculationErrorMessage.setCode(code);
466 oleCirculationErrorMessage.setService(service);
467 oleCirculationErrorMessage.setRequiredParameters(requiredParameters);
468 String errorMessage="";
469 errorMessage=oleCirculationErrorMessageConverter.generateCirculationErrorXml(oleCirculationErrorMessage);
470 if(outputFormat.equalsIgnoreCase(OLENCIPConstants.JSON_FORMAT)){
471 errorMessage=oleCirculationErrorMessageConverter.generateLookupUserJson(errorMessage);
472 }
473 return errorMessage;
474 }
475 }