Project

General

Profile

Revision 3cf47767

ID3cf47767ec610df57afafe46d4db083687df0fae
Parent a180fd4f
Child 891d65aa

Added by Andreas Müller about 3 years ago

#5958 Implement name part search as web service

View differences:

cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/persistence/dao/hibernate/taxon/TaxonDaoHibernateImpl.java
1213 1213
    }
1214 1214

  
1215 1215
    @Override
1216
    public List<TaxonBase> findTaxaByName(Class<? extends TaxonBase> clazz, String genusOrUninomial, String infraGenericEpithet, String specificEpithet, String infraSpecificEpithet, Rank rank, Integer pageSize,	Integer pageNumber) {
1217
        checkNotInPriorView("TaxonDaoHibernateImpl.findTaxaByName(Boolean accepted, String genusOrUninomial, String infraGenericEpithet, String specificEpithet, String infraSpecificEpithet, Rank rank, Integer pageSize,	Integer pageNumber)");
1216
    public List<TaxonBase> findTaxaByName(Class<? extends TaxonBase> clazz, String genusOrUninomial, String infraGenericEpithet, String specificEpithet, String infraSpecificEpithet, String authorship, Rank rank, Integer pageSize,	Integer pageNumber) {
1217
        checkNotInPriorView("TaxonDaoHibernateImpl.findTaxaByName(Boolean accepted, String genusOrUninomial, String infraGenericEpithet, String specificEpithet, String infraSpecificEpithet, String authorship, Rank rank, Integer pageSize,	Integer pageNumber)");
1218 1218
        Criteria criteria = null;
1219 1219
        if (clazz == null){
1220 1220
            criteria = getSession().createCriteria(TaxonBase.class);
......
1249 1249
            criteria.add(Restrictions.eq("name.infraSpecificEpithet", infraSpecificEpithet));
1250 1250
        }
1251 1251

  
1252
        if(authorship == null) {
1253
            criteria.add(Restrictions.isEmpty("name.authorshipCache"));
1254
        } else if(!authorship.equals("*")) {
1255
            criteria.add(Restrictions.eq("name.authorshipCache", authorship));
1256
        }
1257

  
1252 1258
        if(rank != null) {
1253 1259
            criteria.add(Restrictions.eq("name.rank", rank));
1254 1260
        }
cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/persistence/dao/taxon/ITaxonDao.java
166 166
     * @param pageNumber The offset (in pageSize chunks) from the start of the result set (0 - based)
167 167
     * @return a list of TaxonBase instances
168 168
     */
169
    public List<TaxonBase> findTaxaByName(Class<? extends TaxonBase> clazz, String uninomial, String infragenericEpithet, String specificEpithet, String infraspecificEpithet, Rank rank, Integer pageSize, Integer pageNumber);
169
    public List<TaxonBase> findTaxaByName(Class<? extends TaxonBase> clazz, String uninomial, String infragenericEpithet, String specificEpithet, String infraspecificEpithet, String authorship, Rank rank, Integer pageSize, Integer pageNumber);
170 170

  
171 171
    /**
172 172
     * Find taxa by searching for Taxa and Synonyms where the
cdmlib-persistence/src/test/java/eu/etaxonomy/cdm/persistence/dao/hibernate/taxon/TaxonDaoHibernateImplTest.java
699 699
    @Test
700 700
    @DataSet
701 701
    public void testGetTaxonMatchingUninomial() {
702
        List<TaxonBase> result = taxonDao.findTaxaByName(Taxon.class, "Smerinthus", "*", "*", "*",null,null,null);
702
        List<TaxonBase> result = taxonDao.findTaxaByName(Taxon.class, "Smerinthus", "*", "*", "*",null,null,null,null);
703 703

  
704 704
        assertNotNull("findTaxaByName should return a List", result);
705 705
        assertEquals("findTaxaByName should return two Taxa",2,result.size());
......
709 709
    @Test
710 710
    @DataSet
711 711
    public void testGetTaxonMatchingSpeciesBinomial() {
712
        List<TaxonBase> result = taxonDao.findTaxaByName(Taxon.class,"Smerinthus", null, "kindermannii", null,null,null,null);
712
        List<TaxonBase> result = taxonDao.findTaxaByName(Taxon.class, "Smerinthus", null, "kindermannii", null,null,null,null,null);
713 713

  
714 714
        assertNotNull("findTaxaByName should return a List", result);
715 715
        assertEquals("findTaxaByName should return one Taxon",1,result.size());
......
719 719
    @Test
720 720
    @DataSet
721 721
    public void testGetTaxonMatchingTrinomial() {
722
        List<TaxonBase> result = taxonDao.findTaxaByName(Taxon.class,"Cryptocoryne", null,"purpurea","borneoensis",null,null,null);
722
        List<TaxonBase> result = taxonDao.findTaxaByName(Taxon.class,"Cryptocoryne", null,"purpurea","borneoensis",null,null,null,null);
723 723

  
724 724
        assertNotNull("findTaxaByName should return a List", result);
725 725
        assertEquals("findTaxaByName should return one Taxon",1,result.size());
......
729 729
    @Test
730 730
    @DataSet
731 731
    public void testNegativeMatch() {
732
        List<TaxonBase> result = taxonDao.findTaxaByName(Taxon.class,"Acherontia", null,"atropos","dehli",null,null,null);
732
        List<TaxonBase> result = taxonDao.findTaxaByName(Taxon.class,"Acherontia", null,"atropos","dehli",null,null,null,null);
733 733

  
734 734
        assertNotNull("findTaxaByName should return a List", result);
735 735
        assertTrue("findTaxaByName should return an empty List",result.isEmpty());
cdmlib-remote/src/main/java/eu/etaxonomy/cdm/remote/controller/TaxonListController.java
9 9

  
10 10
package eu.etaxonomy.cdm.remote.controller;
11 11

  
12
import io.swagger.annotations.Api;
13

  
14 12
import java.io.IOException;
15 13
import java.util.ArrayList;
16 14
import java.util.Arrays;
......
47 45
import eu.etaxonomy.cdm.api.service.search.SearchResult;
48 46
import eu.etaxonomy.cdm.model.common.CdmBase;
49 47
import eu.etaxonomy.cdm.model.common.DefinedTerm;
48
import eu.etaxonomy.cdm.model.common.DefinedTermBase;
50 49
import eu.etaxonomy.cdm.model.common.IdentifiableEntity;
51 50
import eu.etaxonomy.cdm.model.common.Language;
52 51
import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
53 52
import eu.etaxonomy.cdm.model.description.Feature;
54 53
import eu.etaxonomy.cdm.model.description.PresenceAbsenceTerm;
55 54
import eu.etaxonomy.cdm.model.location.NamedArea;
55
import eu.etaxonomy.cdm.model.name.Rank;
56 56
import eu.etaxonomy.cdm.model.taxon.Classification;
57 57
import eu.etaxonomy.cdm.model.taxon.Synonym;
58 58
import eu.etaxonomy.cdm.model.taxon.Taxon;
......
63 63
import eu.etaxonomy.cdm.remote.controller.util.PagerParameters;
64 64
import eu.etaxonomy.cdm.remote.editor.DefinedTermBaseList;
65 65
import eu.etaxonomy.cdm.remote.editor.MatchModePropertyEditor;
66
import eu.etaxonomy.cdm.remote.editor.RankPropertyEditor;
66 67
import eu.etaxonomy.cdm.remote.editor.TermBaseListPropertyEditor;
67 68
import eu.etaxonomy.cdm.remote.editor.UuidList;
69
import io.swagger.annotations.Api;
68 70

  
69 71
/**
70 72
 * TODO write controller documentation
......
92 94
        setInitializationStrategy(Arrays.asList(new String[]{"$","name.nomenclaturalReference"}));
93 95
    }
94 96

  
95
    /* (non-Javadoc)
96
     * @see eu.etaxonomy.cdm.remote.controller.BaseListController#setService(eu.etaxonomy.cdm.api.service.IService)
97
     */
98 97
    @Override
99 98
    @Autowired
100 99
    public void setService(ITaxonService service) {
......
117 116
        super.initBinder(binder);
118 117
        binder.registerCustomEditor(DefinedTermBaseList.class, new TermBaseListPropertyEditor<NamedArea>(termService));
119 118
        binder.registerCustomEditor(MatchMode.class, new MatchModePropertyEditor());
119
        binder.registerCustomEditor(Rank.class, new RankPropertyEditor());
120 120

  
121 121
    }
122 122

  
......
440 440
            HttpServletRequest request,
441 441
            HttpServletResponse response)throws IOException {
442 442

  
443
        logger.info("doFindBestMatchingTaxon : " + requestPathAndQuery(request) );
444

  
443 445
        Taxon bestMatchingTaxon =  service.findBestMatchingTaxon(taxonName);
444 446

  
445 447
        return bestMatchingTaxon;
......
497 499
        return service.findByIdentifier(type, identifier, definedTerm , subTree, matchMode, includeEntity, pagerParams.getPageSize(), pagerParams.getPageIndex(), initializationStrategy);
498 500
    }
499 501

  
502
    @RequestMapping(value = "doFindByNameParts", method = RequestMethod.GET)
503
    public Pager<TaxonBase> doFindByNameParts(
504
            @RequestParam(value = "genusOrUninomial", required = false) String genusOrUninomial,
505
            @RequestParam(value = "infragenericEpithet", required = false) String infragenericEpithet,
506
            @RequestParam(value = "specificEpithet", required = false) String specificEpithet,
507
            @RequestParam(value = "infraspecificEpithet", required = false) String infraspecificEpithet,
508
            @RequestParam(value = "authorship", required = false) String authorship,
509
            @RequestParam(value = "rankUuid", required = false) UUID rankUuid,
510
            @RequestParam(value = "pageNumber", required = false) Integer pageNumber,
511
            @RequestParam(value = "pageSize", required = false) Integer pageSize,
512
            HttpServletRequest request,
513
            HttpServletResponse response)throws IOException {
514

  
515
        logger.info("doFindByNameParts : " + requestPathAndQuery(request) );
516

  
517
        if (genusOrUninomial == null && infragenericEpithet == null && specificEpithet == null && infraspecificEpithet == null){
518
            response.sendError(404 , "At least 1 name part must be defined " );
519
            return null;
520
        }
521

  
522
        Rank rank = null;
523
        if (rankUuid != null){
524
             rank = findRank(rankUuid);
525
        }
526

  
527
        Pager<TaxonBase> result = service.findTaxaByName(null, genusOrUninomial, infragenericEpithet, specificEpithet, infraspecificEpithet, authorship, rank, pageSize, pageNumber);
528

  
529
        return result;
530
    }
531

  
532

  
533
    private Rank findRank(UUID rankUuid) {
534
        Rank rank = null;
535
        if(rankUuid != null){
536
            DefinedTermBase<?> definedTermBase =  termService.find(rankUuid);
537
            if(definedTermBase instanceof Rank){
538
                rank = (Rank) definedTermBase;
539
            } else {
540
               throw new IllegalArgumentException("DefinedTermBase is not a Rank");
541
            }
542
        }
543
        return rank;
544
    }
545

  
500 546
}
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/ITaxonService.java
483 483
     * @param pageNumber The offset (in pageSize chunks) from the start of the result set (0 - based)
484 484
     * @return a list of TaxonBase instances
485 485
     */
486
    public Pager<TaxonBase> findTaxaByName(Class<? extends TaxonBase> clazz, String uninomial, String infragenericEpithet, String specificEpithet, String infraspecificEpithet, Rank rank, Integer pageSize, Integer pageNumber);
486
    public Pager<TaxonBase> findTaxaByName(Class<? extends TaxonBase> clazz, String uninomial, String infragenericEpithet, String specificEpithet, String infraspecificEpithet, String authorship, Rank rank, Integer pageSize, Integer pageNumber);
487 487

  
488 488
    /**
489 489
     * Returns a list of TaxonBase instances where the
......
500 500
     * @param pageNumber The offset (in pageSize chunks) from the start of the result set (0 - based)
501 501
     * @return a List of TaxonBase instances
502 502
     */
503
    public List<TaxonBase> listTaxaByName(Class<? extends TaxonBase> clazz, String uninomial, String infragenericEpithet, String specificEpithet, String infraspecificEpithet, Rank rank, Integer pageSize, Integer pageNumber);
503
    public List<TaxonBase> listTaxaByName(Class<? extends TaxonBase> clazz, String uninomial, String infragenericEpithet, String specificEpithet, String infraspecificEpithet, String authorship, Rank rank, Integer pageSize, Integer pageNumber);
504 504

  
505 505
    /**
506 506
     * Returns a list of IdentifiableEntity instances (in particular, TaxonNameBase and TaxonBase instances)
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/TaxonServiceImpl.java
451 451
    }
452 452

  
453 453
    @Override
454
    public Pager<TaxonBase> findTaxaByName(Class<? extends TaxonBase> clazz, String uninomial,	String infragenericEpithet, String specificEpithet,	String infraspecificEpithet, Rank rank, Integer pageSize,Integer pageNumber) {
454
    public Pager<TaxonBase> findTaxaByName(Class<? extends TaxonBase> clazz, String uninomial,	String infragenericEpithet, String specificEpithet,	String infraspecificEpithet, String authorship, Rank rank, Integer pageSize,Integer pageNumber) {
455 455
        Integer numberOfResults = dao.countTaxaByName(clazz, uninomial, infragenericEpithet, specificEpithet, infraspecificEpithet, rank);
456 456

  
457 457
        List<TaxonBase> results = new ArrayList<TaxonBase>();
458 458
        if(numberOfResults > 0) { // no point checking again
459
            results = dao.findTaxaByName(clazz, uninomial, infragenericEpithet, specificEpithet, infraspecificEpithet, rank, pageSize, pageNumber);
459
            results = dao.findTaxaByName(clazz, uninomial, infragenericEpithet, specificEpithet, infraspecificEpithet, authorship, rank, pageSize, pageNumber);
460 460
        }
461 461

  
462 462
        return new DefaultPagerImpl<TaxonBase>(pageNumber, numberOfResults, pageSize, results);
463 463
    }
464 464

  
465 465
    @Override
466
    public List<TaxonBase> listTaxaByName(Class<? extends TaxonBase> clazz, String uninomial,	String infragenericEpithet, String specificEpithet,	String infraspecificEpithet, Rank rank, Integer pageSize,Integer pageNumber) {
466
    public List<TaxonBase> listTaxaByName(Class<? extends TaxonBase> clazz, String uninomial,	String infragenericEpithet, String specificEpithet,	String infraspecificEpithet, String authorship, Rank rank, Integer pageSize,Integer pageNumber) {
467 467
        Integer numberOfResults = dao.countTaxaByName(clazz, uninomial, infragenericEpithet, specificEpithet, infraspecificEpithet, rank);
468 468

  
469 469
        List<TaxonBase> results = new ArrayList<TaxonBase>();
470 470
        if(numberOfResults > 0) { // no point checking again
471
            results = dao.findTaxaByName(clazz, uninomial, infragenericEpithet, specificEpithet, infraspecificEpithet, rank, pageSize, pageNumber);
471
            results = dao.findTaxaByName(clazz, uninomial, infragenericEpithet, specificEpithet, infraspecificEpithet, authorship, rank, pageSize, pageNumber);
472 472
        }
473 473

  
474 474
        return results;

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)