Пример #1
0
  public ActionForward doAction(
      ActionMapping mapping, HttpServletRequest request, HttpServletResponse response)
      throws Exception {

    DataHandler handler = (DataHandler) request.getAttribute(BrowserFrameworkConstants.CLIENT_INFO);

    // get values for current location lat and lon, and also distUnit
    TxNode node = (TxNode) handler.getParameter("anchorLat");
    long anchorLat = node != null ? node.valueAt(0) : -1;

    node = (TxNode) handler.getParameter("anchorLon");
    long anchorLon = node != null ? node.valueAt(0) : -1;

    node = (TxNode) handler.getParameter("distUnit");
    long distUnit = node != null ? node.valueAt(0) : 1;

    logger.debug("Lat:" + anchorLat + " Lon:" + anchorLon + "Dist Unit:" + distUnit);

    // convert distUnit to mi or km
    String scale = "mi";
    if (distUnit != Constant.DUNIT_MILES) {
      scale = "km";
    }

    // set attributes for anchor lat, lon, distUnit and scale
    request.setAttribute("anchorLat", anchorLat);
    request.setAttribute("anchorLon", anchorLon);
    request.setAttribute("distUnit", distUnit);
    request.setAttribute("scale", scale);

    try {
      logger.debug("ShareMovie... before");
      ExecutorRequest[] executorRequests = requestParser.parse(request);

      ShareMovieResponse executorResponse = new ShareMovieResponse();

      if (executorRequests != null && executorRequests.length > 0) {
        ExecutorDispatcher ac = ExecutorDispatcher.getInstance();
        ac.execute(executorRequests[0], executorResponse, new ExecutorContext());
      }

      if (executorResponse.getStatus() == ExecutorResponse.STATUS_FAIL) {
        request.setAttribute("errorCode", new Long(-1));
        request.setAttribute("errorMsg", executorResponse.getErrorMessage());
        return mapping.findForward("failure");
      }

      responseFormatter.format(request, new ExecutorResponse[] {executorResponse});
      logger.debug("ShareMovie... after");
      return mapping.findForward("success");
    } catch (Exception e) {
      ActionMessages msgs = new ActionMessages();
      msgs.add("loginfailed", new ActionMessage("errors.movie.failed"));
      addErrors(request, msgs);
      return mapping.findForward("failure");
    }
  }
  public void setUp() {
    tst = new TnSurveyTag();
    tnContext = new TnContext();
    tnContext.addProperty(TnContext.PROP_CARRIER, "ATT");
    tnContext.addProperty(TnContext.PROP_DEVICE, "genericTest");
    tnContext.addProperty(TnContext.PROP_PRODUCT, "ANDROID");
    tnContext.addProperty(TnContext.PROP_VERSION, "6.2.01");
    tnContext.addProperty("application", "ATT_NAV");
    tnContext.addProperty("login", "3817799999");
    tnContext.addProperty("userid", "3707312");

    HttpServletRequest request = new MockHttpServletRequest();
    handler = new DataHandler(request);

    Hashtable clientInfo = new Hashtable();
    clientInfo.put(DataHandler.KEY_CARRIER, "ATT");
    clientInfo.put(DataHandler.KEY_PLATFORM, "ANDROID");
    clientInfo.put(DataHandler.KEY_VERSION, "6.2.01");
    clientInfo.put(DataHandler.KEY_PRODUCTTYPE, "ATT_NAV");
    clientInfo.put(DataHandler.KEY_DEVICEMODEL, "genericTest");

    clientInfo.put(DataHandler.KEY_WIDTH, "480");
    clientInfo.put(DataHandler.KEY_HEIGHT, "800");
    clientInfo.put(DataHandler.KEY_LOCALE, "en_US");
    clientInfo.put(DataHandler.KEY_CLIENT_SUPPORT_SCREEN_WIDTH, "480-800");
    clientInfo.put(DataHandler.KEY_CLIENT_SUPPORT_SCREEN_HEIGHT, "800-480");
    handler.setClientInfo(clientInfo);
  }
  protected ActionForward doAction(
      ActionMapping mapping, HttpServletRequest request, HttpServletResponse response) {
    try {
      DataHandler handler =
          (DataHandler) request.getAttribute(BrowserFrameworkConstants.CLIENT_INFO);
      Long userId = PoiUtil.getUserId(handler);
      TnContext tc = PoiUtil.getTnContext(handler);
      TxNode body = handler.getAJAXBody();
      String joString = body.msgAt(0);
      JSONObject jo = new JSONObject(joString);
      String firstName = jo.getString("firstName");
      String lastName = jo.getString("lastName");
      String email = jo.getString("email");
      if (null != email) {
        email = email.toLowerCase();
      }

      TxNode node = new TxNode();
      node.addMsg(firstName);
      node.addMsg(lastName);
      node.addMsg(email);

      if (email.equals("")) {
        email = null;
      }

      TelepersonalizationFacade.updateUserProfile(
          userId.toString(), firstName, lastName, email, -1, -1, true, tc);

      /*
      TelePersonalize telePersonalize = new TelePersonalize();
      telePersonalize.updateUserInfo(userId.toString(), firstName, lastName, email,
              -1, -1, false, tc.toContextString());*/

      request.setAttribute("node", node);
      return mapping.findForward("success");
    } catch (Exception e) {
      ActionMessages msgs = new ActionMessages();
      msgs.add("UpdateUserInfofailed", new ActionMessage("errors.UpdateUserInfo.failed"));
      addErrors(request, msgs);
      return mapping.findForward("failure");
    }
  }