1
|
/**
|
2
|
* Copyright (C) 2018 EDIT
|
3
|
* European Distributed Institute of Taxonomy
|
4
|
* http://www.e-taxonomy.eu
|
5
|
*
|
6
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
7
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
8
|
*/
|
9
|
package eu.etaxonomy.taxeditor.editor.workingSet.matrix;
|
10
|
|
11
|
import java.util.ArrayList;
|
12
|
import java.util.Collection;
|
13
|
import java.util.HashSet;
|
14
|
import java.util.List;
|
15
|
import java.util.Random;
|
16
|
import java.util.UUID;
|
17
|
|
18
|
import eu.etaxonomy.cdm.api.service.ITermService;
|
19
|
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
|
20
|
import eu.etaxonomy.cdm.model.description.CategoricalData;
|
21
|
import eu.etaxonomy.cdm.model.description.Character;
|
22
|
import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
|
23
|
import eu.etaxonomy.cdm.model.description.Feature;
|
24
|
import eu.etaxonomy.cdm.model.description.FeatureNode;
|
25
|
import eu.etaxonomy.cdm.model.description.QuantitativeData;
|
26
|
import eu.etaxonomy.cdm.model.description.SpecimenDescription;
|
27
|
import eu.etaxonomy.cdm.model.description.State;
|
28
|
import eu.etaxonomy.cdm.model.occurrence.DerivedUnit;
|
29
|
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
|
30
|
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationType;
|
31
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
32
|
|
33
|
/**
|
34
|
* @author pplitzner
|
35
|
* @since Jan 11, 2018
|
36
|
*
|
37
|
*/
|
38
|
public class SpecimenGenerator {
|
39
|
|
40
|
private static final int SPECIMEN_COUNT = 1;
|
41
|
|
42
|
public Collection<SpecimenOrObservationBase> generate(){
|
43
|
Collection<SpecimenOrObservationBase> specimens = new HashSet<>();
|
44
|
List<DescriptionElementBase> descriptionElements = new ArrayList<>();
|
45
|
|
46
|
// descriptionElements.add(generateQuantitativeData("leaf", "length"));
|
47
|
// descriptionElements.add(generateCategoricalData("leaf", "color"));
|
48
|
|
49
|
for(int i=0;i<SPECIMEN_COUNT;i++){
|
50
|
specimens.add(generateSpecimen());
|
51
|
}
|
52
|
return specimens;
|
53
|
}
|
54
|
|
55
|
private SpecimenOrObservationBase generateSpecimen(){
|
56
|
List<DescriptionElementBase> descriptionElements = new ArrayList<>();
|
57
|
descriptionElements.add(generateQuantitativeData("leaf", "length"));
|
58
|
|
59
|
DerivedUnit specimen = DerivedUnit.NewInstance(SpecimenOrObservationType.PreservedSpecimen);
|
60
|
SpecimenDescription description = SpecimenDescription.NewInstance(specimen);
|
61
|
descriptionElements.forEach(descriptionElement->{
|
62
|
initQuantitativeData(descriptionElement);
|
63
|
description.addElement(descriptionElement);
|
64
|
});
|
65
|
specimen.setAccessionNumber("GEN");
|
66
|
return specimen;
|
67
|
}
|
68
|
|
69
|
private QuantitativeData generateQuantitativeData(String structure, String property){
|
70
|
// Character character = Character.NewInstance(generateFeatureNode(structure), generateFeatureNode(property));
|
71
|
Character character = HibernateProxyHelper.deproxy(CdmStore.getService(ITermService.class).load(UUID.fromString("9cceec0e-06c2-48b9-85cf-bf4cb29b71ab")), Character.class);
|
72
|
QuantitativeData data = QuantitativeData.NewInstance(character);
|
73
|
return data;
|
74
|
}
|
75
|
|
76
|
private CategoricalData generateCategoricalData(String structure, String property){
|
77
|
// Character character = Character.NewInstance(generateFeatureNode(structure), generateFeatureNode(property));
|
78
|
Character character = (Character) CdmStore.getService(ITermService.class).load(UUID.fromString("74dbd215-20b6-4cdd-89cb-dacb81b4a7a4"));
|
79
|
CategoricalData data = CategoricalData.NewInstance(character);
|
80
|
return data;
|
81
|
}
|
82
|
|
83
|
private void initQuantitativeData(DescriptionElementBase descriptionElement){
|
84
|
if(descriptionElement.isInstanceOf(QuantitativeData.class)){
|
85
|
QuantitativeData data = HibernateProxyHelper.deproxy(descriptionElement, QuantitativeData.class);
|
86
|
Random random = new Random();
|
87
|
data.setMinimum(random.nextFloat()*10, null);
|
88
|
data.setMaximum(random.nextFloat()*10, null);
|
89
|
}
|
90
|
else if(descriptionElement.isInstanceOf(CategoricalData.class)){
|
91
|
CategoricalData data = HibernateProxyHelper.deproxy(descriptionElement, CategoricalData.class);
|
92
|
Random random = new Random();
|
93
|
String nextInt = "State: "+random.nextInt();
|
94
|
|
95
|
State state = State.NewInstance(nextInt, nextInt, nextInt);
|
96
|
data.addStateData(state);
|
97
|
}
|
98
|
}
|
99
|
|
100
|
private FeatureNode generateFeatureNode(String label){
|
101
|
Feature feature = Feature.NewInstance(label, label, label);
|
102
|
FeatureNode featureNode = FeatureNode.NewInstance(feature);
|
103
|
return featureNode;
|
104
|
}
|
105
|
|
106
|
}
|