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

Source Link

Usage

From source file:com.abubusoft.liferay.linkedin.CreateAccountAction.java

License:Open Source License

public void processAction(StrutsPortletAction originalStrutsPortletAction, PortletConfig portletConfig,
        ActionRequest actionRequest, ActionResponse actionResponse) throws Exception {
    HttpServletRequest request = PortalUtil.getHttpServletRequest(actionRequest);
    HttpSession session = request.getSession();

    Boolean linkedinLoginPending = (Boolean) session.getAttribute(LinkedinConstants.LINKEDIN_LOGIN_PENDING);

    if ((linkedinLoginPending != null) && linkedinLoginPending.booleanValue()) {
        ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);

        Company company = themeDisplay.getCompany();

        if (!company.isStrangers()) {
            throw new PrincipalException();
        }/* ww w .j  ava2 s.c o  m*/

        try {
            addUser(actionRequest, actionResponse);
        } catch (Exception e) {
            if (e instanceof DuplicateUserEmailAddressException || e instanceof DuplicateUserScreenNameException
                    || e instanceof AddressCityException || e instanceof AddressStreetException
                    || e instanceof AddressZipException || e instanceof CaptchaMaxChallengesException
                    || e instanceof CaptchaTextException || e instanceof CompanyMaxUsersException
                    || e instanceof ContactFirstNameException || e instanceof ContactFullNameException
                    || e instanceof ContactLastNameException || e instanceof EmailAddressException
                    || e instanceof GroupFriendlyURLException || e instanceof NoSuchCountryException
                    || e instanceof NoSuchListTypeException || e instanceof NoSuchOrganizationException
                    || e instanceof NoSuchRegionException || e instanceof OrganizationParentException
                    || e instanceof PhoneNumberException || e instanceof RequiredFieldException
                    || e instanceof RequiredUserException || e instanceof ReservedUserEmailAddressException
                    || e instanceof ReservedUserScreenNameException || e instanceof TermsOfUseException
                    || e instanceof UserEmailAddressException || e instanceof UserIdException
                    || e instanceof UserPasswordException || e instanceof UserScreenNameException
                    || e instanceof UserSmsException || e instanceof WebsiteURLException) {

                SessionErrors.add(actionRequest, e.getClass(), e);
            } else {
                throw e;
            }
        }
    } else {
        originalStrutsPortletAction.processAction(originalStrutsPortletAction, portletConfig, actionRequest,
                actionResponse);
    }
}

From source file:com.abubusoft.liferay.twitter.CreateAccountAction.java

License:Open Source License

public void processAction(StrutsPortletAction originalStrutsPortletAction, PortletConfig portletConfig,
        ActionRequest actionRequest, ActionResponse actionResponse) throws Exception {
    HttpServletRequest request = PortalUtil.getHttpServletRequest(actionRequest);
    HttpSession session = request.getSession();

    Boolean twitterLoginPending = (Boolean) session.getAttribute(TwitterConstants.TWITTER_LOGIN_PENDING);

    if ((twitterLoginPending != null) && twitterLoginPending.booleanValue()) {
        ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);

        Company company = themeDisplay.getCompany();

        if (!company.isStrangers()) {
            throw new PrincipalException();
        }/*from  www . j a v a2  s  .c  om*/

        try {
            addUser(actionRequest, actionResponse);
        } catch (Exception e) {
            if (e instanceof DuplicateUserEmailAddressException || e instanceof DuplicateUserScreenNameException
                    || e instanceof AddressCityException || e instanceof AddressStreetException
                    || e instanceof AddressZipException || e instanceof CaptchaMaxChallengesException
                    || e instanceof CaptchaTextException || e instanceof CompanyMaxUsersException
                    || e instanceof ContactFirstNameException || e instanceof ContactFullNameException
                    || e instanceof ContactLastNameException || e instanceof EmailAddressException
                    || e instanceof GroupFriendlyURLException || e instanceof NoSuchCountryException
                    || e instanceof NoSuchListTypeException || e instanceof NoSuchOrganizationException
                    || e instanceof NoSuchRegionException || e instanceof OrganizationParentException
                    || e instanceof PhoneNumberException || e instanceof RequiredFieldException
                    || e instanceof RequiredUserException || e instanceof ReservedUserEmailAddressException
                    || e instanceof ReservedUserScreenNameException || e instanceof TermsOfUseException
                    || e instanceof UserEmailAddressException || e instanceof UserIdException
                    || e instanceof UserPasswordException || e instanceof UserScreenNameException
                    || e instanceof UserSmsException || e instanceof WebsiteURLException) {

                SessionErrors.add(actionRequest, e.getClass(), e);
            } else {
                throw e;
            }
        }
    } else {
        originalStrutsPortletAction.processAction(originalStrutsPortletAction, portletConfig, actionRequest,
                actionResponse);
    }
}

From source file:com.beorn.demopaymentplugin.portlet.PaymentPluginPortlet.java

License:Open Source License

public void completePayment(ActionRequest actionRequest, ActionResponse actionResponse)
        throws IOException, PortletException {

    try {/* w  w w .j av a 2  s .co  m*/
        long transactionId = ParamUtil.getLong(actionRequest, "transactionId");
        double amountPaid = ParamUtil.getDouble(actionRequest, "amountPaid");
        String successUrl = ParamUtil.getString(actionRequest, "successUrl");
        String errorUrl = ParamUtil.getString(actionRequest, "errorUrl");

        PaymentPluginSender paymentPluginSender = PaymentPluginUtil.getPaymentPluginSender();

        try {
            // XXX A real payment plugin would use a unique id for this
            // payment, coming from the remote platform where the payment
            // happened
            String remoteId = String.valueOf(transactionId);

            paymentPluginSender.addPayment(transactionId, remoteId, amountPaid);
            actionResponse.sendRedirect(successUrl);

        } catch (Exception e) {
            actionResponse.sendRedirect(errorUrl);

        }
        actionResponse.sendRedirect(successUrl);

    } catch (Exception e) {
        _log.error(e);
        actionResponse.setRenderParameters(actionRequest.getParameterMap());
        SessionErrors.add(actionRequest, e.getClass().getName(), e);
    }
}

From source file:com.evozon.evoportal.my_account.validator.UserAccountValidation.java

private boolean isCNPDuplicate(ActionRequest actionRequest) {
    boolean isValid = true;
    try {//from w  w  w.  j a v  a2s  . c  om
        User selectedUser = PortalUtil.getSelectedUser(actionRequest);

        if (selectedUser != null) {

            String oldCNP = new UserExpandoWrapper(selectedUser).getPersonalIdentificationNumber();
            String newCNP = ParamUtil.getString(actionRequest, MyAccountConstants.USER_CNP);

            if (!oldCNP.equals(newCNP)) {
                // only if CNP was changed
                long userIdCNP = PortalUtil.getUserId(actionRequest);
                List<String> usersWithSameCNP = getUsersWithCNP(newCNP, userIdCNP);
                if (!usersWithSameCNP.isEmpty()) {
                    String errMsg = "The following users have the same CNP: " + usersWithSameCNP.toString();

                    SessionErrors.add(actionRequest, "duplicate-cnp", errMsg);
                    isValid = false;
                }

            }
        }
    } catch (PortalException e) {
        logger.error(e.getMessage(), e);
    } catch (SystemException e) {
        logger.error(e.getMessage(), e);
    }

    return isValid;
}

From source file:com.liferay.asset.publisher.web.portlet.action.AssetPublisherConfigurationAction.java

License:Open Source License

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

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

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

    PortletPreferences preferences = actionRequest.getPreferences();

    if (cmd.equals(Constants.TRANSLATE)) {
        super.processAction(portletConfig, actionRequest, actionResponse);
    } else if (cmd.equals(Constants.UPDATE)) {
        try {//from  www.  j a v a2s.c  o  m
            HttpServletRequest request = portal.getHttpServletRequest(actionRequest);

            AssetPublisherPortletInstanceConfiguration assetPublisherPortletInstanceConfiguration = _getAssetPublisherPortletInstanceConfiguration(
                    request);

            boolean emailAssetEntryAddedEnabled = GetterUtil.getBoolean(
                    getParameter(actionRequest, "emailAssetEntryAddedEnabled"),
                    assetPublisherPortletInstanceConfiguration.emailAssetEntryAddedEnabled());

            if (emailAssetEntryAddedEnabled) {
                validateEmail(actionRequest, "emailAssetEntryAdded");
                validateEmailFrom(actionRequest);
            }

            updateDisplaySettings(actionRequest);

            String selectionStyle = getParameter(actionRequest, "selectionStyle");

            if (selectionStyle.equals("dynamic")) {
                updateQueryLogic(actionRequest, preferences);
            }

            updateDefaultAssetPublisher(actionRequest);

            super.processAction(portletConfig, actionRequest, actionResponse);
        } catch (Exception e) {
            if (e instanceof AssetTagException || e instanceof DuplicateQueryRuleException) {

                SessionErrors.add(actionRequest, e.getClass(), e);
            } else {
                throw e;
            }
        }
    } else {
        if (cmd.equals("add-scope")) {
            addScope(actionRequest, preferences);
        } else if (cmd.equals("add-selection")) {
            assetPublisherWebUtil.addSelection(actionRequest, preferences);
        } else if (cmd.equals("move-selection-down")) {
            moveSelectionDown(actionRequest, preferences);
        } else if (cmd.equals("move-selection-up")) {
            moveSelectionUp(actionRequest, preferences);
        } else if (cmd.equals("remove-selection")) {
            removeSelection(actionRequest, preferences);
        } else if (cmd.equals("remove-scope")) {
            removeScope(actionRequest, preferences);
        } else if (cmd.equals("select-scope")) {
            setScopes(actionRequest, preferences);
        } else if (cmd.equals("selection-style")) {
            setSelectionStyle(actionRequest, preferences);
        }

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

            SessionMessages.add(actionRequest,
                    portal.getPortletId(actionRequest) + SessionMessages.KEY_SUFFIX_REFRESH_PORTLET,
                    portletResource);

            SessionMessages.add(actionRequest,
                    portal.getPortletId(actionRequest) + SessionMessages.KEY_SUFFIX_UPDATED_CONFIGURATION);
        }

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

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

From source file:com.liferay.blogs.web.internal.portlet.action.EditEntryMVCActionCommand.java

License:Open Source License

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

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

    try {/*from   w  w w  .j av a 2  s . c  o  m*/
        BlogsEntry entry = null;
        List<BlogsEntryAttachmentFileEntryReference> blogsEntryAttachmentFileEntryReferences = null;

        UploadException uploadException = (UploadException) actionRequest
                .getAttribute(WebKeys.UPLOAD_EXCEPTION);

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

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

            if (uploadException.isExceededLiferayFileItemSizeLimit()) {
                throw new LiferayFileItemException(cause);
            }

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

            throw new PortalException(cause);
        } else if (cmd.equals(Constants.ADD) || cmd.equals(Constants.UPDATE)) {

            Callable<Object[]> updateEntryCallable = new UpdateEntryCallable(actionRequest);

            Object[] returnValue = TransactionInvokerUtil.invoke(_transactionConfig, updateEntryCallable);

            entry = (BlogsEntry) returnValue[0];
            blogsEntryAttachmentFileEntryReferences = (List<BlogsEntryAttachmentFileEntryReference>) returnValue[1];
        } else if (cmd.equals(Constants.DELETE)) {
            deleteEntries(actionRequest, false);
        } else if (cmd.equals(Constants.MOVE_TO_TRASH)) {
            deleteEntries(actionRequest, true);
        } else if (cmd.equals(Constants.RESTORE)) {
            restoreTrashEntries(actionRequest);
        } else if (cmd.equals(Constants.SUBSCRIBE)) {
            subscribe(actionRequest);
        } else if (cmd.equals(Constants.UNSUBSCRIBE)) {
            unsubscribe(actionRequest);
        }

        String redirect = ParamUtil.getString(actionRequest, "redirect");
        String portletId = HttpUtil.getParameter(redirect, "p_p_id", false);

        int workflowAction = ParamUtil.getInteger(actionRequest, "workflowAction",
                WorkflowConstants.ACTION_SAVE_DRAFT);

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

        if (ajax) {
            JSONObject jsonObject = JSONFactoryUtil.createJSONObject();

            JSONArray jsonArray = JSONFactoryUtil.createJSONArray();

            for (BlogsEntryAttachmentFileEntryReference blogsEntryAttachmentFileEntryReference : blogsEntryAttachmentFileEntryReferences) {

                JSONObject blogsEntryFileEntryReferencesJSONObject = JSONFactoryUtil.createJSONObject();

                blogsEntryFileEntryReferencesJSONObject.put("attributeDataImageId",
                        EditorConstants.ATTRIBUTE_DATA_IMAGE_ID);
                blogsEntryFileEntryReferencesJSONObject.put("fileEntryId", String.valueOf(
                        blogsEntryAttachmentFileEntryReference.getTempBlogsEntryAttachmentFileEntryId()));
                blogsEntryFileEntryReferencesJSONObject.put("fileEntryUrl",
                        PortletFileRepositoryUtil.getPortletFileEntryURL(null,
                                blogsEntryAttachmentFileEntryReference.getBlogsEntryAttachmentFileEntry(),
                                StringPool.BLANK));

                jsonArray.put(blogsEntryFileEntryReferencesJSONObject);
            }

            jsonObject.put("blogsEntryAttachmentReferences", jsonArray);
            jsonObject.put("coverImageFileEntryId", entry.getCoverImageFileEntryId());
            jsonObject.put("entryId", entry.getEntryId());
            jsonObject.put("redirect", redirect);

            JSONPortletResponseUtil.writeJSON(actionRequest, actionResponse, jsonObject);

            return;
        }

        if ((entry != null) && (workflowAction == WorkflowConstants.ACTION_SAVE_DRAFT)) {

            redirect = getSaveAndContinueRedirect(actionRequest, entry, redirect);

            sendRedirect(actionRequest, actionResponse, redirect);
        } else {
            WindowState windowState = actionRequest.getWindowState();

            if (!windowState.equals(LiferayWindowState.POP_UP)) {
                sendRedirect(actionRequest, actionResponse, redirect);
            } else {
                redirect = PortalUtil.escapeRedirect(redirect);

                if (Validator.isNotNull(redirect)) {
                    if (cmd.equals(Constants.ADD) && (entry != null)) {
                        String namespace = PortalUtil.getPortletNamespace(portletId);

                        redirect = HttpUtil.addParameter(redirect, namespace + "className",
                                BlogsEntry.class.getName());
                        redirect = HttpUtil.addParameter(redirect, namespace + "classPK", entry.getEntryId());
                    }

                    actionRequest.setAttribute(WebKeys.REDIRECT, redirect);
                }
            }
        }
    } catch (AssetCategoryException | AssetTagException e) {
        SessionErrors.add(actionRequest, e.getClass(), e);

        actionResponse.setRenderParameter("mvcRenderCommandName", "/blogs/edit_entry");

        hideDefaultSuccessMessage(actionRequest);
    } catch (EntryContentException | EntryCoverImageCropException | EntryDescriptionException
            | EntryDisplayDateException | EntrySmallImageNameException | EntrySmallImageScaleException
            | EntryTitleException | EntryUrlTitleException | FileSizeException | LiferayFileItemException
            | SanitizerException | UploadRequestSizeException e) {

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

        actionResponse.setRenderParameter("mvcRenderCommandName", "/blogs/edit_entry");

        hideDefaultSuccessMessage(actionRequest);
    } catch (NoSuchEntryException | PrincipalException e) {
        SessionErrors.add(actionRequest, e.getClass());

        actionResponse.setRenderParameter("mvcPath", "/blogs/error.jsp");

        hideDefaultSuccessMessage(actionRequest);
    } catch (Throwable t) {
        _log.error(t, t);

        actionResponse.setRenderParameter("mvcPath", "/blogs/error.jsp");

        hideDefaultSuccessMessage(actionRequest);
    }
}

From source file:com.liferay.configuration.admin.web.internal.portlet.action.BindConfigurationMVCActionCommand.java

License:Open Source License

@Override
public boolean processAction(ActionRequest actionRequest, ActionResponse actionResponse)
        throws PortletException {

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

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

    String pid = ParamUtil.getString(actionRequest, "pid", factoryPid);

    if (_log.isDebugEnabled()) {
        _log.debug("Binding attributes for service " + pid);
    }/*w  w  w . j  a  v a 2  s .c o  m*/

    ConfigurationModel configurationModel = null;

    Map<String, ConfigurationModel> configurationModels = _configurationModelRetriever
            .getConfigurationModels(themeDisplay.getLanguageId());

    if (Validator.isNotNull(factoryPid)) {
        configurationModel = configurationModels.get(factoryPid);
    } else {
        configurationModel = configurationModels.get(pid);
    }

    Configuration configuration = _configurationModelRetriever.getConfiguration(pid);

    ResourceBundleLoader resourceBundleLoader = _resourceBundleLoaderProvider
            .getResourceBundleLoader(configurationModel.getBundleSymbolicName());

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

    ConfigurationModelToDDMFormConverter configurationModelToDDMFormConverter = new ConfigurationModelToDDMFormConverter(
            configurationModel, themeDisplay.getLocale(), resourceBundle);

    DDMForm ddmForm = configurationModelToDDMFormConverter.getDDMForm();

    DDMFormValues ddmFormValues = getDDMFormValues(actionRequest, ddmForm);

    DDMFormValuesToPropertiesConverter ddmFormValuesToPropertiesConverter = new DDMFormValuesToPropertiesConverter(
            configurationModel, ddmFormValues, _jsonFactory, themeDisplay.getLocale());

    Dictionary<String, Object> properties = ddmFormValuesToPropertiesConverter.getProperties();

    properties.put(Constants.SERVICE_PID, pid);

    if (Validator.isNotNull(factoryPid)) {
        properties.put(ConfigurationAdmin.SERVICE_FACTORYPID, factoryPid);
    }

    try {
        configureTargetService(configurationModel, configuration, properties);
    } catch (ConfigurationModelListenerException cmle) {
        SessionErrors.add(actionRequest, ConfigurationModelListenerException.class, cmle);

        actionResponse.setRenderParameter("mvcRenderCommandName", "/edit_configuration");
    }

    return true;
}

From source file:com.liferay.content.targeting.portlet.ContentTargetingPortlet.java

License:Open Source License

public void deleteCampaign(ActionRequest request, ActionResponse response) throws Exception {

    try {//from  w ww.j  a v  a2 s.c o m
        long[] deleteCampaignsIds = null;

        long campaignId = ParamUtil.getLong(request, "campaignId");

        if (campaignId > 0) {
            deleteCampaignsIds = new long[] { campaignId };
        } else {
            deleteCampaignsIds = StringUtil.split(ParamUtil.getString(request, "campaignsIds"), 0L);
        }

        for (long deleteCampaignId : deleteCampaignsIds) {
            _campaignService.deleteCampaign(deleteCampaignId);
        }

        sendRedirect(request, response);
    } catch (Exception e) {
        SessionErrors.add(request, e.getClass().getName(), e);

        response.setRenderParameter("mvcPath", ContentTargetingPath.ERROR);
    }
}

From source file:com.liferay.content.targeting.portlet.ContentTargetingPortlet.java

License:Open Source License

public void deleteUserSegment(ActionRequest request, ActionResponse response) throws Exception {

    try {//from  w ww  .j  a v  a2s . c om
        long[] deleteUserSegmentIds = null;

        long userSegmentId = ParamUtil.getLong(request, "userSegmentId");

        if (userSegmentId > 0) {
            deleteUserSegmentIds = new long[] { userSegmentId };
        } else {
            deleteUserSegmentIds = StringUtil.split(ParamUtil.getString(request, "userSegmentIds"), 0L);
        }

        for (long deleteUserSegmentId : deleteUserSegmentIds) {
            _userSegmentService.deleteUserSegment(deleteUserSegmentId);
        }

        sendRedirect(request, response);
    } catch (Exception e) {
        SessionErrors.add(request, e.getClass().getName(), e);

        if (e instanceof UsedUserSegmentException) {
            SessionMessages.add(request,
                    PortalUtil.getPortletId(request) + SessionMessages.KEY_SUFFIX_HIDE_DEFAULT_ERROR_MESSAGE);

            response.setRenderParameter("mvcPath", ContentTargetingPath.VIEW);
            response.setRenderParameter("tabs1", "user-segments");
        } else {
            response.setRenderParameter("mvcPath", ContentTargetingPath.ERROR);
        }
    }
}

From source file:com.liferay.content.targeting.portlet.ContentTargetingPortlet.java

License:Open Source License

public void updateCampaign(ActionRequest request, ActionResponse response) throws Exception {

    long campaignId = ParamUtil.getLong(request, "campaignId");

    Map<Locale, String> nameMap = LocalizationUtil.getLocalizationMap(request, "name");
    Map<Locale, String> descriptionMap = LocalizationUtil.getLocalizationMap(request, "description");

    Date startDate = _getDate(request, "startDate");
    Date endDate = _getDate(request, "endDate");

    int priority = ParamUtil.getInteger(request, "priority");

    boolean active = ParamUtil.getBoolean(request, "active");

    // Initially, only one user segment per campaign is supported

    long[] userSegmentIds = null;

    long userSegmentId = ParamUtil.getLong(request, "userSegmentId");

    if (userSegmentId > 0) {
        userSegmentIds = new long[] { userSegmentId };
    }/*  ww  w  .j a  va2  s .  co m*/

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

    ServiceContext serviceContext = ServiceContextFactory.getInstance(UserSegment.class.getName(), request);

    try {
        Callable<Campaign> campaignCallable = new CampaignCallable(request, response, themeDisplay.getUserId(),
                campaignId, nameMap, descriptionMap, startDate, endDate, priority, active, userSegmentIds,
                serviceContext);

        TransactionalCallableUtil.call(_transactionAttribute, campaignCallable);

        sendRedirect(request, response);
    } catch (Exception e) {
        PortalUtil.copyRequestParameters(request, response);

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

        if (e instanceof InvalidDateRangeException || e instanceof InvalidNameException
                || e instanceof InvalidTrackingActionsException || e instanceof PrincipalException) {

            SessionMessages.add(request,
                    PortalUtil.getPortletId(request) + SessionMessages.KEY_SUFFIX_HIDE_DEFAULT_ERROR_MESSAGE);

            response.setRenderParameter("mvcPath", ContentTargetingPath.EDIT_CAMPAIGN);
        } else {
            response.setRenderParameter("mvcPath", ContentTargetingPath.ERROR);
        }
    } catch (Throwable t) {
        _log.error(t);

        response.setRenderParameter("mvcPath", ContentTargetingPath.ERROR);
    }
}