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, Object value) 

Source Link

Usage

From source file:com.liferay.exportimport.web.internal.portlet.action.EditExportConfigurationMVCActionCommand.java

License:Open Source License

protected void addSessionMessages(ActionRequest actionRequest) throws Exception {

    String portletId = portal.getPortletId(actionRequest);
    long exportImportConfigurationId = ParamUtil.getLong(actionRequest, "exportImportConfigurationId");

    SessionMessages.add(actionRequest, portletId + "exportImportConfigurationId", exportImportConfigurationId);

    String name = ParamUtil.getString(actionRequest, "name");
    String description = ParamUtil.getString(actionRequest, "description");

    SessionMessages.add(actionRequest, portletId + "name", name);
    SessionMessages.add(actionRequest, portletId + "description", description);

    long groupId = ParamUtil.getLong(actionRequest, "groupId");

    Map<String, Serializable> settingsMap = ExportImportConfigurationSettingsMapFactory
            .buildSettingsMap(actionRequest, groupId, ExportImportConfigurationConstants.TYPE_EXPORT_LAYOUT);

    SessionMessages.add(actionRequest, portletId + "settingsMap", settingsMap);
}

From source file:com.liferay.exportimport.web.internal.portlet.action.EditPublishConfigurationMVCActionCommand.java

License:Open Source License

@Override
protected void addSessionMessages(ActionRequest actionRequest) throws Exception {

    String portletId = portal.getPortletId(actionRequest);
    long exportImportConfigurationId = ParamUtil.getLong(actionRequest, "exportImportConfigurationId");

    SessionMessages.add(actionRequest, portletId + "exportImportConfigurationId", exportImportConfigurationId);

    String name = ParamUtil.getString(actionRequest, "name");
    String description = ParamUtil.getString(actionRequest, "description");

    SessionMessages.add(actionRequest, portletId + "name", name);
    SessionMessages.add(actionRequest, portletId + "description", description);

    long groupId = ParamUtil.getLong(actionRequest, "groupId");

    int exportImportConfigurationType = ExportImportConfigurationConstants.TYPE_PUBLISH_LAYOUT_REMOTE;

    boolean localPublishing = ParamUtil.getBoolean(actionRequest, "localPublishing");

    if (localPublishing) {
        exportImportConfigurationType = ExportImportConfigurationConstants.TYPE_PUBLISH_LAYOUT_LOCAL;
    }//  w ww  . jav  a 2  s. c o m

    Map<String, Serializable> settingsMap = ExportImportConfigurationSettingsMapFactory
            .buildSettingsMap(actionRequest, groupId, exportImportConfigurationType);

    SessionMessages.add(actionRequest, portletId + "settingsMap", settingsMap);
}

From source file:com.liferay.image.uploader.web.internal.portlet.action.UploadImageMVCActionCommand.java

License:Open Source License

@Override
protected void doProcessAction(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception {

    hideDefaultSuccessMessage(actionRequest);

    String cmd = ParamUtil.getString(actionRequest, Constants.CMD);

    long maxFileSize = ParamUtil.getLong(actionRequest, "maxFileSize");

    try {/*from   w  w w. ja  va 2 s  . c o m*/
        UploadException uploadException = (UploadException) actionRequest
                .getAttribute(WebKeys.UPLOAD_EXCEPTION);

        if (uploadException != null) {
            Throwable cause = uploadException.getCause();

            if (uploadException.isExceededFileSizeLimit()) {
                throw new FileSizeException(cause);
            }

            if (uploadException.isExceededUploadRequestSizeLimit()) {
                throw new UploadRequestSizeException(cause);
            }

            throw new PortalException(cause);
        } else if (cmd.equals(Constants.ADD_TEMP)) {
            FileEntry tempImageFileEntry = addTempImageFileEntry(actionRequest);

            JSONObject jsonObject = JSONFactoryUtil.createJSONObject();

            jsonObject.put("tempImageFileName", tempImageFileEntry.getTitle());

            JSONPortletResponseUtil.writeJSON(actionRequest, actionResponse, jsonObject);
        } else {
            FileEntry fileEntry = null;

            boolean imageUploaded = ParamUtil.getBoolean(actionRequest, "imageUploaded");

            if (imageUploaded) {
                fileEntry = saveTempImageFileEntry(actionRequest);

                if (fileEntry.getSize() > maxFileSize) {
                    throw new FileSizeException();
                }
            }

            SessionMessages.add(actionRequest, "imageUploaded", fileEntry);

            sendRedirect(actionRequest, actionResponse);
        }
    } catch (Exception e) {
        handleUploadException(actionRequest, actionResponse, cmd, maxFileSize, e);
    }
}

From source file:com.liferay.journal.web.internal.portlet.JournalPortlet.java

License:Open Source License

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

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

    PortalPreferences portalPreferences = PortletPreferencesFactoryUtil.getPortalPreferences(actionRequest);

    String key = JournalPortletUtil.getAddMenuFavItemKey(actionRequest, actionResponse);

    String[] addMenuFavItems = portalPreferences.getValues(JournalPortletKeys.JOURNAL, key, new String[0]);

    if (addMenuFavItems.length >= _journalWebConfiguration.maxAddMenuItems()) {

        hideDefaultErrorMessage(actionRequest);

        throw new MaxAddMenuFavItemsException();
    }//  ww w.  ja  v  a  2  s .  com

    portalPreferences.setValues(JournalPortletKeys.JOURNAL, key,
            ArrayUtil.append(addMenuFavItems, ddmStructureKey));

    SessionMessages.add(actionRequest,
            _portal.getPortletId(actionRequest) + SessionMessages.KEY_SUFFIX_REFRESH_PORTLET,
            JournalPortletKeys.JOURNAL);
}

From source file:com.liferay.journal.web.internal.portlet.JournalPortlet.java

License:Open Source License

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

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

    PortalPreferences portalPreferences = PortletPreferencesFactoryUtil.getPortalPreferences(actionRequest);

    String key = JournalPortletUtil.getAddMenuFavItemKey(actionRequest, actionResponse);

    String[] addMenuFavItems = portalPreferences.getValues(JournalPortletKeys.JOURNAL, key);

    portalPreferences.setValues(JournalPortletKeys.JOURNAL, key,
            ArrayUtil.remove(addMenuFavItems, ddmStructureKey));

    SessionMessages.add(actionRequest,
            _portal.getPortletId(actionRequest) + SessionMessages.KEY_SUFFIX_REFRESH_PORTLET,
            JournalPortletKeys.JOURNAL);
}

From source file:com.liferay.login.web.internal.portlet.action.CreateAccountMVCActionCommand.java

License:Open Source License

protected void addUser(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception {

    HttpServletRequest request = _portal.getHttpServletRequest(actionRequest);

    HttpSession session = request.getSession();

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

    Company company = themeDisplay.getCompany();

    boolean autoPassword = true;
    String password1 = null;/*from   w  w  w.  j av  a  2s  . co  m*/
    String password2 = null;
    boolean autoScreenName = isAutoScreenName();
    String screenName = ParamUtil.getString(actionRequest, "screenName");
    String emailAddress = ParamUtil.getString(actionRequest, "emailAddress");
    long facebookId = ParamUtil.getLong(actionRequest, "facebookId");
    String openId = ParamUtil.getString(actionRequest, "openId");
    String languageId = ParamUtil.getString(actionRequest, "languageId");
    String firstName = ParamUtil.getString(actionRequest, "firstName");
    String middleName = ParamUtil.getString(actionRequest, "middleName");
    String lastName = ParamUtil.getString(actionRequest, "lastName");
    long prefixId = ParamUtil.getInteger(actionRequest, "prefixId");
    long suffixId = ParamUtil.getInteger(actionRequest, "suffixId");
    boolean male = ParamUtil.getBoolean(actionRequest, "male", true);
    int birthdayMonth = ParamUtil.getInteger(actionRequest, "birthdayMonth");
    int birthdayDay = ParamUtil.getInteger(actionRequest, "birthdayDay");
    int birthdayYear = ParamUtil.getInteger(actionRequest, "birthdayYear");
    String jobTitle = ParamUtil.getString(actionRequest, "jobTitle");
    long[] groupIds = null;
    long[] organizationIds = null;
    long[] roleIds = null;
    long[] userGroupIds = null;
    boolean sendEmail = true;

    ServiceContext serviceContext = ServiceContextFactory.getInstance(User.class.getName(), actionRequest);

    if (PropsValues.LOGIN_CREATE_ACCOUNT_ALLOW_CUSTOM_PASSWORD) {
        autoPassword = false;

        password1 = ParamUtil.getString(actionRequest, "password1");
        password2 = ParamUtil.getString(actionRequest, "password2");
    }

    boolean openIdPending = false;

    Boolean openIdLoginPending = (Boolean) session.getAttribute(WebKeys.OPEN_ID_LOGIN_PENDING);

    if ((openIdLoginPending != null) && openIdLoginPending.booleanValue() && Validator.isNotNull(openId)) {

        sendEmail = false;
        openIdPending = true;
    }

    User user = _userService.addUserWithWorkflow(company.getCompanyId(), autoPassword, password1, password2,
            autoScreenName, screenName, emailAddress, facebookId, openId, LocaleUtil.fromLanguageId(languageId),
            firstName, middleName, lastName, prefixId, suffixId, male, birthdayMonth, birthdayDay, birthdayYear,
            jobTitle, groupIds, organizationIds, roleIds, userGroupIds, sendEmail, serviceContext);

    if (openIdPending) {
        session.setAttribute(WebKeys.OPEN_ID_LOGIN, Long.valueOf(user.getUserId()));

        session.removeAttribute(WebKeys.OPEN_ID_LOGIN_PENDING);
    } else {

        // Session messages

        if (user.getStatus() == WorkflowConstants.STATUS_APPROVED) {
            SessionMessages.add(request, "userAdded", user.getEmailAddress());
            SessionMessages.add(request, "userAddedPassword", user.getPasswordUnencrypted());
        } else {
            SessionMessages.add(request, "userPending", user.getEmailAddress());
        }
    }

    // Send redirect

    sendRedirect(actionRequest, actionResponse, themeDisplay, user, user.getPasswordUnencrypted());
}

From source file:com.liferay.login.web.internal.portlet.action.CreateAccountMVCActionCommand.java

License:Open Source License

protected void updateIncompleteUser(ActionRequest actionRequest, ActionResponse actionResponse)
        throws Exception {

    HttpServletRequest request = _portal
            .getOriginalServletRequest(_portal.getHttpServletRequest(actionRequest));

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

    boolean autoPassword = true;
    String password1 = null;//from w  w w .ja v a  2s  .c  o  m
    String password2 = null;
    boolean autoScreenName = false;
    String screenName = ParamUtil.getString(actionRequest, "screenName");
    String emailAddress = ParamUtil.getString(actionRequest, "emailAddress");

    HttpSession session = request.getSession();

    long facebookId = GetterUtil.getLong(session.getAttribute(WebKeys.FACEBOOK_INCOMPLETE_USER_ID));
    String googleUserId = GetterUtil.getString(session.getAttribute(WebKeys.GOOGLE_INCOMPLETE_USER_ID));

    if (Validator.isNotNull(googleUserId)) {
        autoPassword = false;
    }

    if ((facebookId > 0) || Validator.isNotNull(googleUserId)) {
        password1 = PwdGenerator.getPassword();

        password2 = password1;
    }

    String openId = ParamUtil.getString(actionRequest, "openId");
    String firstName = ParamUtil.getString(actionRequest, "firstName");
    String middleName = ParamUtil.getString(actionRequest, "middleName");
    String lastName = ParamUtil.getString(actionRequest, "lastName");
    long prefixId = ParamUtil.getInteger(actionRequest, "prefixId");
    long suffixId = ParamUtil.getInteger(actionRequest, "suffixId");
    boolean male = ParamUtil.getBoolean(actionRequest, "male", true);
    int birthdayMonth = ParamUtil.getInteger(actionRequest, "birthdayMonth");
    int birthdayDay = ParamUtil.getInteger(actionRequest, "birthdayDay");
    int birthdayYear = ParamUtil.getInteger(actionRequest, "birthdayYear");
    String jobTitle = ParamUtil.getString(actionRequest, "jobTitle");
    boolean updateUserInformation = true;

    boolean sendEmail = true;

    if (Validator.isNotNull(googleUserId)) {
        sendEmail = false;
    }

    ServiceContext serviceContext = ServiceContextFactory.getInstance(User.class.getName(), actionRequest);

    User user = _userService.updateIncompleteUser(themeDisplay.getCompanyId(), autoPassword, password1,
            password2, autoScreenName, screenName, emailAddress, facebookId, openId, themeDisplay.getLocale(),
            firstName, middleName, lastName, prefixId, suffixId, male, birthdayMonth, birthdayDay, birthdayYear,
            jobTitle, updateUserInformation, sendEmail, serviceContext);

    if (facebookId > 0) {
        session.removeAttribute(WebKeys.FACEBOOK_INCOMPLETE_USER_ID);

        updateUserAndSendRedirect(actionRequest, actionResponse, themeDisplay, user, password1);

        return;
    }

    if (Validator.isNotNull(googleUserId)) {
        _userLocalService.updateGoogleUserId(user.getUserId(), googleUserId);

        session.removeAttribute(WebKeys.GOOGLE_INCOMPLETE_USER_ID);

        updateUserAndSendRedirect(actionRequest, actionResponse, themeDisplay, user, password1);

        return;
    }

    // Session messages

    if (user.getStatus() == WorkflowConstants.STATUS_APPROVED) {
        SessionMessages.add(request, "userAdded", user.getEmailAddress());
        SessionMessages.add(request, "userAddedPassword", user.getPasswordUnencrypted());
    } else {
        SessionMessages.add(request, "userPending", user.getEmailAddress());
    }

    // Send redirect

    sendRedirect(actionRequest, actionResponse, themeDisplay, user, user.getPasswordUnencrypted());
}

From source file:com.liferay.login.web.internal.portlet.action.CreateAnonymousAccountMVCActionCommand.java

License:Open Source License

protected void addAnonymousUser(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception {

    HttpServletRequest request = _portal.getHttpServletRequest(actionRequest);

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

    boolean autoPassword = true;
    String password1 = null;//from w ww  . j  a v a 2s. c  om
    String password2 = null;
    boolean autoScreenName = true;
    String screenName = null;
    String emailAddress = ParamUtil.getString(actionRequest, "emailAddress");
    long facebookId = 0;
    String openId = StringPool.BLANK;
    String firstName = ParamUtil.getString(actionRequest, "firstName");
    String lastName = ParamUtil.getString(actionRequest, "lastName");
    long prefixId = 0;
    long suffixId = 0;
    boolean male = true;
    int birthdayMonth = 0;
    int birthdayDay = 1;
    int birthdayYear = 1970;
    String jobTitle = null;
    long[] groupIds = null;
    long[] organizationIds = null;
    long[] roleIds = null;
    long[] userGroupIds = null;
    boolean sendEmail = false;

    ServiceContext serviceContext = ServiceContextFactory.getInstance(User.class.getName(), actionRequest);

    serviceContext.setAttribute("anonymousUser", Boolean.TRUE);

    CaptchaConfiguration captchaConfiguration = getCaptchaConfiguration();

    if (captchaConfiguration.createAccountCaptchaEnabled()) {
        CaptchaUtil.check(actionRequest);
    }

    serviceContext.setWorkflowAction(WorkflowConstants.ACTION_SAVE_DRAFT);

    User user = _userService.addUser(themeDisplay.getCompanyId(), autoPassword, password1, password2,
            autoScreenName, screenName, emailAddress, facebookId, openId, themeDisplay.getLocale(), firstName,
            null, lastName, prefixId, suffixId, male, birthdayMonth, birthdayDay, birthdayYear, jobTitle,
            groupIds, organizationIds, roleIds, userGroupIds, sendEmail, serviceContext);

    _userLocalService.updateStatus(user.getUserId(), WorkflowConstants.STATUS_INCOMPLETE, new ServiceContext());

    // Session messages

    SessionMessages.add(request, "userAdded", user.getEmailAddress());
    SessionMessages.add(request, "userAddedPassword", user.getPasswordUnencrypted());
}

From source file:com.liferay.notifications.web.internal.portlet.NotificationsPortlet.java

License:Open Source License

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

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

    boolean actionRequired = ParamUtil.getBoolean(actionRequest, "actionRequired");

    _userNotificationEventLocalService.archiveUserNotificationEvents(themeDisplay.getUserId(),
            UserNotificationDeliveryConstants.TYPE_WEBSITE, actionRequired);

    ResourceBundle resourceBundle = _resourceBundleLoader.loadResourceBundle(themeDisplay.getLocale());

    SessionMessages.add(actionRequest, "requestProcessed",
            LanguageUtil.get(resourceBundle, "all-notifications-were-marked-as-read-successfully"));

    _sendRedirect(actionRequest, actionResponse);
}

From source file:com.liferay.notifications.web.internal.portlet.NotificationsPortlet.java

License:Open Source License

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

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

    long[] userNotificationDeliveryIds = ParamUtil.getLongValues(actionRequest, "userNotificationDeliveryIds");

    for (long userNotificationDeliveryId : userNotificationDeliveryIds) {
        boolean deliver = ParamUtil.getBoolean(actionRequest, String.valueOf(userNotificationDeliveryId));

        _userNotificationDeliveryLocalService.updateUserNotificationDelivery(userNotificationDeliveryId,
                deliver);//w w w  .  j a va2  s  .com
    }

    ResourceBundle resourceBundle = _resourceBundleLoader.loadResourceBundle(themeDisplay.getLocale());

    SessionMessages.add(actionRequest, "requestProcessed",
            LanguageUtil.get(resourceBundle, "your-configuration-was-saved-sucessfully"));

    _sendRedirect(actionRequest, actionResponse);
}