Project

General

Profile

Revision 177a283a

ID177a283a6184b5ca5ab3344042317f1f96db3b31
Parent cc95089b
Child 4e6f5b53

Added by Katja Luther over 3 years ago

fix #6296: fix the parameter settings in search queries

View differences:

cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/persistence/dao/hibernate/taxon/TaxonDaoHibernateImpl.java
404 404
                taxa.addAll(subCommonNames.list());
405 405
            }
406 406

  
407
            //FIXME : the fourth element of the result should be a boolean, but in the case of a synonym
408
            // (which does require a check) a constant boolean (false) value needs to set. It seems that
409
            // hql cannot parse a constant boolean value in the select list clause. This implies that the
410
            // resulting object could be a Boolean or a String. The workaround for this is to convert the
411
            // resutling object into a String (using toString) and then create a new Boolean object from
412
            // String.
413
            if (doTaxa && doSynonyms){
407

  
408
           // if (doTaxa && doSynonyms){
414 409
                if(synonyms.size()>0 && taxa.size()>0){
415 410
                    hql = "select " + selectWhat;
416 411
                    // in doNotReturnFullEntities mode it is nesscary to also return the type of the matching entities:
......
446 441
                } else{
447 442
                    hql = "select " + selectWhat + " from %s t";
448 443
                }
449
            } else if(doTaxa || doCommonNames){
450
                if  (taxa.size()>0){
451
                    hql = "select " + selectWhat;
452
                    // in doNotReturnFullEntities mode it is nesscary to also return the type of the matching entities:
453
                    // also return the computed isOrphaned flag
454
                    if (doNotReturnFullEntities){
455
                        hql += ", 'taxon', " +
456
                                " case when t.taxonNodes is empty and t.relationsFromThisTaxon is empty and t.relationsToThisTaxon is empty then true else false end ";
457
                    }
458
                    hql +=  " from %s t " +
459
                            " where t.id in (:taxa) ";
460

  
461
                }else{
462
                    hql = "select " + selectWhat + " from %s t";
463
                }
464
            } else if(doSynonyms){
465
                if (synonyms.size()>0){
466

  
467
                    hql = "select " + selectWhat;
468
                    // in doNotReturnFullEntities mode it is nesscary to also return the type of the matching entities:
469
                    // also return the computed isOrphaned flag
470
                    if (doNotReturnFullEntities){
471
                        hql += ", 'synonym', 'false' ";
472
                    }
473
                    hql +=  " from %s t " +
474
                            " where t.id in (:synonyms) ";
475
                }else{
476
                    hql = "select " + selectWhat + " from %s t";
477
                }
478
            } else if (doIncludeMisappliedNames){
479
                hql = "select " + selectWhat;
480
                // in doNotReturnFullEntities mode it is nesscary to also return the type of the matching entities:
481
                // also return the computed isOrphaned flag
482
                if (doNotReturnFullEntities){
483
                    hql += ", 'taxon', " +
484
                            " case when t.taxonNodes is empty and t.relationsFromThisTaxon is empty and t.relationsToThisTaxon is empty then true else false end ";
485
                }
486
                hql +=  " from %s t " +
487
                        " where t.id in (:taxa) ";
488

  
489
            }
490 444

  
491 445
            String classString;
492
            if (doTaxa && doSynonyms){
446
            if ((doTaxa || doCommonNames || doIncludeMisappliedNames) && doSynonyms){
493 447
                classString = "TaxonBase";
494 448
            } else if (doTaxa || doCommonNames){
495 449
                classString = "Taxon";
496
            } else if (doSynonyms){
450
            } else if (doSynonyms && !(doCommonNames|| doTaxa || doIncludeMisappliedNames)){
497 451
                classString = "Synonym";
498 452
            } else{//only misappliedNames
499 453
                classString = "Taxon";
......
524 478
            Query query = getSession().createQuery(hql);
525 479

  
526 480

  
527
            if (doTaxa && doSynonyms){
481
            if ((doTaxa || doCommonNames || doIncludeMisappliedNames) ){
528 482
                // find taxa and synonyms
529 483
                if (taxa.size()>0){
530 484
                    query.setParameterList("taxa", taxa);
......
535 489
                if (taxa.size()== 0 && synonyms.size() == 0){
536 490
                    return null;
537 491
                }
538
            }else if(doTaxa || doCommonNames || doIncludeMisappliedNames){
539
                //find taxa
540
                if (taxa.size()>0){
541
                    query.setParameterList("taxa", taxa );
542
                }else{
543
                    logger.warn("there are no taxa for the query: " + queryString);
544
                    return null;
545
                }
546
            } else if(doSynonyms){
492
            }
493
            if(doSynonyms){
547 494
                // find synonyms
548 495
                if (synonyms.size()>0){
549 496
                    query.setParameterList("synonyms", synonyms);
550 497
                }else{
551 498
                    return null;
552 499
                }
553
            }	else{
554
                //only misappliedNames
555
                if (taxa.size()>0){
556
                    query.setParameterList("taxa", taxa );
557
                }else{
558
                    return null;
559
                }
560 500
            }
561 501

  
562 502
            return query;
cdmlib-services/src/test/java/eu/etaxonomy/cdm/api/service/TaxonServiceSearchTaxaAndNamesTest.java
152 152

  
153 153
        setTaxaAndNamesModes(conf, false, true, true, true, true);
154 154
        pager = taxonService.findTaxaAndNames(conf);
155
        assertEquals(3, pager.getRecords().size());
155
        assertEquals(4, pager.getRecords().size());
156 156

  
157 157
        setTaxaAndNamesModes(conf, true, false, true, true, true);
158 158
        pager = taxonService.findTaxaAndNames(conf);
......
171 171

  
172 172

  
173 173
     // FIXME org.hibernate.QueryParameterException: could not locate named parameter [taxa]
174
     //   setTaxaAndNamesModes(conf, false, true, false, true, true);
175
     //   pager = taxonService.findTaxaAndNames(conf);
176
     //   assertEquals(3, pager.getRecords().size());
174
        setTaxaAndNamesModes(conf, false, true, false, true, true);
175
        pager = taxonService.findTaxaAndNames(conf);
176
        // there are one synonym, two names without taxa and a misapplied name
177
        assertEquals(4, pager.getRecords().size());
177 178

  
178 179
        setTaxaAndNamesModes(conf, true, false, false, true, true);
179 180
        pager = taxonService.findTaxaAndNames(conf);
......
191 192
        assertEquals(10, pager.getRecords().size());
192 193

  
193 194
        // FIXME the Synonym Abies subalpina missing in result set
194
//        setTaxaAndNamesModes(conf, false, true, true, false, true);
195
//        pager = taxonService.findTaxaAndNames(conf);
196
//        logSearchResults(pager, Level.DEBUG);
197
//        assertEquals(3, pager.getRecords().size());
195
        setTaxaAndNamesModes(conf, false, true, true, false, true);
196
        pager = taxonService.findTaxaAndNames(conf);
197
        logSearchResults(pager, Level.DEBUG);
198
        assertEquals(3, pager.getRecords().size());
198 199

  
199 200
        setTaxaAndNamesModes(conf, true, false, true, false, true);
200 201
        pager = taxonService.findTaxaAndNames(conf);
......
241 242
        setTaxaAndNamesModes(conf, false, true, true, true, false);
242 243
        pager = taxonService.findTaxaAndNames(conf);
243 244
        logSearchResults(pager, Level.DEBUG);
244
        assertEquals(1, pager.getRecords().size());
245
        //There is one synonym and a misapplied name
246
        assertEquals(2, pager.getRecords().size());
245 247

  
246 248
        setTaxaAndNamesModes(conf, true, false, true, true, false);
247 249
        pager = taxonService.findTaxaAndNames(conf);
......
261 263
        assertEquals(8, pager.getRecords().size());
262 264

  
263 265
        // FIXME org.hibernate.QueryParameterException: could not locate named parameter [taxa]
264
//        setTaxaAndNamesModes(conf, false, true, false, true, false);
265
//        pager = taxonService.findTaxaAndNames(conf);
266
//        logSearchResults(pager, Level.DEBUG);
267
//        assertEquals(2, pager.getRecords().size());
266
        setTaxaAndNamesModes(conf, false, true, false, true, false);
267
        pager = taxonService.findTaxaAndNames(conf);
268
        logSearchResults(pager, Level.DEBUG);
269
        assertEquals(2, pager.getRecords().size());
268 270

  
269 271
        setTaxaAndNamesModes(conf, true, false, false, true, false);
270 272
        pager = taxonService.findTaxaAndNames(conf);

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)