cdmlib 2.5
[cdmlib.git] / cdmlib-services / src / main / java / eu / etaxonomy / cdm / api / service / ITaxonService.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.util.List;
14 import java.util.Set;
15
16 import eu.etaxonomy.cdm.api.service.config.ITaxonServiceConfigurator;
17 import eu.etaxonomy.cdm.api.service.pager.Pager;
18 import eu.etaxonomy.cdm.model.common.IdentifiableEntity;
19 import eu.etaxonomy.cdm.model.common.OrderedTermVocabulary;
20 import eu.etaxonomy.cdm.model.common.RelationshipBase;
21 import eu.etaxonomy.cdm.model.common.RelationshipBase.Direction;
22 import eu.etaxonomy.cdm.model.media.MediaRepresentation;
23 import eu.etaxonomy.cdm.model.name.NonViralName;
24 import eu.etaxonomy.cdm.model.name.Rank;
25 import eu.etaxonomy.cdm.model.name.TaxonNameBase;
26 import eu.etaxonomy.cdm.model.reference.ReferenceBase;
27 import eu.etaxonomy.cdm.model.taxon.Synonym;
28 import eu.etaxonomy.cdm.model.taxon.SynonymRelationship;
29 import eu.etaxonomy.cdm.model.taxon.SynonymRelationshipType;
30 import eu.etaxonomy.cdm.model.taxon.Taxon;
31 import eu.etaxonomy.cdm.model.taxon.TaxonBase;
32 import eu.etaxonomy.cdm.model.taxon.TaxonNode;
33 import eu.etaxonomy.cdm.model.taxon.TaxonRelationship;
34 import eu.etaxonomy.cdm.model.taxon.TaxonRelationshipType;
35 import eu.etaxonomy.cdm.model.taxon.TaxonomicTree;
36 import eu.etaxonomy.cdm.persistence.dao.BeanInitializer;
37 import eu.etaxonomy.cdm.persistence.fetch.CdmFetch;
38 import eu.etaxonomy.cdm.persistence.query.OrderHint;
39
40
41 public interface ITaxonService extends IIdentifiableEntityService<TaxonBase>{
42
43 /**
44 * Computes all taxon bases.
45 * FIXME could substitute with list(Synonym.class, limit, start)
46 * @param limit
47 * @param start
48 * @return
49 */
50 public List<Synonym> getAllSynonyms(int limit, int start);
51
52 /**
53 * Computes all taxon bases.
54 * FIXME could substitute with list(Taxon.class, limit,start)
55 * @param limit
56 * @param start
57 * @return
58 */
59 public List<Taxon> getAllTaxa(int limit, int start);
60
61 /**
62 * Computes all Taxon instances that do not have a taxonomic parent and has at least one child.
63 * @param sec The concept reference that the taxon belongs to
64 * @return The List<Taxon> of root taxa.
65 * @deprecated obsolete when using taxonomicTree
66 */
67 public List<Taxon> getRootTaxa(ReferenceBase sec);
68
69
70 /**
71 * Computes all Taxon instances that do not have a taxonomic parent.
72 * @param sec The concept reference that the taxon belongs to
73 *
74 * @param onlyWithChildren if true only taxa are returned that have taxonomic children. <Br>Default: true.
75 * @return The List<Taxon> of root taxa.
76 * @deprecated obsolete when using taxonomicTree
77 */
78 public List<Taxon> getRootTaxa(ReferenceBase sec, CdmFetch cdmFetch, boolean onlyWithChildren);
79
80 /**
81 * Computes all Taxon instances that do not have a taxonomic parent.
82 * @param sec The concept reference that the taxon belongs to
83 * @param onlyWithChildren if true only taxa are returned that have taxonomic children. <Br>Default: true.
84 * @param withMisapplications if false taxa that have at least one misapplied name relationship in which they are
85 * the misapplied name are not returned.<Br>Default: true.
86 * @return The List<Taxon> of root taxa.
87 * @deprecated obsolete when using taxonomicTree
88 */
89 public List<Taxon> getRootTaxa(ReferenceBase sec, boolean onlyWithChildren, boolean withMisapplications);
90
91 /**
92 * Computes all Taxon instances which name is of a certain Rank.
93 * @param rank The rank of the taxon name
94 * @param sec The concept reference that the taxon belongs to
95 * @param onlyWithChildren if true only taxa are returned that have taxonomic children. <Br>Default: true.
96 * @param withMisapplications if false taxa that have at least one misapplied name relationship in which they are
97 * the misapplied name are not returned.<Br>Default: true.
98 * @param propertyPaths
99 * properties to be initialized, For detailed description and
100 * examples <b>please refer to:</b>
101 * {@link BeanInitializer#initialize(Object, List)}. <Br>
102 * Default: true.
103 * @return The List<Taxon> of root taxa.
104 * @deprecated obsolete when using taxonomicTree
105 */
106 public List<Taxon> getRootTaxa(Rank rank, ReferenceBase sec, boolean onlyWithChildren, boolean withMisapplications, List<String> propertyPaths);
107
108 /**
109 * Computes all relationships.
110 * @param limit
111 * @param start
112 * @return
113 */
114 public List<RelationshipBase> getAllRelationships(int limit, int start);
115
116 /**
117 * Returns TaxonRelationshipType vocabulary
118 * @return
119 * @deprecated use TermService#getVocabulary(VocabularyType) instead
120 */
121 public OrderedTermVocabulary<TaxonRelationshipType> getTaxonRelationshipTypeVocabulary();
122
123 /**
124 * Returns a list of taxa that matches the name string and the sec reference
125 * @param name the name string to search for
126 * @param sec the taxons sec reference
127 * @return a list of taxa matching the name and the sec reference
128 */
129 public List<TaxonBase> searchTaxaByName(String name, ReferenceBase sec);
130
131 /**
132 * Changes an accepted taxon to a synonym of another taxon.
133 *
134 * @param oldTaxonNode
135 * the <code>TaxonNode</code> of the accepted taxon that will be changed into a synonym
136 * @param newAcceptedTaxonNode
137 * the <code>TaxonNode</code> of the accepted taxon, the old taxon will become a synonym of
138 * @param synonymType
139 * <code>SynonymRelationshipType</code> to indicate whether hetero or homotypic
140 * @param citation
141 * the reference for this assumption
142 * @param citationMicroReference
143 * the micro citation
144 * @return
145 * the newly created synonym
146 */
147 public Synonym changeAcceptedTaxonToSynonym (TaxonNode oldTaxonNode, TaxonNode newAcceptedTaxonNode, SynonymRelationshipType synonymType, ReferenceBase citation, String citationMicroReference);
148
149 /**
150 * Swaps given synonym and accepted taxon.
151 * In particular:
152 * <ul>
153 * <li>A new accepted taxon with the synonyms name is created</li>
154 * <li>The synonym is deleted from the old accepted taxons synonym list</li>
155 * <li>A new synonym with the name of the old accepted taxon is created</li>
156 * <li>The newly created synonym get related to the newly created accepted taxon</li>
157 * </ul>
158 *
159 * @param synonym
160 * @param acceptedTaxon
161 * @param synonymRelationshipType the relationship type the newly created synonym will have. Defaults to SYNONYM_OF
162 */
163 public void swapSynonymAndAcceptedTaxon(Synonym synonym, Taxon acceptedTaxon);
164
165 /**
166 * Change a synonym into an accepted taxon and removes
167 * the synonym relationship to the given accepted taxon.
168 *
169 * @param synonym
170 * the synonym to change into an accepted taxon
171 * @param acceptedTaxon
172 * an accepted taxon, the synonym had a relationship to
173 * @return
174 * the newly created accepted taxon
175 */
176 public Taxon changeSynonymToAcceptedTaxon(Synonym synonym, Taxon acceptedTaxon);
177
178 /**
179 * Change a synonym into a related concept
180 *
181 * @param synonym
182 * the synonym to change into the concept taxon
183 * @param toTaxon
184 * the taxon the newly created concept should be related to
185 * @param taxonRelationshipType
186 * the type of relationship
187 * @param citation
188 * @param microcitation
189 * @return
190 * the newly created concept
191 */
192 public Taxon changeSynonymToRelatedTaxon(Synonym synonym, Taxon toTaxon, TaxonRelationshipType taxonRelationshipType, ReferenceBase citation, String microcitation);
193
194 /**
195 * Returns the TaxonRelationships (of where relationship.type == type, if this argument is supplied)
196 * where the supplied taxon is relatedTo.
197 *
198 * @param taxon The taxon that is relatedTo
199 * @param type The type of TaxonRelationship (can be null)
200 * @param pageSize The maximum number of relationships returned (can be null for all relationships)
201 * @param pageNumber The offset (in pageSize chunks) from the start of the result set (0 - based)
202 * @param orderHints Properties to order by
203 * @param propertyPaths Properties to initialize in the returned entities, following the syntax described in {@link BeanInitializer#initialize(Object, List)}
204 * @return a List of TaxonRelationship instances
205 */
206 public List<TaxonRelationship> listToTaxonRelationships(Taxon taxon, TaxonRelationshipType type, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths);
207
208
209
210 /**
211 * Returns the TaxonRelationships (of where relationship.type == type, if this arguement is supplied)
212 * where the supplied taxon is relatedTo.
213 *
214 * @param taxon The taxon that is relatedTo
215 * @param type The type of TaxonRelationship (can be null)
216 * @param pageSize The maximum number of relationships returned (can be null for all relationships)
217 * @param pageNumber The offset (in pageSize chunks) from the start of the result set (0 - based)
218 * @param orderHints Properties to order by
219 * @param propertyPaths Properties to initialize in the returned entities, following the syntax described in {@link BeanInitializer#initialize(Object, List)}
220 * @return a Pager of TaxonRelationship instances
221 */
222 public Pager<TaxonRelationship> pageToTaxonRelationships(Taxon taxon, TaxonRelationshipType type, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths);
223
224 /**
225 * Returns the TaxonRelationships (of where relationship.type == type, if this argument is supplied)
226 * where the supplied taxon is relatedFrom.
227 *
228 * @param taxon The taxon that is relatedFrom
229 * @param type The type of TaxonRelationship (can be null)
230 * @param pageSize The maximum number of relationships returned (can be null for all relationships)
231 * @param pageNumber The offset (in pageSize chunks) from the start of the result set (0 - based)
232 * @param orderHints Properties to order by
233 * @param propertyPaths Properties to initialize in the returned entities, following the syntax described in {@link BeanInitializer#initialize(Object, List)}
234 * @return a List of TaxonRelationship instances
235 */
236 public List<TaxonRelationship> listFromTaxonRelationships(Taxon taxon, TaxonRelationshipType type, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths);
237
238
239 /**
240 * Returns the TaxonRelationships (of where relationship.type == type, if this argument is supplied)
241 * where the supplied taxon is relatedFrom.
242 *
243 * @param taxon The taxon that is relatedFrom
244 * @param type The type of TaxonRelationship (can be null)
245 * @param pageSize The maximum number of relationships returned (can be null for all relationships)
246 * @param pageNumber The offset (in pageSize chunks) from the start of the result set (0 - based)
247 * @param orderHints Properties to order by
248 * @param propertyPaths Properties to initialize in the returned entities, following the syntax described in {@link BeanInitializer#initialize(Object, List)}
249 * @return a Pager of TaxonRelationship instances
250 */
251 public Pager<TaxonRelationship> pageFromTaxonRelationships(Taxon taxon, TaxonRelationshipType type, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths);
252
253 /**
254 * Returns the SynonymRelationships (of where relationship.type == type, if this argument is supplied)
255 * where the supplied synonym is relatedFrom.
256 *
257 * @param taxon The synonym that is relatedFrom
258 * @param type The type of SynonymRelationship (can be null)
259 * @param pageSize The maximum number of relationships returned (can be null for all relationships)
260 * @param pageNumber The offset (in pageSize chunks) from the start of the result set (0 - based)
261 * * @param orderHints Properties to order by
262 * @param propertyPaths Properties to initialize in the returned entities, following the syntax described in {@link BeanInitializer#initialize(Object, List)}
263 * @return a Pager of SynonymRelationship instances
264 */
265 public Pager<SynonymRelationship> getSynonyms(Synonym synonym, SynonymRelationshipType type, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths);
266
267 /**
268 * Returns the SynonymRelationships (of where relationship.type == type, if this argument is supplied)
269 * where the supplied taxon is relatedTo.
270 *
271 * @param taxon The taxon that is relatedTo
272 * @param type The type of SynonymRelationship (can be null)
273 * @param pageSize The maximum number of relationships returned (can be null for all relationships)
274 * @param pageNumber The offset (in pageSize chunks) from the start of the result set (0 - based)
275 * * @param orderHints Properties to order by
276 * @param propertyPaths Properties to initialize in the returned entities, following the syntax described in {@link BeanInitializer#initialize(Object, List)}
277 * @return a Pager of SynonymRelationship instances
278 */
279 public Pager<SynonymRelationship> getSynonyms(Taxon taxon, SynonymRelationshipType type, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths);
280
281 public List<Synonym> getHomotypicSynonymsByHomotypicGroup(Taxon taxon, List<String> propertyPaths);
282
283 public List<List<Synonym>> getHeterotypicSynonymyGroups(Taxon taxon, List<String> propertyPaths);
284
285 /**
286 * Returns a Paged List of TaxonBase instances where the default field matches the String queryString (as interpreted by the Lucene QueryParser)
287 *
288 * @param clazz filter the results by class (or pass null to return all TaxonBase instances)
289 * @param queryString
290 * @param pageSize The maximum number of taxa returned (can be null for all matching taxa)
291 * @param pageNumber The offset (in pageSize chunks) from the start of the result set (0 - based)
292 * @param orderHints
293 * Supports path like <code>orderHints.propertyNames</code> which
294 * include *-to-one properties like createdBy.username or
295 * authorTeam.persistentTitleCache
296 * @param propertyPaths properties to be initialized
297 * @return a Pager Taxon instances
298 * @see <a href="http://lucene.apache.org/java/2_4_0/queryparsersyntax.html">Apache Lucene - Query Parser Syntax</a>
299 */
300 public Pager<TaxonBase> search(Class<? extends TaxonBase> clazz, String queryString, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths);
301
302 /**
303 * Returns a list of TaxonBase instances where the
304 * taxon.name properties match the parameters passed. In order to search for any string value, pass '*', passing the string value of
305 * <i>null</i> will search for those taxa with a value of null in that field
306 *
307 * @param clazz optionally filter by class (can be null to return all taxa)
308 * @param uninomial
309 * @param infragenericEpithet
310 * @param specificEpithet
311 * @param infraspecificEpithet
312 * @param rank
313 * @param pageSize The maximum number of taxa returned (can be null for all matching taxa)
314 * @param pageNumber The offset (in pageSize chunks) from the start of the result set (0 - based)
315 * @return a list of TaxonBase instances
316 */
317 public Pager<TaxonBase> findTaxaByName(Class<? extends TaxonBase> clazz, String uninomial, String infragenericEpithet, String specificEpithet, String infraspecificEpithet, Rank rank, Integer pageSize, Integer pageNumber);
318
319 /**
320 * Returns a list of TaxonBase instances where the
321 * taxon.name properties match the parameters passed. In order to search for any string value, pass '*', passing the string value of
322 * <i>null</i> will search for those taxa with a value of null in that field
323 *
324 * @param clazz optionally filter by class
325 * @param uninomial
326 * @param infragenericEpithet
327 * @param specificEpithet
328 * @param infraspecificEpithet
329 * @param rank
330 * @param pageSize The maximum number of taxa returned (can be null for all matching taxa)
331 * @param pageNumber The offset (in pageSize chunks) from the start of the result set (0 - based)
332 * @return a List of TaxonBase instances
333 */
334 public List<TaxonBase> listTaxaByName(Class<? extends TaxonBase> clazz, String uninomial, String infragenericEpithet, String specificEpithet, String infraspecificEpithet, Rank rank, Integer pageSize, Integer pageNumber);
335
336 /**
337 * Returns a list of IdentifiableEntity instances (in particular, TaxonNameBase and TaxonBase instances)
338 * that match the properties specified in the configurator.
339 * @param configurator
340 * @return
341 */
342 public Pager<IdentifiableEntity> findTaxaAndNames(ITaxonServiceConfigurator configurator);
343
344 /**
345 *
346 * @param taxon
347 * @param size
348 * @param height
349 * @param widthOrDuration
350 * @param mimeTypes
351 * @return
352 */
353 public List<MediaRepresentation> getAllMedia(Taxon taxon, int size, int height, int widthOrDuration, String[] mimeTypes);
354
355 public List<TaxonBase> findTaxaByID(Set<Integer> listOfIDs);
356 /**
357 * returns a list of inferred synonyms concerning the taxon with synonymrelationshiptype type
358 * @param tree
359 * @param taxon
360 * @param type
361 * @return
362 */
363 public List<Synonym> createInferredSynonyms(TaxonomicTree tree, Taxon taxon, SynonymRelationshipType type);
364 /**
365 * returns a list of all inferred synonyms (inferred epithet, inferred genus and potential combination) concerning the taxon
366 * @param tree
367 * @param taxon
368 * @return
369 */
370 public List<Synonym> createAllInferredSynonyms(TaxonomicTree tree, Taxon taxon);
371
372 public int countAllRelationships();
373
374 public List<TaxonNameBase> findIdenticalTaxonNames(List<String> propertyPath);
375 public List<TaxonNameBase> findIdenticalTaxonNameIds(List<String> propertyPath);
376 public String getPhylumName(TaxonNameBase name);
377
378 public long deleteSynonymRelationships(Synonym syn);
379 /**
380 * Returns the SynonymRelationships (of where relationship.type == type, if this argument is supplied)
381 * depending on direction, where the supplied taxon is relatedTo or the supplied synonym is relatedFrom.
382 *
383 * @param taxonBase The taxon or synonym that is relatedTo or relatedFrom
384 * @param type The type of SynonymRelationship (can be null)
385 * @param pageSize The maximum number of relationships returned (can be null for all relationships)
386 * @param pageNumber The offset (in pageSize chunks) from the start of the result set (0 - based)
387 * @param orderHints Properties to order by
388 * @param propertyPaths Properties to initialize in the returned entities, following the syntax described in {@link BeanInitializer#initialize(Object, List)}
389 * @param direction The direction of the relationship
390 * @return a List of SynonymRelationship instances
391 */
392 public List<SynonymRelationship> listSynonymRelationships(
393 TaxonBase taxonBase, SynonymRelationshipType type, Integer pageSize, Integer pageNumber,
394 List<OrderHint> orderHints, List<String> propertyPaths, Direction direction);
395
396 /**
397 * @param tnb
398 * @return
399 */
400 public Taxon findBestMatchingTaxon(String taxonName);
401 }