INameService : added findByNameExactSearch to return lucene search documents for...
[cdmlib.git] / cdmlib-services / src / main / java / eu / etaxonomy / cdm / api / service / INameService.java
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.List;
16 import java.util.Map;
17 import java.util.UUID;
18
19 import org.apache.lucene.index.CorruptIndexException;
20 import org.apache.lucene.queryParser.ParseException;
21 import org.hibernate.criterion.Criterion;
22
23 import eu.etaxonomy.cdm.api.service.config.NameDeletionConfigurator;
24 import eu.etaxonomy.cdm.api.service.exception.ReferencedObjectUndeletableException;
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.OrderedTermVocabulary;
31 import eu.etaxonomy.cdm.model.common.ReferencedEntityBase;
32 import eu.etaxonomy.cdm.model.common.RelationshipBase;
33 import eu.etaxonomy.cdm.model.common.TermVocabulary;
34 import eu.etaxonomy.cdm.model.common.UuidAndTitleCache;
35 import eu.etaxonomy.cdm.model.name.HomotypicalGroup;
36 import eu.etaxonomy.cdm.model.name.HybridRelationship;
37 import eu.etaxonomy.cdm.model.name.HybridRelationshipType;
38 import eu.etaxonomy.cdm.model.name.NameRelationship;
39 import eu.etaxonomy.cdm.model.name.NameRelationshipType;
40 import eu.etaxonomy.cdm.model.name.NomenclaturalStatus;
41 import eu.etaxonomy.cdm.model.name.NomenclaturalStatusType;
42 import eu.etaxonomy.cdm.model.name.NonViralName;
43 import eu.etaxonomy.cdm.model.name.Rank;
44 import eu.etaxonomy.cdm.model.name.SpecimenTypeDesignationStatus;
45 import eu.etaxonomy.cdm.model.name.TaxonNameBase;
46 import eu.etaxonomy.cdm.model.name.TypeDesignationBase;
47 import eu.etaxonomy.cdm.persistence.dao.IBeanInitializer;
48 import eu.etaxonomy.cdm.persistence.query.MatchMode;
49 import eu.etaxonomy.cdm.persistence.query.OrderHint;
50 import eu.etaxonomy.cdm.strategy.cache.TaggedText;
51
52 public interface INameService extends IIdentifiableEntityService<TaxonNameBase> {
53
54 /**
55 * Deletes a name. Depening on the configurator state links to the name will either be
56 * deleted or throw exceptions.<BR>
57 * If name is <code>null</code> this method has no effect.
58 * @param name
59 * @param config
60 * @throws ReferencedObjectUndeletableException
61 */
62 public UUID delete(TaxonNameBase name, NameDeletionConfigurator config) throws ReferencedObjectUndeletableException;
63
64 /**
65 * Removes the given type designation from the given taxon name and deletes it from
66 * the database if it is not connected to any other name.
67 * If <code>typeDesignation</code> is <code>null</code> all type designations are deleted
68 * from the given taxon name. If <code>name</code> is <code>null</code> all names are removed from
69 * the given type designation. If both are <code>null</code> nothing happens.
70 * @param typeDesignation
71 * @param name
72 * @return
73 */
74 public void deleteTypeDesignation(TaxonNameBase name, TypeDesignationBase typeDesignation);
75
76
77 /**
78 * Saves the given type designations.
79 * @param typeDesignationCollection
80 * @return
81 */
82 public Map<UUID, TypeDesignationBase> saveTypeDesignationAll(Collection<TypeDesignationBase> typeDesignationCollection);
83
84 public Map<UUID, ReferencedEntityBase> saveReferencedEntitiesAll(Collection<ReferencedEntityBase> referencedEntityCollection);
85
86 /**
87 * Saves the given homotypical groups.
88 * @param homotypicalGroups
89 * @return
90 */
91 public Map<UUID, HomotypicalGroup> saveAllHomotypicalGroups(Collection<HomotypicalGroup> homotypicalGroups);
92
93 /**
94 * Returns all nomenclatural status.
95 * @param limit
96 * @param start
97 * @return
98 */
99 public List<NomenclaturalStatus> getAllNomenclaturalStatus(int limit, int start);
100
101 /**
102 * Returns all type designations.
103 * @param limit
104 * @param start
105 * @return
106 */
107 public List<TypeDesignationBase> getAllTypeDesignations(int limit, int start);
108
109 /**
110 * @param name
111 * @return
112 */
113 public List<TaxonNameBase> getNamesByName(String name);
114
115 /**
116 * Returns all NonViralNames with a name cache that matches the given string
117 * @param name
118 * @return
119 */
120 public List<NonViralName> getNamesByNameCache(String nameCache);
121
122 /**
123 * Returns all NonViralNames with a title cache that matches the given string
124 * using the given match mode and initialization strategy
125 *
126 * @param name
127 * @param matchMode
128 * @param propertyPaths
129 * @return
130 */
131 public List<NonViralName> findNamesByTitleCache(String titleCache, MatchMode matchMode, List<String> propertyPaths);
132
133 /**
134 * Returns all NonViralNames with a name cache that matches the given string
135 * using the given match mode and initialization strategy
136 *
137 * @param name
138 * @param matchMode
139 * @param propertyPaths
140 * @return
141 */
142 public List<NonViralName> findNamesByNameCache(String nameCache, MatchMode matchMode, List<String> propertyPaths);
143
144 /**
145 * Returns the NonViralName with the given UUID
146 * using the given match mode and initialization strategy
147 *
148 * @param uuid
149 * @param propertyPaths
150 * @return
151 */
152 public NonViralName findNameByUuid(UUID uuid, List<String> propertyPaths);
153 /**
154 * @param name
155 * @param sessionObject An object that is attached to the session before executing the query
156 * @return
157 */
158 public List getNamesByName(String name, CdmBase sessionObject);
159
160 /**
161 * Fuzzy matching for the taxon name elements. The input name is first atomised using the {@link NonViralNameParserImpl}
162 * into its separate parts (genusOrUninomial,infraGenericEpithet,specificEpithet,infraGenericEpithet,authorshipCache).
163 * Each field is then matched separately with the same accuracy parameter.
164 *
165 * @param name taxon name to fuzzy match
166 * @param accuracy value > 0.0 and < 1.0 which determines the accuracy of the result.
167 * @param languages list of languages to consider when matching (currently not used)
168 * @param highlightFragments
169 * @param propertyPaths
170 * @param maxNoOfResults
171 * @return
172 * @throws CorruptIndexException
173 * @throws IOException
174 * @throws ParseException
175 */
176 public List<SearchResult<TaxonNameBase>> findByNameFuzzySearch(
177 String name,
178 float accuracy,
179 List<Language> languages,
180 boolean highlightFragments,
181 List<String> propertyPaths,
182 int maxNoOfResults) throws CorruptIndexException, IOException, ParseException;
183
184 /**
185 * Fuzzy matching for the taxon name elements using only the lucene index.
186 *
187 * The input name is first atomised using the {@link NonViralNameParserImpl}
188 * into its separate parts (genusOrUninomial,infraGenericEpithet,specificEpithet,infraGenericEpithet,authorshipCache).
189 * Each field is then matched separately with the same accuracy parameter.
190 *
191 * @param name taxon name to fuzzy match
192 * @param accuracy value > 0.0 and < 1.0 which determines the accuracy of the result.
193 * @param languages list of languages to consider when matching (currently not used)
194 * @param highlightFragments
195 * @param maxNoOfResults
196 * @return
197 * @throws CorruptIndexException
198 * @throws IOException
199 * @throws ParseException
200 */
201 public List<DocumentSearchResult> findByNameFuzzySearch(
202 String name,
203 float accuracy,
204 List<Language> languages,
205 boolean highlightFragments,
206 int maxNoOfResults) throws CorruptIndexException, IOException, ParseException;
207
208 /**
209 * Exact matching for the taxon name elements using only the lucene index.
210 *
211 * The input name is first atomised using the {@link NonViralNameParserImpl}
212 * into its separate parts (genusOrUninomial,infraGenericEpithet,specificEpithet,infraGenericEpithet,authorshipCache).
213 * Each field is then matched separately with the same accuracy parameter.
214 *
215 * @param name taxon name to fuzzy match
216 * @param wildcard boolean flag to indicate whether a wildcard '*' should be added at the end of the query
217 * @param languages list of languages to consider when matching (currently not used)
218 * @param highlightFragments
219 * @param maxNoOfResults
220 * @return
221 * @throws CorruptIndexException
222 * @throws IOException
223 * @throws ParseException
224 */
225
226 public List<DocumentSearchResult> findByNameExactSearch(
227 String name,
228 boolean wildcard,
229 List<Language> languages,
230 boolean highlightFragments,
231 int maxNoOfResults) throws CorruptIndexException, IOException, ParseException;
232
233 // TODO: Remove getNamesByName() methods. Use findNamesByTitle() instead.
234
235 // FIXME candidate for harmonization?
236 public List findNamesByTitle(String title);
237
238 public List findNamesByTitle(String title, CdmBase sessionObject);
239
240 public List<HomotypicalGroup> getAllHomotypicalGroups(int limit, int start);
241
242 @Deprecated
243 public List<RelationshipBase> getAllRelationships(int limit, int start);
244
245 /**
246 * Returns all Ranks
247 * @return
248 * @deprecated use VocabularyService#getVocabulary(VocabularyEnum) instead,
249 * this is not possible since VocabularyService#getVocabulary(VocabularyEnum)
250 * is not returning a OrderedTermVocabulary !!! see also http://dev.e-taxonomy.eu/trac/ticket/3327
251 */
252 @Deprecated
253 public OrderedTermVocabulary<Rank> getRankVocabulary();
254
255 /**
256 * Returns all NomenclaturalStatusTypes
257 * @return
258 * @deprecated use VocabularyService#getVocabulary(VocabularyEnum) instead
259 */
260 @Deprecated
261 public TermVocabulary<NomenclaturalStatusType> getStatusTypeVocabulary();
262
263 /**
264 * Returns TypeDesignationStatus vocabulary
265 * @return
266 * @deprecated use VocabularyService#getVocabulary(VocabularyEnum) instead
267 */
268 @Deprecated
269 public TermVocabulary<SpecimenTypeDesignationStatus> getSpecimenTypeDesignationStatusVocabulary();
270
271 /**
272 * Returns TypeDesignationStatus ordered vocabulary
273 * @return
274 * @deprecated use VocabularyService#getVocabulary(VocabularyEnum) instead
275 */
276 @Deprecated
277 public OrderedTermVocabulary<SpecimenTypeDesignationStatus> getSpecimenTypeDesignationVocabulary();
278
279 /**
280 * Returns all NameRelationshipTypes
281 * @return
282 * @deprecated use VocabularyService#getVocabulary(VocabularyEnum) instead
283 */
284 @Deprecated
285 public TermVocabulary<NameRelationshipType> getNameRelationshipTypeVocabulary();
286
287 /**
288 * Return a List of name relationships in which this name is related to
289 * another name, optionally filtered by relationship type
290 *
291 * @param name
292 * the name on either the <i>"from side"</i> or on the
293 * <i>"to side"</i> of the relationship, depending on the
294 * <code>direction</code> of the relationship.
295 * @param direction
296 * the direction of the NameRelationship, may be null to return all relationships
297 * @param type
298 * the relationship type (or null to return all relationships)
299 * @param pageSize
300 * The maximum number of relationships returned (can be null for
301 * all relationships)
302 * @param pageNumber
303 * The offset (in pageSize chunks) from the start of the result
304 * set (0 - based)
305 * @param orderHints
306 * may be null
307 * @param propertyPaths
308 * properties to initialize - see
309 * {@link IBeanInitializer#initialize(Object, List)}
310 * @return a Pager of NameRelationship instances
311 */
312 public List<NameRelationship> listNameRelationships(TaxonNameBase name, NameRelationship.Direction direction, NameRelationshipType type, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths);
313
314 /**
315 * Return a List of name relationships in which this name is related to another name, optionally filtered
316 * by relationship type
317 *
318 * @param name the name on the <i>"from side"</i> of the relationship
319 * @param direction the direction of the NameRelationship
320 * @param type the relationship type (or null to return all relationships)
321 * @param pageSize The maximum number of relationships returned (can be null for all relationships)
322 * @param pageNumber The offset (in pageSize chunks) from the start of the result set (0 - based)
323 * @param orderHints may be null
324 * @param propertyPaths properties to initialize - see {@link IBeanInitializer#initialize(Object, List)}
325 * @return a Pager of NameRelationship instances
326 */
327 public Pager<NameRelationship> pageNameRelationships(TaxonNameBase name, NameRelationship.Direction direction, NameRelationshipType type, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths);
328
329 /**
330 * Return a List of relationships in which this name is related to another name, optionally filtered
331 * by relationship type
332 *
333 * @param name the name on the <i>"from side"</i> of the relationship
334 * @param type the relationship type (or null to return all relationships)
335 * @param pageSize The maximum number of relationships returned (can be null for all relationships)
336 * @param pageNumber The offset (in pageSize chunks) from the start of the result set (0 - based)
337 * @param orderHints may be null
338 * @param propertyPaths properties to initialize - see {@link IBeanInitializer#initialize(Object, List)}
339 * @return a Pager of NameRelationship instances
340 * @deprecated use {@link #listNameRelationships(TaxonNameBase, eu.etaxonomy.cdm.model.common.RelationshipBase.Direction, NameRelationshipType, Integer, Integer, List, List)} instead
341 */
342 @Deprecated
343 public List<NameRelationship> listFromNameRelationships(TaxonNameBase name, NameRelationshipType type, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths);
344
345 /**
346 * Return a List of relationships in which this name is related to another name, optionally filtered
347 * by relationship type
348 *
349 * @param name the name on the <i>"from side"</i> of the relationship
350 * @param type the relationship type (or null to return all relationships)
351 * @param pageSize The maximum number of relationships returned (can be null for all relationships)
352 * @param pageNumber The offset (in pageSize chunks) from the start of the result set (0 - based)
353 * @param orderHints may be null
354 * @param propertyPaths properties to initialize - see {@link IBeanInitializer#initialize(Object, List)}
355 * @return a Pager of NameRelationship instances
356 * @deprecated use {@link #pageNameRelationships(TaxonNameBase, eu.etaxonomy.cdm.model.common.RelationshipBase.Direction, NameRelationshipType, Integer, Integer, List, List)} instead
357 */
358 @Deprecated
359 public Pager<NameRelationship> pageFromNameRelationships(TaxonNameBase name, NameRelationshipType type, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths);
360
361 /**
362 * Return a List of relationships in which another name is related to this name, optionally filtered
363 * by relationship type
364 *
365 * @param name the name on the <i>"to side"</i> of the relationship
366 * @param type the relationship type (or null to return all relationships)
367 * @param pageSize The maximum number of relationships returned (can be null for all relationships)
368 * @param pageNumber The offset (in pageSize chunks) from the start of the result set (0 - based)
369 * @param orderHints may be null
370 * @param propertyPaths properties to initialize - see {@link IBeanInitializer#initialize(Object, List)}
371 * @return a Pager of NameRelationship instances
372 * @deprecated use {@link #listNameRelationships(TaxonNameBase, eu.etaxonomy.cdm.model.common.RelationshipBase.Direction, NameRelationshipType, Integer, Integer, List, List)} instead
373 */
374 @Deprecated
375 public List<NameRelationship> listToNameRelationships(TaxonNameBase name, NameRelationshipType type, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths);
376
377 /**
378 * Return a List of relationships in which another name is related to this name, optionally filtered
379 * by relationship type
380 *
381 * @param name the name on the <i>"to side"</i> of the relationship
382 * @param type the relationship type (or null to return all relationships)
383 * @param pageSize The maximum number of relationships returned (can be null for all relationships)
384 * @param pageNumber The offset (in pageSize chunks) from the start of the result set (0 - based)
385 * @param orderHints may be null
386 * @param propertyPaths properties to initialize - see {@link IBeanInitializer#initialize(Object, List)}
387 * @return a Pager of NameRelationship instances
388 * @deprecated use {@link #pageNameRelationships(TaxonNameBase, eu.etaxonomy.cdm.model.common.RelationshipBase.Direction, NameRelationshipType, Integer, Integer, List, List)} instead
389 */
390 @Deprecated
391 public Pager<NameRelationship> pageToNameRelationships(TaxonNameBase name, NameRelationshipType type, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths);
392
393
394 /**
395 * Return a List of hybrids related to this name, optionally filtered
396 * by hybrid relationship type
397 *
398 * @param name the name
399 * @param type the hybrid relationship type (or null to return all hybrids)
400 * @param pageSize The maximum number of hybrid relationships returned (can be null for all relationships)
401 * @param pageNumber The offset (in pageSize chunks) from the start of the result set (0 - based)
402 * @param orderHints may be null
403 * @param propertyPaths properties to initialize - see {@link IBeanInitializer#initialize(Object, List)}
404 * @return a Pager of HybridRelationship instances
405 */
406 public Pager<HybridRelationship> getHybridNames(NonViralName name, HybridRelationshipType type, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths);
407
408 /**
409 * Return a List of types related to this name, optionally filtered
410 * by type designation status
411 *
412 * @param name the name
413 * @param status the type designation status (or null to return all types)
414 * @param pageSize The maximum number of types returned (can be null for all types)
415 * @param pageNumber The offset (in pageSize chunks) from the start of the result set (0 - based)
416 * @return a Pager of TypeDesignationBase instances
417 */
418 public Pager<TypeDesignationBase> getTypeDesignations(TaxonNameBase name,
419 SpecimenTypeDesignationStatus status, Integer pageSize, Integer pageNumber);
420
421 public Pager<TypeDesignationBase> getTypeDesignations(TaxonNameBase name,
422 SpecimenTypeDesignationStatus status, Integer pageSize, Integer pageNumber, List<String> propertyPaths);
423
424
425 /**
426 * Returns a List of TaxonNameBase instances that match the properties passed
427 *
428 * @param uninomial
429 * @param infraGenericEpithet
430 * @param specificEpithet
431 * @param infraspecificEpithet
432 * @param rank
433 * @param pageSize The maximum number of names returned (can be null for all names)
434 * @param pageNumber The offset (in pageSize chunks) from the start of the result set (0 - based)
435 * @param orderHints may be null
436 * @param propertyPaths properties to initialize - see {@link IBeanInitializer#initialize(Object, List)}
437 * @return a Pager of TaxonNameBase instances
438 */
439 public Pager<TaxonNameBase> searchNames(String uninomial, String infraGenericEpithet, String specificEpithet, String infraspecificEpithet, Rank rank, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths);
440
441 /**
442 * Returns a Paged List of TaxonNameBase instances where the default field matches the String queryString (as interpreted by the Lucene QueryParser)
443 *
444 * @param clazz filter the results by class (or pass null to return all TaxonNameBase instances)
445 * @param queryString
446 * @param pageSize The maximum number of names returned (can be null for all matching names)
447 * @param pageNumber The offset (in pageSize chunks) from the start of the result set (0 - based)
448 * @param orderHints
449 * Supports path like <code>orderHints.propertyNames</code> which
450 * include *-to-one properties like createdBy.username or
451 * authorTeam.persistentTitleCache
452 * @param propertyPaths properties to be initialized
453 * @return a Pager TaxonNameBase instances
454 * @see <a href="http://lucene.apache.org/java/2_4_0/queryparsersyntax.html">Apache Lucene - Query Parser Syntax</a>
455 */
456 @Override
457 public Pager<TaxonNameBase> search(Class<? extends TaxonNameBase> clazz, String queryString, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths);
458
459 /**
460 * Returns a map that holds uuid, titleCache pairs of all names in the current database
461 *
462 * @return
463 * a <code>Map</code> containing uuid and titleCache of names
464 */
465 public List<UuidAndTitleCache> getUuidAndTitleCacheOfNames();
466
467 /**
468 * Return a Pager of names matching the given query string, optionally filtered by class, optionally with a particular MatchMode
469 *
470 * @param clazz filter by class - can be null to include all instances of type T
471 * @param queryString the query string to filter by
472 * @param matchmode use a particular type of matching (can be null - defaults to exact matching)
473 * @param criteria additional criteria to filter by
474 * @param pageSize The maximum number of objects returned (can be null for all objects)
475 * @param pageNumber The offset (in pageSize chunks) from the start of the result set (0 - based)
476 * @param propertyPaths properties to initialize - see {@link IBeanInitializer#initialize(Object, List)}
477 * @param orderHints
478 * Supports path like <code>orderHints.propertyNames</code> which
479 * include *-to-one properties like createdBy.username or
480 * authorTeam.persistentTitleCache
481 * @return a paged list of instances of type T matching the queryString
482 */
483 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);
484
485 /**
486 * Returns a homotypical group with the given UUID or null if not homotypical group exists with that UUID
487 *
488 * @param uuid the uuid of the homotypical group
489 * @return a homotypical group
490 */
491 public HomotypicalGroup findHomotypicalGroup(UUID uuid);
492
493 /**
494 * @param uuid
495 * @return
496 */
497 public List<TaggedText> getTaggedName(UUID uuid);
498 }