Project

General

Profile

Revision d64f3367

IDd64f336751cfe913ace496e4919b90dc942520b0
Parent 0280b3f1
Child e39a2ac2

Added by Sybille Bürs about 7 years ago

just save state

View differences:

cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/persistence/dao/hibernate/statistics/StatisticsDaoHibernateImpl.java
91 91
				queryStrings, null).size());
92 92
	}
93 93

  
94
	
95 94
	/*
96 95
	 * (non-Javadoc)
97 96
	 * 
......
100 99
	 * (eu.etaxonomy.cdm.model.taxon.Classification)
101 100
	 */
102 101
	@Override
103
	public Long countDescriptive(Boolean sourceRef, Classification classification) {
104
		return Long.valueOf(listDescriptiveIds(sourceRef,classification).size());
102
	public Long countDescriptive(Boolean sourceRef,
103
			Classification classification) {
104
		return Long.valueOf(listDescriptiveIds(sourceRef, classification)
105
				.size());
105 106
	}
106 107

  
107 108
	// private Set<Integer> listDescriptiveSourceReferenceIds(
......
202 203
	private Set<Integer> listDescriptiveIds(Boolean sourceReferences,
203 204
			Classification classification) {
204 205

  
205
//		Boolean sourceReferences = true;
206
		// Boolean sourceReferences = true;
206 207
		String sourceRefJoins = "";
207 208
		String sourceRefWhere = "";
208 209
		String selection = "d.id ";
......
386 387
	 * @see eu.etaxonomy.cdm.persistence.dao.statistics.IStatisticsDao#
387 388
	 * countNomenclaturalReferences()
388 389
	 */
389
//	@Override
390
	// @Override
390 391
	public Long countNomenclaturalReferences() {
391 392
		Query query = getSession()
392 393
				.createQuery(
......
394 395
		return (Long) query.uniqueResult();
395 396
	}
396 397

  
397
	/*
398
	 * (non-Javadoc)
399
	 * 
400
	 * @see eu.etaxonomy.cdm.persistence.dao.statistics.IStatisticsDao#
401
	 * countNomenclaturalReferences(eu.etaxonomy.cdm.model.taxon.Classification)
402
	 */
403
	@Override
404
	public Long countNomenclaturalReferences(Classification classification) {
398

  
399
	 @Override
400
	public Long countNomenclaturalReferences(
401
			Classification classification) {
405 402

  
406 403
		if (classification == null)
407 404
			return null; // or MAYDO: throw some Exception???
......
426 423
				queryStrings, parameters).size());
427 424
	}
428 425

  
429
	/*
430
	 * (non-Javadoc)
431
	 * 
432
	 * @see eu.etaxonomy.cdm.persistence.dao.statistics.IStatisticsDao#
433
	 * countReferencesInClassification
434
	 * (eu.etaxonomy.cdm.model.taxon.Classification)
435
	 */
436
	// TODO!!!
437
	@Override
438
	public Long countReferencesInClassification(Classification classification) {
426

  
427
//	@Override
428
	public Long countReferencesInClassificationWithIds(Classification classification) {
439 429
		if (classification == null)
440 430
			return null; // or MAYDO: throw some Exception???
441 431

  
442

  
443 432
		// get all the descriptive source reference ids
444 433
		// ---------------------------------------------
445 434

  
......
566 555
		// "ReferencedMediaBase"
567 556
		// which has a citation
568 557

  
569
		queryStrings
570
				.add("select distinct cit.id " +
571
						" from TaxonNode tn "
572
						+ "join tn.taxon.descriptions as db "
558
		queryStrings.add("select distinct cit.id " + " from TaxonNode tn "
559
				+ "join tn.taxon.descriptions as db "
573 560

  
574
						+ "join db.describedSpecimenOrObservation as so "
575
						+ "join so.sequences as seq "
576
						+ "join seq.citations as cit "
561
				+ "join db.describedSpecimenOrObservation as so "
562
				+ "join so.sequences as seq " + "join seq.citations as cit "
577 563

  
578
						+ "where so.class=:dnaSample "
579
						+ "and tn.classification=:classification "
580
						+ "and cit is not null ");
564
				+ "where so.class=:dnaSample "
565
				+ "and tn.classification=:classification "
566
				+ "and cit is not null ");
581 567

  
582 568
		// traverse to specimenOrObservation via individualsAssociation
583 569

  
584
		queryStrings
585
				.add("select distinct cit.id from TaxonNode tn "
586
						+ "join tn.taxon.descriptions as db "
587
						+ "join db.descriptionElements as ia "
588
						+ "join ia.associatedSpecimenOrObservation as so "
589
						+ "join so.sequences as seq "
590
						+ "join seq.citations as cit "
591

  
592
						+ "where so.class=:dnaSample "
593
						+ "and ia.class=:individualsAssociation "
594
						+ "and tn.classification=:classification "
595
						+ "and cit is not null ");
570
		queryStrings.add("select distinct cit.id from TaxonNode tn "
571
				+ "join tn.taxon.descriptions as db "
572
				+ "join db.descriptionElements as ia "
573
				+ "join ia.associatedSpecimenOrObservation as so "
574
				+ "join so.sequences as seq " + "join seq.citations as cit "
575

  
576
				+ "where so.class=:dnaSample "
577
				+ "and ia.class=:individualsAssociation "
578
				+ "and tn.classification=:classification "
579
				+ "and cit is not null ");
596 580

  
597 581
		// we do assume, that a name description would not have a
598 582
		// SpecimenOrObservation element
......
601 585
		parameters.put("dnaSample", "DnaSample");
602 586
		parameters.put("individualsAssociation", "IndividualsAssociation");
603 587

  
604
//		
605
//		
606
////### TODO v3.3, preliminary removed for adaptation to model v3.3	
607
		// this was all about ReferencedMedia	
588
		//
589
		//
590
		// //### TODO v3.3, preliminary removed for adaptation to model v3.3
591
		// this was all about ReferencedMedia
608 592
		{
609
//		// media
610
//		queryStrings.add("select distinct me.citation.id from TaxonNode tn "
611
//				+ "join tn.taxon.descriptions as db "
612
//				+ "join db.describedSpecimenOrObservation as so "
613
//				+ "join so.sequences as seq "
614
//				+ "join seq.chromatograms as me "
615
//
616
//				+ "where so.class=:dnaSample "
617
//				+ "and me.class=:referencedMediaBase "
618
//				+ "and tn.classification=:classification "
619
//
620
//				+ "and me.citation is not null ");
621
//
622
//		// traverse to specimenOrObservation via individualsAssociation
623
//
624
//		queryStrings.add("select distinct me.citation.id from TaxonNode tn "
625
//				+ "join tn.taxon.descriptions as db "
626
//				+ "join db.descriptionElements as ia "
627
//				+ "join ia.associatedSpecimenOrObservation as so "
628
//				+ "join so.sequences as seq " 
629
//				+ "join seq.chromatograms as me "
630
//				+ "where so.class=:dnaSample "
631
//				+ "and ia.class=:individualsAssociation "
632
//				+ "and me.class=:referencedMediaBase "
633
//				+ "and tn.classification=:classification "
634
//
635
//				+ "and me.citation is not null ");
636
//
637
//// TODO v3.3, preliminary  removed for adaptation to model v3.3, Media.citation does not exist anymore, use OriginalSource instead	
638
//		// via media via name description
639
//		// Taxa:
640
//		queryStrings.add("select distinct me.citation.id from TaxonNode tn "
641
//				+ "join tn.taxon.name.descriptions as d "
642
//				+ "join d.descriptionElements as de "
643
//				+ "join de.media as me "
644
//				+ "where tn.classification=:classification "
645
//				+ "and tn.taxon.name is not null "
646
//				+ "and me.class=:referencedMediaBase "
647
//				+ "and me.citation is not null " + "and tn.taxon is not null "
648
//				+ "and tn.taxon.name is not null ");
649
//
650
//		// synonyms:
651
//		queryStrings.add("select distinct me.citation.id from TaxonNode tn "
652
//				+ "join tn.taxon.synonymRelations as syr "
653
//				+ "join syr.relatedFrom as sy "
654
//				+ "join sy.name.descriptions as d "
655
//				+ "join d.descriptionElements as de "
656
//				+ "join de.media as me "
657
//				+ "where tn.classification=:classification "
658
//				+ "and sy.name is not null "
659
//				+ "and me.class=:referencedMediaBase "
660
//				+ "and me.citation is not null " + "and tn.taxon is not null "
661
//				+ "and tn.taxon.name is not null ");
662
//
663
//		// get all "Media" from everywhere because it could be
664
//		// of the subtype "ReferencedMediaBase"
665
//		// which has a citation
666
//
667
//		// TODO do we need the media from DefinedTermBase???
668
//		// what can be a Feature!
669
//
670
//		// from description element
671
//		queryStrings.add("select distinct me.citation.id from TaxonNode as tn "
672
//				+ "join tn.taxon.descriptions as d "
673
//				+ "join d.descriptionElements as de " 
674
//				+ "join de.media as me "
675
//				+ "where tn.classification=:classification "
676
//				+ "and me.class=:referencedMediaBase "
677
//				+ "and me.citation is not null ");
678
//
679
//		// via NamedArea that has 2 media parameter
680
//		// and a waterbodyOrContinet that has media parameter and has continent
681
//		// parameter
682
//		// which also has media parameter:
683
//
684
//		
685
//
686
//		// from CommonTaxonName or Distribution
687
//		queryStrings
688
//				.add("select distinct de.area.shape.citation.id, me1.citation.id, "
689
//						+ "me2.citation.id, me3.citation.id from TaxonNode as tn "
690
//						+ "join tn.taxon.descriptions as d "
691
//						+ "join d.descriptionElements as de "
692
//						+ "join de.area.media as me1 "
693
//						+ "join de.area.waterbodiesOrCountries as wboc "
694
//						+ "join wboc.media as me2 "
695
//						+ "join wboc.continents as co "
696
//						+ "join co.media as me3 "
697
//						+ "where tn.classification=:classification "
698
//						+ "and (de.class=:commonTaxonName or de.class=:distribution) "
699
//						+ "and me1.class=:referencedMediaBase "
700
//						+ "and me1.citation is not null "
701
//						+ "and me2.class=:referencedMediaBase "
702
//						+ "and me2.citation is not null "
703
//						+ "and me3.class=:referencedMediaBase "
704
//						+ "and me3.citation is not null "
705
//						+ "and de.area.shape.class=:referencedMediaBase "
706
//						+ "and de.area is not null "
707
//						+ "and de.area.shape is not null ");
708
//
709
//		parameters.put("commonTaxonName", "CommonTaxonName");
710
//		parameters.put("distribution", "Distribution");
711
//		//***
712
//		// from TaxonDescription:
713
//		queryStrings
714
//				.add("select distinct na.shape.citation.id, me1.citation.id, "
715
//						+ "me2.citation.id, me3.citation.id from TaxonNode as tn "
716
//						+ "join tn.taxon.descriptions as d "
717
//						+ "join d.geoScopes as na " + "join na.media as me1 "
718
//						+ "join na.waterbodiesOrCountries as wboc "
719
//						+ "join wboc.media as me2 "
720
//						+ "join wboc.continents as co "
721
//						+ "join co.media as me3 "
722
//						+ "where tn.classification=:classification "
723
//						+ "and me1.class=:referencedMediaBase "
724
//						+ "and me1.citation is not null "
725
//						+ "and me2.class=:referencedMediaBase "
726
//						+ "and me2.citation is not null "
727
//						+ "and me3.class=:referencedMediaBase "
728
//						+ "and me3.citation is not null "
729
//						+ "and na.shape.class=:referencedMediaBase "
730
//						+ "and na.shape is not null ");
731
//
732
//		// from gathering event
733
//		queryStrings
734
//				.add("select fo.gatheringEvent.country.shape.citation.id, ca.shape.citation.id " +
735
//						" from TaxonNode tn "
736
//						+ "join tn.taxon.descriptions as db "
737
//						+ "join db.describedSpecimenOrObservation as fo "
738
//						+ "join fo.gatheringEvent.collectingAreas as ca "
739
//						+ "where fo.class=:fieldObservation "
740
//						+ "and fo.gatheringEvent is not null "
741
//						+ "and fo.gatheringEvent.country is not null "
742
//						+ "and fo.gatheringEvent.country.shape is not null "
743
//						+ "and ca.shape is not null "
744
//						+ "and ca.shape.class=:referencedMediaBase "
745
//						+ "and ca.shape.citation is not null "
746
//						+ "and fo.gatheringEvent.country.shape.class=:referencedMediaBase "
747
//						+ " and fo.gatheringEvent.country.shape.citation is not null "
748
//						+ "and tn.classification=:classification ");
749
//
750
//		// traverse to specimenOrObservation via individualsAssociation
751
//
752
//		queryStrings
753
//				.add("select fo.gatheringEvent.country.shape.citation.id, ca.shape.citation.id "
754
//						+ "from TaxonNode tn "
755
//						+ "join tn.taxon.descriptions as db "
756
//						+ "join db.descriptionElements as ia "
757
//						+ "join ia.associatedSpecimenOrObservation as fo "
758
//						+ "join fo.gatheringEvent.collectingAreas as ca "
759
//						+ "where fo.class=:fieldObservation "
760
//						+ "and fo.gatheringEvent is not null "
761
//						+ "and fo.gatheringEvent.country is not null "
762
//						+ "and fo.gatheringEvent.country.shape is not null "
763
//						+ "and ca.shape is not null "
764
//						+ "and ca.shape.class=:referencedMediaBase "
765
//						+ "and ca.shape.citation is not null "
766
//						+ "and fo.gatheringEvent.country.shape.class=:referencedMediaBase "
767
//						+ " and fo.gatheringEvent.country.shape.citation is not null "
768
//						+ "and ia.class=:individualsAssociation "
769
//						+ "and tn.classification=:classification ");
770
//
771
//		
772
//
773
//		parameters.put("fieldObservation", "FieldObservation");
774
//		parameters.put("referencedMediaBase", "ReferencedMediaBase");
775
//
776
//		parameters.put("classification", classification);
777
//
778
//		// via events
779
//		// ----------------------------------------
780
//		// determination event:
781
//		// taxa
782
//		queryStrings
783
//				.add("select distinct sor.id from DeterminationEvent dtev, TaxonNode tn "
784
//						+ "join dtev.setOfReferences as sor "
785
//
786
//						+ "where tn.classification=:classification "
787
//						+ "and tn.taxon=dtev.taxon ");
788
//		
789
//		// synonyms
790
//
791
//		queryStrings
792
//				.add("select distinct sor.id from DeterminationEvent dtev, TaxonNode tn "
793
//						+ "join dtev.setOfReferences as sor "
794
//						+ "join tn.taxon.synonymRelations as syr "
795
//						+ "join syr.relatedTo as sy "
796
//						+ "where tn.classification=:classification "
797
//						+ "and sy=dtev.taxon ");
798
//		
593
			// // media
594
			// queryStrings.add("select distinct me.citation.id from TaxonNode tn "
595
			// + "join tn.taxon.descriptions as db "
596
			// + "join db.describedSpecimenOrObservation as so "
597
			// + "join so.sequences as seq "
598
			// + "join seq.chromatograms as me "
599
			//
600
			// + "where so.class=:dnaSample "
601
			// + "and me.class=:referencedMediaBase "
602
			// + "and tn.classification=:classification "
603
			//
604
			// + "and me.citation is not null ");
605
			//
606
			// // traverse to specimenOrObservation via individualsAssociation
607
			//
608
			// queryStrings.add("select distinct me.citation.id from TaxonNode tn "
609
			// + "join tn.taxon.descriptions as db "
610
			// + "join db.descriptionElements as ia "
611
			// + "join ia.associatedSpecimenOrObservation as so "
612
			// + "join so.sequences as seq "
613
			// + "join seq.chromatograms as me "
614
			// + "where so.class=:dnaSample "
615
			// + "and ia.class=:individualsAssociation "
616
			// + "and me.class=:referencedMediaBase "
617
			// + "and tn.classification=:classification "
618
			//
619
			// + "and me.citation is not null ");
620
			//
621
			// // TODO v3.3, preliminary removed for adaptation to model v3.3,
622
			// Media.citation does not exist anymore, use OriginalSource instead
623
			// // via media via name description
624
			// // Taxa:
625
			// queryStrings.add("select distinct me.citation.id from TaxonNode tn "
626
			// + "join tn.taxon.name.descriptions as d "
627
			// + "join d.descriptionElements as de "
628
			// + "join de.media as me "
629
			// + "where tn.classification=:classification "
630
			// + "and tn.taxon.name is not null "
631
			// + "and me.class=:referencedMediaBase "
632
			// + "and me.citation is not null " + "and tn.taxon is not null "
633
			// + "and tn.taxon.name is not null ");
634
			//
635
			// // synonyms:
636
			// queryStrings.add("select distinct me.citation.id from TaxonNode tn "
637
			// + "join tn.taxon.synonymRelations as syr "
638
			// + "join syr.relatedFrom as sy "
639
			// + "join sy.name.descriptions as d "
640
			// + "join d.descriptionElements as de "
641
			// + "join de.media as me "
642
			// + "where tn.classification=:classification "
643
			// + "and sy.name is not null "
644
			// + "and me.class=:referencedMediaBase "
645
			// + "and me.citation is not null " + "and tn.taxon is not null "
646
			// + "and tn.taxon.name is not null ");
647
			//
648
			// // get all "Media" from everywhere because it could be
649
			// // of the subtype "ReferencedMediaBase"
650
			// // which has a citation
651
			//
652
			// // TODO do we need the media from DefinedTermBase???
653
			// // what can be a Feature!
654
			//
655
			// // from description element
656
			// queryStrings.add("select distinct me.citation.id from TaxonNode as tn "
657
			// + "join tn.taxon.descriptions as d "
658
			// + "join d.descriptionElements as de "
659
			// + "join de.media as me "
660
			// + "where tn.classification=:classification "
661
			// + "and me.class=:referencedMediaBase "
662
			// + "and me.citation is not null ");
663
			//
664
			// // via NamedArea that has 2 media parameter
665
			// // and a waterbodyOrContinet that has media parameter and has
666
			// continent
667
			// // parameter
668
			// // which also has media parameter:
669
			//
670
			//
671
			//
672
			// // from CommonTaxonName or Distribution
673
			// queryStrings
674
			// .add("select distinct de.area.shape.citation.id, me1.citation.id, "
675
			// + "me2.citation.id, me3.citation.id from TaxonNode as tn "
676
			// + "join tn.taxon.descriptions as d "
677
			// + "join d.descriptionElements as de "
678
			// + "join de.area.media as me1 "
679
			// + "join de.area.waterbodiesOrCountries as wboc "
680
			// + "join wboc.media as me2 "
681
			// + "join wboc.continents as co "
682
			// + "join co.media as me3 "
683
			// + "where tn.classification=:classification "
684
			// + "and (de.class=:commonTaxonName or de.class=:distribution) "
685
			// + "and me1.class=:referencedMediaBase "
686
			// + "and me1.citation is not null "
687
			// + "and me2.class=:referencedMediaBase "
688
			// + "and me2.citation is not null "
689
			// + "and me3.class=:referencedMediaBase "
690
			// + "and me3.citation is not null "
691
			// + "and de.area.shape.class=:referencedMediaBase "
692
			// + "and de.area is not null "
693
			// + "and de.area.shape is not null ");
694
			//
695
			// parameters.put("commonTaxonName", "CommonTaxonName");
696
			// parameters.put("distribution", "Distribution");
697
			// //***
698
			// // from TaxonDescription:
699
			// queryStrings
700
			// .add("select distinct na.shape.citation.id, me1.citation.id, "
701
			// + "me2.citation.id, me3.citation.id from TaxonNode as tn "
702
			// + "join tn.taxon.descriptions as d "
703
			// + "join d.geoScopes as na " + "join na.media as me1 "
704
			// + "join na.waterbodiesOrCountries as wboc "
705
			// + "join wboc.media as me2 "
706
			// + "join wboc.continents as co "
707
			// + "join co.media as me3 "
708
			// + "where tn.classification=:classification "
709
			// + "and me1.class=:referencedMediaBase "
710
			// + "and me1.citation is not null "
711
			// + "and me2.class=:referencedMediaBase "
712
			// + "and me2.citation is not null "
713
			// + "and me3.class=:referencedMediaBase "
714
			// + "and me3.citation is not null "
715
			// + "and na.shape.class=:referencedMediaBase "
716
			// + "and na.shape is not null ");
717
			//
718
			// // from gathering event
719
			// queryStrings
720
			// .add("select fo.gatheringEvent.country.shape.citation.id, ca.shape.citation.id "
721
			// +
722
			// " from TaxonNode tn "
723
			// + "join tn.taxon.descriptions as db "
724
			// + "join db.describedSpecimenOrObservation as fo "
725
			// + "join fo.gatheringEvent.collectingAreas as ca "
726
			// + "where fo.class=:fieldObservation "
727
			// + "and fo.gatheringEvent is not null "
728
			// + "and fo.gatheringEvent.country is not null "
729
			// + "and fo.gatheringEvent.country.shape is not null "
730
			// + "and ca.shape is not null "
731
			// + "and ca.shape.class=:referencedMediaBase "
732
			// + "and ca.shape.citation is not null "
733
			// +
734
			// "and fo.gatheringEvent.country.shape.class=:referencedMediaBase "
735
			// + " and fo.gatheringEvent.country.shape.citation is not null "
736
			// + "and tn.classification=:classification ");
737
			//
738
			// // traverse to specimenOrObservation via individualsAssociation
739
			//
740
			// queryStrings
741
			// .add("select fo.gatheringEvent.country.shape.citation.id, ca.shape.citation.id "
742
			// + "from TaxonNode tn "
743
			// + "join tn.taxon.descriptions as db "
744
			// + "join db.descriptionElements as ia "
745
			// + "join ia.associatedSpecimenOrObservation as fo "
746
			// + "join fo.gatheringEvent.collectingAreas as ca "
747
			// + "where fo.class=:fieldObservation "
748
			// + "and fo.gatheringEvent is not null "
749
			// + "and fo.gatheringEvent.country is not null "
750
			// + "and fo.gatheringEvent.country.shape is not null "
751
			// + "and ca.shape is not null "
752
			// + "and ca.shape.class=:referencedMediaBase "
753
			// + "and ca.shape.citation is not null "
754
			// +
755
			// "and fo.gatheringEvent.country.shape.class=:referencedMediaBase "
756
			// + " and fo.gatheringEvent.country.shape.citation is not null "
757
			// + "and ia.class=:individualsAssociation "
758
			// + "and tn.classification=:classification ");
759
			//
760
			//
761
			//
762
			// parameters.put("fieldObservation", "FieldObservation");
763
			// parameters.put("referencedMediaBase", "ReferencedMediaBase");
764
			//
765
			// parameters.put("classification", classification);
766
			//
767
			// // via events
768
			// // ----------------------------------------
769
			// // determination event:
770
			// // taxa
771
			// queryStrings
772
			// .add("select distinct sor.id from DeterminationEvent dtev, TaxonNode tn "
773
			// + "join dtev.setOfReferences as sor "
774
			//
775
			// + "where tn.classification=:classification "
776
			// + "and tn.taxon=dtev.taxon ");
777
			//
778
			// // synonyms
779
			//
780
			// queryStrings
781
			// .add("select distinct sor.id from DeterminationEvent dtev, TaxonNode tn "
782
			// + "join dtev.setOfReferences as sor "
783
			// + "join tn.taxon.synonymRelations as syr "
784
			// + "join syr.relatedTo as sy "
785
			// + "where tn.classification=:classification "
786
			// + "and sy=dtev.taxon ");
787
			//
799 788
		}
800
		
801
		//------------------------------------------------------------------
789

  
790
		// ------------------------------------------------------------------
802 791
		// TODO get all objects that inherit IdentifiableEntity because it has
803 792
		// an
804 793
		// IdentifiableSource which inherits from OriginalSourceBase
......
809 798
		// the sources...
810 799
		// iterate in a certain depth REFERENCE_LINK_RECURSION_DEPTH
811 800

  
812
		//----------------------------------------------------------
813
		
814
		ids.addAll(processQueriesWithIdDistinctListResult(queryStrings,	parameters));
801
		// ----------------------------------------------------------
802

  
803
		ids.addAll(processQueriesWithIdDistinctListResult(queryStrings,
804
				parameters));
805

  
806
		return Long.valueOf(ids.size());
807
	}
808

  
809

  
810
	// TODO!!!
811
	// TODO this is the old reference counter where i counted the referenced
812
	// media as well and fetched ids from the database to erase dublettes
813
	@Override
814
	public Long countReferencesInClassification(Classification classification) {
815
		if (classification == null)
816
			return null; // or MAYDO: throw some Exception???
817

  
818
		// get all the descriptive source reference ids
819
		// ---------------------------------------------
820

  
821
		// preparation
822
		List<String> queryStrings = new ArrayList<String>();
823
		Map<String, Object> parameters = new HashMap<String, Object>();
824

  
825
		parameters.put("classification", classification);
826

  
827
		// get the ids from the Descriptive source references to add them to the
828
		// count
829
		Set<Integer> ids = listDescriptiveIds(true, classification);
830

  
831
		// get classification reference
832
		queryStrings.add("select c.reference.id from Classification as c "
833
				+ "where c.id=:classificationId ");
834
		// TODO ???
835
		// +"join c.souces as s "
836
		// +"join s.citation "
837

  
838
		parameters.put("classificationId", classification.getId());
839

  
840
		// get node relations references:
841
		queryStrings
842
				.add("select distinct tn.referenceForParentChildRelation.id as c from TaxonNode tn "
843
						+ "where tn.classification=:classification "
844
						+ "and tn.referenceForParentChildRelation is not null ");
845

  
846
		// get sec references
847
		// -------------------------------------------------------------------
848
		// taxa
849
		queryStrings
850
				.add("select distinct tn.taxon.sec.id as c from TaxonNode tn "
851
						+ "where tn.classification=:classification "
852
						+ "and tn.taxon.sec is not null ");
853

  
854
		// synonyms
855
		queryStrings
856
				.add("select distinct sr.relatedFrom.sec.id as c from TaxonNode tn "
857
						+ "join tn.taxon.synonymRelations sr "
858
						+ "where tn.classification=:classification "
859
						+ "and sr.relatedFrom.sec is not null ");
860

  
861
		// get relationship citations
862
		// ---------------------------------------------------------------
863

  
864
		// taxon relations
865
		queryStrings.add("select distinct tr.citation.id from TaxonNode tn "
866
				+ "join tn.taxon.relationsFromThisTaxon as tr "
867
				+ "where tn.classification=:classification "
868
				+ "and tn.taxon is not null " + "and tr.citation is not null ");
869

  
870
		// synonym relations
871

  
872
		queryStrings.add("select distinct sr.citation.id from TaxonNode tn "
873
				+ "join tn.taxon.synonymRelations as sr "
874
				+ "where tn.classification=:classification "
875
				+ "and tn.taxon is not null " + "and sr.citation is not null ");
876

  
877
		// get hybrid relation citations
878
		// Taxa:
879
		queryStrings.add("select distinct hr.citation.id from TaxonNode tn "
880
				+ "join tn.taxon.name.hybridParentRelations as hr "
881
				+ "where tn.classification=:classification "
882
				+ "and tn.taxon.name.class=:nonViralName "
883
				+ "and tn.taxon is not null "
884
				+ "and tn.taxon.name is not null ");
885

  
886
		parameters.put("nonViralName", "NonViralName");
887

  
888
		// synonyms:
889
		queryStrings.add("select distinct hr.citation.id from TaxonNode tn "
890
				+ "join tn.taxon.synonymRelations as syr "
891
				+ "join syr.relatedFrom as sy "
892
				+ "join sy.name.hybridParentRelations as hr "
893
				+ "where tn.classification=:classification "
894
				+ "and sy.name.class=:nonViralName " + "and sy is not null " // TODO:
895
																				// is
896
																				// this
897
																				// case
898
																				// actually
899
																				// possible???
900
				+ "and sy.name is not null ");
815 901

  
816
		
902
		// get name relations references:
903
		// -------------------------------------------------------
904
		// Taxa:
905
		queryStrings.add("select distinct nr.citation.id from TaxonNode tn "
906
				+ "join tn.taxon.name.relationsFromThisName as nr "
907
				+ "where tn.classification=:classification "
908
				+ "and tn.taxon is not null "
909
				+ "and tn.taxon.name is not null ");
910

  
911
		// synonyms:
912
		queryStrings.add("select distinct nr.citation.id from TaxonNode tn "
913
				+ "join tn.taxon.synonymRelations as syr "
914
				+ "join syr.relatedFrom as sy "
915
				+ "join sy.name.relationsFromThisName as nr "
916
				+ "where tn.classification=:classification "
917
				+ "and sy is not null " // TODO: is this case actually
918
										// possible???
919
				+ "and sy.name is not null ");
920

  
921
		// get Nomenclatural status citation
922

  
923
		// Taxa:
924
		queryStrings.add("select distinct s.citation.id from TaxonNode tn "
925
				+ "join tn.taxon.name.status as s "
926
				+ "where tn.classification=:classification "
927
				+ "and tn.taxon is not null "
928
				+ "and tn.taxon.name is not null ");
929

  
930
		// synonyms:
931
		queryStrings.add("select distinct s.citation.id from TaxonNode tn "
932
				+ "join tn.taxon.synonymRelations as syr "
933
				+ "join syr.relatedFrom as sy " + "join sy.name.status as s "
934
				+ "where tn.classification=:classification "
935
				+ "and sy is not null " // TODO: is this case actually
936
										// possible???
937
				+ "and sy.name is not null ");
938

  
939
		// get sequences which contain citations and publishedIn ------
940
		// and contain "Media" which could be of the subtype
941
		// "ReferencedMediaBase"
942
		// which has a citation
943

  
944
		queryStrings.add("select distinct cit.id " + " from TaxonNode tn "
945
				+ "join tn.taxon.descriptions as db "
946

  
947
				+ "join db.describedSpecimenOrObservation as so "
948
				+ "join so.sequences as seq " + "join seq.citations as cit "
949

  
950
				+ "where so.class=:dnaSample "
951
				+ "and tn.classification=:classification "
952
				+ "and cit is not null ");
953

  
954
		// traverse to specimenOrObservation via individualsAssociation
955

  
956
		queryStrings.add("select distinct cit.id from TaxonNode tn "
957
				+ "join tn.taxon.descriptions as db "
958
				+ "join db.descriptionElements as ia "
959
				+ "join ia.associatedSpecimenOrObservation as so "
960
				+ "join so.sequences as seq " + "join seq.citations as cit "
961

  
962
				+ "where so.class=:dnaSample "
963
				+ "and ia.class=:individualsAssociation "
964
				+ "and tn.classification=:classification "
965
				+ "and cit is not null ");
966

  
967
		// we do assume, that a name description would not have a
968
		// SpecimenOrObservation element
969

  
970
		//
971
		parameters.put("dnaSample", "DnaSample");
972
		parameters.put("individualsAssociation", "IndividualsAssociation");
973
		ids.addAll(processQueriesWithIdDistinctListResult(queryStrings,
974
				parameters));
817 975

  
818 976
		return Long.valueOf(ids.size());
819 977
	}
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/StatisticsServiceImpl.java
184 184
				case CLASSIFICATION:
185 185
					logger.info("there should not be any classification "
186 186
							+ "nested in an other classification");
187
					// so do nothing
187
					// so we set counter to 1, as a classification itself is one classification
188
					counter = new Long(1);
188 189
					break;
189 190
				case ACCEPTED_TAXA:
190 191
					counter = statisticsDao.countTaxaInClassification(

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)