Example usage for com.liferay.portal.kernel.service ServiceContextFunction ServiceContextFunction

List of usage examples for com.liferay.portal.kernel.service ServiceContextFunction ServiceContextFunction

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.service ServiceContextFunction ServiceContextFunction.

Prototype

public ServiceContextFunction(PortletRequest portletRequest) 

Source Link

Usage

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

License:Open Source License

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

    try {//from   w  ww .j a va2s. c o  m
        BlogsEntry entry = getBlogsEntry(actionRequest);

        validate(entry);

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

        HttpServletRequest request = PortalUtil.getHttpServletRequest(actionRequest);

        HttpServletRequest originalRequest = PortalUtil.getOriginalServletRequest(request);

        String excerpt = ParamUtil.getString(originalRequest, "excerpt");
        String url = ParamUtil.getString(originalRequest, "url");
        String blogName = ParamUtil.getString(originalRequest, "blog_name");
        String title = ParamUtil.getString(originalRequest, "title");

        validate(actionRequest, request.getRemoteAddr(), url);

        _trackback.addTrackback(entry, themeDisplay, excerpt, url, blogName, title,
                new ServiceContextFunction(actionRequest));
    } catch (TrackbackValidationException tve) {
        sendError(actionRequest, actionResponse, tve.getMessage());

        return;
    }

    sendSuccess(actionRequest, actionResponse);
}

From source file:com.liferay.comment.taglib.internal.struts.EditDiscussionStrutsAction.java

License:Open Source License

protected long updateComment(HttpServletRequest request) throws Exception {
    ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);

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

    String className = ParamUtil.getString(request, "className");
    long classPK = ParamUtil.getLong(request, "classPK");
    long parentCommentId = ParamUtil.getLong(request, "parentCommentId");
    String subject = ParamUtil.getString(request, "subject");
    String body = ParamUtil.getString(request, "body");

    Function<String, ServiceContext> serviceContextFunction = new ServiceContextFunction(request);

    DiscussionPermission discussionPermission = _getDiscussionPermission(themeDisplay);

    if (commentId <= 0) {

        // Add message

        User user = null;//ww w . jav  a  2  s  .  c o  m

        if (themeDisplay.isSignedIn()) {
            user = themeDisplay.getUser();
        } else {
            String emailAddress = ParamUtil.getString(request, "emailAddress");

            user = _userLocalService.fetchUserByEmailAddress(themeDisplay.getCompanyId(), emailAddress);

            if ((user == null) || (user.getStatus() != WorkflowConstants.STATUS_INCOMPLETE)) {

                return 0;
            }
        }

        String name = PrincipalThreadLocal.getName();

        PrincipalThreadLocal.setName(user.getUserId());

        try {
            discussionPermission.checkAddPermission(themeDisplay.getCompanyId(), themeDisplay.getScopeGroupId(),
                    className, classPK);

            commentId = _commentManager.addComment(user.getUserId(), className, classPK, user.getFullName(),
                    parentCommentId, subject, body, serviceContextFunction);
        } finally {
            PrincipalThreadLocal.setName(name);
        }
    } else {

        // Update message

        if (Validator.isNull(className) || (classPK == 0)) {
            Comment comment = _commentManager.fetchComment(commentId);

            if (comment != null) {
                className = comment.getClassName();
                classPK = comment.getClassPK();
            }
        }

        discussionPermission.checkUpdatePermission(commentId);

        commentId = _commentManager.updateComment(themeDisplay.getUserId(), className, classPK, commentId,
                subject, body, serviceContextFunction);
    }

    // Subscription

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

    if (subscribe) {
        _commentManager.subscribeDiscussion(themeDisplay.getUserId(), themeDisplay.getScopeGroupId(), className,
                classPK);
    }

    return commentId;
}