001package org.kuali.asr.handler; 002 003import org.codehaus.jettison.json.JSONException; 004import org.codehaus.jettison.json.JSONObject; 005import org.kuali.ole.ncip.bo.OLENCIPConstants; 006 007import java.util.HashMap; 008import java.util.Map; 009 010/** 011 * Created by chenchulakshmig on 8/24/15. 012 */ 013public class CheckoutItemRequestHandler extends RequestHandler{ 014 015 public Map parseRequest(JSONObject jsonObject) throws JSONException { 016 String patronBarcode = getStringValueFromJsonObject(jsonObject, OLENCIPConstants.PATRON_BARCODE); 017 String itemBarcode = getStringValueFromJsonObject(jsonObject, OLENCIPConstants.ITEM_BARCODE); 018 String operatorId = getStringValueFromJsonObject(jsonObject, OLENCIPConstants.OPERATOR_ID); 019 020 String requestFormatType = getStringValueFromJsonObject(jsonObject, OLENCIPConstants.REQUEST_FORMAT_TYPE); 021 String responseFormatType = getStringValueFromJsonObject(jsonObject, OLENCIPConstants.RESPONSE_FORMAT_TYPE); 022 023 Map checkoutParameters = new HashMap(); 024 checkoutParameters.put("patronBarcode", patronBarcode); 025 checkoutParameters.put("itemBarcode", itemBarcode); 026 checkoutParameters.put("operatorId", operatorId); 027 checkoutParameters.put("requestFormatType", requestFormatType); 028 checkoutParameters.put("responseFormatType", responseFormatType); 029 return checkoutParameters; 030 } 031 032 public String getStringValueFromJsonObject(JSONObject jsonObject, String key) { 033 String returnValue = null; 034 try { 035 returnValue = jsonObject.getString(key); 036 } catch (JSONException e) { 037 e.printStackTrace(); 038 } 039 return returnValue; 040 } 041 042}