Example usage for com.liferay.portal.kernel.servlet SessionMessages add

List of usage examples for com.liferay.portal.kernel.servlet SessionMessages add

Introduction

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

Prototype

public static void add(PortletRequest portletRequest, String key) 

Source Link

Usage

From source file:org.oep.cmon.admin.portlet.action.AdminActionPortlet.java

License:Apache License

/**
 * This is  function add public service//from  w ww  . jav a  2  s  .  c  om
 * Version: 1.0
 *  
 * History: 
 *   DATE        AUTHOR      DESCRIPTION 
 *  ------------------------------------------------- 
 *  3-March-2013  Nam Dinh    Create new
 * @param actionRequest
 * @param actionResponse
 * @throws Exception
 */
public void addDichVuCong(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception {
    new DichVuCongAction().addDichVuCong(actionRequest, actionResponse);
    PortletConfig portletConfig = (PortletConfig) actionRequest
            .getAttribute(JavaConstants.JAVAX_PORTLET_CONFIG);
    SessionMessages.add(actionRequest,
            portletConfig.getPortletName() + SessionMessages.KEY_SUFFIX_HIDE_DEFAULT_ERROR_MESSAGE);
}

From source file:org.oep.cmon.admin.portlet.action.AdminActionPortlet.java

License:Apache License

/**
 * This is  function add only public service
 * Version: 1.0/*from  w  ww  . ja v a2 s .c  o m*/
 *  
 * History: 
 *   DATE        AUTHOR      DESCRIPTION 
 *  ------------------------------------------------- 
 *  3-March-2013  Nam Dinh    Create new
 * @param actionRequest
 * @param actionResponse
 * @throws Exception
 */
public void addDichVuCongOnly(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception {
    new DichVuCongAction().addDichVuCongOnly(actionRequest, actionResponse);
    PortletConfig portletConfig = (PortletConfig) actionRequest
            .getAttribute(JavaConstants.JAVAX_PORTLET_CONFIG);
    SessionMessages.add(actionRequest,
            portletConfig.getPortletName() + SessionMessages.KEY_SUFFIX_HIDE_DEFAULT_ERROR_MESSAGE);
}

From source file:org.oep.cmon.admin.portlet.action.CongChucAction.java

License:Apache License

/**
 * This is function add or edit CongChuc
 * Version: 1.0/* w w w.  j av  a  2s . c om*/
 *  
 * History: 
 *   DATE        AUTHOR      DESCRIPTION 
 *  ------------------------------------------------- 
 *  3-March-2013  Nam Dinh    Create new
 * @param actionRequest
 * @param actionResponse
 * @throws Exception
 */
public void addEditCongChuc(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception {
    // Get the  required parameters
    // Action mode (0: Insert, 1: Edit);
    int mode = ParamUtil.getInteger(actionRequest, "mode");

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

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

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

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

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

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

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

    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").trim();
    userRequest.put("noiCapCmnd", noiCapCmnd);

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

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

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

    // Check login name
    if (Validator.isNull(ma)) {
        SessionErrors.add(actionRequest, "vn.dtt.cmon.admin.form.add_edit_congchuc.err.ma");
    }

    // Check full name
    if (Validator.isNull(hoVaTen)) {
        SessionErrors.add(actionRequest, "vn.dtt.cmon.admin.form.add_edit_congchuc.err.hoVaTen");
    }

    // Check password
    if (Validator.isNull(ngaySinh)) {
        SessionErrors.add(actionRequest, "vn.dtt.cmon.admin.form.add_edit_congchuc.err.ngaySinh");
    }

    // Check email
    if (Validator.isNull(chucVu)) {
        SessionErrors.add(actionRequest, "vn.dtt.cmon.admin.form.add_edit_congchuc.err.chucVu");
    }

    // Check co quan quan ly
    if (Validator.isNull(coQuanQuanLy)) {
        SessionErrors.add(actionRequest, "vn.dtt.cmon.admin.form.add_edit_congchuc.err.coQuanQuanLy");
    }

    // Check tai khoan nguoi dung
    if (Validator.isNull(taiKhoanNguoiDung.trim())) {
        SessionErrors.add(actionRequest, "vn.dtt.cmon.admin.form.add_edit_congchuc.err.taiKhoanNguoiDung");
    }

    // Check CMND
    if (soCmnd.trim().length() > 0) {
        if (ConvertUtil.convertToLong(soCmnd) <= 0) {
            SessionErrors.add(actionRequest, "vn.dtt.form.congchuc.error.number.cmnd");
        } else if (soCmnd.length() != 9 && soCmnd.length() != 12) {
            SessionErrors.add(actionRequest, "vn.dtt.form.congchuc.error.arrange.cmnd");
        }
    } else {
        SessionErrors.add(actionRequest, "vn.dtt.form.congchuc.error.number.cmnd");
    }

    // Validate ngay sinh vs current 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
    }

    Date currentDate = new Date();

    if (ngaySinh.trim().length() > 0 && birthDate.compareTo(currentDate) > 0) {
        SessionErrors.add(actionRequest,
                "vn.dtt.cmon.admin.form.add_edit_congchuc.err.ngaySinh.greaterThanCurrent");
    }

    // Validate ngayCapCmnd vs current date
    if (Validator.isNotNull(ngayCapCmnd)) {
        Date issueIdDate = null;
        try {
            issueIdDate = df.parse(ngayCapCmnd);
        } catch (Exception e) {
            // Error never happen so this exception will be swallow
        }

        if (issueIdDate.compareTo(currentDate) > 0) {
            SessionErrors.add(actionRequest,
                    "vn.dtt.cmon.admin.form.add_edit_congchuc.err.ngayCapCmnd.greaterThanCurrent");
        }
    }

    // Check duplicate information
    if (mode == INSERT_MODE) {

        if (Validator.isNotNull(ma)) {
            List<CongChuc> lst = CongChucLocalServiceUtil.findByMa(ma);

            if (lst.size() > 0) {
                SessionErrors.add(actionRequest, "vn.dtt.cmon.admin.form.add_edit_congchuc.err.duplicateMa");
            }
        }
    } else {

        // Get the id
        long id = Long.parseLong(userRequest.get("id"));

        if (Validator.isNotNull(ma)) {
            List<CongChuc> lst = CongChucLocalServiceUtil.findByMa(ma);

            if (lst.size() > 0) {
                // Get the first object in the list
                CongChuc obj = lst.get(0);

                // Check if the login name to be updated is already owned by another
                if (obj.getId() != id) {
                    SessionErrors.add(actionRequest,
                            "vn.dtt.cmon.admin.form.add_edit_congchuc.err.duplicateMa");
                }
            }
        }
    }

    // Redirect
    String redirectUrl = ParamUtil.getString(actionRequest, "redirectUrl");
    if (!SessionErrors.isEmpty(actionRequest)) {
        actionResponse.sendRedirect(redirectUrl);

        return;
    }

    // Insert/updatye record here
    if (mode == INSERT_MODE) {
        new CongChucBs().insert(userRequest, actionRequest);
    } else {
        new CongChucBs().edit(userRequest, actionRequest);
    }

    // Remove attribute
    actionRequest.getPortletSession().removeAttribute("USER_REQUEST_CC_OBJECT");

    // Redirect user
    if (mode == INSERT_MODE) {
        // Add success message
        SessionMessages.add(actionRequest, "success");

        actionResponse.sendRedirect(redirectUrl);
    } else {
        // Redirect to search screen
        Map<String, String> searchParam = (Map<String, String>) actionRequest.getPortletSession()
                .getAttribute("SEARCH_CONG_CHUC_PARAMS");

        String searchOption = searchParam.get("searchOption");

        String keyWord = searchParam.get("keyWord");

        // Do the search
        this.searchCongChuc(searchOption, keyWord, actionRequest, actionResponse);
    }
}

From source file:org.oep.cmon.admin.portlet.action.CoQuanQuanLyAction.java

License:Apache License

/**
 * This is function add or edit CoQuanQuanLy
 * Version: 1.0/*from   ww w  . j av  a  2s .  c  om*/
 *  
 * History: 
 *   DATE        AUTHOR      DESCRIPTION 
 *  ------------------------------------------------- 
 *  3-March-2013  Nam Dinh    Create new
 * @param actionRequest
 * @param actionResponse
 * @throws Exception
 */
public void addEditCoQuanQuanLy(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception {
    // Get the 2 required parameters
    long parentId = ParamUtil.getLong(actionRequest, "parentId");

    // Mode
    int mode = ParamUtil.getInteger(actionRequest, "mode");

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

    // Get ma co quan quan ly
    String ma = ParamUtil.getString(actionRequest, "ma");
    userRequest.put("ma", ma);

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    // Check ma co quan quan ly
    if (Validator.isNull(ma)) {
        SessionErrors.add(actionRequest, "vn.dtt.cmon.admin.form.add_edit_coquanquanly.err.ma");
    }

    // Check ten co quan quan ly
    if (Validator.isNull(ten)) {
        SessionErrors.add(actionRequest, "vn.dtt.cmon.admin.form.add_edit_coquanquanly.err.ten");
    }
    //boolean checkDonViHanhChi = true;
    if (tinh.isEmpty() && huyen.isEmpty() && xa.isEmpty()) {
        SessionErrors.add(actionRequest, "vn.dtt.cmon.admin.form.add_edit_coquanquanly.err.tinh");
    }
    /*
    // Check tinh co quan quan ly
    if (Validator.isNull(tinh)) {
       SessionErrors.add(actionRequest, "vn.dtt.cmon.admin.form.add_edit_coquanquanly.err.tinh");
    }
            
    // Check huyen co quan quan ly
    if (Validator.isNull(huyen)) {
       SessionErrors.add(actionRequest, "vn.dtt.cmon.admin.form.add_edit_coquanquanly.err.huyen");
    }
            
    // Check xa co quan quan ly
    if (Validator.isNull(xa)) {
       SessionErrors.add(actionRequest, "vn.dtt.cmon.admin.form.add_edit_coquanquanly.err.xa");
    }
    */

    // Check mo ta dia chi
    if (Validator.isNull(motaDiaChi)) {
        SessionErrors.add(actionRequest, "vn.dtt.cmon.admin.form.add_edit_coquanquanly.err.motaDiaChi");
    }

    // Check dien thoai
    if (Validator.isNull(dienThoai)) {
        SessionErrors.add(actionRequest, "vn.dtt.cmon.admin.form.add_edit_coquanquanly.err.dienThoai");
    }

    if (Validator.isNull(capCoQuanQuanLy)) {
        SessionErrors.add(actionRequest, "vn.dtt.cmon.admin.form.add_edit_coquanquanly.err.capCoQuanQuanLy");
    }

    if (Validator.isNotNull(merChant)) {
        if (Validator.isNull(accessCode) || Validator.isNull(secureSecret)) {
            SessionErrors.add(actionRequest, "vn.dtt.cmon.admin.form.add_edit_coquanquanly.err.merChant");
        }
    }

    if (Validator.isNotNull(accessCode)) {
        if (Validator.isNull(merChant) || Validator.isNull(secureSecret)) {
            SessionErrors.add(actionRequest, "vn.dtt.cmon.admin.form.add_edit_coquanquanly.err.accessCode");
        }
    }

    if (Validator.isNotNull(secureSecret)) {
        if (Validator.isNull(merChant) || Validator.isNull(accessCode)) {
            SessionErrors.add(actionRequest, "vn.dtt.cmon.admin.form.add_edit_coquanquanly.err.secureSecret");
        }
    }

    if (Validator.isNotNull(email) && !Validator.isEmailAddress(email)) {
        SessionErrors.add(actionRequest, "vn.dtt.cmon.admin.form.add_edit_coquanquanly.err.email");
    }

    // Check ma
    if (Validator.isNotNull(ma) && mode == INSERT_MODE) {
        List<CoQuanQuanLy> lst = CoQuanQuanLyLocalServiceUtil.findByMa(ma);

        if (lst.size() > 0) {
            CoQuanQuanLy coQuan = lst.get(0);
            if (coQuan.getDaXoa() != 1) {
                SessionErrors.add(actionRequest,
                        "vn.dtt.cmon.admin.form.add_edit_coquanquanly.err.dublicateMa");
            }
        }
    }

    // Redirect
    String redirectUrl = ParamUtil.getString(actionRequest, "redirectUrl");
    if (!SessionErrors.isEmpty(actionRequest)) {
        actionResponse.sendRedirect(redirectUrl);

        return;
    }

    // Insert/updatye record here
    if (mode == INSERT_MODE) {
        // Temporily remove cmon_cqql_cmon_cqql_fk
        try {
            new CoQuanQuanLyBusiness().insert(userRequest, parentId, actionRequest);
        } catch (Exception e) {
            e.printStackTrace();

            SessionErrors.add(actionRequest, "vn.dtt.cmon.admin.form.add_edit_coquanquanly.err.unKnown");

            // Redirect to error page
            actionResponse.setRenderParameter("jspPage", "/html/portlet/admin/err_page.jsp");

            return;
        }
    } else {
        try {
            new CoQuanQuanLyBusiness().edit(userRequest, actionRequest);
        } catch (Exception e) {
            e.printStackTrace();

            SessionErrors.add(actionRequest, "vn.dtt.cmon.admin.form.add_edit_coquanquanly.err.unKnown");

            // Redirect to error page
            actionResponse.setRenderParameter("jspPage", "/html/portlet/admin/err_page.jsp");

            return;
        }
    }

    // Remove attribute
    actionRequest.getPortletSession().removeAttribute("USER_REQUEST_CQQL_OBJECT");

    // Redirect user
    if (mode == INSERT_MODE) {
        // Add success message
        SessionMessages.add(actionRequest, "success");

        actionResponse.sendRedirect(redirectUrl);
    } else {
        // Redirect to search screen
        Map<String, String> searchParam = (Map<String, String>) actionRequest.getPortletSession()
                .getAttribute("SEARCH_CO_QUAN_QUAN_LY_PARAMS");

        String searchOption = searchParam.get("searchOption");

        String strParentId = searchParam.get("parentId");

        String keyWord = searchParam.get("keyWord");

        // Do the search
        this.searchCoQuanQuanLy(searchOption, Long.parseLong(strParentId), keyWord, actionRequest,
                actionResponse);
    }
}

From source file:org.oep.cmon.admin.portlet.action.DichVuCongAction.java

License:Apache License

/**
 * This is function add DichVuCong/* w ww. ja va  2 s .c  om*/
 * Version: 1.0
 *  
 * History: 
 *   DATE        AUTHOR      DESCRIPTION 
 *  ------------------------------------------------- 
 *  3-March-2013  Nam Dinh    Create new
 * @param actionRequest
 * @param actionResponse
 * @throws Exception
 */
public void addDichVuCong(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception {
    // Get the  required parameters

    @SuppressWarnings("unchecked")
    Map<String, String> userRequest = (Map<String, String>) actionRequest.getPortletSession()
            .getAttribute("USER_REQUEST_DVC_OBJECT");
    if (userRequest == null) {
        userRequest = new HashMap<String, String>();
    }

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

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

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

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

    // Check login name
    if (Validator.isNull(ma)) {
        SessionErrors.add(actionRequest, "err.ma");
    }

    // Check full name
    if (Validator.isNull(ten)) {
        SessionErrors.add(actionRequest, "err.ten");
    }

    // Check password
    if (Validator.isNull(groupId)) {
        SessionErrors.add(actionRequest, "err.groupId");
    }

    // Check email
    if (Validator.isNull(coQuanQuanLy)) {
        SessionErrors.add(actionRequest, "err.coQuanQuanLy");
    }

    // Redirect
    String redirectUrl = ParamUtil.getString(actionRequest, "redirectUrl");
    if (!SessionErrors.isEmpty(actionRequest)) {
        actionResponse.sendRedirect(redirectUrl);

        return;
    }

    // Process the data here
    String coQuanId = coQuanQuanLy.substring(0, coQuanQuanLy.indexOf("-"));

    // Insert thu tuc hanh chinh to DB
    ThuTucHanhChinh thuTuc = new ThuTucHanhChinhClp();

    thuTuc.setId(CounterLocalServiceUtil.increment("cmon_thutuchanhchinh"));

    thuTuc.setMa(ma);

    thuTuc.setTen(ten);

    thuTuc.setSoNgayXuLy(10);

    thuTuc.setTrangThai(1);

    thuTuc.setPhienBan(1);

    thuTuc.setNhomThuTucHanhChinhId(Long.parseLong(groupId));

    Date currentDate = new Date();

    thuTuc.setNgayTao(currentDate);

    thuTuc.setNgaySua(currentDate);

    User currentUser = PortalUtil.getUser(actionRequest);

    if (currentUser != null) {
        thuTuc.setNguoiTao(currentUser.getFullName());
        thuTuc.setNguoiSua(currentUser.getFullName());
    } else {
        // This is for test without logging in
        thuTuc.setNguoiTao("DUMMY");
        thuTuc.setNguoiSua("DUMMY");
    }

    thuTuc.setDaXoa(0);

    ThuTucHanhChinhLocalServiceUtil.addThuTucHanhChinh(thuTuc);

    // Assign dich vu to co quan quan ly
    this.assignDichVuToCoQuanQuanLy(thuTuc.getId(), Long.parseLong(coQuanId), actionRequest);

    //Redirect
    userRequest.put("ma", "");

    userRequest.put("ten", "");

    SessionMessages.add(actionRequest, "success");

    actionResponse.sendRedirect(redirectUrl);
}

From source file:org.oep.cmon.admin.portlet.action.DichVuCongAction.java

License:Apache License

/**
 * This is function add DichVuCong Only/*from  w w  w . jav a  2s.  co  m*/
 * Version: 1.0
 *  
 * History: 
 *   DATE        AUTHOR      DESCRIPTION 
 *  ------------------------------------------------- 
 *  3-March-2013  Nam Dinh    Create new
 * @param actionRequest
 * @param actionResponse
 * @throws Exception
 */
public void addDichVuCongOnly(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception {
    @SuppressWarnings("unchecked")
    Map<String, String> userRequest = (Map<String, String>) actionRequest.getPortletSession()
            .getAttribute("USER_REQUEST_DVC_ONLY_OBJECT");
    if (userRequest == null) {
        userRequest = new HashMap<String, String>();
    }

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

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

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

    // Check login name
    if (Validator.isNull(ma)) {
        SessionErrors.add(actionRequest, "err.ma");
    }

    // Check full name
    if (Validator.isNull(ten)) {
        SessionErrors.add(actionRequest, "err.ten");
    }

    // Check password
    if (Validator.isNull(groupId)) {
        SessionErrors.add(actionRequest, "err.groupId");
    }

    // Redirect
    String redirectUrl = ParamUtil.getString(actionRequest, "redirectUrl");
    if (!SessionErrors.isEmpty(actionRequest)) {
        actionResponse.sendRedirect(redirectUrl);

        return;
    }

    // Insert thu tuc hanh chinh to DB
    ThuTucHanhChinh thuTuc = new ThuTucHanhChinhClp();

    thuTuc.setId(CounterLocalServiceUtil.increment("cmon_thutuchanhchinh"));

    thuTuc.setMa(ma);

    thuTuc.setTen(ten);

    thuTuc.setSoNgayXuLy(10);

    thuTuc.setTrangThai(1);

    thuTuc.setPhienBan(1);

    thuTuc.setNhomThuTucHanhChinhId(Long.parseLong(groupId));

    Date currentDate = new Date();

    thuTuc.setNgayTao(currentDate);

    thuTuc.setNgaySua(currentDate);

    User currentUser = PortalUtil.getUser(actionRequest);

    if (currentUser != null) {
        thuTuc.setNguoiTao(currentUser.getFullName());
        thuTuc.setNguoiSua(currentUser.getFullName());
    } else {
        // This is for test without logging in
        thuTuc.setNguoiTao("DUMMY");
        thuTuc.setNguoiSua("DUMMY");
    }

    thuTuc.setDaXoa(0);

    ThuTucHanhChinhLocalServiceUtil.addThuTucHanhChinh(thuTuc);

    //Redirect
    userRequest.put("ma", "");

    userRequest.put("ten", "");

    SessionMessages.add(actionRequest, "success");

    actionResponse.sendRedirect(redirectUrl);
}

From source file:org.oep.cmon.admin.portlet.action.DichVuCongAction.java

License:Apache License

/**
 * This is function assign to DichVuCong 
 * Version: 1.0//from  w w  w  .  java  2  s.  c o  m
 *  
 * History: 
 *   DATE        AUTHOR      DESCRIPTION 
 *  ------------------------------------------------- 
 *  3-March-2013  Nam Dinh    Create new
 * @param actionRequest
 * @param actionResponse
 * @throws Exception
 */
public void assignDichVuCong(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception {
    @SuppressWarnings("unchecked")
    Map<String, String> userRequest = (Map<String, String>) actionRequest.getPortletSession()
            .getAttribute("USER_REQUEST_DVC_DONVI_OBJECT");
    if (userRequest == null) {
        userRequest = new HashMap<String, String>();
    }

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

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

    // Check login name
    if (Validator.isNull(ma)) {
        SessionErrors.add(actionRequest, "err.ma");
    }

    // Check co quan quan ly
    if (Validator.isNull(coQuanQuanLy)) {
        SessionErrors.add(actionRequest, "err.coQuanQuanLy");
    }

    // Redirect
    String redirectUrl = ParamUtil.getString(actionRequest, "redirectUrl");
    if (!SessionErrors.isEmpty(actionRequest)) {
        actionResponse.sendRedirect(redirectUrl);

        return;
    }

    // Extrach co quan quan ly id
    String coQuanId = coQuanQuanLy.substring(0, coQuanQuanLy.indexOf("-"));

    // Split array of dich vu cong
    String[] maDvcArray = ma.split(",");

    List<String> errList = new ArrayList<String>();

    // Check the existence of dich vu cong
    for (String maDichVu : maDvcArray) {
        // Delete the existence relation first
        ThuTucHanhChinh thuTuc = ThuTucHanhChinhLocalServiceUtil.getThuTucHanhChinhBoiMa(maDichVu);

        if (thuTuc == null) {
            errList.add(maDichVu);

            continue;
        }

        // Insert to DB
        this.assignDichVuToCoQuanQuanLy(thuTuc.getId(), Long.parseLong(coQuanId), actionRequest);
    }

    if (errList.size() > 0) {

        actionRequest.getPortletSession().setAttribute("MA_DICH_VU_ERR", errList);
    } else {
        actionRequest.getPortletSession().removeAttribute("MA_DICH_VU_ERR");
    }

    // Redirect
    SessionMessages.add(actionRequest, "success");

    actionResponse.sendRedirect(redirectUrl);
}

From source file:org.oep.cmon.admin.portlet.action.TaiKhoanNguoiDungAction.java

License:Apache License

/**
 * This is function add or edit TaiKhoanNguoiDung
 * Version: 1.0//w ww. ja v a  2 s . c o m
 *  
 * History: 
 *   DATE        AUTHOR      DESCRIPTION 
 *  ------------------------------------------------- 
 *  3-March-2013  Nam Dinh    Create new
 * @param actionRequest
 * @param actionResponse
 * @throws Exception
 */
public void addEditTaiKhoanNguoiDung(ActionRequest actionRequest, ActionResponse actionResponse)
        throws Exception {
    // Get the  required parameters
    // Action mode (0: Insert, 1: Edit);
    int mode = ParamUtil.getInteger(actionRequest, "mode");

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

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

    // We use email as login name as well
    String loginName = email;// ParamUtil.getString(actionRequest, "loginName").trim();
    userRequest.put("loginName", loginName);

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

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

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

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

    String liferayID = ParamUtil.getString(actionRequest, "liferayID").trim();
    userRequest.put("TaiKhoanLiferayID", liferayID);

    //      String coQuanQuanLy = ParamUtil.getString(actionRequest, "coQuanQuanLy").trim();
    //      userRequest.put("coQuanQuanLy", coQuanQuanLy);

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

    // Check login name
    if (Validator.isNull(loginName)) {
        SessionErrors.add(actionRequest, "vn.dtt.cmon.admin.form.add_edit_taikhoannguoidung.err.loginName");
    }

    // Check full name
    if (Validator.isNull(fullName)) {
        SessionErrors.add(actionRequest, "vn.dtt.cmon.admin.form.add_edit_taikhoannguoidung.err.fullName");
    }

    // Check password
    if (mode == INSERT_MODE && Validator.isNull(password)) {
        SessionErrors.add(actionRequest, "vn.dtt.cmon.admin.form.add_edit_taikhoannguoidung.err.password");
    }

    // Check email
    if (Validator.isNull(email)) {
        SessionErrors.add(actionRequest, "vn.dtt.cmon.admin.form.add_edit_taikhoannguoidung.err.email");
    }

    if (Validator.isNotNull(email) && !Validator.isEmailAddress(email)) {
        SessionErrors.add(actionRequest, "vn.dtt.cmon.admin.form.add_edit_taikhoannguoidung.err.emailNotValid");
    }

    // Check co quan quan ly
    //      if (Validator.isNull(coQuanQuanLy)) {
    //         SessionErrors.add(actionRequest, "vn.dtt.cmon.admin.form.add_edit_taikhoannguoidung.err.coQuanQuanLy");
    //      }   

    // Check duplicate information
    if (mode == INSERT_MODE) {

        if (Validator.isNotNull(loginName)) {
            TaiKhoanNguoiDung taiKhoan = TaiKhoanNguoiDungLocalServiceUtil.findByTenDangNhap(loginName);

            if (taiKhoan != null) {
                SessionErrors.add(actionRequest,
                        "vn.dtt.cmon.admin.form.add_edit_taikhoannguoidung.err.duplicateLoginName");
            }
        }

        // Check duplicate email
        List<TaiKhoanNguoiDung> lst = TaiKhoanNguoiDungLocalServiceUtil.findByEmail(email);
        if (lst.size() > 0) {
            SessionErrors.add(actionRequest,
                    "vn.dtt.cmon.admin.form.add_edit_taikhoannguoidung.err.duplicateEmail");

        }
    } else {

        // Get the id
        long id = Long.parseLong(userRequest.get("id"));

        if (Validator.isNotNull(loginName)) {
            TaiKhoanNguoiDung taiKhoan = TaiKhoanNguoiDungLocalServiceUtil.findByTenDangNhap(loginName);

            if (taiKhoan != null) {
                // Check if the login name to be updated is already owned by another
                if (taiKhoan.getId() != id) {
                    SessionErrors.add(actionRequest,
                            "vn.dtt.cmon.admin.form.add_edit_taikhoannguoidung.err.duplicateLoginName");
                }
            }
        }

        // Check duplicate email
        List<TaiKhoanNguoiDung> lst = TaiKhoanNguoiDungLocalServiceUtil.findByEmail(email);
        if (lst.size() > 0) {
            // Get the first object in the list
            TaiKhoanNguoiDung obj = lst.get(0);

            // Check if the email to be updated is already owned by another
            if (obj.getId() != id) {
                SessionErrors.add(actionRequest,
                        "vn.dtt.cmon.admin.form.add_edit_taikhoannguoidung.err.duplicateEmail");
            }
        }
    }

    // Redirect
    String redirectUrl = ParamUtil.getString(actionRequest, "redirectUrl");
    if (!SessionErrors.isEmpty(actionRequest)) {
        actionResponse.sendRedirect(redirectUrl);

        return;
    }

    TaiKhoanNguoiDungBusiness taiKhoanNguoiDungBs = new TaiKhoanNguoiDungBusiness();

    TaiKhoanNguoiDung nguoiDung = taiKhoanNguoiDungBs.toEntity(mode, userRequest, actionRequest);

    long userId = 0;

    if (nguoiDung.getTrangThai() != 0) {
        // Create user on LDAP server
        //remove add user to ldap by liemnn
        /*boolean status = taiKhoanNguoiDungBs.createUserOnLDAP(nguoiDung.getEmail(), EncryptionUtil.decrypt(nguoiDung.getMatKhau()), nguoiDung.getTenNguoiDung());
        if (!status) {
           SessionErrors.add(actionRequest, "vn.dtt.cmon.admin.form.add_edit_taikhoannguoidung.err.ldap");
           actionResponse.sendRedirect(redirectUrl);
                   
           return;      
        }   */

        // Create portal user
        try {
            userId = taiKhoanNguoiDungBs.createPortalUser(nguoiDung, actionRequest);
        } catch (Exception es) {
            es.printStackTrace();
        }
    }
    // Insert/updatye record here
    if (mode == INSERT_MODE) {
        try {
            new TaiKhoanNguoiDungBusiness().insert(nguoiDung, userId, actionRequest);
        } catch (Exception e) {
            e.printStackTrace();

            SessionErrors.add(actionRequest, "vn.dtt.cmon.admin.form.add_edit_coquanquanly.err.unKnown");

            // Redirect to error page
            actionResponse.setRenderParameter("jspPage", "/html/portlet/admin/err_page.jsp");

            return;
        }
    } else {
        try {
            if (ConvertUtil.convertToLong(liferayID) > 0) {
                nguoiDung.setTaiKhoanNguoiDungId(ConvertUtil.convertToLong(liferayID));
            }
            new TaiKhoanNguoiDungBusiness().edit(nguoiDung, EncryptionUtil.encrypt(password), actionRequest);
        } catch (Exception e) {
            e.printStackTrace();

            SessionErrors.add(actionRequest, "vn.dtt.cmon.admin.form.add_edit_coquanquanly.err.unKnown");

            // Redirect to error page
            actionResponse.setRenderParameter("jspPage", "/html/portlet/admin/err_page.jsp");

            return;
        }
    }

    // Remove attribute
    actionRequest.getPortletSession().removeAttribute("USER_REQUEST_TKND_OBJECT");

    // Redirect user
    if (mode == INSERT_MODE) {
        // Add success message
        SessionMessages.add(actionRequest, "success");

        actionResponse.sendRedirect(redirectUrl);
    } else {
        // Redirect to search screen
        Map<String, String> searchParam = (Map<String, String>) actionRequest.getPortletSession()
                .getAttribute("SEARCH_TAI_KHOAN_NGUOI_DUNG_PARAMS");

        String searchOption = searchParam.get("searchOption");

        String keyWord = searchParam.get("keyWord");

        // Do the search
        this.searchTaiKhoanNguoiDung(searchOption, keyWord, actionRequest, actionResponse);
    }
}

From source file:org.oep.cmon.admin.portlet.util.SetParamUtil.java

License:Apache License

/**
 * This is function setParameter/*from w  w w.  j a  v a  2  s  . c  o  m*/
 * Version: 1.0
 *  
 * History: 
 *   DATE        AUTHOR      DESCRIPTION 
 *  ------------------------------------------------- 
 *  3-March-2013  Nam Dinh    Create new
 * @param actionRequest
 * @param actionResponse
 * @param value
 */
public static void setParameter(ActionRequest actionRequest, ActionResponse actionResponse, String value) {
    if (value != null) {
        actionResponse.setRenderParameter("searchKeyWord", value);
    }

    // Hidden default error message
    PortletConfig portletConfig = (PortletConfig) actionRequest
            .getAttribute(JavaConstants.JAVAX_PORTLET_CONFIG);
    SessionMessages.add(actionRequest,
            portletConfig.getPortletName() + SessionMessages.KEY_SUFFIX_HIDE_DEFAULT_ERROR_MESSAGE);
}

From source file:org.oep.cmon.czprofile.portlet.action.CitizenProfileActionPortlet.java

License:Apache License

/**
 * This is  function change password/*from  w w w.  j  a  v a 2s.c  o m*/
 * Version: 1.0
 *  
 * History: 
 *   DATE        AUTHOR      DESCRIPTION 
 *  ------------------------------------------------- 
 *  3-March-2013  Nam Dinh    Create new
 * @param actionRequest
 * @param actionResponse
 * @throws Exception
 */
public void changePassword(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception {
    Map<String, String> userRequest = (Map<String, String>) actionRequest.getPortletSession()
            .getAttribute("USER_REQUEST_OBJECT");

    actionRequest.getPortletSession().setAttribute("change_pass", "tab.czprofile.changepass");

    //      String oldPassword = ParamUtil.getString(actionRequest, "oldPassword").trim();
    //      userRequest.put("oldPassword", oldPassword);
    //      
    String newPassword = ParamUtil.getString(actionRequest, "newPassword").trim();
    userRequest.put("newPassword", newPassword);

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

    User currentUser = PortalUtil.getUser(actionRequest);

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

    if (currentUser == null) {
        SessionErrors.add(actionRequest, "vn.dtt.cmon.czprofile.form.input.err.notLogin");
        actionResponse.sendRedirect(redirectUrl);

        return;
    }

    // Validate params

    // Old password
    //      if (Validator.isNull(oldPassword)) {
    //         SessionErrors.add(actionRequest, "vn.dtt.cmon.czprofile.form.input.err.oldPassword");
    //      }

    // New password
    if (Validator.isNull(newPassword)) {
        SessionErrors.add(actionRequest, "vn.dtt.cmon.czprofile.form.input.err.newPassword");
    }

    // Confirm password
    if (Validator.isNull(confirmPassword)) {
        SessionErrors.add(actionRequest, "vn.dtt.cmon.czprofile.form.input.err.confirmPassword");
    }

    // New pass and confirm pass
    if (!newPassword.equals(confirmPassword)) {
        SessionErrors.add(actionRequest, "vn.dtt.cmon.czprofile.form.input.err.oldPassAndNewPass");
    }

    // Check new password and old password
    long userId = currentUser.getUserId();

    // Get tai khoan nguoi dung from liferay
    TaiKhoanNguoiDung taiKhoan = TaiKhoanNguoiDungLocalServiceUtil.findByTaiKhoanNguoiDungId(userId);

    // Get the old password
    String oldDbPassword = taiKhoan.getMatKhau();
    //      
    String newEncryptPassword = EncryptionUtil.encrypt(newPassword);
    //      
    if (oldDbPassword.equals(newEncryptPassword)) {
        SessionErrors.add(actionRequest, "vn.dtt.cmon.czprofile.form.input.err.newPassSameOldPass");
    }

    // Check old password correct or not

    if (!SessionErrors.isEmpty(actionRequest)) {

        actionResponse.sendRedirect(redirectUrl);

        return;
    }

    //      TaiKhoanNguoiDungBusiness taiKhoanNguoiDungBs = new TaiKhoanNguoiDungBusiness();

    // Create user on LDAP server
    //      if ( ! taiKhoanNguoiDungBs.createUserOnLDAP(taiKhoan.getEmail(), newPassword, taiKhoan.getTenNguoiDung())) {
    //         SessionErrors.add(actionRequest, "vn.dtt.cmon.czprofile.form.input.err.ldap");
    //
    //         actionResponse.sendRedirect(redirectUrl);      
    //         
    //         return;      
    //      }      

    // Update portal user password
    UserLocalServiceUtil.updatePassword(userId, newPassword, newPassword, false);

    // Update tai khoan nguoi dung
    taiKhoan.setMatKhau(newEncryptPassword);

    TaiKhoanNguoiDungLocalServiceUtil.updateTaiKhoanNguoiDung(taiKhoan);

    // Remove attribute
    actionRequest.getPortletSession().removeAttribute("USER_REQUEST_OBJECT");

    // Redirect
    SessionMessages.add(actionRequest, "success");

    actionResponse.sendRedirect(redirectUrl);
}