Project

General

Profile

Revision efc5d1e3

IDefc5d1e335b3569ffb89b9a5bd7ff723cc83fd0b
Parent a2a58fcc
Child 9b6c1bf1

Added by Andreas Kohlbecker over 1 year ago

ref #7831 adding name exlude filter to TaxonNamePartsFilter

View differences:

cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/persistence/dao/hibernate/name/TaxonNameDaoHibernateImpl.java
10 10
package eu.etaxonomy.cdm.persistence.dao.hibernate.name;
11 11

  
12 12
import java.util.ArrayList;
13
import java.util.Collection;
13 14
import java.util.HashMap;
14 15
import java.util.List;
15 16
import java.util.Optional;
......
957 958
    @Override
958 959
    public List<TaxonNameParts> findTaxonNameParts(Optional<String> genusOrUninomial,
959 960
            Optional<String> infraGenericEpithet, Optional<String> specificEpithet,
960
            Optional<String> infraSpecificEpithet, Rank rank, Integer pageSize, Integer pageIndex, List<OrderHint> orderHints) {
961
            Optional<String> infraSpecificEpithet, Rank rank, Collection<TaxonName> excludedNames, Integer pageSize, Integer pageIndex, List<OrderHint> orderHints) {
961 962

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

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

  
990 997
        Object count = query.uniqueResult();
991 998
        return (Long) count;
......
996 1003
     */
997 1004
    private StringBuilder prepareFindTaxonNameParts(boolean doCount, Optional<String> genusOrUninomial,
998 1005
            Optional<String> infraGenericEpithet, Optional<String> specificEpithet,
999
            Optional<String> infraSpecificEpithet, Rank rank) {
1006
            Optional<String> infraSpecificEpithet, Rank rank, Collection<TaxonName> excludedNames) {
1000 1007

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

  
1013 1023
        addFieldPredicate(hql, "n.genusOrUninomial", genusOrUninomial);
1014 1024
        addFieldPredicate(hql, "n.infraGenericEpithet", infraGenericEpithet);
cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/persistence/dao/name/ITaxonNameDao.java
8 8
 */
9 9
package eu.etaxonomy.cdm.persistence.dao.name;
10 10

  
11
import java.util.Collection;
11 12
import java.util.HashMap;
12 13
import java.util.List;
13 14
import java.util.Optional;
......
28 29
import eu.etaxonomy.cdm.model.name.TypeDesignationBase;
29 30
import eu.etaxonomy.cdm.model.name.TypeDesignationStatusBase;
30 31
import eu.etaxonomy.cdm.persistence.dao.common.IIdentifiableDao;
31
import eu.etaxonomy.cdm.persistence.dao.initializer.IBeanInitializer;
32 32
import eu.etaxonomy.cdm.persistence.dto.TaxonNameParts;
33 33
import eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache;
34 34
import eu.etaxonomy.cdm.persistence.query.MatchMode;
......
348 348
	 * @param infraSpecificEpithet
349 349
	 * @param rank
350 350
	 *     Only name having the specified rank are taken into account.
351
	 * @param excludedNames
352
     *     Names to be excluded from the result set
351 353
	 * @return
352 354
	 */
353 355
	public List<TaxonNameParts> findTaxonNameParts(Optional<String> genusOrUninomial, Optional<String> infraGenericEpithet, Optional<String> specificEpithet,
354
	        Optional<String> infraSpecificEpithet, Rank rank, Integer pageSize, Integer pageIndex, List<OrderHint> orderHints);
356
	        Optional<String> infraSpecificEpithet, Rank rank, Collection<TaxonName> excludedNames, Integer pageSize, Integer pageIndex, List<OrderHint> orderHints);
355 357
    /**
356 358
     * Count method complementing {@link #findTaxonNameParts(Optional, Optional, Optional, Optional, Rank)}
357 359
     *
......
361 363
     * @param infraSpecificEpithet
362 364
     * @param rank
363 365
     *     Only name having the specified rank are taken into account.
366
     * @param excludedNames
367
     *     Names to be excluded from the result set
364 368
     * @return
365 369
     */
366
    public long countTaxonNameParts(Optional<String> genusOrUninomial, Optional<String> infraGenericEpithet, Optional<String> specificEpithet, Optional<String> infraSpecificEpithet, Rank rank);
370
    public long countTaxonNameParts(Optional<String> genusOrUninomial, Optional<String> infraGenericEpithet, Optional<String> specificEpithet, Optional<String> infraSpecificEpithet,
371
            Rank rank, Collection<TaxonName> excludedNames);
367 372
}
cdmlib-persistence/src/test/java/eu/etaxonomy/cdm/persistence/dao/hibernate/name/TaxonNameDaoHibernateImplTest.java
71 71
        cryptocoryneGriffithiiUuid = UUID.fromString("497a9955-5c5a-4f2b-b08c-2135d336d633");
72 72
        acherontiaUuid = UUID.fromString("c2cab2ad-3e3a-47b8-8aa8-d9e1c0857647");
73 73
        acherontiaLachesisUuid = UUID.fromString("7969821b-a2cf-4d01-95ec-6a5ed0ca3f69");
74
        // Atropos Agassiz, 1846
74 75
        atroposUuid = UUID.fromString("27004fcc-14d4-47d4-a3e1-75750fdb5b79");
76

  
75 77
    }
76 78

  
77 79
    @Test
......
186 188

  
187 189
        List<TaxonNameParts> resuls = taxonNameDao.findTaxonNameParts(
188 190
                Optional.of("Atropos"), null, null, null,
189
                Rank.GENUS(),
191
                Rank.GENUS(), null,
190 192
                pageSize, pageIndex, Arrays.asList(new OrderHint("genusOrUninomial", SortOrder.ASCENDING)));
191 193

  
192 194
        assertNotNull("searchNames should return a list",resuls);
......
201 203

  
202 204
        List<TaxonNameParts> results = taxonNameDao.findTaxonNameParts(
203 205
                Optional.of("Atro*"), null, null, null,
204
                Rank.GENUS(),
206
                Rank.GENUS(), null,
205 207
                pageSize, pageIndex, Arrays.asList(new OrderHint("genusOrUninomial", SortOrder.ASCENDING)));
206 208

  
207 209
        assertNotNull(results);
208 210
        assertFalse(results.isEmpty());
209 211
        assertEquals(3, results.size());
210 212

  
213
        TaxonName n_atropos_agassiz = taxonNameDao.load(atroposUuid);
214
        results = taxonNameDao.findTaxonNameParts(
215
                Optional.of("Atro*"), null, null, null,
216
                Rank.GENUS(), Arrays.asList(n_atropos_agassiz),
217
                pageSize, pageIndex, Arrays.asList(new OrderHint("genusOrUninomial", SortOrder.ASCENDING)));
218

  
219
        assertNotNull(results);
220
        assertFalse(results.isEmpty());
221
        assertEquals(2, results.size());
222

  
211 223
        results = taxonNameDao.findTaxonNameParts(
212 224
                Optional.of("Atro*"), null, null, null,
213
                Rank.SPECIES(),
225
                Rank.SPECIES(), null,
214 226
                pageSize, pageIndex, Arrays.asList(new OrderHint("genusOrUninomial", SortOrder.ASCENDING)));
215 227

  
216 228
        assertNotNull(results);
......
226 238
        // Manduca bergarmatipes
227 239
        List<TaxonNameParts> results = taxonNameDao.findTaxonNameParts(
228 240
                Optional.of("Manduca"), null, Optional.of("*"), null,
229
                Rank.SPECIES(),
241
                Rank.SPECIES(), null,
230 242
                pageSize, pageIndex, Arrays.asList(new OrderHint("specificEpithet", SortOrder.ASCENDING)));
231 243

  
232 244
        assertEquals(3, results.size());
......
236 248

  
237 249
        results = taxonNameDao.findTaxonNameParts(
238 250
                Optional.of("Manduca"), null, Optional.of("chin*"), null,
239
                Rank.SPECIES(),
251
                Rank.SPECIES(), null,
240 252
                pageSize, pageIndex, null);
241 253

  
242 254
        assertEquals(1, results.size());
......
252 264
        // Cryptocoryne cordata var. zonata
253 265
        List<TaxonNameParts> results = taxonNameDao.findTaxonNameParts(
254 266
                Optional.of("Cryptocoryne"), null, null, Optional.of("borneo*"),
255
                Rank.VARIETY(),
267
                Rank.VARIETY(), null,
256 268
                pageSize, pageIndex, Arrays.asList(new OrderHint("specificEpithet", SortOrder.ASCENDING)));
257 269

  
258 270
        assertEquals(1, results.size());
......
260 272
        // now also with "infraGenericEpithet is null AND specificEpithet = purpurea"
261 273
        results = taxonNameDao.findTaxonNameParts(
262 274
                Optional.of("Cryptocoryne"), Optional.empty(), Optional.of("purpurea"), Optional.of("borneo*"),
263
                Rank.VARIETY(),
275
                Rank.VARIETY(), null,
264 276
                pageSize, pageIndex, Arrays.asList(new OrderHint("specificEpithet", SortOrder.ASCENDING)));
265 277

  
266 278
        assertEquals(1, results.size());
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/INameService.java
15 15
import java.util.List;
16 16
import java.util.Map;
17 17
import java.util.Optional;
18
import java.util.Set;
18 19
import java.util.UUID;
19 20

  
20
import org.apache.lucene.index.CorruptIndexException;
21 21
import org.hibernate.criterion.Criterion;
22 22

  
23 23
import eu.etaxonomy.cdm.api.service.config.NameDeletionConfigurator;
......
40 40
import eu.etaxonomy.cdm.model.name.SpecimenTypeDesignationStatus;
41 41
import eu.etaxonomy.cdm.model.name.TaxonName;
42 42
import eu.etaxonomy.cdm.model.name.TypeDesignationBase;
43
import eu.etaxonomy.cdm.persistence.dao.initializer.IBeanInitializer;
44 43
import eu.etaxonomy.cdm.persistence.dto.TaxonNameParts;
45 44
import eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache;
46 45
import eu.etaxonomy.cdm.persistence.query.MatchMode;
47 46
import eu.etaxonomy.cdm.persistence.query.OrderHint;
48 47
import eu.etaxonomy.cdm.strategy.cache.TaggedText;
49
import eu.etaxonomy.cdm.strategy.parser.NonViralNameParserImpl;
50 48

  
51 49
public interface INameService
52 50
        extends IIdentifiableEntityService<TaxonName> {
......
153 151
     * @param infraSpecificEpithet
154 152
     * @param rank
155 153
     *     Only names having the specified rank are taken into account.
154
     * @param excludedNames
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, Integer pageSize, Integer pageIndex, List<OrderHint> orderHints);
160
            Optional<String> infraSpecificEpithet, Rank rank, Set<TaxonName> excludedNames,
161
            Integer pageSize, Integer pageIndex, List<OrderHint> orderHints);
161 162

  
162 163
	/**
163 164
     * <b>This method behaves differently compared to {@link #findTaxonNameParts(Optional, Optional, Optional, Optional, Rank, Integer, Integer, List)}!</b>
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, Integer pageSize, Integer pageIndex, List<OrderHint> orderHints) {
350
            Optional<String> infraSpecificEpithet, Rank rank, Set<TaxonName> excludedNames,
351
            Integer pageSize, Integer pageIndex, List<OrderHint> orderHints) {
351 352

  
352 353

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

  
355 356
        List<TaxonNameParts> results;
356 357
        if(AbstractPagerImpl.hasResultsInRange(count, pageIndex, pageSize)){
357 358
            results = dao.findTaxonNameParts(genusOrUninomial, infraGenericEpithet, specificEpithet, infraSpecificEpithet,
358
                    rank,
359
                    rank, excludedNames,
359 360
                    pageSize, pageIndex, orderHints);
360 361
        } else {
361 362
            results = new ArrayList<>();
......
377 378
                filter.specificEpithet(namePartQueryString),
378 379
                filter.infraspecificEpithet(namePartQueryString),
379 380
                filter.getRank(),
381
                filter.getExludedNames(),
380 382
                pageSize, pageIndex, orderHints);
381 383
    }
382 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;
11 12
import java.util.Optional;
13
import java.util.Set;
12 14

  
13 15
import eu.etaxonomy.cdm.model.name.Rank;
16
import eu.etaxonomy.cdm.model.name.TaxonName;
14 17
import eu.etaxonomy.cdm.persistence.dto.TaxonNameParts;
15 18

  
16 19
/**
......
29 32
 */
30 33
public class TaxonNamePartsFilter extends TaxonNameParts {
31 34

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

  
32 37
    /**
33 38
     * @param taxonNameId
34 39
     * @param rank
......
38 43
     * @param infraSpecificEpithet
39 44
     */
40 45
    public TaxonNamePartsFilter(Rank rank, String genusOrUninomial, String infraGenericEpithet,
41
            String specificEpithet, String infraSpecificEpithet) {
46
            String specificEpithet, String infraSpecificEpithet, Set<TaxonName> exludedNames) {
42 47
        super(null, null, rank, genusOrUninomial, infraGenericEpithet, specificEpithet, infraSpecificEpithet);
48
        this.setExludedNames(exludedNames);
43 49
    }
44 50

  
45 51
    public TaxonNamePartsFilter(){
......
92 98
    }
93 99

  
94 100
    private String appendWildcard(String query){
95
        if(!query.endsWith("*")){
101
        if(query == null){
102
            query = "*";
103
        } else if(!query.endsWith("*")){
96 104
            return query + "*";
97 105
        }
98 106
        return query;
99 107

  
100 108
    }
109

  
110
    /**
111
     * @return the exludedNames
112
     */
113
    public Set<TaxonName> getExludedNames() {
114
        return exludedNames;
115
    }
116

  
117
    /**
118
     * @param exludedNames the exludedNames to set
119
     */
120
    public void setExludedNames(Set<TaxonName> exludedNames) {
121
        this.exludedNames = exludedNames;
122
    }
101 123
}

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)