Project

General

Profile

Download (21.8 KB) Statistics
| Branch: | Tag: | Revision:
1
// $Id$
2
/**
3
* Copyright (C) 2007 EDIT
4
* European Distributed Institute of Taxonomy
5
* http://www.e-taxonomy.eu
6
*
7
* The contents of this file are subject to the Mozilla Public License Version 1.1
8
* See LICENSE.TXT at the top of this package for the full license terms.
9
*/
10

    
11
package eu.etaxonomy.cdm.api.service;
12

    
13
import java.io.IOException;
14
import java.util.Collection;
15
import java.util.HashMap;
16
import java.util.List;
17
import java.util.Map;
18
import java.util.UUID;
19

    
20
import org.apache.lucene.index.CorruptIndexException;
21
import org.apache.lucene.queryparser.classic.ParseException;
22
import org.hibernate.criterion.Criterion;
23

    
24
import eu.etaxonomy.cdm.api.service.config.NameDeletionConfigurator;
25
import eu.etaxonomy.cdm.api.service.pager.Pager;
26
import eu.etaxonomy.cdm.api.service.search.DocumentSearchResult;
27
import eu.etaxonomy.cdm.api.service.search.SearchResult;
28
import eu.etaxonomy.cdm.model.common.CdmBase;
29
import eu.etaxonomy.cdm.model.common.Language;
30
import eu.etaxonomy.cdm.model.common.ReferencedEntityBase;
31
import eu.etaxonomy.cdm.model.common.RelationshipBase;
32
import eu.etaxonomy.cdm.model.name.HomotypicalGroup;
33
import eu.etaxonomy.cdm.model.name.HybridRelationship;
34
import eu.etaxonomy.cdm.model.name.HybridRelationshipType;
35
import eu.etaxonomy.cdm.model.name.NameRelationship;
36
import eu.etaxonomy.cdm.model.name.NameRelationshipType;
37
import eu.etaxonomy.cdm.model.name.NomenclaturalStatus;
38
import eu.etaxonomy.cdm.model.name.NonViralName;
39
import eu.etaxonomy.cdm.model.name.Rank;
40
import eu.etaxonomy.cdm.model.name.SpecimenTypeDesignationStatus;
41
import eu.etaxonomy.cdm.model.name.TaxonNameBase;
42
import eu.etaxonomy.cdm.model.name.TypeDesignationBase;
43
import eu.etaxonomy.cdm.persistence.dao.initializer.IBeanInitializer;
44
import eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache;
45
import eu.etaxonomy.cdm.persistence.query.MatchMode;
46
import eu.etaxonomy.cdm.persistence.query.OrderHint;
47
import eu.etaxonomy.cdm.strategy.cache.TaggedText;
48
import eu.etaxonomy.cdm.strategy.parser.NonViralNameParserImpl;
49

    
50
public interface INameService extends IIdentifiableEntityService<TaxonNameBase> {
51

    
52
	/**
53
	 * Deletes a name. Depening on the configurator state links to the name will either be
54
	 * deleted or throw exceptions.<BR>
55
	 * If name is <code>null</code> this method has no effect.
56
	 * @param name
57
	 * @param config
58
	 *
59
	 */
60
	public DeleteResult delete(UUID nameUUID, NameDeletionConfigurator config);
61

    
62
	/**
63
	 * Removes the given type designation from the given taxon name and deletes it from
64
	 * the database if it is not connected to any other name.
65
	 * If <code>typeDesignation</code> is <code>null</code> all type designations are deleted
66
	 * from the given taxon name. If <code>name</code> is <code>null</code> all names are removed from
67
	 * the given type designation. If both are <code>null</code> nothing happens.
68
	 * @param typeDesignation
69
	 * @param name
70
	 * @return
71
	 */
72
	public DeleteResult deleteTypeDesignation(TaxonNameBase name, TypeDesignationBase typeDesignation);
73

    
74
	/**
75
	 * Removes the given type designation from the given taxon name and deletes it from
76
	 * the database if it is not connected to any other name.
77
	 * If <code>typeDesignation</code> is <code>null</code> all type designations are deleted
78
	 * from the given taxon name. If <code>name</code> is <code>null</code> all names are removed from
79
	 * the given type designation. If both are <code>null</code> nothing happens.
80
	 * @param typeDesignation
81
	 * @param name
82
	 * @return
83
	 */
84
	public DeleteResult deleteTypeDesignation(UUID nameUuid, UUID typeDesignationUuid);
85

    
86

    
87
	/**
88
	 * Saves the given type designations.
89
	 * @param typeDesignationCollection
90
	 * @return
91
	 */
92
	public Map<UUID, TypeDesignationBase> saveTypeDesignationAll(Collection<TypeDesignationBase> typeDesignationCollection);
93

    
94
	public Map<UUID, ReferencedEntityBase> saveReferencedEntitiesAll(Collection<ReferencedEntityBase> referencedEntityCollection);
95

    
96
	/**
97
	 * Saves the given homotypical groups.
98
	 * @param homotypicalGroups
99
	 * @return
100
	 */
101
	public Map<UUID, HomotypicalGroup> saveAllHomotypicalGroups(Collection<HomotypicalGroup> homotypicalGroups);
102

    
103
	/**
104
	 * Returns all nomenclatural status.
105
	 * @param limit
106
	 * @param start
107
	 * @return
108
	 */
109
	public List<NomenclaturalStatus> getAllNomenclaturalStatus(int limit, int start);
110

    
111
	/**
112
	 * Returns all type designations.
113
	 * @param limit
114
	 * @param start
115
	 * @return
116
	 */
117
	public List<TypeDesignationBase> getAllTypeDesignations(int limit, int start);
118

    
119
	/**
120
	 * @param name
121
	 * @return
122
	 */
123
	public List<TaxonNameBase> getNamesByName(String name);
124

    
125
	/**
126
	 * Returns all NonViralNames with a name cache that matches the given string
127
	 * @param name
128
	 * @return
129
	 */
130
	public List<NonViralName> getNamesByNameCache(String nameCache);
131

    
132
	/**
133
	 * Returns all NonViralNames with a title cache that matches the given string
134
	 * using the given match mode and initialization strategy
135
	 *
136
	 * @param name
137
	 * @param matchMode
138
	 * @param propertyPaths
139
	 * @return
140
	 */
141
	public List<NonViralName> findNamesByTitleCache(String titleCache, MatchMode matchMode, List<String> propertyPaths);
142

    
143
	/**
144
	 * Returns all NonViralNames with a name cache that matches the given string
145
	 * using the given match mode and initialization strategy
146
	 *
147
	 * @param name
148
	 * @param matchMode
149
	 * @param propertyPaths
150
	 * @return
151
	 */
152
	public List<NonViralName> findNamesByNameCache(String nameCache, MatchMode matchMode, List<String> propertyPaths);
153

    
154
	/**
155
	 * Returns the NonViralName with the given UUID
156
	 * using the given match mode and initialization strategy
157
	 *
158
	 * @param uuid
159
	 * @param propertyPaths
160
	 * @return
161
	 */
162
	public NonViralName findNameByUuid(UUID uuid, List<String> propertyPaths);
163
	/**
164
	 * @param name
165
	 * @param sessionObject An object that is attached to the session before executing the query
166
	 * @return
167
	 */
168
	public List getNamesByName(String name, CdmBase sessionObject);
169

    
170
	/**
171
	 * Fuzzy matching for the taxon name elements. The input name is first atomised using the {@link NonViralNameParserImpl}
172
	 * into its separate parts (genusOrUninomial,infraGenericEpithet,specificEpithet,infraGenericEpithet,authorshipCache).
173
	 * Each field is then matched separately with the same accuracy parameter.
174
	 *
175
	 * @param name taxon name to fuzzy match
176
	 * @param accuracy value > 0.0 and < 1.0 which determines the accuracy of the result.
177
	 * @param languages list of languages to consider when matching (currently not used)
178
	 * @param highlightFragments
179
	 * @param propertyPaths
180
	 * @param maxNoOfResults
181
	 * @return
182
	 * @throws CorruptIndexException
183
	 * @throws IOException
184
	 * @throws ParseException
185
	 */
186
	public List<SearchResult<TaxonNameBase>> findByNameFuzzySearch(
187
            String name,
188
            float accuracy,
189
            List<Language> languages,
190
            boolean highlightFragments,
191
            List<String> propertyPaths,
192
            int maxNoOfResults) throws CorruptIndexException, IOException, ParseException;
193

    
194
	/**
195
	 * Fuzzy matching for the taxon name elements using only the lucene index.
196
	 *
197
	 * The input name is first atomised using the {@link NonViralNameParserImpl}
198
	 * into its separate parts (genusOrUninomial,infraGenericEpithet,specificEpithet,infraGenericEpithet,authorshipCache).
199
	 * Each field is then matched separately with the same accuracy parameter.
200
	 *
201
	 * @param name taxon name to fuzzy match
202
	 * @param accuracy value > 0.0 and < 1.0 which determines the accuracy of the result.
203
	 * @param languages list of languages to consider when matching (currently not used)
204
	 * @param highlightFragments
205
	 * @param maxNoOfResults
206
	 * @return
207
	 * @throws CorruptIndexException
208
	 * @throws IOException
209
	 * @throws ParseException
210
	 */
211
    public List<DocumentSearchResult> findByNameFuzzySearch(
212
            String name,
213
            float accuracy,
214
            List<Language> languages,
215
            boolean highlightFragments,
216
            int maxNoOfResults) throws CorruptIndexException, IOException, ParseException;
217

    
218
	/**
219
	 * Fuzzy matching against the name cache using only the lucene index.
220
	 *
221
	 *
222
	 * @param name taxon name to fuzzy match
223
	 * @param accuracy value > 0.0 and < 1.0 which determines the accuracy of the result.
224
	 * @param languages list of languages to consider when matching (currently not used)
225
	 * @param highlightFragments
226
	 * @param maxNoOfResults
227
	 * @return
228
	 * @throws CorruptIndexException
229
	 * @throws IOException
230
	 * @throws ParseException
231
	 */
232
    public List<DocumentSearchResult> findByFuzzyNameCacheSearch(
233
            String name,
234
            float accuracy,
235
            List<Language> languages,
236
            boolean highlightFragments,
237
            int maxNoOfResults) throws CorruptIndexException, IOException, ParseException;
238

    
239
	/**
240
	 * Exact matching for the taxon name elements using only the lucene index.
241
	 *
242
	 * The input name is first atomised using the {@link NonViralNameParserImpl}
243
	 * into its separate parts (genusOrUninomial,infraGenericEpithet,specificEpithet,infraGenericEpithet,authorshipCache).
244
	 * Each field is then matched separately with the same accuracy parameter.
245
	 *
246
	 * @param name taxon name to fuzzy match
247
	 * @param wildcard boolean flag to indicate whether a wildcard '*' should be added at the end of the query
248
	 * @param languages list of languages to consider when matching (currently not used)
249
	 * @param highlightFragments
250
	 * @param maxNoOfResults
251
	 * @return
252
	 * @throws CorruptIndexException
253
	 * @throws IOException
254
	 * @throws ParseException
255
	 */
256

    
257
    public List<DocumentSearchResult> findByNameExactSearch(
258
            String name,
259
            boolean wildcard,
260
            List<Language> languages,
261
            boolean highlightFragments,
262
            int maxNoOfResults) throws CorruptIndexException, IOException, ParseException;
263

    
264
	// TODO: Remove getNamesByName() methods. Use findNamesByTitle() instead.
265

    
266
	// FIXME candidate for harmonization?
267
	public List findNamesByTitle(String title);
268

    
269
	public List findNamesByTitle(String title, CdmBase sessionObject);
270

    
271
    public List<HomotypicalGroup> getAllHomotypicalGroups(int limit, int start);
272

    
273
	@Deprecated
274
    public List<RelationshipBase> getAllRelationships(int limit, int start);
275

    
276

    
277
	/**
278
	 * Return a List of name relationships in which this name is related to
279
	 * another name, optionally filtered by relationship type
280
	 *
281
	 * @param name
282
	 *            the name on either the <i>"from side"</i> or on the
283
	 *            <i>"to side"</i> of the relationship, depending on the
284
	 *            <code>direction</code> of the relationship.
285
	 * @param direction
286
	 *            the direction of the NameRelationship, may be null to return all relationships
287
	 * @param type
288
	 *            the relationship type (or null to return all relationships)
289
	 * @param pageSize
290
	 *            The maximum number of relationships returned (can be null for
291
	 *            all relationships)
292
	 * @param pageNumber
293
	 *            The offset (in pageSize chunks) from the start of the result
294
	 *            set (0 - based)
295
	 * @param orderHints
296
	 *            may be null
297
	 * @param propertyPaths
298
	 *            properties to initialize - see
299
	 *            {@link IBeanInitializer#initialize(Object, List)}
300
	 * @return a Pager of NameRelationship instances
301
	 */
302
	public List<NameRelationship> listNameRelationships(TaxonNameBase name,  NameRelationship.Direction direction, NameRelationshipType type, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths);
303

    
304
	/**
305
	 * Return a List of name relationships in which this name is related to another name, optionally filtered
306
	 * by relationship type
307
	 *
308
	 * @param name the name on the <i>"from side"</i> of the relationship
309
	 * @param direction the direction of the NameRelationship
310
	 * @param type the relationship type (or null to return all relationships)
311
	 * @param pageSize The maximum number of relationships returned (can be null for all relationships)
312
	 * @param pageNumber The offset (in pageSize chunks) from the start of the result set (0 - based)
313
	 * @param orderHints may be null
314
	 * @param propertyPaths properties to initialize - see {@link IBeanInitializer#initialize(Object, List)}
315
	 * @return a Pager of NameRelationship instances
316
	 */
317
	public Pager<NameRelationship> pageNameRelationships(TaxonNameBase name,  NameRelationship.Direction direction, NameRelationshipType type, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths);
318

    
319
	/**
320
	 * Return a List of relationships in which this name is related to another name, optionally filtered
321
	 * by relationship type
322
	 *
323
	 * @param name the name on the <i>"from side"</i> of the relationship
324
	 * @param type the relationship type (or null to return all relationships)
325
	 * @param pageSize The maximum number of relationships returned (can be null for all relationships)
326
	 * @param pageNumber The offset (in pageSize chunks) from the start of the result set (0 - based)
327
	 * @param orderHints may be null
328
	 * @param propertyPaths properties to initialize - see {@link IBeanInitializer#initialize(Object, List)}
329
	 * @return a Pager of NameRelationship instances
330
	 * @deprecated use {@link #listNameRelationships(TaxonNameBase, eu.etaxonomy.cdm.model.common.RelationshipBase.Direction, NameRelationshipType, Integer, Integer, List, List)} instead
331
	 */
332
	@Deprecated
333
	public List<NameRelationship> listFromNameRelationships(TaxonNameBase name,  NameRelationshipType type, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths);
334

    
335
	/**
336
	 * Return a List of relationships in which this name is related to another name, optionally filtered
337
	 * by relationship type
338
	 *
339
	 * @param name the name on the <i>"from side"</i> of the relationship
340
	 * @param type the relationship type (or null to return all relationships)
341
	 * @param pageSize The maximum number of relationships returned (can be null for all relationships)
342
	 * @param pageNumber The offset (in pageSize chunks) from the start of the result set (0 - based)
343
	 * @param orderHints may be null
344
	 * @param propertyPaths properties to initialize - see {@link IBeanInitializer#initialize(Object, List)}
345
	 * @return a Pager of NameRelationship instances
346
	 * @deprecated use {@link #pageNameRelationships(TaxonNameBase, eu.etaxonomy.cdm.model.common.RelationshipBase.Direction, NameRelationshipType, Integer, Integer, List, List)} instead
347
	 */
348
	@Deprecated
349
	public Pager<NameRelationship> pageFromNameRelationships(TaxonNameBase name,  NameRelationshipType type, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths);
350

    
351
	/**
352
	 * Return a List of relationships in which another name is related to this name, optionally filtered
353
	 * by relationship type
354
	 *
355
	 * @param name the name on the <i>"to side"</i> of the relationship
356
	 * @param type the relationship type (or null to return all relationships)
357
	 * @param pageSize The maximum number of relationships returned (can be null for all relationships)
358
	 * @param pageNumber The offset (in pageSize chunks) from the start of the result set (0 - based)
359
	 * @param orderHints may be null
360
	 * @param propertyPaths properties to initialize - see {@link IBeanInitializer#initialize(Object, List)}
361
	 * @return a Pager of NameRelationship instances
362
	 * @deprecated use {@link #listNameRelationships(TaxonNameBase, eu.etaxonomy.cdm.model.common.RelationshipBase.Direction, NameRelationshipType, Integer, Integer, List, List)} instead
363
	 */
364
	@Deprecated
365
	public List<NameRelationship> listToNameRelationships(TaxonNameBase name,  NameRelationshipType type, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths);
366

    
367
	/**
368
	 * Return a List of relationships in which another name is related to this name, optionally filtered
369
	 * by relationship type
370
	 *
371
	 * @param name the name on the <i>"to side"</i> of the relationship
372
	 * @param type the relationship type (or null to return all relationships)
373
	 * @param pageSize The maximum number of relationships returned (can be null for all relationships)
374
	 * @param pageNumber The offset (in pageSize chunks) from the start of the result set (0 - based)
375
	 * @param orderHints may be null
376
	 * @param propertyPaths properties to initialize - see {@link IBeanInitializer#initialize(Object, List)}
377
	 * @return a Pager of NameRelationship instances
378
	 * @deprecated use {@link #pageNameRelationships(TaxonNameBase, eu.etaxonomy.cdm.model.common.RelationshipBase.Direction, NameRelationshipType, Integer, Integer, List, List)} instead
379
	 */
380
	@Deprecated
381
	public Pager<NameRelationship> pageToNameRelationships(TaxonNameBase name,  NameRelationshipType type, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths);
382

    
383

    
384
	/**
385
	 * Return a List of hybrids related to this name, optionally filtered
386
	 * by hybrid relationship type
387
	 *
388
	 * @param name the name
389
	 * @param type the hybrid relationship type (or null to return all hybrids)
390
	 * @param pageSize The maximum number of hybrid relationships returned (can be null for all relationships)
391
	 * @param pageNumber The offset (in pageSize chunks) from the start of the result set (0 - based)
392
	 * @param orderHints may be null
393
	 * @param propertyPaths properties to initialize - see {@link IBeanInitializer#initialize(Object, List)}
394
	 * @return a Pager of HybridRelationship instances
395
	 */
396
	public Pager<HybridRelationship> getHybridNames(NonViralName name, HybridRelationshipType type, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths);
397

    
398
	/**
399
	 * Return a List of types related to this name, optionally filtered
400
	 * by type designation status
401
	 *
402
	 * @param name the name
403
	 * @param status the type designation status (or null to return all types)
404
	 * @param pageSize The maximum number of types returned (can be null for all types)
405
	 * @param pageNumber The offset (in pageSize chunks) from the start of the result set (0 - based)
406
	 * @return a Pager of TypeDesignationBase instances
407
	 */
408
	public Pager<TypeDesignationBase> getTypeDesignations(TaxonNameBase name,
409
			SpecimenTypeDesignationStatus status, Integer pageSize, Integer pageNumber);
410

    
411
	public Pager<TypeDesignationBase> getTypeDesignations(TaxonNameBase name,
412
			SpecimenTypeDesignationStatus status, Integer pageSize, Integer pageNumber, List<String> propertyPaths);
413

    
414

    
415
	/**
416
	 * Returns a List of TaxonNameBase instances that match the properties passed
417
	 *
418
	 * @param uninomial
419
	 * @param infraGenericEpithet
420
	 * @param specificEpithet
421
	 * @param infraspecificEpithet
422
	 * @param rank
423
	 * @param pageSize The maximum number of names returned (can be null for all names)
424
	 * @param pageNumber The offset (in pageSize chunks) from the start of the result set (0 - based)
425
	 * @param orderHints may be null
426
	 * @param propertyPaths properties to initialize - see {@link IBeanInitializer#initialize(Object, List)}
427
	 * @return a Pager of TaxonNameBase instances
428
	 */
429
	public Pager<TaxonNameBase> searchNames(String uninomial, String infraGenericEpithet, String specificEpithet, String infraspecificEpithet, Rank rank, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths);
430

    
431
	/**
432
	 * Returns a Paged List of TaxonNameBase instances where the default field matches the String queryString (as interpreted by the Lucene QueryParser)
433
	 *
434
	 * @param clazz filter the results by class (or pass null to return all TaxonNameBase instances)
435
	 * @param queryString
436
	 * @param pageSize The maximum number of names returned (can be null for all matching names)
437
	 * @param pageNumber The offset (in pageSize chunks) from the start of the result set (0 - based)
438
	 * @param orderHints
439
	 *            Supports path like <code>orderHints.propertyNames</code> which
440
	 *            include *-to-one properties like createdBy.username or
441
	 *            authorTeam.persistentTitleCache
442
	 * @param propertyPaths properties to be initialized
443
	 * @return a Pager TaxonNameBase instances
444
	 * @see <a href="http://lucene.apache.org/java/2_4_0/queryparsersyntax.html">Apache Lucene - Query Parser Syntax</a>
445
	 */
446
	@Override
447
    public Pager<TaxonNameBase> search(Class<? extends TaxonNameBase> clazz, String queryString, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths);
448

    
449
	/**
450
	 * Returns a map that holds uuid, titleCache pairs of all names in the current database
451
	 *
452
	 * @return
453
	 * 			a <code>Map</code> containing uuid and titleCache of names
454
	 */
455
	public List<UuidAndTitleCache> getUuidAndTitleCacheOfNames(Integer limit, String pattern);
456

    
457
	/**
458
	 * Return a Pager of names matching the given query string, optionally filtered by class, optionally with a particular MatchMode
459
	 *
460
	 * @param clazz filter by class - can be null to include all instances of type T
461
	 * @param queryString the query string to filter by
462
	 * @param matchmode use a particular type of matching (can be null - defaults to exact matching)
463
	 * @param criteria additional criteria to filter by
464
	 * @param pageSize The maximum number of objects returned (can be null for all objects)
465
	 * @param pageNumber The offset (in pageSize chunks) from the start of the result set (0 - based)
466
	 * @param propertyPaths properties to initialize - see {@link IBeanInitializer#initialize(Object, List)}
467
	 * @param orderHints
468
	 *            Supports path like <code>orderHints.propertyNames</code> which
469
	 *            include *-to-one properties like createdBy.username or
470
	 *            authorTeam.persistentTitleCache
471
	 * @return a paged list of instances of type T matching the queryString
472
	 */
473
    public Pager<TaxonNameBase> findByName(Class<? extends TaxonNameBase> clazz, String queryString,MatchMode matchmode, List<Criterion> criteria, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths);
474

    
475
    /**
476
     * Returns a homotypical group with the given UUID or null if not homotypical group exists with that UUID
477
     *
478
     * @param uuid the uuid of the homotypical group
479
     * @return a homotypical group
480
     */
481
    public HomotypicalGroup findHomotypicalGroup(UUID uuid);
482

    
483
    /**
484
     * @param uuid
485
     * @return
486
     */
487
    public List<TaggedText> getTaggedName(UUID uuid);
488

    
489
    /**
490
     * @param nameUuid
491
     * @return
492
     */
493
    public UpdateResult setAsGroupsBasionym(UUID nameUuid);
494

    
495
	public List<HashMap<String, String>> getNameRecords();
496

    
497

    
498
}
(48-48/97)