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.liferay.content.targeting.portlet.ContentTargetingPortlet.java

License:Open Source License

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

    long classPK = ParamUtil.getLong(request, "classPK");
    String reportKey = ParamUtil.getString(request, "reportKey");

    try {/* w w  w. j a  va 2  s.c om*/
        Report report = _reportsRegistry.getReport(reportKey);

        String typeSettings = report.updateReport(classPK);

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

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

        serviceContext.setScopeGroupId(themeDisplay.getSiteGroupIdOrLiveGroupId());

        _reportInstanceService.addReportInstance(themeDisplay.getUserId(), reportKey, report.getReportType(),
                classPK, typeSettings, serviceContext);

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

        if (e instanceof PrincipalException) {
            response.setRenderParameter("mvcPath", ContentTargetingPath.VIEW_REPORT);
        } else {
            response.setRenderParameter("mvcPath", ContentTargetingPath.ERROR);
        }
    }
}

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

License:Open Source License

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

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

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

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

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

    try {//ww w .  j av  a  2 s. c o m
        Callable<UserSegment> userSegmentCallable = new UserSegmentCallable(request, response,
                themeDisplay.getUserId(), userSegmentId, nameMap, descriptionMap, serviceContext);

        TransactionalCallableUtil.call(_transactionAttribute, userSegmentCallable);

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

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

        if (e instanceof InvalidNameException || e instanceof InvalidRulesException
                || e instanceof PrincipalException) {

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

            response.setRenderParameter("mvcPath", ContentTargetingPath.EDIT_USER_SEGMENT);
        } else {
            _log.error(e);

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

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

From source file:com.liferay.contenttargeting.portlet.ContentTargetingPortlet.java

License:Open Source License

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

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

    try {//from  w w  w  . j  a  v a2  s. com
        _userSegmentService.deleteUserSegment(userSegmentId);

        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.document.library.web.internal.portlet.action.DLViewMVCRenderCommand.java

License:Open Source License

@Override
public String render(RenderRequest renderRequest, RenderResponse renderResponse) throws PortletException {

    renderRequest.setAttribute(DLWebKeys.DOCUMENT_LIBRARY_PORTLET_TOOLBAR_CONTRIBUTOR,
            _dlPortletToolbarContributor);

    try {/* www. j  a  va  2 s. co  m*/
        pingFolderRepository(renderRequest);
    } catch (Exception e) {
        SessionErrors.add(renderRequest, "repositoryPingFailed", e);

        return "/document_library/error.jsp";
    }

    return super.render(renderRequest, renderResponse);
}

From source file:com.liferay.document.library.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 {/*  w  ww .  j  a  v  a 2  s .co m*/
        if (cmd.equals(Constants.CANCEL_CHECKOUT)) {
            cancelCheckedOutEntries(actionRequest);
        } else if (cmd.equals(Constants.CHECKIN)) {
            checkInEntries(actionRequest);
        } else if (cmd.equals(Constants.CHECKOUT)) {
            checkOutEntries(actionRequest);
        } else if (cmd.equals(Constants.DELETE)) {
            deleteEntries(actionRequest, false);
        } else if (cmd.equals(Constants.MOVE)) {
            moveEntries(actionRequest);
        } else if (cmd.equals(Constants.MOVE_TO_TRASH)) {
            deleteEntries(actionRequest, true);
        } else if (cmd.equals(Constants.RESTORE)) {
            restoreTrashEntries(actionRequest);
        }

        WindowState windowState = actionRequest.getWindowState();

        if (windowState.equals(LiferayWindowState.POP_UP)) {
            String redirect = _portal.escapeRedirect(ParamUtil.getString(actionRequest, "redirect"));

            if (Validator.isNotNull(redirect)) {
                sendRedirect(actionRequest, actionResponse, redirect);
            }
        }
    } catch (DuplicateLockException | NoSuchFileEntryException | NoSuchFolderException | PrincipalException e) {

        if (e instanceof DuplicateLockException) {
            DuplicateLockException dle = (DuplicateLockException) e;

            SessionErrors.add(actionRequest, dle.getClass(), dle.getLock());
        } else {
            SessionErrors.add(actionRequest, e.getClass());
        }

        actionResponse.setRenderParameter("mvcPath", "/document_library/error.jsp");
    } catch (DuplicateFileEntryException | DuplicateFolderNameException | SourceFileNameException e) {

        if (e instanceof DuplicateFileEntryException) {
            HttpServletResponse response = _portal.getHttpServletResponse(actionResponse);

            response.setStatus(ServletResponseConstants.SC_DUPLICATE_FILE_EXCEPTION);
        }

        SessionErrors.add(actionRequest, e.getClass());
    } catch (AssetCategoryException | AssetTagException | InvalidFolderException e) {

        SessionErrors.add(actionRequest, e.getClass(), e);
    } catch (Exception e) {
        throw new PortletException(e);
    }
}

From source file:com.liferay.document.library.web.internal.portlet.action.EditFileEntryMVCActionCommand.java

License:Open Source License

protected void handleUploadException(PortletConfig portletConfig, ActionRequest actionRequest,
        ActionResponse actionResponse, String cmd, Exception e) throws Exception {

    if (e instanceof AssetCategoryException || e instanceof AssetTagException) {

        SessionErrors.add(actionRequest, e.getClass(), e);
    } else if (e instanceof AntivirusScannerException || e instanceof DuplicateFileEntryException
            || e instanceof DuplicateFolderNameException || e instanceof FileExtensionException
            || e instanceof FileMimeTypeException || e instanceof FileNameException
            || e instanceof FileSizeException || e instanceof LiferayFileItemException
            || e instanceof NoSuchFolderException || e instanceof SourceFileNameException
            || e instanceof StorageFieldRequiredException || e instanceof UploadRequestSizeException) {

        if (!cmd.equals(Constants.ADD_DYNAMIC) && !cmd.equals(Constants.ADD_MULTIPLE)
                && !cmd.equals(Constants.ADD_TEMP)) {

            if (e instanceof AntivirusScannerException) {
                SessionErrors.add(actionRequest, e.getClass(), e);
            } else {
                SessionErrors.add(actionRequest, e.getClass());
            }/*  w  ww  .  java  2 s  . com*/

            return;
        } else if (cmd.equals(Constants.ADD_TEMP)) {
            hideDefaultErrorMessage(actionRequest);
        }

        if (e instanceof AntivirusScannerException || e instanceof DuplicateFileEntryException
                || e instanceof FileExtensionException || e instanceof FileNameException
                || e instanceof FileSizeException || e instanceof UploadRequestSizeException) {

            HttpServletResponse response = _portal.getHttpServletResponse(actionResponse);

            response.setContentType(ContentTypes.TEXT_HTML);
            response.setStatus(HttpServletResponse.SC_OK);

            String errorMessage = StringPool.BLANK;
            int errorType = 0;

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

            if (e instanceof AntivirusScannerException) {
                AntivirusScannerException ase = (AntivirusScannerException) e;

                errorMessage = themeDisplay.translate(ase.getMessageKey());

                errorType = ServletResponseConstants.SC_FILE_ANTIVIRUS_EXCEPTION;
            }

            if (e instanceof DuplicateFileEntryException) {
                errorMessage = themeDisplay.translate("please-enter-a-unique-document-name");
                errorType = ServletResponseConstants.SC_DUPLICATE_FILE_EXCEPTION;
            } else if (e instanceof FileExtensionException) {
                errorMessage = themeDisplay.translate("please-enter-a-file-with-a-valid-extension-x", StringUtil
                        .merge(getAllowedFileExtensions(portletConfig, actionRequest, actionResponse)));
                errorType = ServletResponseConstants.SC_FILE_EXTENSION_EXCEPTION;
            } else if (e instanceof FileNameException) {
                errorMessage = themeDisplay.translate("please-enter-a-file-with-a-valid-file-name");
                errorType = ServletResponseConstants.SC_FILE_NAME_EXCEPTION;
            } else if (e instanceof FileSizeException) {
                long fileMaxSize = PrefsPropsUtil.getLong(PropsKeys.DL_FILE_MAX_SIZE);

                if (fileMaxSize == 0) {
                    fileMaxSize = PrefsPropsUtil.getLong(PropsKeys.UPLOAD_SERVLET_REQUEST_IMPL_MAX_SIZE);
                }

                errorMessage = themeDisplay.translate(
                        "please-enter-a-file-with-a-valid-file-size-no-" + "larger-than-x",
                        TextFormatter.formatStorageSize(fileMaxSize, themeDisplay.getLocale()));

                errorType = ServletResponseConstants.SC_FILE_SIZE_EXCEPTION;
            }

            JSONObject jsonObject = JSONFactoryUtil.createJSONObject();

            jsonObject.put("message", errorMessage);
            jsonObject.put("status", errorType);

            JSONPortletResponseUtil.writeJSON(actionRequest, actionResponse, jsonObject);
        }

        if (e instanceof AntivirusScannerException) {
            SessionErrors.add(actionRequest, e.getClass(), e);
        } else {
            SessionErrors.add(actionRequest, e.getClass());
        }
    } else if (e instanceof DuplicateLockException || e instanceof FileEntryLockException.MustOwnLock
            || e instanceof InvalidFileVersionException || e instanceof NoSuchFileEntryException
            || e instanceof PrincipalException) {

        if (e instanceof DuplicateLockException) {
            DuplicateLockException dle = (DuplicateLockException) e;

            SessionErrors.add(actionRequest, dle.getClass(), dle.getLock());
        } else {
            SessionErrors.add(actionRequest, e.getClass());
        }

        actionResponse.setRenderParameter("mvcPath", "/document_library/error.jsp");
    } else {
        Throwable cause = e.getCause();

        if (cause instanceof DuplicateFileEntryException) {
            SessionErrors.add(actionRequest, DuplicateFileEntryException.class);
        } else {
            throw e;
        }
    }
}

From source file:com.liferay.document.library.web.portlet.action.UploadAssignmentMVCActionCommand.java

License:Open Source License

protected void handleUploadException(ActionRequest actionRequest, Exception e) throws Exception {

    if (e instanceof AssetCategoryException || e instanceof AssetTagException
            || e instanceof AntivirusScannerException || e instanceof DuplicateFileEntryException
            || e instanceof DuplicateFolderNameException || e instanceof FileExtensionException
            || e instanceof FileMimeTypeException || e instanceof FileNameException
            || e instanceof FileSizeException || e instanceof LiferayFileItemException
            || e instanceof NoSuchFolderException || e instanceof SourceFileNameException
            || e instanceof StorageFieldRequiredException || e instanceof UploadRequestSizeException
            || e instanceof DuplicateLockException || e instanceof FileEntryLockException.MustOwnLock
            || e instanceof InvalidFileVersionException || e instanceof NoSuchFileEntryException
            || e instanceof PrincipalException) {

        SessionErrors.add(actionRequest, e.getClass(), e);
    } else {//from w ww .  ja va  2  s .co m
        throw e;
    }
}

From source file:com.liferay.dynamic.data.lists.form.web.internal.portlet.DDLFormPortlet.java

License:Open Source License

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

    try {/* ww w .  j  ava  2s  . c  om*/
        super.processAction(actionRequest, actionResponse);
    } catch (Exception e) {
        _portal.copyRequestParameters(actionRequest, actionResponse);

        Throwable cause = getRootCause(e);

        hideDefaultErrorMessage(actionRequest);

        if (cause instanceof DDMFormValuesValidationException) {
            if (cause instanceof DDMFormValuesValidationException.MustSetValidValues
                    || cause instanceof DDMFormValuesValidationException.RequiredValue) {

                SessionErrors.add(actionRequest, cause.getClass(), cause);
            } else {
                SessionErrors.add(actionRequest, DDMFormValuesValidationException.class);
            }
        } else {
            SessionErrors.add(actionRequest, cause.getClass(), cause);
        }

        if (isSharedLayout(actionRequest)) {
            saveParametersInSession(actionRequest);
        }
    }
}

From source file:com.liferay.dynamic.data.mapping.form.web.internal.portlet.DDMFormPortlet.java

License:Open Source License

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

    try {//  w w  w  . j a v a 2  s  .  c  om
        super.processAction(actionRequest, actionResponse);
    } catch (Exception e) {
        _portal.copyRequestParameters(actionRequest, actionResponse);

        Throwable cause = getRootCause(e);

        hideDefaultErrorMessage(actionRequest);

        if (cause instanceof DDMFormValuesValidationException) {
            if (cause instanceof DDMFormValuesValidationException.MustSetValidValues
                    || cause instanceof DDMFormValuesValidationException.RequiredValue) {

                SessionErrors.add(actionRequest, cause.getClass(), cause);
            } else {
                SessionErrors.add(actionRequest, DDMFormValuesValidationException.class);
            }
        } else {
            SessionErrors.add(actionRequest, cause.getClass(), cause);
        }

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

        if (_addDefaultSharedFormLayoutPortalInstanceLifecycleListener.isSharedLayout(themeDisplay)) {

            saveParametersInSession(actionRequest);
        }
    }
}

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

License:Open Source License

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

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

    if (cmd.equals(Constants.EXPORT) || cmd.equals(Constants.PUBLISH)) {
        _processExportAndPublishAction(actionRequest, actionResponse);
    } else {//from  w w w.j  a  v a 2  s.  c o m
        SessionErrors.add(actionRequest, ExportImportEntityException.class,
                new ExportImportEntityException(ExportImportEntityException.TYPE_INVALID_COMMAND));
    }
}