Example usage for com.liferay.portal.kernel.comment Comment getClassPK

List of usage examples for com.liferay.portal.kernel.comment Comment getClassPK

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.comment Comment getClassPK.

Prototype

public long getClassPK();

Source Link

Usage

From source file:com.liferay.comment.demo.data.creator.internal.CommentDemoDataCreatorImpl.java

License:Open Source License

@Override
public Comment create(long userId, long parentCommentId) throws PortalException {

    User user = _userLocalService.fetchUser(userId);
    Comment parentComment = _commentManager.fetchComment(parentCommentId);

    IdentityServiceContextFunction identityServiceContextFunction = new IdentityServiceContextFunction(
            new ServiceContext());

    long commentId = _commentManager.addComment(userId, parentComment.getClassName(),
            parentComment.getClassPK(), user.getFullName(), parentCommentId, StringPool.BLANK, _getRandomBody(),
            identityServiceContextFunction);

    return _getComment(commentId);
}

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;//from   ww w. j  ava 2  s .  co 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;
}

From source file:com.liferay.screens.service.impl.ScreensCommentServiceImpl.java

License:Open Source License

@Override
public JSONObject getComment(long commentId) throws PortalException {
    DiscussionPermission discussionPermission = commentManager.getDiscussionPermission(getPermissionChecker());

    Comment comment = commentManager.fetchComment(commentId);

    AssetEntry assetEntry = assetEntryLocalService.getEntry(comment.getClassName(), comment.getClassPK());

    Group group = groupLocalService.getGroup(assetEntry.getGroupId());

    discussionPermission.checkViewPermission(group.getCompanyId(), assetEntry.getGroupId(),
            comment.getClassName(), comment.getClassPK());

    return toJSONObject(comment, discussionPermission);
}

From source file:com.liferay.screens.service.impl.ScreensCommentServiceImpl.java

License:Open Source License

@Override
public JSONObject updateComment(long commentId, String body) throws PortalException {

    DiscussionPermission discussionPermission = commentManager.getDiscussionPermission(getPermissionChecker());

    discussionPermission.checkUpdatePermission(commentId);

    Comment comment = commentManager.fetchComment(commentId);

    commentManager.updateComment(getUserId(), comment.getClassName(), comment.getClassPK(), commentId,
            StringPool.BLANK, body, createServiceContextFunction(WorkflowConstants.ACTION_PUBLISH));

    comment = commentManager.fetchComment(commentId);

    return toJSONObject(comment, discussionPermission);
}

From source file:com.liferay.wiki.search.WikiPageIndexer.java

License:Open Source License

@Override
public void addRelatedEntryFields(Document document, Object obj) throws Exception {

    long classPK = 0;

    if (obj instanceof Comment) {
        Comment comment = (Comment) obj;

        classPK = comment.getClassPK();
    } else if (obj instanceof FileEntry) {
        FileEntry fileEntry = (FileEntry) obj;

        RelatedModelCapability relatedModelCapability = fileEntry
                .getRepositoryCapability(RelatedModelCapability.class);

        classPK = relatedModelCapability.getClassPK(fileEntry);
    }//www  .  j av a 2 s .c  o  m

    WikiPage page = null;

    try {
        page = _wikiPageLocalService.getPage(classPK);
    } catch (Exception e) {
        return;
    }

    document.addKeyword(Field.NODE_ID, page.getNodeId());
}