AT: committing CDMLIB to Branch post Merge
[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 /**
193 * Returns a taxon corresponding to the given uuid
194 *
195 * @param uuid
196 * The uuid of the taxon requested
197 * @param criteria
198 * Custom criteria to be added to the default list of applied criteria.
199 * @param propertyPaths
200 *
201 * @return
202 */
203 public TaxonBase findByUuid(UUID uuid, List<Criterion> criteria, List<String> propertyPaths);
204
205 /**
206 * @param queryString
207 * @param classification
208 * @param matchMode
209 * @param namedAreas
210 * @param pageSize
211 * @param pageNumber
212 * @param propertyPaths
213 * @return A List of arrays. Each entry array holds the following entities: Taxon, CommonName, Description, Feature
214 */
215 public List<Object[]> getTaxaByCommonName(String queryString, Classification classification,
216 MatchMode matchMode, Set<NamedArea> namedAreas, Integer pageSize,
217 Integer pageNumber, List<String> propertyPaths);
218
219
220 /**
221 * Computes all Taxon instances that do not have a taxonomic parent and has at least one child.
222 * @return The List<Taxon> of root taxa.
223 * @deprecated obsolete when using classification
224 */
225 public List<Taxon> getRootTaxa(Reference sec);
226
227
228 /**
229 * Computes all Taxon instances that do not have a taxonomic parent.
230 * @param sec The concept reference that the taxon belongs to
231 * @param cdmFetch not used yet !! TODO
232 * @param onlyWithChildren if true only taxa are returned that have taxonomic children. <Br>Default: true.
233 * @param withMisaplications if false only taxa are returned that have no isMisappliedNameFor relationship.
234 * <Br>Default: true.
235 * @return The List<Taxon> of root taxa.
236 * @deprecated obsolete when using classification
237 */
238 public List<Taxon> getRootTaxa(Reference sec, CdmFetch cdmFetch, Boolean onlyWithChildren, Boolean withMisapplications);
239
240
241 /**
242 * Computes all Taxon instances which name is of a certain Rank.
243 *
244 * @param rank
245 * The rank of the taxon name
246 * @param sec
247 * The concept reference that the taxon belongs to
248 * @param cdmFetch
249 * not used yet !! TODO
250 * @param onlyWithChildren
251 * if true only taxa are returned that have taxonomic children. <Br>
252 * Default: true.
253 * @param withMisaplications
254 * if false only taxa are returned that have no
255 * isMisappliedNameFor relationship.
256 * @param propertyPaths
257 * properties to be initialized, For detailed description and
258 * examples <b>please refer to:</b>
259 * {@link BeanInitializer#initialize(Object, List)}. <Br>
260 * Default: true.
261 * @return The List<Taxon> of root taxa.
262 * @deprecated obsolete when using classification
263 */
264 public List<Taxon>
265 getRootTaxa(Rank rank, Reference sec, CdmFetch cdmFetch, Boolean onlyWithChildren, Boolean withMisapplications, List<String> propertyPaths);
266
267 /**
268 * TODO necessary?
269 * @param pagesize max maximum number of returned taxa
270 * @param page page to start, with 0 being first page
271 * @return
272 */
273 public List<TaxonBase> getAllTaxonBases(Integer pagesize, Integer page);
274
275
276 /**
277 * @param limit
278 * @param start
279 * @return
280 */
281 public List<Taxon> getAllTaxa(Integer limit, Integer start);
282
283 /**
284 * @param limit
285 * @param start
286 * @return
287 */
288 public List<Synonym> getAllSynonyms(Integer limit, Integer start);
289
290 public List<RelationshipBase> getAllRelationships(Integer limit, Integer start);
291
292 public int countAllRelationships();
293
294 /**
295 * @param queryString
296 * @param matchMode
297 * @param onlyAcccepted
298 * @return
299 */
300 public int countMatchesByName(String queryString, MatchMode matchMode, boolean onlyAcccepted);
301
302 /**
303 * @param queryString
304 * @param matchMode
305 * @param onlyAcccepted
306 * @param criteria
307 * @return
308 */
309 public int countMatchesByName(String queryString, MatchMode matchMode, boolean onlyAcccepted, List<Criterion> criteria);
310
311 /**
312 * Returns a count of the TaxonRelationships (of where relationship.type ==
313 * type, if this argument is supplied) where the supplied taxon either is
314 * relatedFrom or relatedTo depending on the <code>direction</code>
315 * parameter.
316 *
317 * @param taxon
318 * The taxon that is relatedFrom
319 * @param type
320 * The type of TaxonRelationship (can be null)
321 * @param direction
322 * specifies the direction of the relationship
323 * @return the number of TaxonRelationship instances
324 */
325 public int countTaxonRelationships(Taxon taxon, TaxonRelationshipType type,
326 Direction direction);
327
328 /**
329 * Returns the TaxonRelationships (of where relationship.type == type, if
330 * this argument is supplied) where the supplied taxon either is
331 * relatedFrom or relatedTo depending on the <code>direction</code>
332 * parameter.
333 *
334 * @param taxon
335 * The taxon that is relatedTo
336 * @param type
337 * The type of TaxonRelationship (can be null)
338 * @param pageSize
339 * The maximum number of relationships returned (can be null for
340 * all relationships)
341 * @param pageNumber
342 * The offset (in pageSize chunks) from the start of the result
343 * set (0 - based)
344 * @param orderHints
345 * Properties to order by
346 * @param propertyPaths
347 * Properties to initialize in the returned entities, following
348 * the syntax described in
349 * {@link BeanInitializer#initialize(Object, List)}
350 * @param direction
351 * specifies the direction of the relationship
352 * @return a List of TaxonRelationship instances
353 */
354 public List<TaxonRelationship> getTaxonRelationships(Taxon taxon,
355 TaxonRelationshipType type, Integer pageSize, Integer pageNumber,
356 List<OrderHint> orderHints, List<String> propertyPaths,
357 Direction direction);
358
359 /**
360 * Returns a count of the SynonymRelationships (of where relationship.type == type,
361 * if this arguement is supplied) where the supplied taxon is relatedTo.
362 *
363 * @param taxon The taxon that is relatedTo
364 * @param type The type of SynonymRelationship (can be null)
365 * @return the number of SynonymRelationship instances
366 */
367 public int countSynonyms(Taxon taxon, SynonymRelationshipType type);
368
369 /**
370 * Returns the SynonymRelationships (of where relationship.type == type, if this arguement is supplied)
371 * where the supplied taxon is relatedTo.
372 *
373 * @param taxon The taxon that is relatedTo
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(Taxon taxon, SynonymRelationshipType type, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths);
382
383 /**
384 * Returns a count of the SynonymRelationships (of where relationship.type == type,
385 * if this arguement is supplied) where the supplied synonym is relatedFrom.
386 *
387 * @param taxon The synonym that is relatedFrom
388 * @param type The type of SynonymRelationship (can be null)
389 * @return the number of SynonymRelationship instances
390 */
391 public int countSynonyms(Synonym synonym, SynonymRelationshipType type);
392
393 /**
394 * Returns the SynonymRelationships (of where relationship.type == type, if this arguement is supplied)
395 * where the supplied synonym is relatedFrom.
396 *
397 * @param taxon The synonym that is relatedFrom
398 * @param type The type of SynonymRelationship (can be null)
399 * @param pageSize The maximum number of relationships returned (can be null for all relationships)
400 * @param pageNumber The offset (in pageSize chunks) from the start of the result set (0 - based)
401 * * @param orderHints Properties to order by
402 * @param propertyPaths Properties to initialize in the returned entities, following the syntax described in {@link BeanInitializer#initialize(Object, List)}
403 * @return a List of SynonymRelationship instances
404 */
405 public List<SynonymRelationship> getSynonyms(Synonym synoynm, SynonymRelationshipType type, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths);
406
407 /**
408 *
409 * @return
410 */
411 public List<UuidAndTitleCache<TaxonNode>> getTaxonNodeUuidAndTitleCacheOfAcceptedTaxaByClassification(Classification classification);
412
413 /**
414 * Creates all inferred synonyms for the species in the tree and insert it to the database
415 * @param tree
416 * @return List of inferred synonyms
417 */
418 //public List<Synonym> insertAllInferredSynonymy(Classification tree);
419
420
421
422 public List<TaxonNameBase> findIdenticalTaxonNames(List<String> propertyPath);
423 public String getPhylumName(TaxonNameBase name);
424
425 public long countTaxaByCommonName(String searchString,
426 Classification classification, MatchMode matchMode,
427 Set<NamedArea> namedAreas);
428
429 /**
430 * Deletes all synonym relationships of a given synonym.
431 * If taxon is given only those relationships to the taxon
432 * are deleted.
433 * @param synonym the synonym
434 * @param taxon the taxon, may be <code>null</code>
435 * @return
436 */
437 public long deleteSynonymRelationships(Synonym syn, Taxon taxon);
438
439 public List<UUID> findIdenticalTaxonNameIds(List<String> propertyPath);
440
441 public List<TaxonNameBase> findIdenticalNamesNew(List <String> propertyPaths);
442
443
444 public Integer countSynonymRelationships(TaxonBase taxonBase,
445 SynonymRelationshipType type, Direction relatedfrom);
446
447 public List<SynonymRelationship> getSynonymRelationships(TaxonBase taxonBase,
448 SynonymRelationshipType type, Integer pageSize, Integer pageNumber,
449 List<OrderHint> orderHints, List<String> propertyPaths,
450 Direction relatedfrom);
451
452 /**
453 * @return
454 */
455 public List<UuidAndTitleCache<TaxonBase>> getUuidAndTitleCacheTaxon();
456
457 /**
458 * @return
459 */
460 public List<UuidAndTitleCache<TaxonBase>> getUuidAndTitleCacheSynonym();
461
462 public List<UuidAndTitleCache<TaxonBase>> getTaxaByNameForEditor(boolean doTaxa, boolean doSynonyms, String queryString, Classification classification,
463 MatchMode matchMode, Set<NamedArea> namedAreas);
464
465 public List<String> taxaByNameNotInDB(List<String> taxonNames);
466
467
468 }