Search in sources :

Example 16 with Indexer

use of com.liferay.portal.kernel.search.Indexer in project sw360portal by sw360.

the class UserPortletUtils method addLiferayUser.

private static User addLiferayUser(PortletRequest request, String firstName, String lastName, String emailAddress, long organizationId, long roleId, boolean isMale, String externalId, String password, boolean passwordEncrypted, boolean activateImmediately) {
    ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);
    String screenName = firstName + lastName;
    long companyId = themeDisplay.getCompanyId();
    try {
        if (userAlreadyExists(request, emailAddress, externalId, screenName, companyId)) {
            return null;
        }
    } catch (PortalException | SystemException e) {
        log.error(e);
        // won't try to create user if even checking for existing user failed
        return null;
    }
    try {
        ServiceContext serviceContext = ServiceContextFactory.getInstance(request);
        long[] roleIds = roleId == 0 ? new long[] {} : new long[] { roleId };
        long[] organizationIds = organizationId == 0 ? new long[] {} : new long[] { organizationId };
        long[] userGroupIds = null;
        long currentUserId = themeDisplay.getUserId();
        User user = UserLocalServiceUtil.addUser(currentUserId, /*creator*/
        companyId, false, /*autoPassword*/
        password, password, false, /*autoScreenName*/
        screenName, emailAddress, 0, /*facebookId*/
        externalId, /*openId*/
        themeDisplay.getLocale(), firstName, "", /*middleName*/
        lastName, 0, /*prefixId*/
        0, /*suffixId*/
        isMale, 4, /*birthdayMonth*/
        12, /*birthdayDay*/
        1959, /*birthdayYear*/
        "", /*jobTitle*/
        null, /*groupIds*/
        organizationIds, roleIds, userGroupIds, false, /*sendEmail*/
        serviceContext);
        user.setPasswordReset(false);
        if (passwordEncrypted) {
            user.setPassword(password);
            user.setPasswordEncrypted(true);
        }
        Role role = RoleLocalServiceUtil.getRole(roleId);
        RoleUtil.addUser(role.getRoleId(), user.getUserId());
        UserLocalServiceUtil.updateUser(user);
        RoleLocalServiceUtil.updateRole(role);
        UserLocalServiceUtil.updateStatus(user.getUserId(), activateImmediately ? WorkflowConstants.STATUS_APPROVED : WorkflowConstants.STATUS_INACTIVE);
        Indexer indexer = IndexerRegistryUtil.getIndexer(User.class);
        indexer.reindex(user);
        return user;
    } catch (PortalException | SystemException e) {
        log.error(e);
        return null;
    }
}
Also used : Role(com.liferay.portal.model.Role) User(com.liferay.portal.model.User) Indexer(com.liferay.portal.kernel.search.Indexer) SystemException(com.liferay.portal.kernel.exception.SystemException) PortalException(com.liferay.portal.kernel.exception.PortalException) ThemeDisplay(com.liferay.portal.theme.ThemeDisplay)

Example 17 with Indexer

use of com.liferay.portal.kernel.search.Indexer in project liferay-ide by liferay.

the class KBArticleLocalServiceImpl method updateStatus.

@Override
public KBArticle updateStatus(long userId, long resourcePrimKey, int status, ServiceContext serviceContext) throws PortalException, SystemException {
    // KB article
    User user = userPersistence.findByPrimaryKey(userId);
    boolean main = false;
    Date now = new Date();
    if (status == WorkflowConstants.STATUS_APPROVED) {
        main = true;
    }
    KBArticle kbArticle = getLatestKBArticle(resourcePrimKey, WorkflowConstants.STATUS_ANY);
    kbArticle.setModifiedDate(serviceContext.getModifiedDate(now));
    kbArticle.setMain(main);
    kbArticle.setStatus(status);
    kbArticle.setStatusByUserId(user.getUserId());
    kbArticle.setStatusByUserName(user.getFullName());
    kbArticle.setStatusDate(serviceContext.getModifiedDate(now));
    kbArticlePersistence.update(kbArticle);
    if (status != WorkflowConstants.STATUS_APPROVED) {
        return kbArticle;
    }
    if (!kbArticle.isFirstVersion()) {
        KBArticle oldKBArticle = kbArticlePersistence.findByR_V(resourcePrimKey, kbArticle.getVersion() - 1);
        oldKBArticle.setMain(false);
        kbArticlePersistence.update(oldKBArticle);
    }
    // Asset
    AssetEntry assetEntry = assetEntryLocalService.getEntry(KBArticle.class.getName(), kbArticle.getKbArticleId());
    List<AssetLink> assetLinks = assetLinkLocalService.getDirectLinks(assetEntry.getEntryId(), AssetLinkConstants.TYPE_RELATED);
    long[] assetLinkEntryIds = StringUtil.split(ListUtil.toString(assetLinks, AssetLink.ENTRY_ID2_ACCESSOR), 0L);
    updateKBArticleAsset(userId, kbArticle, assetEntry.getCategoryIds(), assetEntry.getTagNames(), assetLinkEntryIds);
    SystemEventHierarchyEntryThreadLocal.push(KBArticle.class);
    try {
        assetEntryLocalService.deleteEntry(KBArticle.class.getName(), kbArticle.getKbArticleId());
    } finally {
        SystemEventHierarchyEntryThreadLocal.pop(KBArticle.class);
    }
    assetEntryLocalService.updateVisible(KBArticle.class.getName(), kbArticle.getResourcePrimKey(), true);
    // Social
    JSONObject extraDataJSONObject = JSONFactoryUtil.createJSONObject();
    extraDataJSONObject.put("title", kbArticle.getTitle());
    if (!kbArticle.isFirstVersion()) {
        socialActivityLocalService.addActivity(userId, kbArticle.getGroupId(), KBArticle.class.getName(), resourcePrimKey, AdminActivityKeys.UPDATE_KB_ARTICLE, extraDataJSONObject.toString(), 0);
    } else {
        socialActivityLocalService.addActivity(userId, kbArticle.getGroupId(), KBArticle.class.getName(), resourcePrimKey, AdminActivityKeys.ADD_KB_ARTICLE, extraDataJSONObject.toString(), 0);
    }
    // Indexer
    Indexer indexer = IndexerRegistryUtil.getIndexer(KBArticle.class);
    indexer.reindex(kbArticle);
    // Subscriptions
    notifySubscribers(kbArticle, serviceContext);
    return kbArticle;
}
Also used : AssetEntry(com.liferay.portlet.asset.model.AssetEntry) User(com.liferay.portal.model.User) Indexer(com.liferay.portal.kernel.search.Indexer) KBArticle(com.liferay.knowledgebase.model.KBArticle) JSONObject(com.liferay.portal.kernel.json.JSONObject) Date(java.util.Date) AssetLink(com.liferay.portlet.asset.model.AssetLink)

Example 18 with Indexer

use of com.liferay.portal.kernel.search.Indexer in project liferay-ide by liferay.

the class UserLocalServiceImpl method deleteRoleUser.

/**
 * Removes the user from the role.
 *
 * @param  roleId the primary key of the role
 * @param  userId the primary key of the user
 * @throws PortalException if a role or user with the primary key could not
 *         be found
 * @throws SystemException if a system exception occurred
 */
@Override
public void deleteRoleUser(long roleId, long userId) throws PortalException, SystemException {
    rolePersistence.removeUser(roleId, userId);
    Indexer indexer = IndexerRegistryUtil.nullSafeGetIndexer(User.class);
    indexer.reindex(userId);
    PermissionCacheUtil.clearCache();
}
Also used : Indexer(com.liferay.portal.kernel.search.Indexer)

Example 19 with Indexer

use of com.liferay.portal.kernel.search.Indexer in project liferay-ide by liferay.

the class UserLocalServiceImpl method search.

protected Hits search(long companyId, String firstName, String middleName, String lastName, String fullName, String screenName, String emailAddress, String street, String city, String zip, String region, String country, int status, LinkedHashMap<String, Object> params, boolean andSearch, int start, int end, Sort sort) throws SystemException {
    try {
        SearchContext searchContext = new SearchContext();
        searchContext.setAndSearch(andSearch);
        Map<String, Serializable> attributes = new HashMap<String, Serializable>();
        attributes.put("city", city);
        attributes.put("country", country);
        attributes.put("emailAddress", emailAddress);
        attributes.put("firstName", firstName);
        attributes.put("fullName", fullName);
        attributes.put("lastName", lastName);
        attributes.put("middleName", middleName);
        attributes.put("params", params);
        attributes.put("region", region);
        attributes.put("screenName", screenName);
        attributes.put("street", street);
        attributes.put("status", status);
        attributes.put("zip", zip);
        searchContext.setAttributes(attributes);
        searchContext.setCompanyId(companyId);
        searchContext.setEnd(end);
        if (params != null) {
            String keywords = (String) params.remove("keywords");
            if (Validator.isNotNull(keywords)) {
                searchContext.setKeywords(keywords);
            }
        }
        QueryConfig queryConfig = new QueryConfig();
        queryConfig.setHighlightEnabled(false);
        queryConfig.setScoreEnabled(false);
        searchContext.setQueryConfig(queryConfig);
        if (sort != null) {
            searchContext.setSorts(sort);
        }
        searchContext.setStart(start);
        Indexer indexer = IndexerRegistryUtil.nullSafeGetIndexer(User.class);
        return indexer.search(searchContext);
    } catch (Exception e) {
        throw new SystemException(e);
    }
}
Also used : Serializable(java.io.Serializable) QueryConfig(com.liferay.portal.kernel.search.QueryConfig) Indexer(com.liferay.portal.kernel.search.Indexer) SystemException(com.liferay.portal.kernel.exception.SystemException) LinkedHashMap(java.util.LinkedHashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) SearchContext(com.liferay.portal.kernel.search.SearchContext) ContactFirstNameException(com.liferay.portal.ContactFirstNameException) ModelListenerException(com.liferay.portal.ModelListenerException) NoSuchImageException(com.liferay.portal.NoSuchImageException) GroupFriendlyURLException(com.liferay.portal.GroupFriendlyURLException) DuplicateOpenIdException(com.liferay.portal.DuplicateOpenIdException) ImageSizeException(com.liferay.portlet.documentlibrary.ImageSizeException) PasswordExpiredException(com.liferay.portal.PasswordExpiredException) UserPasswordException(com.liferay.portal.UserPasswordException) NoSuchUserException(com.liferay.portal.NoSuchUserException) UserSmsException(com.liferay.portal.UserSmsException) NoSuchRoleException(com.liferay.portal.NoSuchRoleException) PortalException(com.liferay.portal.kernel.exception.PortalException) UserIdException(com.liferay.portal.UserIdException) UserPortraitTypeException(com.liferay.portal.UserPortraitTypeException) RequiredUserException(com.liferay.portal.RequiredUserException) ReservedUserScreenNameException(com.liferay.portal.ReservedUserScreenNameException) IOException(java.io.IOException) ContactBirthdayException(com.liferay.portal.ContactBirthdayException) UserReminderQueryException(com.liferay.portal.UserReminderQueryException) DuplicateUserScreenNameException(com.liferay.portal.DuplicateUserScreenNameException) UserEmailAddressException(com.liferay.portal.UserEmailAddressException) ContactFullNameException(com.liferay.portal.ContactFullNameException) EncryptorException(com.liferay.util.EncryptorException) CompanyMaxUsersException(com.liferay.portal.CompanyMaxUsersException) NoSuchTicketException(com.liferay.portal.NoSuchTicketException) UserScreenNameException(com.liferay.portal.UserScreenNameException) ContactLastNameException(com.liferay.portal.ContactLastNameException) ReservedUserEmailAddressException(com.liferay.portal.ReservedUserEmailAddressException) DuplicateUserEmailAddressException(com.liferay.portal.DuplicateUserEmailAddressException) NoSuchUserGroupException(com.liferay.portal.NoSuchUserGroupException) PrincipalException(com.liferay.portal.security.auth.PrincipalException) SystemException(com.liferay.portal.kernel.exception.SystemException) NoSuchOrganizationException(com.liferay.portal.NoSuchOrganizationException) UserLockoutException(com.liferay.portal.UserLockoutException) UserPortraitSizeException(com.liferay.portal.UserPortraitSizeException)

Example 20 with Indexer

use of com.liferay.portal.kernel.search.Indexer in project liferay-ide by liferay.

the class UserLocalServiceImpl method updateGroups.

protected void updateGroups(long userId, long[] newGroupIds, ServiceContext serviceContext, boolean indexingEnabled) throws PortalException, SystemException {
    if (newGroupIds == null) {
        return;
    }
    List<Group> oldGroups = userPersistence.getGroups(userId);
    Set<Long> oldGroupIds = new HashSet<Long>(oldGroups.size());
    for (Group oldGroup : oldGroups) {
        long oldGroupId = oldGroup.getGroupId();
        oldGroupIds.add(oldGroupId);
        if (!ArrayUtil.contains(newGroupIds, oldGroupId)) {
            unsetGroupUsers(oldGroupId, new long[] { userId }, serviceContext);
        }
    }
    for (long newGroupId : newGroupIds) {
        if (!oldGroupIds.contains(newGroupId)) {
            addGroupUsers(newGroupId, new long[] { userId });
        }
    }
    if (indexingEnabled) {
        Indexer indexer = IndexerRegistryUtil.nullSafeGetIndexer(User.class);
        indexer.reindex(new long[] { userId });
    }
    PermissionCacheUtil.clearCache();
}
Also used : Group(com.liferay.portal.model.Group) UserGroup(com.liferay.portal.model.UserGroup) Indexer(com.liferay.portal.kernel.search.Indexer) HashSet(java.util.HashSet)

Aggregations

Indexer (com.liferay.portal.kernel.search.Indexer)30 User (com.liferay.portal.model.User)5 Group (com.liferay.portal.model.Group)4 UserGroupRole (com.liferay.portal.model.UserGroupRole)4 Date (java.util.Date)4 ShardCallable (com.liferay.portal.kernel.dao.shard.ShardCallable)3 PortalException (com.liferay.portal.kernel.exception.PortalException)3 SystemException (com.liferay.portal.kernel.exception.SystemException)3 Role (com.liferay.portal.model.Role)3 UserGroup (com.liferay.portal.model.UserGroup)3 CompanyMaxUsersException (com.liferay.portal.CompanyMaxUsersException)2 ContactBirthdayException (com.liferay.portal.ContactBirthdayException)2 ContactFirstNameException (com.liferay.portal.ContactFirstNameException)2 ContactFullNameException (com.liferay.portal.ContactFullNameException)2 ContactLastNameException (com.liferay.portal.ContactLastNameException)2 DuplicateOpenIdException (com.liferay.portal.DuplicateOpenIdException)2 DuplicateUserEmailAddressException (com.liferay.portal.DuplicateUserEmailAddressException)2 DuplicateUserScreenNameException (com.liferay.portal.DuplicateUserScreenNameException)2 GroupFriendlyURLException (com.liferay.portal.GroupFriendlyURLException)2 ModelListenerException (com.liferay.portal.ModelListenerException)2