cleanup
[cdmlib.git] / cdmlib-services / src / main / java / eu / etaxonomy / cdm / api / service / INameService.java
1 /**
2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
5 *
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.
8 */
9
10 package eu.etaxonomy.cdm.api.service;
11
12 import java.io.IOException;
13 import java.util.Collection;
14 import java.util.HashMap;
15 import java.util.List;
16 import java.util.Map;
17 import java.util.Optional;
18 import java.util.Set;
19 import java.util.UUID;
20
21 import org.hibernate.criterion.Criterion;
22
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;
48
49 public interface INameService
50 extends IIdentifiableEntityService<TaxonName> {
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(TaxonName 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 public TypeDesignationBase loadTypeDesignation(int id, List<String> propertyPaths);
120
121 public TypeDesignationBase loadTypeDesignation(UUID uuid, List<String> propertyPaths);
122
123 /**
124 * Returns all NonViralNames with a name cache that matches the given string
125 * @param name
126 * @return
127 */
128 public List<TaxonName> getNamesByNameCache(String nameCache);
129
130 /**
131 * Returns all NonViralNames with a title cache that matches the given string
132 * using the given match mode and initialization strategy
133 *
134 * @param name
135 * @param matchMode must not be <code>NULL</code>
136 * @param propertyPaths
137 * @return
138 */
139 public List<TaxonName> findNamesByTitleCache(String titleCache, MatchMode matchMode, List<String> propertyPaths);
140
141 /**
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.
144 * <p>
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>.
147 *
148 * @param filter
149 * @param infraGenericEpithet
150 * @param specificEpithet
151 * @param infraSpecificEpithet
152 * @param rank
153 * Only names having the specified rank are taken into account.
154 * @param excludedNamesUuids
155 * Names to be excluded from the result set
156 * @return
157 */
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);
162
163 /**
164 * <b>This method behaves differently compared to {@link #findTaxonNameParts(Optional, Optional, Optional, Optional, Rank, Integer, Integer, List)}!</b>
165 * <p>
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.
169 * <p>
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)}
172 *
173 *
174 * @param filter
175 * @return
176 */
177 public Pager<TaxonNameParts> findTaxonNameParts(TaxonNamePartsFilter filter, String namePartQueryString, Integer pageSize, Integer pageIndex, List<OrderHint> orderHints);
178
179 /**
180 * Returns all NonViralNames with a name cache that matches the given string
181 * using the given match mode and initialization strategy
182 *
183 * @param name
184 * @param matchMode
185 * @param propertyPaths
186 * @return
187 */
188 public List<TaxonName> findNamesByNameCache(String nameCache, MatchMode matchMode, List<String> propertyPaths);
189
190 /**
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.
194 *
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
201 * @return
202 * @throws CorruptIndexException
203 * @throws IOException
204 * @throws ParseException
205 */
206 public List<SearchResult<TaxonName>> findByNameFuzzySearch(
207 String name,
208 float accuracy,
209 List<Language> languages,
210 boolean highlightFragments,
211 List<String> propertyPaths,
212 int maxNoOfResults) throws IOException, LuceneParseException;
213
214 /**
215 * Fuzzy matching for the taxon name elements using only the lucene index.
216 *
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.
220 *
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
226 * @return
227 * @throws CorruptIndexException
228 * @throws IOException
229 * @throws ParseException
230 */
231 public List<DocumentSearchResult> findByNameFuzzySearch(
232 String name,
233 float accuracy,
234 List<Language> languages,
235 boolean highlightFragments,
236 int maxNoOfResults) throws IOException, LuceneParseException;
237
238 /**
239 * Fuzzy matching against the name cache using only the lucene index.
240 *
241 *
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
247 * @return
248 * @throws CorruptIndexException
249 * @throws IOException
250 * @throws ParseException
251 */
252 public List<DocumentSearchResult> findByFuzzyNameCacheSearch(
253 String name,
254 float accuracy,
255 List<Language> languages,
256 boolean highlightFragments,
257 int maxNoOfResults) throws IOException, LuceneParseException;
258
259 /**
260 * Exact matching for the taxon name elements using only the lucene index.
261 *
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.
265 *
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
271 * @return
272 * @throws CorruptIndexException
273 * @throws IOException
274 * @throws ParseException
275 */
276
277 public List<DocumentSearchResult> findByNameExactSearch(
278 String name,
279 boolean wildcard,
280 List<Language> languages,
281 boolean highlightFragments,
282 int maxNoOfResults) throws IOException, LuceneParseException;
283
284 // TODO: Remove getNamesByName() methods. Use findNamesByTitle() instead.
285
286 public List<HomotypicalGroup> getAllHomotypicalGroups(int limit, int start);
287
288 @Deprecated
289 public List<RelationshipBase> getAllRelationships(int limit, int start);
290
291
292 /**
293 * Return a List of name relationships in which this name is related to
294 * another name, optionally filtered by relationship type
295 *
296 * @param name
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.
300 * @param direction
301 * the direction of the NameRelationship, may be null to return all relationships
302 * @param type
303 * the relationship type (or null to return all relationships)
304 * @param pageSize
305 * The maximum number of relationships returned (can be null for
306 * all relationships)
307 * @param pageNumber
308 * The offset (in pageSize chunks) from the start of the result
309 * set (0 - based)
310 * @param orderHints
311 * may be null
312 * @param propertyPaths
313 * properties to initialize - see
314 * {@link IBeanInitializer#initialize(Object, List)}
315 * @return a Pager of NameRelationship instances
316 */
317 public List<NameRelationship> listNameRelationships(TaxonName name, NameRelationship.Direction direction, NameRelationshipType type, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths);
318
319 /**
320 * Return a List of name 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 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
331 */
332 public Pager<NameRelationship> pageNameRelationships(TaxonName name, NameRelationship.Direction direction, NameRelationshipType type, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths);
333
334 /**
335 * Return a List of relationships in which this name is related to another name, optionally filtered
336 * by relationship type
337 *
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
346 */
347 @Deprecated
348 public List<NameRelationship> listFromNameRelationships(TaxonName name, NameRelationshipType type, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths);
349
350 /**
351 * Return a List of relationships in which this name is related to another name, optionally filtered
352 * by relationship type
353 *
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
362 */
363 @Deprecated
364 public Pager<NameRelationship> pageFromNameRelationships(TaxonName name, NameRelationshipType type, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths);
365
366 /**
367 * Return a List of relationships in which another name is related to this name, optionally filtered
368 * by relationship type
369 *
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
378 */
379 @Deprecated
380 public List<NameRelationship> listToNameRelationships(TaxonName name, NameRelationshipType type, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths);
381
382 /**
383 * Return a List of relationships in which another name is related to this name, optionally filtered
384 * by relationship type
385 *
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
394 */
395 @Deprecated
396 public Pager<NameRelationship> pageToNameRelationships(TaxonName name, NameRelationshipType type, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths);
397
398
399 /**
400 * Return a List of hybrids related to this name, optionally filtered
401 * by hybrid relationship type
402 *
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
410 */
411 public Pager<HybridRelationship> getHybridNames(INonViralName name, HybridRelationshipType type, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths);
412
413 /**
414 * Return a List of types related to this name, optionally filtered
415 * by type designation status
416 *
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
422 */
423 public Pager<TypeDesignationBase> getTypeDesignations(TaxonName name,
424 SpecimenTypeDesignationStatus status, Integer pageSize, Integer pageNumber);
425
426 public Pager<TypeDesignationBase> getTypeDesignations(TaxonName name,
427 SpecimenTypeDesignationStatus status, Integer pageSize, Integer pageNumber, List<String> propertyPaths);
428
429
430 /**
431 * Returns a List of TaxonName instances that match the properties passed
432 *
433 * @param uninomial
434 * @param infraGenericEpithet
435 * @param specificEpithet
436 * @param infraspecificEpithet
437 * @param rank
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
443 */
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);
445
446 /**
447 * Returns a Paged List of TaxonName instances where the default field matches the String queryString (as interpreted by the Lucene QueryParser)
448 *
449 * @param clazz filter the results by class (or pass null to return all TaxonName instances)
450 * @param queryString
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)
453 * @param orderHints
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>
460 */
461 @Override
462 public Pager<TaxonName> search(Class<? extends TaxonName> clazz, String queryString, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths);
463
464 /**
465 * Returns a map that holds uuid, titleCache pairs of all names in the current database
466 *
467 * @return
468 * a <code>Map</code> containing uuid and titleCache of names
469 */
470 public List<UuidAndTitleCache> getUuidAndTitleCacheOfNames(Integer limit, String pattern);
471
472 /**
473 * Return a Pager of names matching the given query string, optionally filtered by class, optionally with a particular MatchMode
474 *
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)}
482 * @param orderHints
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
487 */
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);
490
491 /**
492 * Returns a homotypical group with the given UUID or null if not homotypical group exists with that UUID
493 *
494 * @param uuid the uuid of the homotypical group
495 * @return a homotypical group
496 */
497 public HomotypicalGroup findHomotypicalGroup(UUID uuid);
498
499 /**
500 * @param uuid
501 * @return
502 */
503 public List<TaggedText> getTaggedName(UUID uuid);
504
505 /**
506 * @param nameUuid
507 * @return
508 */
509 public UpdateResult setAsGroupsBasionym(UUID nameUuid);
510
511 public List<HashMap<String, String>> getNameRecords();
512
513 /**
514 * @param name
515 * @param config
516 * @return
517 */
518 DeleteResult delete(TaxonName name, NameDeletionConfigurator config);
519
520
521 }