use of eu.etaxonomy.cdm.api.service.pager.impl.DefaultPagerImpl in project cdmlib by cybertaxonomy.
the class ChecklistDemoController method doGeneralExport.
/**
* This service endpoint generates a json and xml view of the exported list.
* It takes advantage of pagination.
*
* @param classification uuid of the classification to export
* @param pageIndex
* @param pageSize
* @param response
* @param request
* @return
* @throws IOException
*/
@RequestMapping(value = { "export" }, method = { RequestMethod.GET })
public ModelAndView doGeneralExport(@RequestParam(value = "classification", required = false) String classificationUUID, @RequestParam(value = "pageIndex", required = false) Integer pageIndex, @RequestParam(value = "pageSize", required = false) Integer pageSize, HttpServletResponse response, HttpServletRequest request) throws IOException {
try {
if (pageSize == null) {
pageSize = 20;
}
if (pageIndex == null) {
pageIndex = 0;
}
PagerParameters pagerParams = new PagerParameters(pageSize, pageIndex);
pagerParams.normalizeAndValidate(response);
List<CsvDemoRecord> recordList = new ArrayList<>();
CsvDemoExportConfigurator config = setTaxExportConfigurator(null, classificationUUID, null, null, null, false, false);
config.setPageSize(pagerParams.getPageSize());
config.setPageNumber(pagerParams.getPageIndex());
config.setRecordList(recordList);
@SuppressWarnings("unchecked") CdmApplicationAwareDefaultExport<CsvDemoExportConfigurator> defaultExport = (CdmApplicationAwareDefaultExport<CsvDemoExportConfigurator>) appContext.getBean("defaultExport");
defaultExport.invoke(config);
DefaultPagerImpl<CsvDemoRecord> dpi = new DefaultPagerImpl<>(pagerParams.getPageIndex(), config.getTaxonNodeListSize(), pagerParams.getPageSize(), recordList);
ModelAndView mv = new ModelAndView();
// mv.addObject(recordList);f
mv.addObject(dpi);
return mv;
} catch (Exception e) {
Resource resource = resourceLoader.getResource("classpath:eu/etaxonomy/cdm/doc/remote/apt/checklist-catalogue-export.apt");
return exportGetExplanation(response, request, resource);
}
}
use of eu.etaxonomy.cdm.api.service.pager.impl.DefaultPagerImpl in project cdmlib by cybertaxonomy.
the class AbstractController method pagerForSubCollectionOf.
protected <T extends CdmBase> Pager<T> pagerForSubCollectionOf(Collection<T> c, Integer pageNumber, Integer pageSize, HttpServletResponse response) throws IOException {
PagerParameters pagerParameters = new PagerParameters(pageSize, pageNumber);
pagerParameters.normalizeAndValidate(response);
int subCollectionStart = pagerParameters.getPageIndex() * pagerParameters.getPageSize();
List<T> sub_c = subCollection(c, subCollectionStart, pagerParameters.getPageSize());
Pager<T> p = new DefaultPagerImpl<>(pageNumber, c.size(), pagerParameters.getPageSize(), sub_c);
return p;
}
use of eu.etaxonomy.cdm.api.service.pager.impl.DefaultPagerImpl in project cdmlib by cybertaxonomy.
the class TaxonServiceImpl method findByTitleWithRestrictions.
@Transactional(readOnly = true)
@Override
public <S extends TaxonBase> Pager<S> findByTitleWithRestrictions(Class<S> clazz, String queryString, MatchMode matchmode, List<Restriction<?>> restrictions, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths) {
long numberOfResults = dao.countByTitleWithRestrictions(clazz, queryString, matchmode, restrictions);
long numberOfResults_doubtful = dao.countByTitleWithRestrictions(clazz, "?".concat(queryString), matchmode, restrictions);
List<S> results = new ArrayList<>();
if (numberOfResults > 0 || numberOfResults_doubtful > 0) {
// no point checking again //TODO use AbstractPagerImpl.hasResultsInRange(numberOfResults, pageNumber, pageSize)
results = dao.findByTitleWithRestrictions(clazz, queryString, matchmode, restrictions, pageSize, pageNumber, orderHints, propertyPaths);
results.addAll(dao.findByTitleWithRestrictions(clazz, "?".concat(queryString), matchmode, restrictions, pageSize, pageNumber, orderHints, propertyPaths));
}
Collections.sort(results, new TaxonComparator());
return new DefaultPagerImpl<>(pageNumber, numberOfResults, pageSize, results);
}
use of eu.etaxonomy.cdm.api.service.pager.impl.DefaultPagerImpl in project cdmlib by cybertaxonomy.
the class TaxonServiceImpl method findTaxaAndNames.
@Override
public Pager<IdentifiableEntity> findTaxaAndNames(IFindTaxaAndNamesConfigurator configurator) {
@SuppressWarnings("rawtypes") List<IdentifiableEntity> results = new ArrayList<>();
// overall number of results (as opposed to number of results per page)
long numberOfResults = 0;
List<TaxonBase> taxa = null;
// Taxa and synonyms
long numberTaxaResults = 0L;
List<String> propertyPath = new ArrayList<>();
if (configurator.getTaxonPropertyPath() != null) {
propertyPath.addAll(configurator.getTaxonPropertyPath());
}
if (configurator.isDoMisappliedNames() || configurator.isDoSynonyms() || configurator.isDoTaxa() || configurator.isDoTaxaByCommonNames()) {
if (configurator.getPageSize() != null) {
// no point counting if we need all anyway
numberTaxaResults = dao.countTaxaByName(configurator.isDoTaxa(), configurator.isDoSynonyms(), configurator.isDoMisappliedNames(), configurator.isDoTaxaByCommonNames(), configurator.isDoIncludeAuthors(), configurator.getTitleSearchStringSqlized(), configurator.getClassification(), configurator.getSubtree(), configurator.getMatchMode(), configurator.getNamedAreas(), configurator.isIncludeUnpublished());
}
if (configurator.getPageSize() == null || numberTaxaResults > configurator.getPageSize() * configurator.getPageNumber()) {
// no point checking again if less results
taxa = dao.getTaxaByName(configurator.isDoTaxa(), configurator.isDoSynonyms(), configurator.isDoMisappliedNames(), configurator.isDoTaxaByCommonNames(), configurator.isDoIncludeAuthors(), configurator.getTitleSearchStringSqlized(), configurator.getClassification(), configurator.getSubtree(), configurator.getMatchMode(), configurator.getNamedAreas(), configurator.isIncludeUnpublished(), configurator.getOrder(), configurator.getPageSize(), configurator.getPageNumber(), propertyPath);
}
}
if (logger.isDebugEnabled()) {
logger.debug(numberTaxaResults + " matching taxa counted");
}
if (taxa != null) {
results.addAll(taxa);
}
numberOfResults += numberTaxaResults;
// Names without taxa
if (configurator.isDoNamesWithoutTaxa()) {
int numberNameResults = 0;
List<TaxonName> names = nameDao.findByName(configurator.isDoIncludeAuthors(), configurator.getTitleSearchStringSqlized(), configurator.getMatchMode(), configurator.getPageSize(), configurator.getPageNumber(), null, configurator.getTaxonNamePropertyPath());
if (logger.isDebugEnabled()) {
logger.debug(names.size() + " matching name(s) found");
}
if (names.size() > 0) {
for (TaxonName taxonName : names) {
if (taxonName.getTaxonBases().size() == 0) {
results.add(taxonName);
numberNameResults++;
}
}
if (logger.isDebugEnabled()) {
logger.debug(numberNameResults + " matching name(s) without taxa found");
}
numberOfResults += numberNameResults;
}
}
return new DefaultPagerImpl<>(configurator.getPageNumber(), numberOfResults, configurator.getPageSize(), results);
}
use of eu.etaxonomy.cdm.api.service.pager.impl.DefaultPagerImpl in project cdmlib by cybertaxonomy.
the class TaxonServiceImpl method findByEverythingFullText.
@Override
public Pager<SearchResult<TaxonBase>> findByEverythingFullText(String queryString, Classification classification, TaxonNode subtree, boolean includeUnpublished, List<Language> languages, boolean highlightFragments, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths) throws IOException, LuceneParseException, LuceneMultiSearchException {
LuceneSearch luceneSearchByDescriptionElement = prepareByDescriptionElementFullTextSearch(null, queryString, classification, subtree, null, languages, highlightFragments);
LuceneSearch luceneSearchByTaxonBase = prepareFindByFullTextSearch(null, queryString, classification, subtree, null, includeUnpublished, languages, highlightFragments, null);
LuceneMultiSearch multiSearch = new LuceneMultiSearch(luceneIndexToolProvider, luceneSearchByDescriptionElement, luceneSearchByTaxonBase);
// --- execute search
TopGroups<BytesRef> topDocsResultSet;
try {
topDocsResultSet = multiSearch.executeSearch(pageSize, pageNumber);
} catch (ParseException e) {
LuceneParseException luceneParseException = new LuceneParseException(e.getMessage());
luceneParseException.setStackTrace(e.getStackTrace());
throw luceneParseException;
}
// --- initialize taxa, highlight matches ....
ISearchResultBuilder searchResultBuilder = new SearchResultBuilder(multiSearch, multiSearch.getQuery());
Map<CdmBaseType, String> idFieldMap = new HashMap<>();
idFieldMap.put(CdmBaseType.TAXON_BASE, "id");
idFieldMap.put(CdmBaseType.DESCRIPTION_ELEMENT, "inDescription.taxon.id");
List<SearchResult<TaxonBase>> searchResults = searchResultBuilder.createResultSet(topDocsResultSet, multiSearch.getHighlightFields(), dao, idFieldMap, propertyPaths);
int totalHits = topDocsResultSet != null ? topDocsResultSet.totalGroupCount : 0;
return new DefaultPagerImpl<>(pageNumber, Long.valueOf(totalHits), pageSize, searchResults);
}
Aggregations