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