Project

General

Profile

« Previous | Next » 

Revision 26ab7583

Added by Andreas Müller over 5 years ago

ref #7745 add subtree filter to taxon search (not yet tested for subtree != null)

View differences:

cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/persistence/dao/hibernate/taxon/TaxonDaoHibernateImpl.java
151 151
        return result;
152 152
    }
153 153

  
154
    //TODO needed? Currently only used by tests.
154 155
    public List<TaxonBase> getTaxaByName(boolean doTaxa, boolean doSynonyms, boolean includeUnpublished,
155 156
            String queryString, MatchMode matchMode, Integer pageSize, Integer pageNumber) {
156 157
        return getTaxaByName(doTaxa, doSynonyms, false, false, false,
157
                queryString, null, matchMode, null, includeUnpublished, null, pageSize, pageNumber, null);
158
                queryString, null, null, matchMode, null, includeUnpublished, null, pageSize, pageNumber, null);
158 159
    }
159 160

  
160 161
    @Override
......
175 176
    @Override
176 177
    public List<TaxonBase> getTaxaByName(boolean doTaxa, boolean doSynonyms, boolean doMisappliedNames, boolean doCommonNames,
177 178
            boolean includeAuthors,
178
            String queryString, Classification classification,
179
            String queryString, Classification classification, TaxonNode subtree,
179 180
            MatchMode matchMode, Set<NamedArea> namedAreas, boolean includeUnpublished, NameSearchOrder order,
180 181
            Integer pageSize, Integer pageNumber, List<String> propertyPaths) {
181 182

  
182 183
        boolean doCount = false;
183 184

  
184 185
        String searchField = includeAuthors ? "titleCache" : "nameCache";
185
        Query query = prepareTaxaByName(doTaxa, doSynonyms, doMisappliedNames, doCommonNames, includeUnpublished, searchField, queryString, classification, matchMode, namedAreas, order, pageSize, pageNumber, doCount);
186
        Query query = prepareTaxaByName(doTaxa, doSynonyms, doMisappliedNames, doCommonNames, includeUnpublished, searchField, queryString, classification, subtree, matchMode, namedAreas, order, pageSize, pageNumber, doCount);
186 187

  
187 188
        if (query != null){
188 189
            @SuppressWarnings({ "unchecked", "rawtypes" })
......
204 205
    @Override
205 206
    @SuppressWarnings("unchecked")
206 207
    public List<UuidAndTitleCache<? extends IdentifiableEntity>> getTaxaByNameForEditor(boolean doTaxa, boolean doSynonyms, boolean doNamesWithoutTaxa,
207
            boolean doMisappliedNames, boolean doCommonNames, boolean includeUnpublished, String queryString, Classification classification,
208
            boolean doMisappliedNames, boolean doCommonNames, boolean includeUnpublished, String queryString, Classification classification, TaxonNode subtree,
208 209
            MatchMode matchMode, Set<NamedArea> namedAreas, NameSearchOrder order) {
209 210

  
210 211
        if (order == null){
......
230 231
        	}
231 232
        }
232 233
        Query query = prepareTaxaByNameForEditor(doTaxa, doSynonyms, doMisappliedNames, doCommonNames, includeUnpublished,
233
                "nameCache", queryString, classification, matchMode, namedAreas, doCount, order);
234
                "nameCache", queryString, classification, subtree, matchMode, namedAreas, doCount, order);
234 235

  
235 236
        if (query != null){
236 237
            List<Object[]> results = query.list();
......
291 292
     *
292 293
     */
293 294
    private Query prepareTaxaByNameForEditor(boolean doTaxa, boolean doSynonyms, boolean doMisappliedNames, boolean doCommonNames,
294
            boolean includeUnpublished, String searchField, String queryString, Classification classification,
295
            boolean includeUnpublished, String searchField, String queryString, Classification classification, TaxonNode subtree,
295 296
            MatchMode matchMode, Set<NamedArea> namedAreas, boolean doCount, NameSearchOrder order) {
296 297
        return prepareByNameQuery(doTaxa, doSynonyms, doMisappliedNames, doCommonNames, includeUnpublished,
297 298
                searchField, queryString,
298
                classification, matchMode, namedAreas, order, doCount, true);
299
                classification, subtree, matchMode, namedAreas, order, doCount, true);
299 300
    }
300 301

  
301 302

  
......
320 321
     */
321 322
    private Query prepareByNameQuery(boolean doTaxa, boolean doSynonyms, boolean doMisappliedNames,
322 323
                boolean doCommonNames, boolean includeUnpublished, String searchField, String queryString,
323
                Classification classification, MatchMode matchMode, Set<NamedArea> namedAreas,
324
                Classification classification, TaxonNode subtree, MatchMode matchMode, Set<NamedArea> namedAreas,
324 325
                NameSearchOrder order, boolean doCount, boolean returnIdAndTitle){
325 326

  
326 327
            boolean doProParteSynonyms = doSynonyms;  //we may distinguish in future
......
356 357
            }
357 358

  
358 359
            Subselects subSelects = createByNameHQLString(doConceptRelations,
359
                    includeUnpublished, classification, areasExpanded, matchMode, searchField);
360
                    includeUnpublished, classification, subtree, areasExpanded, matchMode, searchField);
360 361
            String taxonSubselect = subSelects.taxonSubselect;
361 362
            String synonymSubselect = subSelects.synonymSubselect;
362 363
            String conceptSelect = subSelects.conceptSelect;
......
546 547
     */
547 548
    private Query prepareTaxaByName(boolean doTaxa, boolean doSynonyms, boolean doMisappliedNames,
548 549
            boolean doCommonNames, boolean includeUnpublished, String searchField, String queryString,
549
            Classification classification, MatchMode matchMode, Set<NamedArea> namedAreas, NameSearchOrder order, Integer pageSize, Integer pageNumber, boolean doCount) {
550
            Classification classification, TaxonNode subtree, MatchMode matchMode, Set<NamedArea> namedAreas, NameSearchOrder order, Integer pageSize, Integer pageNumber, boolean doCount) {
550 551

  
551 552
        Query query = prepareByNameQuery(doTaxa, doSynonyms, doMisappliedNames, doCommonNames, includeUnpublished,
552
                searchField, queryString, classification, matchMode, namedAreas, order, doCount, false);
553
                searchField, queryString, classification, subtree, matchMode, namedAreas, order, doCount, false);
553 554

  
554 555
        if(pageSize != null && !doCount && query != null) {
555 556
            query.setMaxResults(pageSize);
......
592 593

  
593 594
    @Override
594 595
    public long countTaxaByName(boolean doTaxa, boolean doSynonyms, boolean doMisappliedNames, boolean doCommonNames,
595
            boolean doIncludeAuthors, String queryString, Classification classification,
596
            boolean doIncludeAuthors, String queryString, Classification classification, TaxonNode subtree,
596 597
        MatchMode matchMode, Set<NamedArea> namedAreas, boolean includeUnpublished) {
597 598

  
598 599
        boolean doCount = true;
......
608 609
        String searchField = doIncludeAuthors ? "titleCache": "nameCache";
609 610

  
610 611
        Query query = prepareTaxaByName(doTaxa, doSynonyms, doMisappliedNames, doCommonNames, includeUnpublished,
611
                searchField, queryString, classification, matchMode, namedAreas, null, null, null, doCount);
612
                searchField, queryString, classification, subtree, matchMode, namedAreas, null, null, null, doCount);
612 613
        if (query != null) {
613 614
            return (Long)query.uniqueResult();
614 615
        }else{
......
665 666
    }
666 667

  
667 668
    @Override
668
    public List<TaxonBase> findByNameTitleCache(boolean doTaxa, boolean doSynonyms, boolean includeUnpublished, String queryString, Classification classification, MatchMode matchMode, Set<NamedArea> namedAreas, NameSearchOrder order, Integer pageNumber, Integer pageSize, List<String> propertyPaths) {
669
    public List<TaxonBase> findByNameTitleCache(boolean doTaxa, boolean doSynonyms, boolean includeUnpublished, String queryString, Classification classification, TaxonNode subtree, MatchMode matchMode, Set<NamedArea> namedAreas, NameSearchOrder order, Integer pageNumber, Integer pageSize, List<String> propertyPaths) {
669 670

  
670 671
        boolean doCount = false;
671
        Query query = prepareTaxaByName(doTaxa, doSynonyms, false, false, includeUnpublished, "titleCache", queryString, classification, matchMode, namedAreas, order, pageSize, pageNumber, doCount);
672
        Query query = prepareTaxaByName(doTaxa, doSynonyms, false, false, includeUnpublished, "titleCache", queryString, classification, subtree, matchMode, namedAreas, order, pageSize, pageNumber, doCount);
672 673
        if (query != null){
673 674
            @SuppressWarnings({ "unchecked", "rawtypes" })
674 675
            List<TaxonBase> results = query.list();
......
1444 1445
    }
1445 1446

  
1446 1447
    private Subselects createByNameHQLString(boolean doConceptRelations,
1447
                boolean includeUnpublished, Classification classification,  Set<NamedArea> areasExpanded,
1448
                MatchMode matchMode, String searchField){
1448
                boolean includeUnpublished, Classification classification, TaxonNode subtree,
1449
                Set<NamedArea> areasExpanded, MatchMode matchMode, String searchField){
1449 1450

  
1450 1451
        boolean doAreaRestriction = areasExpanded.size() > 0;
1451 1452
        String doAreaRestrictionSubSelect =
......
1489 1490
                   " LEFT JOIN com.feature f ";
1490 1491

  
1491 1492

  
1492
        String doClassificationWhere = " tn.classification = :classification";
1493
        String doClassificationForConceptRelationsWhere = " tn2.classification = :classification";
1493
        String doTreeWhere = classification == null ? "" : " AND tn.classification = :classification";
1494
        String doTreeForConceptRelationsWhere = classification == null ? "": " AND tn2.classification = :classification";
1495

  
1496
        String doSubtreeWhere = subtree == null? "":" AND tn.treeIndex like :treeIndexLike";
1497
        String doSubtreeForConceptRelationsWhere = subtree == null? "":" AND tn2.treeindex like :treeIndexLike";
1494 1498

  
1495 1499
        String doAreaRestrictionWhere =  " e.area.uuid in (:namedAreasUuids)";
1496 1500
        String doCommonNamesRestrictionWhere = " (f.supportsCommonTaxonName = true and com.name "+matchMode.getMatchOperator()+" :queryString )";
......
1504 1508
        String conceptSelect = null;
1505 1509
        String commonNameSubselect = null;
1506 1510

  
1507
        if(classification != null ){
1511
        if(classification != null || subtree != null){
1508 1512
            if (!doConceptRelations){
1509 1513
                if(doAreaRestriction){
1510 1514
                    taxonSubselect = String.format(doAreaRestrictionSubSelect, "t") + doTaxonNameJoin +
1511
                            " WHERE " + doAreaRestrictionWhere +
1512
                            "  AND " + doClassificationWhere +
1515
                            " WHERE (1=1) AND " + doAreaRestrictionWhere +
1516
                                doTreeWhere + doSubtreeWhere +
1513 1517
                            "  AND " + String.format(doSearchFieldWhere, "n");
1514 1518
                    synonymSubselect = String.format(doAreaRestrictionSubSelect, "s") + doSynonymNameJoin +
1515
                            " WHERE " + doAreaRestrictionWhere +
1516
                            "  AND " + doClassificationWhere +
1519
                            " WHERE (1=1) AND " + doAreaRestrictionWhere +
1520
                                doTreeWhere + doSubtreeWhere +
1517 1521
                            "  AND " + String.format(doSearchFieldWhere, "sn");
1518 1522
                    commonNameSubselect =  String.format(doAreaRestrictionSubSelect, "t") + doCommonNamesJoin +
1519
                            " WHERE " +  doAreaRestrictionWhere +
1520
                            "  AND " + doClassificationWhere +
1523
                            " WHERE (1=1) AND " +  doAreaRestrictionWhere +
1524
                                 doTreeWhere + doSubtreeWhere +
1521 1525
                            "  AND " + String.format(doSearchFieldWhere, "n") +
1522 1526
                            "  AND " + doCommonNamesRestrictionWhere;
1523 1527
                } else {//no area restriction
1524 1528
                    taxonSubselect = String.format(doTaxonSubSelect, "t" )+ doTaxonNameJoin +
1525
                            " WHERE " + doClassificationWhere +
1529
                            " WHERE (1=1) " + doTreeWhere + doSubtreeWhere +
1526 1530
                            "  AND " + String.format(doSearchFieldWhere, "n");
1527 1531
                    synonymSubselect = String.format(doTaxonSubSelect, "s" ) + doSynonymNameJoin +
1528
                            " WHERE " + doClassificationWhere +
1532
                            " WHERE (1=1) " + doTreeWhere + doSubtreeWhere +
1529 1533
                            "  AND " + String.format(doSearchFieldWhere, "sn");
1530 1534
                    commonNameSubselect =String.format(doTaxonSubSelect, "t" )+ doCommonNamesJoin +
1531
                            " WHERE " + doClassificationWhere +
1535
                            " WHERE (1=1) " + doTreeWhere + doSubtreeWhere +
1532 1536
                            "  AND " + doCommonNamesRestrictionWhere;
1533 1537
                }
1534 1538
            }else{ //concept relations included
......
1536 1540
                    conceptSelect = String.format(doAreaRestrictionConceptRelationSubSelect, "t") + doTaxonNameJoin + doConceptRelationJoin  +
1537 1541
                            " WHERE " + doAreaRestrictionWhere +
1538 1542
                            "  AND " + String.format(doSearchFieldWhere, "n") +
1539
                            "  AND " + doClassificationForConceptRelationsWhere +
1543
                                 doTreeForConceptRelationsWhere + doSubtreeForConceptRelationsWhere +
1540 1544
                            "  AND " + doRelationshipTypeComparison;
1541 1545
                    taxonSubselect = String.format(doAreaRestrictionSubSelect, "t") + doTaxonNameJoin +
1542 1546
                            " WHERE " + doAreaRestrictionWhere +
1543 1547
                            "  AND " + String.format(doSearchFieldWhere, "n") +
1544
                            "  AND " + doClassificationWhere;
1548
                                doTreeWhere + doSubtreeWhere;
1545 1549
                    synonymSubselect = String.format(doAreaRestrictionSubSelect, "s") + doSynonymNameJoin +
1546 1550
                            " WHERE " + doAreaRestrictionWhere +
1547
                            "  AND " + doClassificationWhere +
1551
                                doTreeWhere + doSubtreeWhere +
1548 1552
                            "  AND " + String.format(doSearchFieldWhere, "sn");
1549 1553
                    commonNameSubselect= String.format(doAreaRestrictionSubSelect, "t")+ doCommonNamesJoin +
1550 1554
                            " WHERE " + doAreaRestrictionWhere +
1551
                            "  AND " + doClassificationWhere +
1555
                                doTreeWhere + doSubtreeWhere +
1552 1556
                            "  AND " + doCommonNamesRestrictionWhere;
1553 1557
                } else {//no area restriction
1554 1558
                    conceptSelect = String.format(doTaxonMisappliedNameSubSelect, "t" ) + doTaxonNameJoin + doConceptRelationJoin +
1555 1559
                            " WHERE " + String.format(doSearchFieldWhere, "n") +
1556
                            "  AND " + doClassificationForConceptRelationsWhere +
1560
                                  doTreeForConceptRelationsWhere + doSubtreeForConceptRelationsWhere +
1557 1561
                            "  AND " + doRelationshipTypeComparison;
1558 1562
                    taxonSubselect = String.format(doTaxonSubSelect, "t" ) + doTaxonNameJoin +
1559 1563
                            " WHERE " +  String.format(doSearchFieldWhere, "n") +
1560
                            " AND "+ doClassificationWhere;
1564
                                 doTreeWhere + doSubtreeWhere;
1561 1565
                    synonymSubselect = String.format(doTaxonSubSelect, "s" ) + doSynonymNameJoin +
1562
                            " WHERE " + doClassificationWhere +
1566
                            " WHERE (1=1) " + doTreeWhere + doSubtreeWhere +
1563 1567
                            "  AND " +  String.format(doSearchFieldWhere, "sn");
1564 1568
                    commonNameSubselect= String.format(doTaxonSubSelect, "t")+ doCommonNamesJoin +
1565
                            " WHERE " + doClassificationWhere +
1569
                            " WHERE (1=1) " + doTreeWhere + doSubtreeWhere +
1566 1570
                            "  AND " + doCommonNamesRestrictionWhere;
1567 1571
                }
1568 1572
            }
1569
        } else { //classification = null
1573
        } else { //classification = null && subtree = null
1570 1574
            if(doAreaRestriction){
1571 1575
                conceptSelect = String.format(doAreaRestrictionConceptRelationSubSelect, "t") + doTaxonNameJoin + doConceptRelationJoin +
1572 1576
                        " WHERE " + doAreaRestrictionWhere +

Also available in: Unified diff