Example usage for com.liferay.portal.kernel.comment DuplicateCommentException DuplicateCommentException

List of usage examples for com.liferay.portal.kernel.comment DuplicateCommentException DuplicateCommentException

Introduction

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

Prototype

public DuplicateCommentException(Throwable cause) 

Source Link

Usage

From source file:com.liferay.message.boards.comment.internal.MBCommentManagerImpl.java

License:Open Source License

@Override
public long addComment(long userId, long groupId, String className, long classPK, String body,
        Function<String, ServiceContext> serviceContextFunction) throws PortalException {

    MBMessageDisplay messageDisplay = _mbMessageLocalService.getDiscussionMessageDisplay(userId, groupId,
            className, classPK, WorkflowConstants.STATUS_APPROVED);

    MBThread thread = messageDisplay.getThread();

    List<MBMessage> messages = _mbMessageLocalService.getThreadMessages(thread.getThreadId(),
            WorkflowConstants.STATUS_APPROVED);

    for (MBMessage message : messages) {
        String messageBody = message.getBody();

        if (messageBody.equals(body)) {
            throw new DuplicateCommentException(body);
        }//  w  ww  .  j av  a2s .  co m
    }

    ServiceContext serviceContext = serviceContextFunction.apply(MBMessage.class.getName());

    MBMessage mbMessage = _mbMessageLocalService.addDiscussionMessage(userId, StringPool.BLANK, groupId,
            className, classPK, thread.getThreadId(), thread.getRootMessageId(), StringPool.BLANK, body,
            serviceContext);

    return mbMessage.getMessageId();
}