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:com.stc.poc.controller.StcPocController.java

License:Open Source License

/**
 * //from   ww  w . j  ava 2s  . co  m
 * @param actionRequest
 * @param actionResponse
 * @param model 
 */
public void cancelDeduction(RenderRequest actionRequest, RenderResponse actionResponse, ModelMap model) {

    String deductionId = ParamUtil.get(actionRequest, "idDeduction", "");
    if (deductionId != null) {
        try {

            String message = facade.cancelDeduction(deductionId, actionRequest);
            if (SessionErrors.isEmpty(actionRequest)) {
                SessionMessages.add(actionRequest, "cancel-succes");
                model.addAttribute("message", message);
            } else {
                SessionErrors.add(actionRequest, "succes-cancel-deduction");
                model.addAttribute("message", message);
            }

        } catch (NumberFormatException e) {
            _log.error(e.getMessage(), e);
            SessionErrors.add(actionRequest, "poc-stc-error");
        } catch (ServicesConnectException e) {
            _log.error(e.getMessage(), e);
            SessionErrors.add(actionRequest, "poc-stc-error");
        } catch (PortalException e) {
            _log.error(e.getMessage(), e);
            SessionErrors.add(actionRequest, "poc-stc-error");
        } catch (SystemException e) {
            _log.error(e.getMessage(), e);
            SessionErrors.add(actionRequest, "poc-stc-error");
        }
    }
}

From source file:com.stc.poc.controller.StcPocController.java

License:Open Source License

@RenderMapping(params = "action=editDeduction")
public String editDeduction(RenderRequest actionRequest, RenderResponse actionResponse) {

    String deductionId = ParamUtil.get(actionRequest, "deductionId", "");
    if (deductionId != null) {
        try {/*w  ww  .  java  2  s  . c  o  m*/

            //facade.editDeduction(deductionId, actionRequest);
            if (!SessionErrors.isEmpty(actionRequest)) {
                SessionErrors.add(actionRequest, "error-edit-deduction");
            } else {
                SessionMessages.add(actionRequest, "succes-delete-deduction");
            }

        } catch (NumberFormatException e) {
            _log.error(e.getMessage(), e);
        }
    }
    return "EditDeduction";
}

From source file:com.verce.action.ConfigurationActionImpl.java

License:Open Source License

@Override
public void processAction(PortletConfig portletConfig, ActionRequest actionRequest,
        ActionResponse actionResponse) throws Exception {

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

    if (cmd.equals("update")) {
        ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);

        UnicodeProperties properties = PropertiesParamUtil.getProperties(actionRequest, PREFERENCES_PREFIX);

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

        PortletPermissionUtil.check(themeDisplay.getPermissionChecker(), themeDisplay.getLayout(),
                portletResource, ActionKeys.CONFIGURATION);

        PortletPreferences portletPreferences = PortletPreferencesFactoryUtil.getPortletSetup(actionRequest,
                portletResource);//from   ww  w. j a v  a2  s  .com

        for (Map.Entry<String, String> entry : properties.entrySet()) {
            String name = entry.getKey();
            String value = entry.getValue();

            portletPreferences.setValue(name, value);
        }

        Map<String, String[]> portletPreferencesMap = (Map<String, String[]>) actionRequest
                .getAttribute(WebKeys.PORTLET_PREFERENCES_MAP);

        if (portletPreferencesMap != null) {
            for (Map.Entry<String, String[]> entry : portletPreferencesMap.entrySet()) {

                String name = entry.getKey();
                String[] values = entry.getValue();

                portletPreferences.setValues(name, values);
            }
        }

        if (SessionErrors.isEmpty(actionRequest)) {
            portletPreferences.store();

            LiferayPortletConfig liferayPortletConfig = (LiferayPortletConfig) portletConfig;

            SessionMessages.add(actionRequest, liferayPortletConfig.getPortletId() + ".refreshPortlet",
                    portletResource);

            SessionMessages.add(actionRequest, liferayPortletConfig.getPortletId() + ".updatedConfiguration");
        }
    }
}

From source file:org.gfbio.ContactFormToHelpdeskPortlet.java

License:Open Source License

public void saveData(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception {

    ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);

    String portletId = (String) actionRequest.getAttribute(WebKeys.PORTLET_ID);

    PortletPreferences preferences = PortletPreferencesFactoryUtil.getPortletSetup(actionRequest, portletId);

    String emailFromAddress = actionRequest.getParameter("fromAddress");
    String emailFromName = actionRequest.getParameter("fromName");
    String emailSubject = actionRequest.getParameter("fromSubject");

    preferences.setValue("emailFromAddress", emailFromAddress);
    preferences.setValue("emailFromName", emailFromName);
    preferences.setValue("emailSubject", emailSubject);

    boolean requireCaptcha = GetterUtil.getBoolean(preferences.getValue("requireCaptcha", StringPool.BLANK));

    String successURL = GetterUtil.getString(preferences.getValue("successURL", StringPool.BLANK));
    boolean sendAsEmail = GetterUtil.getBoolean(preferences.getValue("sendAsEmail", StringPool.BLANK));
    boolean saveToDatabase = GetterUtil.getBoolean(preferences.getValue("saveToDatabase", StringPool.BLANK));
    String databaseTableName = GetterUtil
            .getString(preferences.getValue("databaseTableName", StringPool.BLANK));
    boolean saveToFile = GetterUtil.getBoolean(preferences.getValue("saveToFile", StringPool.BLANK));
    String fileName = GetterUtil.getString(preferences.getValue("fileName", StringPool.BLANK));

    Boolean validCapatcha = false;
    //check  the reCaptcha 
    try {// www  .  ja va 2s  .c o  m
        //_log.info("validatechallenge called "+actionRequest);

        validCapatcha = validateChallenge(actionRequest);
        _log.info("valid Capatcha " + validCapatcha);

        //_log.info("ActionRequest"+actionRequest);
        //_log.info("--------------------------"+"emailFromAddress" +emailFromAddress+ " g-recaptcha-response ");
    } catch (CaptchaTextException cte) {
        SessionErrors.add(actionRequest, CaptchaTextException.class.getName());

        return;
    }

    /*      
          if (requireCaptcha) {
             try {
    CaptchaUtil.check(actionRequest);
             }
             catch (CaptchaTextException cte) {
    SessionErrors.add(
       actionRequest, CaptchaTextException.class.getName());
            
    return;
             }
          }
    */
    //validation of fix fields (emailFromName, emailFromAddress, subject) 

    //check if emailAddress is ok
    String[] emailAdresses = WebFormUtil.split(preferences.getValue("emailFromAddress", StringPool.BLANK));

    Set<String> validationFixFieldsErrors = null;
    try {
        validationFixFieldsErrors = validateFixFields(emailAdresses, emailFromName, emailSubject);
    } catch (Exception e) {
        SessionErrors.add(actionRequest, "validationScriptError", e.getMessage().trim());

        return;
    }
    if (!validCapatcha) {
        validationFixFieldsErrors.add("captchanotverified");

    }

    Map<String, String> fieldsMap = new LinkedHashMap<String, String>();

    for (int i = 1; true; i++) {
        String fieldLabel = preferences.getValue("fieldLabel" + i, StringPool.BLANK);

        String fieldType = preferences.getValue("fieldType" + i, StringPool.BLANK);

        if (Validator.isNull(fieldLabel)) {
            break;
        }

        if (StringUtil.equalsIgnoreCase(fieldType, "paragraph")) {
            continue;
        }

        fieldsMap.put(fieldLabel, actionRequest.getParameter("field" + i));
    }

    Set<String> validationErrors = null;

    try {
        validationErrors = validate(fieldsMap, preferences);

    } catch (Exception e) {
        SessionErrors.add(actionRequest, "validationScriptError", e.getMessage().trim());

        return;
    }

    if (validationErrors.isEmpty() && validationFixFieldsErrors.isEmpty()) {
        boolean emailSuccess = true;
        boolean databaseSuccess = true;
        boolean fileSuccess = true;

        if (sendAsEmail) {
            emailSuccess = sendEmail(themeDisplay.getCompanyId(), fieldsMap, preferences);
        }

        if (saveToDatabase) {
            if (Validator.isNull(databaseTableName)) {
                databaseTableName = WebFormUtil.getNewDatabaseTableName(portletId);

                preferences.setValue("databaseTableName", databaseTableName);

                preferences.store();
            }

            databaseSuccess = saveDatabase(themeDisplay.getCompanyId(), fieldsMap, preferences,
                    databaseTableName);
        }

        if (saveToFile) {
            fileSuccess = saveFile(fieldsMap, fileName);
        }

        if (emailSuccess && databaseSuccess && fileSuccess) {
            SessionMessages.add(actionRequest, "success");
        } else {
            SessionErrors.add(actionRequest, "error");
        }
    } else {
        for (String badField : validationErrors) {
            SessionErrors.add(actionRequest, "error" + badField);
        }
        for (String badField : validationFixFieldsErrors) {
            _log.info(badField);
            SessionErrors.add(actionRequest, badField);
        }
    }

    if (SessionErrors.isEmpty(actionRequest) && Validator.isNotNull(successURL)) {

        actionResponse.sendRedirect(successURL);
    }
}

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

License:Apache License

/**
 * This is  function validation input//from  w  w w  . j  av a 2s.com
 * Version: 1.0
 *  
 * History: 
 *   DATE        AUTHOR      DESCRIPTION 
 *  ------------------------------------------------- 
 *  3-March-2013  Nam Dinh    Create new
 * @param maCapCoQuanQuanLy
 * @param tenCapCoQuanQuanLy
 * @param actionRequest
 * @return boolean
 */
private boolean validationInput(String maCapCoQuanQuanLy, String tenCapCoQuanQuanLy,
        ActionRequest actionRequest) {
    if (maCapCoQuanQuanLy.trim().length() == 0) {
        SessionErrors.add(actionRequest, "emptyMaCapCoQuanQuanLy");
    }
    if (tenCapCoQuanQuanLy.trim().length() == 0) {
        SessionErrors.add(actionRequest, "emptyTenCapCoQuanQuanLy");
    }

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

    return false;
}

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

License:Apache License

/**
 * This is  function check validation input
 * Version: 1.0/*from  w  w w. ja  v a 2  s . co m*/
 *  
 * History: 
 *   DATE        AUTHOR      DESCRIPTION 
 *  ------------------------------------------------- 
 *  3-March-2013  Nam Dinh    Create new
 * @param maDonViHanhChinh
 * @param tenDonViHanhChinh
 * @param DonViHanhChinhId
 * @param _capDonViHanhChinh
 * @param actionRequest
 * @param moTaCapDonViHanhChinh
 * @return boolean
 */
private boolean validationInput(String maDonViHanhChinh, String tenDonViHanhChinh, String DonViHanhChinhId,
        String _capDonViHanhChinh, ActionRequest actionRequest, String moTaCapDonViHanhChinh) {
    if (maDonViHanhChinh.trim().length() == 0) {
        SessionErrors.add(actionRequest, "emptyMaCapDonViHanhChinh");
    }
    if (_capDonViHanhChinh.trim().length() == 0) {
        SessionErrors.add(actionRequest, "emptyCapDonViHanhChinh");
    }
    if (_capDonViHanhChinh.trim().length() > 0) {
        if (ConvertUtil.convertToLong(_capDonViHanhChinh) == 0) {
            SessionErrors.add(actionRequest, "numberCapDonViHanhChinh");
        }
    }
    if (tenDonViHanhChinh.trim().length() == 0) {
        SessionErrors.add(actionRequest, "emptyTenCapDonViHanhChinh");
    }
    if (moTaCapDonViHanhChinh.trim().length() == 0) {
        SessionErrors.add(actionRequest, "emptyMoTaCapDonViHanhChinh");
    }
    // Neu thong tin nhap khac rong
    if (SessionErrors.isEmpty(actionRequest)) {
        CapDonViHanhChinh capDonViHanhChinh = null;
        try {
            // Kieam tra theo Ma
            try {
                capDonViHanhChinh = CapDonViHanhChinhLocalServiceUtil
                        .findByMaCapDonViHanhChinh(maDonViHanhChinh);
            } catch (NoSuchCapDonViHanhChinhException es) {
            }
            if (capDonViHanhChinh != null) {
                if (capDonViHanhChinh.getDaXoa() == SetParamUtil.DA_XOA_DEACTIVATE) {
                    return true;
                }

                if (DonViHanhChinhId.trim().length() > 0) {
                    if (ConvertUtil.convertToLong(DonViHanhChinhId) != capDonViHanhChinh.getId()) {
                        SessionErrors.add(actionRequest, "exitMaCapDonViHanhChinh");
                    }
                } else {
                    SessionErrors.add(actionRequest, "exitMaCapDonViHanhChinh");
                }
            }

            //            // Kiem tra theo Ten
            //            try {
            //               capDonViHanhChinh = null;
            //               capDonViHanhChinh = CapDonViHanhChinhLocalServiceUtil.findByTenCapDonViHanhChinh(tenDonViHanhChinh);
            //            } catch (NoSuchCapDonViHanhChinhException es) {
            //            }
            //            if (capDonViHanhChinh != null) {
            //               if (DonViHanhChinhId.trim().length() > 0) {
            //                  if (ConvertUtil.convertToLong(DonViHanhChinhId) != capDonViHanhChinh.getId()) {
            //                     SessionErrors.add(actionRequest, "exitTenCapDonViHanhChinh");
            //                  }
            //               } else {
            //                  SessionErrors.add(actionRequest, "exitTenCapDonViHanhChinh");
            //               }
            //            }
        } catch (Exception es) {
        }
    }

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

    return false;
}

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

License:Apache License

/**
 * This is  function check validation input
 * Version: 1.0//from  w ww.j a  va 2s  . c o m
 *  
 * History: 
 *   DATE        AUTHOR      DESCRIPTION 
 *  ------------------------------------------------- 
 *  3-March-2013  Nam Dinh    Create new
 * @param tenDoiTuongSuDung
 * @param doiTuongSuDungId
 * @param maDoiTuongSuDung
 * @param actionRequest
 * @return boolean
 */
private boolean validationInput(String tenDoiTuongSuDung, String doiTuongSuDungId, String maDoiTuongSuDung,
        ActionRequest actionRequest) {
    if (maDoiTuongSuDung.trim().length() == 0) {
        SessionErrors.add(actionRequest, "emptyMaChucVu");
    }
    if (tenDoiTuongSuDung.trim().length() == 0) {
        SessionErrors.add(actionRequest, "emptyTenChucVu");
    }
    // Neu thong tin nhap khac rong
    if (SessionErrors.isEmpty(actionRequest)) {
        ChucVu doiTuongSuDung = null;
        try {

            // Kiem tra theo Ma
            try {
                doiTuongSuDung = null;
                List<ChucVu> list = ChucVuLocalServiceUtil.findMa(maDoiTuongSuDung);
                if (list != null && list.size() > 0) {
                    doiTuongSuDung = list.get(0);
                }
            } catch (Exception es) {
            }
            if (doiTuongSuDung != null) {
                if (doiTuongSuDung.getDaXoa() == SetParamUtil.DA_XOA_DEACTIVATE) {
                    return true;
                }
                if (doiTuongSuDungId.trim().length() > 0) {
                    if (ConvertUtil.convertToLong(doiTuongSuDungId) != doiTuongSuDung.getId()) {
                        SessionErrors.add(actionRequest, "exitMaChucVu");
                    }
                } else {
                    SessionErrors.add(actionRequest, "exitMaChucVu");
                }
            }

            //            // Kiem tra theo Ten
            //            try {
            //               doiTuongSuDung = null;
            //               List<ChucVu> list = ChucVuLocalServiceUtil.findTen(tenDoiTuongSuDung);
            //               if (list != null && list.size() > 0) {
            //                  doiTuongSuDung = list.get(0);
            //               }
            //            } catch (Exception es) {
            //            }
            //            if (doiTuongSuDung != null) {
            //               if (doiTuongSuDungId.trim().length() > 0) {
            //                  if (ConvertUtil.convertToLong(doiTuongSuDungId) != doiTuongSuDung.getId()) {
            //                     SessionErrors.add(actionRequest, "exitTenChucVu");
            //                  }
            //               } else {
            //                  SessionErrors.add(actionRequest, "exitTenChucVu");
            //               }
            //            }
        } catch (Exception es) {
        }
    }

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

    return false;
}

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

License:Apache License

/**
 * This is  function check validation input
 * Version: 1.0// w w w.j av  a 2 s .  c  o m
 *  
 * History: 
 *   DATE        AUTHOR      DESCRIPTION 
 *  ------------------------------------------------- 
 *  3-March-2013  Nam Dinh    Create new
 * @param chucVuId
 * @param vaiTroId
 * @param chucVuVaiTroId
 * @param coQuanQuanLyId
 * @param actionRequest
 * @return boolean
 */
private boolean validationInput(String chucVuId, String vaiTroId, String chucVuVaiTroId, String coQuanQuanLyId,
        ActionRequest actionRequest) {
    if (chucVuId.trim().length() == 0 || ConvertUtil.convertToLong(chucVuId) == 0) {
        SessionErrors.add(actionRequest, "emptyChucVuIdChucVu2VaiTro");
    }
    if (vaiTroId.trim().length() == 0 || ConvertUtil.convertToLong(vaiTroId) == 0) {
        SessionErrors.add(actionRequest, "emptyVaiTroIdChucVu2VaiTro");
    }

    if (SessionErrors.isEmpty(actionRequest)) {
        DynamicQuery query = DynamicQueryFactoryUtil.forClass(ChucVu2VaiTro.class);

        // This is a test line for display all request if there's no search criteria
        Criterion criteriaChucVu = RestrictionsFactoryUtil.eq("chucVuId", ConvertUtil.convertToLong(chucVuId));
        Criterion criteriaVaiTro = RestrictionsFactoryUtil.eq("vaiTroId", ConvertUtil.convertToLong(vaiTroId));
        Criterion criteriaDaXoa = RestrictionsFactoryUtil.eq("daXoa", 0);
        Criterion criteriaCoQuanQuanLyId = RestrictionsFactoryUtil.eq("coQuanQuanLyId",
                ConvertUtil.convertToLong(coQuanQuanLyId));

        // Define search criteria
        query = query.add(criteriaChucVu).add(criteriaVaiTro).add(criteriaCoQuanQuanLyId).add(criteriaDaXoa);
        try {
            List<ChucVu2VaiTro> listChucVu2VaiTro = ChucVu2VaiTroLocalServiceUtil.dynamicQuery(query);
            if (listChucVu2VaiTro.size() > 0) {
                if (chucVuVaiTroId.trim().length() > 0) {
                    ChucVu2VaiTro chucVu2VaiTro = listChucVu2VaiTro.get(0);
                    if (chucVu2VaiTro.getId() != ConvertUtil.convertToLong(chucVuVaiTroId)) {
                        SessionErrors.add(actionRequest, "exitChucVu2VaiTro");
                    }
                } else {
                    SessionErrors.add(actionRequest, "exitChucVu2VaiTro");
                }
            }
        } catch (SystemException e) {
        }
    }
    if (SessionErrors.isEmpty(actionRequest)) {
        return true;
    }

    return false;
}

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

License:Apache License

/**
 * This is function add or edit CongChuc
 * Version: 1.0//from   ww w  . j  a  va 2  s . c  o m
 *  
 * 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  w w  w  .j  a  va 2 s . co m*/
 *  
 * 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);
    }
}