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 |
}
|
new implementation for Xper data fetching from persistence and some further changes to Xper