@Override public void followThread(final long threadId) throws DataSourceException { if (isLoggedInUser()) { try { SubscriptionLocalServiceUtil.addSubscription(currentUserId, UserLocalServiceUtil.getUser(currentUserId) .getGroupId(), MBThread.class.getName(), threadId); } catch (final NestableException e) { LOG.error(String.format("Cannot follow thread %d", threadId), e); throw new DataSourceException(e); } catch (final NullPointerException e) { LOG.error(String.format("Cannot follow thread %d", threadId), e); } } }
@Override public boolean isFollowingThread(final long threadId) { boolean result = false; if (isLoggedInUser()) { try { final com.liferay.portal.model.User user = UserLocalServiceUtil .getUser(currentUserId); result = SubscriptionLocalServiceUtil.isSubscribed( user.getCompanyId(), user.getUserId(), MBThread.class.getName(), threadId); } catch (final NestableException e) { LOG.error(String .format("Cannot check if user is following thread %d", threadId), e); } } return result; }
public Idea addMBMessage(Idea idea, ServiceContext serviceContext, long groupId, long userId, String comment, long ideaCommentClassPK) throws PortalException, SystemException { User user = UserLocalServiceUtil.getUser(userId); String threadView = PropsKeys.DISCUSSION_THREAD_VIEW; MBMessageDisplay messageDisplay = MBMessageLocalServiceUtil.getDiscussionMessageDisplay( userId, groupId, IdeaContent.class.getName(), ideaCommentClassPK, WorkflowConstants.STATUS_ANY, threadView); MBThread thread = messageDisplay.getThread(); long threadId = thread.getThreadId(); long rootThreadId = thread.getRootMessageId(); String commentContentCleaned = comment; final int maxLenghtCommentSubject = 50; String commentSubject = comment; commentSubject = StringUtil.shorten(commentSubject, maxLenghtCommentSubject); commentSubject += "..."; // TODO - validate comment and preserve line breaks MBMessageLocalServiceUtil.addDiscussionMessage( userId, user.getScreenName(), groupId, IdeaContent.class.getName(), ideaCommentClassPK, threadId, rootThreadId, commentSubject, commentContentCleaned, serviceContext); return idea; }
long userId = message.getUserId(); User user = UserLocalServiceUtil.getUser(userId); String userScreenName = message.getName(); long messageId = message.getMessageId();
@Override public void reportPost(final long postId, final Reason reason, final String additionalInfo, final String postUrl) { String reporterEmailAddress = ""; try { reporterEmailAddress = UserLocalServiceUtil.getUser(currentUserId) .getEmailAddress(); } catch (final NestableException e) { LOG.error("Couldn't get the email address of current user.", e); } try { Post post = getPost(postId); final long reportedUserId = post.getAuthor().getId(); final String contentTitle = post.getThread().getTopic(); final String contentURL = postUrl; String reasonString = reason.toString(); if (additionalInfo != null && !additionalInfo.isEmpty()) { reasonString += ": " + additionalInfo; } FlagsEntryServiceUtil.addEntry(MBMessage.class.getName(), postId, reporterEmailAddress, reportedUserId, contentTitle, contentURL, reasonString, flagsServiceContext); } catch (DataSourceException e) { e.printStackTrace(); } }
String ideaId = idea.getId(); User user = UserLocalServiceUtil.getUser(userId);
private User getUser(final long userId) throws PortalException, SystemException { if (userId == 0) { return LiferayEntityFactoryUtil .createAnonymousUser(imagePath); } else { try { final com.liferay.portal.model.User liferayUser = UserLocalServiceUtil .getUser(userId); if (liferayUser.isDefaultUser()) { return LiferayEntityFactoryUtil .createAnonymousUser(imagePath); } else { final boolean isBanned = MBBanLocalServiceUtil.hasBan( scopeGroupId, liferayUser.getUserId()); String userLink = null; if (liferayUser.getGroup() != null && liferayUser.getPublicLayoutsPageCount() > 0) { userLink = liferayUser.getDisplayURL(themeDisplay); } return LiferayEntityFactoryUtil.createUser( liferayUser, imagePath, userLink, liferayUser.isFemale(), isBanned); } } catch (NoSuchUserException e) { return LiferayEntityFactoryUtil .createAnonymousUser(imagePath); } } }
String avatarUrl = ""; try { user = UserLocalServiceUtil.getUser(mbMessage.getUserId()); String userAvatarUrl = LiferayEntityFactoryUtil.getAvatarUrl( user.getPortraitId(), imagePath, user.isFemale());