public ActionForward execute(
      ActionMapping mapping,
      ActionForm actionForm,
      HttpServletRequest request,
      HttpServletResponse reponse)
      throws Exception {
    BeanEcrireCommentaire bean = (BeanEcrireCommentaire) actionForm;
    String contenu = bean.getContenu();
    BeanCommentaire beanCommentaire = new BeanCommentaire();
    beanCommentaire.setContenu(contenu);
    Abonne abonne =
        (Abonne)
            bdutil.getUtilisateur(((Integer) request.getSession().getAttribute("id")).intValue());
    beanCommentaire.setIdRedacteur(abonne.getId());

    Article article = bdart.getArticle(Integer.parseInt(request.getParameter("idArticle")));
    beanCommentaire.setIdArticle(article.getId());

    // beanCommentaire.setId(bdart.getIdLibre());

    if (contenu.equals("")) return mapping.findForward("echec");
    else {

      bdcom.addCommentaire(beanCommentaire.getCommentaire());

      //        bdart.addArticle(beanArticle.getArticle());

      //	beanCommentaire.setIdRedacteur(request.getSession(true));
      //	beanCommentaire.setIdArticle(((Article)request.getAttribute("article")).getId());
      //	bean.setId(BDArticles.getIdLibre())
      /// bdart.addArticle(beanCommentaire.getCommentaire());     // /!\ omg!!!

      return mapping.findForward("succes");
    }
  }
Пример #2
0
  public ActionForward execute(
      ActionMapping mapping, ActionForm form, HttpServletRequest req, HttpServletResponse res)
      throws ServletException, IOException {
    try {
      GpsImportForm gpsForm = (GpsImportForm) form;
      User user = (User) req.getSession().getAttribute("user");
      int entryId = gpsForm.getEntryId();
      String fileName = gpsForm.getFileName();
      String title = gpsForm.getTitle();
      String activityId = gpsForm.getActivityId();
      String xml = gpsForm.getXml();
      log.debug(xml);

      List<GpsTrack> tracks = new TcxParser().parse(xml.getBytes());
      GpsTrack track = tracks.get(0); // Horrible hack.
      createAttachment(user, entryId, fileName, title, activityId, track);
      createGeotag(fileName, track);

      req.setAttribute("status", "success");
      req.setAttribute("message", "");
      log.debug("Returning status: success.");
      return mapping.findForward("results");
    } catch (Exception e) {
      log.fatal("Error processing incoming Garmin XML", e);
      req.setAttribute("status", "failure");
      req.setAttribute("message", e.toString());
      return mapping.findForward("results");
    }
  }
 public ActionForward execute(
     ActionMapping mapping, ActionForm form, HttpServletRequest req, HttpServletResponse res)
     throws Exception {
   ProductLoaderForm obj = (ProductLoaderForm) form;
   String productName = obj.getProductName();
   String productId = obj.getProductId();
   String store = obj.getStore();
   String notes = obj.getNotes();
   String productDesc = obj.getProductDesc();
   String price = obj.getPrice();
   Connection con = null;
   Class.forName(ConnectionStats.DRIVER);
   String url = ConnectionStats.DB_URL;
   String usr = ConnectionStats.DB_USER;
   String pwd = ConnectionStats.DB_PASSWORD;
   con = DriverManager.getConnection(url, usr, pwd);
   Statement stmt = con.createStatement();
   try {
     ResultSet rs =
         stmt.executeQuery("select * from service2_main where productId = '" + productId + "'");
     if (!(rs.next())) {
       stmt.executeUpdate(
           "insert into service2_main values('"
               + productId
               + "','"
               + productName
               + "','"
               + productDesc
               + "',)");
     }
     stmt.executeUpdate(
         "delete from service2_tbl where productId = '"
             + productId
             + "' and store = '"
             + store
             + "'");
     stmt.executeUpdate(
         "insert into service2_tbl values('"
             + productId
             + "','"
             + store
             + "',"
             + Float.parseFloat(price)
             + ",'"
             + notes
             + "')");
     req.setAttribute("msg", "Succeeded");
     System.out.println("succeded");
     return mapping.findForward("success");
   } catch (Exception ex) {
     System.out.println("failure");
     req.setAttribute("msg", "Data updating failed");
     return mapping.findForward("failure");
   }
 }
 public ActionForward execute(
     ActionMapping mapping, ActionForm form, HttpServletRequest req, HttpServletResponse res)
     throws Exception {
   ServiceDataForm obj = (ServiceDataForm) form;
   String serviceId = obj.getServiceId();
   CalculateService obj2 = new CalculateService();
   obj2.calculate(serviceId);
   Connection con = null;
   Class.forName(ConnectionStats.DRIVER);
   String url = ConnectionStats.DB_URL;
   String usr = ConnectionStats.DB_USER;
   String pwd = ConnectionStats.DB_PASSWORD;
   con = DriverManager.getConnection(url, usr, pwd);
   Statement stmt = con.createStatement();
   ResultSet rs = null;
   rs = stmt.executeQuery("select * from " + serviceId + "_main");
   ResultSetMetaData rsmd = rs.getMetaData();
   int col = rsmd.getColumnCount();
   String[] mainHeader = new String[col];
   for (int i = 0; i < col; i++) {
     mainHeader[i] = rsmd.getColumnLabel(i + 1);
   }
   ArrayList<String[]> serviceDataMain = new ArrayList<String[]>();
   while (rs.next()) {
     String[] str = new String[col];
     for (int i = 0; i < col; i++) {
       str[i] = rs.getString(i + 1);
     }
     serviceDataMain.add(str);
   }
   req.setAttribute("mainHeader", mainHeader);
   req.setAttribute("serviceDataMain", serviceDataMain);
   rs = stmt.executeQuery("select * from " + serviceId + "_tbl");
   rsmd = rs.getMetaData();
   col = rsmd.getColumnCount();
   String[] tblHeader = new String[col];
   for (int i = 0; i < col; i++) {
     tblHeader[i] = rsmd.getColumnLabel(i + 1);
   }
   ArrayList<String[]> serviceDatatbl = new ArrayList<String[]>();
   while (rs.next()) {
     String[] str = new String[col];
     for (int i = 0; i < col; i++) {
       str[i] = rs.getString(i + 1);
     }
     serviceDatatbl.add(str);
   }
   req.setAttribute("tblHeader", tblHeader);
   req.setAttribute("serviceDatatbl", serviceDatatbl);
   rs.close();
   con.close();
   return mapping.findForward("success");
 }
Пример #5
0
  /**
   * Process the specified HTTP request, and create the corresponding HTTP response (or forward to
   * another web component that will create it). Return an <code>ActionForward</code> instance
   * describing where and how control should be forwarded, or <code>null</code> if the response has
   * already been completed.
   *
   * @param form
   * @param req
   * @param res
   * @param mapping The ActionMapping used to select this instance
   * @exception IOException if an input/output error occurs
   * @exception ServletException if a servlet exception occurs
   * @return destination
   */
  public ActionForward execute(
      ActionMapping mapping, ActionForm form, HttpServletRequest req, HttpServletResponse res)
      throws IOException, ServletException {
    ActionMessages errors = new ActionMessages();
    ActionForward destination = null;

    if (!this.checkLogon(req)) {
      return mapping.findForward("logon");
    }
    Integer action;

    try {
      action = Integer.parseInt(req.getParameter("action"));
    } catch (Exception e) {
      action = BlacklistAction.ACTION_LIST;
    }

    AgnUtils.logger().info("Action: " + action);

    try {
      destination = executeIntern(mapping, req, errors, destination, action);
    } catch (Exception e) {
      AgnUtils.logger().error("execute: " + e + "\n" + AgnUtils.getStackTrace(e));
      errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("error.exception"));
    }

    // Report any errors we have discovered back to the original form
    if (!errors.isEmpty()) {
      saveErrors(req, errors);
    }
    return destination;
  }
  /**
   * Method execute
   *
   * @param ActionMapping mapping
   * @param ActionForm form
   * @param HttpServletRequest request
   * @param HttpServletResponse response
   * @return ActionForward
   * @throws Exception
   */
  public ActionForward execute(
      ActionMapping mapping,
      ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response)
      throws Exception {

    HttpSession session = request.getSession();
    // clientXML = (XMLClient) session.getAttribute("client");
    clientXML = XMLClient.getInstance();
    sessionLogin = (String) session.getAttribute("login");

    ajoutsuppressionForm ajoutForm = (ajoutsuppressionForm) form;

    String idperm = ajoutForm.getId1();
    String idrole = ajoutForm.getId2();

    response.setContentType("text/html");

    boolean ajout = clientXML.ajouterPermissionRole(sessionLogin, idperm, idrole);

    if (ajout) {
      String result = "INFO: Permission ajoutée au role";

      session.setAttribute("Resultat", result);
      return mapping.findForward("ok");
    } else {
      String erreur = "ERREUR: Permission non ajoutée au role";

      session.setAttribute("Resultat", erreur);
      return mapping.findForward("failed");
    }
  }
Пример #7
0
  public ActionForward execute(
      ActionMapping actionMapping,
      ActionForm actionForm,
      HttpServletRequest request,
      HttpServletResponse response)
      throws Exception {
    ListForm aWebForm = (ListForm) actionForm;

    if (aWebForm.getMethod() == null) { // 初次进行页面,需要取初始值
      Deal.doList(aWebForm, request, response); // 查询处理
      return actionMapping.getInputForward();
    } else {
      String sMessage = "未能找到 " + aWebForm.getMethod() + " 对应的处理方法";
      if (aWebForm.getMethod().equals("jgys_submit")) { // 修改
        Deal.doList(aWebForm, request, response); // 查询处理
        Deal.doJgys_submit(aWebForm, request, response);
        sMessage = "确定竣工验收报告,并提交到工程结算处理成功";
      }

      CCommonMessage mMessage = new CCommonMessage(); // 统一提示页面
      mMessage.setMessage(sMessage); // 默认为"处理成功!"
      String[] button = {"关闭"}; // 按钮数组
      String[] onclick = {"parent.window.close()"}; // 按钮响应事件
      mMessage.setButtonName(button);
      mMessage.setOnClickFunc(onclick);
      request.setAttribute(CConstants.MESSAGE_OBJECT, mMessage);
      // 在处理页面最后调用(事先要配置名字为success的forward,在全局配置里有 message)
      return actionMapping.findForward("message");
    }
  }
Пример #8
0
  protected ActionForward executeIntern(
      ActionMapping mapping,
      HttpServletRequest req,
      ActionMessages errors,
      ActionForward destination,
      Integer action) {

    BlacklistDao dao = (BlacklistDao) getBean("BlacklistDao");
    String email = null;

    switch (action) {
      case BlacklistAction.ACTION_LIST:
        if (allowed("settings.show", req)) {
          destination = mapping.findForward("list");
        } else {
          errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("error.permissionDenied"));
        }
        break;
      case BlacklistAction.ACTION_SAVE:
        email = req.getParameter("newemail");
        if (dao.insert(getCompanyID(req), email)) {
          updateUserStatus(email.trim(), req);
        }
        destination = mapping.findForward("list");
        break;
      case ACTION_CONFIRM_DELETE:
        destination = mapping.findForward("delete");
        break;
      case BlacklistAction.ACTION_DELETE:
        email = req.getParameter("delete");
        dao.delete(getCompanyID(req), email);
        destination = mapping.findForward("list");
        break;
      default:
        destination = mapping.findForward("list");
    }
    return destination;
  }
Пример #9
0
 /**
  * 响应页面提交
  *
  * @param actionMapping ActionMapping这个 Action 的配置信息
  * @param actionForm ActionForm 用户提交的表单数据
  * @param request HttpServletRequest当前的 HTTP 请求对象
  * @param response HttpServletResponse当前的 HTTP 响应对象
  * @return ActionForward 提交到查询页面
  * @throws Exception
  */
 public ActionForward execute(
     ActionMapping actionMapping,
     ActionForm actionForm,
     HttpServletRequest request,
     HttpServletResponse response)
     throws Exception {
   EditForm aWebForm = (EditForm) actionForm;
   Deal.setEditDefault(aWebForm, request, response); // 设置进入增加页面的初始值
   if (request.getParameter("print") == null) {
     return actionMapping.getInputForward();
   } else {
     return actionMapping.findForward("print");
   }
 }
Пример #10
0
  /**
   * 响应页面提交
   *
   * @param actionMapping ActionMapping这个 Action 的配置信息
   * @param actionForm ActionForm 用户提交的表单数据
   * @param request HttpServletRequest当前的 HTTP 请求对象
   * @param response HttpServletResponse当前的 HTTP 响应对象
   * @return ActionForward 提交到查询页面
   * @throws Exception
   */
  public ActionForward execute(
      ActionMapping actionMapping,
      ActionForm actionForm,
      HttpServletRequest request,
      HttpServletResponse response)
      throws Exception {
    EditForm aWebForm = (EditForm) actionForm;
    if (aWebForm.getMethod() == null) { // 初次进行页面,需要取初始值
      Deal.setEditDefault(aWebForm, request, response); // 设置进入增加页面的初始值
      return actionMapping.getInputForward();
    } else {
      String sMessage = "未能找到 " + aWebForm.getMethod() + " 对应的处理方法";
      String[] button; // 按钮数组
      String[] onclick; // 按钮响应事件

      if (aWebForm.getMethod().equals("edit")) { // 修改
        Deal.doDHHFEdit(aWebForm, request, response); // 处理修改
        sMessage = mModuleName + "修改处理成功";
        button = new String[] {"关闭"}; // 按钮数组
        onclick = new String[] {"parent.window.close()"}; // 按钮响应事件
      } else if (aWebForm.getMethod().equals("add")) { // 修改
        Deal.doDHHFAdd(aWebForm, request, response); // 处理修改
        sMessage = mModuleName + "增加处理成功";
        button = new String[] {"关闭"}; // 按钮数组
        onclick = new String[] {"parent.window.close()"}; // 按钮响应事件
      } else if (aWebForm.getMethod().equals("del")) { // 删除
        Deal.doDHHFDelete(aWebForm, request, response); // 处理删除
        sMessage = mModuleName + "删除处理成功";
        button = new String[] {"关闭"}; // 按钮数组
        onclick = new String[] {"parent.window.close()"}; // 按钮响应事件
      } else { // 未能找到 " + aWebForm.getMethod() + " 对应的处理方法
        button = new String[] {"关闭"}; // 按钮数组
        onclick = new String[] {"parent.window.close()"}; // 按钮响应事件
      }
      CCommonMessage mMessage = new CCommonMessage(); // 统一提示页面
      mMessage.setMessage(sMessage); // 默认为"处理成功!"
      mMessage.setButtonName(button);
      mMessage.setOnClickFunc(onclick);
      request.setAttribute(CConstants.MESSAGE_OBJECT, mMessage);
      // 在处理页面最后调用(事先要配置名字为success的forward,在全局配置里有 message)
      return actionMapping.findForward("message");
    }
  }
  /**
   * Method execute
   *
   * @param ActionMapping mapping
   * @param ActionForm form
   * @param HttpServletRequest request
   * @param HttpServletResponse response
   * @return ActionForward
   * @throws Exception
   */
  public ActionForward execute(
      ActionMapping mapping,
      ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response)
      throws Exception {

    HttpSession session = request.getSession();
    // clientXML = (XMLClient) session.getAttribute("client");
    clientXML = XMLClient.getInstance();
    sessionLogin = (String) session.getAttribute("login");

    planifProgForm planifForm = (planifProgForm) form;

    String idprog = planifForm.getIdprog();
    String idcanal = planifForm.getIdcanal();
    String jour = planifForm.getJour();
    String mois = planifForm.getMois();
    String annee = planifForm.getAnnee();
    String heure = planifForm.getHeure();
    String minute = planifForm.getMinute();
    String seconde = planifForm.getSeconde();

    response.setContentType("text/html");

    boolean planifie =
        clientXML.planifierProgramme(
            sessionLogin, idprog, idcanal, jour, mois, annee, heure, minute, seconde);

    if (planifie) {
      String result = "INFO: Programme planifié sur le canal";

      session.setAttribute("Resultat", result);
      return mapping.findForward("ok");
    } else {
      String erreur = "ERREUR: Programme non planifié";

      session.setAttribute("Resultat", erreur);
      return mapping.findForward("failed");
    }
  }
Пример #12
0
  public ActionForward execute(
      ActionMapping actionMapping,
      ActionForm actionForm,
      HttpServletRequest httpServletRequest,
      HttpServletResponse httpServletResponse) {
    LazyValidatorForm frm = (LazyValidatorForm) actionForm;

    if (formCanceled(frm)) {
      return actionMapping.findForward(SUCCESS);
    }

    resetFocusControl(frm, CANCEL);
    ActionMessages msgs = new ActionMessages();
    if (!formSaved(frm)) {
      setFormMode(frm, ((String) httpServletRequest.getParameter(BROWSE_ACTION)));
      setFormId(frm, (String) httpServletRequest.getParameter(BROWSE_ID));
      try {
        httpServletRequest
            .getSession()
            .setAttribute("hozehKindList", Misc.listHardCode(Constants.TableId.HOZEH_KIND));

        LoginInfo loginInfo = getLoginInfo(httpServletRequest);
        if (!loginInfo.userHasAccess(getFormId(frm), getFormMode(frm))) {
          if (isFormInModifyMode(frm)
              && loginInfo.userHasAccess(getFormId(frm), Constants.ActionType.ENQUERY)) {
            setFormMode(frm, Constants.ActionType.ENQUERY);
          } else {
            throw new Exception(INVALID_ACCESS);
          }
        }
        if (!isFormInAddMode(frm)) {
          String formKey = (String) httpServletRequest.getParameter(BROWSE_KEY);
          frm.set("formKey", formKey);
          String key[] = formKey.split(Constants.DATA_SEPARATOR_SPLIT);
          short officeCode = Short.parseShort(key[0]);
          short hozehCode = Short.parseShort(key[1]);
          String hozehKind = key[2];

          HozehInfo inf = Place.getHozehDetails(officeCode, hozehCode, hozehKind);
          frm.set(OFFICE_CODE, Short.toString(inf.getOfficeCode()));
          frm.set(HOZEH_CODE, Short.toString(inf.getHozehCode()));
          frm.set(HOZEH_KIND, inf.getHozehKind());
          frm.set(HOZEH_DESC, inf.getHozehDesc());
          if (inf.isInactive()) {
            frm.set(CODE_ACTIVE_FLAG, "on");
          }
        }
        String officeCode = (String) frm.get(OFFICE_CODE);
        if (Utils.isEmpty(officeCode)) {
          officeCode = "0";
          frm.set(OFFICE_CODE, officeCode);
        }
        frm.set(OFFICE_NAME, Place.getOfficeName(Short.parseShort(officeCode)));

        if (isFormInAddMode(frm)) {
          resetFocusControl(frm, HOZEH_CODE);
        } else if (isFormInModifyMode(frm)) {
          resetFocusControl(frm, HOZEH_DESC);
        }
      } catch (Exception ex) {
        addError(msgs, ex.getMessage());
        saveErrors(httpServletRequest, msgs);
      }
      return actionMapping.findForward(EDIT);
    } else {
      HozehInfo inf = new HozehInfo();
      resetFocusControl(frm, "");

      if (isFormInAddMode(frm)) {

        String officeCode = ((String) frm.get(OFFICE_CODE)).trim();
        resetFocusControl(frm, "");
        if (Utils.isEmpty(officeCode)) {
          addError(msgs, FIELD_CAN_NOT_BE_EMPTY, "اداره");
          setFocusControl(frm, OFFICE_CODE);
        } else if (!Utils.isValidNotZeroNumber(officeCode, 3)) {
          addError(msgs, FIELD_INVALID, "اداره");
          setFocusControl(frm, OFFICE_CODE);
        } else {
          inf.setOfficeCode(Short.parseShort(officeCode));
        }

        String hozehCode = ((String) frm.get(HOZEH_CODE)).trim();
        if (Utils.isEmpty(hozehCode)) {
          addError(msgs, FIELD_CAN_NOT_BE_EMPTY, "كد");
          setFocusControl(frm, HOZEH_CODE);
        } else if (!Utils.isValidNotZeroNumber(hozehCode, 3)) {
          addError(msgs, FIELD_INVALID, "كد");
          setFocusControl(frm, HOZEH_CODE);
        } else {
          inf.setHozehCode(Short.parseShort(hozehCode));
        }

        String hozehKind = ((String) frm.get(HOZEH_KIND)).trim();
        if (Utils.isEmpty(hozehKind)) {
          addError(msgs, FIELD_CAN_NOT_BE_EMPTY, "نوع");
          setFocusControl(frm, HOZEH_KIND);
        } else if (hozehKind.length() > 1) {
          addError(msgs, FIELD_INVALID, "نوع");
          setFocusControl(frm, HOZEH_KIND);
        } else {
          inf.setHozehKind(hozehKind);
        }

      } else {
        String formKey = (String) frm.get("formKey");
        String key[] = formKey.split(Constants.DATA_SEPARATOR_SPLIT);

        inf.setOfficeCode(Short.parseShort(key[0]));
        inf.setHozehCode(Short.parseShort(key[1]));
        inf.setHozehKind(key[2]);
      }

      if (!isFormInDeleteMode(frm)) {
        String hozehDesc = Utils.charVal((String) frm.get(HOZEH_DESC));
        frm.set(HOZEH_DESC, hozehDesc);
        if (Utils.isEmpty(hozehDesc)) {
          addError(msgs, FIELD_CAN_NOT_BE_EMPTY, "شرح");
          setFocusControl(frm, HOZEH_DESC);
        } else if (hozehDesc.length() > 50) {
          addError(msgs, FIELD_INVALID, "شرح");
          setFocusControl(frm, HOZEH_DESC);
        } else {
          inf.setHozehDesc(hozehDesc);
        }

        if (frm.get(CODE_ACTIVE_FLAG) == null) {
          inf.setCodeActiveFlag(Constants.CodeActiveFlag.ACTIVE);
        } else {
          inf.setCodeActiveFlag(Constants.CodeActiveFlag.INACTIVE);
        }
      }

      if (!msgs.isEmpty()) {
        saveErrors(httpServletRequest, msgs);
        return actionMapping.findForward(EDIT);
      }

      resetFocusControl(frm, CANCEL);
      try {
        Place.saveHozeh(getFormMode(frm), inf);
        httpServletRequest.setAttribute(BROWSE_KEY, inf.getKey());
        return actionMapping.findForward(SUCCESS);
      } catch (Exception ex) {
        resetFocusControl(frm, CANCEL);
        addError(msgs, ex.getMessage());
        saveErrors(httpServletRequest, msgs);
        return actionMapping.findForward(EDIT);
      }
    }
  }
Пример #13
0
  public ActionForward execute(
      ActionMapping actionMapping,
      ActionForm actionForm,
      HttpServletRequest httpServletRequest,
      HttpServletResponse httpServletResponse) {
    LazyValidatorForm frm = (LazyValidatorForm) actionForm;
    resetFocusControl(frm, CANCEL);
    ActionMessages msgs = new ActionMessages();

    if (formCanceled(frm)) {
      return actionMapping.findForward(SUCCESS);
    }

    String geoFlag = (String) frm.get(GEO_FLAG);
    if (Utils.isEmpty(geoFlag)) {
      geoFlag = (String) httpServletRequest.getParameter(GEO_FLAG);
      frm.set(GEO_FLAG, geoFlag);
    }

    if (!formSaved(frm)) {
      setFormMode(frm, ((String) httpServletRequest.getParameter(BROWSE_ACTION)));
      setFormId(frm, (String) httpServletRequest.getParameter(BROWSE_ID));
      try {
        LoginInfo loginInfo = getLoginInfo(httpServletRequest);

        String geoFlagDesc = Misc.getHardCodeDesc(Constants.TableId.GEO_FLAG, geoFlag);
        frm.set(GEO_FLAG_DESC, geoFlagDesc);

        if (!loginInfo.userHasAccess("Geo_Conversion", getFormMode(frm))) {
          if (isFormInModifyMode(frm)
              && loginInfo.userHasAccess("Geo_Conversion", Constants.ActionType.ENQUERY)) {
            setFormMode(frm, Constants.ActionType.ENQUERY);
          } else {
            throw new Exception(INVALID_ACCESS);
          }
        }
        if (!geoFlag.equals(Constants.GeoFlag.VILLAGE)) {
          throw new Exception(INVALID_ACCESS);
        }
        if (!isFormInAddMode(frm)) {
          String formKey = (String) httpServletRequest.getParameter(BROWSE_KEY);
          GeoFormationInfo inf = Geo.getGeoFormationDetails(Integer.parseInt(formKey));
          frm.set(GEO_FORMATION_SERIAL, Integer.toString(inf.getGeoFormationSerial()));
          frm.set(GEO_SERIAL, Integer.toString(inf.getGeoSerial()));
          frm.set(APPROVAL_LETTER_NO, inf.getApprovalLetterNo());
          frm.set(APPROVAL_LETTER_DATE, DateUtils.revFormatDate(inf.getApprovalLetterDate()));
          frm.set(GEO_DESC, Geo.getGeoDesc(inf.getGeoSerial()));
        }
        frm.set(GEO_FLAG_DESC, geoFlagDesc);

        if (isFormInModifyMode(frm)) {
          resetFocusControl(frm, APPROVAL_LETTER_NO);
        }
      } catch (Exception ex) {
        addError(msgs, ex.getMessage());
        saveErrors(httpServletRequest, msgs);
      }
      return actionMapping.findForward(EDIT);
    } else {
      try {
        String geoFlagDesc = (String) frm.get(GEO_FLAG_DESC);
        if (!geoFlag.equals(Constants.GeoFlag.VILLAGE)) {
          addError(msgs, FIELD_CAN_NOT_BE_EMPTY, "علامت محل جغرافيايي");
          setFocusControl(frm, GEO_SERIAL);
        }
        GeoFormationInfo inf = new GeoFormationInfo();
        resetFocusControl(frm, "");
        if (isFormInDeleteMode(frm) || isFormInModifyMode(frm)) {
          String geoFormationSerial = ((String) frm.get(GEO_FORMATION_SERIAL)).trim();
          if (Utils.isEmpty(geoFormationSerial)) {
            addError(msgs, FIELD_CAN_NOT_BE_EMPTY, "سريال");
            setFocusControl(frm, GEO_SERIAL);
          } else if (!Utils.isValidNotZeroNumber(geoFormationSerial, 6)) {
            addError(msgs, FIELD_INVALID, "سريال");
            setFocusControl(frm, GEO_SERIAL);
          } else {
            inf.setGeoFormationSerial(Integer.parseInt(geoFormationSerial));
          }
        }

        if (isFormInAddMode(frm)) {
          String geoSerial = ((String) frm.get(GEO_SERIAL)).trim();
          if (Utils.isEmpty(geoSerial)) {
            addError(msgs, FIELD_CAN_NOT_BE_EMPTY, "سريال " + geoFlagDesc);
            setFocusControl(frm, GEO_SERIAL);
          }
          /*  else if (searchGeoDesc(frm, geoFlag) == false) {
            addError(msgs, FIELD_INVALID, "سريال " + geoFlagDesc);
            setFocusControl(frm, GEO_SERIAL);
          }  */
          else {
            inf.setGeoSerial(Integer.parseInt(geoSerial));
          }
        }

        if (!isFormInDeleteMode(frm)) {
          String approvalLetterNo = Utils.trimConvert((String) frm.get(APPROVAL_LETTER_NO));
          frm.set(APPROVAL_LETTER_NO, approvalLetterNo);
          if (Utils.isEmpty(approvalLetterNo)) {
            addError(msgs, FIELD_CAN_NOT_BE_EMPTY, "شماره تصويب نامه");
            setFocusControl(frm, APPROVAL_LETTER_NO);
          } else if (approvalLetterNo.length() > 20) {
            addError(msgs, FIELD_INVALID, "شماره تصويب نامه");
            setFocusControl(frm, APPROVAL_LETTER_NO);
          } else {
            inf.setApprovalLetterNo(approvalLetterNo);
          }

          String approvalLetterDate = ((String) frm.get(APPROVAL_LETTER_DATE)).trim();
          if (Utils.isEmpty(approvalLetterDate)) {
            addError(msgs, FIELD_CAN_NOT_BE_EMPTY, "تاريخ تصويب نامه");
            setFocusControl(frm, APPROVAL_LETTER_DATE);
          } else if (!DateUtils.isValidRevFormattedFDate(approvalLetterDate)) {
            addError(msgs, FIELD_INVALID, "تاريخ تصويب نامه");
            setFocusControl(frm, APPROVAL_LETTER_DATE);
          } else if (DateUtils.unformatRevFormattedFdate(approvalLetterDate)
                  .compareTo(DateUtils.fDate())
              > 0) {
            addError(msgs, FIELD_SHOULD_BE_LESS_THAN, "تاريخ تصويب نامه", "تاريخ روز");
            setFocusControl(frm, APPROVAL_LETTER_DATE);
          } else {
            inf.setApprovalLetterDate(DateUtils.unformatRevFormattedFdate(approvalLetterDate));
          }
        }

        if (!msgs.isEmpty()) {
          saveErrors(httpServletRequest, msgs);
          return actionMapping.findForward(EDIT);
        }
        resetFocusControl(frm, CANCEL);
        Geo.saveConversion(getFormMode(frm), inf, geoFlag);
        httpServletRequest.setAttribute(BROWSE_KEY, inf.getKey());
        return actionMapping.findForward(SUCCESS);
      } catch (Exception ex) {
        resetFocusControl(frm, CANCEL);
        addError(msgs, ex.getMessage());
        saveErrors(httpServletRequest, msgs);
        return actionMapping.findForward(EDIT);
      }
    }
  }
Пример #14
0
  public ActionForward execute(
      ActionMapping actionMapping,
      ActionForm actionForm,
      HttpServletRequest httpServletRequest,
      HttpServletResponse httpServletResponse) {
    LazyValidatorForm frm = (LazyValidatorForm) actionForm;

    if (formCanceled(frm)) {
      return actionMapping.findForward(SUCCESS);
    }

    resetFocusControl(frm, CANCEL);
    ActionMessages msgs = new ActionMessages();
    if (!formSaved(frm)) {
      setFormMode(frm, ((String) httpServletRequest.getParameter(BROWSE_ACTION)));
      setFormId(frm, (String) httpServletRequest.getParameter(BROWSE_ID));
      try {
        LoginInfo loginInfo = getLoginInfo(httpServletRequest);
        if (!loginInfo.userHasAccess(getFormId(frm), getFormMode(frm))) {
          if (isFormInModifyMode(frm)
              && loginInfo.userHasAccess(getFormId(frm), Constants.ActionType.ENQUERY)) {
            setFormMode(frm, Constants.ActionType.ENQUERY);
          } else {
            throw new Exception(INVALID_ACCESS);
          }
        }

        if (!isFormInAddMode(frm)) {
          String formKey = (String) httpServletRequest.getParameter(BROWSE_KEY);
          VillageInfo inf = Geo.getVillageDetails(Integer.parseInt(formKey));
          frm.set(GEO_SERIAL, Integer.toString(inf.getGeoSerial()));
          frm.set(GEO_DESC, inf.getGeoDesc());
          frm.set(OSTAN_SERIAL, Integer.toString(inf.getOstanSerial()));
          frm.set(SHAHRESTAN_SERIAL, Integer.toString(inf.getShahrestanSerial()));
          frm.set(BAKHSH_SERIAL, Integer.toString(inf.getBakhshSerial()));
          frm.set(DEHESTAN_SERIAL, Integer.toString(inf.getDehestanSerial()));
          if (inf.isInactive()) {
            frm.set(CODE_ACTIVE_FLAG, "on");
          }
        } else {
          frm.set(GEO_SERIAL, Integer.toString(Geo.getNewGeoSerial(Constants.GeoFlag.VILLAGE)));
        }

        String serial;
        serial = (String) frm.get(OSTAN_SERIAL);
        if (Utils.isEmpty(serial)) {
          serial = "0";
          frm.set(OSTAN_SERIAL, serial);
        }
        frm.set(OSTAN_DESC, Geo.getOstanDesc(Integer.parseInt(serial)));

        serial = (String) frm.get(SHAHRESTAN_SERIAL);
        if (Utils.isEmpty(serial)) {
          serial = "0";
          frm.set(SHAHRESTAN_SERIAL, serial);
        }
        frm.set(SHAHRESTAN_DESC, Geo.getShahrestanDesc(Integer.parseInt(serial)));

        serial = (String) frm.get(BAKHSH_SERIAL);
        if (Utils.isEmpty(serial)) {
          serial = "0";
          frm.set(BAKHSH_SERIAL, serial);
        }
        frm.set(BAKHSH_DESC, Geo.getBakhshDesc(Integer.parseInt(serial)));

        serial = (String) frm.get(DEHESTAN_SERIAL);
        if (Utils.isEmpty(serial)) {
          serial = "0";
          frm.set(DEHESTAN_SERIAL, serial);
        }
        frm.set(DEHESTAN_DESC, Geo.getDehestanDesc(Integer.parseInt(serial)));

        if (isFormInAddMode(frm)) {
          resetFocusControl(frm, GEO_SERIAL);
        } else if (isFormInModifyMode(frm)) {
          resetFocusControl(frm, GEO_DESC);
        }
      } catch (Exception ex) {
        addError(msgs, ex.getMessage());
        saveErrors(httpServletRequest, msgs);
      }
      return actionMapping.findForward(EDIT);
    } else {
      VillageInfo inf = new VillageInfo();
      String geoSerial = ((String) frm.get(GEO_SERIAL)).trim();
      resetFocusControl(frm, "");
      if (Utils.isEmpty(geoSerial)) {
        addError(msgs, FIELD_CAN_NOT_BE_EMPTY, "كد");
        setFocusControl(frm, GEO_SERIAL);
      } else if (!Utils.isValidNotZeroNumber(geoSerial, 6)) {
        addError(msgs, FIELD_INVALID, "كد");
        setFocusControl(frm, GEO_SERIAL);
      } else {
        inf.setGeoSerial(Integer.parseInt(geoSerial));
      }

      if (!isFormInDeleteMode(frm)) {
        String geoDesc = Utils.charVal((String) frm.get(GEO_DESC));
        frm.set(GEO_DESC, geoDesc);
        if (Utils.isEmpty(geoDesc)) {
          addError(msgs, FIELD_CAN_NOT_BE_EMPTY, "نام");
          setFocusControl(frm, GEO_DESC);
        } else if (geoDesc.length() > 50) {
          addError(msgs, FIELD_INVALID, "نام");
          setFocusControl(frm, GEO_DESC);
        } else {
          inf.setGeoDesc(geoDesc);
        }

        String ostanSerial = (String) frm.get(OSTAN_SERIAL).toString();
        if (Utils.isEmpty(ostanSerial)) {
          addError(msgs, FIELD_CAN_NOT_BE_EMPTY, "استان");
          setFocusControl(frm, GEO_DESC);
        } else if (!Utils.isValidNotZeroNumber(ostanSerial, 6)) {
          addError(msgs, FIELD_INVALID, "استان");
          setFocusControl(frm, GEO_DESC);
        } else {
          inf.setOstanSerial(Integer.parseInt(ostanSerial));
        }

        String shahrestanSerial = (String) frm.get(SHAHRESTAN_SERIAL).toString();
        if (Utils.isEmpty(shahrestanSerial)) {
          addError(msgs, FIELD_CAN_NOT_BE_EMPTY, "شهرستان");
          setFocusControl(frm, GEO_DESC);
        } else if (!Utils.isValidNotZeroNumber(shahrestanSerial, 6)) {
          addError(msgs, FIELD_INVALID, "شهرستان");
          setFocusControl(frm, GEO_DESC);
        } else {
          inf.setShahrestanSerial(Integer.parseInt(shahrestanSerial));
        }

        String bakhshSerial = (String) frm.get(BAKHSH_SERIAL).toString();
        if (Utils.isEmpty(bakhshSerial)) {
          addError(msgs, FIELD_CAN_NOT_BE_EMPTY, "بخش");
          setFocusControl(frm, GEO_DESC);
        } else if (!Utils.isValidNotZeroNumber(bakhshSerial, 6)) {
          addError(msgs, FIELD_INVALID, "بخش");
          setFocusControl(frm, GEO_DESC);
        } else {
          inf.setBakhshSerial(Integer.parseInt(bakhshSerial));
        }

        String dehestanSerial = (String) frm.get(DEHESTAN_SERIAL).toString();
        if (Utils.isEmpty(dehestanSerial)) {
          addError(msgs, FIELD_CAN_NOT_BE_EMPTY, "دهستان");
          setFocusControl(frm, GEO_DESC);
        } else if (!Utils.isValidNotZeroNumber(dehestanSerial, 6)) {
          addError(msgs, FIELD_INVALID, "دهستان");
          setFocusControl(frm, GEO_DESC);
        } else {
          inf.setDehestanSerial(Integer.parseInt(dehestanSerial));
        }

        if (Utils.isEmpty(frm.get(CODE_ACTIVE_FLAG))) {
          inf.setCodeActiveFlag(Constants.CodeActiveFlag.ACTIVE);
        } else {
          inf.setCodeActiveFlag(Constants.CodeActiveFlag.INACTIVE);
        }
      }

      if (!msgs.isEmpty()) {
        saveErrors(httpServletRequest, msgs);
        return actionMapping.findForward(EDIT);
      }
      resetFocusControl(frm, CANCEL);
      try {
        Geo.saveVillage(getFormMode(frm), inf);
        httpServletRequest.setAttribute(BROWSE_KEY, inf.getKey());
        return actionMapping.findForward(SUCCESS);
      } catch (Exception ex) {
        resetFocusControl(frm, CANCEL);
        addError(msgs, ex.getMessage());
        saveErrors(httpServletRequest, msgs);
        return actionMapping.findForward(EDIT);
      }
    }
  }
Пример #15
0
  public ActionForward execute(
      ActionMapping actionMapping,
      ActionForm actionForm,
      HttpServletRequest httpServletRequest,
      HttpServletResponse httpServletResponse)
      throws Exception {

    LazyValidatorForm frm = (LazyValidatorForm) actionForm;
    LoginInfo loginInfo = (LoginInfo) httpServletRequest.getSession().getAttribute("loginInfo");
    if (formCanceled(frm)) {
      return actionMapping.findForward(SUCCESS);
    }
    resetFocusControl(frm, CANCEL);
    ActionMessages msgs = new ActionMessages();
    DocInvTransactionInfo inf = new DocInvTransactionInfo();
    if (!formSaved(frm)) {
      setFormMode(frm, ((String) httpServletRequest.getParameter(BROWSE_ACTION)));
      setFormId(frm, (String) httpServletRequest.getParameter(BROWSE_ID));
      try {
        short officeCode = loginInfo.getOfficeCode();
        if (!loginInfo.userHasAccess(getFormId(frm), getFormMode(frm))) {
          if (isFormInModifyMode(frm)
              && loginInfo.userHasAccess(getFormId(frm), Constants.ActionType.ENQUERY)) {
            setFormMode(frm, Constants.ActionType.ENQUERY);
          } else {
            throw new Exception(INVALID_ACCESS);
          }
        }
        if (!isFormInAddMode(frm)) {
          String formKey = (String) httpServletRequest.getParameter(BROWSE_KEY);
          frm.set("formKey", formKey);
          StringTokenizer st = new StringTokenizer(formKey, Constants.DATA_SEPARATOR);
          officeCode = Short.parseShort(st.nextToken());
          String eventType = st.nextToken();
          String docType = st.nextToken();
          String docSeri = st.nextToken().trim();
          int docStartSrno = Integer.parseInt(st.nextToken());
          inf = Inventory.getDetails(officeCode, eventType, docType, docSeri, docStartSrno);
          frm.set(ASSIGN_DATE, DateUtils.revFormatDate(inf.getEventDate()));
          frm.set(DOC_SERI, inf.getDocSeri());
          frm.set(DOC_START_SRNO, Integer.toString(inf.getDocStartSrno()));
          frm.set(DOC_END_SRNO, Integer.toString(inf.getDocEndSrno()));
        }
        if (isFormInAddMode(frm)) {
          frm.set(ASSIGN_DATE, DateUtils.fDateRevFormatted());
          resetFocusControl(frm, DOC_SERI);
        }

      } catch (Exception ex) {
        addError(msgs, ex.getMessage());
        saveErrors(httpServletRequest, msgs);
      }
      return actionMapping.findForward(EDIT);

    } else {
      String assignDate = ((String) frm.get(ASSIGN_DATE)).trim();
      if (Utils.isEmpty(assignDate)) {
        addError(msgs, FIELD_CAN_NOT_BE_EMPTY, "تاريخ تخصيص");
        setFocusControl(frm, ASSIGN_DATE);
      } else if (!DateUtils.isValidRevFormattedFDate(assignDate)
          || Integer.parseInt(DateUtils.unformatRevFormattedFdate(assignDate))
              > Integer.parseInt(DateUtils.fDate())) {
        addError(msgs, FIELD_INVALID, "تاريخ تخصيص");
        setFocusControl(frm, ASSIGN_DATE);
      } else {
        inf.setEventDate(DateUtils.unformatRevFormattedFdate(assignDate));
      }
      inf.setOfficeCode(loginInfo.getOfficeCode());
      inf.setEventType(Constants.EventType.ASSIGN);

      String docSeri = Utils.charVal2((String) frm.get(DOC_SERI));
      if (Utils.isEmpty(docSeri)) {
        addError(msgs, FIELD_INVALID, "سري كارتهاي شناسايي");
        setFocusControl(frm, DOC_SERI);
      } else {
        inf.setDocSeri(docSeri);
        frm.set(DOC_SERI, docSeri);
      }
      String docStartSrno = ((String) frm.get(DOC_START_SRNO)).trim();
      if (Utils.isEmpty(docStartSrno)) {
        addError(msgs, FIELD_CAN_NOT_BE_EMPTY, "سريال شروع");
        setFocusControl(frm, DOC_START_SRNO);
      }
      String docEndSrno = ((String) frm.get(DOC_END_SRNO)).trim();
      if (Utils.isEmpty(docEndSrno)) {
        addError(msgs, FIELD_CAN_NOT_BE_EMPTY, "سريال خاتمه");
        setFocusControl(frm, DOC_END_SRNO);
      } else {
        if (!Utils.isValidNumber(docStartSrno, 6) || !Utils.isValidNumber(docEndSrno, 6)) {
          addError(msgs, FIELD_INVALID, "محدوده سريال كارت شناسايي");
          setFocusControl(frm, DOC_START_SRNO);
        } else {
          if (Integer.parseInt(docStartSrno) > Integer.parseInt(docEndSrno)) {
            addError(msgs, FIELD_INVALID, "محدوده سريال كارت شناسايي");
            setFocusControl(frm, DOC_START_SRNO);
          } else {
            inf.setDocStartSrno(Integer.parseInt(docStartSrno));
            inf.setDocEndSrno(Integer.parseInt(docEndSrno));
          }
        }
      }

      inf.setMamoorId("9991");
      inf.setUserId(loginInfo.getUserId());
      inf.setDocType(Constants.DocType.ID_CARD_CENTRAL_BANK);

      if (!msgs.isEmpty()) {
        saveErrors(httpServletRequest, msgs);
        return actionMapping.findForward(EDIT);
      }
      resetFocusControl(frm, CANCEL);
      // Save Data
      try {
        String eventErrorCode = null;
        if (isFormInDeleteMode(frm)) {
          eventErrorCode = Inventory.deleteAssign(inf);
        } else {
          eventErrorCode = Inventory.addAssign(inf);
        }
        if (!Utils.isEmpty(eventErrorCode)) {
          StringTokenizer st = new StringTokenizer(eventErrorCode, Constants.FIELD_SEPARATOR);
          int countErrorToken = st.countTokens();
          for (int countError = 1; countError <= countErrorToken; countError++) {
            addError(msgs, st.nextToken());
          }
          saveErrors(httpServletRequest, msgs);
          return actionMapping.findForward(EDIT);
        } else {
          httpServletRequest.setAttribute(BROWSE_KEY, inf.getKey());
          return actionMapping.findForward(SUCCESS);
        }
      } catch (Exception ex) {
        resetFocusControl(frm, CANCEL);
        addError(msgs, ex.getMessage());
        saveErrors(httpServletRequest, msgs);
        return actionMapping.findForward(EDIT);
      }
    }
  }