Project

General

Profile

« Previous | Next » 

Revision 3dff50a1

Added by Andreas Müller about 13 years ago

new implementation for Xper data fetching from persistence and some further changes to Xper

View differences:

XperCdmIntegration/src/main/java/eu/etaxonomy/cdm/io/xper/BaseCdm.java
19 19

  
20 20
import org.apache.commons.lang.StringUtils;
21 21
import org.apache.log4j.Logger;
22
import org.hibernate.validator.util.GetConstructor;
23 22

  
24 23
import eu.etaxonomy.cdm.api.application.CdmApplicationUtils;
25
import eu.etaxonomy.cdm.common.CdmUtils;
26 24
import fr_jussieu_snv_lis.base.BaseObject;
27 25
import fr_jussieu_snv_lis.base.BaseObjectResource;
28 26
import fr_jussieu_snv_lis.base.Group;
......
233 231
	public List<Individual> getIndividuals() {
234 232
		if (cdmIndividuals == null){
235 233
			cdmIndividuals = new ArrayList<Individual>();
236
			getAdapter().loadTaxaAndDescription();
234
			getAdapter().loadTaxa();
237 235
		}
238 236
		return cdmIndividuals;
239 237
	}
......
243 241
	 */
244 242
	@Override
245 243
	public Individual getIndividualAt(int i) {
246
		logger.warn("getIndividualAt Not yet implemented");
247
		return null;
244
		return this.cdmIndividuals.get(i);
248 245
	}
249 246

  
250 247
	/* (non-Javadoc)
......
440 437
	 */
441 438
	@Override
442 439
	public int getNbIndividuals() {
443
		logger.warn("getNbIndividuals Not yet implemented");
444
		return 0;
440
		return this.cdmIndividuals.size();
445 441
	}
446 442

  
447 443
	/* (non-Javadoc)
......
450 446
	@Override
451 447
	public void setNbIndividuals(int n) {
452 448
		logger.warn("setNbIndividuals Not yet implemented");
453

  
454 449
	}
455 450

  
456 451
	/* (non-Javadoc)
......
710 705
	 */
711 706
	@Override
712 707
	public Set<String> getLinks() {
713
		logger.warn("getLinks Not yet implemented");
714
		return null;
715
	}
716

  
717
	/* (non-Javadoc)
718
	 * @see fr_jussieu_snv_lis.base.IBase#getLinkAt(int)
719
	 */
720
	@Override
721
	public String getLinkAt(int i) {
722
		logger.warn("getLinkAt Not yet implemented");
723
		return null;
708
		logger.warn("getLinks Not yet implemented. Returns empty list");
709
		return new HashSet<String>();
724 710
	}
725 711

  
726 712
	/* (non-Javadoc)
XperCdmIntegration/src/main/java/eu/etaxonomy/cdm/io/xper/CdmXperAdapter.java
1 1
package eu.etaxonomy.cdm.io.xper;
2 2

  
3
import java.util.ArrayList;
4
import java.util.Arrays;
5 3
import java.util.HashMap;
6 4
import java.util.List;
5
import java.util.Map;
7 6
import java.util.Set;
8 7
import java.util.UUID;
9 8

  
10 9
import org.apache.commons.lang.StringUtils;
11 10
import org.apache.log4j.Logger;
11
import org.springframework.stereotype.Component;
12 12
import org.springframework.transaction.TransactionStatus;
13 13

  
14
import eu.etaxonomy.cdm.api.application.CdmApplicationController;
15 14
import eu.etaxonomy.cdm.api.service.ITermService;
16 15
import eu.etaxonomy.cdm.api.service.IVocabularyService;
17 16
import eu.etaxonomy.cdm.api.service.pager.Pager;
18 17
import eu.etaxonomy.cdm.common.CdmUtils;
18
import eu.etaxonomy.cdm.io.common.CdmIoBase;
19
import eu.etaxonomy.cdm.io.common.IoStateBase;
19 20
import eu.etaxonomy.cdm.model.common.CdmBase;
20 21
import eu.etaxonomy.cdm.model.common.DefinedTermBase;
21 22
import eu.etaxonomy.cdm.model.common.Language;
22 23
import eu.etaxonomy.cdm.model.common.Representation;
23 24
import eu.etaxonomy.cdm.model.common.TermVocabulary;
25
import eu.etaxonomy.cdm.model.common.UuidAndTitleCache;
24 26
import eu.etaxonomy.cdm.model.description.CategoricalData;
25
import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
26 27
import eu.etaxonomy.cdm.model.description.Feature;
27 28
import eu.etaxonomy.cdm.model.description.FeatureNode;
28 29
import eu.etaxonomy.cdm.model.description.FeatureTree;
......
30 31
import eu.etaxonomy.cdm.model.description.QuantitativeData;
31 32
import eu.etaxonomy.cdm.model.description.State;
32 33
import eu.etaxonomy.cdm.model.description.StateData;
33
import eu.etaxonomy.cdm.model.description.TaxonDescription;
34 34
import eu.etaxonomy.cdm.model.description.WorkingSet;
35
import eu.etaxonomy.cdm.model.taxon.Taxon;
36 35
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
37 36
import fr_jussieu_snv_lis.XPApp;
37
import fr_jussieu_snv_lis.Xper;
38 38
import fr_jussieu_snv_lis.IO.IExternalAdapter;
39
import fr_jussieu_snv_lis.base.BaseObjectResource;
40 39
import fr_jussieu_snv_lis.base.Individual;
41 40
import fr_jussieu_snv_lis.base.Mode;
42 41
import fr_jussieu_snv_lis.base.Variable;
43
import fr_jussieu_snv_lis.base.XPResource;
44 42
import fr_jussieu_snv_lis.utils.Utils;
45 43

  
46
public class CdmXperAdapter implements IExternalAdapter{
44
@Component
45
public class CdmXperAdapter extends CdmIoBase implements IExternalAdapter{
47 46
	private static final Logger logger = Logger.getLogger(CdmXperAdapter.class);
48 47
	
49 48
	TransactionStatus tx;
49
	
50
	private CdmXperAdapter  adapter = this;
50 51

  
51
	private CdmApplicationController cdmApplicationController;
52
//	private CdmApplicationController cdmApplicationController;
52 53
	private CdmXperBaseControler baseController;
53 54
	private UUID uuidWorkingSet;
54
	private WorkingSet workingSet; 
55
//	private WorkingSet workingSet; 
55 56
	
57
	//TODO preliminary
58
	//CONFIGURATION
59
	private boolean isLazyModes = false;
60
	private boolean isLazyIndMatrix = true;
61
	private boolean useSecInTaxonName = false;
56 62
	
57
	public CdmXperAdapter(CdmApplicationController appCtr, UUID uuidWorkingSet) {
58
		this.uuidWorkingSet = uuidWorkingSet;
59
		setCdmApplicationController(appCtr);
60
		BaseCdm base = new BaseCdm(); 
61
		setBaseController(new CdmXperBaseControler(base, this));
63
	public CdmXperAdapter(){
64
		BaseCdm base = new BaseCdm();
65
		CdmXperBaseControler baseController = new CdmXperBaseControler(base, this);
66
		setBaseController(baseController);
62 67
	}
63 68
	
64
//************************* GETTER /SETTER **********************/	
65

  
66
	public void setCdmApplicationController(CdmApplicationController appCtr) {
67
		this.cdmApplicationController = appCtr;
68
		 tx = cdmApplicationController.startTransaction();
69
	public boolean startXper(UUID uuidWorkingSet){
70
		this.uuidWorkingSet = uuidWorkingSet;
71
		Thread t = new Thread() {
72
			public void run() {
73
				new Xper(adapter);
74
			}
75
			
76
		};
77
		System.out.println("xper2 start");
78
		t.start();
79
//		while(!XPApp.xperReady){
80
//			//TODO
81
//		}
82
//		System.out.println("xper2 started :::");
83
		return true;
69 84
	}
70 85

  
71

  
72
//	public CdmApplicationController getCdmApplicationController() {
73
//		return cdmApplicationController;
74
//	}
75

  
86
	
87
//************************* GETTER /SETTER **********************/	
76 88

  
77 89
	public void setBaseController(CdmXperBaseControler baseController) {
78 90
		this.baseController = baseController;
......
86 98
	}
87 99

  
88 100
	public WorkingSet getWorkingSet() {
89
		if (this.workingSet == null){
90
			this.workingSet = cdmApplicationController.getWorkingSetService().find(uuidWorkingSet);
91
		}
101
//		if (this.workingSet == null){
102
			WorkingSet workingSet = getWorkingSetService().find(uuidWorkingSet);
103
//		}
92 104
		return workingSet;
93 105
	}
94 106
	
107
	public WorkingSet getLanguage() {
108
		
109
//		if (this.workingSet == null){
110
			WorkingSet workingSet = getWorkingSetService().find(uuidWorkingSet);
111
//		}
112
		return workingSet;
113
	}
95 114
	
96 115
	
97 116
	
......
99 118
	
100 119
	public void load(){
101 120
		loadFeatures();
102
		loadTaxaAndDescription();
103

  
121
		loadTaxa();
104 122
	}
105 123

  
106 124
	// Load the featureTree with the UUID
107 125
	public void loadFeatures() {
126
		logger.warn("load features start");
108 127
		TransactionStatus tx = startTransaction();
109 128
		
110 129
		FeatureTree featureTree = getWorkingSet().getDescriptiveSystem();
111
		this.cdmApplicationController.getWorkingSetService().saveOrUpdate(workingSet);
130
		getFeatureTreeService().saveOrUpdate(featureTree);
112 131
		
113
//		UUID featureTreeUUID = UUID.fromString("1045f91b-6f1a-4a7d-8783-82a58a01ab25");
114
////		UUID featureTreeUUID = UUID.fromString("43ab1efd-fa15-419a-8cd6-05477e4b37bc");
115
//		List<String> featureTreeInit = Arrays.asList(new String[]{"root.children.feature.representations"});
116
//		
117
//		TransactionStatus tx = cdmApplicationController.startTransaction();
118
//		FeatureTree featureTree = cdmApplicationController.getFeatureTreeService().load(featureTreeUUID, featureTreeInit);
119 132
		if (featureTree != null) {
120 133
			loadFeatureNode(featureTree.getRoot(), -1);
121 134
		}else{
122 135
			logger.warn("No feature tree available");
123 136
		}
124 137
		commitTransaction(tx);
138
		logger.warn("load features end :::");
125 139
	}
126 140

  
127 141

  
......
162 176
//				result.add(variable);
163 177
				
164 178
				if(child.getFeature().isSupportsCategoricalData()){
165
					// Add states to the character
166
					Set<TermVocabulary<State>> termVocabularySet = child.getFeature().getSupportedCategoricalEnumerations();
167
					for(TermVocabulary<State> termVocabulary : termVocabularySet){
168
						for(State state : termVocabulary.getTerms()){
169
							Mode mode = adaptStateToMode(state);
170
							variable.addMode(mode);
171
						}
179
					// Add states to the feature
180
					if (! isLazyModes){
181
						addModesToVariable(child, variable);
172 182
					}
173
				}else if (child.getFeature().isSupportsQuantitativeData()) {
174
					// Specify the character type (numerical)
175
					variable.setType(Utils.numType);
176 183
				}
177 184
				
178 185
				if(indiceParent != -1 && XPApp.getCurrentBase().getVariableAt(indiceParent) != null){
......
189 196
		return;
190 197
	}
191 198

  
199
	/**
200
	 * @param child
201
	 * @param variable
202
	 */
203
	private void addModesToVariable(FeatureNode child, Variable variable) {
204
		Set<TermVocabulary<State>> termVocabularySet = child.getFeature().getSupportedCategoricalEnumerations();
205
		for(TermVocabulary<State> termVocabulary : termVocabularySet){
206
			for(State state : termVocabulary.getTerms()){
207
				Mode mode = adaptStateToMode(state);
208
				variable.addMode(mode);
209
			}
210
		}
211
	}
212

  
192 213
	/**
193 214
	 * @param child
194 215
	 * @return
......
196 217
	private Variable adaptFeatureNodeToVariable(FeatureNode child) {
197 218
		Variable variable = new Variable(child.getFeature().getLabel());
198 219
		variable.setUuid(child.getFeature().getUuid());
220
		if (child.getFeature().isSupportsQuantitativeData()){
221
			// Specify the character type (numerical)
222
			variable.setType(Utils.numType);
223
		}else if (child.getFeature().isSupportsCategoricalData()){
224
			variable.setType(Utils.catType);
225
		}
199 226
		return variable;
200 227
	}
201 228
	
......
213 240
		return state;
214 241
	}
215 242
	
243
// ******************** TAXON - INDIVIDUAL ***********************************/
244

  
245
	/**
246
	 * @param taxonBase
247
	 * @return
248
	 */
249
	public Individual adaptTaxonToIndividual(TaxonBase taxonBase) {
250
		String name = useSecInTaxonName? taxonBase.getTitleCache() : taxonBase.getName().getTitleCache();
251
		Individual individual = new Individual(name);
252
		individual.setUuid(taxonBase.getUuid());
253
		return individual;
254
	}
255
	
216 256
// ******************************** ******************************************/	
257
//    // OLD
258
//	// Load all the taxa and 1 description
259
//	public void loadTaxaAndDescription() {
260
//		logger.warn("load taxa start");
261
//		//fill all variables with empty lists
262
//
263
//		
264
//		TransactionStatus tx = startTransaction();
265
//		
266
//		getWorkingSet().getDescriptions();
267
//		
268
//		logger.warn("load taxa from CDM");
269
//		List<TaxonBase> taxonList = getTaxonService().list(Taxon.class , null, null, null, null);
270
//		
271
//		for(TaxonBase taxonBase : taxonList){
272
//			if (XPApp.getCurrentBase() != null) {
273
//				
274
//				// Add a image to the taxon
275
//				BaseObjectResource bor = new BaseObjectResource(new XPResource("http://www.cheloniophilie.com/Images/Photos/Chelonia-mydas/tortue-marine.JPG"));
276
//                individual.addResource(bor); 
277
//                
278
//				// Add an empty description
279
//                
280
//                loadDescription(individual, taxonBase);
281
//                
282
//			}
283
//		}
284
//		commitTransaction(tx);
285
//		logger.warn("load taxa end :::");
286
//	}
217 287

  
218
	// Load all the taxa and 1 description
219
	public void loadTaxaAndDescription() {
220
		TransactionStatus tx = startTransaction();
221
		List<TaxonBase> taxonList = cdmApplicationController.getTaxonService().list(Taxon.class , null, null, null, null);
222
		for(TaxonBase taxonBase : taxonList){
223
			if (XPApp.getCurrentBase() != null) {
224
				Individual individual = new Individual(taxonBase.getName().toString());
225
				individual.setUuid(taxonBase.getUuid());
226
				
227
				// Add a image to the taxon
228
				BaseObjectResource bor = new BaseObjectResource(new XPResource("http://www.cheloniophilie.com/Images/Photos/Chelonia-mydas/tortue-marine.JPG"));
229
                individual.addResource(bor); 
230
                
231
				// Add an empty description
232
                List<Variable> vars = XPApp.getCurrentBase().getVariables();
233
				for(Variable var : vars){
234
					individual.addMatrix(var, new ArrayList<Mode>());
235
				}
236
				loadDescription(individual, taxonBase);
237
				XPApp.getCurrentBase().addIndividual(individual);
238
			}
288

  
289
	/**
290
	 * Load taxa and convert to individuals.
291
	 * Loads the 
292
	 *  - uuid
293
	 *  - name
294
	 *  - varModMatrix, 
295
	 *  - varNumValuesMatrix
296
	 *  - varComment (TODO)
297
	 *  - varUnknown (TODO)
298
	 */
299
	public void loadTaxa(){
300
		//categorical data
301
		logger.warn("load categorical data");
302
		Map<UuidAndTitleCache, Map<UUID, Set<CategoricalData>>> categoricalData = getCategoricalData();
303
		handleCategoricalData(categoricalData);
304
		logger.warn("load categorical data :::");
305
		
306
		//quantitative data
307
		logger.warn("load quantitative data");
308
		Map<UuidAndTitleCache, Map<UUID, Set<QuantitativeData>>> quantitativeData = getQuantitativeData();
309
		handleQuantitativeData(quantitativeData);
310
		logger.warn("load quantitative data :::");
311
		
312
		//TODO
313
		//descriptions with no data
314
		
315
		//TODO varComment
316
		
317
		//TODO varUnknown
318
		
319
		//TODO Resources
320
		
321
//		TODO private String index;
322
//		TODO private String description;
323

  
324
		
325
		
326
	}
327

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

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

  
343

  
344

  
345
	private void handleCategoricalData(Map<UuidAndTitleCache, Map<UUID, Set<CategoricalData>>> categoricalData) {
346
		for (UuidAndTitleCache taxon : categoricalData.keySet()){
347
			Map<UUID, Set<CategoricalData>> variableMap = categoricalData.get(taxon);
348
			Individual individual = getIndividualByUuidAndTitleCache(taxon);
349
			
350
			handleCategoricalData(variableMap, individual);
351
		}
352
	}
353
	
354
	private void handleQuantitativeData(Map<UuidAndTitleCache, Map<UUID, Set<QuantitativeData>>> quantitativeData) {
355
		for (UuidAndTitleCache taxon : quantitativeData.keySet()){
356
			Map<UUID, Set<QuantitativeData>> variableMap = quantitativeData.get(taxon);
357
			Individual individual = getIndividualByUuidAndTitleCache(taxon);
358
			handleQuantitativeData(variableMap, individual);
239 359
		}
240
		commitTransaction(tx);
241 360
	}
242 361

  
243
	// Load the first taxonDescription
244
	public void loadDescription(Individual individual, TaxonBase taxonBase) {
245
		
246
		Pager<TaxonDescription> taxonDescriptionPager = cdmApplicationController.getDescriptionService().getTaxonDescriptions((Taxon)taxonBase, null, null, null, 0, Arrays.asList(new String[]{"elements.states", "elements.feature"} ));
247
		List<TaxonDescription> taxonDescriptionList = taxonDescriptionPager.getRecords();
248
		TaxonDescription taxonDescription = taxonDescriptionList.get(0);
249
		Set<DescriptionElementBase> DescriptionElementBaseList = taxonDescription.getElements();
250
		for(DescriptionElementBase descriptionElementBase : DescriptionElementBaseList){
251
			if(descriptionElementBase instanceof CategoricalData){
252
				// find the xper variable corresponding
253
				Variable variable = null;
254
				List<Variable> vars = XPApp.getCurrentBase().getVariables();
255
				for(Variable var : vars){
256
					if(var.getUuid().equals(((CategoricalData)descriptionElementBase).getFeature().getUuid())){
257
						variable = var;
258
					}
259
				}
260
				if(variable != null){
362

  
363
	private void handleCategoricalData(Map<UUID, Set<CategoricalData>> variableMap, Individual individual) {
364
		for (UUID featureUuid : variableMap.keySet()){
365
			Variable variable = baseController.findVariableByUuid(featureUuid);
366
			if (variable != null){
367
				for (CategoricalData categorical : variableMap.get(featureUuid)) {
261 368
					// create a list of xper Mode corresponding
262 369
					List<Mode> modesList = variable.getModes();
263
					List<StateData> stateList = ((CategoricalData)descriptionElementBase).getStates();
264
					for(StateData state : stateList){
265
						for(Mode mode : modesList){
266
							if(state.getState().getUuid().equals(mode.getUuid())){
370
					List<StateData> stateDataList = categorical.getStates();
371
					for (StateData state : stateDataList) {
372
						for (Mode mode : modesList) {
373
							if (state.getState().getUuid().equals(mode.getUuid())) {
267 374
								// Add state to the Description
268 375
								individual.addModeMatrix(variable, mode);
269 376
							}
270 377
						}
271 378
					}
272 379
				}
273
			}else if(descriptionElementBase instanceof QuantitativeData){
274
				// find the xper variable corresponding
275
				Variable variable = null;
276
				List<Variable> vars = XPApp.getCurrentBase().getVariables();
277
				for(Variable var : vars){
278
					if(var.getUuid().equals(((QuantitativeData)descriptionElementBase).getFeature().getUuid())){
279
						variable = var;
280
					}
281
				}
282
				if(variable != null){
283
					fr_jussieu_snv_lis.base.QuantitativeData qdXper = new fr_jussieu_snv_lis.base.QuantitativeData();
284
					QuantitativeData qdCDM = ((QuantitativeData)descriptionElementBase);
285
					
286
					if(qdCDM.getMax() != null)
287
						qdXper.setMax(new Double(qdCDM.getMax()));
288
					if(qdCDM.getMin() != null)
289
						qdXper.setMin(new Double(qdCDM.getMin()));
290
					if(qdCDM.getTypicalLowerBoundary() != null)
291
						qdXper.setUmethLower(new Double(qdCDM.getTypicalLowerBoundary()));
292
					if(qdCDM.getTypicalUpperBoundary() != null)
293
						qdXper.setUmethUpper(new Double(qdCDM.getTypicalUpperBoundary()));
294
					
295
					// Does not work
296
					//qdXper.setMean(new Double(qdCDM.getAverage()));
297
					//qdXper.setSd(new Double(qdCDM.getStandardDeviation()));
298
					//qdXper.setNSample(new Double(qdCDM.getSampleSize()));
299
					
380
			}else{
381
				logger.warn("Variable not found for uuid " +  featureUuid.toString());
382
			}
383
		}
384
	}
385
	
386
	
387
	private void handleQuantitativeData(Map<UUID, Set<QuantitativeData>> variableMap, Individual individual) {
388
		for (UUID featureUuid : variableMap.keySet()){
389
			Variable variable = baseController.findVariableByUuid(featureUuid);
390
			if (variable != null){
391
				for (QuantitativeData qdCDM : variableMap.get(featureUuid)){
392
					fr_jussieu_snv_lis.base.QuantitativeData qdXper = adaptQdCdm2QdXper(qdCDM);
300 393
					individual.addNumMatrix(variable, qdXper);
301 394
				}
302
				
395
			}else{
396
				logger.warn("Variable not found for uuid " +  featureUuid.toString());
303 397
			}
304 398
		}
305 399
	}
306
	
307
	// Create a workingSet if not exist
308
	public void createWorkingSet(){
400

  
401
	/**
402
	 * @param qdCDM
403
	 * @return
404
	 */
405
	private fr_jussieu_snv_lis.base.QuantitativeData adaptQdCdm2QdXper(
406
			QuantitativeData qdCDM) {
407
		fr_jussieu_snv_lis.base.QuantitativeData qdXper = new fr_jussieu_snv_lis.base.QuantitativeData();
309 408
		
310
		if(cdmApplicationController.getWorkingSetService().list(WorkingSet.class, null, null, null, null).size() <= 0){
311
			WorkingSet ws = WorkingSet.NewInstance();
312
			
313
			UUID featureTreeUUID = UUID.fromString("47eda782-89c7-4c69-9295-e4052ebe16c6");
314
			List<String> featureTreeInit = Arrays.asList(new String[]{"root.children.feature.representations"});
315
			
316
			FeatureTree featureTree = cdmApplicationController.getFeatureTreeService().load(featureTreeUUID, featureTreeInit);
317
			ws.setDescriptiveSystem(featureTree);
318
			
319
			List<TaxonBase> taxonList = cdmApplicationController.getTaxonService().list(Taxon.class , null, null, null, null);
320
			for(TaxonBase taxonBase : taxonList){
321
				Pager<TaxonDescription> taxonDescriptionPager = cdmApplicationController.getDescriptionService().getTaxonDescriptions((Taxon)taxonBase, null, null, null, 0, Arrays.asList(new String[]{"elements.states", "elements.feature"} ));
322
				List<TaxonDescription> taxonDescriptionList = taxonDescriptionPager.getRecords();
323
				TaxonDescription taxonDescription = taxonDescriptionList.get(0);
324
				ws.addDescription(taxonDescription);
325
				System.out.println(taxonDescription.getUuid());
326
			}
327
			
328
			cdmApplicationController.getWorkingSetService().save(ws);
409
		if (qdCDM.getMax() != null){
410
			qdXper.setMax(new Double(qdCDM.getMax()));
411
		}
412
		if (qdCDM.getMin() != null){
413
			qdXper.setMin(new Double(qdCDM.getMin()));
329 414
		}
415
		if (qdCDM.getTypicalLowerBoundary() != null){
416
			qdXper.setUmethLower(new Double(qdCDM
417
					.getTypicalLowerBoundary()));
418
		}
419
		if (qdCDM.getTypicalUpperBoundary() != null){
420
			qdXper.setUmethUpper(new Double(qdCDM
421
					.getTypicalUpperBoundary()));
422
		}
423
		if (qdCDM.getAverage() != null){
424
			qdXper.setMean(new Double(qdCDM.getAverage()));
425
		}
426
		if (qdCDM.getStandardDeviation() != null){
427
			qdXper.setSd(new Double(qdCDM.getStandardDeviation()));
428
		}
429
		if (qdCDM.getSampleSize() != null){
430
			qdXper.setNSample(new Integer(Math.round(qdCDM.getSampleSize())));
431
		}
432
		return qdXper;
433
	}
434
	
435
	
436
	private Individual getIndividualByUuidAndTitleCache(UuidAndTitleCache taxon) {
437
		Individual result = this.getBaseController().findIndividualByName(taxon.getTitleCache());
438
		if (result == null){
439
			result= new Individual(taxon.getTitleCache());
440
			result.setUuid(taxon.getUuid());
441
			this.getBaseController().addIndividual(result);
442
		}
443
		return result;
330 444
	}
331 445

  
446

  
447
//	// Create a workingSet if not exist
448
//	public void createWorkingSet(){
449
//		
450
//		if(getWorkingSetService().list(WorkingSet.class, null, null, null, null).size() <= 0){
451
//			WorkingSet ws = WorkingSet.NewInstance();
452
//			
453
//			UUID featureTreeUUID = UUID.fromString("47eda782-89c7-4c69-9295-e4052ebe16c6");
454
//			List<String> featureTreeInit = Arrays.asList(new String[]{"root.children.feature.representations"});
455
//			
456
//			FeatureTree featureTree = getFeatureTreeService().load(featureTreeUUID, featureTreeInit);
457
//			ws.setDescriptiveSystem(featureTree);
458
//			
459
//			List<TaxonBase> taxonList = getTaxonService().list(Taxon.class , null, null, null, null);
460
//			for(TaxonBase taxonBase : taxonList){
461
//				Pager<TaxonDescription> taxonDescriptionPager = getDescriptionService().getTaxonDescriptions((Taxon)taxonBase, null, null, null, 0, Arrays.asList(new String[]{"elements.states", "elements.feature"} ));
462
//				List<TaxonDescription> taxonDescriptionList = taxonDescriptionPager.getRecords();
463
//				TaxonDescription taxonDescription = taxonDescriptionList.get(0);
464
//				ws.addDescription(taxonDescription);
465
//				System.out.println(taxonDescription.getUuid());
466
//			}
467
//			
468
//			getWorkingSetService().save(ws);
469
//		}
470
//	}
471

  
472
// ************************************ SAVE *************************************/	
473
	
332 474
	@Override
333 475
	public void save() {
334 476
		List<Variable> vars = XPApp.getCurrentBase().getVariables();
......
345 487
	 * @param vars
346 488
	 */
347 489
	private void saveFeatures(List<Variable> vars) {
348
		tx = cdmApplicationController.startTransaction();
490
		tx = startTransaction();
349 491
		for (Variable variable : vars){
350 492
			Feature feature = getFeature(variable);
351 493
			if (Utils.numType.equals(variable.getType())){
......
356 498
				logger.warn("variable type undefined");
357 499
			}
358 500
		}
359
		cdmApplicationController.commitTransaction(tx);
501
		commitTransaction(tx);
360 502
	}
361 503

  
362 504

  
......
366 508
	 */
367 509
	public Feature getFeature(Variable variable) {
368 510
		UUID uuid = variable.getUuid();
369
		ITermService termService = cdmApplicationController.getTermService();
511
		ITermService termService = getTermService();
370 512
		DefinedTermBase<?> term = termService.find(uuid);
371 513
		Feature feature = CdmBase.deproxy(term, Feature.class);
372 514
		return feature;
373 515
	}
374 516

  
375 517
	private void saveCategoricalFeature(Variable variable, Feature feature) {
376
		ITermService termService = cdmApplicationController.getTermService();
377
		IVocabularyService vocService = cdmApplicationController.getVocabularyService();
518
		ITermService termService = getTermService();
519
		IVocabularyService vocService = getVocabularyService();
378 520
		if (feature == null){
379 521
			saveNewFeature(variable, termService, vocService);
380 522
		}else{
......
428 570

  
429 571
	public void saveNewState(Mode mode, Feature feature) {
430 572
		TransactionStatus ta = startTransaction();
431
		ITermService termService = cdmApplicationController.getTermService();
432
		IVocabularyService vocService = cdmApplicationController.getVocabularyService();
573
		ITermService termService = getTermService();
574
		IVocabularyService vocService = getVocabularyService();
433 575
		
434 576
		termService.saveOrUpdate(feature);
435 577
		int numberOfVocs = feature.getSupportedCategoricalEnumerations().size();
......
519 661

  
520 662

  
521 663
	private void saveNumericalFeature(Variable variable, Feature feature) {
522
		ITermService termService = cdmApplicationController.getTermService();
523
		IVocabularyService vocService = cdmApplicationController.getVocabularyService();
664
//		IVocabularyService vocService = getVocabularyService();
524 665
		String variableUnit = variable.getUnit();
525 666
		Set<MeasurementUnit> units = feature.getRecommendedMeasurementUnits();
526 667
		//preliminary
......
542 683
			}
543 684
			if (! unitExists){
544 685
				units.clear();
545
				MeasurementUnit existingUnit = findExistingUnit(variableUnit, termService);
686
				MeasurementUnit existingUnit = findExistingUnit(variableUnit);
546 687
				if (existingUnit == null){
547 688
					String unitDescription = null;
548 689
					String unitLabel = variableUnit;
549 690
					String labelAbbrev = null;
550 691
					MeasurementUnit newUnit = MeasurementUnit.NewInstance(unitDescription, unitLabel, labelAbbrev);
551
					termService.save(newUnit);
692
					getTermService().save(newUnit);
552 693
					UUID defaultMeasurmentUnitVocabularyUuid = UUID.fromString("3b82c375-66bb-4636-be74-dc9cd087292a");
553
					TermVocabulary voc = vocService.find(defaultMeasurmentUnitVocabularyUuid);
694
					TermVocabulary voc = getVocabularyService().find(defaultMeasurmentUnitVocabularyUuid);
554 695
					if (voc == null){
555 696
						logger.warn("Could not find MeasurementService vocabulary");
556 697
					}else{
557 698
						voc.addTerm(newUnit);
558
						vocService.saveOrUpdate(voc);
699
						getVocabularyService().saveOrUpdate(voc);
559 700
					}
560 701
					existingUnit = newUnit;
561 702
				}
......
565 706
	}
566 707

  
567 708

  
568
	private MeasurementUnit findExistingUnit(String variableUnit, ITermService termService) {
569
		Pager<MeasurementUnit> existingUnits = termService.findByRepresentationText(variableUnit, MeasurementUnit.class, null, null);
709
	private MeasurementUnit findExistingUnit(String variableUnit) {
710
		Pager<MeasurementUnit> existingUnits = getTermService().findByRepresentationText(variableUnit, MeasurementUnit.class, null, null);
570 711
		for (MeasurementUnit exUnit : existingUnits.getRecords()){
571 712
			if (variableUnit.equals(exUnit.getLabel())){
572 713
				return exUnit;
......
576 717
	}
577 718

  
578 719

  
579
	/**
580
	 * @param tx
581
	 */
582
	private void commitTransaction(TransactionStatus tx) {
583
		cdmApplicationController.commitTransaction(tx);
720
// ************************** Override ********************************/	
721
	
722
	@Override
723
	protected boolean doInvoke(IoStateBase state) {
724
		//not needed
725
		return false;
584 726
	}
585 727

  
586
	/**
587
	 * @return
588
	 */
589
	private TransactionStatus startTransaction() {
590
		TransactionStatus tx = cdmApplicationController.startTransaction();
591
		return tx;
728
	@Override
729
	protected boolean doCheck(IoStateBase state) {
730
		//not needed
731
		return false;
592 732
	}
733

  
734
	@Override
735
	protected boolean isIgnore(IoStateBase state) {
736
		//not needed
737
		return false;
738
	}
739

  
740
	@Override
741
	public String toString() {
742
		String ws = uuidWorkingSet == null ?"-" : uuidWorkingSet.toString();
743
		return "CdmXperAdapter (" + ws + ")";
744
	}
745
	
746
	
593 747
	
594 748

  
595 749
}
XperCdmIntegration/src/main/java/eu/etaxonomy/cdm/io/xper/CdmXperBaseControler.java
10 10
package eu.etaxonomy.cdm.io.xper;
11 11

  
12 12
import java.util.List;
13
import java.util.UUID;
13 14

  
14 15
import org.apache.log4j.Logger;
15 16

  
......
436 437
	 */
437 438
	@Override
438 439
	public boolean matchNumValue(Individual ind, Variable var, Double value) {
439
		logger.warn("matchNumValue Not yet implemented");
440
		return false;
440
		logger.info("matchNumValue implemented by using super");
441
		return super.matchNumValue(ind, var, value);
441 442
	}
442 443

  
443 444
	/* (non-Javadoc)
......
508 509
	 */
509 510
	@Override
510 511
	public void addIndividual(Individual ind) {
511
		logger.warn("addIndividual Not yet implemented");
512

  
512
		super.addIndividual(ind);
513 513
	}
514 514

  
515 515
	/* (non-Javadoc)
......
526 526
	 */
527 527
	@Override
528 528
	public Individual findIndividualByName(String ind) {
529
		logger.warn("findIndividualByName Not yet implemented");
530
		return null;
529
		return super.findIndividualByName(ind);
531 530
	}
532 531

  
533 532
	/* (non-Javadoc)
......
616 615
	 */
617 616
	@Override
618 617
	public boolean checkingUnknown(Variable var, Individual ind) {
619
		logger.warn("checkingUnknown Not yet implemented");
620
		return false;
618
		return super.checkingUnknown(var, ind);
621 619
	}
622 620

  
623 621
	/* (non-Javadoc)
......
625 623
	 */
626 624
	@Override
627 625
	public void checkUnknown(Variable var, Individual ind, boolean b, boolean withDaughters) {
628
		logger.warn("checkUnknown Not yet implemented");
629

  
626
		super.checkUnknown(var, ind, b, withDaughters);
630 627
	}
631 628

  
632 629
	/* (non-Javadoc)
633 630
	 * @see fr_jussieu_snv_lis.base.IControlerBase#checkUnknown(fr_jussieu_snv_lis.base.Variable, fr_jussieu_snv_lis.base.Individual[], boolean, boolean)
634 631
	 */
635 632
	@Override
636
	public void checkUnknown(Variable var, Individual[] tab, boolean b,
637
			boolean withDaughters) {
638
		logger.warn("checkUnknown(var,tab, b, withDaughters) Not yet implemented");
639

  
633
	public void checkUnknown(Variable var, Individual[] tab, boolean b, boolean withDaughters) {
634
		super.checkUnknown(var, tab, b, withDaughters);
640 635
	}
641 636

  
642 637
	/* (non-Javadoc)
......
725 720
	 */
726 721
	@Override
727 722
	public Variable findVariableByName(String str) {
728
		logger.warn("findVariableByName Not yet implemented");
723
		logger.warn("findVariableByName implemented as super");
724
		return super.findVariableByName(str);
725
	}
726
	
727
	/**
728
	 * Returns the variable with variable.uuid equal to uuid. 
729
	 * Returns <code>null</code> if no such variable exists or
730
	 * if <code>uuid == null</code>
731
	 * @param uuid
732
	 * @return
733
	 */
734
	public Variable findVariableByUuid(UUID uuid) {
735
		if (uuid == null){
736
			return null;
737
		}
738
		//TODO improve performance by storing variables also in a
739
		//hashmap
740
		for (Variable var : base.getVariables()) {
741
			if (uuid.equals(var.getUuid())) {
742
				return var;
743
			}
744
		}
729 745
		return null;
730 746
	}
731 747

  
......
734 750
	 */
735 751
	@Override
736 752
	public boolean checkExistanceOneVariable(String s) {
737
		logger.warn("checkExistanceOneVariable Not yet implemented");
738
		return false;
753
		logger.warn("checkExistanceOneVariable implemented as super");
754
		return super.checkExistanceOneVariable(s);
739 755
	}
740 756

  
741 757
	/* (non-Javadoc)
......
789 805
	@Override
790 806
	public void addNewVariableAndItsModesToMatrix(Variable newVariable) {
791 807
		logger.warn("addNewVariableAndItsModesToMatrix Not yet implemented");
792

  
793 808
	}
794 809

  
795 810
	/* (non-Javadoc)
......
798 813
	@Override
799 814
	public void addNewVariableNumAndItsModesToMatrix(Variable newVariable) {
800 815
		logger.warn("addNewVariableNumAndItsModesToMatrix Not yet implemented");
801

  
802 816
	}
803 817

  
804 818
	/* (non-Javadoc)
......
807 821
	@Override
808 822
	public void deleteVariableFromMatrix(Variable variable) {
809 823
		logger.warn("deleteVariableFromMatrix Not yet implemented");
810

  
811 824
	}
812 825

  
813 826
	/* (non-Javadoc)
......
816 829
	@Override
817 830
	public void deleteVariable(Variable va) {
818 831
		logger.warn("deleteVariable Not yet implemented");
819

  
820 832
	}
821 833

  
822 834
	/* (non-Javadoc)
......
825 837
	@Override
826 838
	public void deleteVariableAndAllDaughters(Variable v) {
827 839
		logger.warn("deleteVariableAndAllDaughters Not yet implemented");
828

  
829 840
	}
830 841

  
831 842
	/* (non-Javadoc)
......
834 845
	@Override
835 846
	public void deleteVariablesAndAllDaughters(Variable[] tab) {
836 847
		logger.warn("deleteVariablesAndAllDaughters Not yet implemented");
837

  
838 848
	}
839 849

  
840 850
	/* (non-Javadoc)
......
852 862
	@Override
853 863
	public void deleteVariablesWithoutDaughters(Variable[] tab) {
854 864
		logger.warn("deleteVariablesWithoutDaughters Not yet implemented");
855

  
856 865
	}
857 866

  
858 867
	/* (non-Javadoc)
......
865 874
		return null;
866 875
	}
867 876

  
868
	/* (non-Javadoc)
869
	 * @see fr_jussieu_snv_lis.base.IControlerBase#getVariableDaughters(java.util.List, fr_jussieu_snv_lis.base.Variable)
870
	 */
871
	@Override
872
	public List<Variable> getVariableDaughters(List<Variable> listDaugther,
873
			Variable v) {
874
		logger.warn("getVariableDaughters Not yet implemented");
875
		return null;
876
	}
877

  
878 877
	/* (non-Javadoc)
879 878
	 * @see fr_jussieu_snv_lis.base.IControlerBase#getVariableDaughters(fr_jussieu_snv_lis.base.Variable)
880 879
	 */
881 880
	@Override
882 881
	public List<Variable> getVariableDaughters(Variable v) {
883
		logger.warn("getVariableDaughters Not yet implemented");
884
		return null;
882
		return super.getVariableDaughters(v);
885 883
	}
886 884

  
887 885
	/* (non-Javadoc)
XperCdmIntegration/src/test/java/eu/etaxonomy/cdm/io/xper/TestAdapterCdmXper.java
24 24
	 * 
25 25
	 */
26 26
	private boolean startApplications() {
27
		boolean result = false;
27 28
		DbSchemaValidation dbSchemaValidation = DbSchemaValidation.VALIDATE;
28 29
		ICdmDataSource datasource = CdmDestinations.cdm_test_local_xper();
29 30
		System.out.println("cdm start");
......
36 37
			return false;
37 38
		}else{
38 39
			UUID uuidWorkingSet =  workingSets.iterator().next().getUuid();
39
			adapterCdmXper = new CdmXperAdapter(appCtr, uuidWorkingSet);
40
			
41
			adapterCdmXper = (CdmXperAdapter)appCtr.getBean("cdmXperAdapter");
42
//			adapterCdmXper = new CdmXperAdapter(appCtr, uuidWorkingSet);
43
			result =  adapterCdmXper.startXper(uuidWorkingSet);
40 44
		}
45

  
46
		return result;
41 47
		
42
		
43
		
44
		Thread t = new Thread() {
45
			public void run() {
46
				new Xper(adapterCdmXper);
47
			}
48
		};
49
		System.out.println("xper2 start");
50
		t.start();
51
		while(!XPApp.xperReady){
52
			//TODO wait
53
		}
54
		System.out.println("xper2 started :::");
55
		return true;
56 48
	}
57 49
	
58 50
	public void xperloadDataFromCdm(){
......
139 131
	 * @param args
140 132
	 */
141 133
	public static void main(String[] args) {
142
		System.out.println("start test");
134
		System.out.println("start test adapter");
143 135
		//start CDM and Xper
144 136
		TestAdapterCdmXper testAdapter = new TestAdapterCdmXper();
145 137
		boolean success = testAdapter.startApplications();
138
		while(!XPApp.xperReady){
139
			try {
140
				Thread.sleep(200);
141
			} catch (InterruptedException e) {
142
				e.printStackTrace();
143
			}
144
		}
145
		System.out.println("xper2 started :::");
146 146
		if (success){
147 147
			testAdapter.createThumbnailDirectory();
148 148
			if (args.length >= 1 && "-p".equals(args[0]) ){
......
156 156
				testAdapter.generateThumbnails();
157 157
			}
158 158
		}else{
159
			System.out.println("end test adapter with errors");
159 160
			System.exit(-1);
161

  
160 162
		}
163
		System.out.println("end test adapter");
161 164

  
162 165
		
163 166
	}

Also available in: Unified diff