Project

General

Profile

Revision b27b3345

IDb27b334572fadefd55af0d358c5ed576d3634e59
Parent d9b27602
Child 5f492efb

Added by Patrick Plitzner over 1 year ago

ref #7095 Code clean up and refactoring

View differences:

cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/persistence/dao/hibernate/occurrence/OccurrenceDaoHibernateImpl.java
591 591
        return results;
592 592
    }
593 593

  
594
    private List<SpecimenNodeWrapper> queryIndividualAssociatedSpecimen(List<UUID> taxonNodeUuids,
595
            Integer limit, Integer start, List<OrderHint> orderHintss){
596
        String queryString =  "SELECT "
597
                + "de.associatedSpecimenOrObservation.uuid, "
598
                + "de.associatedSpecimenOrObservation.id, "
599
                + "de.associatedSpecimenOrObservation.titleCache, "
600
                + "tn "
601
                + "FROM DescriptionElementBase AS de "
602
                + "LEFT JOIN de.inDescription AS d "
603
                + "LEFT JOIN d.taxon AS t "
604
                + "JOIN t.taxonNodes AS tn "
605
                + "WHERE d.class = 'TaxonDescription' "
606
                + "AND tn.uuid in (:taxonNodeUuids) "
607
                ;
608
        Query query = getSession().createQuery(queryString);
609

  
594
    private List<SpecimenNodeWrapper> querySpecimen(
595
            Query query, List<UUID> taxonNodeUuids,
596
            Integer limit, Integer start){
610 597
        query.setParameterList("taxonNodeUuids", taxonNodeUuids);
611 598

  
612 599
        if(limit != null) {
......
631 618
        return list;
632 619
    }
633 620

  
621
    private List<SpecimenNodeWrapper> queryIndividualAssociatedSpecimen(List<UUID> taxonNodeUuids,
622
            Integer limit, Integer start){
623
        String queryString =  "SELECT "
624
                + "de.associatedSpecimenOrObservation.uuid, "
625
                + "de.associatedSpecimenOrObservation.id, "
626
                + "de.associatedSpecimenOrObservation.titleCache, "
627
                + "tn "
628
                + "FROM DescriptionElementBase AS de "
629
                + "LEFT JOIN de.inDescription AS d "
630
                + "LEFT JOIN d.taxon AS t "
631
                + "JOIN t.taxonNodes AS tn "
632
                + "WHERE d.class = 'TaxonDescription' "
633
                + "AND tn.uuid in (:taxonNodeUuids) "
634
                ;
635
        Query query = getSession().createQuery(queryString);
636
        return querySpecimen(query, taxonNodeUuids, limit, start);
637
    }
638

  
634 639
    private List<SpecimenNodeWrapper> queryTypeSpecimen(List<UUID> taxonNodeUuids,
635
            Integer limit, Integer start, List<OrderHint> orderHints){
640
            Integer limit, Integer start){
636 641
        String queryString =  "SELECT "
637 642
                + "td.typeSpecimen.uuid, "
638 643
                + "td.typeSpecimen.id, "
......
645 650
                + "WHERE tn.uuid in (:taxonNodeUuids) "
646 651
                ;
647 652
        Query query = getSession().createQuery(queryString);
648

  
649
        query.setParameterList("taxonNodeUuids", taxonNodeUuids);
650

  
651
        if(limit != null) {
652
            if(start != null) {
653
                query.setFirstResult(start);
654
            } else {
655
                query.setFirstResult(0);
656
            }
657
            query.setMaxResults(limit);
658
        }
659

  
660
        List<SpecimenNodeWrapper> list = new ArrayList<>();
661
        List<Object[]> result = query.list();
662
        for(Object[] object : result){
663
            list.add(new SpecimenNodeWrapper(
664
                    new UuidAndTitleCache<SpecimenOrObservationBase>(
665
                            (UUID) object[0],
666
                            (Integer) object[1],
667
                            (String) object[2]),
668
                    (TaxonNode)object[3]));
669
        }
670
        return list;
653
        return querySpecimen(query, taxonNodeUuids, limit, start);
671 654
    }
672 655

  
673 656
    private List<SpecimenNodeWrapper> queryTaxonDeterminations(List<UUID> taxonNodeUuids,
674
            Integer limit, Integer start, List<OrderHint> orderHints){
657
            Integer limit, Integer start){
675 658
        String queryString =  "SELECT "
676 659
                + "det.identifiedUnit.uuid, "
677 660
                + "det.identifiedUnit.id, "
......
683 666
                + "WHERE tn.uuid in (:taxonNodeUuids) "
684 667
                ;
685 668
        Query query = getSession().createQuery(queryString);
686

  
687
        query.setParameterList("taxonNodeUuids", taxonNodeUuids);
688

  
689
        if(limit != null) {
690
            if(start != null) {
691
                query.setFirstResult(start);
692
            } else {
693
                query.setFirstResult(0);
694
            }
695
            query.setMaxResults(limit);
696
        }
697

  
698
        List<SpecimenNodeWrapper> list = new ArrayList<>();
699
        List<Object[]> result = query.list();
700
        for(Object[] object : result){
701
            list.add(new SpecimenNodeWrapper(
702
                    new UuidAndTitleCache<SpecimenOrObservationBase>(
703
                            (UUID) object[0],
704
                            (Integer) object[1],
705
                            (String) object[2]),
706
                    (TaxonNode)object[3]));
707
        }
708
        return list;
669
        return querySpecimen(query, taxonNodeUuids, limit, start);
709 670
    }
710 671

  
711 672
    private List<SpecimenNodeWrapper> queryTaxonNameDeterminations(List<UUID> taxonNodeUuids,
712
            Integer limit, Integer start, List<OrderHint> orderHints){
673
            Integer limit, Integer start){
713 674
        String queryString =  "SELECT "
714 675
                + "det.identifiedUnit.uuid, "
715 676
                + "det.identifiedUnit.id, "
......
722 683
                + "WHERE tn.uuid in (:taxonNodeUuids) "
723 684
                ;
724 685
        Query query = getSession().createQuery(queryString);
725

  
726
        query.setParameterList("taxonNodeUuids", taxonNodeUuids);
727

  
728
        if(limit != null) {
729
            if(start != null) {
730
                query.setFirstResult(start);
731
            } else {
732
                query.setFirstResult(0);
733
            }
734
            query.setMaxResults(limit);
735
        }
736

  
737
        List<SpecimenNodeWrapper> list = new ArrayList<>();
738
        List<Object[]> result = query.list();
739
        for(Object[] object : result){
740
            list.add(new SpecimenNodeWrapper(
741
                    new UuidAndTitleCache<SpecimenOrObservationBase>(
742
                            (UUID) object[0],
743
                            (Integer) object[1],
744
                            (String) object[2]),
745
                    (TaxonNode)object[3]));
746
        }
747
        return list;
686
        return querySpecimen(query, taxonNodeUuids, limit, start);
748 687
    }
749 688

  
750 689
    @Override
751 690
    public Collection<SpecimenNodeWrapper> listUuidAndTitleCacheByAssociatedTaxon(List<UUID> taxonNodeUuids,
752
            Integer limit, Integer start, List<OrderHint> orderHints){
691
            Integer limit, Integer start){
753 692

  
754 693
        Collection<SpecimenNodeWrapper> wrappers = new HashSet<>();
755
        wrappers.addAll(queryIndividualAssociatedSpecimen(taxonNodeUuids, limit, start, orderHints));
756
        wrappers.addAll(queryTaxonDeterminations(taxonNodeUuids, limit, start, orderHints));
757
        wrappers.addAll(queryTaxonNameDeterminations(taxonNodeUuids, limit, start, orderHints));
758
        wrappers.addAll(queryTypeSpecimen(taxonNodeUuids, limit, start, orderHints));
694
        wrappers.addAll(queryIndividualAssociatedSpecimen(taxonNodeUuids, limit, start));
695
        wrappers.addAll(queryTaxonDeterminations(taxonNodeUuids, limit, start));
696
        wrappers.addAll(queryTaxonNameDeterminations(taxonNodeUuids, limit, start));
697
        wrappers.addAll(queryTypeSpecimen(taxonNodeUuids, limit, start));
759 698

  
760 699
        return wrappers;
761 700
    }
cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/persistence/dao/occurrence/IOccurrenceDao.java
327 327
     * @param taxonNodeUuids a list of {@link UUID}s of the taxon nodes
328 328
     * @param limit
329 329
     * @param start
330
     * @param orderHints
331 330
     * @return a collection of {@link SpecimenNodeWrapper} containing the {@link TaxonNode}
332 331
     * and the corresponding {@link UuidAndTitleCache}  object for the specimen found for this taxon node
333 332
     */
334 333
	public Collection<SpecimenNodeWrapper> listUuidAndTitleCacheByAssociatedTaxon(List<UUID> taxonNodeUuids,
335
            Integer limit, Integer start, List<OrderHint> orderHints);
334
            Integer limit, Integer start);
336 335

  
337 336
    /**
338 337
     * Retrieves all {@link IndividualsAssociation} with the given specimen.<br>
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/IOccurrenceService.java
273 273
     *            a list of {@link UUID}s of the taxon nodes
274 274
     * @param limit
275 275
     * @param start
276
     * @param orderHints
277 276
     * @return a collection of {@link SpecimenNodeWrapper} containing the
278 277
     *         {@link TaxonNode} and the corresponding {@link UuidAndTitleCache}
279 278
     *         object for the specimen found for this taxon node
280 279
     */
281 280
    public Collection<SpecimenNodeWrapper> listUuidAndTitleCacheByAssociatedTaxon(List<UUID> taxonNodeUuids,
282
            Integer limit, Integer start, List<OrderHint> orderHints);
281
            Integer limit, Integer start);
283 282

  
284 283

  
285 284
    /**
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/OccurrenceServiceImpl.java
360 360

  
361 361
    @Override
362 362
    public Collection<SpecimenNodeWrapper> listUuidAndTitleCacheByAssociatedTaxon(List<UUID> taxonNodeUuids,
363
            Integer limit, Integer start, List<OrderHint> orderHints) {
364
        return dao.listUuidAndTitleCacheByAssociatedTaxon(taxonNodeUuids, limit, start, orderHints);
363
            Integer limit, Integer start) {
364
        return dao.listUuidAndTitleCacheByAssociatedTaxon(taxonNodeUuids, limit, start);
365 365
        }
366 366

  
367 367
    @Override
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/WorkingSetService.java
115 115
        filter.setIncludeUnpublished(true);
116 116

  
117 117
        List<UUID> filteredNodes = taxonNodeService.uuidList(filter);
118
        return occurrenceService.listUuidAndTitleCacheByAssociatedTaxon(filteredNodes, null, null, null);
118
        return occurrenceService.listUuidAndTitleCacheByAssociatedTaxon(filteredNodes, null, null);
119 119
    }
120 120

  
121 121
    @Override
cdmlib-services/src/test/java/eu/etaxonomy/cdm/api/service/OccurrenceServiceTest.java
1201 1201
        FindOccurrencesConfigurator config = new FindOccurrencesConfigurator();
1202 1202
        config.setAssociatedTaxonUuid(taxonUuid);
1203 1203
        Collection<SpecimenNodeWrapper> specimens = occurrenceService
1204
                .listUuidAndTitleCacheByAssociatedTaxon(Collections.singletonList(taxonNodeUuid), null, null, null);
1204
                .listUuidAndTitleCacheByAssociatedTaxon(Collections.singletonList(taxonNodeUuid), null, null);
1205 1205
        List<UUID> uuidList = specimens.stream().map(specimen ->
1206 1206
        specimen.getUuidAndTitleCache().getUuid()).collect(Collectors.toList());
1207 1207
        assertTrue(uuidList.contains(derivedUnitDeterminationNameUuid));

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)