Project

General

Profile

Revision 949cae00

ID949cae00125ee55eeb1915014a21302e03cdb18a
Parent c3f658e9

Added by Patrick Plitzner 11 months ago

ref #7750 Adapt services to new AssignmentStatus

View differences:

cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/persistence/dao/hibernate/occurrence/OccurrenceDaoHibernateImpl.java
58 58
import eu.etaxonomy.cdm.persistence.dao.occurrence.IOccurrenceDao;
59 59
import eu.etaxonomy.cdm.persistence.dto.SpecimenNodeWrapper;
60 60
import eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache;
61
import eu.etaxonomy.cdm.persistence.query.AssignmentStatus;
61 62
import eu.etaxonomy.cdm.persistence.query.MatchMode;
62 63
import eu.etaxonomy.cdm.persistence.query.OrderHint;
63 64

  
......
298 299
    @Override
299 300
    public <T extends SpecimenOrObservationBase> List<UuidAndTitleCache<SpecimenOrObservationBase>> findOccurrencesUuidAndTitleCache(
300 301
            Class<T> clazz, String queryString, String significantIdentifier, SpecimenOrObservationType recordBasis,
301
            Taxon associatedTaxon, TaxonName associatedTaxonName, MatchMode matchmode, Integer limit, Integer start,
302
            Taxon associatedTaxon, TaxonName associatedTaxonName,
303
            Set<AssignmentStatus> assignmentStates, MatchMode matchmode, Integer limit, Integer start,
302 304
            List<OrderHint> orderHints) {
303 305
        Criteria criteria = createFindOccurrenceCriteria(clazz, queryString, significantIdentifier, recordBasis,
304
                associatedTaxon, associatedTaxonName, matchmode, limit, start, orderHints, null);
306
                associatedTaxon, associatedTaxonName, assignmentStates, matchmode, limit, start, orderHints, null);
305 307
        if(criteria!=null){
306 308
            ProjectionList projectionList = Projections.projectionList();
307 309
            projectionList.add(Projections.property("uuid"));
......
324 326
    @Override
325 327
    public <T extends SpecimenOrObservationBase> List<T> findOccurrences(Class<T> clazz, String queryString,
326 328
            String significantIdentifier, SpecimenOrObservationType recordBasis, Taxon associatedTaxon, TaxonName associatedTaxonName,
329
            Set<AssignmentStatus> assignmentStates,
327 330
            MatchMode matchmode, Integer limit, Integer start, List<OrderHint> orderHints, List<String> propertyPaths) {
328 331

  
329 332
        Criteria criteria = createFindOccurrenceCriteria(clazz, queryString, significantIdentifier, recordBasis,
330
                associatedTaxon, associatedTaxonName, matchmode, limit, start, orderHints, propertyPaths);
333
                associatedTaxon, associatedTaxonName, assignmentStates, matchmode, limit, start, orderHints, propertyPaths);
331 334
        if(criteria!=null){
332 335
            @SuppressWarnings("unchecked")
333 336
            List<T> results = criteria.list();
......
338 341
        }
339 342
    }
340 343

  
341
    private <T extends SpecimenOrObservationBase> Criteria createFindOccurrenceCriteria(Class<T> clazz, String queryString,
342
            String significantIdentifier, SpecimenOrObservationType recordBasis, Taxon associatedTaxon, TaxonName associatedTaxonName, MatchMode matchmode, Integer limit,
343
            Integer start, List<OrderHint> orderHints, List<String> propertyPaths) {
344
    private <T extends SpecimenOrObservationBase> Criteria createFindOccurrenceCriteria(Class<T> clazz,
345
            String queryString, String significantIdentifier, SpecimenOrObservationType recordBasis,
346
            Taxon associatedTaxon, TaxonName associatedTaxonName, Set<AssignmentStatus> assignmentStates,
347
            MatchMode matchmode, Integer limit, Integer start,
348
            List<OrderHint> orderHints, List<String> propertyPaths) {
344 349
        Criteria criteria = null;
345 350

  
346 351
        if(clazz == null) {
......
386 391
        }
387 392
        criteria.add(Restrictions.in("recordBasis", typeAndSubtypes));
388 393

  
394
        if(assignmentStates==null
395
                ||assignmentStates.contains(AssignmentStatus.INDIVIDUALS_ASSOCIATION)
396
                ||assignmentStates.contains(AssignmentStatus.DETERMINATION)
397
                ||assignmentStates.contains(AssignmentStatus.TYPE_DESIGNATION)
398
                ){
389 399
        Set<UUID> associationUuids = new HashSet<UUID>();
390
        //taxon associations
391
        if(associatedTaxon!=null){
392
            List<UuidAndTitleCache<SpecimenOrObservationBase>> associatedTaxaList = listUuidAndTitleCacheByAssociatedTaxon(clazz, associatedTaxon, limit, start, orderHints);
393
            if(associatedTaxaList!=null){
394
                for (UuidAndTitleCache<SpecimenOrObservationBase> uuidAndTitleCache : associatedTaxaList) {
395
                    associationUuids.add(uuidAndTitleCache.getUuid());
400
            //taxon associations
401
            if(associatedTaxon!=null){
402
                List<UuidAndTitleCache<SpecimenOrObservationBase>> associatedTaxaList = listUuidAndTitleCacheByAssociatedTaxon(clazz, associatedTaxon, assignmentStates, limit, start, orderHints);
403
                if(associatedTaxaList!=null){
404
                    for (UuidAndTitleCache<SpecimenOrObservationBase> uuidAndTitleCache : associatedTaxaList) {
405
                        associationUuids.add(uuidAndTitleCache.getUuid());
406
                    }
396 407
                }
397 408
            }
398
        }
399
        //taxon name associations
400
        else if(associatedTaxonName!=null){
401
            List<? extends SpecimenOrObservationBase> associatedTaxaList = listByAssociatedTaxonName(clazz, associatedTaxonName, limit, start, orderHints, propertyPaths);
402
            if(associatedTaxaList!=null){
403
                for (SpecimenOrObservationBase<?> specimenOrObservationBase : associatedTaxaList) {
404
                    associationUuids.add(specimenOrObservationBase.getUuid());
409
            //taxon name associations
410
            else if(associatedTaxonName!=null){
411
                List<? extends SpecimenOrObservationBase> associatedTaxaList = listByAssociatedTaxonName(clazz, associatedTaxonName, limit, start, orderHints, propertyPaths);
412
                if(associatedTaxaList!=null){
413
                    for (SpecimenOrObservationBase<?> specimenOrObservationBase : associatedTaxaList) {
414
                        associationUuids.add(specimenOrObservationBase.getUuid());
415
                    }
405 416
                }
406 417
            }
407
        }
408
        if(associatedTaxon!=null || associatedTaxonName!=null){
409
            if(!associationUuids.isEmpty()){
410
                criteria.add(Restrictions.in("uuid", associationUuids));
411
            }
412
            else{
413
                return null;
418
            if(associatedTaxon!=null || associatedTaxonName!=null){
419
                if(!associationUuids.isEmpty()){
420
                    criteria.add(Restrictions.in("uuid", associationUuids));
421
                }
422
                else{
423
                    return null;
424
                }
414 425
            }
415 426
        }
416 427
        if(limit != null) {
......
432 443
    @Override
433 444
    public <T extends SpecimenOrObservationBase> long countOccurrences(Class<T> clazz, String queryString,
434 445
            String significantIdentifier, SpecimenOrObservationType recordBasis, Taxon associatedTaxon, TaxonName associatedTaxonName,
446
            Set<AssignmentStatus> assignmentStates,
435 447
            MatchMode matchmode, Integer limit, Integer start, List<OrderHint> orderHints, List<String> propertyPaths) {
436 448

  
437 449
        Criteria criteria = createFindOccurrenceCriteria(clazz, queryString, significantIdentifier, recordBasis,
438
                associatedTaxon, associatedTaxonName, matchmode, limit, start, orderHints, propertyPaths);
450
                associatedTaxon, associatedTaxonName, assignmentStates, matchmode, limit, start, orderHints, propertyPaths);
439 451

  
440 452
        if(criteria!=null){
441 453
            criteria.setProjection(Projections.rowCount());
......
626 638

  
627 639
    @Override
628 640
    public Collection<SpecimenNodeWrapper> listUuidAndTitleCacheByAssociatedTaxon(List<UUID> taxonNodeUuids,
641
            Set<AssignmentStatus> assignmentStates,
629 642
            Integer limit, Integer start){
630 643

  
631 644
        Collection<SpecimenNodeWrapper> wrappers = new HashSet<>();
......
639 652

  
640 653
    @Override
641 654
    public <T extends SpecimenOrObservationBase> List<UuidAndTitleCache<SpecimenOrObservationBase>> listUuidAndTitleCacheByAssociatedTaxon(Class<T> clazz, Taxon associatedTaxon,
642
            Integer limit, Integer start, List<OrderHint> orderHints){
643
        Query query = createSpecimenQuery("sob.uuid, sob.id, sob.titleCache", clazz, associatedTaxon, limit, start, orderHints, null);
655
            Set<AssignmentStatus> assignmentStates, Integer limit, Integer start, List<OrderHint> orderHints){
656
        Query query = createSpecimenQuery("sob.uuid, sob.id, sob.titleCache", clazz, associatedTaxon, assignmentStates, limit, start, orderHints, null);
644 657
        if(query==null){
645 658
            return Collections.emptyList();
646 659
        }
......
655 668

  
656 669
    @Override
657 670
    public <T extends SpecimenOrObservationBase> List<T> listByAssociatedTaxon(Class<T> clazz,
658
            Taxon associatedTaxon, Integer limit, Integer start, List<OrderHint> orderHints, List<String> propertyPaths) {
659
        Query query = createSpecimenQuery("sob", clazz, associatedTaxon, limit, start, orderHints, propertyPaths);
671
            Taxon associatedTaxon, Set<AssignmentStatus> assignmentStates, Integer limit, Integer start, List<OrderHint> orderHints, List<String> propertyPaths) {
672
        Query query = createSpecimenQuery("sob", clazz, associatedTaxon, assignmentStates, limit, start, orderHints, propertyPaths);
660 673
        if(query==null){
661 674
            return Collections.emptyList();
662 675
        }
......
667 680
    }
668 681

  
669 682
    private <T extends SpecimenOrObservationBase> Query createSpecimenQuery(String select, Class<T> clazz,
670
            Taxon associatedTaxon, Integer limit, Integer start, List<OrderHint> orderHints, List<String> propertyPaths){
683
            Taxon associatedTaxon, Set<AssignmentStatus> assignmentStates, Integer limit, Integer start, List<OrderHint> orderHints, List<String> propertyPaths){
671 684
        Set<SpecimenOrObservationBase> setOfAll = new HashSet<>();
672 685
        Set<Integer> setOfAllIds = new HashSet<>();
673 686

  
674
        Criteria criteria = null;
675
        if(clazz == null) {
676
            criteria = getSession().createCriteria(type, "specimen");
677
        } else {
678
            criteria = getSession().createCriteria(clazz, "specimen");
687
        if(assignmentStates==null){
688
            assignmentStates = new HashSet<>();
689
            assignmentStates.add(AssignmentStatus.INDIVIDUALS_ASSOCIATION);
690
            assignmentStates.add(AssignmentStatus.DETERMINATION);
691
            assignmentStates.add(AssignmentStatus.TYPE_DESIGNATION);
692
            assignmentStates.add(AssignmentStatus.NONE);
679 693
        }
680 694

  
681
        Disjunction determinationOr = Restrictions.disjunction();
695
        if(assignmentStates.contains(AssignmentStatus.DETERMINATION)){
696
            Criteria criteria = null;
697
            if(clazz == null) {
698
                criteria = getSession().createCriteria(type, "specimen");
699
            } else {
700
                criteria = getSession().createCriteria(clazz, "specimen");
701
            }
702

  
703
            Disjunction determinationOr = Restrictions.disjunction();
682 704

  
683
        // A Taxon may be referenced by the DeterminationEvent of the SpecimenOrObservationBase
684
        Criteria determinationsCriteria = criteria.createCriteria("determinations");
705
            // A Taxon may be referenced by the DeterminationEvent of the SpecimenOrObservationBase
706
            Criteria determinationsCriteria = criteria.createCriteria("determinations");
685 707

  
686
        determinationOr.add(Restrictions.eq("taxon", associatedTaxon));
687
        //check also for synonyms
688
        for (Synonym synonym : associatedTaxon.getSynonyms()) {
689
            determinationOr.add(Restrictions.eq("taxon", synonym));
690
        }
708
            determinationOr.add(Restrictions.eq("taxon", associatedTaxon));
709
            //check also for synonyms
710
            for (Synonym synonym : associatedTaxon.getSynonyms()) {
711
                determinationOr.add(Restrictions.eq("taxon", synonym));
712
            }
691 713

  
692
        //check also for name determinations
693
        determinationOr.add(Restrictions.eq("taxonName", associatedTaxon.getName()));
694
        for (TaxonName synonymName : associatedTaxon.getSynonymNames()) {
695
            determinationOr.add(Restrictions.eq("taxonName", synonymName));
696
        }
714
            //check also for name determinations
715
            determinationOr.add(Restrictions.eq("taxonName", associatedTaxon.getName()));
716
            for (TaxonName synonymName : associatedTaxon.getSynonymNames()) {
717
                determinationOr.add(Restrictions.eq("taxonName", synonymName));
718
            }
697 719

  
698
        determinationsCriteria.add(determinationOr);
720
            determinationsCriteria.add(determinationOr);
699 721

  
700
        if(limit != null) {
701
            if(start != null) {
702
                criteria.setFirstResult(start);
703
            } else {
704
                criteria.setFirstResult(0);
722
            if(limit != null) {
723
                if(start != null) {
724
                    criteria.setFirstResult(start);
725
                } else {
726
                    criteria.setFirstResult(0);
727
                }
728
                criteria.setMaxResults(limit);
705 729
            }
706
            criteria.setMaxResults(limit);
707
        }
708
        criteria.setProjection(Projections.property("id"));
730
            criteria.setProjection(Projections.property("id"));
709 731

  
710
        addOrder(criteria,orderHints);
732
            addOrder(criteria,orderHints);
711 733

  
712
        @SuppressWarnings("unchecked")
713
        List<Integer> detResults = criteria.list();
714
        setOfAllIds.addAll(detResults);
734
            @SuppressWarnings("unchecked")
735
            List<Integer> detResults = criteria.list();
736
            setOfAllIds.addAll(detResults);
737
        }
715 738

  
716
        // The IndividualsAssociation elements in a TaxonDescription contain DerivedUnits
717
        setOfAllIds.addAll(descriptionDao.getIndividualAssociationSpecimenIDs(
718
                associatedTaxon.getUuid(), null, null, 0, null));
739
        if(assignmentStates.contains(AssignmentStatus.INDIVIDUALS_ASSOCIATION)){
740
            // The IndividualsAssociation elements in a TaxonDescription contain DerivedUnits
741
            setOfAllIds.addAll(descriptionDao.getIndividualAssociationSpecimenIDs(
742
                    associatedTaxon.getUuid(), null, null, 0, null));
743
        }
719 744

  
720 745

  
721
        // SpecimenTypeDesignations may be associated with the TaxonName.
722
        setOfAllIds.addAll(taxonNameDao.getTypeSpecimenIdsForTaxonName(
723
                associatedTaxon.getName(), null, null, null));
746
        if(assignmentStates.contains(AssignmentStatus.TYPE_DESIGNATION)){
747
            // SpecimenTypeDesignations may be associated with the TaxonName.
748
            setOfAllIds.addAll(taxonNameDao.getTypeSpecimenIdsForTaxonName(
749
                    associatedTaxon.getName(), null, null, null));
724 750

  
725
        // SpecimenTypeDesignations may be associated with any HomotypicalGroup related to the specific Taxon.
726
        //TODO adapt to set of ids
727
        for(HomotypicalGroup homotypicalGroup :  associatedTaxon.getHomotypicSynonymyGroups()) {
728
            List<SpecimenTypeDesignation> byHomotypicalGroup = homotypicalGroupDao.getTypeDesignations(homotypicalGroup, SpecimenTypeDesignation.class, null, null, 0, null);
729
            for (SpecimenTypeDesignation specimenTypeDesignation : byHomotypicalGroup) {
730
                setOfAll.add(specimenTypeDesignation.getTypeSpecimen());
751
            // SpecimenTypeDesignations may be associated with any HomotypicalGroup related to the specific Taxon.
752
            //TODO adapt to set of ids
753
            for(HomotypicalGroup homotypicalGroup :  associatedTaxon.getHomotypicSynonymyGroups()) {
754
                List<SpecimenTypeDesignation> byHomotypicalGroup = homotypicalGroupDao.getTypeDesignations(homotypicalGroup, SpecimenTypeDesignation.class, null, null, 0, null);
755
                for (SpecimenTypeDesignation specimenTypeDesignation : byHomotypicalGroup) {
756
                    setOfAll.add(specimenTypeDesignation.getTypeSpecimen());
757
                }
731 758
            }
732 759
        }
733 760

  
cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/persistence/dao/occurrence/IOccurrenceDao.java
8 8

  
9 9
import java.util.Collection;
10 10
import java.util.List;
11
import java.util.Set;
11 12
import java.util.UUID;
12 13

  
13 14
import org.springframework.dao.DataAccessException;
......
34 35
import eu.etaxonomy.cdm.persistence.dao.initializer.IBeanInitializer;
35 36
import eu.etaxonomy.cdm.persistence.dto.SpecimenNodeWrapper;
36 37
import eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache;
38
import eu.etaxonomy.cdm.persistence.query.AssignmentStatus;
37 39
import eu.etaxonomy.cdm.persistence.query.MatchMode;
38 40
import eu.etaxonomy.cdm.persistence.query.OrderHint;
39 41

  
......
112 114
     *            etc.
113 115
     * @param associatedTaxonName
114 116
     *            the taxon name that the specimens have been determined as
117
     * @param assignmentStates set of {@link AssignmentStatus} to determine how the
118
     * specimen is linked to the taxon:
119
     * <ul>
120
     * <li>IndividualsAssociation</li>
121
     * <li>type designation</li>
122
     * <li>determination</li>
123
     * </ul>
115 124
     * @param matchmode
116 125
     *            determines how the query string should be matched
117 126
     * @param limit
......
127 136
     */
128 137
    public <T extends SpecimenOrObservationBase> List<T> findOccurrences(Class<T> clazz, String queryString,
129 138
            String significantIdentifier, SpecimenOrObservationType type, Taxon determinedAs,
130
            TaxonName associatedTaxonName, MatchMode matchmode, Integer limit, Integer start,
139
            TaxonName associatedTaxonName, Set<AssignmentStatus> assignmentStates, MatchMode matchmode, Integer limit, Integer start,
131 140
            List<OrderHint> orderHints, List<String> propertyPaths);
132 141

  
133 142
    /**
......
148 157
    public <T extends SpecimenOrObservationBase> List<UuidAndTitleCache<SpecimenOrObservationBase>> findOccurrencesUuidAndTitleCache(
149 158
            Class<T> clazz, String queryString,
150 159
            String significantIdentifier, SpecimenOrObservationType type, Taxon determinedAs,
151
            TaxonName associatedTaxonName, MatchMode matchmode, Integer limit, Integer start,
160
            TaxonName associatedTaxonName,
161
            Set<AssignmentStatus> assignmentStates,
162
            MatchMode matchmode, Integer limit, Integer start,
152 163
            List<OrderHint> orderHints);
153 164

  
154 165
    /**
......
170 181
     *            etc.
171 182
     * @param associatedTaxonName
172 183
     *            the taxon name that the specimens have been determined as
184
     * @param assignmentStates set of {@link AssignmentStatus} to determine how the
185
     * specimen is linked to the taxon:
186
     * <ul>
187
     * <li>IndividualsAssociation</li>
188
     * <li>type designation</li>
189
     * <li>determination</li>
190
     * </ul>
173 191
     * @param matchmode
174 192
     *            determines how the query string should be matched
175 193
     * @param limit
......
184 202
     */
185 203
    public <T extends SpecimenOrObservationBase> long countOccurrences(Class<T> clazz, String queryString,
186 204
            String significantIdentifier, SpecimenOrObservationType recordBasis, Taxon associatedTaxon,
187
            TaxonName associatedTaxonName, MatchMode matchmode, Integer limit, Integer start,
205
            TaxonName associatedTaxonName,
206
            Set<AssignmentStatus> assignmentStates, MatchMode matchmode, Integer limit, Integer start,
188 207
            List<OrderHint> orderHints, List<String> propertyPaths);
189 208

  
190 209
	/**
......
287 306
	 * @param <T>
288 307
	 * @param type
289 308
	 * @param associatedTaxon
309
	 * @param assignmentStates set of {@link AssignmentStatus} to determine how the
310
     * specimen is linked to the taxon:
311
     * <ul>
312
     * <li>IndividualsAssociation</li>
313
     * <li>type designation</li>
314
     * <li>determination</li>
315
     * </ul>
290 316
	 * @param limit
291 317
	 * @param start
292 318
	 * @param orderHints
......
294 320
	 * @return
295 321
	 */
296 322
	public <T extends SpecimenOrObservationBase> List<T> listByAssociatedTaxon(Class<T> type, Taxon associatedTaxon,
323
	        Set<AssignmentStatus> assignmentStates,
297 324
			Integer limit, Integer start, List<OrderHint> orderHints, List<String> propertyPaths);
298 325

  
299 326
	/**
......
307 334
	 * @return
308 335
	 */
309 336
	public <T extends SpecimenOrObservationBase> List<UuidAndTitleCache<SpecimenOrObservationBase>> listUuidAndTitleCacheByAssociatedTaxon(Class<T> type, Taxon associatedTaxon,
310
	        Integer limit, Integer start, List<OrderHint> orderHints);
337
	        Set<AssignmentStatus> assignmentStates, Integer limit, Integer start, List<OrderHint> orderHints);
311 338

  
312 339
    /**
313 340
     * The method will search for specimen associated with the taxon nodes.<br>
314
     * It will search for 3 possible association types:
341
     * It will search for 3 possible association types depending on the assignemnt states:
315 342
     * : <br>
316 343
     *  - via IndividualAssociations of the taxon<br>
317 344
     *  - via TypeDesignations of the taxon name<br>
......
320 347
     *  (more are covered in
321 348
     * {@link IOccurrenceDao#findOccurrences(Class, String, String, SpecimenOrObservationType, Taxon, TaxonName, MatchMode, Integer, Integer, List, List)}
322 349
     * @param taxonNodeUuids a list of {@link UUID}s of the taxon nodes
350
     * @param assignmentStates set of {@link AssignmentStatus} to determine how the
351
     * specimen is linked to the taxon:
352
     * <ul>
353
     * <li>IndividualsAssociation</li>
354
     * <li>type designation</li>
355
     * <li>determination</li>
356
     * </ul>
323 357
     * @param limit
324 358
     * @param start
325 359
     * @return a collection of {@link SpecimenNodeWrapper} containing the {@link TaxonNode}
326 360
     * and the corresponding {@link UuidAndTitleCache}  object for the specimen found for this taxon node
327 361
     */
328 362
	public Collection<SpecimenNodeWrapper> listUuidAndTitleCacheByAssociatedTaxon(List<UUID> taxonNodeUuids,
329
            Integer limit, Integer start);
363
	        Set<AssignmentStatus> assignmentStates, Integer limit, Integer start);
330 364

  
331 365
    /**
332 366
     * Retrieves all {@link IndividualsAssociation} with the given specimen.<br>
cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/persistence/query/AssignmentStatus.java
11 11
import java.util.UUID;
12 12

  
13 13
/**
14
 * Enum to indicate if the retrieved specimens are associated to a taxon. Default is <code>ALL_SPECIMEN</code>.<br>
14
 * Enum to indicate how the retrieved specimens are associated to a taxon.
15 15
 * <br>
16 16
 * <b>Note:</b>This status is <b>ignored</b> if the configurator has either a name
17 17
 * or a taxon set via {@link #setAssociatedTaxonNameUuid(UUID)} or
......
20 20
 * @author pplitzner
21 21
 */
22 22
public enum AssignmentStatus{
23
    ALL_SPECIMENS,
24
    ASSIGNED_SPECIMENS,
25
    UNASSIGNED_SPECIMENS
23
    INDIVIDUALS_ASSOCIATION,
24
    TYPE_DESIGNATION,
25
    DETERMINATION,
26
    NONE
26 27
}
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/OccurrenceServiceImpl.java
115 115
import eu.etaxonomy.cdm.persistence.dao.occurrence.IOccurrenceDao;
116 116
import eu.etaxonomy.cdm.persistence.dto.SpecimenNodeWrapper;
117 117
import eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache;
118
import eu.etaxonomy.cdm.persistence.query.AssignmentStatus;
119 118
import eu.etaxonomy.cdm.persistence.query.OrderHint;
120 119
import eu.etaxonomy.cdm.strategy.cache.common.IIdentifiableEntityCacheStrategy;
121 120
import eu.etaxonomy.cdm.strategy.cache.common.IdentifiableEntityDefaultCacheStrategy;
......
360 359
    @Override
361 360
    public Collection<SpecimenNodeWrapper> listUuidAndTitleCacheByAssociatedTaxon(List<UUID> taxonNodeUuids,
362 361
            Integer limit, Integer start) {
363
        return dao.listUuidAndTitleCacheByAssociatedTaxon(taxonNodeUuids, limit, start);
362
        return dao.listUuidAndTitleCacheByAssociatedTaxon(taxonNodeUuids, null, limit, start);
364 363
        }
365 364

  
366 365
    @Override
......
804 803
        taxa.add(associatedTaxon);
805 804

  
806 805
        for (Taxon taxon : taxa) {
807
            List<T> perTaxonOccurrences = dao.listByAssociatedTaxon(type, taxon, null, null, orderHints, propertyPaths);
806
            List<T> perTaxonOccurrences = dao.listByAssociatedTaxon(type, taxon, null, null, null, orderHints, propertyPaths);
808 807
            for (SpecimenOrObservationBase<?> o : perTaxonOccurrences) {
809 808
                occurrenceIds.add(o.getId());
810 809
            }
......
852 851
        taxa.add(associatedTaxon);
853 852

  
854 853
        for (Taxon taxon : taxa) {
855
            List<SpecimenOrObservationBase> perTaxonOccurrences = dao.listByAssociatedTaxon(null,taxon, null, null, null, null);
854
            List<SpecimenOrObservationBase> perTaxonOccurrences = dao.listByAssociatedTaxon(null, taxon, null, null, null, null, null);
856 855
            for (SpecimenOrObservationBase<?> o : perTaxonOccurrences) {
857 856
                if (o.isInstanceOf(DerivedUnit.class)){
858 857
                    DerivedUnit derivedUnit;
......
1552 1551
             * significantly slow down this method as we have to retreive the entities instead of
1553 1552
             * the just the amount.
1554 1553
             */
1555
            if(occurrenceConfig.isRetrieveIndirectlyAssociatedSpecimens() || !occurrenceConfig.getAssignmentStatus().equals(AssignmentStatus.ALL_SPECIMENS)){
1554
            if(occurrenceConfig.isRetrieveIndirectlyAssociatedSpecimens() || !occurrenceConfig.getAssignmentStates().isEmpty()){
1556 1555
                List<SpecimenOrObservationBase> occurrences = new ArrayList<>();
1557 1556
                occurrences.addAll(dao.findOccurrences(occurrenceConfig.getClazz(),
1558 1557
                        occurrenceConfig.getTitleSearchStringSqlized(), occurrenceConfig.getSignificantIdentifier(),
1559
                        occurrenceConfig.getSpecimenType(), taxon, taxonName, occurrenceConfig.getMatchMode(), null, null,
1558
                        occurrenceConfig.getSpecimenType(), taxon, taxonName, occurrenceConfig.getAssignmentStates(),
1559
                        occurrenceConfig.getMatchMode(), null, null,
1560 1560
                        occurrenceConfig.getOrderHints(), occurrenceConfig.getPropertyPaths()));
1561 1561
                occurrences = filterOccurencesByAssignmentAndHierarchy(occurrenceConfig, occurrences, taxon, taxonName);
1562 1562
                return occurrences.size();
......
1564 1564

  
1565 1565
            return dao.countOccurrences(occurrenceConfig.getClazz(),
1566 1566
                    occurrenceConfig.getTitleSearchStringSqlized(), occurrenceConfig.getSignificantIdentifier(),
1567
                    occurrenceConfig.getSpecimenType(), taxon, taxonName, occurrenceConfig.getMatchMode(), null, null,
1567
                    occurrenceConfig.getSpecimenType(), taxon, taxonName, occurrenceConfig.getAssignmentStates(),
1568
                    occurrenceConfig.getMatchMode(), null, null,
1568 1569
                    occurrenceConfig.getOrderHints(), occurrenceConfig.getPropertyPaths());
1569 1570
        }
1570 1571
        else{
......
1589 1590
        }
1590 1591
        occurrences.addAll(dao.findOccurrencesUuidAndTitleCache(config.getClazz(),
1591 1592
                config.getTitleSearchString(), config.getSignificantIdentifier(),
1592
                config.getSpecimenType(), taxon, taxonName, config.getMatchMode(), null, null,
1593
                config.getSpecimenType(), taxon, taxonName, config.getAssignmentStates(),
1594
                config.getMatchMode(), null, null,
1593 1595
                config.getOrderHints()));
1594 1596

  
1595 1597
        return new DefaultPagerImpl<>(config.getPageNumber(), occurrences.size(), config.getPageSize(), occurrences);
......
1614 1616
            }
1615 1617
            List<? extends SpecimenOrObservationBase> foundOccurrences = dao.findOccurrences(occurrenceConfig.getClazz(),
1616 1618
                    occurrenceConfig.getTitleSearchString(), occurrenceConfig.getSignificantIdentifier(),
1617
                    occurrenceConfig.getSpecimenType(), taxon, taxonName, occurrenceConfig.getMatchMode(), null, null,
1619
                    occurrenceConfig.getSpecimenType(), taxon, taxonName, occurrenceConfig.getAssignmentStates(),
1620
                    occurrenceConfig.getMatchMode(), null, null,
1618 1621
                    occurrenceConfig.getOrderHints(), occurrenceConfig.getPropertyPaths());
1619 1622
            occurrences.addAll(foundOccurrences);
1620 1623
            occurrences = filterOccurencesByAssignmentAndHierarchy(occurrenceConfig, occurrences, taxon, taxonName);
......
1627 1630
    private List<SpecimenOrObservationBase> filterOccurencesByAssignmentAndHierarchy(
1628 1631
            FindOccurrencesConfigurator occurrenceConfig, List<SpecimenOrObservationBase> occurrences, Taxon taxon,
1629 1632
            TaxonName taxonName) {
1630
        //filter out (un-)assigned specimens
1631
        if(taxon==null && taxonName==null){
1632
            AssignmentStatus assignmentStatus = occurrenceConfig.getAssignmentStatus();
1633
            List<SpecimenOrObservationBase> specimenWithAssociations = new ArrayList<>();
1634
            if(!assignmentStatus.equals(AssignmentStatus.ALL_SPECIMENS)){
1635
                for (SpecimenOrObservationBase specimenOrObservationBase : occurrences) {
1636
                    boolean includeUnpublished = true;  //TODO not sure if this is correct, maybe we have to propagate publish flag to higher methods.
1637
                    Collection<TaxonBase<?>> associatedTaxa = listAssociatedTaxa(specimenOrObservationBase,
1638
                            includeUnpublished, null, null, null, null);
1639
                    if(!associatedTaxa.isEmpty()){
1640
                        specimenWithAssociations.add(specimenOrObservationBase);
1641
                    }
1642
                }
1643
            }
1644
            if(assignmentStatus.equals(AssignmentStatus.UNASSIGNED_SPECIMENS)){
1645
                occurrences.removeAll(specimenWithAssociations);
1646
            }
1647
            if(assignmentStatus.equals(AssignmentStatus.ASSIGNED_SPECIMENS)){
1648
                occurrences = new ArrayList<>(specimenWithAssociations);
1649
            }
1650
        }
1633
//        //filter out (un-)assigned specimens
1634
//        if(taxon==null && taxonName==null){
1635
//            AssignmentStatus assignmentStatus = occurrenceConfig.getAssignmentStatus();
1636
//            List<SpecimenOrObservationBase> specimenWithAssociations = new ArrayList<>();
1637
//            if(!assignmentStatus.equals(AssignmentStatus.ALL_SPECIMENS)){
1638
//                for (SpecimenOrObservationBase specimenOrObservationBase : occurrences) {
1639
//                    boolean includeUnpublished = true;  //TODO not sure if this is correct, maybe we have to propagate publish flag to higher methods.
1640
//                    Collection<TaxonBase<?>> associatedTaxa = listAssociatedTaxa(specimenOrObservationBase,
1641
//                            includeUnpublished, null, null, null, null);
1642
//                    if(!associatedTaxa.isEmpty()){
1643
//                        specimenWithAssociations.add(specimenOrObservationBase);
1644
//                    }
1645
//                }
1646
//            }
1647
//            if(assignmentStatus.equals(AssignmentStatus.UNASSIGNED_SPECIMENS)){
1648
//                occurrences.removeAll(specimenWithAssociations);
1649
//            }
1650
//            if(assignmentStatus.equals(AssignmentStatus.ASSIGNED_SPECIMENS)){
1651
//                occurrences = new ArrayList<>(specimenWithAssociations);
1652
//            }
1653
//        }
1651 1654
        // indirectly associated specimens
1652 1655
        if(occurrenceConfig.isRetrieveIndirectlyAssociatedSpecimens()){
1653 1656
            List<SpecimenOrObservationBase> indirectlyAssociatedOccurrences = new ArrayList<>(occurrences);
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/TaxonServiceImpl.java
801 801
            Set<SpecimenOrObservationBase> specimensOrObservations = new HashSet<>();
802 802
            // --- Specimens
803 803
            for (Taxon t : taxa) {
804
                specimensOrObservations.addAll(occurrenceDao.listByAssociatedTaxon(null, t, null, null, null, null));
804
                specimensOrObservations.addAll(occurrenceDao.listByAssociatedTaxon(null, t, null, null, null, null, null));
805 805
            }
806 806
            for (SpecimenOrObservationBase<?> occurrence : specimensOrObservations) {
807 807

  
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/config/FindOccurrencesConfigurator.java
8 8
*/
9 9
package eu.etaxonomy.cdm.api.service.config;
10 10

  
11
import java.util.HashSet;
12
import java.util.Set;
11 13
import java.util.UUID;
12 14

  
13 15
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
......
29 31
    private String significantIdentifier;
30 32
    private boolean retrieveIndirectlyAssociatedSpecimens;
31 33

  
32
    private AssignmentStatus assignmentStatus = AssignmentStatus.ALL_SPECIMENS;
34
    private Set<AssignmentStatus> assignmentStates;
33 35

  
34
    public void setAssignmentStatus(AssignmentStatus assignmentStatus) {
35
        this.assignmentStatus = assignmentStatus;
36
    public void addAssignmentStatus(AssignmentStatus assignmentStatus) {
37
        if(assignmentStates==null){
38
            assignmentStates = new HashSet<>();
39
        }
40
        this.assignmentStates.add(assignmentStatus);
36 41
    }
37
    public AssignmentStatus getAssignmentStatus() {
38
        return assignmentStatus;
42
    public Set<AssignmentStatus> getAssignmentStates() {
43
        return assignmentStates;
39 44
    }
40 45

  
41 46
    public String getSignificantIdentifier() {
cdmlib-services/src/test/java/eu/etaxonomy/cdm/api/service/OccurrenceServiceTest.java
1113 1113
        assertTrue(specimensOrObservations.contains(derivedUnit1));
1114 1114

  
1115 1115
        //test assignment status
1116
        //all specimen
1116
        //all specimens 1 (either null for AssignmentStatus)
1117 1117
        config = new FindOccurrencesConfigurator();
1118
        config.setAssignmentStatus(AssignmentStatus.ALL_SPECIMENS);
1119 1118
        assertEquals(5, occurrenceService.countOccurrences(config));
1120
        List<SpecimenOrObservationBase> allSpecimens = occurrenceService.findByTitle(config).getRecords();
1121
        assertEquals(5, allSpecimens.size());
1122
        assertTrue(allSpecimens.contains(derivedUnit1));
1123
        assertTrue(allSpecimens.contains(derivedUnit2));
1124
        assertTrue(allSpecimens.contains(tissue));
1125
        assertTrue(allSpecimens.contains(dnaSample));
1119
        List<SpecimenOrObservationBase> allSpecimens1 = occurrenceService.findByTitle(config).getRecords();
1120
        assertEquals(5, allSpecimens1.size());
1121
        assertTrue(allSpecimens1.contains(derivedUnit1));
1122
        assertTrue(allSpecimens1.contains(derivedUnit2));
1123
        assertTrue(allSpecimens1.contains(tissue));
1124
        assertTrue(allSpecimens1.contains(dnaSample));
1125

  
1126
        //all specimens 2 (or all enum values for AssignmentStatus))
1127
        config = new FindOccurrencesConfigurator();
1128
        config.addAssignmentStatus(AssignmentStatus.DETERMINATION);
1129
        config.addAssignmentStatus(AssignmentStatus.INDIVIDUALS_ASSOCIATION);
1130
        config.addAssignmentStatus(AssignmentStatus.TYPE_DESIGNATION);
1131
        config.addAssignmentStatus(AssignmentStatus.NONE);
1132
        assertEquals(5, occurrenceService.countOccurrences(config));
1133
        List<SpecimenOrObservationBase> allSpecimens2 = occurrenceService.findByTitle(config).getRecords();
1134
        assertEquals(5, allSpecimens2.size());
1135
        assertTrue(allSpecimens2.contains(derivedUnit1));
1136
        assertTrue(allSpecimens2.contains(derivedUnit2));
1137
        assertTrue(allSpecimens2.contains(tissue));
1138
        assertTrue(allSpecimens2.contains(dnaSample));
1126 1139

  
1127 1140
        //assigned specimen
1128 1141
        config = new FindOccurrencesConfigurator();
1129
        config.setAssignmentStatus(AssignmentStatus.ASSIGNED_SPECIMENS);
1142
        config.addAssignmentStatus(AssignmentStatus.DETERMINATION);
1143
        config.addAssignmentStatus(AssignmentStatus.INDIVIDUALS_ASSOCIATION);
1144
        config.addAssignmentStatus(AssignmentStatus.TYPE_DESIGNATION);
1130 1145
        assertEquals(2, occurrenceService.countOccurrences(config));
1131 1146
        List<SpecimenOrObservationBase> assignedSpecimens = occurrenceService.findByTitle(config).getRecords();
1132 1147
        assertEquals(2, assignedSpecimens.size());
......
1135 1150

  
1136 1151
        //unassigned specimen
1137 1152
        config = new FindOccurrencesConfigurator();
1138
        config.setAssignmentStatus(AssignmentStatus.UNASSIGNED_SPECIMENS);
1153
        config.addAssignmentStatus(AssignmentStatus.NONE);
1139 1154
        assertEquals(3, occurrenceService.countOccurrences(config));
1140 1155
        List<SpecimenOrObservationBase> unAssignedSpecimens = occurrenceService.findByTitle(config).getRecords();
1141 1156
        assertEquals(3, unAssignedSpecimens.size());
......
1145 1160
        //ignore assignment status because taxon uuid is set
1146 1161
        config = new FindOccurrencesConfigurator();
1147 1162
        config.setAssociatedTaxonUuid(taxon.getUuid());
1148
        config.setAssignmentStatus(AssignmentStatus.UNASSIGNED_SPECIMENS);
1163
        config.addAssignmentStatus(AssignmentStatus.NONE);
1149 1164
        assertEquals(2, occurrenceService.countOccurrences(config));
1150 1165
        List<SpecimenOrObservationBase> ignoreAssignmentStatusSpecimens = occurrenceService.findByTitle(config).getRecords();
1151 1166
        assertEquals(2, ignoreAssignmentStatusSpecimens.size());

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)