com.liferay.trash.test.util.DefaultWhenIsIndexableBaseModel.java Source code

Java tutorial

Introduction

Here is the source code for com.liferay.trash.test.util.DefaultWhenIsIndexableBaseModel.java

Source

/**
 * 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.trash.test.util;

import com.liferay.portal.kernel.dao.orm.QueryUtil;
import com.liferay.portal.kernel.search.Hits;
import com.liferay.portal.kernel.search.Indexer;
import com.liferay.portal.kernel.search.IndexerRegistryUtil;
import com.liferay.portal.kernel.search.SearchContext;
import com.liferay.portal.kernel.service.ServiceContext;
import com.liferay.portal.kernel.test.util.SearchContextTestUtil;
import com.liferay.trash.service.TrashEntryLocalServiceUtil;

/**
 * @author Cristina Gonzlez
 */
public class DefaultWhenIsIndexableBaseModel implements WhenIsIndexableBaseModel {

    @Override
    public String getSearchKeywords() {
        return "Title";
    }

    @Override
    public int searchBaseModelsCount(Class<?> clazz, long groupId) throws Exception {

        Indexer<?> indexer = IndexerRegistryUtil.getIndexer(clazz);

        SearchContext searchContext = SearchContextTestUtil.getSearchContext();

        searchContext.setGroupIds(new long[] { groupId });

        Hits results = indexer.search(searchContext);

        return results.getLength();
    }

    @Override
    public int searchTrashEntriesCount(String keywords, ServiceContext serviceContext) throws Exception {

        Hits results = TrashEntryLocalServiceUtil.search(serviceContext.getCompanyId(),
                serviceContext.getScopeGroupId(), serviceContext.getUserId(), keywords, QueryUtil.ALL_POS,
                QueryUtil.ALL_POS, null);

        return results.getLength();
    }

}