/** * Method description * * * @return * * @throws PortalException * @throws SystemException */ public User getPortalUser() throws PortalException, SystemException { return UserLocalServiceUtil.getUserById(portalUserId); }
@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); } } }
public static UserData getLiferayUserByEmailNoException(String email, Long companyId) { try { User user = UserLocalServiceUtil.getUserByEmailAddress(companyId, email); return convertLiferayUser(user); } catch (Exception e) { return null; } }
public static List<UserData> getAllUsers() { try { return convertLiferayUsers(UserLocalServiceUtil.getUsers(0, UserLocalServiceUtil.getUsersCount())); } catch (SystemException e) { throw new LiferayBridgeException(e); } }
public static UserData getLiferayUser(String login, Long companyId) { try { User user = UserLocalServiceUtil.getUserByScreenName(companyId, login); return convertLiferayUser(user); } catch (Exception e) { throw new LiferayBridgeException(e); } }
private static void refreshUsers() throws SystemException { if (debug) { log("refreshing users"); } for (User user: UserLocalServiceUtil.getUsers(0, QueryUtil.ALL_POS)) { if (debug) { log("have user " + user.getScreenName() + ", " + user.getEmailAddress()); } cache.put(user.getScreenName(), new UserContainer(user)); emailCache.put(user.getEmailAddress(), new UserContainer(user)); } }
public static List<UserData> getUsersByCompanyId(Long companyId) { try { if (companyId == null) { return new ArrayList<UserData>(0); } return convertLiferayUsers(UserLocalServiceUtil.getCompanyUsers(companyId, 0, Integer.MAX_VALUE)); } catch (SystemException e) { throw new LiferayBridgeException(e); } }
private static User getUserFromCookies(HttpServletRequest request) throws SystemException, PortalException { // https://www.everit.biz/web/guest/everit-blog/-/blogs/getting-current-liferay-user-in-a-standalone-webapp final Cookie[] cookies = request.getCookies() == null?new Cookie[0]:request.getCookies(); String userId = null; String password = null; String companyId = null; if (debug) { log("getting user from cookies"); } for (Cookie c : cookies) { if ("COMPANY_ID".equals(c.getName())) { companyId = c.getValue(); } else if ("ID".equals(c.getName())) { userId = hexStringToStringByAscii(c.getValue()); } else if ("PASSWORD".equals(c.getName())) { password = hexStringToStringByAscii(c.getValue()); } } if (debug) { log("have cookies {0} {1} {2}", userId, password, companyId); } if (userId != null && password != null && companyId != null) { final KeyValuePair kvp = UserLocalServiceUtil.decryptUserId(Long.parseLong(companyId), userId, password); return getUser(kvp.getKey()); } if (debug) { log("no cookies found"); } return null; }
@Override public UserData getUserByLogin(String login, Long companyId) throws UserSourceException { try { User user = UserLocalServiceUtil.getUserByScreenName(companyId, login); return LiferayUserConverter.convertLiferayUser(user); } catch (Exception e) { throw new UserSourceException(e); } }
public static List<UserData> getAllUsersByCurrentUser(UserData currentUser) { try { if (currentUser == null) { return new ArrayList<UserData>(0); } return convertLiferayUsers(UserLocalServiceUtil.getCompanyUsers(currentUser.getCompanyId(), 0, Integer.MAX_VALUE)); } catch (SystemException e) { throw new LiferayBridgeException(e); } }
public static User getUser(String user) { if (debug) { log("getting user from liferay " + user); } try { return UserLocalServiceUtil.getUserById(Long.valueOf(user,10)); } catch (Exception ex) { throw new RuntimeException(ex); } }
@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 Locale getUserLocale(String login) { if (login == null) { return null; } long[] companyIds = PortalUtil.getCompanyIds(); for (long companyId : companyIds) { try { User u = UserLocalServiceUtil.getUserByScreenName(companyId, login); if (u != null) { return u.getLocale(); } } catch (PortalException e) { return new Locale("en"); } catch (Exception e) { throw new UserSourceException(e); } } return new Locale("en"); }
public static UserData getLiferayUserByEmail(String email, Long companyId) { try { User user = UserLocalServiceUtil.getUserByEmailAddress(companyId, email); return convertLiferayUser(user); } catch (Exception e) { throw new LiferayBridgeException(e); } }
public User getScopeGroupUser() { User groupUser = null; Group scopeGroup = getScopeGroup(); if (scopeGroup.isUser()) { try { groupUser = UserLocalServiceUtil.getUserById(scopeGroup.getClassPK()); } catch (Exception e) { logger.error(e.getMessage(), e); } } return groupUser; }
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; }
public static UserData getLiferayUser(final String login) { if (login == null) { return null; } try { long[] companyIds = PortalUtil.getCompanyIds(); for (int i = 0; i < companyIds.length; ++i) { long ci = companyIds[i]; try { User u = UserLocalServiceUtil.getUserByScreenName(ci, login); if (u != null) { return convertLiferayUser(u); } } catch (NoSuchUserException e) { // continue } } return null; } catch (Exception e) { throw new LiferayBridgeException(e); } }
@Override public UserData getUserByEmail(String email) { if (email == null) return null; try { long[] companyIds = PortalUtil.getCompanyIds(); for (int i = 0; i < companyIds.length; ++i) { long ci = companyIds[i]; try { User u = UserLocalServiceUtil.getUserByEmailAddress(ci, email); if (u != null) { return LiferayUserConverter.convertLiferayUser(u); } } catch (NoSuchUserException e) { // continue } } return null; } catch (Exception e) { throw new UserSourceException(e); } }
public User getScopeGroupUser() { User groupUser = null; Group scopeGroup = getScopeGroup(); if (scopeGroup.isUser()) { try { groupUser = UserLocalServiceUtil.getUserById(scopeGroup.getClassPK()); } catch (Exception e) { logger.error(e.getMessage(), e); } } return groupUser; }
@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(); } }