Project

General

Profile

« Previous | Next » 

Revision ed898dfc

Added by Andreas Müller almost 13 years ago

improve Xper adapter

View differences:

XperCdmIntegration/src/main/java/eu/etaxonomy/cdm/io/xper/CdmXperAdapter.java
1 1
package eu.etaxonomy.cdm.io.xper;
2 2

  
3 3
import java.util.HashMap;
4
import java.util.HashSet;
4 5
import java.util.List;
5 6
import java.util.Map;
6 7
import java.util.Set;
......
31 32
import eu.etaxonomy.cdm.model.description.QuantitativeData;
32 33
import eu.etaxonomy.cdm.model.description.State;
33 34
import eu.etaxonomy.cdm.model.description.StateData;
35
import eu.etaxonomy.cdm.model.description.TaxonDescription;
34 36
import eu.etaxonomy.cdm.model.description.WorkingSet;
37
import eu.etaxonomy.cdm.model.taxon.Taxon;
35 38
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
36 39
import fr_jussieu_snv_lis.XPApp;
37 40
import fr_jussieu_snv_lis.Xper;
......
45 48
public class CdmXperAdapter extends CdmIoBase implements IExternalAdapter{
46 49
	private static final Logger logger = Logger.getLogger(CdmXperAdapter.class);
47 50
	
48
	TransactionStatus tx;
49
	
50 51
	private CdmXperAdapter  adapter = this;
51 52

  
52 53
//	private CdmApplicationController cdmApplicationController;
......
330 331
	 */
331 332
	private Map<UuidAndTitleCache, Map<UUID, Set<CategoricalData>>> getCategoricalData() {
332 333
		Map<UuidAndTitleCache, Map<UUID, Set<CategoricalData>>> data = getWorkingSetService().getTaxonFeatureDescriptionElementMap(
333
				CategoricalData.class, uuidWorkingSet, null, null, null, null);
334
				CategoricalData.class, uuidWorkingSet, null);
334 335
		return data;
335 336
	}
336 337

  
337 338
	private Map<UuidAndTitleCache, Map<UUID, Set<QuantitativeData>>> getQuantitativeData() {
338 339
		Map<UuidAndTitleCache, Map<UUID, Set<QuantitativeData>>> data = getWorkingSetService().getTaxonFeatureDescriptionElementMap(
339
				QuantitativeData.class, uuidWorkingSet, null, null, null, null);
340
				QuantitativeData.class, uuidWorkingSet, null);
340 341
		return data;
341 342
	}
342 343

  
......
368 369
					// create a list of xper Mode corresponding
369 370
					List<Mode> modesList = variable.getModes();
370 371
					List<StateData> stateDataList = categorical.getStates();
371
					for (StateData state : stateDataList) {
372
					for (StateData stateData : stateDataList) {
372 373
						for (Mode mode : modesList) {
373
							if (state.getState().getUuid().equals(mode.getUuid())) {
374
							if (stateData.getState().getUuid().equals(mode.getUuid())) {
374 375
								// Add state to the Description
375 376
								individual.addModeMatrix(variable, mode);
376 377
							}
......
487 488
	 * @param vars
488 489
	 */
489 490
	private void saveFeatures(List<Variable> vars) {
490
		tx = startTransaction();
491
		TransactionStatus tx = startTransaction();
491 492
		for (Variable variable : vars){
492 493
			Feature feature = getFeature(variable);
493 494
			if (variable.isNumType()){
......
742 743
		String ws = uuidWorkingSet == null ?"-" : uuidWorkingSet.toString();
743 744
		return "CdmXperAdapter (" + ws + ")";
744 745
	}
746

  
747
	public void controlModeIndVar(boolean selected, Variable v, Individual i, Mode m) {
748
//		(boolean selected, Variable v, Individual i, Mode m);
749
		TransactionStatus txStatus = startTransaction();
750
		Taxon taxon = (Taxon)getTaxonService().find(i.getUuid());
751
		Feature feature = (Feature)getTermService().find(v.getUuid());
752
		Set<Feature> features = new HashSet<Feature>();
753
		features.add(feature);
754
		List<CategoricalData> catData = getDescriptionService().getDescriptionElementsForTaxon(taxon, features, CategoricalData.class, null, null, null);
755
		if (catData.size()>1){
756
			logger.warn("There is more than one categorical data for the same taxon and the same feature");
757
		}
758
		if (selected && catData.size() == 0 ){
759
			CategoricalData data = CategoricalData.NewInstance();
760
			data.setFeature(feature);
761
			TaxonDescription desc = taxon.getDescriptions().iterator().next();
762
			desc.addElement(data);
763
			addModeToCategoricalData(m, data);
764
			getDescriptionService().saveDescriptionElement(data);
765
		}else{
766
			for (CategoricalData data: catData){
767
				State tmpState = adaptModeToState(m);
768
				StateData existingState = null;
769
				//test data exists
770
				for (StateData sd : data.getStates()){
771
					if (tmpState.equals(sd.getState())){
772
						existingState = sd;
773
						break;
774
					}
775
				}
776
				if (selected && existingState == null){
777
					//selected
778
					addModeToCategoricalData(m, data);
779
				}else if (!selected && existingState != null){
780
					//unselected
781
					data.getStates().remove(existingState);
782
				}
783
				getDescriptionService().saveDescriptionElement(data);
784
			}
785
		}
786
		commitTransaction(txStatus);
787
		
788
	}
789

  
790
	/**
791
	 * @param m
792
	 * @param data
793
	 */
794
	private void addModeToCategoricalData(Mode m, CategoricalData data) {
795
		StateData sd =  StateData.NewInstance();
796
		State state = (State)getTermService().find(m.getUuid());
797
		sd.setState(state);
798
		data.getStates().add(sd);
799
	}
745 800
	
746 801
	
747 802
	
XperCdmIntegration/src/main/java/eu/etaxonomy/cdm/io/xper/CdmXperBaseControler.java
588 588
	 */
589 589
	@Override
590 590
	public void controlModeIndVar(boolean selected, Variable v, Individual i, Mode m) {
591
		logger.warn("controlModeIndVar Not yet implemented");
592

  
591
		this.cdmXperAdapter.controlModeIndVar(selected, v, i, m);
593 592
	}
594 593

  
595 594
	/* (non-Javadoc)
......
598 597
	@Override
599 598
	public void controlModeIndVarRec(boolean selected, Variable v, Individual i, Mode m) {
600 599
		logger.warn("controlModeIndVarRec Not yet implemented");
601

  
602 600
	}
603 601

  
604 602
	/* (non-Javadoc)

Also available in: Unified diff