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/27/15.
012 */
013public class CheckinItemRequestHandler extends RequestHandler {
014
015    public Map parseRequest(JSONObject jsonObject) throws JSONException {
016        String itemBarcode = getStringValueFromJsonObject(jsonObject, OLENCIPConstants.ITEM_BARCODE);
017        String operatorId = getStringValueFromJsonObject(jsonObject, OLENCIPConstants.OPERATOR_ID);
018
019        String requestFormatType = getStringValueFromJsonObject(jsonObject, OLENCIPConstants.REQUEST_FORMAT_TYPE);
020        String responseFormatType = getStringValueFromJsonObject(jsonObject, OLENCIPConstants.RESPONSE_FORMAT_TYPE);
021
022        Map checkinParameters = new HashMap();
023        checkinParameters.put("itemBarcode", itemBarcode);
024        checkinParameters.put("operatorId", operatorId);
025        checkinParameters.put("requestFormatType", requestFormatType);
026        checkinParameters.put("responseFormatType", responseFormatType);
027        return checkinParameters;
028    }
029
030    public String getStringValueFromJsonObject(JSONObject jsonObject, String key) {
031        String returnValue = null;
032        try {
033            returnValue = jsonObject.getString(key);
034        } catch (JSONException e) {
035            e.printStackTrace();
036        }
037        return returnValue;
038    }
039
040}
041