1 package org.kuali.ole.ncip.servlet;
2
3 import org.kuali.ole.OLEConstants;
4 import org.kuali.ole.ncip.bo.OLECirculationErrorMessage;
5 import org.kuali.ole.ncip.bo.OLENCIPConstants;
6 import org.kuali.ole.ncip.bo.OLENCIPErrorResponse;
7 import org.kuali.ole.ncip.converter.*;
8 import org.kuali.ole.ncip.service.OLECirculationService;
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,null,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 responseString=oleCirculationService.checkOutItem(parameterMap.get(OLENCIPConstants.PATRON_BARCODE)[0],parameterMap.get(OLENCIPConstants.OPERATOR_ID)[0],parameterMap.get(OLENCIPConstants.ITEM_BARCODE)[0],false);
237 if(outputFormat.equalsIgnoreCase(OLENCIPConstants.JSON_FORMAT)){
238 responseString=new OLECheckOutItemConverter().generateCheckOutItemJson(responseString);
239 }
240 if(responseString==null){
241 OLENCIPErrorResponse olencipErrorResponse=new OLENCIPErrorResponse();
242 olencipErrorResponse.getErrorMap().put(OLENCIPConstants.PATRON_BARCODE,parameterMap.get(OLENCIPConstants.PATRON_BARCODE)[0]);
243 olencipErrorResponse.getErrorMap().put(OLENCIPConstants.OPERATOR_ID,parameterMap.get(OLENCIPConstants.OPERATOR_ID)[0]);
244 olencipErrorResponse.getErrorMap().put(OLENCIPConstants.MESSAGE,OLENCIPConstants.INVALID_INPUT);
245 responseString=olencipErrorResponse.getErrorXml(service);
246 }
247 }else{
248 responseString=getCirculationErrorMessage(service,OLENCIPConstants.INVALID_PARAMETERS,"501",OLENCIPConstants.CHECKOUTITEM,outputFormat);
249 }
250 }else{
251 responseString=getCirculationErrorMessage(service,OLENCIPConstants.PARAMETER_MISSING,"502",OLENCIPConstants.CHECKOUTITEM,outputFormat);
252 }
253
254 break;
255 default:
256 LOG.info("Unknown Service Name: "+service+" Parameter is missing");
257 responseString=getCirculationErrorMessage(service,OLENCIPConstants.UNKNOWN_SERVICE,"503",null,outputFormat);
258 response.sendError(405,"Method Not Supported");
259 }
260 }else{
261 responseString=getCirculationErrorMessage(service,OLENCIPConstants.INVALID_FORMAT,"504",null,outputFormat);
262 }
263 }
264 else{
265 responseString=OLENCIPConstants.NULL_SERVICE;
266 }
267
268 LOG.info("Response :"+responseString);
269 if(responseString==null){
270 responseString=OLENCIPConstants.INVALID_DATA;
271 }
272 if(responseString!=null){
273 responseString=responseString.replaceAll("errorMessage",OLENCIPConstants.MESSAGE);
274 responseString=responseString.replaceAll("<br/>","");
275 }
276 responseString=responseString.replaceAll("errorMessage",OLENCIPConstants.MESSAGE);
277 PrintWriter out=response.getWriter();
278 response.setContentType(OLENCIPConstants.XML_CONTENT_TYPE);
279 response.setCharacterEncoding(OLENCIPConstants.XML_CHAR_ENCODING);
280 if(responseString.contains(OLENCIPConstants.INVALID_FORMAT)){
281 response.setStatus(406);
282 } else if(responseString.contains(OLENCIPConstants.PARAMETER_MISSING)){
283 response.setStatus(422);
284 }else{
285 response.setStatus(200);
286 }
287 out.write(responseString);
288 }
289
290 public void doGet(HttpServletRequest request, HttpServletResponse response)
291 throws ServletException, IOException {
292 OLECirculationService oleCirculationService=new OLECirculationServiceImpl();
293
294 String responseString="";
295 boolean doProcess=true;
296 Map<String,String[]> parameterMap=new HashMap<String,String[]>();
297 String outputFormat=OLENCIPConstants.XML_FORMAT;
298 String service=null;
299
300 parameterMap=request.getParameterMap();
301 if(parameterMap.containsKey(OLENCIPConstants.FORMAT)){
302 if(parameterMap.get(OLENCIPConstants.FORMAT)[0].equalsIgnoreCase(OLENCIPConstants.XML_FORMAT) || parameterMap.get(OLENCIPConstants.FORMAT)[0].equalsIgnoreCase(OLENCIPConstants.JSON_FORMAT)){
303 outputFormat=parameterMap.get(OLENCIPConstants.FORMAT)[0];
304 }
305 else{
306 doProcess=false;
307 }
308 }
309 if(parameterMap.containsKey(OLENCIPConstants.OLE_CIRCULATION_SERVICE)){
310 service=parameterMap.get(OLENCIPConstants.OLE_CIRCULATION_SERVICE)[0];
311 }
312
313 if(service!=null){
314 if(doProcess){
315 if(service.equals(OLENCIPConstants.LOOKUPUSER_SERVICE)){
316 if(parameterMap.containsKey(OLENCIPConstants.PATRON_BARCODE) &&
317 parameterMap.containsKey(OLENCIPConstants.OPERATOR_ID)){
318 if(parameterMap.size()==3 || parameterMap.size()==4){
319 responseString=oleCirculationService.lookupUser(parameterMap.get(OLENCIPConstants.PATRON_BARCODE)[0],parameterMap.get(OLENCIPConstants.OPERATOR_ID)[0],null, false);
320 if(outputFormat.equalsIgnoreCase(OLENCIPConstants.JSON_FORMAT)){
321 responseString=new OLELookupUserConverter().generateLookupUserJson(responseString);
322 }
323 if(responseString==null){
324 OLENCIPErrorResponse olencipErrorResponse=new OLENCIPErrorResponse();
325 olencipErrorResponse.getErrorMap().put(OLENCIPConstants.PATRON_BARCODE,parameterMap.get(OLENCIPConstants.PATRON_BARCODE)[0]);
326 olencipErrorResponse.getErrorMap().put(OLENCIPConstants.OPERATOR_ID,parameterMap.get(OLENCIPConstants.OPERATOR_ID)[0]);
327 responseString=olencipErrorResponse.getErrorXml(service);
328 }
329
330 }else{
331 responseString=getCirculationErrorMessage(service,OLENCIPConstants.INVALID_PARAMETERS,"501",OLENCIPConstants.LOOKUPUSER,outputFormat);
332 }
333
334
335 }else{
336 responseString=getCirculationErrorMessage(service,OLENCIPConstants.PARAMETER_MISSING,"502",OLENCIPConstants.LOOKUPUSER,outputFormat);
337 }
338 }
339 else if(service.equals(OLENCIPConstants.GETCHECKEDOUTITEM_SERVICE)){
340 if(parameterMap.containsKey(OLENCIPConstants.PATRON_BARCODE) &&
341 parameterMap.containsKey(OLENCIPConstants.OPERATOR_ID)){
342 if(parameterMap.size()==3 || parameterMap.size()==4){
343 try {
344 responseString=oleCirculationService.getCheckedOutItems(parameterMap.get(OLENCIPConstants.PATRON_BARCODE)[0],parameterMap.get(OLENCIPConstants.OPERATOR_ID)[0]);
345 if(outputFormat.equalsIgnoreCase(OLENCIPConstants.JSON_FORMAT)){
346 responseString=new OLECheckoutItemsConverter().generateGetCheckedOutItemsJson(responseString);
347 System.out.println(responseString);
348 }
349 if(responseString==null){
350 OLENCIPErrorResponse olencipErrorResponse=new OLENCIPErrorResponse();
351 olencipErrorResponse.getErrorMap().put(OLENCIPConstants.PATRON_BARCODE,parameterMap.get(OLENCIPConstants.PATRON_BARCODE)[0]);
352 olencipErrorResponse.getErrorMap().put(OLENCIPConstants.OPERATOR_ID,parameterMap.get(OLENCIPConstants.OPERATOR_ID)[0]);
353 olencipErrorResponse.getErrorMap().put(OLENCIPConstants.MESSAGE,OLENCIPConstants.INVALID_INPUT);
354 responseString=olencipErrorResponse.getErrorXml(service);
355 }
356 } catch (Exception e) {
357 LOG.error(e,e);
358 }
359 }else{
360 responseString=getCirculationErrorMessage(service,OLENCIPConstants.INVALID_PARAMETERS,"501",OLENCIPConstants.GETCHECKOUTITEMS,outputFormat);
361 }
362 }else{
363 responseString=getCirculationErrorMessage(service,OLENCIPConstants.PARAMETER_MISSING,"502",OLENCIPConstants.GETCHECKOUTITEMS,outputFormat);
364 }
365 }
366 else if(service.equals(OLENCIPConstants.FINE_SERVICE)){
367 if(parameterMap.containsKey(OLENCIPConstants.PATRON_BARCODE) &&
368 parameterMap.containsKey(OLENCIPConstants.OPERATOR_ID)){
369 if(parameterMap.size()==3 || parameterMap.size()==4){
370 try {
371 responseString=oleCirculationService.getFine(parameterMap.get(OLENCIPConstants.PATRON_BARCODE)[0], parameterMap.get(OLENCIPConstants.OPERATOR_ID)[0]);
372 if(outputFormat.equalsIgnoreCase(OLENCIPConstants.JSON_FORMAT)){
373 responseString=new OLEItemFineConverter().generateFineJson(responseString);
374 System.out.println(responseString);
375 }
376 if(responseString==null){
377 OLENCIPErrorResponse olencipErrorResponse=new OLENCIPErrorResponse();
378 olencipErrorResponse.getErrorMap().put(OLENCIPConstants.PATRON_BARCODE,parameterMap.get(OLENCIPConstants.PATRON_BARCODE)[0]);
379 olencipErrorResponse.getErrorMap().put(OLENCIPConstants.OPERATOR_ID,parameterMap.get(OLENCIPConstants.OPERATOR_ID)[0]);
380 olencipErrorResponse.getErrorMap().put(OLENCIPConstants.MESSAGE,OLENCIPConstants.INVALID_INPUT);
381 responseString=olencipErrorResponse.getErrorXml(service);
382 }
383 } catch (Exception e) {
384 LOG.error(e,e);
385 }
386 }else{
387 responseString=getCirculationErrorMessage(service,OLENCIPConstants.INVALID_PARAMETERS,"501",OLENCIPConstants.FINE,outputFormat);
388 }
389 }else{
390 responseString=getCirculationErrorMessage(service,OLENCIPConstants.PARAMETER_MISSING,"502",OLENCIPConstants.FINE,outputFormat);
391 }
392 }
393 else if(service.equals(OLENCIPConstants.HOLDS_SERVICE)){
394 if(parameterMap.containsKey(OLENCIPConstants.PATRON_BARCODE) &&
395 parameterMap.containsKey(OLENCIPConstants.OPERATOR_ID)){
396 if(parameterMap.size()==3 || parameterMap.size()==4){
397 try {
398 responseString=oleCirculationService.getHolds(parameterMap.get(OLENCIPConstants.PATRON_BARCODE)[0], parameterMap.get(OLENCIPConstants.OPERATOR_ID)[0]);
399 if(outputFormat.equalsIgnoreCase(OLENCIPConstants.JSON_FORMAT)){
400 responseString=new OLEHoldsConverter().generateHoldsJson(responseString);
401 System.out.println(responseString);
402 }
403 if(responseString==null){
404 OLENCIPErrorResponse olencipErrorResponse=new OLENCIPErrorResponse();
405 olencipErrorResponse.getErrorMap().put(OLENCIPConstants.PATRON_BARCODE,parameterMap.get(OLENCIPConstants.PATRON_BARCODE)[0]);
406 olencipErrorResponse.getErrorMap().put(OLENCIPConstants.OPERATOR_ID,parameterMap.get(OLENCIPConstants.OPERATOR_ID)[0]);
407 olencipErrorResponse.getErrorMap().put(OLENCIPConstants.MESSAGE,OLENCIPConstants.INVALID_INPUT);
408 responseString=olencipErrorResponse.getErrorXml(service);
409 }
410 } catch (Exception e) {
411 LOG.error(e,e);
412 }
413 }else{
414 responseString=getCirculationErrorMessage(service,OLENCIPConstants.INVALID_PARAMETERS,"501",OLENCIPConstants.HOLDS,outputFormat);
415 }
416 }else{
417 responseString=getCirculationErrorMessage(service,OLENCIPConstants.PARAMETER_MISSING,"502",OLENCIPConstants.HOLDS,outputFormat);
418 }
419 }
420 else{
421 LOG.info("Unknown Service Name: "+service+" Parameter is missing");
422 responseString=getCirculationErrorMessage(service,OLENCIPConstants.UNKNOWN_SERVICE,"503",null,outputFormat);
423 response.sendError(405,"Method Not Supported");
424 }
425 }
426 else{
427 responseString=getCirculationErrorMessage(service,OLENCIPConstants.INVALID_FORMAT,"504",null,outputFormat);
428 }
429 }
430 else{
431 responseString=OLENCIPConstants.NULL_SERVICE;
432 }
433 if(responseString!=null){
434 responseString=responseString.replaceAll("errorMessage",OLENCIPConstants.MESSAGE);
435 responseString=responseString.replaceAll("<br/>","");
436 }
437 PrintWriter out=response.getWriter();
438 if(outputFormat.equalsIgnoreCase(OLENCIPConstants.XML_FORMAT)){
439 response.setContentType(OLENCIPConstants.XML_CONTENT_TYPE);
440 response.setCharacterEncoding(OLENCIPConstants.XML_CHAR_ENCODING);
441
442 }
443 if(responseString.contains(OLENCIPConstants.INVALID_FORMAT)){
444 response.setStatus(406);
445 } else if(responseString.contains(OLENCIPConstants.PARAMETER_MISSING)){
446 response.setStatus(422);
447 }else{
448 response.setStatus(200);
449 }
450
451
452 out.write(responseString);
453
454 }
455
456
457 private String getCirculationErrorMessage(String service,String message,String code,String requiredParameters,String outputFormat){
458 OLECirculationErrorMessage oleCirculationErrorMessage=new OLECirculationErrorMessage();
459 OLECirculationErrorMessageConverter oleCirculationErrorMessageConverter=new OLECirculationErrorMessageConverter();
460 oleCirculationErrorMessage.setMessage(message);
461 oleCirculationErrorMessage.setCode(code);
462 oleCirculationErrorMessage.setService(service);
463 oleCirculationErrorMessage.setRequiredParameters(requiredParameters);
464 String errorMessage="";
465 errorMessage=oleCirculationErrorMessageConverter.generateCirculationErrorXml(oleCirculationErrorMessage);
466 if(outputFormat.equalsIgnoreCase(OLENCIPConstants.JSON_FORMAT)){
467 errorMessage=oleCirculationErrorMessageConverter.generateLookupUserJson(errorMessage);
468 }
469 return errorMessage;
470 }
471 }