001    /**
002     * Copyright (c) 2000-present Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portlet.trash.test;
016    
017    import com.liferay.portal.kernel.dao.orm.QueryUtil;
018    import com.liferay.portal.kernel.search.Hits;
019    import com.liferay.portal.kernel.search.Indexer;
020    import com.liferay.portal.kernel.search.IndexerRegistryUtil;
021    import com.liferay.portal.kernel.search.SearchContext;
022    import com.liferay.portal.kernel.test.util.SearchContextTestUtil;
023    import com.liferay.portal.service.ServiceContext;
024    import com.liferay.portlet.trash.service.TrashEntryLocalServiceUtil;
025    
026    /**
027     * @author Cristina Gonz??lez
028     */
029    public class DefaultWhenIsIndexableBaseModel
030            implements WhenIsIndexableBaseModel {
031    
032            @Override
033            public String getSearchKeywords() {
034                    return "Title";
035            }
036    
037            @Override
038            public int searchBaseModelsCount(Class<?> clazz, long groupId)
039                    throws Exception {
040    
041                    Indexer<?> indexer = IndexerRegistryUtil.getIndexer(clazz);
042    
043                    SearchContext searchContext = SearchContextTestUtil.getSearchContext();
044    
045                    searchContext.setGroupIds(new long[] {groupId});
046    
047                    Hits results = indexer.search(searchContext);
048    
049                    return results.getLength();
050            }
051    
052            @Override
053            public int searchTrashEntriesCount(
054                            String keywords, ServiceContext serviceContext)
055                    throws Exception {
056    
057                    Hits results = TrashEntryLocalServiceUtil.search(
058                            serviceContext.getCompanyId(), serviceContext.getScopeGroupId(),
059                            serviceContext.getUserId(), keywords, QueryUtil.ALL_POS,
060                            QueryUtil.ALL_POS, null);
061    
062                    return results.getLength();
063            }
064    
065    }