Search in sources :

Example 1 with DefaultPagerImpl

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);
    }
}
Also used : CdmApplicationAwareDefaultExport(eu.etaxonomy.cdm.io.common.CdmApplicationAwareDefaultExport) DefaultPagerImpl(eu.etaxonomy.cdm.api.service.pager.impl.DefaultPagerImpl) PagerParameters(eu.etaxonomy.cdm.remote.controller.util.PagerParameters) CsvDemoExportConfigurator(eu.etaxonomy.cdm.io.csv.redlist.demo.CsvDemoExportConfigurator) ArrayList(java.util.ArrayList) ModelAndView(org.springframework.web.servlet.ModelAndView) Resource(org.springframework.core.io.Resource) IOException(java.io.IOException) CsvDemoRecord(eu.etaxonomy.cdm.io.csv.redlist.demo.CsvDemoRecord) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with DefaultPagerImpl

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;
}
Also used : DefaultPagerImpl(eu.etaxonomy.cdm.api.service.pager.impl.DefaultPagerImpl) PagerParameters(eu.etaxonomy.cdm.remote.controller.util.PagerParameters)

Example 3 with DefaultPagerImpl

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);
}
Also used : DefaultPagerImpl(eu.etaxonomy.cdm.api.service.pager.impl.DefaultPagerImpl) HomotypicGroupTaxonComparator(eu.etaxonomy.cdm.compare.taxon.HomotypicGroupTaxonComparator) TaxonComparator(eu.etaxonomy.cdm.compare.taxon.TaxonComparator) ArrayList(java.util.ArrayList) Transactional(org.springframework.transaction.annotation.Transactional)

Example 4 with DefaultPagerImpl

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);
}
Also used : IdentifiableEntity(eu.etaxonomy.cdm.model.common.IdentifiableEntity) DefaultPagerImpl(eu.etaxonomy.cdm.api.service.pager.impl.DefaultPagerImpl) ArrayList(java.util.ArrayList) OrderHint(eu.etaxonomy.cdm.persistence.query.OrderHint) TaxonBase(eu.etaxonomy.cdm.model.taxon.TaxonBase) CommonTaxonName(eu.etaxonomy.cdm.model.description.CommonTaxonName) TaxonName(eu.etaxonomy.cdm.model.name.TaxonName)

Example 5 with DefaultPagerImpl

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);
}
Also used : LuceneParseException(eu.etaxonomy.cdm.api.service.search.LuceneParseException) DefaultPagerImpl(eu.etaxonomy.cdm.api.service.pager.impl.DefaultPagerImpl) HashMap(java.util.HashMap) ISearchResultBuilder(eu.etaxonomy.cdm.api.service.search.ISearchResultBuilder) SearchResultBuilder(eu.etaxonomy.cdm.api.service.search.SearchResultBuilder) SearchResult(eu.etaxonomy.cdm.api.service.search.SearchResult) OrderHint(eu.etaxonomy.cdm.persistence.query.OrderHint) LuceneSearch(eu.etaxonomy.cdm.api.service.search.LuceneSearch) LuceneMultiSearch(eu.etaxonomy.cdm.api.service.search.LuceneMultiSearch) LuceneParseException(eu.etaxonomy.cdm.api.service.search.LuceneParseException) ParseException(org.apache.lucene.queryparser.classic.ParseException) ISearchResultBuilder(eu.etaxonomy.cdm.api.service.search.ISearchResultBuilder) CdmBaseType(eu.etaxonomy.cdm.model.CdmBaseType) BytesRef(org.apache.lucene.util.BytesRef)

Aggregations

DefaultPagerImpl (eu.etaxonomy.cdm.api.service.pager.impl.DefaultPagerImpl)22 ArrayList (java.util.ArrayList)15 OrderHint (eu.etaxonomy.cdm.persistence.query.OrderHint)7 ISearchResultBuilder (eu.etaxonomy.cdm.api.service.search.ISearchResultBuilder)6 LuceneParseException (eu.etaxonomy.cdm.api.service.search.LuceneParseException)6 LuceneSearch (eu.etaxonomy.cdm.api.service.search.LuceneSearch)6 SearchResult (eu.etaxonomy.cdm.api.service.search.SearchResult)6 SearchResultBuilder (eu.etaxonomy.cdm.api.service.search.SearchResultBuilder)6 CdmBaseType (eu.etaxonomy.cdm.model.CdmBaseType)6 HashMap (java.util.HashMap)6 ParseException (org.apache.lucene.queryparser.classic.ParseException)6 BytesRef (org.apache.lucene.util.BytesRef)6 Taxon (eu.etaxonomy.cdm.model.taxon.Taxon)5 TaxonName (eu.etaxonomy.cdm.model.name.TaxonName)4 TaxonBase (eu.etaxonomy.cdm.model.taxon.TaxonBase)4 HomotypicGroupTaxonComparator (eu.etaxonomy.cdm.compare.taxon.HomotypicGroupTaxonComparator)3 TaxonNode (eu.etaxonomy.cdm.model.taxon.TaxonNode)3 LuceneMultiSearch (eu.etaxonomy.cdm.api.service.search.LuceneMultiSearch)2 TaxonComparator (eu.etaxonomy.cdm.compare.taxon.TaxonComparator)2 LSID (eu.etaxonomy.cdm.model.common.LSID)2