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.czprofile.portlet.action.CitizenProfileActionPortlet.java

License:Apache License

/**
 * This is  function update detail/*from w ww.j ava2  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 updateDetail(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception {
    Map<String, String> userRequest = (Map<String, String>) actionRequest.getPortletSession()
            .getAttribute("USER_REQUEST_OBJECT");

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

    /*String ngayCapCmnd = ParamUtil.getString(actionRequest, "ngayCapCmnd").trim();
    userRequest.put("NGAYCAPCMND", ngayCapCmnd);*/
    String noiCapCmnd = ParamUtil.getString(actionRequest, "noiCapCmnd").trim();
    if (Validator.isNotNull(noiCapCmnd)) {
        userRequest.put("IDNOICAPCMND", noiCapCmnd);
    }
    /*String ghiChuCmnd = ParamUtil.getString(actionRequest, "ghiChuCmnd").trim();
    userRequest.put("GHICHUCMND", ghiChuCmnd);*/

    String ngayHetHanHoChieuStr = ParamUtil.getString(actionRequest, "ngayHetHanHoChieu");

    userRequest.put("NGAYHETHANHOCHIEU", ngayHetHanHoChieuStr);
    /*
    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 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 tinhTrangHonNhan = ParamUtil.getString(actionRequest, "tinhTrangHonNhan");
    if (Validator.isNotNull(tinhTrangHonNhan)) {
        userRequest.put("IDTINHTRANGHONNHAN", tinhTrangHonNhan);
    }

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

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

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

    // validate data
    // Check noi cap cmnd
    if (Validator.isNull(noiCapCmnd)) {
        SessionErrors.add(actionRequest, "vn.dtt.cmon.userreg.form.input.err.noiCapCmnd");
    }

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

    // Check tinh trang hon nhan
    if (Validator.isNull(tinhTrangHonNhan)) {
        SessionErrors.add(actionRequest, "vn.dtt.cmon.userreg.form.input.err.tinhTrangHonNhan");
    }

    // Check mo ta dia chi hien tai
    //      if (Validator.isNull(motaDiachiHienTai)) {
    //         SessionErrors.add(actionRequest, "vn.dtt.cmon.userreg.form.input.err.motaDiachiHienTai");
    //      }      

    // Validate ngayHetHanHoChieu
    Date ngayHetHanHoChieu = null;
    if (ngayHetHanHoChieuStr != null && !"".equals(ngayHetHanHoChieuStr)) {
        DateFormat df = new SimpleDateFormat(DATE_FORMAT);

        df.setLenient(false);
        try {
            ngayHetHanHoChieu = df.parse(ngayHetHanHoChieuStr);
        } catch (Exception e) {
            SessionErrors.add(actionRequest, "vn.dtt.cmon.userreg.form.input.err.ngayHetHanHoChieu.notValid");
        }
    }

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

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

    CongDan citizen = CongDanLocalServiceUtil.fetchCongDan(Long.parseLong(id));
    if (citizen == null) {
        SessionErrors.add(actionRequest, "vn.dtt.cmon.czprofile.form.input.err.notExist");
        actionResponse.sendRedirect(redirectUrl);
        return;
    }

    // Update citizen
    citizen.setTrinhDoHocVanId(Long.parseLong(trinhDoHocVan));
    citizen.setTinhTrangHonNhanId(Long.parseLong(tinhTrangHonNhan));
    citizen.setNoiCapCmndId(Long.parseLong(noiCapCmnd));
    citizen.setGioiTinh(Integer.parseInt(gioiTinh));
    citizen.setDiaChiHienNay(motaDiachiHienTai);
    citizen.setNgayHetHanHoChieu(ngayHetHanHoChieu);
    citizen.setSoBaoHiemYTe(soBhyt);

    CongDanLocalServiceUtil.updateCongDan(citizen);

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

    // Redirect
    SessionMessages.add(actionRequest, "success");
    actionResponse.sendRedirect(redirectUrl);
}

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

License:Apache License

/**
 * This is  function update CongChuc detail
 * Version: 1.0//w ww  .  j  a  v  a2 s  .  co  m
 *  
 * History: 
 *   DATE        AUTHOR      DESCRIPTION 
 *  ------------------------------------------------- 
 *  3-March-2013  Nam Dinh    Create new
 * @param actionRequest
 * @param actionResponse
 * @throws Exception
 */
public void updateCongChucDetail(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception {
    Map<String, String> userRequest = (Map<String, String>) actionRequest.getPortletSession()
            .getAttribute("USER_REQUEST_OBJECT");

    // Get all parameters from request
    String id = ParamUtil.getString(actionRequest, "id").trim();
    _log.info("======= cong dan Id = " + String.valueOf(id));
    if (Validator.isNotNull(id)) {
        userRequest.put("id", id);
    }

    String tenDaydu = ParamUtil.getString(actionRequest, "tenDaydu").trim();
    _log.info("======= tenDaydu = " + tenDaydu);
    if (Validator.isNotNull(tenDaydu)) {
        userRequest.put("tenDaydu", tenDaydu);
    }

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

    String gioiTinh = ParamUtil.getString(actionRequest, "gioiTinh");
    _log.info("======= gioiTinh = " + String.valueOf(gioiTinh));
    if (Validator.isNotNull(gioiTinh)) {
        userRequest.put("gioiTinh", gioiTinh);
    }

    String soCmnd = ParamUtil.getString(actionRequest, "soCmnd").trim();
    _log.info("======= soCmnd = " + soCmnd);
    if (Validator.isNotNull(tenDaydu)) {
        userRequest.put("soCmnd", soCmnd);
    }

    String ngayCapCmnd = ParamUtil.getString(actionRequest, "ngayCapCmnd");
    _log.info("======= ngayCapCmnd = " + String.valueOf(ngayCapCmnd));
    userRequest.put("ngayCapCmnd", ngayCapCmnd);

    String noiCapCmnd = ParamUtil.getString(actionRequest, "noiCapCmnd").trim();
    _log.info("======= noiCapCmnd = " + String.valueOf(noiCapCmnd));
    if (Validator.isNotNull(noiCapCmnd)) {
        userRequest.put("noiCapCmnd", noiCapCmnd);
    }

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

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

    boolean isValid = validationInput(tenDaydu, ngaySinh, soCmnd, ngayCapCmnd, noiCapCmnd, actionRequest);

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

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

    CongChuc congChuc = CongChucLocalServiceUtil.getCongChuc(Long.parseLong(id));
    _log.info("======= congChuc info = " + congChuc);
    if (congChuc == null) {
        SessionErrors.add(actionRequest, "vn.dtt.cmon.czprofile.form.input.err.notExist");
        actionResponse.sendRedirect(redirectUrl);
        return;
    }

    // Update cong chuc;
    congChuc.setHoVaTen(tenDaydu);
    //congChuc.setNoiCapCmndId(Long.parseLong(noiCapCmnd));
    congChuc.setNgaySinh(ConvertUtil.parseStringToDate(ngaySinh));
    congChuc.setGioiTinhId(Integer.parseInt(gioiTinh));
    congChuc.setSoCmnd(soCmnd);
    congChuc.setNgayCapCmnd(ConvertUtil.parseStringToDate(ngayCapCmnd));
    congChuc.setNoiCapCmnd(noiCapCmnd);

    _log.info("======= congChuc info update: = " + congChuc);

    CongChucLocalServiceUtil.updateCongChuc(congChuc);

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

    // Redirect
    SessionMessages.add(actionRequest, "success");
    actionResponse.sendRedirect(redirectUrl);
}

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

License:Apache License

/**
 * This is  function search CoQuanQuanLy popup
 * 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 request
 * @param response
 * @throws Exception
 */
public void searchCoQuanQuanLyPopup(ActionRequest request, ActionResponse response) throws Exception {
    String chucVuId = ParamUtil.getString(request, "chucVuId", "");
    String coQuanQuanLyId = ParamUtil.getString(request, "coQuanQuanLyId", "");
    String searchInputText = ParamUtil.getString(request, "searchInputText", "");
    String[] strcqqlids = request.getParameterValues("strcqqlids[]");
    if (strcqqlids != null) {
        boolean insertOk = true;
        ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);
        User user = themeDisplay.getUser();
        ChucVu chucVu = ChucVuLocalServiceUtil.fetchChucVu(Long.valueOf(chucVuId));
        List<ChucVu2VaiTro> listChucVu2VaiTro = ChucVu2VaiTroLocalServiceUtil
                .findByIdChucVuAndIdCoQuanQuanLy(Long.valueOf(chucVuId), Long.valueOf(coQuanQuanLyId), 0);
        long[] vaitroids = new long[listChucVu2VaiTro.size()];
        for (int i = 0; i < listChucVu2VaiTro.size(); i++) {
            vaitroids[i] = listChucVu2VaiTro.get(i).getVaiTroId();
        }
        for (int i = 0; i < strcqqlids.length; i++) {
            CoQuanQuanLy coQuanQuanLy = CoQuanQuanLyLocalServiceUtil
                    .fetchCoQuanQuanLy(Long.valueOf(strcqqlids[i]));
            if (chucVu != null && coQuanQuanLy != null && user != null) {
                boolean subInsert = CongChucUtils.ganChucVuToCoQuanQuanLy(chucVu, vaitroids, coQuanQuanLy,
                        user);
                if (!subInsert) {
                    insertOk = false;
                }
            }
        }
        if (insertOk) {
            SessionMessages.add(request, "createChucVuSuccess");
        } else {
            SessionErrors.add(request, "addChucVuError");
        }

    }
    List<CoQuanQuanLy> listCoQuanQuanLy = new ArrayList<CoQuanQuanLy>();
    listCoQuanQuanLy = CongChucUtils.searchCoQuanQuanLyByMaOrTen(searchInputText, 0);

    request.setAttribute("chucVuId", chucVuId);
    request.setAttribute("coQuanQuanLyId", coQuanQuanLyId);
    request.setAttribute("listCoQuanQuanLy", listCoQuanQuanLy);
    request.setAttribute("searchInputText", searchInputText);
    response.setRenderParameter("jspPage", "/html/portlet/admin/congchuc/coquanquanly/addchucvutocqql.jsp");
}

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

License:Apache License

/**
 * This is  function save CoQuanQuanLy/*from   w  w  w .j  a  va 2  s  .com*/
 * Version: 1.0
 *  
 * History: 
 *   DATE        AUTHOR      DESCRIPTION 
 *  ------------------------------------------------- 
 *  3-March-2013  Nam Dinh    Create new
 * @param request
 * @param response
 * @throws Exception
 */
public void saveCoQuanQuanLy(ActionRequest request, ActionResponse response) throws Exception {
    String type = ParamUtil.getString(request, "type", "");
    String searchInputText = ParamUtil.getString(request, "searchInputText", "");
    String parentId = ParamUtil.getString(request, "parentId", "");
    List<String> errors = CongChucUtils.validCoQuanQuanLy(request);
    Map<String, String> userRequest = CongChucUtils.getMapCQQLFromRequest(request);
    if (errors.isEmpty()) {
        request.setAttribute("searchInputText", URLDecoder.decode(searchInputText, StringPool.UTF8));
        if (type.equals("add")) {
            try {
                CongChucUtils.insertCoQuanQuanLy(userRequest, request);
                SessionMessages.add(request, "coquanquanly.success.create");
            } catch (Exception e) {
                response.setRenderParameter("jspPage", PageError);
            }

        } else {
            try {
                CongChucUtils.updateCoQuanQuanLy(userRequest, request);
                SessionMessages.add(request, "coquanquanly.success.update");
            } catch (Exception e) {
                response.setRenderParameter("jspPage", PageError);
            }
        }
    } else {
        for (int i = 0; i < errors.size(); i++) {
            SessionErrors.add(request, errors.get(i));
        }
        List<CapCoQuanQuanLy> listCapCoQuanQuanLy = CapCoQuanQuanLyLocalServiceUtil.findByTrangThai(0);
        request.setAttribute("CQQL_OBJECT", userRequest);
        request.setAttribute("listCapCoQuanQuanLy", listCapCoQuanQuanLy);
        request.setAttribute("searchInputText", searchInputText);
        response.setRenderParameter("jspPage", createCoQuanQuanLyJSP);
    }
    request.setAttribute("type", type);
    request.setAttribute("parentId", parentId);
}

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

License:Apache License

/**
 * This is  function delete CoQuanQuanLy
 * Version: 1.0/*from   ww w  .ja v a2s.c  o m*/
 *  
 * History: 
 *   DATE        AUTHOR      DESCRIPTION 
 *  ------------------------------------------------- 
 *  3-March-2013  Nam Dinh    Create new
 * @param request
 * @param response
 * @throws Exception
 */
public void deleteCoQuanQuanLy(ActionRequest request, ActionResponse response) throws Exception {
    long id = ParamUtil.getLong(request, "coQuanQuanLyId");
    String searchInputText = URLDecoder.decode(ParamUtil.getString(request, "searchInputText", ""),
            StringPool.UTF8);
    String parentId = ParamUtil.getString(request, "parentId", "");

    request.setAttribute("searchInputText", searchInputText);
    request.setAttribute("parentId", parentId);
    List<CoQuanQuanLy> lst = CoQuanQuanLyLocalServiceUtil.findByParentId(id, 0);
    List<CongChuc> lcc = CongChucLocalServiceUtil.listCongChuc(id, "", 0, 1);
    if (lst.size() > 0) {
        SessionErrors.add(request, "coquanquanly.err.childExists");
        return;
    }
    if (lcc.size() > 0) {
        SessionErrors.add(request, "coquanquanly.err.congChucExists");
        return;
    }

    try {
        List<ChucVu2VaiTro> listChucVu2VaiTro = ChucVu2VaiTroLocalServiceUtil.findByIdCoQuanQuanLy(id);
        for (int i = 0; i < listChucVu2VaiTro.size(); i++) {
            ChucVu2VaiTroLocalServiceUtil.deleteChucVu2VaiTro(listChucVu2VaiTro.get(i));
        }
        CongChucUtils.delete(id);
        SessionMessages.add(request, "coquanquanly.success.delete");
    } catch (Exception e) {
        e.printStackTrace();
        SessionErrors.add(request, "coquanquanly.err.unKnown");
        return;
    }
}

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

License:Apache License

/**
 * This is  function save ChucVu//from  w ww.j a  v  a 2 s  . c  o  m
 * Version: 1.0
 *  
 * History: 
 *   DATE        AUTHOR      DESCRIPTION 
 *  ------------------------------------------------- 
 *  3-March-2013  Nam Dinh    Create new
 * @param request
 * @param response
 * @throws Exception
 */
public void saveChucVu(ActionRequest request, ActionResponse response) throws Exception {
    boolean insertOk = false;
    long coQuanQuanLyId = ParamUtil.getLong(request, "coquanquanlyid", 0l);
    long chucVuId = ParamUtil.getLong(request, "chucvuid", 0l);
    String parentId = ParamUtil.getString(request, "parentId", "");
    String searchInputText = ParamUtil.getString(request, "searchInputText", "");
    String[] strVaiTroIds = request.getParameterValues("vaitroids");
    long[] vaiTroIds = new long[strVaiTroIds.length];
    User user = PortalUtil.getUser(request);
    ChucVu chucVu = ChucVuLocalServiceUtil.fetchChucVu(chucVuId);
    CoQuanQuanLy coQuanQuanLy = CoQuanQuanLyLocalServiceUtil.fetchCoQuanQuanLy(coQuanQuanLyId);
    for (int i = 0; i < strVaiTroIds.length; i++) {
        vaiTroIds[i] = Long.parseLong(strVaiTroIds[i]);
    }
    if (user != null && chucVu != null && coQuanQuanLy != null) {
        insertOk = CongChucUtils.ganChucVuToCoQuanQuanLy(chucVu, vaiTroIds, coQuanQuanLy, user);
    }
    if (user == null) {
        SessionErrors.add(request, "not.login.error");
    }
    if (insertOk) {
        SessionMessages.add(request, "createChucVuSuccess");
    } else {
        SessionErrors.add(request, "addChucVuError");
    }
    if (coQuanQuanLyId != 0l) {
        Set<Long> setChucVuId = new HashSet<Long>();
        List<ChucVu2VaiTro> listChucVu2VaiTro = ChucVu2VaiTroLocalServiceUtil
                .findByIdCoQuanQuanLyAndDaXoa(coQuanQuanLyId, 0);
        for (int i = 0; i < listChucVu2VaiTro.size(); i++) {
            setChucVuId.add(listChucVu2VaiTro.get(i).getChucVuId());
        }
        request.setAttribute("setChucVuId", setChucVuId);
        request.setAttribute("listChucVu2VaiTro", listChucVu2VaiTro);
    }
    request.setAttribute("parentId", parentId);
    request.setAttribute("searchInputText", searchInputText);
    request.setAttribute("coQuanQuanLyId", coQuanQuanLyId);
    response.setRenderParameter("jspPage", "/html/portlet/admin/congchuc/coquanquanly/listchucvu.jsp");
}

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

License:Apache License

/**
 * This is  function delete ChucVu/*from  w w  w.  j av a2 s . c  o  m*/
 * Version: 1.0
 *  
 * History: 
 *   DATE        AUTHOR      DESCRIPTION 
 *  ------------------------------------------------- 
 *  3-March-2013  Nam Dinh    Create new
 * @param request
 * @param response
 * @throws Exception
 */
public void deleteChucVu(ActionRequest request, ActionResponse response) throws Exception {
    boolean deleteOk = false;
    long coQuanQuanLyId = ParamUtil.getLong(request, "coQuanQuanLyId", 0l);
    long chucVuId = ParamUtil.getLong(request, "chucVuId", 0l);
    String parentId = ParamUtil.getString(request, "parentId", "");
    String searchInputText = ParamUtil.getString(request, "searchInputText", "");
    ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);
    User user = themeDisplay.getUser();
    ChucVu chucVu = ChucVuLocalServiceUtil.fetchChucVu(chucVuId);
    CoQuanQuanLy coQuanQuanLy = CoQuanQuanLyLocalServiceUtil.fetchCoQuanQuanLy(coQuanQuanLyId);
    if (user != null && chucVu != null && coQuanQuanLy != null) {
        deleteOk = CongChucUtils.xoaChucVuToCoQuanQuanLy(chucVu, coQuanQuanLy, user);
    }
    if (deleteOk) {
        SessionMessages.add(request, "deleteChucVuSuccess");
    } else {
        SessionErrors.add(request, "deleteChucVuError");
    }
    if (coQuanQuanLyId != 0l) {
        Set<Long> setChucVuId = new HashSet<Long>();
        List<ChucVu2VaiTro> listChucVu2VaiTro = ChucVu2VaiTroLocalServiceUtil
                .findByIdCoQuanQuanLyAndDaXoa(coQuanQuanLyId, 0);
        for (int i = 0; i < listChucVu2VaiTro.size(); i++) {
            setChucVuId.add(listChucVu2VaiTro.get(i).getChucVuId());
        }
        request.setAttribute("setChucVuId", setChucVuId);
        request.setAttribute("listChucVu2VaiTro", listChucVu2VaiTro);
    }
    request.setAttribute("parentId", parentId);
    request.setAttribute("searchInputText", searchInputText);
    request.setAttribute("coQuanQuanLyId", coQuanQuanLyId);
    response.setRenderParameter("jspPage", "/html/portlet/admin/congchuc/coquanquanly/listchucvu.jsp");
}

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

License:Apache License

/**
 * This is  function save CongChuc/*w  ww .  ja  v a2s .com*/
 * Version: 1.0
 *  
 * History: 
 *   DATE        AUTHOR      DESCRIPTION 
 *  ------------------------------------------------- 
 *  3-March-2013  Nam Dinh    Create new
 * @param actionRequest
 * @param actionResponse
 * @throws Exception
 */
public void saveCongChuc(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception {
    String coQuanQuanLyId = ParamUtil.getString(actionRequest, "coQuanQuanLyId", "");
    String maOrTenOrEmail = ParamUtil.getString(actionRequest, "maOrTenOrEmail", "");
    String emailForm = ParamUtil.getString(actionRequest, "email", "");
    String tab = ParamUtil.getString(actionRequest, "tab", "CC");

    long id = ParamUtil.getLong(actionRequest, "id", 0);
    User currentUser = PortalUtil.getUser(actionRequest);
    if (currentUser == null) {
        SessionErrors.add(actionRequest, "not.login.error");
    }
    CongChuc congChuc = null;
    if (id > 0) {
        congChuc = CongChucLocalServiceUtil.fetchCongChuc(id);
    } else {
        congChuc = new CongChucClp();
    }
    try {
        congChuc = this.getCongChucFormHtml(congChuc, actionRequest);
    } catch (Exception e1) {
        e1.printStackTrace();
    }

    TaiKhoanNguoiDung taiKhoan = new TaiKhoanNguoiDungClp();

    CoQuanQuanLy coQuanQuanLy = CoQuanQuanLyLocalServiceUtil.fetchCoQuanQuanLy(congChuc.getCoQuanQuanLyId());
    ChucVu chucVu = null;
    if (congChuc.getChucVuId() > 0) {
        chucVu = ChucVuLocalServiceUtil.getChucVu(congChuc.getChucVuId());
    }
    List<String> errors = CongChucUtils.validCongChuc(actionRequest);
    if (errors.isEmpty() && currentUser != null) {
        String password = (ParamUtil.getString(actionRequest, "password", ""));
        String rePassword = ParamUtil.getString(actionRequest, "rePassword", "");
        String email = (ParamUtil.getString(actionRequest, "email", ""));
        boolean flag = true;
        if (id == 0) {
            //truong hop them moi
            flag = LiferayUtils.addUser(congChuc.getHoVaTen(), email, password, rePassword,
                    currentUser.getUserId(), currentUser.getCompanyId());

            if (flag) {
                User user = UserLocalServiceUtil.getUserByEmailAddress(currentUser.getCompanyId(), email);
                try {
                    String loaiDoiTuongId = ThamSoLocalServiceUtil.getValue("LDT_CANBO");
                    taiKhoan.setId(
                            CounterLocalServiceUtil.increment(TaoCongDanBusiness.TAIKHOANNGUOIDUNG_SEQUENCE));
                    taiKhoan.setTaiKhoanNguoiDungId(user.getUserId());
                    taiKhoan.setNgayTao(new Date());
                    taiKhoan.setNguoiTao(currentUser.getFullName());
                    taiKhoan.setTenNguoiDung(congChuc.getHoVaTen());
                    taiKhoan.setTenDangNhap(email);
                    taiKhoan.setLoaiDoiTuongId(Long.valueOf(loaiDoiTuongId));
                    taiKhoan.setEmail(email);
                    taiKhoan.setMatKhau(CongChucUtils.md5(password));
                    taiKhoan.setTrangThai(1);
                    TaiKhoanNguoiDung taiKhoanResult = TaiKhoanNguoiDungLocalServiceUtil
                            .addTaiKhoanNguoiDung(taiKhoan);
                    if (taiKhoanResult != null) {
                        try {
                            congChuc.setId(CounterLocalServiceUtil.increment("cmon_congchuc"));
                            congChuc.setNgayTao(new Date());
                            congChuc.setTaiKhoanNguoiDungId(taiKhoanResult.getId());
                            congChuc.setNguoiTao(currentUser.getFullName());
                            CongChuc congChucReturn = CongChucLocalServiceUtil.addCongChuc(congChuc);
                            if (chucVu != null) {
                                CongChucUtils.ganChucVuToCanBo(congChucReturn, coQuanQuanLy, chucVu);
                            }
                            SessionMessages.add(actionRequest, "insert.success");
                            actionRequest.setAttribute("coQuanQuanLyId", String.valueOf(coQuanQuanLyId));
                            actionRequest.setAttribute("maOrTenOrEmail",
                                    URLDecoder.decode(maOrTenOrEmail, StringPool.UTF8));
                            actionRequest.setAttribute("tab", tab);
                        } catch (Exception e) {
                            TaiKhoanNguoiDungLocalServiceUtil.deleteTaiKhoanNguoiDung(taiKhoanResult);
                            UserLocalServiceUtil.deleteUser(user);
                            actionResponse.setRenderParameter("jspPage", PageError);
                            return;
                        }

                    }
                } catch (Exception e) {
                    UserLocalServiceUtil.deleteUser(user);
                    actionResponse.setRenderParameter("jspPage", PageError);
                    return;
                }
            } else {
                actionResponse.setRenderParameter("jspPage", PageError);
                return;
            }
        } else {
            //Truong hop chinh sua
            try {
                taiKhoan = TaiKhoanNguoiDungLocalServiceUtil
                        .fetchTaiKhoanNguoiDung(congChuc.getTaiKhoanNguoiDungId());
                User user = UserLocalServiceUtil.fetchUser(taiKhoan.getTaiKhoanNguoiDungId());
                if (user == null) {
                    LiferayUtils.addUser(congChuc.getHoVaTen(), email, "huynq", "huynq",
                            currentUser.getUserId(), currentUser.getCompanyId());
                    user = UserLocalServiceUtil.getUserByEmailAddress(currentUser.getCompanyId(),
                            taiKhoan.getEmail());
                } else {
                    user.setFirstName(congChuc.getHoVaTen());
                    user.setEmailAddress(email);
                    user.setModifiedDate(new Date());
                    UserLocalServiceUtil.updateUser(user);
                }
                CongChuc currentCongChuc = CongChucLocalServiceUtil.fetchCongChuc(id);
                if (chucVu != null) {
                    CongChucUtils.xoaChucVuToCanBo(currentCongChuc, CoQuanQuanLyLocalServiceUtil
                            .fetchCoQuanQuanLy(currentCongChuc.getCoQuanQuanLyId()));
                    CongChucUtils.ganChucVuToCanBo(congChuc, coQuanQuanLy, chucVu);
                } else {
                    CongChucUtils.xoaChucVuToCanBo(currentCongChuc, CoQuanQuanLyLocalServiceUtil
                            .fetchCoQuanQuanLy(currentCongChuc.getCoQuanQuanLyId()));
                }
                taiKhoan.setNgaySua(new Date());
                taiKhoan.setNguoiSua(currentUser.getFullName());
                taiKhoan.setTenNguoiDung(congChuc.getHoVaTen());
                taiKhoan.setTenDangNhap(email);
                taiKhoan.setEmail(email);
                taiKhoan.setTaiKhoanNguoiDungId(user.getUserId());
                TaiKhoanNguoiDung taiKhoanResult = TaiKhoanNguoiDungLocalServiceUtil
                        .updateTaiKhoanNguoiDung(taiKhoan);
                congChuc.setNgaySua(new Date());
                congChuc.setTaiKhoanNguoiDungId(taiKhoanResult.getId());
                congChuc.setNguoiSua(currentUser.getFullName());
                CongChucLocalServiceUtil.updateCongChuc(congChuc);
                SessionMessages.add(actionRequest, "update.success");
                actionRequest.setAttribute("coQuanQuanLyId", String.valueOf(coQuanQuanLyId));
                actionRequest.setAttribute("maOrTenOrEmail",
                        URLDecoder.decode(maOrTenOrEmail, StringPool.UTF8));
                actionRequest.setAttribute("tab", tab);
            } catch (Exception e) {
                actionResponse.setRenderParameter("jspPage", PageError);
                return;
            }

        }
    } else {
        for (int i = 0; i < errors.size(); i++) {
            SessionErrors.add(actionRequest, errors.get(i));
        }
        actionRequest.setAttribute("coQuanQuanLyId", String.valueOf(coQuanQuanLyId));
        actionRequest.setAttribute("maOrTenOrEmail", maOrTenOrEmail);
        actionRequest.setAttribute("emailForm", emailForm);
        actionRequest.setAttribute("congChuc", congChuc);
        actionRequest.setAttribute("taiKhoan", taiKhoan);
        actionRequest.setAttribute("coQuanQuanLy", coQuanQuanLy);
        actionResponse.setRenderParameter("jspPage", PageEditCongChuc);
    }
}

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

License:Apache License

/**
 * This is  function delete CongChuc/*  ww w. j av  a  2  s  . co  m*/
 * Version: 1.0
 *  
 * History: 
 *   DATE        AUTHOR      DESCRIPTION 
 *  ------------------------------------------------- 
 *  3-March-2013  Nam Dinh    Create new
 * @param actionRequest
 * @param actionResponse
 * @throws UnsupportedEncodingException
 */
public void deleteCongChuc(ActionRequest actionRequest, ActionResponse actionResponse)
        throws UnsupportedEncodingException {
    String congChucId = ParamUtil.getString(actionRequest, "congChucId");
    String tab = ParamUtil.getString(actionRequest, "tab", "CC");
    String coQuanQuanLyId = ParamUtil.getString(actionRequest, "coQuanQuanLyId", "");
    String maOrTenOrEmail = URLDecoder.decode(ParamUtil.getString(actionRequest, "maOrTenOrEmail", ""),
            StringPool.UTF8);
    try {
        CongChuc congChuc = CongChucLocalServiceUtil.fetchCongChuc(Long.valueOf(congChucId));
        if (congChuc != null) {
            TaiKhoanNguoiDung taiKhoan = TaiKhoanNguoiDungLocalServiceUtil
                    .fetchTaiKhoanNguoiDung(congChuc.getTaiKhoanNguoiDungId());
            if (taiKhoan != null) {
                User user = UserLocalServiceUtil.fetchUser(taiKhoan.getTaiKhoanNguoiDungId());
                if (user != null) {
                    CongChucLocalServiceUtil.deleteCongChuc(congChuc);
                    List<NguoiDung2VaiTro> listNguoiDung2VaiTro = NguoiDung2VaiTroLocalServiceUtil
                            .findByTaiKhoanNguoiDungID(taiKhoan.getId(), 0);
                    for (int i = 0; i < listNguoiDung2VaiTro.size(); i++) {
                        NguoiDung2VaiTroLocalServiceUtil.deleteNguoiDung2VaiTro(listNguoiDung2VaiTro.get(i));
                    }
                    TaiKhoanNguoiDungLocalServiceUtil.deleteTaiKhoanNguoiDung(taiKhoan);
                    UserLocalServiceUtil.deleteUser(user);
                    SessionMessages.add(actionRequest, "delete.success");
                } else {
                    SessionErrors.add(actionRequest, "delete.error");
                }
            } else {
                SessionErrors.add(actionRequest, "delete.error");
            }
        } else {
            SessionErrors.add(actionRequest, "delete.error");
        }
    } catch (Exception e) {
        actionResponse.setRenderParameter("jspPage", PageError);
        return;
    }
    actionRequest.setAttribute("coQuanQuanLyId", String.valueOf(coQuanQuanLyId));
    actionRequest.setAttribute("maOrTenOrEmail", maOrTenOrEmail);
    actionRequest.setAttribute("tab", tab);
}

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

License:Apache License

/**
 * This is  function save password//w ww  .  ja  v  a  2s.c  om
 * Version: 1.0
 *  
 * History: 
 *   DATE        AUTHOR      DESCRIPTION 
 *  ------------------------------------------------- 
 *  3-March-2013  Nam Dinh    Create new
 * @param actionRequest
 * @param actionResponse
 * @throws Exception
 */
public void saveResetPassword(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception {
    String password = ParamUtil.getString(actionRequest, "password", "");
    String rePassword = ParamUtil.getString(actionRequest, "rePassword", "");
    long taiKhoanId = ParamUtil.getLong(actionRequest, "taiKhoanId", 0);
    CongChuc congChuc = CongChucLocalServiceUtil.fetchByTaiKhoanNguoiDung(taiKhoanId);
    boolean valid = true;
    if (Validator.isNull(ParamUtil.getString(actionRequest, "password"))) {
        SessionErrors.add(actionRequest, "empty.password");
        valid = false;
    }
    if (Validator.isNull(ParamUtil.getString(actionRequest, "rePassword"))) {
        SessionErrors.add(actionRequest, "empty.repassword");
        valid = false;
    }
    if (Validator.isNotNull(ParamUtil.getString(actionRequest, "rePassword"))
            && Validator.isNotNull(ParamUtil.getString(actionRequest, "password"))) {
        if (!ParamUtil.getString(actionRequest, "rePassword")
                .equals(ParamUtil.getString(actionRequest, "password"))) {
            SessionErrors.add(actionRequest, "missmatch.password");
            valid = false;
        }
    }
    if (valid) {
        TaiKhoanNguoiDung taiKhoan = TaiKhoanNguoiDungLocalServiceUtil.fetchTaiKhoanNguoiDung(taiKhoanId);
        taiKhoan.setMatKhau(CongChucUtils.md5(password));
        TaiKhoanNguoiDungLocalServiceUtil.updateTaiKhoanNguoiDung(taiKhoan);
        boolean changeOk = LiferayUtils.changePassword(taiKhoan.getTaiKhoanNguoiDungId(), password, rePassword);
        if (changeOk) {
            SessionMessages.add(actionRequest, "change.success");
        } else {
            SessionErrors.add(actionRequest, "change.error");
        }
    }
    actionRequest.setAttribute("congChuc", congChuc);
    actionResponse.setRenderParameter("jspPage", PageResetPassword);
}