com.liferay.mentions.internal.util.DefaultMentionsUserFinder Maven / Gradle / Ivy
/**
* Copyright (c) 2000-present Liferay, Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 2.1 of the License, or (at your option)
* any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*/
package com.liferay.mentions.internal.util;
import com.liferay.mentions.util.MentionsUserFinder;
import com.liferay.portal.kernel.dao.orm.WildcardMode;
import com.liferay.portal.kernel.exception.PortalException;
import com.liferay.portal.kernel.model.Group;
import com.liferay.portal.kernel.model.User;
import com.liferay.portal.kernel.service.GroupLocalService;
import com.liferay.portal.kernel.service.UserLocalService;
import com.liferay.portal.kernel.util.LinkedHashMapBuilder;
import com.liferay.portal.kernel.util.ListUtil;
import com.liferay.portal.kernel.util.comparator.UserScreenNameComparator;
import com.liferay.portal.kernel.workflow.WorkflowConstants;
import com.liferay.social.kernel.model.SocialRelationConstants;
import com.liferay.social.kernel.util.SocialInteractionsConfiguration;
import java.util.Collections;
import java.util.List;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
/**
* @author Sergio González
*/
@Component(service = MentionsUserFinder.class)
public class DefaultMentionsUserFinder implements MentionsUserFinder {
@Override
public List getUsers(
long companyId, long userId, String query,
SocialInteractionsConfiguration socialInteractionsConfiguration)
throws PortalException {
if (socialInteractionsConfiguration.
isSocialInteractionsAnyUserEnabled()) {
return _userLocalService.search(
companyId, query, WorkflowConstants.STATUS_APPROVED,
LinkedHashMapBuilder.put(
"wildcardMode", WildcardMode.TRAILING
).build(),
0, _MAX_USERS, new UserScreenNameComparator());
}
User user = _userLocalService.getUser(userId);
long[] groupIds = ListUtil.toLongArray(
_groupLocalService.getUserSitesGroups(user.getUserId()),
Group.GROUP_ID_ACCESSOR);
if (socialInteractionsConfiguration.
isSocialInteractionsFriendsEnabled() &&
socialInteractionsConfiguration.
isSocialInteractionsSitesEnabled()) {
return _userLocalService.searchBySocial(
groupIds, userId, _TYPES, query, 0, _MAX_USERS);
}
if (socialInteractionsConfiguration.
isSocialInteractionsSitesEnabled()) {
return _userLocalService.searchBySocial(
companyId, groupIds, query, 0, _MAX_USERS);
}
if (socialInteractionsConfiguration.
isSocialInteractionsFriendsEnabled()) {
return _userLocalService.searchBySocial(
userId, _TYPES, query, 0, _MAX_USERS);
}
return Collections.emptyList();
}
private static final int _MAX_USERS = 20;
private static final int[] _TYPES = {
SocialRelationConstants.TYPE_BI_FRIEND
};
@Reference
private GroupLocalService _groupLocalService;
@Reference
private UserLocalService _userLocalService;
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy