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