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

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

Introduction

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

Prototype

public static void add(PortletRequest portletRequest, String key) 

Source Link

Usage

From source file:com.liferay.portlet.usersadmin.action.EditOrganizationAction.java

License:Open Source License

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

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

    try {/*  w w w .  ja va 2s  .  c  o m*/
        Organization organization = null;

        if (cmd.equals(Constants.ADD) || cmd.equals(Constants.UPDATE)) {
            organization = updateOrganization(actionRequest);
        } else if (cmd.equals(Constants.DELETE)) {
            deleteOrganizations(actionRequest);
        }

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

        if (organization != null) {
            redirect = HttpUtil.setParameter(redirect, actionResponse.getNamespace() + "organizationId",
                    organization.getOrganizationId());
        }

        sendRedirect(actionRequest, actionResponse, redirect);
    } catch (Exception e) {
        if (e instanceof NoSuchOrganizationException || e instanceof PrincipalException) {

            SessionErrors.add(actionRequest, e.getClass().getName());

            setForward(actionRequest, "portlet.users_admin.error");
        } else if (e instanceof AddressCityException || e instanceof AddressStreetException
                || e instanceof AddressZipException || e instanceof DuplicateOrganizationException
                || e instanceof EmailAddressException || e instanceof NoSuchCountryException
                || e instanceof NoSuchListTypeException || e instanceof NoSuchRegionException
                || e instanceof OrganizationNameException || e instanceof OrganizationParentException
                || e instanceof PhoneNumberException || e instanceof RequiredOrganizationException
                || e instanceof WebsiteURLException) {

            if (e instanceof NoSuchListTypeException) {
                NoSuchListTypeException nslte = (NoSuchListTypeException) e;

                SessionErrors.add(actionRequest, e.getClass().getName() + nslte.getType());
            } else {
                SessionErrors.add(actionRequest, e.getClass().getName());
            }

            if (e instanceof RequiredOrganizationException) {
                String redirect = PortalUtil.escapeRedirect(ParamUtil.getString(actionRequest, "redirect"));

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

                if (organizationId > 0) {
                    redirect = HttpUtil.setParameter(redirect, actionResponse.getNamespace() + "organizationId",
                            organizationId);
                }

                if (Validator.isNotNull(redirect)) {
                    actionResponse.sendRedirect(redirect);
                }
            }
        } else {
            throw e;
        }
    }
}

From source file:com.liferay.portlet.usersadmin.action.EditOrganizationAction.java

License:Open Source License

@Override
public ActionForward render(ActionMapping mapping, ActionForm form, PortletConfig portletConfig,
        RenderRequest renderRequest, RenderResponse renderResponse) throws Exception {

    try {//from  ww w  .  j av  a  2  s. c o  m
        ActionUtil.getOrganization(renderRequest);
    } catch (Exception e) {
        if (e instanceof NoSuchOrganizationException || e instanceof PrincipalException) {

            SessionErrors.add(renderRequest, e.getClass().getName());

            return mapping.findForward("portlet.users_admin.error");
        } else {
            throw e;
        }
    }

    return mapping.findForward(getForward(renderRequest, "portlet.users_admin.edit_organization"));
}

From source file:com.liferay.portlet.usersadmin.action.EditOrganizationAssignmentsAction.java

License:Open Source License

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

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

    try {//  w  ww.  j  a v a2s. c om
        if (cmd.equals("organization_user_groups")) {
            updateOrganizationUserGroups(actionRequest);
        } else if (cmd.equals("organization_users")) {
            updateOrganizationUsers(actionRequest);
        }

        if (Validator.isNotNull(cmd)) {
            String redirect = ParamUtil.getString(actionRequest, "assignmentsRedirect");

            sendRedirect(actionRequest, actionResponse, redirect);
        }
    } catch (Exception e) {
        if (e instanceof NoSuchOrganizationException || e instanceof PrincipalException) {

            SessionErrors.add(actionRequest, e.getClass().getName());

            setForward(actionRequest, "portlet.users_admin.error");
        } else {
            throw e;
        }
    }
}

From source file:com.liferay.portlet.usersadmin.action.EditOrganizationAssignmentsAction.java

License:Open Source License

@Override
public ActionForward render(ActionMapping mapping, ActionForm form, PortletConfig portletConfig,
        RenderRequest renderRequest, RenderResponse renderResponse) throws Exception {

    try {/*w  w  w. j a  v a 2s .c o m*/
        ActionUtil.getOrganization(renderRequest);
    } catch (Exception e) {
        if (e instanceof NoSuchOrganizationException || e instanceof PrincipalException) {

            SessionErrors.add(renderRequest, e.getClass().getName());

            return mapping.findForward("portlet.users_admin.error");
        } else {
            throw e;
        }
    }

    return mapping.findForward(getForward(renderRequest, "portlet.users_admin.edit_organization_assignments"));
}

From source file:com.liferay.portlet.usersadmin.action.EditOrganizationLogoAction.java

License:Open Source License

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

    try {//from  www  .j av a 2 s.  co m
        updateLogo(actionRequest);

        sendRedirect(actionRequest, actionResponse);
    } catch (Exception e) {
        if (e instanceof ImageTypeException || e instanceof NoSuchOrganizationException
                || e instanceof PrincipalException) {

            SessionErrors.add(actionRequest, e.getClass().getName());

            setForward(actionRequest, "portlet.users_admin.error");
        } else if (e instanceof UploadException) {

            SessionErrors.add(actionRequest, e.getClass().getName());
        } else {
            throw e;
        }
    }
}

From source file:com.liferay.portlet.usersadmin.action.EditOrgLaborAction.java

License:Open Source License

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

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

    try {/*  www  . j a  va  2  s.  co m*/
        if (cmd.equals(Constants.ADD) || cmd.equals(Constants.UPDATE)) {
            updateOrgLabor(actionRequest);
        } else if (cmd.equals(Constants.DELETE)) {
            deleteOrgLabor(actionRequest);
        }

        sendRedirect(actionRequest, actionResponse);
    } catch (Exception e) {
        if (e instanceof NoSuchOrgLaborException || e instanceof PrincipalException) {

            SessionErrors.add(actionRequest, e.getClass().getName());

            setForward(actionRequest, "portlet.users_admin.error");
        } else if (e instanceof NoSuchListTypeException) {
            SessionErrors.add(actionRequest, e.getClass().getName());
        } else {
            throw e;
        }
    }
}

From source file:com.liferay.portlet.usersadmin.action.EditOrgLaborAction.java

License:Open Source License

@Override
public ActionForward render(ActionMapping mapping, ActionForm form, PortletConfig portletConfig,
        RenderRequest renderRequest, RenderResponse renderResponse) throws Exception {

    try {// www.  j av  a 2  s . c o m
        ActionUtil.getOrgLabor(renderRequest);
    } catch (Exception e) {
        if (e instanceof NoSuchOrgLaborException || e instanceof PrincipalException) {

            SessionErrors.add(renderRequest, e.getClass().getName());

            return mapping.findForward("portlet.users_admin.error");
        } else {
            throw e;
        }
    }

    return mapping.findForward(getForward(renderRequest, "portlet.users_admin.edit_org_labor"));
}

From source file:com.liferay.portlet.usersadmin.action.EditUserAction.java

License:Open Source License

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

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

    try {//ww w.j av  a  2s .c  o m
        User user = null;
        String oldScreenName = StringPool.BLANK;
        String oldLanguageId = StringPool.BLANK;

        if (cmd.equals(Constants.ADD)) {
            user = addUser(actionRequest);
        } else if (cmd.equals(Constants.DEACTIVATE) || cmd.equals(Constants.DELETE)
                || cmd.equals(Constants.RESTORE)) {

            deleteUsers(actionRequest);
        } else if (cmd.equals("deleteRole")) {
            deleteRole(actionRequest);
        } else if (cmd.equals(Constants.UPDATE)) {
            Object[] returnValue = updateUser(actionRequest, actionResponse);

            user = (User) returnValue[0];
            oldScreenName = ((String) returnValue[1]);
            oldLanguageId = ((String) returnValue[2]);
        } else if (cmd.equals("unlock")) {
            user = updateLockout(actionRequest);
        }

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

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

        if (user != null) {
            if (Validator.isNotNull(oldScreenName)) {

                // This will fix the redirect if the user is on his personal
                // my account page and changes his screen name. A redirect
                // that references the old screen name no longer points to a
                // valid screen name and therefore needs to be updated.

                Group group = user.getGroup();

                if (group.getGroupId() == themeDisplay.getScopeGroupId()) {
                    Layout layout = themeDisplay.getLayout();

                    String friendlyURLPath = group.getPathFriendlyURL(layout.isPrivateLayout(), themeDisplay);

                    String oldPath = friendlyURLPath + StringPool.SLASH + oldScreenName;
                    String newPath = friendlyURLPath + StringPool.SLASH + user.getScreenName();

                    redirect = StringUtil.replace(redirect, oldPath, newPath);

                    redirect = StringUtil.replace(redirect, HttpUtil.encodeURL(oldPath),
                            HttpUtil.encodeURL(newPath));
                }
            }

            if (Validator.isNotNull(oldLanguageId) && themeDisplay.isI18n()) {

                String i18nLanguageId = user.getLanguageId();
                int pos = i18nLanguageId.indexOf(CharPool.UNDERLINE);

                if (pos != -1) {
                    i18nLanguageId = i18nLanguageId.substring(0, pos);
                }

                String i18nPath = StringPool.SLASH + i18nLanguageId;

                redirect = StringUtil.replace(redirect, themeDisplay.getI18nPath(), i18nPath);
            }

            redirect = HttpUtil.setParameter(redirect, actionResponse.getNamespace() + "p_u_i_d",
                    user.getUserId());
        }

        Group scopeGroup = themeDisplay.getScopeGroup();

        if (scopeGroup.isUser()) {
            try {
                UserLocalServiceUtil.getUserById(scopeGroup.getClassPK());
            } catch (NoSuchUserException nsue) {
                redirect = HttpUtil.setParameter(redirect, "doAsGroupId", 0);
                redirect = HttpUtil.setParameter(redirect, "refererPlid", 0);
            }
        }

        sendRedirect(actionRequest, actionResponse, redirect);
    } catch (Exception e) {
        if (e instanceof NoSuchUserException || e instanceof PrincipalException) {

            SessionErrors.add(actionRequest, e.getClass().getName());

            setForward(actionRequest, "portlet.users_admin.error");
        } else if (e instanceof AddressCityException || e instanceof AddressStreetException
                || e instanceof AddressZipException || e instanceof CompanyMaxUsersException
                || e instanceof ContactBirthdayException || e instanceof ContactFirstNameException
                || e instanceof ContactFullNameException || e instanceof ContactLastNameException
                || e instanceof DuplicateUserEmailAddressException
                || e instanceof DuplicateUserScreenNameException || e instanceof EmailAddressException
                || e instanceof GroupFriendlyURLException || e instanceof NoSuchCountryException
                || e instanceof NoSuchListTypeException || e instanceof NoSuchRegionException
                || e instanceof PhoneNumberException || e instanceof RequiredUserException
                || e instanceof ReservedUserEmailAddressException
                || e instanceof ReservedUserScreenNameException || e instanceof UserEmailAddressException
                || e instanceof UserIdException || e instanceof UserPasswordException
                || e instanceof UserReminderQueryException || e instanceof UserScreenNameException
                || e instanceof UserSmsException || e instanceof WebsiteURLException) {

            if (e instanceof NoSuchListTypeException) {
                NoSuchListTypeException nslte = (NoSuchListTypeException) e;

                SessionErrors.add(actionRequest, e.getClass().getName() + nslte.getType());
            } else {
                SessionErrors.add(actionRequest, e.getClass().getName(), e);
            }

            if (e instanceof RequiredUserException) {
                String redirect = PortalUtil.escapeRedirect(ParamUtil.getString(actionRequest, "redirect"));

                if (Validator.isNotNull(redirect)) {
                    actionResponse.sendRedirect(redirect);
                }
            }
        } else {
            throw e;
        }
    }
}

From source file:com.liferay.portlet.usersadmin.action.EditUserAction.java

License:Open Source License

@Override
public ActionForward render(ActionMapping mapping, ActionForm form, PortletConfig portletConfig,
        RenderRequest renderRequest, RenderResponse renderResponse) throws Exception {

    try {//  www.j  av a2  s. com
        PortalUtil.getSelectedUser(renderRequest);
    } catch (Exception e) {
        if (e instanceof PrincipalException) {
            SessionErrors.add(renderRequest, e.getClass().getName());

            return mapping.findForward("portlet.users_admin.error");
        } else {
            throw e;
        }
    }

    return mapping.findForward(getForward(renderRequest, "portlet.users_admin.edit_user"));
}

From source file:com.liferay.portlet.usersadmin.action.EditUserPortraitAction.java

License:Open Source License

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

    try {//  w  w  w .  j  av  a2  s. c o m
        updatePortrait(actionRequest);

        sendRedirect(actionRequest, actionResponse);
    } catch (Exception e) {
        if (e instanceof NoSuchUserException || e instanceof PrincipalException) {

            SessionErrors.add(actionRequest, e.getClass().getName());

            setForward(actionRequest, "portlet.users_admin.error");
        } else if (e instanceof UploadException || e instanceof UserPortraitSizeException
                || e instanceof UserPortraitTypeException) {

            SessionErrors.add(actionRequest, e.getClass().getName());
        } else {
            throw e;
        }
    }
}