Ejemplo n.º 1
0
  public ActionForward saveMacro(
      ActionMapping maping,
      ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response)
      throws Exception {
    EyeformMacroDao eyeformMacroDao = (EyeformMacroDao) SpringUtils.getBean("eyeformMacroDao");
    HashMap<String, Object> hashMap = new HashMap<String, Object>();

    try {
      EyeformMacro macro = new EyeformMacro();
      if (request.getParameter("macroIdField") != null
          && request.getParameter("macroIdField").length() > 0) {
        macro = eyeformMacroDao.find(Integer.parseInt(request.getParameter("macroIdField")));
        macro = (macro == null ? new EyeformMacro() : macro);
      }

      macro.setMacroName(request.getParameter("macroNameBox"));
      macro.setImpressionText(request.getParameter("macroImpressionBox"));
      macro.setPlanText(request.getParameter("macroPlanBox"));
      macro.setCopyFromLastImpression(
          Boolean.parseBoolean(request.getParameter("macroCopyFromLastImpression")));

      if (request.getParameter("billingData") != null
          && request.getParameter("billingData").length() > 0) {
        String[] billingItems = request.getParameterValues("billingData");

        List<EyeformMacroBillingItem> billingItemList = new LinkedList<EyeformMacroBillingItem>();
        for (String b : billingItems) {
          EyeformMacroBillingItem billingItem = new EyeformMacroBillingItem();
          String billingCode = b.substring(0, b.indexOf("|"));
          String multiplier = b.substring(b.indexOf("|"));

          billingItem.setBillingServiceCode(billingCode);
          billingItem.setMultiplier(Double.parseDouble(multiplier));

          billingItemList.add(billingItem);
        }

        macro.setBillingItems(billingItemList);
      }

      eyeformMacroDao.merge(macro);

      hashMap.put("saved", macro.getId());
    } catch (Exception e) {
      hashMap.put("error", e.getMessage());
    }

    JsonConfig config = new JsonConfig();
    config.registerJsonBeanProcessor(java.sql.Date.class, new JsDateJsonBeanProcessor());

    JSONObject json = JSONObject.fromObject(hashMap, config);
    response.getOutputStream().write(json.toString().getBytes());

    return null;
  }
Ejemplo n.º 2
0
  public ActionForward getMacroList(
      ActionMapping mapping,
      ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response)
      throws Exception {
    EyeformMacroDao eyeformMacroDao = (EyeformMacroDao) SpringUtils.getBean("eyeformMacroDao");

    List<EyeformMacro> macroList = eyeformMacroDao.getMacros();
    HashMap<String, Object> hashMap = new HashMap<String, Object>();
    hashMap.put("macros", macroList);

    JsonConfig config = new JsonConfig();
    config.registerJsonBeanProcessor(java.sql.Date.class, new JsDateJsonBeanProcessor());

    JSONObject json = JSONObject.fromObject(hashMap, config);
    response.getOutputStream().write(json.toString().getBytes());

    return null;
  }