Revision 7dab8082
Added by Patrick Plitzner about 6 years ago
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/OccurrenceServiceImpl.java | ||
---|---|---|
1457 | 1457 |
if(occurrenceConfig.getAssociatedTaxonNameUuid()!=null){ |
1458 | 1458 |
taxonName = nameService.load(occurrenceConfig.getAssociatedTaxonNameUuid()); |
1459 | 1459 |
} |
1460 |
/*TODO: #6484 Neither isRetrieveIndirectlyAssociatedSpecimens() nor the AssignmentStatus |
|
1461 |
* is currently reflected in the HQL query. So using these in the count method will |
|
1462 |
* significantly slow down this method as we have to retreive the entities instead of |
|
1463 |
* the just the amount. |
|
1464 |
*/ |
|
1465 |
if(occurrenceConfig.isRetrieveIndirectlyAssociatedSpecimens() || !occurrenceConfig.getAssignmentStatus().equals(AssignmentStatus.ALL_SPECIMENS)){ |
|
1466 |
List<SpecimenOrObservationBase> occurrences = new ArrayList<>(); |
|
1467 |
occurrences.addAll(dao.findOccurrences(occurrenceConfig.getClazz(), |
|
1468 |
occurrenceConfig.getTitleSearchString(), occurrenceConfig.getSignificantIdentifier(), |
|
1469 |
occurrenceConfig.getSpecimenType(), taxon, taxonName, occurrenceConfig.getMatchMode(), null, null, |
|
1470 |
occurrenceConfig.getOrderHints(), occurrenceConfig.getPropertyPaths())); |
|
1471 |
occurrences = filterOccurencesByAssignmentAndHierarchy(occurrenceConfig, occurrences, taxon, taxonName); |
|
1472 |
return occurrences.size(); |
|
1473 |
} |
|
1474 |
|
|
1460 | 1475 |
return dao.countOccurrences(occurrenceConfig.getClazz(), |
1461 | 1476 |
occurrenceConfig.getTitleSearchString(), occurrenceConfig.getSignificantIdentifier(), |
1462 | 1477 |
occurrenceConfig.getSpecimenType(), taxon, taxonName, occurrenceConfig.getMatchMode(), null, null, |
... | ... | |
1465 | 1480 |
else{ |
1466 | 1481 |
return dao.countByTitle(config.getTitleSearchString()); |
1467 | 1482 |
} |
1468 |
|
|
1469 | 1483 |
} |
1470 | 1484 |
|
1471 | 1485 |
@Override |
... | ... | |
1489 | 1503 |
occurrenceConfig.getTitleSearchString(), occurrenceConfig.getSignificantIdentifier(), |
1490 | 1504 |
occurrenceConfig.getSpecimenType(), taxon, taxonName, occurrenceConfig.getMatchMode(), null, null, |
1491 | 1505 |
occurrenceConfig.getOrderHints(), occurrenceConfig.getPropertyPaths())); |
1492 |
//filter out (un-)assigned specimens |
|
1493 |
if(taxon==null && taxonName==null){ |
|
1494 |
AssignmentStatus assignmentStatus = occurrenceConfig.getAssignmentStatus(); |
|
1495 |
List<SpecimenOrObservationBase<?>> specimenWithAssociations = new ArrayList<>(); |
|
1496 |
if(!assignmentStatus.equals(AssignmentStatus.ALL_SPECIMENS)){ |
|
1497 |
for (SpecimenOrObservationBase specimenOrObservationBase : occurrences) { |
|
1498 |
Collection<TaxonBase<?>> associatedTaxa = listAssociatedTaxa(specimenOrObservationBase, null, null, null, null); |
|
1499 |
if(!associatedTaxa.isEmpty()){ |
|
1500 |
specimenWithAssociations.add(specimenOrObservationBase); |
|
1501 |
} |
|
1506 |
occurrences = filterOccurencesByAssignmentAndHierarchy(occurrenceConfig, occurrences, taxon, taxonName); |
|
1507 |
|
|
1508 |
return new DefaultPagerImpl<SpecimenOrObservationBase>(config.getPageNumber(), occurrences.size(), config.getPageSize(), occurrences); |
|
1509 |
} |
|
1510 |
return super.findByTitle(config); |
|
1511 |
} |
|
1512 |
|
|
1513 |
private List<SpecimenOrObservationBase> filterOccurencesByAssignmentAndHierarchy( |
|
1514 |
FindOccurrencesConfigurator occurrenceConfig, List<SpecimenOrObservationBase> occurrences, Taxon taxon, |
|
1515 |
TaxonName taxonName) { |
|
1516 |
//filter out (un-)assigned specimens |
|
1517 |
if(taxon==null && taxonName==null){ |
|
1518 |
AssignmentStatus assignmentStatus = occurrenceConfig.getAssignmentStatus(); |
|
1519 |
List<SpecimenOrObservationBase<?>> specimenWithAssociations = new ArrayList<>(); |
|
1520 |
if(!assignmentStatus.equals(AssignmentStatus.ALL_SPECIMENS)){ |
|
1521 |
for (SpecimenOrObservationBase specimenOrObservationBase : occurrences) { |
|
1522 |
Collection<TaxonBase<?>> associatedTaxa = listAssociatedTaxa(specimenOrObservationBase, null, null, null, null); |
|
1523 |
if(!associatedTaxa.isEmpty()){ |
|
1524 |
specimenWithAssociations.add(specimenOrObservationBase); |
|
1502 | 1525 |
} |
1503 | 1526 |
} |
1504 |
if(assignmentStatus.equals(AssignmentStatus.UNASSIGNED_SPECIMENS)){ |
|
1505 |
occurrences.removeAll(specimenWithAssociations); |
|
1506 |
} |
|
1507 |
if(assignmentStatus.equals(AssignmentStatus.ASSIGNED_SPECIMENS)){ |
|
1508 |
occurrences = new ArrayList<>(specimenWithAssociations); |
|
1509 |
} |
|
1510 | 1527 |
} |
1511 |
// indirectly associated specimens |
|
1512 |
if(occurrenceConfig.isRetrieveIndirectlyAssociatedSpecimens()){ |
|
1513 |
List<SpecimenOrObservationBase> indirectlyAssociatedOccurrences = new ArrayList<>(occurrences); |
|
1514 |
for (SpecimenOrObservationBase specimen : occurrences) { |
|
1515 |
List<SpecimenOrObservationBase<?>> allHierarchyDerivates = getAllHierarchyDerivatives(specimen); |
|
1516 |
for (SpecimenOrObservationBase<?> specimenOrObservationBase : allHierarchyDerivates) { |
|
1517 |
if(!occurrences.contains(specimenOrObservationBase)){ |
|
1518 |
indirectlyAssociatedOccurrences.add(specimenOrObservationBase); |
|
1519 |
} |
|
1528 |
if(assignmentStatus.equals(AssignmentStatus.UNASSIGNED_SPECIMENS)){ |
|
1529 |
occurrences.removeAll(specimenWithAssociations); |
|
1530 |
} |
|
1531 |
if(assignmentStatus.equals(AssignmentStatus.ASSIGNED_SPECIMENS)){ |
|
1532 |
occurrences = new ArrayList<>(specimenWithAssociations); |
|
1533 |
} |
|
1534 |
} |
|
1535 |
// indirectly associated specimens |
|
1536 |
if(occurrenceConfig.isRetrieveIndirectlyAssociatedSpecimens()){ |
|
1537 |
List<SpecimenOrObservationBase> indirectlyAssociatedOccurrences = new ArrayList<>(occurrences); |
|
1538 |
for (SpecimenOrObservationBase specimen : occurrences) { |
|
1539 |
List<SpecimenOrObservationBase<?>> allHierarchyDerivates = getAllHierarchyDerivatives(specimen); |
|
1540 |
for (SpecimenOrObservationBase<?> specimenOrObservationBase : allHierarchyDerivates) { |
|
1541 |
if(!occurrences.contains(specimenOrObservationBase)){ |
|
1542 |
indirectlyAssociatedOccurrences.add(specimenOrObservationBase); |
|
1520 | 1543 |
} |
1521 | 1544 |
} |
1522 |
occurrences = indirectlyAssociatedOccurrences; |
|
1523 | 1545 |
} |
1524 |
|
|
1525 |
return new DefaultPagerImpl<SpecimenOrObservationBase>(config.getPageNumber(), occurrences.size(), config.getPageSize(), occurrences); |
|
1546 |
occurrences = indirectlyAssociatedOccurrences; |
|
1526 | 1547 |
} |
1527 |
return super.findByTitle(config);
|
|
1548 |
return occurrences;
|
|
1528 | 1549 |
} |
1529 | 1550 |
|
1530 | 1551 |
@Override |
Also available in: Unified diff
ref #6484 Adjust count method to find method to return the same number