Example usage for com.liferay.portal.kernel.search Field USER_ID

List of usage examples for com.liferay.portal.kernel.search Field USER_ID

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.search Field USER_ID.

Prototype

String USER_ID

To view the source code for com.liferay.portal.kernel.search Field USER_ID.

Click Source Link

Usage

From source file:com.inkwell.internet.slogan.search.SloganIndexer.java

License:Open Source License

@Override
protected Document doGetDocument(Object obj) throws Exception {

    Slogan slogan = (Slogan) obj;//from w w  w . ja v a2s. c  o m
    long companyId = slogan.getCompanyId();
    long groupId = getParentGroupId(slogan.getGroupId());
    long scopeGroupId = slogan.getGroupId();
    long userId = slogan.getUserId();
    long resourcePrimKey = slogan.getPrimaryKey();
    String title = slogan.getSloganText();
    String content = slogan.getSloganText();
    String description = slogan.getSloganText();
    Date modifiedDate = slogan.getSloganDate();

    long[] assetCategoryIds = AssetCategoryLocalServiceUtil.getCategoryIds(Slogan.class.getName(),
            resourcePrimKey);

    List<AssetCategory> categories = AssetCategoryLocalServiceUtil.getCategories(Slogan.class.getName(),
            resourcePrimKey);

    String[] assetCategoryNames = StringUtil.split(ListUtil.toString(categories, "name"));

    // EE lets you do this quicker: 

    // String[] assetCategoryNames =
    //     AssetCategoryLocalServiceUtil.getCategoryNames(
    //         Slogan.class.getName(), resourcePrimKey);

    String[] assetTagNames = AssetTagLocalServiceUtil.getTagNames(Slogan.class.getName(), resourcePrimKey);

    Document document = new DocumentImpl();

    document.addUID(PORTLET_ID, resourcePrimKey);

    document.addModifiedDate(modifiedDate);

    document.addKeyword(Field.COMPANY_ID, companyId);
    document.addKeyword(Field.PORTLET_ID, PORTLET_ID);
    document.addKeyword(Field.GROUP_ID, groupId);
    document.addKeyword(Field.SCOPE_GROUP_ID, scopeGroupId);
    document.addKeyword(Field.USER_ID, userId);
    document.addText(Field.TITLE, title);
    document.addText(Field.CONTENT, content);
    document.addText(Field.DESCRIPTION, description);
    document.addKeyword(Field.ASSET_CATEGORY_IDS, assetCategoryIds);
    document.addKeyword("assetCategoryNames", assetCategoryNames);
    //document.addKeyword(Field.ASSET_CATEGORY_NAMES, assetCategoryNames);
    document.addKeyword(Field.ASSET_TAG_NAMES, assetTagNames);

    document.addKeyword(Field.ENTRY_CLASS_NAME, Slogan.class.getName());
    document.addKeyword(Field.ENTRY_CLASS_PK, resourcePrimKey);

    return document;
}

From source file:com.liferay.bookmarks.service.impl.BookmarksEntryLocalServiceImpl.java

License:Open Source License

@Override
public Hits search(long groupId, long userId, long creatorUserId, int status, int start, int end)
        throws PortalException {

    Indexer<BookmarksEntry> indexer = IndexerRegistryUtil.getIndexer(BookmarksEntry.class.getName());

    SearchContext searchContext = new SearchContext();

    searchContext.setAttribute(Field.STATUS, status);

    if (creatorUserId > 0) {
        searchContext.setAttribute(Field.USER_ID, String.valueOf(creatorUserId));
    }/* ww  w . j  a  v  a2  s .c o m*/

    searchContext.setAttribute("paginationType", "none");

    Group group = groupLocalService.getGroup(groupId);

    searchContext.setCompanyId(group.getCompanyId());

    searchContext.setEnd(end);
    searchContext.setGroupIds(new long[] { groupId });
    searchContext.setSorts(new Sort(Field.MODIFIED_DATE, true));
    searchContext.setStart(start);
    searchContext.setUserId(userId);

    QueryConfig queryConfig = searchContext.getQueryConfig();

    queryConfig.setHighlightEnabled(false);
    queryConfig.setScoreEnabled(false);

    return indexer.search(searchContext);
}

From source file:com.liferay.calendar.search.test.CalendarBookingIndexerIndexedFieldsTest.java

License:Open Source License

protected void populateCalendar(Calendar calendar, Map<String, String> map) {

    map.put(Field.DEFAULT_LANGUAGE_ID, calendar.getDefaultLanguageId());
    map.put(Field.USER_ID, String.valueOf(calendar.getUserId()));
    map.put(Field.USER_NAME, StringUtil.toLowerCase(calendar.getUserName()));
    map.put("visible", "true");
}

From source file:com.liferay.calendar.search.test.CalendarIndexerIndexedFieldsTest.java

License:Open Source License

protected void populateExpectedFieldValues(Calendar calendar, Map<String, String> map) throws Exception {

    map.put(Field.COMPANY_ID, String.valueOf(calendar.getCompanyId()));
    map.put(Field.DEFAULT_LANGUAGE_ID, calendar.getDefaultLanguageId());
    map.put(Field.ENTRY_CLASS_NAME, calendar.getModelClassName());
    map.put(Field.ENTRY_CLASS_PK, String.valueOf(calendar.getCalendarId()));
    map.put(Field.GROUP_ID, String.valueOf(calendar.getGroupId()));
    map.put(Field.SCOPE_GROUP_ID, String.valueOf(calendar.getGroupId()));
    map.put(Field.STAGING_GROUP, "false");
    map.put(Field.USER_ID, String.valueOf(calendar.getUserId()));
    map.put(Field.USER_NAME, StringUtil.toLowerCase(calendar.getUserName()));
    map.put("calendarId", String.valueOf(calendar.getCalendarId()));

    DateFormat dateFormat = DateFormatFactoryUtil.getSimpleDateFormat("yyyyMMddHHmmss");

    populateCalendarDate(Field.CREATE_DATE, calendar.getCreateDate(), map, dateFormat);
    populateCalendarDate(Field.MODIFIED_DATE, calendar.getModifiedDate(), map, dateFormat);

    populateCalendarResource(calendar.getCalendarResource(), calendar, map);

    calendarFieldsFixture.populateGroupRoleId(map);
    calendarFieldsFixture.populateRoleId("Guest", map);
    calendarFieldsFixture.populateUID(calendar, map);
}

From source file:com.liferay.document.library.repository.cmis.search.BaseCmisSearchQueryBuilder.java

License:Open Source License

protected CMISCriterion buildFieldExpression(String field, String value,
        CMISSimpleExpressionOperator cmisSimpleExpressionOperator, QueryConfig queryConfig)
        throws SearchException {

    CMISCriterion cmisCriterion = null;/* w  w  w.  ja v a2  s.c  o  m*/

    boolean wildcard = false;

    if (CMISSimpleExpressionOperator.LIKE == cmisSimpleExpressionOperator) {
        wildcard = true;
    }

    if (field.equals(Field.FOLDER_ID)) {
        long folderId = GetterUtil.getLong(value);

        try {
            RepositoryEntry repositoryEntry = _repositoryEntryLocalService.fetchRepositoryEntry(folderId);

            if (repositoryEntry != null) {
                String objectId = repositoryEntry.getMappedId();

                objectId = CMISParameterValueUtil.formatParameterValue(field, objectId, wildcard, queryConfig);

                if (queryConfig.isSearchSubfolders()) {
                    cmisCriterion = new CMISInTreeExpression(objectId);
                } else {
                    cmisCriterion = new CMISInFolderExpression(objectId);
                }
            }
        } catch (SystemException se) {
            throw new SearchException("Unable to determine folder {folderId=" + folderId + "}", se);
        }
    } else if (field.equals(Field.USER_ID)) {
        try {
            long userId = GetterUtil.getLong(value);

            User user = _userLocalService.getUserById(userId);

            String screenName = CMISParameterValueUtil.formatParameterValue(field, user.getScreenName(),
                    wildcard, queryConfig);

            cmisCriterion = new CMISSimpleExpression(getCmisField(field), screenName,
                    cmisSimpleExpressionOperator);
        } catch (Exception e) {
            if (e instanceof SearchException) {
                throw (SearchException) e;
            }

            throw new SearchException("Unable to determine user {" + field + "=" + value + "}", e);
        }
    } else {
        value = CMISParameterValueUtil.formatParameterValue(field, value, wildcard, queryConfig);

        cmisCriterion = new CMISSimpleExpression(getCmisField(field), value, cmisSimpleExpressionOperator);
    }

    return cmisCriterion;
}

From source file:com.liferay.document.library.repository.external.ExtRepositoryQueryMapperImpl.java

License:Open Source License

@Override
public String formatParameterValue(String fieldName, String fieldValue) throws SearchException {

    if (fieldName.equals(Field.CREATE_DATE) || fieldName.equals(Field.MODIFIED_DATE)) {

        throw new SearchException(
                "Use the method formatDateParameterValue to format the date " + "field " + fieldName);
    } else if (fieldName.equals(Field.FOLDER_ID)) {
        try {// w  w w.ja v a 2 s  .  c  om
            long folderId = GetterUtil.getLong(fieldValue);

            return _extRepositoryAdapter.getExtRepositoryObjectKey(folderId);
        } catch (PortalException pe) {
            throw new SearchException("Unable to get folder folder " + fieldValue, pe);
        } catch (SystemException se) {
            throw new SearchException("Unable to get folder folder " + fieldValue, se);
        }
    } else if (fieldName.equals(Field.USER_ID)) {
        try {
            long userId = GetterUtil.getLong(fieldValue);

            User user = UserLocalServiceUtil.getUserById(userId);

            return user.getScreenName();
        } catch (Exception e) {
            throw new SearchException("Unable to get user user " + fieldValue, e);
        }
    } else {
        return fieldValue;
    }
}

From source file:com.liferay.exportimport.search.ExportImportConfigurationIndexer.java

License:Open Source License

@Override
protected Document doGetDocument(ExportImportConfiguration exportImportConfiguration) throws Exception {

    Document document = getBaseModelDocument(CLASS_NAME, exportImportConfiguration);

    document.addText(Field.DESCRIPTION, exportImportConfiguration.getDescription());
    document.addText(Field.NAME, exportImportConfiguration.getName());
    document.addKeyword(Field.TYPE, exportImportConfiguration.getType());
    document.addNumber("exportImportConfigurationId",
            exportImportConfiguration.getExportImportConfigurationId());

    Map<String, Serializable> settingsMap = exportImportConfiguration.getSettingsMap();

    populateDates(document, settingsMap);
    populateLayoutIds(document, settingsMap);
    populateLocale(document, settingsMap);
    populateParameterMap(document, settingsMap);
    populateSiteInformation(document, settingsMap);
    populateTimeZone(document, settingsMap);

    document.addKeyword(_PREFIX_SETTING + Field.USER_ID, MapUtil.getLong(settingsMap, "userId"));

    return document;
}

From source file:com.liferay.faces.demos.list.UserLazyDataModel.java

License:Open Source License

/**
 * This method is called by the PrimeFaces {@link DataTable} according to the rows specified in the currently
 * displayed page of data./*from  w w  w  .j  av  a2s .  c  o  m*/
 *
 * @param  first      The zero-relative first row index.
 * @param  pageSize   The number of rows to fetch.
 * @param  sortField  The name of the field which the table is sorted by.
 * @param  sortOrder  The sort order, which can be either ascending (default) or descending.
 * @param  filters    The query criteria. Note that in order for the filtering to work with the Liferay API, the
 *                    end-user must specify complete, matching words. Wildcards and partial matches are not
 *                    supported.
 */
@Override
public List<User> load(int first, int pageSize, String sortField, SortOrder sortOrder,
        Map<String, Object> filters) {

    List<User> users = null;

    Sort sort;

    // sort
    if (sortField != null) {

        if (sortOrder.equals(SortOrder.DESCENDING)) {
            sort = SortFactoryUtil.getSort(User.class, sortField, "desc");
        } else {
            sort = SortFactoryUtil.getSort(User.class, sortField, "asc");
        }
    } else {
        sort = SortFactoryUtil.getSort(User.class, DEFAULT_SORT_CRITERIA, "asc");
    }

    try {
        LinkedHashMap<String, Object> params = new LinkedHashMap<String, Object>();
        int liferayOneRelativeFinishRow = first + pageSize + 1;

        boolean andSearch = true;
        int status = WorkflowConstants.STATUS_ANY;

        String firstName = trimExpresssion((String) filters.get("firstName"));
        String middleName = trimExpresssion((String) filters.get("middleName"));
        String lastName = trimExpresssion((String) filters.get("lastName"));
        String screenName = trimExpresssion((String) filters.get("screenName"));
        String emailAddress = trimExpresssion((String) filters.get("emailAddress"));

        // For the sake of speed, search for users in the index rather than
        // querying the database directly.
        Hits hits = UserLocalServiceUtil.search(companyId, firstName, middleName, lastName, screenName,
                emailAddress, status, params, andSearch, first, liferayOneRelativeFinishRow, sort);

        List<Document> documentHits = hits.toList();

        logger.debug(
                ("filters firstName=[{0}] middleName=[{1}] lastName=[{2}] screenName=[{3}] emailAddress=[{4}] active=[{5}] andSearch=[{6}] startRow=[{7}] liferayOneRelativeFinishRow=[{8}] sortColumn=[{9}] reverseOrder=[{10}] hitCount=[{11}]"),
                firstName, middleName, lastName, screenName, emailAddress, status, andSearch, first,
                liferayOneRelativeFinishRow, sortField, sort.isReverse(), documentHits.size());

        // Convert the results from the search index into a list of user
        // objects.
        users = new ArrayList<User>(documentHits.size());

        for (Document document : documentHits) {

            long userId = GetterUtil.getLong(document.get(Field.USER_ID));

            try {
                User user = UserLocalServiceUtil.getUserById(userId);
                users.add(user);
            } catch (NoSuchUserException nsue) {
                logger.error("User with userId=[{0}] does not exist in the search index. Please reindex.");
            }
        }

    } catch (Exception e) {
        logger.error(e.getMessage(), e);
    }

    return users;

}

From source file:com.liferay.journal.service.impl.JournalArticleLocalServiceImpl.java

License:Open Source License

protected SearchContext buildSearchContext(long groupId, long userId, long creatorUserId, int status, int start,
        int end) throws PortalException {

    SearchContext searchContext = new SearchContext();

    searchContext.setAttribute(Field.STATUS, status);

    searchContext.setAttribute("paginationType", "none");

    if (creatorUserId > 0) {
        searchContext.setAttribute(Field.USER_ID, String.valueOf(creatorUserId));
    }//from   ww  w  .j  a  v a2  s. c  om

    Group group = groupLocalService.getGroup(groupId);

    searchContext.setCompanyId(group.getCompanyId());

    searchContext.setEnd(end);
    searchContext.setGroupIds(new long[] { groupId });
    searchContext.setSorts(new Sort(Field.MODIFIED_DATE, true));
    searchContext.setStart(start);
    searchContext.setUserId(userId);

    return searchContext;
}

From source file:com.liferay.portlet.documentlibrary.util.DLIndexer.java

License:Open Source License

@Override
protected Document doGetDocument(Object obj) throws Exception {
    DLFileEntry dlFileEntry = (DLFileEntry) obj;

    if (_log.isDebugEnabled()) {
        _log.debug("Indexing document " + dlFileEntry);
    }/*w  w  w  .  ja  va2 s .  com*/

    boolean indexContent = true;

    InputStream is = null;

    try {
        if (PropsValues.DL_FILE_INDEXING_MAX_SIZE == 0) {
            indexContent = false;
        } else if (PropsValues.DL_FILE_INDEXING_MAX_SIZE != -1) {
            if (dlFileEntry.getSize() > PropsValues.DL_FILE_INDEXING_MAX_SIZE) {

                indexContent = false;
            }
        }

        if (indexContent) {
            String[] ignoreExtensions = PrefsPropsUtil
                    .getStringArray(PropsKeys.DL_FILE_INDEXING_IGNORE_EXTENSIONS, StringPool.COMMA);

            if (ArrayUtil.contains(ignoreExtensions, StringPool.PERIOD + dlFileEntry.getExtension())) {

                indexContent = false;
            }
        }

        if (indexContent) {
            is = dlFileEntry.getFileVersion().getContentStream(false);
        }
    } catch (Exception e) {
    }

    if (indexContent && (is == null)) {
        if (_log.isDebugEnabled()) {
            _log.debug("Document " + dlFileEntry + " does not have any content");
        }

        return null;
    }

    try {
        Document document = new DocumentImpl();

        long fileEntryId = dlFileEntry.getFileEntryId();

        document.addUID(PORTLET_ID, fileEntryId);

        List<AssetCategory> assetCategories = AssetCategoryLocalServiceUtil
                .getCategories(DLFileEntry.class.getName(), fileEntryId);

        long[] assetCategoryIds = StringUtil
                .split(ListUtil.toString(assetCategories, AssetCategory.CATEGORY_ID_ACCESSOR), 0L);

        document.addKeyword(Field.ASSET_CATEGORY_IDS, assetCategoryIds);

        String[] assetCategoryNames = StringUtil
                .split(ListUtil.toString(assetCategories, AssetCategory.NAME_ACCESSOR));

        document.addKeyword(Field.ASSET_CATEGORY_NAMES, assetCategoryNames);

        String[] assetTagNames = AssetTagLocalServiceUtil.getTagNames(DLFileEntry.class.getName(), fileEntryId);

        document.addKeyword(Field.ASSET_TAG_NAMES, assetTagNames);

        document.addKeyword(Field.COMPANY_ID, dlFileEntry.getCompanyId());

        if (indexContent) {
            try {
                document.addFile(Field.CONTENT, is, dlFileEntry.getTitle());
            } catch (IOException ioe) {
                throw new SearchException("Cannot extract text from file" + dlFileEntry);
            }
        }

        document.addText(Field.DESCRIPTION, dlFileEntry.getDescription());
        document.addKeyword(Field.ENTRY_CLASS_NAME, DLFileEntry.class.getName());
        document.addKeyword(Field.ENTRY_CLASS_PK, fileEntryId);
        document.addKeyword(Field.FOLDER_ID, dlFileEntry.getFolderId());
        document.addKeyword(Field.GROUP_ID, getParentGroupId(dlFileEntry.getGroupId()));
        document.addDate(Field.MODIFIED_DATE, dlFileEntry.getModifiedDate());
        document.addKeyword(Field.PORTLET_ID, PORTLET_ID);
        document.addText(Field.PROPERTIES, dlFileEntry.getLuceneProperties());
        document.addKeyword(Field.SCOPE_GROUP_ID, dlFileEntry.getGroupId());

        DLFileVersion dlFileVersion = dlFileEntry.getFileVersion();

        document.addKeyword(Field.STATUS, dlFileVersion.getStatus());
        document.addText(Field.TITLE, dlFileEntry.getTitle());

        long userId = dlFileEntry.getUserId();

        document.addKeyword(Field.USER_ID, userId);
        document.addKeyword(Field.USER_NAME, PortalUtil.getUserName(userId, dlFileEntry.getUserName()), true);

        document.addKeyword("dataRepositoryId", dlFileEntry.getDataRepositoryId());
        document.addKeyword("extension", dlFileEntry.getExtension());
        document.addKeyword("fileEntryTypeId", dlFileEntry.getFileEntryTypeId());
        document.addKeyword("path", dlFileEntry.getTitle());

        ExpandoBridge expandoBridge = ExpandoBridgeFactoryUtil.getExpandoBridge(dlFileEntry.getCompanyId(),
                DLFileEntry.class.getName(), dlFileVersion.getFileVersionId());

        ExpandoBridgeIndexerUtil.addAttributes(document, expandoBridge);

        addFileEntryTypeAttributes(document, dlFileVersion);

        if (_log.isDebugEnabled()) {
            _log.debug("Document " + dlFileEntry + " indexed successfully");
        }

        return document;
    } finally {
        if (is != null) {
            try {
                is.close();
            } catch (IOException ioe) {
            }
        }
    }
}