2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
10 package eu
.etaxonomy
.cdm
.api
.service
;
12 import java
.io
.IOException
;
13 import java
.util
.Collection
;
14 import java
.util
.HashMap
;
15 import java
.util
.List
;
17 import java
.util
.Optional
;
19 import java
.util
.UUID
;
21 import org
.hibernate
.criterion
.Criterion
;
23 import eu
.etaxonomy
.cdm
.api
.service
.config
.NameDeletionConfigurator
;
24 import eu
.etaxonomy
.cdm
.api
.service
.pager
.Pager
;
25 import eu
.etaxonomy
.cdm
.api
.service
.search
.DocumentSearchResult
;
26 import eu
.etaxonomy
.cdm
.api
.service
.search
.LuceneParseException
;
27 import eu
.etaxonomy
.cdm
.api
.service
.search
.SearchResult
;
28 import eu
.etaxonomy
.cdm
.api
.utility
.TaxonNamePartsFilter
;
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
.INonViralName
;
36 import eu
.etaxonomy
.cdm
.model
.name
.NameRelationship
;
37 import eu
.etaxonomy
.cdm
.model
.name
.NameRelationshipType
;
38 import eu
.etaxonomy
.cdm
.model
.name
.NomenclaturalStatus
;
39 import eu
.etaxonomy
.cdm
.model
.name
.Rank
;
40 import eu
.etaxonomy
.cdm
.model
.name
.SpecimenTypeDesignationStatus
;
41 import eu
.etaxonomy
.cdm
.model
.name
.TaxonName
;
42 import eu
.etaxonomy
.cdm
.model
.name
.TypeDesignationBase
;
43 import eu
.etaxonomy
.cdm
.persistence
.dto
.TaxonNameParts
;
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
;
49 public interface INameService
50 extends IIdentifiableEntityService
<TaxonName
> {
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.
60 public DeleteResult
delete(UUID nameUUID
, NameDeletionConfigurator config
);
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
72 public DeleteResult
deleteTypeDesignation(TaxonName name
, TypeDesignationBase typeDesignation
);
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
84 public DeleteResult
deleteTypeDesignation(UUID nameUuid
, UUID typeDesignationUuid
);
88 * Saves the given type designations.
89 * @param typeDesignationCollection
92 public Map
<UUID
, TypeDesignationBase
> saveTypeDesignationAll(Collection
<TypeDesignationBase
> typeDesignationCollection
);
94 public Map
<UUID
, ReferencedEntityBase
> saveReferencedEntitiesAll(Collection
<ReferencedEntityBase
> referencedEntityCollection
);
97 * Saves the given homotypical groups.
98 * @param homotypicalGroups
101 public Map
<UUID
, HomotypicalGroup
> saveAllHomotypicalGroups(Collection
<HomotypicalGroup
> homotypicalGroups
);
104 * Returns all nomenclatural status.
109 public List
<NomenclaturalStatus
> getAllNomenclaturalStatus(int limit
, int start
);
112 * Returns all type designations.
117 public List
<TypeDesignationBase
> getAllTypeDesignations(int limit
, int start
);
119 public TypeDesignationBase
loadTypeDesignation(int id
, List
<String
> propertyPaths
);
121 public TypeDesignationBase
loadTypeDesignation(UUID uuid
, List
<String
> propertyPaths
);
124 * Returns all NonViralNames with a name cache that matches the given string
128 public List
<TaxonName
> getNamesByNameCache(String nameCache
);
131 * Returns all NonViralNames with a title cache that matches the given string
132 * using the given match mode and initialization strategy
135 * @param matchMode must not be <code>NULL</code>
136 * @param propertyPaths
139 public List
<TaxonName
> findNamesByTitleCache(String titleCache
, MatchMode matchMode
, List
<String
> propertyPaths
);
142 * Supports using wildcards in the query parameters.
143 * If a name part passed to the method contains the asterisk character ('*') it will be translated into '%' the related field is search with a LIKE clause.
145 * A query parameter which is passed as <code>NULL</code> value will be ignored. A parameter passed as {@link Optional} object containing a <code>NULL</code> value will be used
146 * to filter select taxon names where the according field is <code>null</code>.
149 * @param infraGenericEpithet
150 * @param specificEpithet
151 * @param infraSpecificEpithet
153 * Only names having the specified rank are taken into account.
154 * @param excludedNamesUuids
155 * Names to be excluded from the result set
158 public Pager
<TaxonNameParts
> findTaxonNameParts(Optional
<String
> genusOrUninomial
,
159 Optional
<String
> infraGenericEpithet
, Optional
<String
> specificEpithet
,
160 Optional
<String
> infraSpecificEpithet
, Rank rank
, Set
<UUID
> excludedNamesUuids
,
161 Integer pageSize
, Integer pageIndex
, List
<OrderHint
> orderHints
);
164 * <b>This method behaves differently compared to {@link #findTaxonNameParts(Optional, Optional, Optional, Optional, Rank, Integer, Integer, List)}!</b>
166 * The {@link TaxonNamePartsFilter} defines the rank and fixed name parts for the search process.
167 * For example: In case the <code>rank</code> is "genus", the <code>genusOrUninomial</code> will be used as search parameter which needs to match exactly.
168 * The <code>namePartQueryString</code> will be used to do a wildcard search on the specificEpithet.
170 * For name part lookup purposes the <code>TaxonNameParts</code> in the result list can be asked to return the relavant name part by
171 * calling {@link TaxonNameParts#nameRankSpecificNamePart(TaxonName)}
177 public Pager
<TaxonNameParts
> findTaxonNameParts(TaxonNamePartsFilter filter
, String namePartQueryString
, Integer pageSize
, Integer pageIndex
, List
<OrderHint
> orderHints
);
180 * Returns all NonViralNames with a name cache that matches the given string
181 * using the given match mode and initialization strategy
185 * @param propertyPaths
188 public List
<TaxonName
> findNamesByNameCache(String nameCache
, MatchMode matchMode
, List
<String
> propertyPaths
);
191 * Fuzzy matching for the taxon name elements. The input name is first atomised using the {@link NonViralNameParserImpl}
192 * into its separate parts (genusOrUninomial,infraGenericEpithet,specificEpithet,infraGenericEpithet,authorshipCache).
193 * Each field is then matched separately with the same accuracy parameter.
195 * @param name taxon name to fuzzy match
196 * @param accuracy value > 0.0 and < 1.0 which determines the accuracy of the result.
197 * @param languages list of languages to consider when matching (currently not used)
198 * @param highlightFragments
199 * @param propertyPaths
200 * @param maxNoOfResults
202 * @throws CorruptIndexException
203 * @throws IOException
204 * @throws ParseException
206 public List
<SearchResult
<TaxonName
>> findByNameFuzzySearch(
209 List
<Language
> languages
,
210 boolean highlightFragments
,
211 List
<String
> propertyPaths
,
212 int maxNoOfResults
) throws IOException
, LuceneParseException
;
215 * Fuzzy matching for the taxon name elements using only the lucene index.
217 * The input name is first atomised using the {@link NonViralNameParserImpl}
218 * into its separate parts (genusOrUninomial,infraGenericEpithet,specificEpithet,infraGenericEpithet,authorshipCache).
219 * Each field is then matched separately with the same accuracy parameter.
221 * @param name taxon name to fuzzy match
222 * @param accuracy value > 0.0 and < 1.0 which determines the accuracy of the result.
223 * @param languages list of languages to consider when matching (currently not used)
224 * @param highlightFragments
225 * @param maxNoOfResults
227 * @throws CorruptIndexException
228 * @throws IOException
229 * @throws ParseException
231 public List
<DocumentSearchResult
> findByNameFuzzySearch(
234 List
<Language
> languages
,
235 boolean highlightFragments
,
236 int maxNoOfResults
) throws IOException
, LuceneParseException
;
239 * Fuzzy matching against the name cache using only the lucene index.
242 * @param name taxon name to fuzzy match
243 * @param accuracy value > 0.0 and < 1.0 which determines the accuracy of the result.
244 * @param languages list of languages to consider when matching (currently not used)
245 * @param highlightFragments
246 * @param maxNoOfResults
248 * @throws CorruptIndexException
249 * @throws IOException
250 * @throws ParseException
252 public List
<DocumentSearchResult
> findByFuzzyNameCacheSearch(
255 List
<Language
> languages
,
256 boolean highlightFragments
,
257 int maxNoOfResults
) throws IOException
, LuceneParseException
;
260 * Exact matching for the taxon name elements using only the lucene index.
262 * The input name is first atomised using the {@link NonViralNameParserImpl}
263 * into its separate parts (genusOrUninomial,infraGenericEpithet,specificEpithet,infraGenericEpithet,authorshipCache).
264 * Each field is then matched separately with the same accuracy parameter.
266 * @param name taxon name to fuzzy match
267 * @param wildcard boolean flag to indicate whether a wildcard '*' should be added at the end of the query
268 * @param languages list of languages to consider when matching (currently not used)
269 * @param highlightFragments
270 * @param maxNoOfResults
272 * @throws CorruptIndexException
273 * @throws IOException
274 * @throws ParseException
277 public List
<DocumentSearchResult
> findByNameExactSearch(
280 List
<Language
> languages
,
281 boolean highlightFragments
,
282 int maxNoOfResults
) throws IOException
, LuceneParseException
;
284 // TODO: Remove getNamesByName() methods. Use findNamesByTitle() instead.
286 public List
<HomotypicalGroup
> getAllHomotypicalGroups(int limit
, int start
);
289 public List
<RelationshipBase
> getAllRelationships(int limit
, int start
);
293 * Return a List of name relationships in which this name is related to
294 * another name, optionally filtered by relationship type
297 * the name on either the <i>"from side"</i> or on the
298 * <i>"to side"</i> of the relationship, depending on the
299 * <code>direction</code> of the relationship.
301 * the direction of the NameRelationship, may be null to return all relationships
303 * the relationship type (or null to return all relationships)
305 * The maximum number of relationships returned (can be null for
308 * The offset (in pageSize chunks) from the start of the result
312 * @param propertyPaths
313 * properties to initialize - see
314 * {@link IBeanInitializer#initialize(Object, List)}
315 * @return a Pager of NameRelationship instances
317 public List
<NameRelationship
> listNameRelationships(TaxonName name
, NameRelationship
.Direction direction
, NameRelationshipType type
, Integer pageSize
, Integer pageNumber
, List
<OrderHint
> orderHints
, List
<String
> propertyPaths
);
320 * Return a List of name relationships in which this name is related to another name, optionally filtered
321 * by relationship type
323 * @param name the name on the <i>"from side"</i> of the relationship
324 * @param direction the direction of the NameRelationship
325 * @param type the relationship type (or null to return all relationships)
326 * @param pageSize The maximum number of relationships returned (can be null for all relationships)
327 * @param pageNumber The offset (in pageSize chunks) from the start of the result set (0 - based)
328 * @param orderHints may be null
329 * @param propertyPaths properties to initialize - see {@link IBeanInitializer#initialize(Object, List)}
330 * @return a Pager of NameRelationship instances
332 public Pager
<NameRelationship
> pageNameRelationships(TaxonName name
, NameRelationship
.Direction direction
, NameRelationshipType type
, Integer pageSize
, Integer pageNumber
, List
<OrderHint
> orderHints
, List
<String
> propertyPaths
);
335 * Return a List of relationships in which this name is related to another name, optionally filtered
336 * by relationship type
338 * @param name the name on the <i>"from side"</i> of the relationship
339 * @param type the relationship type (or null to return all relationships)
340 * @param pageSize The maximum number of relationships returned (can be null for all relationships)
341 * @param pageNumber The offset (in pageSize chunks) from the start of the result set (0 - based)
342 * @param orderHints may be null
343 * @param propertyPaths properties to initialize - see {@link IBeanInitializer#initialize(Object, List)}
344 * @return a Pager of NameRelationship instances
345 * @deprecated use {@link #listNameRelationships(TaxonName, eu.etaxonomy.cdm.model.common.RelationshipBase.Direction, NameRelationshipType, Integer, Integer, List, List)} instead
348 public List
<NameRelationship
> listFromNameRelationships(TaxonName name
, NameRelationshipType type
, Integer pageSize
, Integer pageNumber
, List
<OrderHint
> orderHints
, List
<String
> propertyPaths
);
351 * Return a List of relationships in which this name is related to another name, optionally filtered
352 * by relationship type
354 * @param name the name on the <i>"from side"</i> of the relationship
355 * @param type the relationship type (or null to return all relationships)
356 * @param pageSize The maximum number of relationships returned (can be null for all relationships)
357 * @param pageNumber The offset (in pageSize chunks) from the start of the result set (0 - based)
358 * @param orderHints may be null
359 * @param propertyPaths properties to initialize - see {@link IBeanInitializer#initialize(Object, List)}
360 * @return a Pager of NameRelationship instances
361 * @deprecated use {@link #pageNameRelationships(TaxonName, eu.etaxonomy.cdm.model.common.RelationshipBase.Direction, NameRelationshipType, Integer, Integer, List, List)} instead
364 public Pager
<NameRelationship
> pageFromNameRelationships(TaxonName name
, NameRelationshipType type
, Integer pageSize
, Integer pageNumber
, List
<OrderHint
> orderHints
, List
<String
> propertyPaths
);
367 * Return a List of relationships in which another name is related to this name, optionally filtered
368 * by relationship type
370 * @param name the name on the <i>"to side"</i> of the relationship
371 * @param type the relationship type (or null to return all relationships)
372 * @param pageSize The maximum number of relationships returned (can be null for all relationships)
373 * @param pageNumber The offset (in pageSize chunks) from the start of the result set (0 - based)
374 * @param orderHints may be null
375 * @param propertyPaths properties to initialize - see {@link IBeanInitializer#initialize(Object, List)}
376 * @return a Pager of NameRelationship instances
377 * @deprecated use {@link #listNameRelationships(TaxonName, eu.etaxonomy.cdm.model.common.RelationshipBase.Direction, NameRelationshipType, Integer, Integer, List, List)} instead
380 public List
<NameRelationship
> listToNameRelationships(TaxonName name
, NameRelationshipType type
, Integer pageSize
, Integer pageNumber
, List
<OrderHint
> orderHints
, List
<String
> propertyPaths
);
383 * Return a List of relationships in which another name is related to this name, optionally filtered
384 * by relationship type
386 * @param name the name on the <i>"to side"</i> of the relationship
387 * @param type the relationship type (or null to return all relationships)
388 * @param pageSize The maximum number of relationships returned (can be null for all relationships)
389 * @param pageNumber The offset (in pageSize chunks) from the start of the result set (0 - based)
390 * @param orderHints may be null
391 * @param propertyPaths properties to initialize - see {@link IBeanInitializer#initialize(Object, List)}
392 * @return a Pager of NameRelationship instances
393 * @deprecated use {@link #pageNameRelationships(TaxonName, eu.etaxonomy.cdm.model.common.RelationshipBase.Direction, NameRelationshipType, Integer, Integer, List, List)} instead
396 public Pager
<NameRelationship
> pageToNameRelationships(TaxonName name
, NameRelationshipType type
, Integer pageSize
, Integer pageNumber
, List
<OrderHint
> orderHints
, List
<String
> propertyPaths
);
400 * Return a List of hybrids related to this name, optionally filtered
401 * by hybrid relationship type
403 * @param name the name
404 * @param type the hybrid relationship type (or null to return all hybrids)
405 * @param pageSize The maximum number of hybrid relationships returned (can be null for all relationships)
406 * @param pageNumber The offset (in pageSize chunks) from the start of the result set (0 - based)
407 * @param orderHints may be null
408 * @param propertyPaths properties to initialize - see {@link IBeanInitializer#initialize(Object, List)}
409 * @return a Pager of HybridRelationship instances
411 public Pager
<HybridRelationship
> getHybridNames(INonViralName name
, HybridRelationshipType type
, Integer pageSize
, Integer pageNumber
, List
<OrderHint
> orderHints
, List
<String
> propertyPaths
);
414 * Return a List of types related to this name, optionally filtered
415 * by type designation status
417 * @param name the name
418 * @param status the type designation status (or null to return all types)
419 * @param pageSize The maximum number of types returned (can be null for all types)
420 * @param pageNumber The offset (in pageSize chunks) from the start of the result set (0 - based)
421 * @return a Pager of TypeDesignationBase instances
423 public Pager
<TypeDesignationBase
> getTypeDesignations(TaxonName name
,
424 SpecimenTypeDesignationStatus status
, Integer pageSize
, Integer pageNumber
);
426 public Pager
<TypeDesignationBase
> getTypeDesignations(TaxonName name
,
427 SpecimenTypeDesignationStatus status
, Integer pageSize
, Integer pageNumber
, List
<String
> propertyPaths
);
431 * Returns a List of TaxonName instances that match the properties passed
434 * @param infraGenericEpithet
435 * @param specificEpithet
436 * @param infraspecificEpithet
438 * @param pageSize The maximum number of names returned (can be null for all names)
439 * @param pageNumber The offset (in pageSize chunks) from the start of the result set (0 - based)
440 * @param orderHints may be null
441 * @param propertyPaths properties to initialize - see {@link IBeanInitializer#initialize(Object, List)}
442 * @return a Pager of TaxonName instances
444 public Pager
<TaxonName
> searchNames(String uninomial
, String infraGenericEpithet
, String specificEpithet
, String infraspecificEpithet
, Rank rank
, Integer pageSize
, Integer pageNumber
, List
<OrderHint
> orderHints
, List
<String
> propertyPaths
);
447 * Returns a Paged List of TaxonName instances where the default field matches the String queryString (as interpreted by the Lucene QueryParser)
449 * @param clazz filter the results by class (or pass null to return all TaxonName instances)
451 * @param pageSize The maximum number of names returned (can be null for all matching names)
452 * @param pageNumber The offset (in pageSize chunks) from the start of the result set (0 - based)
454 * Supports path like <code>orderHints.propertyNames</code> which
455 * include *-to-one properties like createdBy.username or
456 * authorTeam.persistentTitleCache
457 * @param propertyPaths properties to be initialized
458 * @return a Pager TaxonName instances
459 * @see <a href="http://lucene.apache.org/java/2_4_0/queryparsersyntax.html">Apache Lucene - Query Parser Syntax</a>
462 public Pager
<TaxonName
> search(Class
<?
extends TaxonName
> clazz
, String queryString
, Integer pageSize
, Integer pageNumber
, List
<OrderHint
> orderHints
, List
<String
> propertyPaths
);
465 * Returns a map that holds uuid, titleCache pairs of all names in the current database
468 * a <code>Map</code> containing uuid and titleCache of names
470 public List
<UuidAndTitleCache
> getUuidAndTitleCacheOfNames(Integer limit
, String pattern
);
473 * Return a Pager of names matching the given query string, optionally filtered by class, optionally with a particular MatchMode
475 * @param clazz filter by class - can be null to include all instances of type T
476 * @param queryString the query string to filter by
477 * @param matchmode use a particular type of matching (can be null - defaults to exact matching)
478 * @param criteria additional criteria to filter by
479 * @param pageSize The maximum number of objects returned (can be null for all objects)
480 * @param pageNumber The offset (in pageSize chunks) from the start of the result set (0 - based)
481 * @param propertyPaths properties to initialize - see {@link IBeanInitializer#initialize(Object, List)}
483 * Supports path like <code>orderHints.propertyNames</code> which
484 * include *-to-one properties like createdBy.username or
485 * authorTeam.persistentTitleCache
486 * @return a paged list of instances of type T matching the queryString
488 public Pager
<TaxonName
> findByName(Class
<TaxonName
> clazz
, String queryString
, MatchMode matchmode
,
489 List
<Criterion
> criteria
, Integer pageSize
, Integer pageNumber
, List
<OrderHint
> orderHints
, List
<String
> propertyPaths
);
492 * Returns a homotypical group with the given UUID or null if not homotypical group exists with that UUID
494 * @param uuid the uuid of the homotypical group
495 * @return a homotypical group
497 public HomotypicalGroup
findHomotypicalGroup(UUID uuid
);
503 public List
<TaggedText
> getTaggedName(UUID uuid
);
509 public UpdateResult
setAsGroupsBasionym(UUID nameUuid
);
511 public List
<HashMap
<String
, String
>> getNameRecords();
518 DeleteResult
delete(TaxonName name
, NameDeletionConfigurator config
);