View Javadoc
1   package org.kuali.asr.handler;
2   
3   import org.codehaus.jettison.json.JSONException;
4   import org.codehaus.jettison.json.JSONObject;
5   import org.kuali.ole.ncip.bo.OLENCIPConstants;
6   
7   import java.util.HashMap;
8   import java.util.Map;
9   
10  /**
11   * Created by chenchulakshmig on 8/24/15.
12   */
13  public class CheckoutItemRequestHandler extends RequestHandler{
14  
15      public Map parseRequest(JSONObject jsonObject) throws JSONException {
16          String patronBarcode = getStringValueFromJsonObject(jsonObject, OLENCIPConstants.PATRON_BARCODE);
17          String itemBarcode = getStringValueFromJsonObject(jsonObject, OLENCIPConstants.ITEM_BARCODE);
18          String operatorId = getStringValueFromJsonObject(jsonObject, OLENCIPConstants.OPERATOR_ID);
19          
20          String requestFormatType = getStringValueFromJsonObject(jsonObject, OLENCIPConstants.REQUEST_FORMAT_TYPE);
21          String responseFormatType = getStringValueFromJsonObject(jsonObject, OLENCIPConstants.RESPONSE_FORMAT_TYPE);
22  
23          Map checkoutParameters = new HashMap();
24          checkoutParameters.put("patronBarcode", patronBarcode);
25          checkoutParameters.put("itemBarcode", itemBarcode);
26          checkoutParameters.put("operatorId", operatorId);
27          checkoutParameters.put("requestFormatType", requestFormatType);
28          checkoutParameters.put("responseFormatType", responseFormatType);
29          return checkoutParameters;
30      }
31  
32      public String getStringValueFromJsonObject(JSONObject jsonObject, String key) {
33          String returnValue = null;
34          try {
35              returnValue = jsonObject.getString(key);
36          } catch (JSONException e) {
37              e.printStackTrace();
38          }
39          return returnValue;
40      }
41  
42  }