3 * Copyright (C) 2007 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
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.
11 package eu
.etaxonomy
.cdm
.api
.service
;
13 import java
.io
.IOException
;
14 import java
.util
.Collection
;
15 import java
.util
.HashMap
;
16 import java
.util
.List
;
18 import java
.util
.UUID
;
20 import org
.apache
.lucene
.index
.CorruptIndexException
;
21 import org
.apache
.lucene
.queryparser
.classic
.ParseException
;
22 import org
.hibernate
.criterion
.Criterion
;
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
;
50 public interface INameService
extends IIdentifiableEntityService
<TaxonNameBase
> {
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 void deleteTypeDesignation(TaxonNameBase name
, TypeDesignationBase typeDesignation
);
76 * Saves the given type designations.
77 * @param typeDesignationCollection
80 public Map
<UUID
, TypeDesignationBase
> saveTypeDesignationAll(Collection
<TypeDesignationBase
> typeDesignationCollection
);
82 public Map
<UUID
, ReferencedEntityBase
> saveReferencedEntitiesAll(Collection
<ReferencedEntityBase
> referencedEntityCollection
);
85 * Saves the given homotypical groups.
86 * @param homotypicalGroups
89 public Map
<UUID
, HomotypicalGroup
> saveAllHomotypicalGroups(Collection
<HomotypicalGroup
> homotypicalGroups
);
92 * Returns all nomenclatural status.
97 public List
<NomenclaturalStatus
> getAllNomenclaturalStatus(int limit
, int start
);
100 * Returns all type designations.
105 public List
<TypeDesignationBase
> getAllTypeDesignations(int limit
, int start
);
111 public List
<TaxonNameBase
> getNamesByName(String name
);
114 * Returns all NonViralNames with a name cache that matches the given string
118 public List
<NonViralName
> getNamesByNameCache(String nameCache
);
121 * Returns all NonViralNames with a title cache that matches the given string
122 * using the given match mode and initialization strategy
126 * @param propertyPaths
129 public List
<NonViralName
> findNamesByTitleCache(String titleCache
, MatchMode matchMode
, List
<String
> propertyPaths
);
132 * Returns all NonViralNames with a name cache that matches the given string
133 * using the given match mode and initialization strategy
137 * @param propertyPaths
140 public List
<NonViralName
> findNamesByNameCache(String nameCache
, MatchMode matchMode
, List
<String
> propertyPaths
);
143 * Returns the NonViralName with the given UUID
144 * using the given match mode and initialization strategy
147 * @param propertyPaths
150 public NonViralName
findNameByUuid(UUID uuid
, List
<String
> propertyPaths
);
153 * @param sessionObject An object that is attached to the session before executing the query
156 public List
getNamesByName(String name
, CdmBase sessionObject
);
159 * Fuzzy matching for the taxon name elements. The input name is first atomised using the {@link NonViralNameParserImpl}
160 * into its separate parts (genusOrUninomial,infraGenericEpithet,specificEpithet,infraGenericEpithet,authorshipCache).
161 * Each field is then matched separately with the same accuracy parameter.
163 * @param name taxon name to fuzzy match
164 * @param accuracy value > 0.0 and < 1.0 which determines the accuracy of the result.
165 * @param languages list of languages to consider when matching (currently not used)
166 * @param highlightFragments
167 * @param propertyPaths
168 * @param maxNoOfResults
170 * @throws CorruptIndexException
171 * @throws IOException
172 * @throws ParseException
174 public List
<SearchResult
<TaxonNameBase
>> findByNameFuzzySearch(
177 List
<Language
> languages
,
178 boolean highlightFragments
,
179 List
<String
> propertyPaths
,
180 int maxNoOfResults
) throws CorruptIndexException
, IOException
, ParseException
;
183 * Fuzzy matching for the taxon name elements using only the lucene index.
185 * The input name is first atomised using the {@link NonViralNameParserImpl}
186 * into its separate parts (genusOrUninomial,infraGenericEpithet,specificEpithet,infraGenericEpithet,authorshipCache).
187 * Each field is then matched separately with the same accuracy parameter.
189 * @param name taxon name to fuzzy match
190 * @param accuracy value > 0.0 and < 1.0 which determines the accuracy of the result.
191 * @param languages list of languages to consider when matching (currently not used)
192 * @param highlightFragments
193 * @param maxNoOfResults
195 * @throws CorruptIndexException
196 * @throws IOException
197 * @throws ParseException
199 public List
<DocumentSearchResult
> findByNameFuzzySearch(
202 List
<Language
> languages
,
203 boolean highlightFragments
,
204 int maxNoOfResults
) throws CorruptIndexException
, IOException
, ParseException
;
207 * Fuzzy matching against the name cache using only the lucene index.
210 * @param name taxon name to fuzzy match
211 * @param accuracy value > 0.0 and < 1.0 which determines the accuracy of the result.
212 * @param languages list of languages to consider when matching (currently not used)
213 * @param highlightFragments
214 * @param maxNoOfResults
216 * @throws CorruptIndexException
217 * @throws IOException
218 * @throws ParseException
220 public List
<DocumentSearchResult
> findByFuzzyNameCacheSearch(
223 List
<Language
> languages
,
224 boolean highlightFragments
,
225 int maxNoOfResults
) throws CorruptIndexException
, IOException
, ParseException
;
228 * Exact matching for the taxon name elements using only the lucene index.
230 * The input name is first atomised using the {@link NonViralNameParserImpl}
231 * into its separate parts (genusOrUninomial,infraGenericEpithet,specificEpithet,infraGenericEpithet,authorshipCache).
232 * Each field is then matched separately with the same accuracy parameter.
234 * @param name taxon name to fuzzy match
235 * @param wildcard boolean flag to indicate whether a wildcard '*' should be added at the end of the query
236 * @param languages list of languages to consider when matching (currently not used)
237 * @param highlightFragments
238 * @param maxNoOfResults
240 * @throws CorruptIndexException
241 * @throws IOException
242 * @throws ParseException
245 public List
<DocumentSearchResult
> findByNameExactSearch(
248 List
<Language
> languages
,
249 boolean highlightFragments
,
250 int maxNoOfResults
) throws CorruptIndexException
, IOException
, ParseException
;
252 // TODO: Remove getNamesByName() methods. Use findNamesByTitle() instead.
254 // FIXME candidate for harmonization?
255 public List
findNamesByTitle(String title
);
257 public List
findNamesByTitle(String title
, CdmBase sessionObject
);
259 public List
<HomotypicalGroup
> getAllHomotypicalGroups(int limit
, int start
);
262 public List
<RelationshipBase
> getAllRelationships(int limit
, int start
);
266 * Return a List of name relationships in which this name is related to
267 * another name, optionally filtered by relationship type
270 * the name on either the <i>"from side"</i> or on the
271 * <i>"to side"</i> of the relationship, depending on the
272 * <code>direction</code> of the relationship.
274 * the direction of the NameRelationship, may be null to return all relationships
276 * the relationship type (or null to return all relationships)
278 * The maximum number of relationships returned (can be null for
281 * The offset (in pageSize chunks) from the start of the result
285 * @param propertyPaths
286 * properties to initialize - see
287 * {@link IBeanInitializer#initialize(Object, List)}
288 * @return a Pager of NameRelationship instances
290 public List
<NameRelationship
> listNameRelationships(TaxonNameBase name
, NameRelationship
.Direction direction
, NameRelationshipType type
, Integer pageSize
, Integer pageNumber
, List
<OrderHint
> orderHints
, List
<String
> propertyPaths
);
293 * Return a List of name relationships in which this name is related to another name, optionally filtered
294 * by relationship type
296 * @param name the name on the <i>"from side"</i> of the relationship
297 * @param direction the direction of the NameRelationship
298 * @param type the relationship type (or null to return all relationships)
299 * @param pageSize The maximum number of relationships returned (can be null for all relationships)
300 * @param pageNumber The offset (in pageSize chunks) from the start of the result set (0 - based)
301 * @param orderHints may be null
302 * @param propertyPaths properties to initialize - see {@link IBeanInitializer#initialize(Object, List)}
303 * @return a Pager of NameRelationship instances
305 public Pager
<NameRelationship
> pageNameRelationships(TaxonNameBase name
, NameRelationship
.Direction direction
, NameRelationshipType type
, Integer pageSize
, Integer pageNumber
, List
<OrderHint
> orderHints
, List
<String
> propertyPaths
);
308 * Return a List of relationships in which this name is related to another name, optionally filtered
309 * by relationship type
311 * @param name the name on the <i>"from side"</i> of the relationship
312 * @param type the relationship type (or null to return all relationships)
313 * @param pageSize The maximum number of relationships returned (can be null for all relationships)
314 * @param pageNumber The offset (in pageSize chunks) from the start of the result set (0 - based)
315 * @param orderHints may be null
316 * @param propertyPaths properties to initialize - see {@link IBeanInitializer#initialize(Object, List)}
317 * @return a Pager of NameRelationship instances
318 * @deprecated use {@link #listNameRelationships(TaxonNameBase, eu.etaxonomy.cdm.model.common.RelationshipBase.Direction, NameRelationshipType, Integer, Integer, List, List)} instead
321 public List
<NameRelationship
> listFromNameRelationships(TaxonNameBase name
, NameRelationshipType type
, Integer pageSize
, Integer pageNumber
, List
<OrderHint
> orderHints
, List
<String
> propertyPaths
);
324 * Return a List of relationships in which this name is related to another name, optionally filtered
325 * by relationship type
327 * @param name the name on the <i>"from side"</i> of the relationship
328 * @param type the relationship type (or null to return all relationships)
329 * @param pageSize The maximum number of relationships returned (can be null for all relationships)
330 * @param pageNumber The offset (in pageSize chunks) from the start of the result set (0 - based)
331 * @param orderHints may be null
332 * @param propertyPaths properties to initialize - see {@link IBeanInitializer#initialize(Object, List)}
333 * @return a Pager of NameRelationship instances
334 * @deprecated use {@link #pageNameRelationships(TaxonNameBase, eu.etaxonomy.cdm.model.common.RelationshipBase.Direction, NameRelationshipType, Integer, Integer, List, List)} instead
337 public Pager
<NameRelationship
> pageFromNameRelationships(TaxonNameBase name
, NameRelationshipType type
, Integer pageSize
, Integer pageNumber
, List
<OrderHint
> orderHints
, List
<String
> propertyPaths
);
340 * Return a List of relationships in which another name is related to this name, optionally filtered
341 * by relationship type
343 * @param name the name on the <i>"to side"</i> of the relationship
344 * @param type the relationship type (or null to return all relationships)
345 * @param pageSize The maximum number of relationships returned (can be null for all relationships)
346 * @param pageNumber The offset (in pageSize chunks) from the start of the result set (0 - based)
347 * @param orderHints may be null
348 * @param propertyPaths properties to initialize - see {@link IBeanInitializer#initialize(Object, List)}
349 * @return a Pager of NameRelationship instances
350 * @deprecated use {@link #listNameRelationships(TaxonNameBase, eu.etaxonomy.cdm.model.common.RelationshipBase.Direction, NameRelationshipType, Integer, Integer, List, List)} instead
353 public List
<NameRelationship
> listToNameRelationships(TaxonNameBase name
, NameRelationshipType type
, Integer pageSize
, Integer pageNumber
, List
<OrderHint
> orderHints
, List
<String
> propertyPaths
);
356 * Return a List of relationships in which another name is related to this name, optionally filtered
357 * by relationship type
359 * @param name the name on the <i>"to side"</i> of the relationship
360 * @param type the relationship type (or null to return all relationships)
361 * @param pageSize The maximum number of relationships returned (can be null for all relationships)
362 * @param pageNumber The offset (in pageSize chunks) from the start of the result set (0 - based)
363 * @param orderHints may be null
364 * @param propertyPaths properties to initialize - see {@link IBeanInitializer#initialize(Object, List)}
365 * @return a Pager of NameRelationship instances
366 * @deprecated use {@link #pageNameRelationships(TaxonNameBase, eu.etaxonomy.cdm.model.common.RelationshipBase.Direction, NameRelationshipType, Integer, Integer, List, List)} instead
369 public Pager
<NameRelationship
> pageToNameRelationships(TaxonNameBase name
, NameRelationshipType type
, Integer pageSize
, Integer pageNumber
, List
<OrderHint
> orderHints
, List
<String
> propertyPaths
);
373 * Return a List of hybrids related to this name, optionally filtered
374 * by hybrid relationship type
376 * @param name the name
377 * @param type the hybrid relationship type (or null to return all hybrids)
378 * @param pageSize The maximum number of hybrid relationships returned (can be null for all relationships)
379 * @param pageNumber The offset (in pageSize chunks) from the start of the result set (0 - based)
380 * @param orderHints may be null
381 * @param propertyPaths properties to initialize - see {@link IBeanInitializer#initialize(Object, List)}
382 * @return a Pager of HybridRelationship instances
384 public Pager
<HybridRelationship
> getHybridNames(NonViralName name
, HybridRelationshipType type
, Integer pageSize
, Integer pageNumber
, List
<OrderHint
> orderHints
, List
<String
> propertyPaths
);
387 * Return a List of types related to this name, optionally filtered
388 * by type designation status
390 * @param name the name
391 * @param status the type designation status (or null to return all types)
392 * @param pageSize The maximum number of types returned (can be null for all types)
393 * @param pageNumber The offset (in pageSize chunks) from the start of the result set (0 - based)
394 * @return a Pager of TypeDesignationBase instances
396 public Pager
<TypeDesignationBase
> getTypeDesignations(TaxonNameBase name
,
397 SpecimenTypeDesignationStatus status
, Integer pageSize
, Integer pageNumber
);
399 public Pager
<TypeDesignationBase
> getTypeDesignations(TaxonNameBase name
,
400 SpecimenTypeDesignationStatus status
, Integer pageSize
, Integer pageNumber
, List
<String
> propertyPaths
);
404 * Returns a List of TaxonNameBase instances that match the properties passed
407 * @param infraGenericEpithet
408 * @param specificEpithet
409 * @param infraspecificEpithet
411 * @param pageSize The maximum number of names returned (can be null for all names)
412 * @param pageNumber The offset (in pageSize chunks) from the start of the result set (0 - based)
413 * @param orderHints may be null
414 * @param propertyPaths properties to initialize - see {@link IBeanInitializer#initialize(Object, List)}
415 * @return a Pager of TaxonNameBase instances
417 public Pager
<TaxonNameBase
> searchNames(String uninomial
, String infraGenericEpithet
, String specificEpithet
, String infraspecificEpithet
, Rank rank
, Integer pageSize
, Integer pageNumber
, List
<OrderHint
> orderHints
, List
<String
> propertyPaths
);
420 * Returns a Paged List of TaxonNameBase instances where the default field matches the String queryString (as interpreted by the Lucene QueryParser)
422 * @param clazz filter the results by class (or pass null to return all TaxonNameBase instances)
424 * @param pageSize The maximum number of names returned (can be null for all matching names)
425 * @param pageNumber The offset (in pageSize chunks) from the start of the result set (0 - based)
427 * Supports path like <code>orderHints.propertyNames</code> which
428 * include *-to-one properties like createdBy.username or
429 * authorTeam.persistentTitleCache
430 * @param propertyPaths properties to be initialized
431 * @return a Pager TaxonNameBase instances
432 * @see <a href="http://lucene.apache.org/java/2_4_0/queryparsersyntax.html">Apache Lucene - Query Parser Syntax</a>
435 public Pager
<TaxonNameBase
> search(Class
<?
extends TaxonNameBase
> clazz
, String queryString
, Integer pageSize
, Integer pageNumber
, List
<OrderHint
> orderHints
, List
<String
> propertyPaths
);
438 * Returns a map that holds uuid, titleCache pairs of all names in the current database
441 * a <code>Map</code> containing uuid and titleCache of names
443 public List
<UuidAndTitleCache
> getUuidAndTitleCacheOfNames();
446 * Return a Pager of names matching the given query string, optionally filtered by class, optionally with a particular MatchMode
448 * @param clazz filter by class - can be null to include all instances of type T
449 * @param queryString the query string to filter by
450 * @param matchmode use a particular type of matching (can be null - defaults to exact matching)
451 * @param criteria additional criteria to filter by
452 * @param pageSize The maximum number of objects returned (can be null for all objects)
453 * @param pageNumber The offset (in pageSize chunks) from the start of the result set (0 - based)
454 * @param propertyPaths properties to initialize - see {@link IBeanInitializer#initialize(Object, List)}
456 * Supports path like <code>orderHints.propertyNames</code> which
457 * include *-to-one properties like createdBy.username or
458 * authorTeam.persistentTitleCache
459 * @return a paged list of instances of type T matching the queryString
461 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
);
464 * Returns a homotypical group with the given UUID or null if not homotypical group exists with that UUID
466 * @param uuid the uuid of the homotypical group
467 * @return a homotypical group
469 public HomotypicalGroup
findHomotypicalGroup(UUID uuid
);
475 public List
<TaggedText
> getTaggedName(UUID uuid
);
481 public UpdateResult
setAsGroupsBasionym(UUID nameUuid
);
483 public List
<HashMap
<String
, String
>> getNameRecords();