3 * Copyright (C) 2009 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
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.
11 package eu
.etaxonomy
.cdm
.api
.service
;
13 import java
.io
.IOException
;
14 import java
.util
.Collection
;
15 import java
.util
.List
;
17 import java
.util
.UUID
;
19 import org
.apache
.lucene
.index
.CorruptIndexException
;
20 import org
.apache
.lucene
.queryParser
.ParseException
;
21 import org
.hibernate
.search
.spatial
.impl
.Rectangle
;
23 import eu
.etaxonomy
.cdm
.api
.facade
.DerivedUnitFacade
;
24 import eu
.etaxonomy
.cdm
.api
.facade
.DerivedUnitFacadeNotSupportedException
;
25 import eu
.etaxonomy
.cdm
.api
.service
.config
.IIdentifiableEntityServiceConfigurator
;
26 import eu
.etaxonomy
.cdm
.api
.service
.config
.SpecimenDeleteConfigurator
;
27 import eu
.etaxonomy
.cdm
.api
.service
.dto
.FieldUnitDTO
;
28 import eu
.etaxonomy
.cdm
.api
.service
.dto
.PreservedSpecimenDTO
;
29 import eu
.etaxonomy
.cdm
.api
.service
.pager
.Pager
;
30 import eu
.etaxonomy
.cdm
.api
.service
.search
.SearchResult
;
31 import eu
.etaxonomy
.cdm
.api
.service
.util
.TaxonRelationshipEdge
;
32 import eu
.etaxonomy
.cdm
.model
.common
.ICdmBase
;
33 import eu
.etaxonomy
.cdm
.model
.common
.Language
;
34 import eu
.etaxonomy
.cdm
.model
.description
.DescriptionBase
;
35 import eu
.etaxonomy
.cdm
.model
.description
.DescriptionElementBase
;
36 import eu
.etaxonomy
.cdm
.model
.description
.IndividualsAssociation
;
37 import eu
.etaxonomy
.cdm
.model
.description
.TaxonDescription
;
38 import eu
.etaxonomy
.cdm
.model
.location
.Country
;
39 import eu
.etaxonomy
.cdm
.model
.media
.Media
;
40 import eu
.etaxonomy
.cdm
.model
.molecular
.DnaSample
;
41 import eu
.etaxonomy
.cdm
.model
.molecular
.Sequence
;
42 import eu
.etaxonomy
.cdm
.model
.name
.HomotypicalGroup
;
43 import eu
.etaxonomy
.cdm
.model
.name
.SpecimenTypeDesignation
;
44 import eu
.etaxonomy
.cdm
.model
.name
.TaxonNameBase
;
45 import eu
.etaxonomy
.cdm
.model
.occurrence
.DerivationEvent
;
46 import eu
.etaxonomy
.cdm
.model
.occurrence
.DerivedUnit
;
47 import eu
.etaxonomy
.cdm
.model
.occurrence
.DeterminationEvent
;
48 import eu
.etaxonomy
.cdm
.model
.occurrence
.FieldUnit
;
49 import eu
.etaxonomy
.cdm
.model
.occurrence
.MediaSpecimen
;
50 import eu
.etaxonomy
.cdm
.model
.occurrence
.SpecimenOrObservationBase
;
51 import eu
.etaxonomy
.cdm
.model
.occurrence
.SpecimenOrObservationType
;
52 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
53 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonBase
;
54 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonRelationship
;
55 import eu
.etaxonomy
.cdm
.persistence
.dao
.initializer
.IBeanInitializer
;
56 import eu
.etaxonomy
.cdm
.persistence
.dto
.UuidAndTitleCache
;
57 import eu
.etaxonomy
.cdm
.persistence
.query
.OrderHint
;
60 * @author a.babadshanjan
63 public interface IOccurrenceService
extends IIdentifiableEntityService
<SpecimenOrObservationBase
> {
65 public Country
getCountryByIso(String iso639
);
67 public List
<Country
> getCountryByName(String name
);
70 * Returns a paged list of occurrences that have been determined to belong
71 * to the taxon concept determinedAs, optionally restricted to objects
72 * belonging to a class that that extends SpecimenOrObservationBase. This
73 * will also consider specimens that are determined as a taxon concept
74 * belonging to the synonymy of the given taxon concept.
76 * In contrast to {@link #listByAnyAssociation(Class, Taxon, List)} this
77 * method only takes SpecimenOrObservationBase instances into account which
78 * are actually determined as the taxon specified by
79 * <code>determinedAs</code>.
82 * The type of entities to return (can be null to count all
83 * entities of type <T>)
85 * the taxon concept that the occurrences have been determined to
88 * The maximum number of objects returned (can be null for all
91 * The offset (in pageSize chunks) from the start of the result
92 * set (0 - based, can be null, equivalent of starting at the
93 * beginning of the recordset)
95 * Supports path like <code>orderHints.propertyNames</code> which
96 * include *-to-one properties like createdBy.username or
97 * authorTeam.persistentTitleCache
98 * @param propertyPaths
99 * properties to be initialized
102 public Pager
<SpecimenOrObservationBase
> list(Class
<?
extends SpecimenOrObservationBase
> type
, TaxonBase determinedAs
, Integer limit
, Integer start
, List
<OrderHint
> orderHints
, List
<String
> propertyPaths
);
105 * Returns a paged list of occurrences that have been determined to belong
106 * to the taxon name determinedAs, optionally restricted to objects
107 * belonging to a class that that extends SpecimenOrObservationBase.
109 * In contrast to {@link #listByAnyAssociation(Class, Taxon, List)} this
110 * method only takes SpecimenOrObservationBase instances into account which
111 * are actually determined as the taxon specified by
112 * <code>determinedAs</code>.
115 * The type of entities to return (can be null to count all
116 * entities of type <T>)
117 * @param determinedAs
118 * the taxon name that the occurrences have been determined to
121 * The maximum number of objects returned (can be null for all
124 * The offset (in pageSize chunks) from the start of the result
125 * set (0 - based, can be null, equivalent of starting at the
126 * beginning of the recordset)
128 * Supports path like <code>orderHints.propertyNames</code> which
129 * include *-to-one properties like createdBy.username or
130 * authorTeam.persistentTitleCache
131 * @param propertyPaths
132 * properties to be initialized
135 public Pager
<SpecimenOrObservationBase
> list(Class
<?
extends SpecimenOrObservationBase
> type
, TaxonNameBase determinedAs
, Integer limit
, Integer start
, List
<OrderHint
> orderHints
, List
<String
> propertyPaths
);
138 * Returns a List of Media that are associated with a given occurence
140 * @param occurence the occurence associated with these media
141 * @param pageSize The maximum number of media returned (can be null for all related media)
142 * @param pageNumber The offset (in pageSize chunks) from the start of the result set (0 - based)
143 * @param propertyPaths properties to initialize - see {@link IBeanInitializer#initialize(Object, List)}
144 * @return a Pager of media instances
146 public Pager
<Media
> getMedia(SpecimenOrObservationBase occurence
, Integer pageSize
, Integer pageNumber
, List
<String
> propertyPaths
);
149 * Returns all media attached to this occurence and its children. Also takes
150 * {@link MediaSpecimen} and molecular images into account.
152 * @param occurence the occurence and its children from which the media to get
153 * @param pageNumber The offset (in pageSize chunks) from the start of the result set (0 - based)
154 * @param propertyPaths properties to initialize - see {@link IBeanInitializer#initialize(Object, List)}
155 * @return a Pager of media instances
157 public Pager
<Media
> getMediainHierarchy(SpecimenOrObservationBase rootOccurence
, Integer pageSize
, Integer pageNumber
, List
<String
> propertyPaths
);
160 * Returns a count of determinations that have been made for a given occurence and for a given taxon concept
162 * @param occurence the occurence associated with these determinations (can be null for all occurrences)
163 * @param taxonbase the taxon concept associated with these determinations (can be null for all taxon concepts)
164 * @return a count of determination events
166 public int countDeterminations(SpecimenOrObservationBase occurence
,TaxonBase taxonbase
);
169 * Returns a List of determinations that have been made for a given occurence
171 * @param occurence the occurence associated with these determinations (can be null for all occurrences)
172 * @param taxonbase the taxon concept associated with these determinations (can be null for all taxon concepts)
173 * @param pageSize The maximum number of determinations returned (can be null for all related determinations)
174 * @param pageNumber The offset (in pageSize chunks) from the start of the result set (0 - based)
175 * @return a Pager of determination instances
177 public Pager
<DeterminationEvent
> getDeterminations(SpecimenOrObservationBase occurence
, TaxonBase taxonBase
, Integer pageSize
, Integer pageNumber
, List
<String
> propertyPaths
);
180 * Returns a list of derivation events that have involved creating new DerivedUnits from this occurence
182 * @param occurence the occurence that was a source of these derivation events
183 * @param pageSize The maximum number of derivation events returned (can be null for all related derivation events)
184 * @param pageNumber The offset (in pageSize chunks) from the start of the result set (0 - based)
185 * @return a Pager of derivation events
187 public Pager
<DerivationEvent
> getDerivationEvents(SpecimenOrObservationBase occurence
, Integer pageSize
, Integer pageNumber
, List
<String
> propertyPaths
);
190 * Returns a Paged List of SpecimenOrObservationBase instances where the default field matches the String queryString (as interpreted by the Lucene QueryParser)
192 * @param clazz filter the results by class (or pass null to return all SpecimenOrObservationBase instances)
194 * @param pageSize The maximum number of occurrences returned (can be null for all matching occurrences)
195 * @param pageNumber The offset (in pageSize chunks) from the start of the result set (0 - based)
197 * Supports path like <code>orderHints.propertyNames</code> which
198 * include *-to-one properties like createdBy.username or
199 * authorTeam.persistentTitleCache
200 * @param propertyPaths properties to be initialized
201 * @return a Pager SpecimenOrObservationBase instances
202 * @see <a href="http://lucene.apache.org/java/2_4_0/queryparsersyntax.html">Apache Lucene - Query Parser Syntax</a>
205 public Pager
<SpecimenOrObservationBase
> search(Class
<?
extends SpecimenOrObservationBase
> clazz
, String query
, Integer pageSize
,Integer pageNumber
, List
<OrderHint
> orderHints
,List
<String
> propertyPaths
);
208 * Retrieves the {@link UUID} and the string representation (title cache) of all
209 * {@link FieldUnit}s found in the data base.
210 * @return a list of {@link UuidAndTitleCache}
212 public List
<UuidAndTitleCache
<FieldUnit
>> getFieldUnitUuidAndTitleCache();
215 * Retrieves the {@link UUID} and the string representation (title cache) of all
216 * {@link DerivedUnit}s found in the data base.
217 * @return a list of {@link UuidAndTitleCache}
219 public List
<UuidAndTitleCache
<DerivedUnit
>> getDerivedUnitUuidAndTitleCache();
221 public DerivedUnitFacade
getDerivedUnitFacade(DerivedUnit derivedUnit
, List
<String
> propertyPaths
) throws DerivedUnitFacadeNotSupportedException
;
223 public List
<DerivedUnitFacade
> listDerivedUnitFacades(DescriptionBase description
, List
<String
> propertyPaths
);
226 * Lists all instances of {@link SpecimenOrObservationBase} which are
227 * associated with the <code>taxon</code> specified as parameter.
228 * SpecimenOrObservationBase instances can be associated to taxa in multiple
229 * ways, all these possible relations are taken into account:
231 * <li>The {@link IndividualsAssociation} elements in a
232 * {@link TaxonDescription} contain {@link DerivedUnit}s</li>
233 * <li>{@link SpecimenTypeDesignation}s may be associated with any
234 * {@link HomotypicalGroup} related to the specific {@link Taxon}.</li>
235 * <li>A {@link Taxon} may be referenced by the {@link DeterminationEvent}
236 * of the {@link SpecimenOrObservationBase}</li>
238 * Further more there also can be taxa which are associated with the taxon
239 * in question (parameter associatedTaxon) by {@link TaxonRelationship}s. If
240 * the parameter <code>includeRelationships</code> is containing elements,
241 * these according {@TaxonRelationshipType}s and
242 * directional information will be used to collect further
243 * {@link SpecimenOrObservationBase} instances found this way.
247 * @param associatedTaxon
248 * @param Set<TaxonRelationshipVector> includeRelationships. TaxonRelationships will not be taken into account if this is <code>NULL</code>.
249 * @param maxDepth TODO
253 * @param propertyPaths
256 public <T
extends SpecimenOrObservationBase
> List
<T
> listByAssociatedTaxon(Class
<T
> type
, Set
<TaxonRelationshipEdge
> includeRelationships
,
257 Taxon associatedTaxon
, Integer maxDepth
, Integer pageSize
, Integer pageNumber
, List
<OrderHint
> orderHints
, List
<String
> propertyPaths
);
260 * Lists all instances of {@link FieldUnit} which are
261 * associated <b>directly or indirectly</b>with the <code>taxon</code> specified
262 * as parameter. "Indirectly" means that a sub derivate of the FieldUnit is
263 * directly associated with the given taxon.
264 * SpecimenOrObservationBase instances can be associated to taxa in multiple
265 * ways, all these possible relations are taken into account:
267 * <li>The {@link IndividualsAssociation} elements in a
268 * {@link TaxonDescription} contain {@link DerivedUnit}s</li>
269 * <li>{@link SpecimenTypeDesignation}s may be associated with any
270 * {@link HomotypicalGroup} related to the specific {@link Taxon}.</li>
271 * <li>A {@link Taxon} may be referenced by the {@link DeterminationEvent}
272 * of the {@link SpecimenOrObservationBase}</li>
274 * Further more there also can be taxa which are associated with the taxon
275 * in question (parameter associatedTaxon) by {@link TaxonRelationship}s. If
276 * the parameter <code>includeRelationships</code> is containing elements,
277 * these according {@TaxonRelationshipType}s and
278 * directional information will be used to collect further
279 * {@link SpecimenOrObservationBase} instances found this way.
283 * @param associatedTaxon
284 * @param Set<TaxonRelationshipVector> includeRelationships. TaxonRelationships will not be taken into account if this is <code>NULL</code>.
285 * @param maxDepth TODO
289 * @param propertyPaths
292 public Collection
<SpecimenOrObservationBase
> listFieldUnitsByAssociatedTaxon(Taxon associatedTaxon
, List
<OrderHint
> orderHints
, List
<String
> propertyPaths
);
295 * See {@link #listFieldUnitsByAssociatedTaxon(Set, Taxon, Integer, Integer, Integer, List, List)}
297 public Pager
<SpecimenOrObservationBase
> pageFieldUnitsByAssociatedTaxon(Set
<TaxonRelationshipEdge
> includeRelationships
,
298 Taxon associatedTaxon
, Integer maxDepth
, Integer pageSize
, Integer pageNumber
, List
<OrderHint
> orderHints
, List
<String
> propertyPaths
);
301 * See {@link #listByAssociatedTaxon(Class, Set, Taxon, Integer, Integer, Integer, List, List)}
304 * @param includeRelationships
305 * @param associatedTaxon
310 * @param propertyPaths
313 public <T
extends SpecimenOrObservationBase
> Pager
<T
> pageByAssociatedTaxon(Class
<T
> type
, Set
<TaxonRelationshipEdge
> includeRelationships
,
314 Taxon associatedTaxon
, Integer maxDepth
, Integer pageSize
, Integer pageNumber
, List
<OrderHint
> orderHints
, List
<String
> propertyPaths
);
317 * Retrieves all {@link FieldUnit}s for the {@link SpecimenOrObservationBase} with the given {@link UUID}.<br>
318 * @param specimenUuid the UUID of the specimen
319 * @return either a collection of FieldUnits this specimen was derived from, the FieldUnit itself
320 * if this was a FieldUnit or an empty collection if no FieldUnits were found
322 public Collection
<FieldUnit
> getFieldUnits(UUID specimenUuid
);
328 * @param highlightFragments
332 * @param propertyPaths
334 * @throws CorruptIndexException
335 * @throws IOException
336 * @throws ParseException
338 Pager
<SearchResult
<SpecimenOrObservationBase
>> findByFullText(Class
<?
extends SpecimenOrObservationBase
> clazz
,
339 String queryString
, Rectangle boundingBox
, List
<Language
> languages
, boolean highlightFragments
, Integer pageSize
,
340 Integer pageNumber
, List
<OrderHint
> orderHints
, List
<String
> propertyPaths
) throws CorruptIndexException
,
341 IOException
, ParseException
;
343 * See {@link #listByAssociatedTaxon(Class, Set, String, Integer, Integer, Integer, List, List)}
346 * @param includeRelationships
347 * @param associatedTaxon
352 * @param propertyPaths
355 public <T
extends SpecimenOrObservationBase
> Pager
<T
> pageByAssociatedTaxon(Class
<T
> type
, Set
<TaxonRelationshipEdge
> includeRelationships
,
356 String taxonUUID
, Integer maxDepth
, Integer pageSize
, Integer pageNumber
, List
<OrderHint
> orderHints
, List
<String
> propertyPaths
);
359 * Moves the given {@link Sequence} from one {@link DnaSample} to another
360 * @param from the DnaSample from which the sequence will be removed
361 * @param to the DnaSample which to which the sequence will be added
362 * @param sequence the Sequence to move
363 * @return <code>true</code> if successfully moved, <code>false</code> otherwise
365 public UpdateResult
moveSequence(DnaSample from
, DnaSample to
, Sequence sequence
);
371 * @param sequenceUuid
374 public UpdateResult
moveSequence(UUID fromUuid
, UUID toUuid
, UUID sequenceUuid
);
377 * Moves the given {@link DerivedUnit} from one {@link SpecimenOrObservationBase} to another.
378 * @param from the SpecimenOrObservationBase from which the DerivedUnit will be removed
379 * @param to the SpecimenOrObservationBase to which the DerivedUnit will be added
380 * @param derivate the DerivedUnit to move
381 * @return <code>true</code> if successfully moved, <code>false</code> otherwise
383 public UpdateResult
moveDerivate(UUID specimenFromUuid
, UUID specimenToUuid
, UUID derivateUuid
);
391 public boolean moveDerivate(SpecimenOrObservationBase
<?
> from
, SpecimenOrObservationBase
<?
> to
, DerivedUnit derivate
);
394 * Assembles a {@link FieldUnitDTO} for the given field unit uuid which is associated to the {@link Taxon}.<br>
396 * For the meaning of "associated" see also {@link #listFieldUnitsByAssociatedTaxon(Set, Taxon, Integer, Integer, Integer, List, List)}
398 * @param associatedTaxonUuid
399 * @return a DTO with all the assembled information
401 public FieldUnitDTO
assembleFieldUnitDTO(FieldUnit fieldUnit
, UUID associatedTaxonUuid
);
404 * Assembles a {@link PreservedSpecimenDTO} for the given derived unit.
406 * @return a DTO with all the assembled information
408 public PreservedSpecimenDTO
assemblePreservedSpecimenDTO(DerivedUnit derivedUnit
);
411 * Returns a collection of {@link ICdmBase}s that are not persisted via cascading when saving the given specimen (mostly DefinedTerms).
412 * @param specimen the specimen that is checked for non-cascaded elements.
413 * @return collection of non-cascaded element associated with the specimen
415 public Collection
<ICdmBase
> getNonCascadedAssociatedElements(SpecimenOrObservationBase
<?
> specimen
);
418 * Deletes the specified specimen according to the setting in the {@link SpecimenDeleteConfigurator}.<br>
419 * @param specimen the specimen which shoul be deleted
420 * @param config specifies options if and how the specimen should be deleted like e.g. including all
422 * @return the {@link DeleteResult} which holds information about the outcome of this operation
424 public DeleteResult
delete(SpecimenOrObservationBase
<?
> specimen
, SpecimenDeleteConfigurator config
);
427 * Deletes the specified specimen belonging to the given {@link UUID}
428 * according to the setting in the {@link SpecimenDeleteConfigurator}.
431 * the specimen which shoul be deleted
433 * specifies options if and how the specimen should be deleted
434 * like e.g. including all of its children
435 * @return the {@link DeleteResult} which holds information about the
436 * outcome of this operation
438 public DeleteResult
delete(UUID specimenUuid
, SpecimenDeleteConfigurator config
);
441 * Retrieves all {@link IndividualsAssociation} with the given specimen.<br>
442 * @param specimen the specimen for which the associations are retrieved
446 * @param propertyPaths
447 * @return collection of all associations
449 public Collection
<IndividualsAssociation
> listIndividualsAssociations(SpecimenOrObservationBase
<?
> specimen
, Integer limit
, Integer start
, List
<OrderHint
> orderHints
, List
<String
> propertyPaths
);
452 * Retrieves all associated taxa for the given specimen
457 * @param propertyPaths
460 public Collection
<TaxonBase
<?
>> listAssociatedTaxa(SpecimenOrObservationBase
<?
> specimen
, Integer limit
, Integer start
, List
<OrderHint
> orderHints
, List
<String
> propertyPaths
);
463 * Retrieves all {@link DeterminationEvent}s which have the given specimen set as identified unit.
464 * @param specimen the type specimen
468 * @param propertyPaths
469 * @return collection of all designations with the given type specimen
471 public Collection
<DeterminationEvent
> listDeterminationEvents(SpecimenOrObservationBase
<?
> specimen
, Integer limit
, Integer start
, List
<OrderHint
> orderHints
, List
<String
> propertyPaths
);
474 * Retrieves all {@link SpecimenTypeDesignation}s which have the given specimen as a type specimen.
475 * @param specimen the type specimen
479 * @param propertyPaths
480 * @return collection of all designations with the given type specimen
482 public Collection
<SpecimenTypeDesignation
> listTypeDesignations(SpecimenOrObservationBase
<?
> specimen
, Integer limit
, Integer start
, List
<OrderHint
> orderHints
, List
<String
> propertyPaths
);
485 * Retrieves all {@link DescriptionBase}s that have the given specimen set as described specimen.
486 * @param specimen the described specimen
490 * @param propertyPaths
491 * @return collection of all descriptions with the given described specimen
493 public Collection
<DescriptionBase
<?
>> listDescriptionsWithDescriptionSpecimen(SpecimenOrObservationBase
<?
> specimen
, Integer limit
, Integer start
, List
<OrderHint
> orderHints
, List
<String
> propertyPaths
);
496 * Gets all description elements that are used for describing the character
497 * states of the given specimen
500 * the specimen for which the character state description
501 * elements should be retrieved
502 * @return a collection of all character state description elements for this
505 public Collection
<DescriptionElementBase
> getCharacterDataForSpecimen(SpecimenOrObservationBase
<?
> specimen
);
508 * Gets all description elements that are used for describing the character
509 * states of the given specimen
511 * @param specimenUuid
512 * the specimen {@link UUID} for which the character state description
513 * elements should be retrieved
514 * @return a collection of all character state description elements for this
517 public Collection
<DescriptionElementBase
> getCharacterDataForSpecimen(UUID specimenUuid
);
520 * Returns the most significant identifier for the given {@link DerivedUnit}.
521 * @param derivedUnit the derived unit to check
522 * @return the identifier string
524 public String
getMostSignificantIdentifier(DerivedUnit derivedUnit
);
527 * Returns the number of specimens that match the given parameters
528 * @param clazz the class to match
529 * @param queryString the queryString to match
530 * @param type the {@link SpecimenOrObservationType} to match
531 * @param associatedTaxon the taxon these specimens are in any way associated to via
532 * determination, type designations, individuals associations, etc.
533 * @param matchmode determines how the query string should be matched
535 * the maximum number of entities returned (can be null to return
539 * Supports path like <code>orderHints.propertyNames</code> which
540 * include *-to-one properties like createdBy.username or
541 * authorTeam.persistentTitleCache
542 * @return the number of found specimens
544 public int countOccurrences(IIdentifiableEntityServiceConfigurator
<SpecimenOrObservationBase
> config
);
547 * Return the all {@link SpecimenOrObservationBase}s of the complete
548 * derivative hierarchy i.e. all parent and child derivatives and the given
552 * a specimen or observation
553 * @return the derivative hierarchy as an unordered list of all specimens or observation
555 public List
<SpecimenOrObservationBase
<?
>> getAllHierarchyDerivatives(SpecimenOrObservationBase
<?
> specimen
);
558 * Returns all child derivatives of the given specimen.
559 * @param specimen a specimen or observation
560 * @return an unordered list of all child derivatives
562 public List
<DerivedUnit
> getAllChildDerivatives(SpecimenOrObservationBase
<?
> specimen
);