hibernate fulltext search & refactoring getTaxaByName*() method headers
[cdmlib.git] / cdmlib-persistence / src / main / java / eu / etaxonomy / cdm / persistence / dao / taxon / ITaxonDao.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.persistence.dao.taxon;
11
12 import java.util.List;
13 import java.util.Set;
14 import java.util.UUID;
15
16 import org.hibernate.criterion.Criterion;
17
18 import eu.etaxonomy.cdm.model.common.RelationshipBase;
19 import eu.etaxonomy.cdm.model.common.UuidAndTitleCache;
20 import eu.etaxonomy.cdm.model.common.RelationshipBase.Direction;
21 import eu.etaxonomy.cdm.model.location.NamedArea;
22 import eu.etaxonomy.cdm.model.name.NonViralName;
23 import eu.etaxonomy.cdm.model.name.Rank;
24 import eu.etaxonomy.cdm.model.name.TaxonNameBase;
25 import eu.etaxonomy.cdm.model.reference.Reference;
26 import eu.etaxonomy.cdm.model.taxon.Synonym;
27 import eu.etaxonomy.cdm.model.taxon.SynonymRelationship;
28 import eu.etaxonomy.cdm.model.taxon.SynonymRelationshipType;
29 import eu.etaxonomy.cdm.model.taxon.Taxon;
30 import eu.etaxonomy.cdm.model.taxon.TaxonBase;
31 import eu.etaxonomy.cdm.model.taxon.TaxonNode;
32 import eu.etaxonomy.cdm.model.taxon.TaxonRelationship;
33 import eu.etaxonomy.cdm.model.taxon.TaxonRelationshipType;
34 import eu.etaxonomy.cdm.model.taxon.Classification;
35 import eu.etaxonomy.cdm.persistence.dao.BeanInitializer;
36 import eu.etaxonomy.cdm.persistence.dao.common.IIdentifiableDao;
37 import eu.etaxonomy.cdm.persistence.dao.common.ITitledDao;
38 import eu.etaxonomy.cdm.persistence.fetch.CdmFetch;
39 import eu.etaxonomy.cdm.persistence.query.MatchMode;
40 import eu.etaxonomy.cdm.persistence.query.OrderHint;
41 import eu.etaxonomy.cdm.model.common.IdentifiableEntity;
42
43 /**
44 * @author a.mueller
45 *
46 */
47 public interface ITaxonDao extends IIdentifiableDao<TaxonBase>, ITitledDao<TaxonBase> {
48
49 /**
50 * Returns a list of TaxonBase instances where the taxon.titleCache property matches the name parameter,
51 * and taxon.sec matches the sec parameter.
52 * @param name
53 * @param sec
54 * @return
55 */
56 public List<TaxonBase> getTaxaByName(String name, Reference sec);
57
58 /**
59 * Returns a list of TaxonBase instances (or Taxon instances, if accepted == true, or Synonym instance, if accepted == false)
60 * where the taxonBase.name.nameCache property matches the String queryString, and taxon.sec matches the sec parameter.
61 * @param name
62 * @param sec
63 * @return
64 */
65 public List<TaxonBase> getTaxaByName(String queryString, Boolean accepted, Reference sec);
66
67 /**
68 * Returns a list of TaxonBase instances (or Taxon instances, if accepted == true, or Synonym instance, if accepted == false)
69 * where the taxonBase.name.nameCache property matches the String queryString.
70 * @param queryString
71 * @param matchMode
72 * @param accepted
73 * @param pageSize
74 * @param pageNumber
75 * @return
76 */
77 public List<TaxonBase> getTaxaByName(String queryString, MatchMode matchMode,
78 Boolean accepted, Integer pageSize, Integer pageNumber);
79
80
81 /**
82 * Returns a list of TaxonBase instances (or Taxon instances, if accepted == true, or Synonym instance, if accepted == false)
83 * where the taxonBase.name.nameCache property matches the String queryString.
84 * @param doTaxa
85 * @param doSynonyms
86 * @param queryString
87 * @param classification TODO
88 * @param matchMode
89 * @param namedAreas TODO
90 * @param pageSize
91 * @param pageNumber
92 * @param propertyPaths TODO
93 * @return list of found taxa
94 */
95 public List<TaxonBase> getTaxaByName(boolean doTaxa, boolean doSynonyms, boolean doMisappliedNames, String queryString, Classification classification,
96 MatchMode matchMode, Set<NamedArea> namedAreas, Integer pageSize, Integer pageNumber, List<String> propertyPaths);
97
98 /**
99 * @param doTaxa
100 * @param doSynonyms
101 * @param queryString
102 * @param classification TODO
103 * @param matchMode
104 * @param namedAreas
105 * @param pageSize
106 * @param pageNumber
107 * @param propertyPaths
108 * @return
109 */
110 public long countTaxaByName(boolean doTaxa, boolean doSynonyms, boolean doMisappliedNames, String queryString, Classification classification,
111
112 MatchMode matchMode, Set<NamedArea> namedAreas);
113
114 // /**
115 // * @param queryString
116 // * @param matchMode
117 // * @param accepted
118 // * @return
119 // */
120 // public Integer countTaxaByName(String queryString, MatchMode matchMode,
121 // Boolean accepted);
122
123 // /**
124 // * Returns a count of TaxonBase instances where the
125 // * taxon.name properties match the parameters passed.
126 // *
127 // * @param queryString search string
128 // * @param matchMode way how search string shall be matched: exact, beginning, or anywhere
129 // * @param selectModel all taxon base, taxa, or synonyms
130 // */
131 // public Integer countTaxaByName(String queryString, MatchMode matchMode, SelectMode selectMode);
132
133 /**
134 * Returns a count of TaxonBase instances where the
135 * taxon.name properties match the parameters passed.
136 *
137 * @param doTaxa
138 * @param doSynonyms
139 * @param uninomial
140 * @param infragenericEpithet
141 * @param specificEpithet
142 * @param infraspecificEpithet
143 * @param rank
144 * @return a count of TaxonBase instances
145 */
146 public int countTaxaByName(Class <? extends TaxonBase> clazz, String uninomial, String infragenericEpithet,String specificEpithet, String infraspecificEpithet, Rank rank);
147
148 /**
149 * Returns a list of TaxonBase instances where the
150 * taxon.name properties match the parameters passed. In order to search for any string value, pass '*', passing the string value of
151 * <i>null</i> will search for those taxa with a value of null in that field
152 * <p>
153 * Compare with
154 * {@link #findByName(String, MatchMode, int, int, boolean)}
155 * which searches for {@link TaxonNameBase}<strong><code>.titleCache</code>
156 * </strong>
157 *
158 * @param doTaxa
159 * @param doSynonyms
160 * @param uninomial
161 * @param infragenericEpithet
162 * @param specificEpithet
163 * @param infraspecificEpithet
164 * @param rank
165 * @param pageSize The maximum number of taxa returned (can be null for all matching taxa)
166 * @param pageNumber The offset (in pageSize chunks) from the start of the result set (0 - based)
167 * @return a list of TaxonBase instances
168 */
169 public List<TaxonBase> findTaxaByName(Class<? extends TaxonBase> clazz, String uninomial, String infragenericEpithet, String specificEpithet, String infraspecificEpithet, Rank rank, Integer pageSize, Integer pageNumber);
170
171 /**
172 * Find taxa by searching for Taxa and Synonyms where the
173 * {@link TaxonNameBase}<strong><code>.titleCache</code></strong> matches
174 * the name specified as queryString <code>taxonName</code>
175 * <P>
176 * Compare with
177 * {@link #findTaxaByName(Class, String, String, String, String, Rank, Integer, Integer)}
178 * which searches for {@link TaxonNameBase}<strong><code>.nameCache</code>
179 * </strong>
180 * @param queryString
181 * the taqxon Name to search for
182 * @param classification TODO
183 * @param matchMode
184 * @param namedAreas TODO
185 * @param pageNumber
186 * @param pageSize
187 * @param onlyAcccepted
188 * @return
189 */
190 public List<TaxonBase> findByNameTitleCache(boolean doTaxa, boolean doSynonyms, String queryString, Classification classification, MatchMode matchMode, Set<NamedArea> namedAreas, Integer pageNumber, Integer pageSize, List<String> propertyPaths) ;
191
192 public List<TaxonBase> getTaxaByCommonName(String queryString, Classification classification,
193 MatchMode matchMode, Set<NamedArea> namedAreas, Integer pageSize,
194 Integer pageNumber, List<String> propertyPaths);
195
196 /**
197 * Computes all Taxon instances that do not have a taxonomic parent and has at least one child.
198 * @return The List<Taxon> of root taxa.
199 * @deprecated obsolete when using classification
200 */
201 public List<Taxon> getRootTaxa(Reference sec);
202
203
204 /**
205 * Computes all Taxon instances that do not have a taxonomic parent.
206 * @param sec The concept reference that the taxon belongs to
207 * @param cdmFetch not used yet !! TODO
208 * @param onlyWithChildren if true only taxa are returned that have taxonomic children. <Br>Default: true.
209 * @param withMisaplications if false only taxa are returned that have no isMisappliedNameFor relationship.
210 * <Br>Default: true.
211 * @return The List<Taxon> of root taxa.
212 * @deprecated obsolete when using classification
213 */
214 public List<Taxon> getRootTaxa(Reference sec, CdmFetch cdmFetch, Boolean onlyWithChildren, Boolean withMisapplications);
215
216
217 /**
218 * Computes all Taxon instances which name is of a certain Rank.
219 *
220 * @param rank
221 * The rank of the taxon name
222 * @param sec
223 * The concept reference that the taxon belongs to
224 * @param cdmFetch
225 * not used yet !! TODO
226 * @param onlyWithChildren
227 * if true only taxa are returned that have taxonomic children. <Br>
228 * Default: true.
229 * @param withMisaplications
230 * if false only taxa are returned that have no
231 * isMisappliedNameFor relationship.
232 * @param propertyPaths
233 * properties to be initialized, For detailed description and
234 * examples <b>please refer to:</b>
235 * {@link BeanInitializer#initialize(Object, List)}. <Br>
236 * Default: true.
237 * @return The List<Taxon> of root taxa.
238 * @deprecated obsolete when using classification
239 */
240 public List<Taxon>
241 getRootTaxa(Rank rank, Reference sec, CdmFetch cdmFetch, Boolean onlyWithChildren, Boolean withMisapplications, List<String> propertyPaths);
242
243 /**
244 * TODO necessary?
245 * @param pagesize max maximum number of returned taxa
246 * @param page page to start, with 0 being first page
247 * @return
248 */
249 public List<TaxonBase> getAllTaxonBases(Integer pagesize, Integer page);
250
251
252 /**
253 * @param limit
254 * @param start
255 * @return
256 */
257 public List<Taxon> getAllTaxa(Integer limit, Integer start);
258
259 /**
260 * @param limit
261 * @param start
262 * @return
263 */
264 public List<Synonym> getAllSynonyms(Integer limit, Integer start);
265
266 public List<RelationshipBase> getAllRelationships(Integer limit, Integer start);
267
268 public int countAllRelationships();
269
270 /**
271 * @param queryString
272 * @param matchMode
273 * @param onlyAcccepted
274 * @return
275 */
276 public int countMatchesByName(String queryString, MatchMode matchMode, boolean onlyAcccepted);
277
278 /**
279 * @param queryString
280 * @param matchMode
281 * @param onlyAcccepted
282 * @param criteria
283 * @return
284 */
285 public int countMatchesByName(String queryString, MatchMode matchMode, boolean onlyAcccepted, List<Criterion> criteria);
286
287 /**
288 * Returns a count of the TaxonRelationships (of where relationship.type ==
289 * type, if this argument is supplied) where the supplied taxon either is
290 * relatedFrom or relatedTo depending on the <code>direction</code>
291 * parameter.
292 *
293 * @param taxon
294 * The taxon that is relatedFrom
295 * @param type
296 * The type of TaxonRelationship (can be null)
297 * @param direction
298 * specifies the direction of the relationship
299 * @return the number of TaxonRelationship instances
300 */
301 public int countTaxonRelationships(Taxon taxon, TaxonRelationshipType type,
302 Direction direction);
303
304 /**
305 * Returns the TaxonRelationships (of where relationship.type == type, if
306 * this argument is supplied) where the supplied taxon either is
307 * relatedFrom or relatedTo depending on the <code>direction</code>
308 * parameter.
309 *
310 * @param taxon
311 * The taxon that is relatedTo
312 * @param type
313 * The type of TaxonRelationship (can be null)
314 * @param pageSize
315 * The maximum number of relationships returned (can be null for
316 * all relationships)
317 * @param pageNumber
318 * The offset (in pageSize chunks) from the start of the result
319 * set (0 - based)
320 * @param orderHints
321 * Properties to order by
322 * @param propertyPaths
323 * Properties to initialize in the returned entities, following
324 * the syntax described in
325 * {@link BeanInitializer#initialize(Object, List)}
326 * @param direction
327 * specifies the direction of the relationship
328 * @return a List of TaxonRelationship instances
329 */
330 public List<TaxonRelationship> getTaxonRelationships(Taxon taxon,
331 TaxonRelationshipType type, Integer pageSize, Integer pageNumber,
332 List<OrderHint> orderHints, List<String> propertyPaths,
333 Direction direction);
334
335 /**
336 * Returns a count of the SynonymRelationships (of where relationship.type == type,
337 * if this arguement is supplied) where the supplied taxon is relatedTo.
338 *
339 * @param taxon The taxon that is relatedTo
340 * @param type The type of SynonymRelationship (can be null)
341 * @return the number of SynonymRelationship instances
342 */
343 public int countSynonyms(Taxon taxon, SynonymRelationshipType type);
344
345 /**
346 * Returns the SynonymRelationships (of where relationship.type == type, if this arguement is supplied)
347 * where the supplied taxon is relatedTo.
348 *
349 * @param taxon The taxon that is relatedTo
350 * @param type The type of SynonymRelationship (can be null)
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 Properties to order by
354 * @param propertyPaths Properties to initialize in the returned entities, following the syntax described in {@link BeanInitializer#initialize(Object, List)}
355 * @return a List of SynonymRelationship instances
356 */
357 public List<SynonymRelationship> getSynonyms(Taxon taxon, SynonymRelationshipType type, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths);
358
359 /**
360 * Returns a count of the SynonymRelationships (of where relationship.type == type,
361 * if this arguement is supplied) where the supplied synonym is relatedFrom.
362 *
363 * @param taxon The synonym that is relatedFrom
364 * @param type The type of SynonymRelationship (can be null)
365 * @return the number of SynonymRelationship instances
366 */
367 public int countSynonyms(Synonym synonym, SynonymRelationshipType type);
368
369 /**
370 * Returns the SynonymRelationships (of where relationship.type == type, if this arguement is supplied)
371 * where the supplied synonym is relatedFrom.
372 *
373 * @param taxon The synonym that is relatedFrom
374 * @param type The type of SynonymRelationship (can be null)
375 * @param pageSize The maximum number of relationships returned (can be null for all relationships)
376 * @param pageNumber The offset (in pageSize chunks) from the start of the result set (0 - based)
377 * * @param orderHints Properties to order by
378 * @param propertyPaths Properties to initialize in the returned entities, following the syntax described in {@link BeanInitializer#initialize(Object, List)}
379 * @return a List of SynonymRelationship instances
380 */
381 public List<SynonymRelationship> getSynonyms(Synonym synoynm, SynonymRelationshipType type, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths);
382
383 /**
384 *
385 * @return
386 */
387 public List<UuidAndTitleCache<TaxonNode>> getTaxonNodeUuidAndTitleCacheOfAcceptedTaxaByClassification(Classification classification);
388
389 /**
390 * Creates all inferred synonyms for the species in the tree and insert it to the database
391 * @param tree
392 * @return List of inferred synonyms
393 */
394 //public List<Synonym> insertAllInferredSynonymy(Classification tree);
395
396 /**
397 * Creates all inferred synonyms for the taxon in the classification, but do not insert it to the database
398 * @param taxon
399 * @param tree
400 * @return list of inferred synonyms
401 */
402 public List<Synonym> createAllInferredSynonyms(Taxon taxon, Classification tree);
403 /**
404 * Creates the specified inferred synonyms for the taxon in the classification, but do not insert it to the database
405 * @param taxon
406 * @param tree
407 * @return list of inferred synonyms
408 */
409 public List<Synonym> createInferredSynonyms(Taxon taxon, Classification tree, SynonymRelationshipType type);
410
411 public List<TaxonNameBase> findIdenticalTaxonNames(List<String> propertyPath);
412 public String getPhylumName(TaxonNameBase name);
413
414 public long countTaxaByCommonName(String searchString,
415 Classification classification, MatchMode matchMode,
416 Set<NamedArea> namedAreas);
417
418 /**
419 * Deletes all synonym relationships of a given synonym.
420 * If taxon is given only those relationships to the taxon
421 * are deleted.
422 * @param synonym the synonym
423 * @param taxon the taxon, may be <code>null</code>
424 * @return
425 */
426 public long deleteSynonymRelationships(Synonym syn, Taxon taxon);
427
428 public List<UUID> findIdenticalTaxonNameIds(List<String> propertyPath);
429
430 public List<TaxonNameBase> findIdenticalNamesNew(List <String> propertyPaths);
431
432
433 public Integer countSynonymRelationships(TaxonBase taxonBase,
434 SynonymRelationshipType type, Direction relatedfrom);
435
436 public List<SynonymRelationship> getSynonymRelationships(TaxonBase taxonBase,
437 SynonymRelationshipType type, Integer pageSize, Integer pageNumber,
438 List<OrderHint> orderHints, List<String> propertyPaths,
439 Direction relatedfrom);
440
441 /**
442 * @return
443 */
444 public List<UuidAndTitleCache<TaxonBase>> getUuidAndTitleCacheTaxon();
445
446 /**
447 * @return
448 */
449 public List<UuidAndTitleCache<TaxonBase>> getUuidAndTitleCacheSynonym();
450
451 public List<UuidAndTitleCache<TaxonBase>> getTaxaByNameForEditor(boolean doTaxa, boolean doSynonyms, String queryString, Classification classification,
452 MatchMode matchMode, Set<NamedArea> namedAreas);
453
454
455 }