Example #1
0
  private Map<String, Object> createContext(
      HttpServletRequest req, RequestType reqType, Request wiraRequest) {
    Map<String, Object> context = new HashMap<String, Object>();
    context.put("docType", req.getParameter("docType"));
    context.put("requestType", req.getParameter("docType"));

    switch (reqType) {
      case ALLOCATIONREQUEST:
        wiraRequest.setDescription(
            req.getParameter("allocateeName") + "-" + req.getParameter("terminalName"));
        context.put("allocateeName", req.getParameter("allocateeName"));
        context.put("terminalName", req.getParameter("terminalName"));
        context.put("terminalId", req.getParameter("terminalId"));
        context.put("imeiCode", req.getParameter("imeiCode"));
        context.put("allocatedTo", req.getParameter("allocatedTo"));
        context.put("ownerId", req.getParameter("allocateeName"));
        break;

      case MPESAIPN:
        wiraRequest.setDescription(
            req.getParameter("senderName") + "-" + req.getParameter("senderPhone"));
        context.put("senderName", req.getParameter("senderName"));
        context.put("senderPhone", req.getParameter("senderPhone"));
        context.put("enteredId", req.getParameter("enteredId"));
        context.put("clCode", req.getParameter("clCode"));
        context.put("customerNames", req.getParameter("customerNames"));
        context.put("mpesaCode", req.getParameter("mpesaCode"));
        context.put("mpesaDate", req.getParameter("mpesaDate"));
        context.put("mpesaTime", req.getParameter("mpesaTime"));
        context.put("mpesaAmount", req.getParameter("mpesaAmount"));
        context.put("ownerId", "Administrator");
        break;

      case DEALLOCATIONREQUEST:
        wiraRequest.setDescription(
            req.getParameter("allocateeNames") + "-" + req.getParameter("terminalName"));

        Detail detail = new Detail();
        detail.setName("summaryTable");
        Map<String, Object> summaryDetails = new HashMap<String, Object>();

        if (req.getParameter("allocateeNames") != null) {
          summaryDetails.put(
              "terminalUser",
              req.getParameter("userName") + " " + req.getParameter("terminalName"));
        }

        if (req.getParameter("transactionCount") != null) {
          summaryDetails.put("transactionCount", req.getParameter("transactionCount"));
        }

        System.err.println("transactionSum<<<" + req.getParameter("transactionSum"));
        if (req.getParameter("transactionSum") != null) {
          try {
            summaryDetails.put(
                "transactionSum",
                NumberFormat.getNumberInstance().parse(req.getParameter("transactionSum")));
          } catch (ParseException e) {
            e.printStackTrace();
          }
        }

        if (req.getParameter("customerCount") != null) {
          summaryDetails.put("customerCount", req.getParameter("customerCount"));
        }

        if (req.getParameter("allocationId") != null) {
          summaryDetails.put("allocationId", req.getParameter("allocationId"));
        }

        detail.setDetails(summaryDetails);

        wiraRequest.setDetails(Arrays.asList(detail));

        context.put("ownerId", req.getParameter("userName"));
        context.put("actorId", req.getParameter("userName"));
        break;

      default:
        break;
    }
    return context;
  }