Project

General

Profile

Revision 2ac69f0c

ID2ac69f0c0f023403ec36424ac27bf5d743f3538c
Parent aec3c7b7
Child f57aebc4

Added by Andreas Kohlbecker over 1 year ago

ref #7831 using uuids in findTaxonNameParts() methods as name exclude filter

View differences:

cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/persistence/dao/hibernate/name/TaxonNameDaoHibernateImpl.java
958 958
    @Override
959 959
    public List<TaxonNameParts> findTaxonNameParts(Optional<String> genusOrUninomial,
960 960
            Optional<String> infraGenericEpithet, Optional<String> specificEpithet,
961
            Optional<String> infraSpecificEpithet, Rank rank, Collection<TaxonName> excludedNames, Integer pageSize, Integer pageIndex, List<OrderHint> orderHints) {
961
            Optional<String> infraSpecificEpithet, Rank rank, Collection<UUID> excludedNamesUuids, Integer pageSize, Integer pageIndex, List<OrderHint> orderHints) {
962 962

  
963 963
        StringBuilder hql = prepareFindTaxonNameParts(false, genusOrUninomial, infraGenericEpithet,
964
                specificEpithet, infraSpecificEpithet, rank, excludedNames);
964
                specificEpithet, infraSpecificEpithet, rank, excludedNamesUuids);
965 965
        addOrder(hql, "n", orderHints);
966 966
        Query query = getSession().createQuery(hql.toString());
967 967
        if(rank != null){
968 968
            query.setParameter("rank", rank);
969 969
        }
970
        if(excludedNames != null && excludedNames.size() > 0){
971
            query.setParameterList("excludedNames", excludedNames);
970
        if(excludedNamesUuids != null && excludedNamesUuids.size() > 0){
971
            query.setParameterList("excludedNamesUuids", excludedNamesUuids);
972 972
        }
973 973
        setPagingParameter(query, pageSize, pageIndex);
974 974
        @SuppressWarnings("unchecked")
......
983 983
     */
984 984
    @Override
985 985
    public long countTaxonNameParts(Optional<String> genusOrUninomial, Optional<String> infraGenericEpithet,
986
            Optional<String> specificEpithet, Optional<String> infraSpecificEpithet, Rank rank, Collection<TaxonName> excludedNames) {
986
            Optional<String> specificEpithet, Optional<String> infraSpecificEpithet, Rank rank, Collection<UUID> excludedNamesUUIDs) {
987 987

  
988
        StringBuilder hql = prepareFindTaxonNameParts(true, genusOrUninomial, infraGenericEpithet, specificEpithet, infraSpecificEpithet, rank, excludedNames);
988
        StringBuilder hql = prepareFindTaxonNameParts(true, genusOrUninomial, infraGenericEpithet, specificEpithet, infraSpecificEpithet, rank, excludedNamesUUIDs);
989 989
        Query query = getSession().createQuery(hql.toString());
990 990
        if(rank != null){
991 991
            query.setParameter("rank", rank);
992 992
        }
993
        if(excludedNames != null && excludedNames.size() > 0){
994
            query.setParameterList("excludedNames", excludedNames);
993
        if(excludedNamesUUIDs != null && excludedNamesUUIDs.size() > 0){
994
            query.setParameterList("excludedNamesUuids", excludedNamesUUIDs);
995 995
        }
996 996

  
997 997
        Object count = query.uniqueResult();
......
1003 1003
     */
1004 1004
    private StringBuilder prepareFindTaxonNameParts(boolean doCount, Optional<String> genusOrUninomial,
1005 1005
            Optional<String> infraGenericEpithet, Optional<String> specificEpithet,
1006
            Optional<String> infraSpecificEpithet, Rank rank, Collection<TaxonName> excludedNames) {
1006
            Optional<String> infraSpecificEpithet, Rank rank, Collection<UUID> excludedNamesUuids) {
1007 1007

  
1008 1008
        StringBuilder hql = new StringBuilder();
1009 1009
        if(doCount){
......
1016 1016
        if(rank != null){
1017 1017
            hql.append("and n.rank = :rank ");
1018 1018
        }
1019
        if(excludedNames != null && excludedNames.size() > 0){
1020
            hql.append("and n not in ( :excludedNames ) ");
1019
        if(excludedNamesUuids != null && excludedNamesUuids.size() > 0){
1020
            hql.append("and n.uuid not in ( :excludedNamesUuids ) ");
1021 1021
        }
1022 1022

  
1023 1023
        addFieldPredicate(hql, "n.genusOrUninomial", genusOrUninomial);
cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/persistence/dao/name/ITaxonNameDao.java
348 348
	 * @param infraSpecificEpithet
349 349
	 * @param rank
350 350
	 *     Only name having the specified rank are taken into account.
351
	 * @param excludedNames
351
	 * @param excludedNamesUuids
352 352
     *     Names to be excluded from the result set
353 353
	 * @return
354 354
	 */
355 355
	public List<TaxonNameParts> findTaxonNameParts(Optional<String> genusOrUninomial, Optional<String> infraGenericEpithet, Optional<String> specificEpithet,
356
	        Optional<String> infraSpecificEpithet, Rank rank, Collection<TaxonName> excludedNames, Integer pageSize, Integer pageIndex, List<OrderHint> orderHints);
356
	        Optional<String> infraSpecificEpithet, Rank rank, Collection<UUID> excludedNamesUuids, Integer pageSize, Integer pageIndex, List<OrderHint> orderHints);
357 357
    /**
358 358
     * Count method complementing {@link #findTaxonNameParts(Optional, Optional, Optional, Optional, Rank)}
359 359
     *
......
363 363
     * @param infraSpecificEpithet
364 364
     * @param rank
365 365
     *     Only name having the specified rank are taken into account.
366
     * @param excludedNames
366
     * @param excludedNamesUuids
367 367
     *     Names to be excluded from the result set
368 368
     * @return
369 369
     */
370 370
    public long countTaxonNameParts(Optional<String> genusOrUninomial, Optional<String> infraGenericEpithet, Optional<String> specificEpithet, Optional<String> infraSpecificEpithet,
371
            Rank rank, Collection<TaxonName> excludedNames);
371
            Rank rank, Collection<UUID> excludedNames);
372 372
}
cdmlib-persistence/src/test/java/eu/etaxonomy/cdm/persistence/dao/hibernate/name/TaxonNameDaoHibernateImplTest.java
213 213
        TaxonName n_atropos_agassiz = taxonNameDao.load(atroposUuid);
214 214
        results = taxonNameDao.findTaxonNameParts(
215 215
                Optional.of("Atro*"), null, null, null,
216
                Rank.GENUS(), Arrays.asList(n_atropos_agassiz),
216
                Rank.GENUS(), Arrays.asList(n_atropos_agassiz.getUuid()),
217 217
                pageSize, pageIndex, Arrays.asList(new OrderHint("genusOrUninomial", SortOrder.ASCENDING)));
218 218

  
219 219
        assertNotNull(results);
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/INameService.java
151 151
     * @param infraSpecificEpithet
152 152
     * @param rank
153 153
     *     Only names having the specified rank are taken into account.
154
     * @param excludedNames
154
     * @param excludedNamesUuids
155 155
     *     Names to be excluded from the result set
156 156
     * @return
157 157
     */
158 158
	public Pager<TaxonNameParts> findTaxonNameParts(Optional<String> genusOrUninomial,
159 159
            Optional<String> infraGenericEpithet, Optional<String> specificEpithet,
160
            Optional<String> infraSpecificEpithet, Rank rank, Set<TaxonName> excludedNames,
160
            Optional<String> infraSpecificEpithet, Rank rank, Set<UUID> excludedNamesUuids,
161 161
            Integer pageSize, Integer pageIndex, List<OrderHint> orderHints);
162 162

  
163 163
	/**
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/NameServiceImpl.java
347 347
    @Override
348 348
    public Pager<TaxonNameParts> findTaxonNameParts(Optional<String> genusOrUninomial,
349 349
            Optional<String> infraGenericEpithet, Optional<String> specificEpithet,
350
            Optional<String> infraSpecificEpithet, Rank rank, Set<TaxonName> excludedNames,
350
            Optional<String> infraSpecificEpithet, Rank rank, Set<UUID> excludedNamesUuids,
351 351
            Integer pageSize, Integer pageIndex, List<OrderHint> orderHints) {
352 352

  
353 353

  
354
        long count = dao.countTaxonNameParts(genusOrUninomial, infraGenericEpithet, specificEpithet, infraGenericEpithet, rank, excludedNames);
354
        long count = dao.countTaxonNameParts(genusOrUninomial, infraGenericEpithet, specificEpithet, infraGenericEpithet, rank, excludedNamesUuids);
355 355

  
356 356
        List<TaxonNameParts> results;
357 357
        if(AbstractPagerImpl.hasResultsInRange(count, pageIndex, pageSize)){
358 358
            results = dao.findTaxonNameParts(genusOrUninomial, infraGenericEpithet, specificEpithet, infraSpecificEpithet,
359
                    rank, excludedNames,
359
                    rank, excludedNamesUuids,
360 360
                    pageSize, pageIndex, orderHints);
361 361
        } else {
362 362
            results = new ArrayList<>();
......
378 378
                filter.specificEpithet(namePartQueryString),
379 379
                filter.infraspecificEpithet(namePartQueryString),
380 380
                filter.getRank(),
381
                filter.getExludedNames(),
381
                filter.getExludedNamesUuids(),
382 382
                pageSize, pageIndex, orderHints);
383 383
    }
384 384

  
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/utility/TaxonNamePartsFilter.java
8 8
*/
9 9
package eu.etaxonomy.cdm.api.utility;
10 10

  
11
import java.util.HashSet;
12 11
import java.util.Optional;
13 12
import java.util.Set;
13
import java.util.UUID;
14 14

  
15 15
import eu.etaxonomy.cdm.model.name.Rank;
16 16
import eu.etaxonomy.cdm.model.name.TaxonName;
......
32 32
 */
33 33
public class TaxonNamePartsFilter extends TaxonNameParts {
34 34

  
35
    private Set<TaxonName> exludedNames = new HashSet<>();
35
    private Set<UUID> exludedNamesUuids;
36 36

  
37 37
    /**
38 38
     * @param taxonNameId
......
110 110
    /**
111 111
     * @return the exludedNames
112 112
     */
113
    public Set<TaxonName> getExludedNames() {
114
        return exludedNames;
113
    public Set<UUID> getExludedNamesUuids() {
114
        return exludedNamesUuids;
115 115
    }
116 116

  
117 117
    /**
118 118
     * @param exludedNames the exludedNames to set
119 119
     */
120 120
    public void setExludedNames(Set<TaxonName> exludedNames) {
121
        this.exludedNames = exludedNames;
121
        for(TaxonName name : exludedNames){
122
            exludedNamesUuids.add(name.getUuid());
123
        }
122 124
    }
123 125
}

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)