Project

General

Profile

Download (37.2 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.springframework.transaction.annotation.Transactional;
21

    
22
import eu.etaxonomy.cdm.api.facade.DerivedUnitFacade;
23
import eu.etaxonomy.cdm.api.facade.DerivedUnitFacadeNotSupportedException;
24
import eu.etaxonomy.cdm.api.service.config.FindOccurrencesConfigurator;
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.DerivedUnitDTO;
28
import eu.etaxonomy.cdm.api.service.dto.FieldUnitDTO;
29
import eu.etaxonomy.cdm.api.service.dto.MediaDTO;
30
import eu.etaxonomy.cdm.api.service.dto.RectangleDTO;
31

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
283

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

    
290

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

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

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

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

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

    
372

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

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

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

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

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

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

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

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

    
447

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

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

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

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

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

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

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

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

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

    
573
    /**
574
     * Returns the most significant identifier for the given {@link DerivedUnit}.
575
     * @param derivedUnit the derived unit to check
576
     * @return the identifier string
577
     */
578

    
579
    public String getMostSignificantIdentifier(UUID 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
	Pager<Media> getMediaInHierarchy(SpecimenOrObservationBase<?> rootOccurence, boolean collectOriginalMedia, boolean collectDerivativeMedia,
796
			Integer pageSize, Integer pageNumber, List<String> propertyPaths);
797

    
798
}
(44-44/95)