Example usage for com.liferay.portal.kernel.servlet SessionErrors isEmpty

List of usage examples for com.liferay.portal.kernel.servlet SessionErrors isEmpty

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.servlet SessionErrors isEmpty.

Prototype

public static boolean isEmpty(PortletRequest portletRequest) 

Source Link

Usage

From source file:org.oep.cmon.portlet.ipmslist.business.FormOfflineBusiness.java

License:Apache License

/**
 * This is function validationDataDoanhNghiep
 * Version: 1.0//from  www  .  j a  v  a2s.  c  o m
 *  
 * History: 
 *   DATE        AUTHOR      DESCRIPTION 
 *  ------------------------------------------------- 
 *  3-March-2013  Nam Dinh    Create new
 * @param maSoDoanhNghiep
 * @param maSothueDoanhNghiep
 * @param tenDoanhNghiep
 * @param soGiayPhepDangKyDoanhNghiep
 * @param ngayCapGiayPhepDangKyDoanhNghiep
 * @param tongSoVon
 * @param idLoaiDoiTuong
 * @param numberHome
 * @param idTinhHienTai
 * @param idHuyenHienTai
 * @param idXaHienTai
 * @param moTaNganhNgheKinhDoanh
 * @param quocGiaId
 * @param idTrangThai
 * @param actionRequest
 * @return boolean
 */
private boolean validationDataDoanhNghiep(String maSoDoanhNghiep, String maSothueDoanhNghiep,
        String tenDoanhNghiep, String soGiayPhepDangKyDoanhNghiep, String ngayCapGiayPhepDangKyDoanhNghiep,
        String tongSoVon, String idLoaiDoiTuong, String numberHome, String idTinhHienTai, String idHuyenHienTai,
        String idXaHienTai, String moTaNganhNgheKinhDoanh, String quocGiaId, String idTrangThai,
        ActionRequest actionRequest) {
    SessionErrors.clear(actionRequest);
    if (tenDoanhNghiep.length() == 0) {
        SessionErrors.add(actionRequest, "requireTenDoanhNghiep");
    } else {
        DoanhNghiep doanhNghiep = DoanhNghiepLocalServiceUtil.findByTen(tenDoanhNghiep);
        if (doanhNghiep != null) {
            SessionErrors.add(actionRequest, "exitTenDoanhNghiep");
        }
    }
    if (ngayCapGiayPhepDangKyDoanhNghiep.trim().length() == 0) {
        SessionErrors.add(actionRequest, "requireNgayCapGiayPhepDangKyDoanhNghiep");
    } else {
        if (ConvertUtil.parseStringToDate(ngayCapGiayPhepDangKyDoanhNghiep).after(new Date())) {
            SessionErrors.add(actionRequest, "afterNgayCapGiayPhepDangKyDoanhNghiep");
        }
    }
    if (moTaNganhNgheKinhDoanh.length() == 0) {
        SessionErrors.add(actionRequest, "requireMoTaNganhNgheKinhDoanh");
    }

    if (maSoDoanhNghiep.trim().length() == 0) {
        SessionErrors.add(actionRequest, "requireMaSoDoanhNghiep");
    } else if (ConvertUtil.convertToLong(maSoDoanhNghiep) <= 0) {
        SessionErrors.add(actionRequest, "numberMaSoDoanhNghiep");
    } else {
        DoanhNghiep doanhNghiep = DoanhNghiepLocalServiceUtil.findByMaDoanhNghiep(maSoDoanhNghiep);
        if (doanhNghiep != null) {
            SessionErrors.add(actionRequest, "exitMaSoDoanhNghiep");
        }
    }
    if (maSothueDoanhNghiep.trim().length() == 0) {
        SessionErrors.add(actionRequest, "requireMaSothueDoanhNghiep");
    } else if (ConvertUtil.convertToLong(maSothueDoanhNghiep) <= 0) {
        SessionErrors.add(actionRequest, "numberMaSothueDoanhNghiep");
    } else {
        DoanhNghiep doanhNghiep = DoanhNghiepLocalServiceUtil.findByMaSoThue(maSothueDoanhNghiep);
        if (doanhNghiep != null) {
            SessionErrors.add(actionRequest, "exitMaSothueDoanhNghiep");
        }
    }
    if (soGiayPhepDangKyDoanhNghiep.trim().length() == 0) {
        SessionErrors.add(actionRequest, "requireSoGiayPhepDangKyDoanhNghiep");
    } else if (ConvertUtil.convertToLong(soGiayPhepDangKyDoanhNghiep) <= 0) {
        SessionErrors.add(actionRequest, "numberSoGiayPhepDangKyDoanhNghiep");
    } else {
        DoanhNghiep doanhNghiep = DoanhNghiepLocalServiceUtil.findBySoGCNDKKD(soGiayPhepDangKyDoanhNghiep);
        if (doanhNghiep != null) {
            SessionErrors.add(actionRequest, "exitSoGiayPhepDangKyDoanhNghiep");
        }
    }
    if (tongSoVon.trim().length() == 0) {
        SessionErrors.add(actionRequest, "requireTongSoVon");
    } else if (ConvertUtil.convertToLong(tongSoVon) <= 0) {
        SessionErrors.add(actionRequest, "numberTongSoVon");
    }
    if (ConvertUtil.convertToLong(quocGiaId) <= 0) {
        SessionErrors.add(actionRequest, "numberQuocGia");
    }
    if (ConvertUtil.convertToLong(idLoaiDoiTuong) <= 0) {
        SessionErrors.add(actionRequest, "numberLoaiDoiTuong");
    }
    if (numberHome.length() == 0) {
        SessionErrors.add(actionRequest, "requireNumberhome");
    }
    if (ConvertUtil.convertToInt(idTinhHienTai) == 0) {
        SessionErrors.add(actionRequest, "requireTinh");
    }
    if (ConvertUtil.convertToInt(idHuyenHienTai) == 0) {
        SessionErrors.add(actionRequest, "requireHuyen");
    }
    if (ConvertUtil.convertToInt(idXaHienTai) == 0) {
        SessionErrors.add(actionRequest, "requireXa");
    }
    if (ConvertUtil.convertToLong(idTrangThai) <= 0) {
        SessionErrors.add(actionRequest, "numberIdTrangThai");
    }

    if (SessionErrors.isEmpty(actionRequest)) {
        return true;
    }

    return false;
}

From source file:org.oep.cmon.portlet.quanlyvaitro.action.QuanLyVaiTroPortlet.java

License:Apache License

/**
 * This is function validationVaiTroInput
 * Version: 1.0/*from www  . j a  v  a 2  s . c  o  m*/
 *  
 * History: 
 *   DATE        AUTHOR      DESCRIPTION 
 *  ------------------------------------------------- 
 *  3-March-2013  Nam Dinh    Create new
 * @param vaiTroId
 * @param ten 
 * @param ma
 * @param ungDungId
 * @param trangThai
 * @param actionRequest
 * @throws Exception
 * @return boolean
 */
private boolean validationVaiTroInput(String vaiTroId, String ten, String ma, String ungDungId,
        String trangThai, ActionRequest actionRequest) throws Exception {

    if (Helpers.isEmpty(ten)) {
        SessionErrors.add(actionRequest, "emptyTen");
    }
    if (Helpers.isEmpty(ma)) {
        SessionErrors.add(actionRequest, "emptyMa");
    } else {
        if (QuanLyVaiTroBusiness.checkExistingVaiTro(vaiTroId, ma)) {
            SessionErrors.add(actionRequest, "existMa");
        }
    }
    if (Helpers.isEmpty(ungDungId)) {
        SessionErrors.add(actionRequest, "emptyUngDungId");
    }
    if (Helpers.isEmpty(trangThai)) {
        SessionErrors.add(actionRequest, "emptyTrangThai");
    }

    if (SessionErrors.isEmpty(actionRequest)) {
        return true;
    }

    return false;
}

From source file:org.oep.cmon.portlet.tainguyen.action.TaiNguyenPortlet.java

License:Apache License

/**
 * This is function validationInput//from   www  . ja v a 2s  .co  m
 * Version: 1.0
 *  
 * History: 
 *   DATE        AUTHOR      DESCRIPTION 
 *  ------------------------------------------------- 
 *  3-March-2013  Nam Dinh    Create new
 * @param tenTaiNguyen
 * @param giaTri
 * @param loai
 * @param ungDungId
 * @param heThongId
 * @param taiNguyenId
 * @param actionRequest
 * @return boolean
 */
private boolean validationInput(String tenTaiNguyen, String giaTri, int loai, Long ungDungId, Long heThongId,
        long taiNguyenId, ActionRequest actionRequest) {

    if (tenTaiNguyen.trim().length() == 0) {
        SessionErrors.add(actionRequest, "emptyTenTaiNguyen");
    }
    if (giaTri.trim().length() == 0) {
        SessionErrors.add(actionRequest, "emptyGiaTri");
    }
    // Neu thong tin nhap khac rong
    if (SessionErrors.isEmpty(actionRequest)) {
        TaiNguyen taiNguyen = null;
        try {

            // Kiem tra theo Ten
            try {
                taiNguyen = null;
                taiNguyen = TaiNguyenLocalServiceUtil.findByTen(tenTaiNguyen, loai, giaTri, ungDungId,
                        heThongId, FormatUtil.DA_XOA_ACTIVATE);
            } catch (Exception es) {
            }
            if (taiNguyen != null) {
                if (taiNguyenId > 0) {
                    if (taiNguyenId != taiNguyen.getId()) {
                        SessionErrors.add(actionRequest, "existTenTaiNguyen");
                    }
                } else {
                    SessionErrors.add(actionRequest, "existTenTaiNguyen");
                }
            }

        } catch (Exception es) {
        }
    }

    if (SessionErrors.isEmpty(actionRequest)) {
        return true;
    }

    return false;
}

From source file:org.oep.cmon.portlet.taocongdan.action.TaoCongDanAction.java

License:Apache License

/**
  * This is fucntion addEditTaoCongDan/*from w w  w  .j  av  a2s  . com*/
  * Version: 1.0
  *  
  * History: 
  *   DATE        AUTHOR      DESCRIPTION 
  *  ------------------------------------------------- 
  *  3-March-2013  Nam Dinh    Create new
  * @param ActionRequest actionRequest, ActionResponse actionResponse
  * @return void
  */
public void addEditTaoCongDan(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception {
    String mode = ParamUtil.getString(actionRequest, "mode");
    String isLoaded = ParamUtil.getString(actionRequest, "isLoaded", null);
    ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);
    String taiKhoanCongDanId = ParamUtil.getString(actionRequest, "taiKhoanCongDanId");
    String congDanId = ParamUtil.getString(actionRequest, "congDanId");

    Map<String, String> userRequest = (Map<String, String>) actionRequest.getPortletSession()
            .getAttribute("USER_REQUEST_TK_CONG_DAN_OBJECT");
    if (userRequest == null) {
        userRequest = new HashMap<String, String>();
    }
    userRequest.put("mode", mode);

    userRequest.put("isLoaded", isLoaded);

    userRequest.put("congDanId", congDanId);

    userRequest.put("taiKhoanCongDanId", taiKhoanCongDanId);

    String email = ParamUtil.getString(actionRequest, "email");
    userRequest.put("email", email);

    String matKhau = ParamUtil.getString(actionRequest, "matKhau");
    userRequest.put("matKhau", matKhau);

    String reMatKhau = ParamUtil.getString(actionRequest, "reMatKhau");
    userRequest.put("reMatKhau", reMatKhau);

    String ma = ParamUtil.getString(actionRequest, "ma");
    userRequest.put("ma", ma);

    String ho = ParamUtil.getString(actionRequest, "ho", "");
    userRequest.put("ho", ho);
    String dem = ParamUtil.getString(actionRequest, "dem", "");
    userRequest.put("dem", dem);
    String ten = ParamUtil.getString(actionRequest, "ten");
    userRequest.put("ten", ten);

    String tenDayDu = ho + " " + dem + " " + ten;

    String ngaySinh = ParamUtil.getString(actionRequest, "ngaySinh");
    userRequest.put("ngaySinh", ngaySinh);

    String quocTichId = ParamUtil.getString(actionRequest, "quocTichId");
    userRequest.put("quocTichId", quocTichId);

    String soCmnd = ParamUtil.getString(actionRequest, "soCmnd");
    userRequest.put("soCmnd", soCmnd);

    String ngayCapCmnd = ParamUtil.getString(actionRequest, "ngayCapCmnd");
    userRequest.put("ngayCapCmnd", ngayCapCmnd);

    String noiCapCmndId = ParamUtil.getString(actionRequest, "noiCapCmndId");
    userRequest.put("noiCapCmndId", noiCapCmndId);

    String gioiTinh = ParamUtil.getString(actionRequest, "gioiTinh");
    userRequest.put("gioiTinh", gioiTinh);

    String tonGiaoId = ParamUtil.getString(actionRequest, "tonGiaoId");
    userRequest.put("tonGiaoId", tonGiaoId);

    String danTocId = ParamUtil.getString(actionRequest, "danTocId");
    userRequest.put("danTocId", danTocId);

    String diaChiThuongTruTinhId = ParamUtil.getString(actionRequest, "diaChiThuongTruTinhId");
    userRequest.put("diaChiThuongTruTinhId", diaChiThuongTruTinhId);

    String diaChiThuongTruHuyenId = ParamUtil.getString(actionRequest, "diaChiThuongTruHuyenId");
    userRequest.put("diaChiThuongTruHuyenId", diaChiThuongTruHuyenId);

    String diaChiThuongTruXaId = ParamUtil.getString(actionRequest, "diaChiThuongTruXaId");
    userRequest.put("diaChiThuongTruXaId", diaChiThuongTruXaId);

    String diaChiThuongTru = ParamUtil.getString(actionRequest, "diaChiThuongTru");
    userRequest.put("diaChiThuongTru", diaChiThuongTru);

    actionRequest.getPortletSession().setAttribute("USER_REQUEST_TK_CONG_DAN_OBJECT", userRequest);

    // Validate parameteter
    if (validate(userRequest, actionRequest, actionResponse)) {
        _log.info("1. validate info ok");

        TaoCongDanBusiness taoCongDanBusiness = new TaoCongDanBusiness();
        if (mode.equals(TaoCongDanBusiness.ADD_CONGDAN)) {

            User userLiferay = addUserLiferay(userRequest, actionRequest, actionResponse);

            try {

                if (userLiferay != null) {

                    // Update organization
                    String citizenOrg = getOrganizationForCitizen();
                    _log.info("citizenOrgCodeLoaiDoiTuong:" + citizenOrg);
                    Organization organization = OrganizationLocalServiceUtil
                            .getOrganization(userLiferay.getCompanyId(), citizenOrg);

                    long[] orgIds = { organization.getOrganizationId() };

                    UserLocalServiceUtil.updateOrganizations(userLiferay.getUserId(), orgIds,
                            new ServiceContext());

                    long userLiferayId = userLiferay.getUserId();

                    if (!this.userLiferayExists(userLiferayId) && !this.emailExists(email)) {

                        TaiKhoanNguoiDung taiKhoanNguoiDung = taoCongDanBusiness
                                .insertTaiKhoanNguoiDung(userLiferay, matKhau, email, tenDayDu, actionRequest);

                        if (taiKhoanNguoiDung != null) {
                            String maCongDan = taoCongDanBusiness.congdanExists(soCmnd, ngaySinh);
                            _log.info("maCongDan" + maCongDan);
                            if (Validator.isNull(maCongDan)) {
                                CongDan congDan1 = CongDanLocalServiceUtil
                                        .findByTaiKhoanNguoiDungId(taiKhoanNguoiDung.getId());
                                _log.info("congDan1: " + congDan1);
                                boolean result = false;
                                if (congDan1 == null) {
                                    _log.info("vao day : " + congDan1);
                                    result = taoCongDanBusiness.insertCongDan(userRequest,
                                            taiKhoanNguoiDung.getId(), tenDayDu, actionRequest);
                                } else {
                                    SessionMessages.add(actionRequest, "TaiKhoanDaTonTai");
                                }

                                if (result) {
                                    SessionMessages.add(actionRequest, "successAddTKCD");
                                } else {

                                    TaiKhoanNguoiDungLocalServiceUtil
                                            .deleteTaiKhoanNguoiDung(taiKhoanNguoiDung.getId());
                                    UserLocalServiceUtil.deleteUser(userLiferayId);
                                    SessionMessages.add(actionRequest, "successAddTKCD");
                                }

                            } else {
                                _log.info("update tai khoang trong csms_congdan" + taiKhoanNguoiDung.getId());
                                taoCongDanBusiness.editCongDan(userRequest, congDanId,
                                        String.valueOf(taiKhoanNguoiDung.getId()), tenDayDu, actionRequest);
                                SessionMessages.add(actionRequest, "successEditTKCD");

                            }

                            String uri = actionRequest.getScheme() + "://" + actionRequest.getServerName();
                            String urlTaiKhoanNguoiDung = ParamUtil.getString(actionRequest,
                                    "urlTaiKhoanNguoiDung");
                            urlTaiKhoanNguoiDung = urlTaiKhoanNguoiDung.replace("DUMMY_AUTH_CODE",
                                    taiKhoanCongDanId);
                            this.sendEmailToCongDan(ho, dem, ten, matKhau, urlTaiKhoanNguoiDung, email, uri);

                        } else {
                            UserLocalServiceUtil.deleteUser(userLiferayId);
                            SessionErrors.add(actionRequest,
                                    "org.oep.taocongdan.forms.err.isNotCreatedUserLiferay");

                        }

                    } else {
                        SessionErrors.add(actionRequest, "org.oep.taocongdan.forms.err.Error.TTKND");
                    }

                } else {
                    SessionErrors.add(actionRequest, "org.oep.taocongdan.forms.err.isNotCreatedUserLiferay");
                }

            } catch (Exception e) {

                e.printStackTrace();
                SessionErrors.add(actionRequest, "org.oep.taocongdan.forms.err.unKnown");

                actionResponse.setRenderParameter("jspPage", "/html/portlet/taocongdan/tao_cong_dan_form.jsp");

            }

        } else if (mode.equals(TaoCongDanBusiness.UPDATE_CONGDAN)) {

            CongDan congDan = CongDanLocalServiceUtil.fetchCongDan(FormatUtil.convertToLong(congDanId));

            try {

                User user = UserLocalServiceUtil.getUserByEmailAddress(PortalUtil.getCompanyId(actionRequest),
                        userRequest.get("email"));
                _log.info("email user " + user.getEmailAddress());

                if (user != null) {
                    user = updateUserLiferay(userRequest, actionRequest, actionResponse);
                }
                if (taiKhoanCongDanId != null) {
                    _log.info("idthong tin tai khoan nguoi dung " + taiKhoanCongDanId);
                    taoCongDanBusiness.editTaiKhoanNguoiDung(userRequest,
                            String.valueOf(congDan.getTaiKhoanNguoiDungId()), tenDayDu, actionRequest);
                    SessionMessages.add(actionRequest, "successEditTKND");

                }

                if (congDanId != null) {
                    _log.info("idthong tin cong dan " + congDanId);
                    taoCongDanBusiness.editCongDan(userRequest, congDanId, taiKhoanCongDanId, tenDayDu,
                            actionRequest);
                    SessionMessages.add(actionRequest, "successEditTKCD");

                }

            } catch (Exception e) {

                e.printStackTrace();
                _log.error("[addEditTaoCongDan] error: " + e.toString());
                SessionErrors.add(actionRequest, "org.oep.taocongdan.forms.err.unKnown");

                actionResponse.setRenderParameter("jspPage", "/html/portlet/taocongdan/tao_cong_dan_form.jsp");

            }
        }

        String redirectUrl = ParamUtil.getString(actionRequest, "redirectUrl");

        if (!SessionErrors.isEmpty(actionRequest)) {
            actionResponse.sendRedirect(redirectUrl);
            return;
        }

        actionRequest.getPortletSession().removeAttribute("USER_REQUEST_TK_CONG_DAN_OBJECT");

        if (userRequest.get("mode").equals(TaoCongDanBusiness.ADD_CONGDAN)) {

            SessionMessages.add(actionRequest, "success");

            actionResponse.sendRedirect(redirectUrl);
        } else if (userRequest.get("mode").equals(TaoCongDanBusiness.UPDATE_CONGDAN)) {

            SessionMessages.add(actionRequest, "success");

            actionResponse.sendRedirect(redirectUrl);
        }

    } else {

        if (userRequest.get("mode").equals(TaoCongDanBusiness.ADD_CONGDAN)) {

            actionResponse.setRenderParameter("mode", TaoCongDanBusiness.ADD_CONGDAN);
            actionResponse.setRenderParameter("jspPage", "/html/portlet/taocongdan/tao_cong_dan_form.jsp");
        } else {

            actionResponse.setRenderParameter("mode", TaoCongDanBusiness.UPDATE_CONGDAN);
            actionResponse.setRenderParameter("jspPage", "/html/portlet/taocongdan/tao_cong_dan_form.jsp");
        }
    }

}

From source file:org.oep.cmon.portlet.taocongdan.action.TaoCongDanAction.java

License:Apache License

/**
  * This is fucntion validate/* ww w.  j  a va  2s .  c om*/
  * Version: 1.0
  *  
  * History: 
  *   DATE        AUTHOR      DESCRIPTION 
  *  ------------------------------------------------- 
  *  3-March-2013  Nam Dinh    Create new
  * @param Map <String, String> userRequest,ActionRequest actionRequest, ActionResponse actionResponse
  * @return boolean
  */
private boolean validate(Map<String, String> userRequest, ActionRequest actionRequest,
        ActionResponse actionResponse) throws SystemException {

    TaoCongDanBusiness taoCongDanBusiness = new TaoCongDanBusiness();

    if (userRequest.get("mode").equals(TaoCongDanBusiness.ADD_CONGDAN)) {
        String maCongDan = null;
        try {

            try {
                User user = UserLocalServiceUtil.getUserByEmailAddress(PortalUtil.getCompanyId(actionRequest),
                        userRequest.get("email"));
                if (user.getEmailAddress().equals(userRequest.get("email"))) {
                    SessionErrors.add(actionRequest, "org.oep.taocongdan.form.err.emailTontai");
                }
            } catch (PortalException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

            if (userRequest.get("isLoaded").equals("load")) {
                if (this.emailExists(userRequest.get("email"))) {
                    SessionErrors.add(actionRequest, "org.oep.taocongdan.form.err.email.daCo");
                }

                if (FormatUtil.isEmpty(userRequest.get("email"))) {

                    SessionErrors.add(actionRequest, "org.oep.taocongdan.form.err.email");
                }

                if (FormatUtil.isEmpty(userRequest.get("matKhau"))) {
                    SessionErrors.add(actionRequest, "org.oep.taocongdan.form.err.matKhau");
                }

                if (!userRequest.get("matKhau").equals(userRequest.get("reMatKhau"))) {
                    SessionErrors.add(actionRequest, "org.oep.taocongdan.form.err.matKhau.KhongGiong");
                }

                if (Validator.isNull(userRequest.get("ho"))) {
                    SessionErrors.add(actionRequest, "org.oep.taocongdan.form.err.ho");
                }

                if (Validator.isNull(userRequest.get("ten"))) {
                    SessionErrors.add(actionRequest, "org.oep.taocongdan.form.err.ten");
                }

                if (Validator.isNull(userRequest.get("ngaySinh"))) {
                    SessionErrors.add(actionRequest, "org.oep.taocongdan.form.err.ngaySinh");
                }

                long quocTichId = ConvertUtil.convertToLong(userRequest.get("quocTichId"));
                if (quocTichId == 0) {
                    SessionErrors.add(actionRequest, "org.oep.taocongdan.form.err.quocTichId");
                }

                if (Validator.isNull(userRequest.get("noiCapCmndId"))) {
                    SessionErrors.add(actionRequest, "org.oep.taocongdan.form.err.noiCapCmndId");
                }

                if (Validator.isNull(userRequest.get("soCmnd"))) {
                    SessionErrors.add(actionRequest, "org.oep.taocongdan.form.err.soCmnd");
                }

                if (Validator.isNull(userRequest.get("ngayCapCmnd"))) {
                    SessionErrors.add(actionRequest, "org.oep.taocongdan.form.err.ngayCapCmnd");
                }

                long tinhid = ConvertUtil.convertToLong(userRequest.get("diaChiThuongTruTinhId"));

                if (tinhid == 0) {
                    SessionErrors.add(actionRequest, "org.oep.taocongdan.form.err.diaChiThuongTruTinhId");
                }

                long huyenid = ConvertUtil.convertToLong(userRequest.get("diaChiThuongTruHuyenId"));

                if (huyenid == 0) {
                    SessionErrors.add(actionRequest, "org.oep.taocongdan.form.err.diaChiThuongTruHuyenId");
                }

                long xaid = ConvertUtil.convertToLong(userRequest.get("diaChiThuongTruXaId"));
                if (xaid == 0) {
                    SessionErrors.add(actionRequest, "org.oep.taocongdan.form.err.diaChiThuongTruXaId");
                }

                if (userRequest.get("soCmnd").trim().length() > 0) {
                    if (ConvertUtil.convertToLong(userRequest.get("soCmnd")) <= 0) {
                        SessionErrors.add(actionRequest, "org.oep.taocongdan.form.err.soCmnd");
                    } else if (userRequest.get("soCmnd").length() != 9
                            && userRequest.get("soCmnd").length() != 12) {
                        SessionErrors.add(actionRequest, "org.oep.taocongdan.form.err.soCmnd.9or12");
                    }
                } else {
                    SessionErrors.add(actionRequest, "org.oep.taocongdan.form.err.soCmnd");
                }

                if (!Validator.isEmailAddress(userRequest.get("email"))) {

                    SessionErrors.add(actionRequest, "org.oep.taocongdan.form.err.email.khongDungDinhDang");
                }

                if (SessionErrors.isEmpty(actionRequest)) {
                    return true;
                }
                return false;
            }

            maCongDan = taoCongDanBusiness.congdanExists(userRequest.get("soCmnd"),
                    userRequest.get("ngaySinh"));
            _log.error("maCongDan: " + maCongDan);
            if (maCongDan.length() > 0) {

                SessionErrors.add(actionRequest, "org.oep.taocongdan.form.err.soCmnd.daCo");
            }

            if (this.emailExists(userRequest.get("email"))) {
                SessionErrors.add(actionRequest, "org.oep.taocongdan.form.err.email.daCo");
            }

            if (FormatUtil.isEmpty(userRequest.get("email"))) {

                SessionErrors.add(actionRequest, "org.oep.taocongdan.form.err.email");
            }

            if (FormatUtil.isEmpty(userRequest.get("matKhau"))) {
                SessionErrors.add(actionRequest, "org.oep.taocongdan.form.err.matKhau");
            }

            if (!userRequest.get("matKhau").equals(userRequest.get("reMatKhau"))) {
                SessionErrors.add(actionRequest, "org.oep.taocongdan.form.err.matKhau.KhongGiong");
            }

            if (Validator.isNull(userRequest.get("ho"))) {
                SessionErrors.add(actionRequest, "org.oep.taocongdan.form.err.ho");
            }

            if (Validator.isNull(userRequest.get("ten"))) {
                SessionErrors.add(actionRequest, "org.oep.taocongdan.form.err.ten");
            }

            if (Validator.isNull(userRequest.get("ngaySinh"))) {
                SessionErrors.add(actionRequest, "org.oep.taocongdan.form.err.ngaySinh");
            }

            long quocTichId = ConvertUtil.convertToLong(userRequest.get("quocTichId"));
            if (quocTichId == 0) {
                SessionErrors.add(actionRequest, "org.oep.taocongdan.form.err.quocTichId");
            }

            if (Validator.isNull(userRequest.get("noiCapCmndId"))) {
                SessionErrors.add(actionRequest, "org.oep.taocongdan.form.err.noiCapCmndId");
            }

            if (Validator.isNull(userRequest.get("soCmnd"))) {
                SessionErrors.add(actionRequest, "org.oep.taocongdan.form.err.soCmnd");
            }

            if (Validator.isNull(userRequest.get("ngayCapCmnd"))) {
                SessionErrors.add(actionRequest, "org.oep.taocongdan.form.err.ngayCapCmnd");
            }

            long tinhid = ConvertUtil.convertToLong(userRequest.get("diaChiThuongTruTinhId"));

            if (tinhid == 0) {
                SessionErrors.add(actionRequest, "org.oep.taocongdan.form.err.diaChiThuongTruTinhId");
            }

            long huyenid = ConvertUtil.convertToLong(userRequest.get("diaChiThuongTruHuyenId"));

            if (huyenid == 0) {
                SessionErrors.add(actionRequest, "org.oep.taocongdan.form.err.diaChiThuongTruHuyenId");
            }

            long xaid = ConvertUtil.convertToLong(userRequest.get("diaChiThuongTruXaId"));
            if (xaid == 0) {
                SessionErrors.add(actionRequest, "org.oep.taocongdan.form.err.diaChiThuongTruXaId");
            }

            if (userRequest.get("soCmnd").trim().length() > 0) {
                if (ConvertUtil.convertToLong(userRequest.get("soCmnd")) <= 0) {
                    SessionErrors.add(actionRequest, "org.oep.taocongdan.form.err.soCmnd");
                } else if (userRequest.get("soCmnd").length() != 9
                        && userRequest.get("soCmnd").length() != 12) {
                    SessionErrors.add(actionRequest, "org.oep.taocongdan.form.err.soCmnd.9or12");
                }
            } else {
                SessionErrors.add(actionRequest, "org.oep.taocongdan.form.err.soCmnd");
            }

            if (!Validator.isEmailAddress(userRequest.get("email"))) {

                SessionErrors.add(actionRequest, "org.oep.taocongdan.form.err.email.khongDungDinhDang");
            }

            if (SessionErrors.isEmpty(actionRequest)) {
                return true;
            }

        } catch (ParseException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

    } else if (userRequest.get("mode").equals(TaoCongDanBusiness.UPDATE_CONGDAN)) {

        String maCongDan = null;
        try {

            if (!userRequest.get("matKhau").equals(userRequest.get("reMatKhau"))) {
                SessionErrors.add(actionRequest, "org.oep.taocongdan.form.err.matKhau.KhongGiong");
            }

            if (Validator.isNull(userRequest.get("ho"))) {
                SessionErrors.add(actionRequest, "org.oep.taocongdan.form.err.ho");
            }

            if (Validator.isNull(userRequest.get("ten"))) {
                SessionErrors.add(actionRequest, "org.oep.taocongdan.form.err.ten");
            }

            if (Validator.isNull(userRequest.get("ngaySinh"))) {
                SessionErrors.add(actionRequest, "org.oep.taocongdan.form.err.ngaySinh");
            }

            if (Validator.isNull(userRequest.get("quocTichId"))) {
                SessionErrors.add(actionRequest, "org.oep.taocongdan.form.err.quocTichId");
            }

            if (Validator.isNull(userRequest.get("soCmnd"))) {
                SessionErrors.add(actionRequest, "org.oep.taocongdan.form.err.soCmnd");
            }

            if (Validator.isNull(userRequest.get("ngayCapCmnd"))) {
                SessionErrors.add(actionRequest, "org.oep.taocongdan.form.err.ngayCapCmnd");
            }

            maCongDan = taoCongDanBusiness.congdanExists(userRequest.get("soCmnd"),
                    userRequest.get("ngaySinh"));

            long tinhid = ConvertUtil.convertToLong(userRequest.get("diaChiThuongTruTinhId"));

            if (tinhid == 0) {
                SessionErrors.add(actionRequest, "org.oep.taocongdan.form.err.diaChiThuongTruTinhId");
            }

            long huyenid = ConvertUtil.convertToLong(userRequest.get("diaChiThuongTruHuyenId"));

            if (huyenid == 0) {
                SessionErrors.add(actionRequest, "org.oep.taocongdan.form.err.diaChiThuongTruHuyenId");
            }

            long xaid = ConvertUtil.convertToLong(userRequest.get("diaChiThuongTruXaId"));
            if (xaid == 0) {
                SessionErrors.add(actionRequest, "org.oep.taocongdan.form.err.diaChiThuongTruXaId");
            }

            if (userRequest.get("soCmnd").trim().length() > 0) {
                if (ConvertUtil.convertToLong(userRequest.get("soCmnd")) <= 0) {
                    SessionErrors.add(actionRequest, "org.oep.taocongdan.form.err.soCmnd");
                } else if (userRequest.get("soCmnd").length() != 9
                        && userRequest.get("soCmnd").length() != 12) {
                    SessionErrors.add(actionRequest, "org.oep.taocongdan.form.err.soCmnd.9or12");
                }
            } else {
                SessionErrors.add(actionRequest, "org.oep.taocongdan.form.err.soCmnd");
            }

            //            
            if (SessionErrors.isEmpty(actionRequest)) {
                return true;
            }

        } catch (ParseException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

    return false;
}

From source file:org.oep.cmon.portlet.thamso.action.ThamSoPortlet.java

License:Apache License

/**
* This is fucntion validationInput//w  w w . j  ava  2s.  c  om
* Version: 1.0
*  
* History: 
*   DATE        AUTHOR      DESCRIPTION 
*  ------------------------------------------------- 
*  3-March-2013  Nam Dinh    Create new
* @param String tenThamSo, long thamSoId, ActionRequest actionRequest
* @return boolean
*/
private boolean validationInput(String tenThamSo, long thamSoId, ActionRequest actionRequest) {

    if (tenThamSo.trim().length() == 0) {
        SessionErrors.add(actionRequest, "emptyTenThamSo");
    }
    if (SessionErrors.isEmpty(actionRequest)) {
        ThamSo thamSo = null;
        try {
            try {
                thamSo = null;
                thamSo = ThamSoLocalServiceUtil.findByTen(tenThamSo);
            } catch (Exception es) {
            }
            if (thamSo != null) {
                if (thamSo.getDaXoa() == FormatUtil.DA_XOA_DEACTIVATE) {
                    return true;
                }
                if (thamSoId > 0) {
                    if (thamSoId != thamSo.getId()) {
                        SessionErrors.add(actionRequest, "existTenThamSo");
                    }
                } else {
                    SessionErrors.add(actionRequest, "existTenThamSo");
                }
            }

        } catch (Exception es) {
        }
    }

    if (SessionErrors.isEmpty(actionRequest)) {
        return true;
    }

    return false;
}

From source file:org.oep.cmon.report.portlet.util.ReportValidate.java

License:Apache License

/**
 * This is function validation inputDMBaocao
 * Version: 1.0//from   w w w .j a  va2  s  .  co m
 *  
 * History: 
 *   DATE        AUTHOR      DESCRIPTION 
 *  ------------------------------------------------- 
 *  3-March-2013  Nam Dinh    Create new
 * @param reportname
 * @param url
 * @param actionRequest
 * @return boolean
 */
public static boolean validationInputDMBaocao(String reportname, String url, ActionRequest actionRequest) {
    if (reportname.trim().length() == 0) {
        SessionErrors.add(actionRequest, "emptyTenBaoCao");
    }
    if (url.trim().length() == 0) {
        SessionErrors.add(actionRequest, "emptyDuongDan");
    }
    if (SessionErrors.isEmpty(actionRequest)) {
        return true;
    }
    return false;
}

From source file:org.oep.cmon.report.portlet.util.ReportValidate.java

License:Apache License

/**
 * This is function validation inputDMRole
 * Version: 1.0//from ww w  .  ja v  a2 s .  c  o m
 *  
 * History: 
 *   DATE        AUTHOR      DESCRIPTION 
 *  ------------------------------------------------- 
 *  3-March-2013  Nam Dinh    Create new
 * @param name
 * @param actionRequest
 * @return boolean
 */
public static boolean validationInputDMRole(String name, ActionRequest actionRequest) {
    if (name.trim().length() == 0) {
        SessionErrors.add(actionRequest, "emptyTenRole");
    }
    if (SessionErrors.isEmpty(actionRequest)) {
        return true;
    }
    return false;
}

From source file:org.oep.cmon.user.portlet.action.UserEndorsePortlet.java

License:Apache License

/**
 * This is function Citizen endorsement/*ww  w. j  a v a  2 s.co m*/
 * Version: 1.0
 *  
 * History: 
 *   DATE        AUTHOR      DESCRIPTION 
 *  ------------------------------------------------- 
 *  3-March-2013  Nam Dinh    Create new
 * @param actionRequest
 * @param actionResponse
 * @throws Exception 
 */
public void endorse(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception {
    // Get the object from session
    Map<String, String> userRequest = (Map<String, String>) actionRequest.getPortletSession()
            .getAttribute("USER_REQUEST_OBJECT");

    // Get all parameters from request
    String hoCongDan = "";
    if (Validator.isNotNull(ParamUtil.getString(actionRequest, "ho"))) {
        hoCongDan = ParamUtil.getString(actionRequest, "ho").trim().toUpperCase();
        userRequest.put("HOCONGDAN", hoCongDan);
    }

    String tenDem = "";
    if (Validator.isNotNull(ParamUtil.getString(actionRequest, "dem"))) {
        tenDem = ParamUtil.getString(actionRequest, "dem").trim().toUpperCase();
        userRequest.put("TENDEM", tenDem);
    }

    String tenCongDan = "";
    if (Validator.isNotNull(ParamUtil.getString(actionRequest, "ten"))) {
        tenCongDan = ParamUtil.getString(actionRequest, "ten").trim().toUpperCase();
        userRequest.put("TENCONGDAN", tenCongDan);
    }

    String soCmnd = ParamUtil.getString(actionRequest, "soCmnd").trim();
    userRequest.put("SOCMND", soCmnd);

    String ngayCapCmnd = ParamUtil.getString(actionRequest, "ngayCapCmnd");
    userRequest.put("NGAYCAPCMND", ngayCapCmnd);

    String noiCapCmnd = ParamUtil.getString(actionRequest, "noiCapCmnd");
    if (Validator.isNotNull(noiCapCmnd)) {
        userRequest.put("IDNOICAPCMND", noiCapCmnd);
    }

    String ghiChuCmnd = ParamUtil.getString(actionRequest, "ghiChuCmnd").trim();
    userRequest.put("GHICHUCMND", ghiChuCmnd);

    String email = ParamUtil.getString(actionRequest, "email").trim();
    userRequest.put("EMAIL", email);

    String soHoChieu = ParamUtil.getString(actionRequest, "soHoChieu").trim();
    userRequest.put("SOHOCHIEU", soHoChieu);

    String ngayCapHoChieu = ParamUtil.getString(actionRequest, "ngayCapHoChieu");
    userRequest.put("NGAYCAPHOCHIEU", ngayCapHoChieu);

    String noiCapHoChieu = ParamUtil.getString(actionRequest, "noiCapHoChieu");
    // If the data is not submitted from client, keep the original value from the object in session
    if (Validator.isNotNull(noiCapHoChieu)) {
        userRequest.put("IDNOICAPHOCHIEU", noiCapHoChieu);
    }

    String ngayHetHanHoChieu = ParamUtil.getString(actionRequest, "ngayHetHanHoChieu");
    userRequest.put("NGAYHETHANHOCHIEU", ngayHetHanHoChieu);

    String ghiChuHoChieu = ParamUtil.getString(actionRequest, "ghiChuHoChieu").trim();
    userRequest.put("GHICHUHOCHIEU", ghiChuHoChieu);

    String gioiTinh = ParamUtil.getString(actionRequest, "gioiTinh");
    if (Validator.isNotNull(gioiTinh)) {
        userRequest.put("IDGIOITINH", gioiTinh);
    }

    String danToc = ParamUtil.getString(actionRequest, "danToc");
    if (Validator.isNotNull(danToc)) {
        userRequest.put("IDDANTOC", danToc);
    }

    String tonGiao = ParamUtil.getString(actionRequest, "tonGiao");
    if (Validator.isNotNull(tonGiao)) {
        userRequest.put("IDTONGIAO", tonGiao);
    }

    String quocTich = ParamUtil.getString(actionRequest, "quocTich");
    if (Validator.isNotNull(quocTich)) {
        userRequest.put("IDQUOCTICH", quocTich);
    }

    String ngaySinh = ParamUtil.getString(actionRequest, "ngaySinh");
    userRequest.put("NGAYSINH", ngaySinh);

    String dtCoDinh = ParamUtil.getString(actionRequest, "dtCoDinh").trim();
    userRequest.put("DIENTHOAICODINH", dtCoDinh);

    String dtDiDong = ParamUtil.getString(actionRequest, "dtDiDong").trim();
    userRequest.put("DIENTHOAIDIDONG", dtDiDong);

    String trinhDoHocVan = ParamUtil.getString(actionRequest, "trinhDoHocVan");
    if (Validator.isNotNull(trinhDoHocVan)) {
        userRequest.put("IDTRINHDOHOCVAN", trinhDoHocVan);
    }

    String soBhyt = ParamUtil.getString(actionRequest, "soBhyt").trim();
    userRequest.put("SOBAOHIEMYTE", soBhyt);

    String ngheNghiep = ParamUtil.getString(actionRequest, "ngheNghiep");
    if (Validator.isNotNull(ngheNghiep)) {
        userRequest.put("IDNGHENGHIEP", ngheNghiep);
    }

    String trinhDoChuyenMon = ParamUtil.getString(actionRequest, "trinhDoChuyenMon");
    if (Validator.isNotNull(trinhDoChuyenMon)) {
        userRequest.put("IDTRINHDOCHUYENMON", trinhDoChuyenMon);
    }

    String tinhTrangHonNhan = ParamUtil.getString(actionRequest, "tinhTrangHonNhan");
    if (Validator.isNotNull(tinhTrangHonNhan)) {
        userRequest.put("IDTINHTRANGHONNHAN", tinhTrangHonNhan);
    }

    String tinhNoiSinh = ParamUtil.getString(actionRequest, "tinhNoiSinh");
    if (Validator.isNotNull(tinhNoiSinh)) {
        userRequest.put("IDTINHTHANHNOISINH", tinhNoiSinh);
    }

    String huyenNoiSinh = ParamUtil.getString(actionRequest, "huyenNoiSinh");
    if (Validator.isNotNull(huyenNoiSinh)) {
        userRequest.put("IDQUANHUYENNOISINH", huyenNoiSinh);
    }

    String xaNoiSinh = ParamUtil.getString(actionRequest, "xaNoiSinh");
    if (Validator.isNotNull(xaNoiSinh)) {
        userRequest.put("IDPHUONGXANOISINH", xaNoiSinh);
    }

    String motaNoisinh = ParamUtil.getString(actionRequest, "motaNoisinh").trim();
    userRequest.put("MOTADIACHINOISINH", motaNoisinh);

    String tinhThuongTru = ParamUtil.getString(actionRequest, "tinhThuongTru");
    if (Validator.isNotNull(tinhThuongTru)) {
        userRequest.put("IDTINHTHANHTHUONGTRU", tinhThuongTru);
    }

    String huyenThuongTru = ParamUtil.getString(actionRequest, "huyenThuongTru");
    if (Validator.isNotNull(huyenThuongTru)) {
        userRequest.put("IDQUANHUYENTHUONGTRU", huyenThuongTru);
    }

    String xaThuongTru = ParamUtil.getString(actionRequest, "xaThuongTru");
    if (Validator.isNotNull(xaThuongTru)) {
        userRequest.put("IDPHUONGXATHUONGTRU", xaThuongTru);
    }

    String motaThuongTru = ParamUtil.getString(actionRequest, "motaThuongTru").trim();
    userRequest.put("MOTADIACHITHUONGTRU", motaThuongTru);

    String tinhHienTai = ParamUtil.getString(actionRequest, "tinhHienTai");
    if (Validator.isNotNull(tinhHienTai)) {
        userRequest.put("IDTINHTHANHHIENTAI", tinhHienTai);
    }

    String huyenHienTai = ParamUtil.getString(actionRequest, "huyenHienTai");
    if (Validator.isNotNull(huyenHienTai)) {
        userRequest.put("IDQUANHUYENHIENTAI", huyenHienTai);
    }

    String xaHienTai = ParamUtil.getString(actionRequest, "xaHienTai");
    if (Validator.isNotNull(xaHienTai)) {
        userRequest.put("IDPHUONGXAHIENTAI", xaHienTai);
    }

    String motaDiachiHienTai = ParamUtil.getString(actionRequest, "motaDiachiHienTai").trim();
    userRequest.put("MOTADIACHIHIENTAI", motaDiachiHienTai);

    String soHoKhau = ParamUtil.getString(actionRequest, "soHoKhau").trim();
    userRequest.put("SOHOKHAU", soHoKhau);

    String chuHo = ParamUtil.getString(actionRequest, "chuHo");
    userRequest.put("CHUHO", chuHo);

    String mstCaNhan = ParamUtil.getString(actionRequest, "mstCaNhan").trim();
    userRequest.put("MASOTHUECANHAN", mstCaNhan);

    String quanHeChuHo = ParamUtil.getString(actionRequest, "quanHeChuHo");
    if (Validator.isNotNull(quanHeChuHo)) {
        userRequest.put("IDQUANHE", quanHeChuHo);
    }

    PortletConfig portletConfig = (PortletConfig) actionRequest
            .getAttribute(JavaConstants.JAVAX_PORTLET_CONFIG);
    SessionMessages.add(actionRequest,
            portletConfig.getPortletName() + SessionMessages.KEY_SUFFIX_HIDE_DEFAULT_ERROR_MESSAGE);

    // Set the data back to session
    actionRequest.getPortletSession().setAttribute("USER_REQUEST_OBJECT", userRequest);

    // Check Ho cong dan
    if (Validator.isNull(hoCongDan)) {
        SessionErrors.add(actionRequest, "vn.dtt.cmon.user.form.endorse.err.hoCongDan");
    }

    // Check ten cong dan
    if (Validator.isNull(tenCongDan)) {
        SessionErrors.add(actionRequest, "vn.dtt.cmon.user.form.endorse.err.tenCongDan");
    }

    // Check so cmnd
    if (!Constaints.isValidCMND(soCmnd)) {
        SessionErrors.add(actionRequest, "vn.dtt.cmon.user.form.endorse.err.soCmnd");
    }

    // Check email
    if (Validator.isNull(email) || !email.contains("@")) {
        SessionErrors.add(actionRequest, "vn.dtt.cmon.user.form.endorse.err.email");
    } else {
        TaiKhoanNguoiDung taiKhoan = TaiKhoanNguoiDungLocalServiceUtil.findByTenDangNhap(email);
        if (taiKhoan != null) {
            SessionErrors.add(actionRequest, "vn.dtt.cmon.user.form.endorse.err.emailDuplicate");
        }
    }

    // Check gioi tinh
    if (Validator.isNull(gioiTinh)) {
        SessionErrors.add(actionRequest, "vn.dtt.cmon.user.form.endorse.err.gioiTinh");
    }

    // Check ngay sinh
    if (Validator.isNull(ngaySinh)) {
        SessionErrors.add(actionRequest, "vn.dtt.cmon.user.form.endorse.err.ngaySinh");
    } else {
        // Validate birth date
        DateFormat df = new SimpleDateFormat(DATE_FORMAT);
        Date birthDate = null;
        df.setLenient(false);
        try {
            birthDate = df.parse(ngaySinh);
        } catch (Exception e) {
            // Error never happen so this exception will be swallow
        }

        if (birthDate.compareTo(new Date()) > 0) {
            SessionErrors.add(actionRequest, "vn.dtt.cmon.user.form.endorse.err.ngaySinh.greaterThanCurrent");
        }
    }

    // ngay cap
    if (Validator.isNull(ngayCapCmnd)) {
        SessionErrors.add(actionRequest, "vn.dtt.cmon.user.form.endorse.err.ngayCapCmnd");
    } else {
        DateFormat df = new SimpleDateFormat(DATE_FORMAT);
        Date birthDate = null;
        df.setLenient(false);
        try {
            birthDate = df.parse(ngayCapCmnd);
        } catch (Exception e) {
            // Error never happen so this exception will be swallow
        }
        if (birthDate.compareTo(new Date()) > 0) {
            SessionErrors.add(actionRequest, "vn.dtt.cmon.user.form.endorse.err.ngayCap.greaterThanCurrent");
        }
    }

    // Check dan toc
    if (Validator.isNull(danToc)) {
        SessionErrors.add(actionRequest, "vn.dtt.cmon.user.form.endorse.err.danToc");
    }

    // Check ton giao
    if (Validator.isNull(tonGiao)) {
        SessionErrors.add(actionRequest, "vn.dtt.cmon.user.form.endorse.err.tonGiao");
    }

    // Check tinh thuong tru
    if (Validator.isNull(tinhThuongTru)) {
        SessionErrors.add(actionRequest, "vn.dtt.cmon.user.form.endorse.err.tinhThuongTru");
    }

    // Check huyen thuong tru
    if (Validator.isNull(huyenThuongTru)) {
        SessionErrors.add(actionRequest, "vn.dtt.cmon.user.form.endorse.err.huyenThuongTru");
    }

    // Check xa thuong tru
    if (Validator.isNull(xaThuongTru)) {
        SessionErrors.add(actionRequest, "vn.dtt.cmon.user.form.endorse.err.xaThuongTru");
    }

    // In case there's error      
    String redirectUrl = ParamUtil.getString(actionRequest, "redirectUrl");
    if (!SessionErrors.isEmpty(actionRequest)) {

        actionResponse.sendRedirect(redirectUrl);

        return;
    }

    // Generate random password for user
    String password = AuthenticateCodeUtil.generateAuthCode().toLowerCase().trim();

    EndorsementBs endorse = new EndorsementBs(actionRequest);

    String fullName = hoCongDan + StringPool.SPACE + tenDem + StringPool.SPACE + tenCongDan;

    try {
        // Update yeu cau dang ky to DB      
        YeuCauDangKyCongDan yeuCau = endorse.updateUserRequest(userRequest);

        // Create portal user
        long userId = endorse.createPortalCitizenUser(yeuCau, password);

        String maCongDan = endorse.citizenExists(hoCongDan, tenDem, tenCongDan, soCmnd, ngaySinh);

        // Create data on cmon_taikhoan nguoidung
        long taiKhoanNguoiDungId = endorse.createTaiKhoan(userId, fullName, email, password);

        // Create citizen
        endorse.createCitizen(yeuCau, taiKhoanNguoiDungId, maCongDan);

        String portalUrl = PortalUtil.getPortalURL(actionRequest);
        endorse.sendEmail(fullName, email, password, portalUrl, actionRequest);

        // Remove sessioj items
        actionRequest.getPortletSession().removeAttribute("PROFILE_PIC");

        actionRequest.getPortletSession().removeAttribute("USER_REQUEST_OBJECT");

        // Redirect to success URL
        //String successUrl = ParamUtil.getString(actionRequest, "successUrl");

        actionRequest.setAttribute("endorseSuccess", "endorseSuccess");
        SessionMessages.add(actionRequest, "endorseSuccess");

    } catch (Exception e) {
        actionRequest.setAttribute("endorseError", "endorseError");
        SessionMessages.add(actionRequest, "endorseError");

        e.printStackTrace();
    }
}

From source file:org.oep.cmon.userreg.portlet.action.UserRegActionPortlet.java

License:Apache License

/**
 * This is function input basic information
 * Version: 1.0//from w  w w  . j a v a  2s. co m
 *  
 * History: 
 *   DATE        AUTHOR      DESCRIPTION 
 *  ------------------------------------------------- 
 *  3-March-2013  Nam Dinh    Create new
 * @param actionRequest
 * @param actionResponse
 * @throws IOException
 * @throws PortletException
 * @throws PortalException
 * @throws SystemException
 * @throws ParseException
 */
public void inputBasic(ActionRequest actionRequest, ActionResponse actionResponse)
        throws IOException, PortletException, PortalException, SystemException, ParseException {
    // Get the object from session
    Map<String, String> userRequest = (Map<String, String>) actionRequest.getPortletSession()
            .getAttribute("USER_REQUEST_OBJECT");

    // Get all parameters from request
    String hoCongDan = ParamUtil.getString(actionRequest, "ho").trim().toUpperCase();
    userRequest.put("HOCONGDAN", hoCongDan);

    String tenDem = ParamUtil.getString(actionRequest, "dem").trim().toUpperCase();
    userRequest.put("TENDEM", tenDem);

    String tenCongDan = ParamUtil.getString(actionRequest, "ten").trim().toUpperCase();
    userRequest.put("TENCONGDAN", tenCongDan);

    String soCmnd = ParamUtil.getString(actionRequest, "soCmnd").trim();
    userRequest.put("SOCMND", soCmnd);

    String email = ParamUtil.getString(actionRequest, "email").trim();
    userRequest.put("EMAIL", email);

    String ngaySinh = ParamUtil.getString(actionRequest, "ngaySinh").trim();
    userRequest.put("NGAYSINH", ngaySinh);

    String ngayCapCmnd = ParamUtil.getString(actionRequest, "ngayCapCmnd").trim();
    userRequest.put("NGAYCAPCMND", ngayCapCmnd);

    String gioiTinh = ParamUtil.getString(actionRequest, "gioiTinh");
    if (Validator.isNotNull(gioiTinh)) {
        userRequest.put("IDGIOITINH", gioiTinh);
    }

    String danToc = ParamUtil.getString(actionRequest, "danToc");
    if (Validator.isNotNull(danToc)) {
        userRequest.put("IDDANTOC", danToc);
    }

    String tonGiao = ParamUtil.getString(actionRequest, "tonGiao");
    if (Validator.isNotNull(tonGiao)) {
        userRequest.put("IDTONGIAO", tonGiao);
    }

    String tinhThuongTru = ParamUtil.getString(actionRequest, "tinhThuongTru");
    if (Validator.isNotNull(tinhThuongTru)) {
        userRequest.put("IDTINHTHANHTHUONGTRU", tinhThuongTru);
    }

    String huyenThuongTru = ParamUtil.getString(actionRequest, "huyenThuongTru");
    if (Validator.isNotNull(huyenThuongTru)) {
        userRequest.put("IDQUANHUYENTHUONGTRU", huyenThuongTru);
    }

    String xaThuongTru = ParamUtil.getString(actionRequest, "xaThuongTru");
    if (Validator.isNotNull(xaThuongTru)) {
        userRequest.put("IDPHUONGXATHUONGTRU", xaThuongTru);
    }

    String motaThuongTru = ParamUtil.getString(actionRequest, "motaThuongTru").trim();
    userRequest.put("MOTADIACHITHUONGTRU", motaThuongTru);

    // Set the data back to session
    actionRequest.getPortletSession().setAttribute("USER_REQUEST_OBJECT", userRequest);

    // BinhNT add 2013-12-22 
    String reloadcapchar = ParamUtil.getString(actionRequest, "reloadcapchar").trim();
    if (reloadcapchar.trim().compareTo("reloadcapchar") == 0) {
        String redirectUrl = ParamUtil.getString(actionRequest, "redirectUrl");
        actionResponse.sendRedirect(redirectUrl);
        return;
    }
    // End BinhNT Add 2013-12-22
    // Validate captcha
    if (!CheckCaptchaUtil.isTrue(actionRequest, "captcha")) {
        SessionErrors.add(actionRequest, "vn.dtt.cmon.userreg.form.input.err.captcha");
    }

    // Check Ho cong dan
    if (Validator.isNull(hoCongDan)) {
        SessionErrors.add(actionRequest, "vn.dtt.cmon.userreg.form.input.err.hoCongDan");
    }

    // Check ten cong dan
    if (Validator.isNull(tenCongDan)) {
        SessionErrors.add(actionRequest, "vn.dtt.cmon.userreg.form.input.err.tenCongDan");
    }

    // Check so cmnd
    if (Validator.isNull(soCmnd) || !Validator.isNumber(soCmnd)) {
        SessionErrors.add(actionRequest, "vn.dtt.cmon.userreg.form.input.err.soCmnd");
    }

    if (soCmnd.trim().length() < 9 || soCmnd.trim().length() > 12) {
        SessionErrors.add(actionRequest, "err.soCmndVoPhaiNamTrongKhoangTuChinDenMuoiHaiChuSo");
    }

    // Check email
    if (!Validator.isEmailAddress(email)) {
        SessionErrors.add(actionRequest, "vn.dtt.cmon.userreg.form.input.err.email");
    }

    // Check ngay sinh
    if (Validator.isNull(ngaySinh)) {
        SessionErrors.add(actionRequest, "vn.dtt.cmon.userreg.form.input.err.ngaySinh");
    }

    // In case there's error      
    String redirectUrl = ParamUtil.getString(actionRequest, "redirectUrl");

    if (!SessionErrors.isEmpty(actionRequest)) {

        actionResponse.sendRedirect(redirectUrl);

        return;
    }

    // Validate data against DB

    // Validate birth date
    DateFormat df = new SimpleDateFormat(DATE_FORMAT);
    Date birthDate = null;
    df.setLenient(false);
    try {
        birthDate = df.parse(ngaySinh);
    } catch (Exception e) {
        // Error never happen so this exception will be swallow
    }

    if (birthDate.compareTo(new Date()) > 0) {
        SessionErrors.add(actionRequest, "vn.dtt.cmon.userreg.form.input.err.ngaySinh.greaterThanCurrent");
    }

    //      // Check if in DB, there's already user request that not processed yet   
    //      if (this.requestExists(soCmnd)) {
    //         SessionErrors.add(actionRequest, "vn.dtt.cmon.userreg.form.input.err.requestExists");
    //      }

    List<CongDan> congDan = CongDanLocalServiceUtil.findByEmail(email);
    if (congDan.size() > 0) {
        if (this.cmndExists(soCmnd)) {
            SessionErrors.add(actionRequest, "vn.dtt.cmon.userreg.form.input.err.requestExists");
        }
        // Check email if exists in CSMS cong dan
        if (this.emailExistsInCongDan(email)) {
            SessionErrors.add(actionRequest, "vn.dtt.cmon.userreg.form.input.err.email.alreadyOwned");
        }
    }

    if (!SessionErrors.isEmpty(actionRequest)) {
        actionResponse.sendRedirect(redirectUrl);
        return;
    }

    // Check if citizen exists or not
    //String maCongDan = this.citizenExists(hoCongDan, tenDem, tenCongDan, soCmnd, ngaySinh);
    String maCongDan = this.congdanExists(soCmnd, ngaySinh);
    _log.info("ma cong dan:" + maCongDan);
    if (Validator.isNull(maCongDan)) {
        _log.info("chua co thong tin trong csms_congdan");
        // Redirect to input detail confirm
        String inputDetailDialogUrl = ParamUtil.getString(actionRequest, "inputDetailDialogUrl");

        PortletConfig portletConfig = (PortletConfig) actionRequest
                .getAttribute(JavaConstants.JAVAX_PORTLET_CONFIG);
        SessionMessages.add(actionRequest,
                portletConfig.getPortletName() + SessionMessages.KEY_SUFFIX_HIDE_DEFAULT_ERROR_MESSAGE);

        actionResponse.sendRedirect(inputDetailDialogUrl);

        return;
    }

    else {
        CongDan congDan1 = CongDanLocalServiceUtil.findByMa(maCongDan);
        _log.info("congDan1: " + congDan1);

        // Check email if exists in CSMS cong dan
        if (congDan1.getEmail().length() > 0) {
            _log.info("da co tai khoan csms_congdan");
            String accountExistDialog = ParamUtil.getString(actionRequest, "accountExistDialog");

            PortletConfig portletConfig = (PortletConfig) actionRequest
                    .getAttribute(JavaConstants.JAVAX_PORTLET_CONFIG);
            SessionMessages.add(actionRequest,
                    portletConfig.getPortletName() + SessionMessages.KEY_SUFFIX_HIDE_DEFAULT_ERROR_MESSAGE);
            actionResponse.sendRedirect(accountExistDialog);
            return;
        } else {
            _log.info("chua co tai khoan trong csms_congdan");
            String inputDetailDialogUrlExistInCongDan = ParamUtil.getString(actionRequest,
                    "inputDetailDialogUrlExistInCongDan");

            PortletConfig portletConfig = (PortletConfig) actionRequest
                    .getAttribute(JavaConstants.JAVAX_PORTLET_CONFIG);
            SessionMessages.add(actionRequest,
                    portletConfig.getPortletName() + SessionMessages.KEY_SUFFIX_HIDE_DEFAULT_ERROR_MESSAGE);
            actionResponse.sendRedirect(inputDetailDialogUrlExistInCongDan);
            return;

        }

    }

    // Generate authentication code
    //      String authCode = AuthenticateCodeUtil.generateAuthCode();
    //      
    //      // Insert data to yeu cau dang ky cong dan   
    //      this.createAccountRequest(maCongDan, authCode, userRequest, actionRequest);
    //      
    //      String accountCreationUrl = ParamUtil.getString(actionRequest, "accountCreationUrl");
    //      
    //      accountCreationUrl = accountCreationUrl.replace("DUMMY_AUTH_CODE", authCode);
    //      
    //      // Send email here
    //      this.sendAccountConfirmationEmail(hoCongDan, tenDem, tenCongDan, accountCreationUrl, email);
    //      
    //      // Redirect to success page   
    //      String accountRegisterSuccessUrl = ParamUtil.getString(actionRequest, "accountRegisterSuccessUrl");
    //      
    //      // Remove object in session
    //      actionRequest.getPortletSession().removeAttribute("USER_REQUEST_OBJECT");
    //      
    //      PortletConfig portletConfig = (PortletConfig)actionRequest.getAttribute(JavaConstants.JAVAX_PORTLET_CONFIG);
    //      SessionMessages.add(actionRequest,  portletConfig.getPortletName() + SessionMessages.KEY_SUFFIX_HIDE_DEFAULT_ERROR_MESSAGE);
    //      
    //      // Redirect to account register success page
    //      actionResponse.sendRedirect(accountRegisterSuccessUrl);
}