Project

General

Profile

Download (37.9 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2009 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.api.service;
11

    
12
import java.io.IOException;
13
import java.util.Collection;
14
import java.util.List;
15
import java.util.Map;
16
import java.util.Set;
17
import java.util.UUID;
18

    
19
import org.apache.lucene.index.CorruptIndexException;
20
import org.hibernate.search.spatial.impl.Rectangle;
21
import org.springframework.transaction.annotation.Transactional;
22

    
23
import eu.etaxonomy.cdm.api.facade.DerivedUnitFacade;
24
import eu.etaxonomy.cdm.api.facade.DerivedUnitFacadeNotSupportedException;
25
import eu.etaxonomy.cdm.api.service.config.FindOccurrencesConfigurator;
26
import eu.etaxonomy.cdm.api.service.config.IIdentifiableEntityServiceConfigurator;
27
import eu.etaxonomy.cdm.api.service.config.SpecimenDeleteConfigurator;
28
import eu.etaxonomy.cdm.api.service.dto.DerivedUnitDTO;
29
import eu.etaxonomy.cdm.api.service.dto.FieldUnitDTO;
30
import eu.etaxonomy.cdm.api.service.dto.MediaDTO;
31
import eu.etaxonomy.cdm.api.service.dto.SpecimenOrObservationBaseDTO;
32
import eu.etaxonomy.cdm.api.service.pager.Pager;
33
import eu.etaxonomy.cdm.api.service.search.LuceneParseException;
34
import eu.etaxonomy.cdm.api.service.search.SearchResult;
35
import eu.etaxonomy.cdm.api.util.TaxonRelationshipEdge;
36
import eu.etaxonomy.cdm.model.common.Language;
37
import eu.etaxonomy.cdm.model.description.DescriptionBase;
38
import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
39
import eu.etaxonomy.cdm.model.description.IndividualsAssociation;
40
import eu.etaxonomy.cdm.model.description.TaxonDescription;
41
import eu.etaxonomy.cdm.model.location.Point;
42
import eu.etaxonomy.cdm.model.media.Media;
43
import eu.etaxonomy.cdm.model.molecular.DnaSample;
44
import eu.etaxonomy.cdm.model.molecular.Sequence;
45
import eu.etaxonomy.cdm.model.name.HomotypicalGroup;
46
import eu.etaxonomy.cdm.model.name.SpecimenTypeDesignation;
47
import eu.etaxonomy.cdm.model.name.TaxonName;
48
import eu.etaxonomy.cdm.model.occurrence.DerivationEvent;
49
import eu.etaxonomy.cdm.model.occurrence.DerivedUnit;
50
import eu.etaxonomy.cdm.model.occurrence.DeterminationEvent;
51
import eu.etaxonomy.cdm.model.occurrence.FieldUnit;
52
import eu.etaxonomy.cdm.model.occurrence.GatheringEvent;
53
import eu.etaxonomy.cdm.model.occurrence.MediaSpecimen;
54
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
55
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationType;
56
import eu.etaxonomy.cdm.model.taxon.Taxon;
57
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
58
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
59
import eu.etaxonomy.cdm.model.taxon.TaxonRelationship;
60
import eu.etaxonomy.cdm.persistence.dao.initializer.IBeanInitializer;
61
import eu.etaxonomy.cdm.persistence.dto.SpecimenNodeWrapper;
62
import eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache;
63
import eu.etaxonomy.cdm.persistence.query.OrderHint;
64

    
65
/**
66
 * @author a.babadshanjan
67
 * @since 01.09.2008
68
 */
69
public interface IOccurrenceService
70
        extends IIdentifiableEntityService<SpecimenOrObservationBase> {
71

    
72
    /**
73
     * Returns a paged list of occurrences that have been determined to belong
74
     * to the taxon concept determinedAs, optionally restricted to objects
75
     * belonging to a class that that extends SpecimenOrObservationBase. This
76
     * will also consider specimens that are determined as a taxon concept
77
     * belonging to the synonymy of the given taxon concept.
78
     * <p>
79
     * In contrast to {@link #listByAnyAssociation(Class, Taxon, List)} this
80
     * method only takes SpecimenOrObservationBase instances into account which
81
     * are actually determined as the taxon specified by
82
     * <code>determinedAs</code>.
83
     *
84
     * @param type
85
     *            The type of entities to return (can be null to count all
86
     *            entities of type <T>)
87
     * @param determinedAs
88
     *            the taxon concept that the occurrences have been determined to
89
     *            belong to
90
     * @param pageSize
91
     *            The maximum number of objects returned (can be null for all
92
     *            matching objects)
93
     * @param pageNumber
94
     *            The offset (in pageSize chunks) from the start of the result
95
     *            set (0 - based, can be null, equivalent of starting at the
96
     *            beginning of the recordset)
97
     * @param orderHints
98
     *            Supports path like <code>orderHints.propertyNames</code> which
99
     *            include *-to-one properties like createdBy.username or
100
     *            authorTeam.persistentTitleCache
101
     * @param propertyPaths
102
     *            properties to be initialized
103
     * @return
104
     */
105
    public Pager<SpecimenOrObservationBase> list(Class<? extends SpecimenOrObservationBase> type, TaxonBase determinedAs, Integer limit, Integer start, List<OrderHint> orderHints, List<String> propertyPaths);
106

    
107
    /**
108
     * Returns a paged list of occurrences that have been determined to belong
109
     * to the taxon name determinedAs, optionally restricted to objects
110
     * belonging to a class that that extends SpecimenOrObservationBase.
111
     * <p>
112
     * In contrast to {@link #listByAnyAssociation(Class, Taxon, List)} this
113
     * method only takes SpecimenOrObservationBase instances into account which
114
     * are actually determined as the taxon specified by
115
     * <code>determinedAs</code>.
116
     *
117
     * @param type
118
     *            The type of entities to return (can be null to count all
119
     *            entities of type <T>)
120
     * @param determinedAs
121
     *            the taxon name that the occurrences have been determined to
122
     *            belong to
123
     * @param pageSize
124
     *            The maximum number of objects returned (can be null for all
125
     *            matching objects)
126
     * @param pageNumber
127
     *            The offset (in pageSize chunks) from the start of the result
128
     *            set (0 - based, can be null, equivalent of starting at the
129
     *            beginning of the recordset)
130
     * @param orderHints
131
     *            Supports path like <code>orderHints.propertyNames</code> which
132
     *            include *-to-one properties like createdBy.username or
133
     *            authorTeam.persistentTitleCache
134
     * @param propertyPaths
135
     *            properties to be initialized
136
     * @return
137
     */
138
    public Pager<SpecimenOrObservationBase> list(Class<? extends SpecimenOrObservationBase> type, TaxonName determinedAs, Integer limit, Integer start, List<OrderHint> orderHints, List<String> propertyPaths);
139

    
140
    /**
141
     * Returns a List of Media that are associated with a given occurence
142
     *
143
     * @param occurence the occurence associated with these media
144
     * @param pageSize The maximum number of media returned (can be null for all related media)
145
     * @param pageNumber The offset (in pageSize chunks) from the start of the result set (0 - based)
146
     * @param propertyPaths properties to initialize - see {@link IBeanInitializer#initialize(Object, List)}
147
     * @return a Pager of media instances
148
     */
149
    public Pager<Media> getMedia(SpecimenOrObservationBase occurence, Integer pageSize, Integer pageNumber, List<String> propertyPaths);
150

    
151
    /**
152
     * Returns all media attached to this occurence and its children. Also takes
153
     * {@link MediaSpecimen} and molecular images into account.
154
     *
155
     * @param occurence the occurence and its children from which the media to get
156
     * @param pageNumber The offset (in pageSize chunks) from the start of the result set (0 - based)
157
     * @param propertyPaths properties to initialize - see {@link IBeanInitializer#initialize(Object, List)}
158
     * @return a Pager of media instances
159
     */
160
    public Pager<Media> getMediaInHierarchy(SpecimenOrObservationBase<?> rootOccurence, Integer pageSize, Integer pageNumber, List<String> propertyPaths);
161

    
162
    /**
163
     * Returns a count of determinations that have been made for a given occurence and for a given taxon concept
164
     *
165
     * @param occurence the occurence associated with these determinations (can be null for all occurrences)
166
     * @param taxonbase the taxon concept associated with these determinations (can be null for all taxon concepts)
167
     * @return a count of determination events
168
     */
169
    public long countDeterminations(SpecimenOrObservationBase occurence,TaxonBase taxonbase);
170

    
171
    /**
172
     * Returns a List of determinations that have been made for a given occurence
173
     *
174
     * @param occurence the occurence associated with these determinations (can be null for all occurrences)
175
     * @param taxonbase the taxon concept associated with these determinations (can be null for all taxon concepts)
176
     * @param pageSize The maximum number of determinations returned (can be null for all related determinations)
177
     * @param pageNumber The offset (in pageSize chunks) from the start of the result set (0 - based)
178
     * @return a Pager of determination instances
179
     */
180
    public Pager<DeterminationEvent> getDeterminations(SpecimenOrObservationBase occurence, TaxonBase taxonBase, Integer pageSize, Integer pageNumber, List<String> propertyPaths);
181

    
182
    /**
183
     * Returns a list of derivation events that have involved creating new DerivedUnits from this occurence
184
     *
185
     * @param occurence the occurence that was a source of these derivation events
186
     * @param pageSize The maximum number of derivation events returned (can be null for all related derivation events)
187
     * @param pageNumber The offset (in pageSize chunks) from the start of the result set (0 - based)
188
     * @return a Pager of derivation events
189
     */
190
    public Pager<DerivationEvent> getDerivationEvents(SpecimenOrObservationBase occurence, Integer pageSize, Integer pageNumber, List<String> propertyPaths);
191

    
192
    /**
193
     * Returns a Paged List of SpecimenOrObservationBase instances where the default field matches the String queryString (as interpreted by the Lucene QueryParser)
194
     *
195
     * @param clazz filter the results by class (or pass null to return all SpecimenOrObservationBase instances)
196
     * @param queryString
197
     * @param pageSize The maximum number of occurrences returned (can be null for all matching occurrences)
198
     * @param pageNumber The offset (in pageSize chunks) from the start of the result set (0 - based)
199
     * @param orderHints
200
     *            Supports path like <code>orderHints.propertyNames</code> which
201
     *            include *-to-one properties like createdBy.username or
202
     *            authorTeam.persistentTitleCache
203
     * @param propertyPaths properties to be initialized
204
     * @return a Pager SpecimenOrObservationBase instances
205
     * @see <a href="http://lucene.apache.org/java/2_4_0/queryparsersyntax.html">Apache Lucene - Query Parser Syntax</a>
206
     */
207
    @Override
208
    public Pager<SpecimenOrObservationBase> search(Class<? extends SpecimenOrObservationBase> clazz, String query, Integer pageSize,Integer pageNumber, List<OrderHint> orderHints,List<String> propertyPaths);
209

    
210
    /**
211
     * Retrieves the {@link UUID} and the string representation (title cache) of all
212
     * {@link FieldUnit}s found in the data base.
213
     * @return a list of {@link UuidAndTitleCache}
214
     */
215
    public List<UuidAndTitleCache<FieldUnit>> getFieldUnitUuidAndTitleCache();
216

    
217
    /**
218
     * Retrieves the {@link UUID} and the string representation (title cache) of all
219
     * {@link DerivedUnit}s found in the data base.
220
     * @return a list of {@link UuidAndTitleCache}
221
     */
222
    public List<UuidAndTitleCache<DerivedUnit>> getDerivedUnitUuidAndTitleCache(Integer limit, String pattern);
223

    
224
    public DerivedUnitFacade getDerivedUnitFacade(DerivedUnit derivedUnit, List<String> propertyPaths) throws DerivedUnitFacadeNotSupportedException;
225

    
226
    public List<DerivedUnitFacade> listDerivedUnitFacades(DescriptionBase description, List<String> propertyPaths);
227

    
228
    /**
229
     * Lists all instances of {@link SpecimenOrObservationBase} which are
230
     * associated with the <code>taxon</code> specified as parameter.
231
     * SpecimenOrObservationBase instances can be associated to taxa in multiple
232
     * ways, all these possible relations are taken into account:
233
     * <ul>
234
     * <li>The {@link IndividualsAssociation} elements in a
235
     * {@link TaxonDescription} contain {@link DerivedUnit}s</li>
236
     * <li>{@link SpecimenTypeDesignation}s may be associated with any
237
     * {@link HomotypicalGroup} related to the specific {@link Taxon}.</li>
238
     * <li>A {@link Taxon} may be referenced by the {@link DeterminationEvent}
239
     * of the {@link SpecimenOrObservationBase}</li>
240
     * </ul>
241
     * Further more there also can be taxa which are associated with the taxon
242
     * in question (parameter associatedTaxon) by {@link TaxonRelationship}s. If
243
     * the parameter <code>includeRelationships</code> is containing elements,
244
     * these according {@TaxonRelationshipType}s and
245
     * directional information will be used to collect further
246
     * {@link SpecimenOrObservationBase} instances found this way.
247
     *
248
     * @param <T>
249
     * @param type
250
     * @param associatedTaxon
251
     * @param Set<TaxonRelationshipVector> includeRelationships. TaxonRelationships will not be taken into account if this is <code>NULL</code>.
252
     * @param maxDepth TODO
253
     * @param pageSize
254
     * @param pageNumber
255
     * @param orderHints
256
     * @param propertyPaths
257
     * @return
258
     */
259
    public <T extends SpecimenOrObservationBase> List<T> listByAssociatedTaxon(Class<T> type, Set<TaxonRelationshipEdge> includeRelationships,
260
            Taxon associatedTaxon, Integer maxDepth, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths);
261

    
262
    /**
263
     * The method will search for specimen associated with the taxon nodes.<br>
264
     * It will search for 3 possible association types: <br>
265
     * - via IndividualAssociations of the taxon<br>
266
     *  - via TypeDesignations of the taxon name<br>
267
     *  - via Determinations of the taxon or taxon name<br>
268
     * <br>
269
     * more are covered in
270
     * {@link IOccurrenceService#findByTitle(IIdentifiableEntityServiceConfigurator)}
271
     * @param taxonNodeUuids
272
     *            a list of {@link UUID}s of the taxon nodes
273
     * @param limit
274
     * @param start
275
     * @return a collection of {@link SpecimenNodeWrapper} containing the
276
     *         {@link TaxonNode} and the corresponding {@link UuidAndTitleCache}
277
     *         object for the specimen found for this taxon node
278
     */
279
    public Collection<SpecimenNodeWrapper> listUuidAndTitleCacheByAssociatedTaxon(List<UUID> taxonNodeUuids,
280
            Integer limit, Integer start);
281

    
282

    
283
    /**
284
     * @deprecated replace by {@link #listRootUnitsByAssociatedTaxon(Class, Taxon, List, List)}
285
     */
286
    @Deprecated
287
    public Collection<FieldUnit> listFieldUnitsByAssociatedTaxon(Taxon associatedTaxon, List<OrderHint> orderHints, List<String> propertyPaths);
288

    
289

    
290
    /**
291
     * See {@link #listByAssociatedTaxon(Class, Set, Taxon, Integer, Integer, Integer, List, List)}
292
     *
293
     * @param type
294
     *  Restriction to subtype of <code>SpecimenOrObservationBase</code>, can be NULL.
295
     * @param includeRelationships
296
     * @param associatedTaxon
297
     * @param maxDepth
298
     * @param pageSize
299
     * @param pageNumber
300
     * @param orderHints
301
     * @param propertyPaths
302
     * @return a Pager
303
     */
304
    public <T extends SpecimenOrObservationBase> Pager<T> pageByAssociatedTaxon(Class<T> type, Set<TaxonRelationshipEdge> includeRelationships,
305
            Taxon associatedTaxon, Integer maxDepth, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths);
306

    
307
    /**
308
     * Retrieves all {@link FieldUnit}s for the {@link SpecimenOrObservationBase} with the given {@link UUID}.<br>
309
     * @param specimenUuid the UUID of the specimen
310
     * @param propertyPaths the property path
311
     * @return either a collection of FieldUnits this specimen was derived from, the FieldUnit itself
312
     * if this was a FieldUnit or an empty collection if no FieldUnits were found
313
     */
314
    public Collection<FieldUnit> findFieldUnits(UUID specimenUuid, List<String> propertyPaths);
315

    
316
    /**
317
     * Retrieves top most originals for a {@link SpecimenOrObservationBase} in the derivation graph by recursively
318
     * walking all {@link DerivationEvent}s.
319
     * In most cases item in the returned collection will be {@link FieldUnit FieldUnits} but also DerivedUnits are possible, in
320
     * cases where no FieledUnit exists.
321
     *
322
     * @param specimenUuid the UUID of the specimen
323
     * @param propertyPaths the property path
324
     * @return either a collection of root units
325
     */
326
    public Collection<SpecimenOrObservationBase> findRootUnits(UUID specimenUuid, List<String> propertyPaths);
327

    
328
    /**
329
     * @param clazz
330
     * @param queryString
331
     * @param languages
332
     * @param highlightFragments
333
     * @param pageSize
334
     * @param pageNumber
335
     * @param orderHints
336
     * @param propertyPaths
337
     * @return
338
     * @throws CorruptIndexException
339
     * @throws IOException
340
     * @throws ParseException
341
     */
342
    Pager<SearchResult<SpecimenOrObservationBase>> findByFullText(Class<? extends SpecimenOrObservationBase> clazz,
343
            String queryString, Rectangle boundingBox, List<Language> languages, boolean highlightFragments,
344
            Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths)
345
            throws IOException, LuceneParseException;
346
    /**
347
     * See {@link #listByAssociatedTaxon(Class, Set, String, Integer, Integer, Integer, List, List)}
348
     *
349
     * @param type
350
     * @param includeRelationships
351
     * @param associatedTaxon
352
     * @param maxDepth
353
     * @param pageSize
354
     * @param pageNumber
355
     * @param orderHints
356
     * @param propertyPaths
357
     * @return a Pager
358
     */
359
    public <T extends SpecimenOrObservationBase> Pager<T>  pageByAssociatedTaxon(Class<T> type, Set<TaxonRelationshipEdge> includeRelationships,
360
            String taxonUUID, Integer maxDepth, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths);
361

    
362
    /**
363
     * Moves the given {@link Sequence} from one {@link DnaSample} to another
364
     * @param from the DnaSample from which the sequence will be removed
365
     * @param to the DnaSample which to which the sequence will be added
366
     * @param sequence the Sequence to move
367
     * @return <code>true</code> if successfully moved, <code>false</code> otherwise
368
     */
369
    public UpdateResult moveSequence(DnaSample from, DnaSample to, Sequence sequence);
370

    
371

    
372
    /**
373
     * @param fromUuid
374
     * @param toUuid
375
     * @param sequenceUuid
376
     * @return
377
     */
378
    public UpdateResult moveSequence(UUID fromUuid, UUID toUuid, UUID sequenceUuid);
379

    
380
    /**
381
     * Moves the given {@link DerivedUnit} from one {@link SpecimenOrObservationBase} to another.
382
     * @param from the SpecimenOrObservationBase from which the DerivedUnit will be removed
383
     * @param to the SpecimenOrObservationBase to which the DerivedUnit will be added
384
     * @param derivate the DerivedUnit to move
385
     * @return <code>true</code> if successfully moved, <code>false</code> otherwise
386
     */
387
    public UpdateResult moveDerivate(UUID specimenFromUuid, UUID specimenToUuid, UUID derivateUuid);
388

    
389
    /**
390
     * @param from
391
     * @param to
392
     * @param derivate
393
     * @return
394
     */
395
    public boolean moveDerivate(SpecimenOrObservationBase<?> from, SpecimenOrObservationBase<?> to, DerivedUnit derivate);
396

    
397
    /**
398
     * Assembles a {@link FieldUnitDTO} for the given field unit.<br>
399
     *
400
     * @param fieldUnit
401
     * @return a DTO with all the assembled information
402
     */
403
    public FieldUnitDTO assembleFieldUnitDTO(FieldUnit fieldUnit);
404

    
405
    /**
406
     * Assembles a {@link DerivedUnitDTO} for the given derived unit.
407
     * @param derivedUnit
408
     * @return a DTO with all the assembled information
409
     */
410
    public SpecimenOrObservationBaseDTO assembleDerivedUnitDTO(DerivedUnit derivedUnit);
411

    
412
    /**
413
     * Deletes the specified specimen according to the setting in the {@link SpecimenDeleteConfigurator}.<br>
414
     * @param specimen the specimen which shoul be deleted
415
     * @param config specifies options if and how the specimen should be deleted like e.g. including all
416
     * of its children
417
     * @return the {@link DeleteResult} which holds information about the outcome of this operation
418
     */
419
    public DeleteResult delete(SpecimenOrObservationBase<?> specimen, SpecimenDeleteConfigurator config);
420

    
421
    /**
422
     * Deletes the specified specimen belonging to the given {@link UUID}
423
     * according to the setting in the {@link SpecimenDeleteConfigurator}.
424
     *
425
     * @param specimen
426
     *            the specimen which shoul be deleted
427
     * @param config
428
     *            specifies options if and how the specimen should be deleted
429
     *            like e.g. including all of its children
430
     * @return the {@link DeleteResult} which holds information about the
431
     *         outcome of this operation
432
     */
433
    public DeleteResult delete(UUID specimenUuid, SpecimenDeleteConfigurator config);
434

    
435
    /**
436
     * Retrieves all {@link IndividualsAssociation} with the given specimen.<br>
437
     * @param specimen the specimen for which the associations are retrieved
438
     * @param limit
439
     * @param start
440
     * @param orderHints
441
     * @param propertyPaths
442
     * @return collection of all associations
443
     */
444
    public Collection<IndividualsAssociation> listIndividualsAssociations(SpecimenOrObservationBase<?> specimen, Integer limit, Integer start, List<OrderHint> orderHints, List<String> propertyPaths);
445

    
446

    
447
    /**
448
     * Retrieves all taxa linked via {@link IndividualsAssociation} with the given specimen.<br>
449
     * @param specimen the specimen which is linked to the taxa
450
     * @param limit
451
     * @param start
452
     * @param orderHints
453
     * @param propertyPaths
454
     * @return a collection of associated taxa
455
     */
456
    public Collection<TaxonBase<?>> listIndividualsAssociationTaxa(SpecimenOrObservationBase<?> specimen,
457
            Integer limit, Integer start, List<OrderHint> orderHints, List<String> propertyPaths);
458
    /**
459
      * @see #listIndividualsAssociationTaxa(SpecimenOrObservationBase, Integer, Integer, List, List)
460
      */
461
    public Collection<TaxonBase<?>> listIndividualsAssociationTaxa(SpecimenOrObservationBase<?> specimen, boolean includeUnpublished,
462
            Integer limit, Integer start, List<OrderHint> orderHints, List<String> propertyPaths);
463

    
464
    /**
465
     * Retrieves all associated taxa for the given specimen (via type designations, determination, individuals associations)
466
     * @param specimen
467
     * @param limit
468
     * @param start
469
     * @param orderHints
470
     * @param propertyPaths
471
     * @return
472
     */
473
    public Collection<TaxonBase<?>> listAssociatedTaxa(SpecimenOrObservationBase<?> specimen, boolean includeUnpublished,
474
            Integer limit, Integer start, List<OrderHint> orderHints, List<String> propertyPaths);
475
    /**
476
     * @see #listAssociatedTaxa(SpecimenOrObservationBase, Integer, Integer, List, List)axa
477
     */
478
    public Collection<TaxonBase<?>> listAssociatedTaxa(SpecimenOrObservationBase<?> specimen,
479
            Integer limit, Integer start, List<OrderHint> orderHints, List<String> propertyPaths);
480

    
481
    /**
482
     * Retrieves all taxa that the given specimen is determined as
483
     * @param specimen
484
     * @param limit
485
     * @param start
486
     * @param orderHints
487
     * @param propertyPaths
488
     * @return collection of all taxa the given specimen is determined as
489
     */
490
    public Collection<TaxonBase<?>> listDeterminedTaxa(SpecimenOrObservationBase<?> specimen, boolean includeUnpublished,
491
            Integer limit, Integer start, List<OrderHint> orderHints, List<String> propertyPaths);
492
    /**
493
     * @see #listDeterminedTaxa(SpecimenOrObservationBase, Integer, Integer, List, List)
494
     */
495
    public Collection<TaxonBase<?>> listDeterminedTaxa(SpecimenOrObservationBase<?> specimen,
496
            Integer limit, Integer start, List<OrderHint> orderHints, List<String> propertyPaths);
497

    
498
    /**
499
     * Retrieves all {@link DeterminationEvent}s which have the given specimen set as identified unit.
500
     * @param specimen
501
     * @param limit
502
     * @param start
503
     * @param orderHints
504
     * @param propertyPaths
505
     * @return collection of all determination events with the given specimen
506
     */
507
    public Collection<DeterminationEvent> listDeterminationEvents(SpecimenOrObservationBase<?> specimen, Integer limit, Integer start, List<OrderHint> orderHints, List<String> propertyPaths);
508

    
509
    /**
510
     * Retrieves all taxa with a {@link SpecimenTypeDesignation} with the given specimen as a type specimen.
511
     * @param specimen the type specimen
512
     * @param specimen
513
     * @param limit
514
     * @param start
515
     * @param orderHints
516
     * @param propertyPaths
517
     * @return a collection of all taxa where the given specimen is the type specimen
518
     */
519
    public Collection<TaxonBase<?>> listTypeDesignationTaxa(DerivedUnit specimen,
520
            Integer limit, Integer start, List<OrderHint> orderHints, List<String> propertyPaths);
521
    /**
522
     * @see #listTypeDesignationTaxa(DerivedUnit, Integer, Integer, List, List)a
523
     */
524
    public Collection<TaxonBase<?>> listTypeDesignationTaxa(DerivedUnit specimen, boolean includeUnpublished,
525
            Integer limit, Integer start, List<OrderHint> orderHints, List<String> propertyPaths);
526

    
527
    /**
528
     * Retrieves all {@link SpecimenTypeDesignation}s which have the given specimens as a type specimen.
529
     * @param specimens the type specimens
530
     * @param limit
531
     * @param start
532
     * @param orderHints
533
     * @param propertyPaths
534
     * @return map of all designations with the given type specimens
535
     */
536
    public Map<DerivedUnit, Collection<SpecimenTypeDesignation>> listTypeDesignations(Collection<DerivedUnit> specimens, Integer limit, Integer start, List<OrderHint> orderHints, List<String> propertyPaths);
537

    
538
    /**
539
     * Retrieves all {@link SpecimenTypeDesignation}s which have the given specimen as a type specimen.
540
     * @param specimen the type specimen
541
     * @param limit
542
     * @param start
543
     * @param orderHints
544
     * @param propertyPaths
545
     * @return collection of all designations with the given type specimen
546
     */
547
    public Collection<SpecimenTypeDesignation> listTypeDesignations(DerivedUnit specimen, Integer limit, Integer start, List<OrderHint> orderHints, List<String> propertyPaths);
548

    
549
    /**
550
     * Retrieves all {@link DescriptionBase}s that have the given specimen set as described specimen.
551
     * @param specimen the described specimen
552
     * @param limit
553
     * @param start
554
     * @param orderHints
555
     * @param propertyPaths
556
     * @return collection of all descriptions with the given described specimen
557
     */
558
    public Collection<DescriptionBase<?>> listDescriptionsWithDescriptionSpecimen(SpecimenOrObservationBase<?> specimen, Integer limit, Integer start, List<OrderHint> orderHints, List<String> propertyPaths);
559

    
560
    /**
561
     * Gets all description elements that are used for describing the character
562
     * states of the given specimen
563
     *
564
     * @param specimenUuid
565
     *            the specimen {@link UUID} for which the character state description
566
     *            elements should be retrieved
567
     * @return a collection of all character state description elements for this
568
     *         specimen
569
     */
570
    public Collection<DescriptionElementBase> getCharacterDataForSpecimen(UUID specimenUuid);
571

    
572
    /**
573
     * Returns the most significant identifier for the given {@link DerivedUnit}.
574
     * @param derivedUnit the derived unit to check
575
     * @return the identifier string
576
     * @deprecated use {@link DerivedUnit#getMostSignificantIdentifier()} instead
577
     */
578
    @Deprecated
579
    public String getMostSignificantIdentifier(DerivedUnit derivedUnit);
580

    
581
    /**
582
     * Returns the number of specimens that match the given parameters
583
     * <br>
584
     * <b>NOTE - issue #6484:</b> the parameters {@link FindOccurrencesConfigurator#getAssignmentStatus()}
585
     * and {@link FindOccurrencesConfigurator#isRetrieveIndirectlyAssociatedSpecimens()} are not evaluated
586
     * in the count method
587
     * @param clazz the class to match
588
     * @param queryString the queryString to match
589
     * @param type the {@link SpecimenOrObservationType} to match
590
     * @param associatedTaxon the taxon these specimens are in any way associated to via
591
     * determination, type designations, individuals associations, etc.
592
     * @param matchmode determines how the query string should be matched
593
     * @param limit
594
     *            the maximum number of entities returned (can be null to return
595
     *            all entities)
596
     * @param start
597
     * @param orderHints
598
     *            Supports path like <code>orderHints.propertyNames</code> which
599
     *            include *-to-one properties like createdBy.username or
600
     *            authorTeam.persistentTitleCache
601
     * @return the number of found specimens
602
     */
603
    public long countOccurrences(IIdentifiableEntityServiceConfigurator<SpecimenOrObservationBase> config);
604

    
605
    /**
606
     * Return the all {@link SpecimenOrObservationBase}s of the complete
607
     * derivative hierarchy i.e. all parent and child derivatives and the given
608
     * specimen itself.
609
     *
610
     * @param specimen
611
     *            a specimen or observation
612
     * @return the derivative hierarchy as an unordered list of all specimens or observation
613
     */
614
    public List<SpecimenOrObservationBase<?>> getAllHierarchyDerivatives(SpecimenOrObservationBase<?> specimen);
615

    
616
    /**
617
     * Returns all child derivatives of the given specimen.
618
     * @param specimen a specimen or observation
619
     * @return an unordered list of all child derivatives
620
     */
621
    public List<DerivedUnit> getAllChildDerivatives(SpecimenOrObservationBase<?> specimen);
622

    
623
    /**
624
     * Returns all child derivatives of the given specimen.
625
     * @param specimen the UUID of a specimen or observation
626
     * @return an unordered list of all child derivatives
627
     */
628
    public List<DerivedUnit> getAllChildDerivatives(UUID specimenUuid);
629

    
630
    /**
631
     * Returns all {@link FieldUnit}s that are referencing this {@link GatheringEvent}
632
     * @param gatheringEventUuid the {@link UUID} of the gathering event
633
     * @return a list of field units referencing the gathering event
634
     */
635
    public List<FieldUnit> findFieldUnitsForGatheringEvent(UUID gatheringEventUuid);
636

    
637

    
638
    /**
639
     * Returns a list of {@link UuidAndTitleCache} for the specimens found with the
640
     * given configurator
641
     * @param config the configurator for the search
642
     * @return a list of UuidAndTitleCache object
643
     */
644
    @Transactional(readOnly = true)
645
    public Pager<UuidAndTitleCache<SpecimenOrObservationBase>> findByTitleUuidAndTitleCache(
646
            FindOccurrencesConfigurator config);
647

    
648
    /**
649
     * Returns a list of {@link DerivedUnitDTO} for the specimens found with the
650
     * given configurator
651
     * @param config the configurator for the search
652
     * @return a list of {@link DerivedUnitDTO} object
653
     */
654
    @Transactional(readOnly = true)
655
    public List<DerivedUnitDTO> findByTitleDerivedUnitDTO(
656
            FindOccurrencesConfigurator config);
657

    
658

    
659
    /**
660
     * Collects the <code>FieldUnits</code> which are at the root of the derivation event
661
     * graph in which the {@link DerivedUnit} with the specified <code>findByAccessionNumber</code>
662
     * is found.
663
     *
664
     * @deprecated method name unclear and thus replaced by {@link #findByGeneticAccessionNumber(String, List)}
665
     */
666
    @Deprecated
667
    SpecimenOrObservationBaseDTO findByAccessionNumber(String accessionNumberString, List<OrderHint> orderHints);
668

    
669
    /**
670
     * Collects the <code>FieldUnits</code> which are at the root of the derivation event
671
     * graph in which the {@link DnaSample} with the specified <code>accessionNumberString</code>
672
     * is found.
673
     */
674
    SpecimenOrObservationBaseDTO findByGeneticAccessionNumber(String dnaAccessionNumber, List<OrderHint> orderHints);
675

    
676
    /**
677
     * Recursively searches all {@link DerivationEvent}s to find all "originals" ({@link SpecimenOrObservationBase})
678
     * from which this DerivedUnit was derived until all FieldUnits are found.
679
     * <p>
680
     * <b>NOTE:</b> The recursive search still is a bit incomplete and may miss originals in the rare case where a
681
     * derivative has more than one original. (see https://dev.e-taxonomy.eu/redmine/issues/9253)
682
     *
683
     * @param derivedUnitDTO
684
     *      The DerivedUnitDTO to start the search from.
685
     * @param alreadyCollectedSpecimen
686
     *      A map to hold all originals that have been sees during the recursive walk.
687
     * @return
688
     *      The collection of all Field Units that are accessible from the derivative from where the search was started.
689
     */
690
    public Collection<SpecimenOrObservationBaseDTO> findRootUnitDTOs(UUID unitUUID);
691

    
692
    /**
693
     * Finds the units which are associated to a taxon
694
     * (<code>associatedTaxonUuid</code>) and returns all related root units
695
     * with the derivation branches up to the derivatives associated with the
696
     * taxon and the full derivation sub-tree of those.
697
     * <p>
698
     * Requirements as stated in the below linked tickets:
699
     * <ol>
700
     * <li>The derivation trees (derivatives, sub-derivatives,
701
     * sub-sub-derivatives, ....) of each of the root units will be included in
702
     * the result items in
703
     * ({@link SpecimenOrObservationBaseDTO#getDerivatives()})</li>
704
     * <li>.... should contain all derivates of a derivate determined to the
705
     * taxon or its name and all elements should be displayed only once.
706
     * ....</li>
707
     * <li>... also sollen beim DerivateTree eigentlich auch nur die Derivate
708
     * angezeigt werden, die über Taxon Association oder Determination an einem
709
     * Taxon oder Namen hängen und ihre direkten Eltern und Kinder (+
710
     * KindesKinder…).
711
     * <li>Also im Endeffekt muss man die Derivate raus suchen, die eine
712
     * Assoziation zu dem Taxon haben und dann die direkten Vorgänger und die
713
     * Nachfolger finden. Andere Derivate, die von Origin Derivaten abstammen
714
     * würden erstmal nicht dazugehören, außer sie sind ebenfalls mit dem Taxon
715
     * assoziiert....</li>
716
     * <ul>
717
     *
718
     * Related tickets:
719
     *
720
     * <ul>
721
     * <li>https://dev.e-taxonomy.eu/redmine/issues/7599</li>
722
     * <li>https://dev.e-taxonomy.eu/redmine/issues/9216</li>
723
     * </ul>
724
     *
725
     * @param includedRelationships
726
     *  TODO
727
     * @param associatedTaxonUuid
728
     *  The uuid of the taxon for which associated derivatives are to be found.
729
     * @param propertyPaths
730
     *  The bean initialization strategy
731
     * @return
732
     *  The list of root units with fully or partially assembled derivation graph.
733
     */
734
    List<SpecimenOrObservationBaseDTO> listRootUnitDTOsByAssociatedTaxon(Set<TaxonRelationshipEdge> includedRelationships,
735
            UUID associatedTaxonUuid, List<String> propertyPaths);
736

    
737

    
738
    /**
739
     * Lists all root units which are
740
     * associated <b>directly or indirectly</b>with the <code>taxon</code> specified
741
     * as parameter. "Indirectly" means that a sub derivate of the FieldUnit is
742
     * directly associated with the given taxon.
743
     * SpecimenOrObservationBase instances can be associated to taxa in multiple
744
     * ways, all these possible relations are taken into account:
745
     * <ul>
746
     * <li>The {@link IndividualsAssociation} elements in a
747
     * {@link TaxonDescription} contain {@link DerivedUnit}s</li>
748
     * <li>{@link SpecimenTypeDesignation}s may be associated with any
749
     * {@link HomotypicalGroup} related to the specific {@link Taxon}.</li>
750
     * <li>A {@link Taxon} may be referenced by the {@link DeterminationEvent}
751
     * of the {@link SpecimenOrObservationBase}</li>
752
     * </ul>
753
     * Further more there also can be taxa which are associated with the taxon
754
     * in question (parameter associatedTaxon) by {@link TaxonRelationship}s. If
755
     * the parameter <code>includeRelationships</code> is containing elements,
756
     * these according {@TaxonRelationshipType}s and
757
     * directional information will be used to collect further
758
     * {@link SpecimenOrObservationBase} instances found this way.
759
     *
760
     * @param <T>
761
     * @param type
762
     *  Restriction to a specific subtype, may be null.
763
     * @param associatedTaxon
764
     * @param Set<TaxonRelationshipVector> includeRelationships. TaxonRelationships will not be taken into account if this is <code>NULL</code>.
765
     * @param maxDepth TODO
766
     * @param pageSize
767
     * @param pageNumber
768
     * @param orderHints
769
     * @param propertyPaths
770
     * @return
771
     */
772
    public <T extends SpecimenOrObservationBase> Collection<T> listRootUnitsByAssociatedTaxon(Class<T> type, Taxon associatedTaxon, List<OrderHint> orderHints, List<String> propertyPaths);
773

    
774

    
775
    /**
776
     * See {@link #listFieldUnitsByAssociatedTaxon(Set, Taxon, Integer, Integer, Integer, List, List)}
777
     */
778
    public <T extends SpecimenOrObservationBase> Pager<T> pageRootUnitsByAssociatedTaxon(Class<T> type, Set<TaxonRelationshipEdge> includeRelationships,
779
            Taxon associatedTaxon, Integer maxDepth, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths);
780

    
781

    
782

    
783
    public List<Point> findPointsForFieldUnitList(List<UUID> fieldUnitUuids);
784

    
785
    /**
786
     * Load the FieldUnitDTO for the given <code>derivedUnitUuid</code> with all intermediate derivatives and {@link eu.etaxonomy.cdm.api.service.dto.GatheringEventDTO}
787

    
788
     * @param derivedUnitUuid
789
     * @return
790
     */
791
    FieldUnitDTO loadFieldUnitDTO(UUID derivedUnitUuid);
792

    
793
    Pager<MediaDTO> getMediaDTOs(SpecimenOrObservationBase<?> occurence, Integer pageSize, Integer pageNumber);
794

    
795
}
(46-46/97)