Project

General

Profile

Revision 83c72818

ID83c72818d2e637f56f3e956c99cb0e6c1e508cbd
Parent f31f3e26
Child 39c4cced

Added by Andreas Kohlbecker about 1 year ago

fix #8676 adding authorship parameter to countTaxaByName

View differences:

cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/persistence/dao/hibernate/taxon/TaxonDaoHibernateImpl.java
14 14
import java.util.Comparator;
15 15
import java.util.HashMap;
16 16
import java.util.HashSet;
17
import java.util.Iterator;
18 17
import java.util.List;
19 18
import java.util.Map;
20 19
import java.util.Set;
......
32 31
import org.hibernate.Session;
33 32
import org.hibernate.criterion.Criterion;
34 33
import org.hibernate.criterion.Order;
35
import org.hibernate.criterion.ProjectionList;
36 34
import org.hibernate.criterion.Projections;
37 35
import org.hibernate.criterion.Restrictions;
38 36
import org.hibernate.envers.query.AuditEntity;
......
47 45
import org.springframework.stereotype.Repository;
48 46

  
49 47
import eu.etaxonomy.cdm.model.common.IdentifiableEntity;
50
import eu.etaxonomy.cdm.model.common.IdentifiableSource;
51 48
import eu.etaxonomy.cdm.model.common.LSID;
52 49
import eu.etaxonomy.cdm.model.common.MarkerType;
53 50
import eu.etaxonomy.cdm.model.common.RelationshipBase.Direction;
54 51
import eu.etaxonomy.cdm.model.location.NamedArea;
55 52
import eu.etaxonomy.cdm.model.name.Rank;
56 53
import eu.etaxonomy.cdm.model.name.TaxonName;
57
import eu.etaxonomy.cdm.model.name.TaxonNameComparator;
58 54
import eu.etaxonomy.cdm.model.reference.Reference;
59 55
import eu.etaxonomy.cdm.model.taxon.Classification;
60 56
import eu.etaxonomy.cdm.model.taxon.Synonym;
......
891 887
    }
892 888

  
893 889
    @Override
894
    public long countTaxaByName(Class<? extends TaxonBase> clazz, String genusOrUninomial, String infraGenericEpithet, String specificEpithet,	String infraSpecificEpithet, Rank rank) {
895
        checkNotInPriorView("TaxonDaoHibernateImpl.countTaxaByName(Boolean accepted, String genusOrUninomial,	String infraGenericEpithet, String specificEpithet,	String infraSpecificEpithet, Rank rank)");
890
    public long countTaxaByName(Class<? extends TaxonBase> clazz, String genusOrUninomial, String infraGenericEpithet, String specificEpithet,	String infraSpecificEpithet, String authorship, Rank rank) {
891
        checkNotInPriorView("TaxonDaoHibernateImpl.countTaxaByName(Boolean accepted, String genusOrUninomial,	String infraGenericEpithet, String specificEpithet,	String infraSpecificEpithet, String authorship, Rank rank)");
896 892
        Criteria criteria = null;
897 893

  
898 894
        criteria = getCriteria(clazz);
......
925 921
            criteria.add(Restrictions.eq("name.infraSpecificEpithet", infraSpecificEpithet));
926 922
        }
927 923

  
924
        if(authorship == null) {
925
            criteria.add(Restrictions.eq("name.authorshipCache", ""));
926
        } else if(!authorship.equals("*")) {
927
            criteria.add(Restrictions.eq("name.authorshipCache", authorship));
928
        }
929

  
928 930
        if(rank != null) {
929 931
            criteria.add(Restrictions.eq("name.rank", rank));
930 932
        }
......
1373 1375
        return taxonNames;
1374 1376
    }
1375 1377

  
1376
   
1378

  
1377 1379

  
1378 1380
    /**
1379 1381
     * Returns a map of nameCaches and names available for sec1 and sec2
1380 1382
     * this is used for the merging of two instances into one
1381
     * 
1383
     *
1382 1384
     * @param secRef1
1383 1385
     * @param secRef2
1384
     * return map 
1385
     * 
1386
     * return map
1387
     *
1386 1388
     */
1387 1389
    @Override
1388 1390
    public Map<String, List<TaxonName>> findIdenticalNamesNew(Reference sec1, Reference sec2, List<String> propertyPaths){
1389 1391

  
1390 1392

  
1391
        //get all names from erms 
1393
        //get all names from erms
1392 1394
        Query query=getSession().createQuery("SELECT DISTINCT ermsName from TaxonName ermsName join ermsName.taxonBases ermsTaxon WHERE ermsTaxon.sec = :ermsSec AND ermsName.nameCache IN ( Select faunaName.nameCache FROM TaxonName faunaName JOIN faunaName.taxonBases faunaTaxon WHERE faunaTaxon.sec = :faunaSec) ORDER BY ermsName.nameCache");
1393 1395
        query.setParameter("ermsSec", sec1);
1394 1396
        query.setParameter("faunaSec", sec2);
1395 1397
        List <TaxonName> identicalErmsNames = query.list();
1396 1398
        defaultBeanInitializer.initializeAll(identicalErmsNames, propertyPaths);
1397
        
1399

  
1398 1400
        //get all nameCaches
1399 1401
        List<String> nameCacheList = identicalErmsNames.stream().map(TaxonName::getNameCache).collect(Collectors.toList());
1400
        
1402

  
1401 1403
        //get all names from fauna europaea having the same nameCache as a name from erms
1402 1404
        query=getSession().createQuery("SELECT DISTINCT faunaEuName from TaxonName faunaEuName join faunaEuName.taxonBases faunaTaxon WHERE faunaTaxon.sec = :faunaSec AND faunaEuName.nameCache IN (:ermsNameCaches) ORDER BY faunaEuName.nameCache");
1403 1405
        query.setParameter("faunaSec", sec2);
1404 1406
        query.setParameterList("ermsNameCaches", nameCacheList);
1405
        
1407

  
1406 1408
        List <TaxonName> identicalFaunaEuNames = query.list();
1407 1409
        defaultBeanInitializer.initializeAll(identicalFaunaEuNames, propertyPaths);
1408 1410
        //create a map with nameCache and list of identical names
......
1411 1413
    	   List<TaxonName> names = identicalErmsNames.stream().filter(name-> name.getNameCache().equals(nameCache)).collect(Collectors.toList());
1412 1414
    	   names.addAll(identicalFaunaEuNames.stream().filter(name-> name.getNameCache().equals(nameCache)).collect(Collectors.toList()));
1413 1415
    	   nameCacheNameMap.put(nameCache, names);
1414
    	   
1416

  
1415 1417
       }
1416
      
1417
       
1418

  
1419

  
1418 1420
        return nameCacheNameMap;
1419 1421

  
1420 1422
    }
cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/persistence/dao/taxon/ITaxonDao.java
142 142
     * @param rank
143 143
     * @return a count of TaxonBase instances
144 144
     */
145
    public long countTaxaByName(Class <? extends TaxonBase> clazz, String uninomial, String infragenericEpithet,String specificEpithet, String infraspecificEpithet, Rank rank);
145
    public long countTaxaByName(Class <? extends TaxonBase> clazz, String uninomial, String infragenericEpithet,String specificEpithet, String infraspecificEpithet, String authorship, Rank rank);
146 146

  
147 147
    /**
148 148
     * Returns a list of TaxonBase instances where the
......
350 350

  
351 351
 //   public List<UUID> findIdenticalTaxonNameIds(List<String> propertyPath);
352 352

  
353
    
353

  
354 354
    /**
355 355
     * finds all names with identical nameCache but belonging to taxa with different sec references
356 356
     * @param sec1
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/TaxonServiceImpl.java
506 506

  
507 507
    @Override
508 508
    public Pager<TaxonBase> findTaxaByName(Class<? extends TaxonBase> clazz, String uninomial,	String infragenericEpithet, String specificEpithet,	String infraspecificEpithet, String authorship, Rank rank, Integer pageSize,Integer pageNumber) {
509
        long numberOfResults = dao.countTaxaByName(clazz, uninomial, infragenericEpithet, specificEpithet, infraspecificEpithet, rank);
509
        long numberOfResults = dao.countTaxaByName(clazz, uninomial, infragenericEpithet, specificEpithet, infraspecificEpithet, authorship, rank);
510 510

  
511 511
        List<TaxonBase> results = new ArrayList<>();
512 512
        if(numberOfResults > 0) { // no point checking again
......
517 517
    }
518 518

  
519 519
    @Override
520
    public List<TaxonBase> listTaxaByName(Class<? extends TaxonBase> clazz, String uninomial, String infragenericEpithet, String specificEpithet,	String infraspecificEpithet, String authorship, Rank rank, Integer pageSize,Integer pageNumber) {
521
        long numberOfResults = dao.countTaxaByName(clazz, uninomial, infragenericEpithet, specificEpithet, infraspecificEpithet, rank);
520
    public List<TaxonBase> listTaxaByName(Class<? extends TaxonBase> clazz, String uninomial, String infragenericEpithet, String specificEpithet, String infraspecificEpithet, String authorship, Rank rank, Integer pageSize,Integer pageNumber) {
521
        long numberOfResults = dao.countTaxaByName(clazz, uninomial, infragenericEpithet, specificEpithet, infraspecificEpithet, authorship, rank);
522 522

  
523 523
        List<TaxonBase> results = new ArrayList<>();
524 524
        if(numberOfResults > 0) { // no point checking again

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)