Esempio n. 1
0
  public ActionForward execute(
      ActionMapping mapping,
      ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response)
      throws Exception {
    LazyValidatorForm frm = (LazyValidatorForm) form;
    LoginInfo loginInfo = getLoginInfo(request);
    DivorceIranianSpouseInfo hsbInf = null;
    DivorceIranianSpouseInfo wfInf = null;
    DivorceInfo divInf = null;
    MarriageInfo mrgInf = null;
    InactiveDivorceInfo inactiveDivInf = null;
    frm.set(VIRTUAL_MODIFY_SAVE, "");

    ActionMessages msgsWarning = new ActionMessages();
    if (frm.get(VIRTUAL_WARNING_CONFIRM) == null
        || frm.get(VIRTUAL_WARNING_CONFIRM).toString().equalsIgnoreCase("")
        || !frm.get(VIRTUAL_WARNING_CONFIRM)
            .toString()
            .equalsIgnoreCase(Value_True_False_Is.TRUE)) {
      msgsWarning = (ActionMessages) request.getSession().getAttribute("warnings");
      saveErrors(request, msgsWarning);
    } else {
      if (request.getSession().getAttribute("hsbInf_2") != null)
        hsbInf = (DivorceIranianSpouseInfo) request.getSession().getAttribute("hsbInf_2");
      if (request.getSession().getAttribute("wfInf_2") != null)
        wfInf = (DivorceIranianSpouseInfo) request.getSession().getAttribute("wfInf_2");
      if (request.getSession().getAttribute("divInf_2") != null)
        divInf = (DivorceInfo) request.getSession().getAttribute("divInf_2");
      if (request.getSession().getAttribute("mrgInf_2") != null)
        mrgInf = (MarriageInfo) request.getSession().getAttribute("mrgInf_2");
      if (request.getSession().getAttribute("inactiveDivorceInf_2") != null)
        inactiveDivInf =
            (InactiveDivorceInfo) request.getSession().getAttribute("inactiveDivorceInf_2");

      if (isFormInAddMode(frm)) {
        Person.saveDivIrn(getFormMode(frm), wfInf, hsbInf, divInf, null, null, null, mrgInf, null);
      }
      if (isFormInModifyMode(frm)) {
        DivorceIranianSpouseInfo husbandInf =
            (DivorceIranianSpouseInfo) request.getSession().getAttribute("modifyDivorceHusbandInf");
        DivorceIranianSpouseInfo wifeInf =
            (DivorceIranianSpouseInfo) request.getSession().getAttribute("modifyDivorceWifeInf");
        DivorceInfo divorceInf =
            (DivorceInfo) request.getSession().getAttribute("modifyDivorceInf");

        divInf.setDivorceId(divorceInf.getDivorceId());
        Vector changeVct =
            Common.gatherUpdateFields(divorceInf, husbandInf, wifeInf, divInf, hsbInf, wfInf);

        DivorceUpdateLogInfo changeInf = new DivorceUpdateLogInfo();
        changeInf.setDivorceId(divorceInf.getDivorceId());
        changeInf.setUserId(loginInfo.getUserId());
        changeInf.setMamoorId((new Security()).getMamoorIdByUserId(loginInfo.getUserId()));
        changeInf.setOfficeCode(loginInfo.getOfficeCode());

        /**/
        MarriageInfo preMrgInf = null;
        if (changeVct.size() > 0) {
          for (int i = 0; i < changeVct.size(); i++) {
            if (changeVct
                .elementAt(i)
                .toString()
                .split(Constants.FIELD_SEPARATOR)[0]
                .equalsIgnoreCase(Short.toString(Constants.DivorceUpdateLogCode.MRG_DATE))) {
              preMrgInf =
                  Person.getMarriageDetails(
                      hsbInf.getPersonNin(),
                      wfInf.getPersonNin(),
                      changeVct.elementAt(i).toString().split(Constants.FIELD_SEPARATOR)[1]);
              if (preMrgInf != null) {
                preMrgInf.setCodeActiveFlag(Constants.CodeActiveFlag.ACTIVE);
              }
            }
          }
        }
        /**/
        resetFocusControl(frm, CANCEL);
        if (changeVct.size() > 0) {
          Person.saveDivIrn(
              getFormMode(frm),
              wfInf,
              hsbInf,
              divInf,
              null,
              changeInf,
              changeVct,
              mrgInf,
              preMrgInf);
          frm.set(VIRTUAL_MODIFY_SAVE, Value_True_False_Is.TRUE);
        }
      }
      if (isFormInDeleteMode(frm)) {
        inactiveDivInf.setDivorceId(divInf.getDivorceId());
        Person.saveDivIrn(
            getFormMode(frm), wfInf, hsbInf, divInf, inactiveDivInf, null, null, mrgInf, null);
      }
    }
    return mapping.findForward("ok");
  }
Esempio 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 {
        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);
      }
    }
  }
Esempio n. 3
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);
      }
    }
  }
Esempio n. 4
0
  public ActionMessages[] validMrgRecord(
      LazyValidatorForm frm, HttpServletRequest request, String action, boolean isOfficeManager)
      throws Exception {
    ActionMessages msgs[] = new ActionMessages[2];
    ActionMessages msgsErrors = new ActionMessages();
    ActionMessages msgsWarnings = new ActionMessages();
    MarriageInfo mrgInf = null;
    InactiveMarriageInfo inactiveMrgInf = null;

    mrgInf = new MarriageInfo();
    inactiveMrgInf = new InactiveMarriageInfo();
    LoginInfo loginInfo = getLoginInfo(request);
    try {
      if (action.equalsIgnoreCase(Constants.ActionType.ADD)
          || action.equalsIgnoreCase(Constants.ActionType.MODIFY)) {
        reapetAjaxSideServer(frm, request);

        String regstLable = "";
        String regstAuLabel = "";
        String regstRegstGeoLabel = "";
        boolean isConsul = false;
        mrgInf.setForeignStatusCode(Short.toString(Constants.ForeignStatusCode.FOREIGN));
        String marConfirm = frm.get(MARRIAGE_CONFIRM_AUT_CODE).toString().trim();
        if (!Utils.isEmpty(marConfirm)) {
          mrgInf.setMarriageConfirmAutCode(marConfirm);
          switch (Short.parseShort(frm.get(MARRIAGE_CONFIRM_AUT_CODE).toString())) {
            case Constants.MarriageConfirmAut.DECLARATION:
              frm.set(
                  MARRIAGE_REGST_REF, String.valueOf(Constants.MarriageRegstRef.MARRIAGE_OFFICE));
              regstLable = " ثبت ازدواج";
              regstAuLabel = "شماره دفترخانه ازدواج ";
              regstRegstGeoLabel = "محل دفترخانه ازدواج ";

              break;
            case Constants.MarriageConfirmAut.PROFESSION:
              frm.set(
                  MARRIAGE_REGST_REF,
                  String.valueOf(Constants.MarriageRegstRef.FORMAL_DOCUMENT_OFFICE));
              regstLable = " اقرارنامه";
              regstAuLabel = "شماره دفترخانه اسناد رسمي ";
              regstRegstGeoLabel = "محل دفترخانه اسناد رسمي ";

              break;
            case Constants.MarriageConfirmAut.PETITION:
              frm.set(MARRIAGE_REGST_REF, String.valueOf(Constants.MarriageRegstRef.COURT));
              regstLable = " دادنامه";
              regstAuLabel = "شماره شعبه ";
              regstRegstGeoLabel = "محل شعبه ";

              break;
            case Constants.MarriageConfirmAut.CONSULE:
              frm.set(
                  MARRIAGE_REGST_REF, String.valueOf(Constants.MarriageRegstRef.MARRIAGE_OFFICE));
              isConsul = true;
              regstLable = " ثبت ازدواج";
              regstAuLabel = "حوزه کنسولي تابعه ";
              regstRegstGeoLabel = "نام کشور ";

              break;
          }
        }
        boolean isDouplicateMarriageRecord = false;
        boolean isDouplicateMarriageHsb = false;
        boolean isDouplicateMarriageWf = false;

        if (action.equalsIgnoreCase(Constants.ActionType.ADD)
            && !Utils.isEmpty(frm.get(HSB_NO).toString().trim())
            && Utils.isValidFoPersonalityNo(frm.get(HSB_NO).toString().trim())
            && !Utils.isEmpty(frm.get(WF_NIN).toString().trim())
            && Utils.isValidNin(frm.get(WF_NIN).toString().trim())
            && !Utils.isEmpty(frm.get(MARRIAGE_DATE).toString().trim())
            && ((!isOfficeManager
                    && DateUtils.isValidRevFormattedFDate(((String) frm.get(MARRIAGE_DATE)).trim()))
                || (isOfficeManager
                    && DateUtils.isValidNaghesOrCompDate(
                        ((String) frm.get(MARRIAGE_DATE)).trim())))) {
          String hsbNo = frm.get(HSB_NO).toString().trim();
          long wfNin = Long.parseLong(frm.get(WF_NIN).toString().trim());
          String marriageDate = DateUtils.getCompleteDate(((String) frm.get(MARRIAGE_DATE)).trim());

          isDouplicateMarriageRecord = Person.isDouplicateMarriage(hsbNo, wfNin, marriageDate);
          isDouplicateMarriageWf = Person.isDouplicateMarriageWife(wfNin, marriageDate);

          if (isDouplicateMarriageRecord) {
            addError(msgsErrors, "errIsDouplicateMarriage_3F");
            setFocusControl(frm, HSB_NO);
          } else {
            if (isDouplicateMarriageWf) {
              addError(msgsWarnings, "errIsDouplicateMarriageWf_3F");
              setFocusControl(frm, HSB_NO);
            }
          }
        }

        if (msgsErrors.isEmpty()) {
          String mrgType = frm.get(MARRIAGE_TYPE).toString().trim();
          if (Utils.isEmpty(mrgType)) {
            addError(msgsErrors, FIELD_CAN_NOT_BE_EMPTY, "نوع ازدواج");
            setFocusControl(frm, MARRIAGE_TYPE);
          } else if (mrgType.length() > 1) {
            addError(msgsErrors, FIELD_INVALID, "نوع ازدواج");
            setFocusControl(frm, MARRIAGE_TYPE);
          } else {
            mrgInf.setMarriageTypeCode(mrgType);
          }
          String marRegstRef = frm.get(MARRIAGE_REGST_REF).toString().trim();
          if (Utils.isEmpty(marRegstRef)) {
            addError(msgsErrors, FIELD_CAN_NOT_BE_EMPTY, "مرجع ثبت");
            setFocusControl(frm, MARRIAGE_REGST_REF);
          } else if (marRegstRef.length() > 2) {
            addError(msgsErrors, FIELD_INVALID, "مرجع ثبت");
            setFocusControl(frm, MARRIAGE_REGST_REF);
          } else {
            mrgInf.setMarriageRegstRefCode(marRegstRef);
          }
          String marriageDate = "";
          String husbandNo = "";
          long wifeNin = 0;
          String hsbDeathDate = "";
          String wfDeathDate = "";
          String lastBeforHsbDateOfDeath = "";
          String lastAfterDateOfMarriage = "";

          if (!Utils.isEmpty(frm.get(HSB_NO).toString().trim())) {
            husbandNo = frm.get(HSB_NO).toString().trim();
          }
          if (!Utils.isEmpty(frm.get(WF_NIN).toString().trim())
              && Utils.isValidNin(frm.get(WF_NIN).toString().trim())) {
            wifeNin = Long.parseLong(frm.get(WF_NIN).toString().trim());
            String wifeDateOfDeath = getDateOfDeath(wifeNin);
            if (!Utils.isEmpty(wifeDateOfDeath))
              wfDeathDate = DateUtils.unformatSpaceToZeroDate(wifeDateOfDeath);
            IranianInfo wfInfo = (IranianInfo) Person.getIranianDetails(wifeNin);
            if (wfInfo != null) {
              if (!Utils.isEmpty(frm.get(MARRIAGE_DATE).toString().trim())
                  && ((!isOfficeManager
                          && DateUtils.isValidRevFormattedFDate(
                              ((String) frm.get(MARRIAGE_DATE)).trim()))
                      || (isOfficeManager
                          && DateUtils.isValidNaghesOrCompDate(
                              ((String) frm.get(MARRIAGE_DATE)).trim())))) {
                MarriageInfo lastBeforMarriage =
                    Person.getLastBeforMarriageDetails(
                        wifeNin,
                        DateUtils.getCompleteDate(((String) frm.get(MARRIAGE_DATE)).trim()));

                MarriageInfo lastAfterMarriage =
                    Person.getLastAfterMarriageDetails(
                        wifeNin,
                        DateUtils.getCompleteDate(((String) frm.get(MARRIAGE_DATE)).trim()));

                long hsbBeforNin = 0;

                if (lastBeforMarriage != null) {
                  hsbBeforNin = lastBeforMarriage.getHusbandNin();
                  lastBeforHsbDateOfDeath = getDateOfDeath(hsbBeforNin);
                }
                if (lastAfterMarriage != null) {
                  lastAfterDateOfMarriage = lastAfterMarriage.getMarriageDate();
                }
              }
            }
          }
          boolean marriageDateIsTrue = true;
          if (Utils.isEmpty(frm.get(MARRIAGE_DATE).toString().trim())) {
            addError(msgsErrors, FIELD_CAN_NOT_BE_EMPTY, "تاريخ ازدواج");
            setFocusControl(frm, MARRIAGE_DATE);
            marriageDateIsTrue = false;
          } else if ((!isOfficeManager
                  && !DateUtils.isValidRevFormattedFDate(((String) frm.get(MARRIAGE_DATE)).trim()))
              || isOfficeManager
                  && !DateUtils.isValidNaghesOrCompDate(((String) frm.get(MARRIAGE_DATE)).trim())) {
            addError(msgsErrors, FIELD_INVALID, "تاريخ ازدواج");
            setFocusControl(frm, MARRIAGE_DATE);
            marriageDateIsTrue = false;
          } else if (DateUtils.getCompleteDate(((String) frm.get(MARRIAGE_DATE)).trim())
                  .compareTo(DateUtils.fDate())
              > 0) {
            addError(msgsErrors, SHOULD_BE_LESS_EQUAL, "تاريخ ازدواج", "تاريخ روز ");
            setFocusControl(frm, MARRIAGE_DATE);
            marriageDateIsTrue = false;
          } else if (!Utils.isEmpty(frm.get(MARRIAGE_DATE).toString().trim())
              && ((!isOfficeManager
                      && DateUtils.isValidRevFormattedFDate(
                          ((String) frm.get(MARRIAGE_DATE)).trim()))
                  || isOfficeManager
                      && DateUtils.isValidNaghesOrCompDate(
                          ((String) frm.get(MARRIAGE_DATE)).trim()))
              && DateUtils.getCompleteDate(((String) frm.get(MARRIAGE_DATE)).trim())
                      .compareTo(DateUtils.fDate())
                  <= 0) {
            marriageDate = DateUtils.getCompleteDate(((String) frm.get(MARRIAGE_DATE)).trim());

            if (action.equalsIgnoreCase(Constants.ActionType.ADD)
                && !Utils.isEmpty(wfDeathDate)
                && !wfDeathDate.equalsIgnoreCase("نامعلوم")
                && Integer.parseInt(wfDeathDate) < Integer.parseInt(marriageDate)) {
              addError(msgsErrors, "errMrgDateIsGreaterWfDeathDate_3F");
              setFocusControl(frm, MARRIAGE_DATE);
              marriageDateIsTrue = false;
            }
          }
          if (marriageDateIsTrue) {
            mrgInf.setMarriageDate(DateUtils.unformatZeroToSpaceDate(marriageDate));
            if ((!Utils.isEmpty(lastBeforHsbDateOfDeath)
                    && marriageDate.compareTo(lastBeforHsbDateOfDeath) >= 0
                    && (marriageDate.compareTo(
                            Utils_3F.threeOrFourAndTenAfter(lastBeforHsbDateOfDeath, 4))
                        < 0))
                || (!Utils.isEmpty(hsbDeathDate)
                    && !Utils.isEmpty(lastAfterDateOfMarriage)
                    && lastAfterDateOfMarriage.compareTo(hsbDeathDate) >= 0
                    && (lastAfterDateOfMarriage.compareTo(
                            Utils_3F.threeOrFourAndTenAfter(hsbDeathDate, 4))
                        < 0))) {
              addError(msgsWarnings, "errHusbandDead130Day_3F");
              setFocusControl(frm, MARRIAGE_DATE);
            }
            DivorceInfo lastBeforDivorce =
                Person.getLastBeforDivorcesDetails(wifeNin, marriageDate);
            String lastBeforDivorceDate = "";
            if (lastBeforDivorce != null)
              lastBeforDivorceDate =
                  DateUtils.unformatSpaceToZeroDate(lastBeforDivorce.getDivorceDate());

            if (lastBeforDivorce != null
                && !lastBeforDivorce
                    .getDivorceTypeCode()
                    .equalsIgnoreCase(Constants.DivorceType.BAEN_GHEIR_MADKHULEH)
                && !lastBeforDivorce
                    .getDivorceTypeCode()
                    .equalsIgnoreCase(Constants.DivorceType.BAEN_SAER)
                && !Utils.isEmpty(lastBeforDivorceDate)
                && marriageDate.compareTo(lastBeforDivorceDate) >= 0
                && (lastBeforDivorceDate.compareTo(
                        Utils_3F.xMonthBefore(DateUtils.unformatSpaceToZeroDate(marriageDate), 3))
                    > 0)) {
              addError(msgsWarnings, "errLastDivorce90Day_3F");
              setFocusControl(frm, MARRIAGE_DATE);
            }
          }
          Vector allMarriage = Person.getAllMarriage(husbandNo, wifeNin);
          Vector allCorrespondingDivorce = new Vector();

          DivorceInfo correspondingDivorce = new DivorceInfo();
          for (int i = 0; i < allMarriage.size(); i++) {
            String correspondingMrgDate =
                ((MarriageInfo) allMarriage.elementAt(i)).getMarriageDate();
            correspondingDivorce =
                Person.getCorrespondingDivorce(husbandNo, wifeNin, correspondingMrgDate);
            if (correspondingDivorce != null) allCorrespondingDivorce.add(correspondingDivorce);
          }
          if (allMarriage.size() >= 3 && allCorrespondingDivorce.size() >= 3) {
            addError(msgsWarnings, "err3HusbandWifeMarriage_3F");
            setFocusControl(frm, HSB_NO);
          }

          int countAllDivorce = Person.getCountAllDivorce(husbandNo, wifeNin);
          if (countAllDivorce >= 9) {
            addError(msgsWarnings, "err9HusbandWifeDivorce_3F");
            setFocusControl(frm, HSB_NO);
          }

          if (mrgInf.getMarriageTypeCode().equalsIgnoreCase(Constants.MarriageType.BROKEN)) {
            String expDate = "";
            if (!Utils.isEmpty(frm.get(EXPIRY_DATE).toString().trim())) {
              if (((!isOfficeManager
                      && !DateUtils.isValidRevFormattedFDate(
                          ((String) frm.get(EXPIRY_DATE)).trim()))
                  || isOfficeManager
                      && !DateUtils.isValidNaghesOrCompDate(
                          ((String) frm.get(EXPIRY_DATE)).trim()))) {
                addError(msgsErrors, FIELD_INVALID, "تاريخ انقضاء");
                setFocusControl(frm, EXPIRY_DATE);
              } else if (!Utils.isEmpty(frm.get(EXPIRY_DATE).toString().trim())
                  && !Utils.isEmpty(marriageDate)
                  && marriageDate.compareTo(
                          DateUtils.getCompleteDate(((String) frm.get(EXPIRY_DATE)).trim()))
                      > 0) {
                addError(msgsErrors, SHOULD_BE_GREATER_EQUAL, "تاريخ انقضاء", "تاريخ ازدواج");
                setFocusControl(frm, EXPIRY_DATE);
              } else {
                expDate = DateUtils.getCompleteDate(((String) frm.get(EXPIRY_DATE)).trim());
                mrgInf.setExpiryDate(DateUtils.unformatZeroToSpaceDate(expDate));
              }
            }
          } else if (mrgInf.getMarriageTypeCode().equalsIgnoreCase(Constants.MarriageType.BROKEN)) {
            mrgInf.setExpiryDate("");
          }
          String regstDate = frm.get(REGST_DATE).toString().trim();

          if (Utils.isEmpty(regstDate)) {
            addError(msgsErrors, FIELD_CAN_NOT_BE_EMPTY, "تاريخ " + regstLable);
            setFocusControl(frm, REGST_DATE);
          } else if ((!isOfficeManager
                  && !DateUtils.isValidRevFormattedFDate(((String) frm.get(REGST_DATE)).trim()))
              || isOfficeManager
                  && !DateUtils.isValidNaghesOrCompDate(((String) frm.get(REGST_DATE)).trim())) {
            addError(msgsErrors, FIELD_INVALID, "تاريخ " + regstLable);
            setFocusControl(frm, REGST_DATE);
          } else if (DateUtils.getCompleteDate(regstDate).compareTo(DateUtils.fDate()) > 0) {
            addError(msgsErrors, SHOULD_BE_LESS_EQUAL, "تاريخ " + regstLable, "تاريخ روز ");
            setFocusControl(frm, REGST_DATE);
          } else {
            boolean regstDateIsTrue = true;
            regstDate = DateUtils.getCompleteDate(((String) frm.get(REGST_DATE)).trim());
            if (!Utils.isEmpty(frm.get(HSB_DATE_OF_BIRTH_SUN).toString().trim())
                && (DateUtils.getCompleteDate(((String) frm.get(HSB_DATE_OF_BIRTH_SUN)).trim()))
                        .compareTo(regstDate)
                    >= 0) {
              addError(msgsErrors, SHOULD_BE_GREATER, "تاريخ " + regstLable, "تاريخ تولد زوج");
              setFocusControl(frm, REGST_DATE);
              regstDateIsTrue = false;
            }
            if (!Utils.isEmpty(frm.get(WF_DATE_OF_BIRTH_SUN).toString().trim())
                && (DateUtils.getCompleteDate(((String) frm.get(WF_DATE_OF_BIRTH_SUN)).trim()))
                        .compareTo(regstDate)
                    >= 0) {
              addError(msgsErrors, SHOULD_BE_GREATER, "تاريخ " + regstLable, "تاريخ تولد زوجه");
              setFocusControl(frm, REGST_DATE);
              regstDateIsTrue = false;
            }
            if (!Utils.isEmpty(marriageDate) && marriageDate.compareTo(regstDate) > 0) {
              addError(msgsErrors, SHOULD_BE_GREATER_EQUAL, "تاريخ " + regstLable, "تاريخ ازدواج");
              setFocusControl(frm, REGST_DATE);
              regstDateIsTrue = false;
            }
            if (regstDateIsTrue) {
              mrgInf.setRegstDate(
                  DateUtils.unformatZeroToSpaceDate(
                      DateUtils.getCompleteDate(frm.get(REGST_DATE).toString().trim())));
            }
          }
          String regstNo = Utils.charVal2((String) frm.get(REGST_NO));
          if (Utils.isEmpty(regstNo)) {
            addError(msgsErrors, FIELD_CAN_NOT_BE_EMPTY, "شماره " + regstLable);
            setFocusControl(frm, REGST_NO);
          } else if (regstNo.length() > 20 || regstNo.matches("[0]*")) {
            addError(msgsErrors, FIELD_INVALID, "شماره " + regstLable);
            setFocusControl(frm, REGST_NO);
          } else {
            mrgInf.setRegstNo(regstNo);
          }

          String regstAu = "";
          if (!isConsul) regstAu = Utils.charVal2((String) frm.get(REGST_AU));
          else if (isConsul) regstAu = Utils.charVal2((String) frm.get(CONSUL_NO));
          if (Utils.isEmpty(regstAu)) {
            addError(msgsErrors, FIELD_CAN_NOT_BE_EMPTY, regstAuLabel);
            setFocusControl(frm, REGST_AU);
          } else if ((!isConsul && !Utils.isValidNumber(regstAu, 10) || regstAu.matches("[0]*"))
              || (isConsul && regstAu.length() > 10)) {
            addError(msgsErrors, FIELD_INVALID, regstAuLabel);
            setFocusControl(frm, REGST_AU);
          } else {
            mrgInf.setRegstAu(regstAu);
          }
          String regstGeo = "";
          if (!isConsul) regstGeo = ((String) frm.get(REGST_GEO));
          else if (isConsul) regstGeo = ((String) frm.get(CONSUL_GEO));
          if (Utils.isEmpty(regstGeo)) {
            addError(msgsErrors, FIELD_CAN_NOT_BE_EMPTY, regstRegstGeoLabel);
            setFocusControl(frm, REGST_GEO);
          } else if (!isConsul && searchOfficeGeoSerial(frm) == false) {
            addError(msgsErrors, FIELD_INVALID, regstRegstGeoLabel);
            setFocusControl(frm, REGST_GEO);
          } else {

            mrgInf.setRegstGeoSerial(regstGeo);
          }

          if (action.equalsIgnoreCase(Constants.ActionType.ADD)) {
            mrgInf.setMamoorId((new Security()).getMamoorIdByUserId(loginInfo.getUserId()));
            mrgInf.setUserId(loginInfo.getUserId());
            mrgInf.setOfficeCode(loginInfo.getOfficeCode());
          }
          mrgInf.setCodeActiveFlag(Constants.CodeActiveFlag.ACTIVE);
        }
      } else if (action.equalsIgnoreCase(Constants.ActionType.DELETE)) {
        String marriageDate =
            DateUtils.unformatZeroToSpaceDate(
                DateUtils.getCompleteDate(frm.get(MARRIAGE_DATE).toString().trim()));

        mrgInf =
            Person.getMarriageDetails(
                frm.get(HSB_NO).toString().trim(),
                Long.parseLong(frm.get(WF_NIN).toString().trim()),
                marriageDate);

        mrgInf.setInactiveMarriageReasonCode(Constants.InactiveMrgReasonCode.DELETE);

        String opinionNo = Utils.charVal2(frm.get(OPINION_NO).toString().trim());
        frm.set(OPINION_NO, opinionNo);
        if (Utils.isEmpty(opinionNo)) {
          addError(msgsErrors, FIELD_CAN_NOT_BE_EMPTY, "شماره رأي هيأت ");
          setFocusControl(frm, OPINION_NO);
        } else if (opinionNo.length() > 20) {
          addError(msgsErrors, FIELD_INVALID, "شماره رأي هيأت ");
          setFocusControl(frm, OPINION_NO);
        } else {
          inactiveMrgInf.setOpinionNo(opinionNo);
        }
        String opinionDate = "";
        if (Utils.isEmpty(frm.get(OPINION_DATE).toString().trim())) {
          addError(msgsErrors, FIELD_CAN_NOT_BE_EMPTY, "تاريخ رأي هيأت ");
          setFocusControl(frm, OPINION_DATE);
        } else if ((!isOfficeManager
                && !DateUtils.isValidRevFormattedFDate(((String) frm.get(OPINION_DATE)).trim()))
            || isOfficeManager
                && !DateUtils.isValidNaghesOrCompDate(((String) frm.get(OPINION_DATE)).trim())) {
          addError(msgsErrors, FIELD_INVALID, "تاريخ رأي هيأت ");
          setFocusControl(frm, OPINION_DATE);
        } else if (DateUtils.getCompleteDate(((String) frm.get(OPINION_DATE)).trim())
                .compareTo(DateUtils.fDate())
            > 0) {
          addError(msgsErrors, SHOULD_BE_LESS_EQUAL, "تاريخ رأي هيأت ", "تاريخ روز ");
          setFocusControl(frm, OPINION_DATE);
        } else if (DateUtils.getCompleteDate(((String) frm.get(OPINION_DATE)).trim())
                .compareTo(DateUtils.getCompleteDate(((String) frm.get(MARRIAGE_DATE)).trim()))
            < 0) {
          addError(msgsErrors, SHOULD_BE_GREATER_EQUAL, "تاريخ رأي هيأت ", "تاريخ ازدواج");
          setFocusControl(frm, OPINION_DATE);
        } else {
          opinionDate = DateUtils.getCompleteDate(((String) frm.get(OPINION_DATE)).trim());
          inactiveMrgInf.setOpinionDate(DateUtils.unformatZeroToSpaceDate(opinionDate));
        }
        mrgInf.setInactiveMarriageReasonCode(Constants.InactiveMrgReasonCode.DELETE);
        mrgInf.setCodeActiveFlag(Constants.CodeActiveFlag.INACTIVE);
        inactiveMrgInf.setMamoorId((new Security()).getMamoorIdByUserId(loginInfo.getUserId()));

        inactiveMrgInf.setUserId(loginInfo.getUserId());

        inactiveMrgInf.setOfficeCode(loginInfo.getOfficeCode());
      }

      request.getSession().setAttribute("marriageInf", mrgInf);
      request.getSession().setAttribute("inactiveMarriageInf", inactiveMrgInf);
      msgs[0] = msgsErrors;
      msgs[1] = msgsWarnings;
    } catch (Exception ex) {
      Utils.log4j(ex);
    }
    return msgs;
  }
Esempio n. 5
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);
      }
    }
  }
Esempio n. 6
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);
      }
    }
  }
Esempio n. 7
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);
          DeathReasonGroupInfo inf = Misc.getDeathReasonGroupDetails(Short.parseShort(formKey));
          frm.set(DEATH_REASON_GROUP_CODE, Long.toString(inf.getReasonCode()));
          frm.set(DEATH_REASON_GROUP_DESC, inf.getReasonDesc());
          if (inf.isInactive()) {
            frm.set(CODE_ACTIVE_FLAG, "on");
          }
        }
        if (isFormInAddMode(frm)) {
          resetFocusControl(frm, DEATH_REASON_GROUP_CODE);
        } else if (isFormInModifyMode(frm)) {
          resetFocusControl(frm, DEATH_REASON_GROUP_DESC);
        }
      } catch (Exception ex) {
        addError(msgs, ex.getMessage());
        saveErrors(httpServletRequest, msgs);
      }
      return actionMapping.findForward(EDIT);
    } else {
      DeathReasonGroupInfo inf = new DeathReasonGroupInfo();
      String deathReasonGroupCode = ((String) frm.get(DEATH_REASON_GROUP_CODE)).trim();
      resetFocusControl(frm, "");
      if (Utils.isEmpty(deathReasonGroupCode)) {
        addError(msgs, FIELD_CAN_NOT_BE_EMPTY, "كد");
        setFocusControl(frm, DEATH_REASON_GROUP_CODE);
      } else if (!Utils.isValidNotZeroNumber(deathReasonGroupCode, 2)) {
        addError(msgs, FIELD_INVALID, "كد");
        setFocusControl(frm, DEATH_REASON_GROUP_CODE);
      } else {
        inf.setReasonCode(Short.parseShort(deathReasonGroupCode));
      }

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

        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 {
        Misc.saveDeathReasonGroup(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);
      }
    }
  }