public void reapetAjaxSideServer(LazyValidatorForm frm, HttpServletRequest request) throws Exception { long country = 0; try { if (frm.get(CONSUL_GEO) != null && !Utils.isEmpty(String.valueOf(frm.get(CONSUL_GEO)))) country = Long.parseLong(String.valueOf(frm.get(CONSUL_GEO))); Vector vConsulHozeh = new Vector(); if (country != 0) vConsulHozeh = Place.listConsulHozeh(country); vConsulHozeh.add(0, new CodeDesc("", "")); request.getSession().setAttribute("consulHozehList", vConsulHozeh); } catch (Exception ex) { Utils.log4j(ex); } }
private String getDateOfDeath(long personNin) throws Exception { String deathDate = ""; try { IranianInfo info = (IranianInfo) Person.getIranianDetails(personNin); if (info != null && !Utils.isEmpty(info.getDeathStatus()) && info.getDeathStatus().equalsIgnoreCase(Constants.DeathStatus.DEAD)) { String deathKey = Person.getDeathKey(personNin); if (!Utils.isEmpty(deathKey)) { DeathExtInfo deathInfo = Person.getDeathDetails( Long.parseLong(deathKey.split(Constants.DATA_SEPARATOR_SPLIT)[0]), Short.parseShort(deathKey.split(Constants.DATA_SEPARATOR_SPLIT)[1])); if (deathInfo != null) deathDate = deathInfo.getDateOfDeath(); } } if (!Utils.isEmpty(deathDate) && !deathDate.equalsIgnoreCase("نامعلوم")) return DateUtils.unformatSpaceToZeroDate(deathDate); else return ""; } catch (Exception ex) { Utils.log4j(ex); return ""; } }
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; }