Ejemplo n.º 1
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);
      }
    }
  }
Ejemplo n.º 2
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);
      }
    }
  }