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 9/29/15.
012 */
013public class LoginRequestHandler extends RequestHandler {
014
015    public Map parseRequest(JSONObject jsonObject) throws JSONException {
016        String loginUserId = getStringValueFromJsonObject(jsonObject, "loginUserId");
017        String loginPassword = getStringValueFromJsonObject(jsonObject, "loginPassword");
018
019        String requestFormatType = getStringValueFromJsonObject(jsonObject, OLENCIPConstants.REQUEST_FORMAT_TYPE);
020        String responseFormatType = getStringValueFromJsonObject(jsonObject, OLENCIPConstants.RESPONSE_FORMAT_TYPE);
021
022        Map lookupUserParameters = new HashMap();
023        lookupUserParameters.put("loginUserId", loginUserId);
024        lookupUserParameters.put("loginPassword", loginPassword);
025        lookupUserParameters.put("requestFormatType", requestFormatType);
026        lookupUserParameters.put("responseFormatType", responseFormatType);
027        return lookupUserParameters;
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}