Project

General

Profile

« Previous | Next » 

Revision 75d06679

Added by Andreas Müller about 13 years ago

latest xper adaptations

View differences:

XperCdmIntegration/src/main/java/eu/etaxonomy/cdm/io/xper/CdmXperAdapter.java
9 9

  
10 10
import org.apache.commons.lang.StringUtils;
11 11
import org.apache.log4j.Logger;
12
import org.hsqldb.NumberSequence;
12 13
import org.springframework.stereotype.Component;
13 14
import org.springframework.transaction.TransactionStatus;
14 15

  
......
32 33
import eu.etaxonomy.cdm.model.description.QuantitativeData;
33 34
import eu.etaxonomy.cdm.model.description.State;
34 35
import eu.etaxonomy.cdm.model.description.StateData;
36
import eu.etaxonomy.cdm.model.description.StatisticalMeasurementValue;
35 37
import eu.etaxonomy.cdm.model.description.TaxonDescription;
36 38
import eu.etaxonomy.cdm.model.description.WorkingSet;
37 39
import eu.etaxonomy.cdm.model.taxon.Taxon;
......
237 239

  
238 240
	public State adaptModeToState(Mode mode) {
239 241
		State state = State.NewInstance(mode.getDescription(), mode.getName(), null);
240
		mode.setUuid(state.getUuid());
242
		if (mode.getUuid() == null){
243
			mode.setUuid(state.getUuid());
244
		}else{
245
			state.setUuid(mode.getUuid());
246
		}
241 247
		return state;
242 248
	}
243 249
	
......
516 522
	}
517 523

  
518 524
	private void saveCategoricalFeature(Variable variable, Feature feature) {
519
		ITermService termService = getTermService();
520
		IVocabularyService vocService = getVocabularyService();
525
//		ITermService termService = getTermService();
526
//		IVocabularyService vocService = getVocabularyService();
521 527
		if (feature == null){
522
			saveNewFeature(variable, termService, vocService);
528
			saveNewFeature(variable);
523 529
		}else{
524 530
			if (isChanged(feature, variable)){
525 531
				feature.setLabel(variable.getName());
526
				termService.save(feature);
532
				getTermService().save(feature);
527 533
			}else{
528 534
				logger.info("No change for variable: " + variable.getName());
529 535
			}
......
542 548
						Language lang = Language.DEFAULT();
543 549
						Representation rep = state.getRepresentation(lang);
544 550
						rep.setLabel(stateLabel);
545
						termService.saveOrUpdate(state);
551
						getTermService().saveOrUpdate(state);
546 552
//						State state = State.NewInstance(stateDescription, stateLabel, stateAbbrev);
547 553
//						termService.save(state);
548 554
//						voc.addTerm(state);
......
593 599
			logger.warn("Multiple supported vocabularies not yet correctly implemented");
594 600
			voc = feature.getSupportedCategoricalEnumerations().iterator().next();
595 601
		}
596
		saveNewModeToVoc(termService, vocService, voc, mode);
602
		saveNewModeToVoc(termService, voc, mode);
597 603
		commitTransaction(ta);
598 604
	}
599 605
	
......
603 609
	 * @param termService
604 610
	 * @param vocService
605 611
	 */
606
	private void saveNewFeature(Variable variable, ITermService termService,
607
			IVocabularyService vocService) {
612
	private void saveNewFeature(Variable variable) {
608 613
		Feature feature;
609 614
		//new feature
610 615
		String description = null;
......
612 617
		String labelAbbrev = null;
613 618
		feature = Feature.NewInstance(description, label, labelAbbrev);
614 619
		variable.setUuid(feature.getUuid());
615
		termService.save(feature);
620
		getTermService().save(feature);
616 621
		//new voc
617 622
		String vocDescription = null;
618 623
		String vocLabel = "Vocabulary for feature " + label;
......
620 625
		String termSourceUri = null;
621 626
		TermVocabulary<State> voc = TermVocabulary.NewInstance(vocDescription, vocLabel, vocAbbrev, termSourceUri);
622 627
		for (Mode mode:variable.getModes()){
623
			saveNewModeToVoc(termService, vocService, voc, mode);
628
			saveNewModeToVoc(getTermService(), voc, mode);
624 629
		}
625 630
		feature.addSupportedCategoricalEnumeration(voc);
626
		termService.saveOrUpdate(feature);
631
		getTermService().saveOrUpdate(feature);
627 632
	}
628 633

  
629 634

  
......
633 638
	 * @param voc
634 639
	 * @param mode
635 640
	 */
636
	private void saveNewModeToVoc(ITermService termService, IVocabularyService vocService, TermVocabulary<State> voc, Mode mode) {
641
	private void saveNewModeToVoc(ITermService termService, TermVocabulary<State> voc, Mode mode) {
637 642
		State state = adaptModeToState(mode);
638 643
		termService.save(state);
639 644
		voc.addTerm(state);
640
		vocService.saveOrUpdate(voc);
645
		getVocabularyService().saveOrUpdate(voc);
641 646
	}
642 647

  
643 648

  
......
744 749
		return "CdmXperAdapter (" + ws + ")";
745 750
	}
746 751

  
747
	public void controlModeIndVar(boolean selected, Variable v, Individual i, Mode m) {
752
	public void controlModeIndVar(boolean selected, Variable var, Individual ind, Mode m) {
748 753
//		(boolean selected, Variable v, Individual i, Mode m);
749 754
		TransactionStatus txStatus = startTransaction();
750
		Taxon taxon = (Taxon)getTaxonService().find(i.getUuid());
751
		Feature feature = (Feature)getTermService().find(v.getUuid());
755
		Taxon taxon = (Taxon)getTaxonService().find(ind.getUuid());
756
		Feature feature = (Feature)getTermService().find(var.getUuid());
752 757
		Set<Feature> features = new HashSet<Feature>();
753 758
		features.add(feature);
754 759
		List<CategoricalData> catData = getDescriptionService().getDescriptionElementsForTaxon(taxon, features, CategoricalData.class, null, null, null);
......
794 799
	private void addModeToCategoricalData(Mode m, CategoricalData data) {
795 800
		StateData sd =  StateData.NewInstance();
796 801
		State state = (State)getTermService().find(m.getUuid());
802
		if (state == null){
803
			logger.warn("State not found: " + m.getName() + "; " + m.getUuid());
804
		}
797 805
		sd.setState(state);
798 806
		data.getStates().add(sd);
799 807
	}
800
	
801
	
802
	
808

  
809
	public void controlModeIndVar(Individual ind, Variable var, Double min,
810
			Double max, Double mean, Double sd, Double umethLower,
811
			Double umethUpper, Integer nSample) {
812
//		(boolean selected, Variable v, Individual i, Mode m);
813
		TransactionStatus txStatus = startTransaction();
814
		Taxon taxon = (Taxon)getTaxonService().find(ind.getUuid());
815
		Feature feature = (Feature)getTermService().find(var.getUuid());
816
		Set<Feature> features = new HashSet<Feature>();
817
		features.add(feature);
818
		List<QuantitativeData> quantData = getDescriptionService().getDescriptionElementsForTaxon(taxon, features, QuantitativeData.class, null, null, null);
819
		if (quantData.size()>1){
820
			logger.warn("There are more than one quantitative data for the same taxon and the same feature");
821
		}
822
		fr_jussieu_snv_lis.base.QuantitativeData qdXper = ind.getNumMatrix().get(var);
823
		if (qdXper == null ){
824
			//TODO needed?
825
		}
826
		
827
		
828
		if (quantData.size() == 0 ){
829
			QuantitativeData data = QuantitativeData.NewInstance();
830
			data.setFeature(feature);
831
			TaxonDescription desc = taxon.getDescriptions().iterator().next();
832
			desc.addElement(data);
833
//			addValuesToQuantitativeData(qdXper, data, min, max, 
834
//					mean, sd, umethLower, umethUpper, nSample);
835
			setQdValues(qdXper, data, min, max, mean, sd, umethLower, umethUpper, nSample);
836
			
837
			getDescriptionService().saveDescriptionElement(data);
838
		}else{
839
			for (QuantitativeData data: quantData){
840
				//TODO handle existing data better
841
				setQdValues(qdXper, data, min, max, mean, sd, umethLower, umethUpper, nSample);
842

  
843
				//test data exists
844
//				for (StateData sd : data.getStates()){
845
//					if (tmpState.equals(sd.getState())){
846
//						existingState = sd;
847
//						break;
848
//					}
849
//				}
850
				getDescriptionService().saveDescriptionElement(data);
851
			}
852
		}
853
		commitTransaction(txStatus);
854
		
855
	}
856

  
857
	/**
858
	 * @param qdXper
859
	 * @param data
860
	 * @param nSample 
861
	 * @param umethUpper 
862
	 * @param umethLower 
863
	 * @param sd 
864
	 * @param mean 
865
	 * @param max 
866
	 * @param min 
867
	 */
868
	private void setQdValues(fr_jussieu_snv_lis.base.QuantitativeData qdXper,
869
			QuantitativeData data, Double min, Double max, Double mean, Double sd, Double umethLower, Double umethUpper, Integer nSample) {
870
		data.setMinimum(getFloat(min), null);
871
		data.setMaximum(getFloat(max), null);
872
		data.setAverage(getFloat(mean), null);
873
		data.setStandardDeviation(getFloat(sd), null);
874
		data.setTypicalLowerBoundary(getFloat(umethLower), null);
875
		data.setTypicalUpperBoundary(getFloat(umethUpper), null);
876
		data.setSampleSize(getFloat(nSample), null);
877
	}
878

  
879
	private Float getFloat(Number myNumber) {
880
		Float result = (myNumber == null) ? null : myNumber.floatValue();
881
		return result;
882
	}
803 883

  
804 884
}
XperCdmIntegration/src/main/java/eu/etaxonomy/cdm/io/xper/CdmXperBaseControler.java
589 589
	@Override
590 590
	public void controlModeIndVar(boolean selected, Variable v, Individual i, Mode m) {
591 591
		this.cdmXperAdapter.controlModeIndVar(selected, v, i, m);
592
		super.controlModeIndVar(selected, v, i, m);
592 593
	}
593 594

  
594 595
	/* (non-Javadoc)
......
598 599
	public void controlModeIndVarRec(boolean selected, Variable v, Individual i, Mode m) {
599 600
		logger.warn("controlModeIndVarRec Not yet implemented");
600 601
	}
602
	
603
	@Override
604
	public void controlNumValue(Individual ind, Variable var, Double min,
605
			Double max, Double mean, Double sd, Double umethLower,
606
			Double umethUpper, Integer nSample) {
607
		this.cdmXperAdapter.controlModeIndVar(ind, var, min, max, mean, sd, 
608
				umethLower, umethUpper, nSample);
609
		super.controlNumValue(ind, var, min, max, mean, sd, umethLower, umethUpper,
610
				nSample);
611
	}
601 612

  
602 613
	/* (non-Javadoc)
603 614
	 * @see fr_jussieu_snv_lis.base.IControlerBase#checkBadDescription(fr_jussieu_snv_lis.base.Variable, fr_jussieu_snv_lis.base.Individual)
......
1025 1036
	@Override
1026 1037
	public void moveVariableTo(int i, Variable v) {
1027 1038
		logger.warn("moveVariableTo Not yet implemented");
1028

  
1029 1039
	}
1030 1040

  
1031 1041
	/* (non-Javadoc)
......
1034 1044
	@Override
1035 1045
	public void moveVariablesTo(int i, List<Variable> a) {
1036 1046
		logger.warn("moveVariablesTo Not yet implemented");
1037

  
1038 1047
	}
1039 1048

  
1040 1049
	/* (non-Javadoc)
......
1043 1052
	@Override
1044 1053
	public void moveGroupTo(int i, Group g) {
1045 1054
		logger.warn("moveGroupTo Not yet implemented");
1046

  
1047 1055
	}
1048 1056

  
1057

  
1049 1058
}

Also available in: Unified diff