1
|
package eu.etaxonomy.taxeditor.editor;
|
2
|
|
3
|
import java.net.URI;
|
4
|
import java.net.URISyntaxException;
|
5
|
import java.util.List;
|
6
|
import java.util.UUID;
|
7
|
|
8
|
import org.eclipse.core.runtime.IProgressMonitor;
|
9
|
import org.eclipse.ui.IMemento;
|
10
|
|
11
|
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
|
12
|
import eu.etaxonomy.cdm.api.service.IFeatureTreeService;
|
13
|
import eu.etaxonomy.cdm.api.service.ITermService;
|
14
|
import eu.etaxonomy.cdm.api.service.IVocabularyService;
|
15
|
import eu.etaxonomy.cdm.model.common.MarkerType;
|
16
|
import eu.etaxonomy.cdm.model.common.TermVocabulary;
|
17
|
import eu.etaxonomy.cdm.model.description.Feature;
|
18
|
import eu.etaxonomy.cdm.model.description.FeatureNode;
|
19
|
import eu.etaxonomy.cdm.model.description.FeatureTree;
|
20
|
import eu.etaxonomy.cdm.model.description.Modifier;
|
21
|
import eu.etaxonomy.cdm.model.description.State;
|
22
|
import eu.etaxonomy.taxeditor.model.ContextListenerAdapter;
|
23
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
24
|
import eu.etaxonomy.taxeditor.store.StoreUtil;
|
25
|
|
26
|
public class UseObjectManager extends ContextListenerAdapter{
|
27
|
@Override
|
28
|
public void contextRefresh(IProgressMonitor monitor) {
|
29
|
monitor.subTask("Refreshing the Uses View");
|
30
|
StoreUtil.warn(getClass(), "Refreshing Uses View warn");
|
31
|
setupNecessaryItems(monitor);
|
32
|
}
|
33
|
|
34
|
|
35
|
@Override
|
36
|
public void contextStart(IMemento memento, IProgressMonitor monitor) {
|
37
|
monitor.subTask("Starting the Uses View");
|
38
|
StoreUtil.warn(getClass(), "Starting Uses View warn");
|
39
|
setupNecessaryItems(monitor);
|
40
|
}
|
41
|
|
42
|
private void setupNecessaryItems(IProgressMonitor monitor) {
|
43
|
MarkerType existingMarkertype = (MarkerType) CdmStore.getService(ITermService.class).find(UUID.fromString("2e6e42d9-e92a-41f4-899b-03c0ac64f039"));
|
44
|
TermVocabulary<State> stateVocabulary = (TermVocabulary<State>) CdmStore.getService(IVocabularyService.class).find(UUID.fromString("67430d7c-fd43-4e9d-af5e-d0dca3f74931"));
|
45
|
Feature featureUseRecord = (Feature) CdmStore.getService(ITermService.class).find(UUID.fromString("8125a59d-b4d5-4485-89ea-67306297b599"));
|
46
|
TermVocabulary<Modifier> countryVocabulary = (TermVocabulary<Modifier>) CdmStore.getService(IVocabularyService.class).find(UUID.fromString("116c51f1-e63a-46f7-a258-e1149a42868b"));
|
47
|
TermVocabulary<Modifier> plantPartVocabulary = (TermVocabulary<Modifier>) CdmStore.getService(IVocabularyService.class).find(UUID.fromString("369914fe-d54b-4063-99ce-abc81d30ad35"));
|
48
|
TermVocabulary<Modifier> humanGroupVocabulary = (TermVocabulary<Modifier>) CdmStore.getService(IVocabularyService.class).find(UUID.fromString("ca46cea5-bdf7-438d-9cd8-e2793d2178dc"));
|
49
|
|
50
|
ConversationHolder conversation = CdmStore.createConversation();
|
51
|
if (existingMarkertype == null) {
|
52
|
existingMarkertype = MarkerType.NewInstance("use", "use", null);
|
53
|
existingMarkertype.setUuid( UUID.fromString("2e6e42d9-e92a-41f4-899b-03c0ac64f039"));
|
54
|
TermVocabulary<MarkerType> markerTypeVocabulary = (TermVocabulary<MarkerType>)CdmStore.getService(IVocabularyService.class).find((UUID.fromString("19dffff7-e142-429c-a420-5d28e4ebe305")));
|
55
|
markerTypeVocabulary.addTerm(existingMarkertype);
|
56
|
CdmStore.getService(IVocabularyService.class).saveOrUpdate(markerTypeVocabulary);
|
57
|
conversation.commit(true);
|
58
|
}
|
59
|
if (stateVocabulary == null) {
|
60
|
monitor.subTask("stateVocabulary empty");
|
61
|
URI termSourceUri = null;
|
62
|
try {
|
63
|
termSourceUri = new URI("eu.etaxonomy.cdm.model.description.State");
|
64
|
} catch (URISyntaxException e) {
|
65
|
e.printStackTrace();
|
66
|
}
|
67
|
stateVocabulary = TermVocabulary.NewInstance("Use Category", "Use Category", null, termSourceUri);
|
68
|
stateVocabulary.setUuid(UUID.fromString("67430d7c-fd43-4e9d-af5e-d0dca3f74931"));
|
69
|
State newDummyState = State.NewInstance("Dummy Use Cat", "Dummy Use Cat", null);
|
70
|
State newDummySubCat = State.NewInstance("Dummy Use Sub Cat", "Dummy Use Sub Cat", null);
|
71
|
newDummyState.addIncludes(newDummySubCat);
|
72
|
stateVocabulary.addTerm(newDummyState);
|
73
|
CdmStore.getService(IVocabularyService.class).saveOrUpdate(stateVocabulary);
|
74
|
conversation.commit(true);
|
75
|
}
|
76
|
if (countryVocabulary == null) {
|
77
|
monitor.subTask("countryVocabulary empty");
|
78
|
URI termSourceUri = null;
|
79
|
try {
|
80
|
termSourceUri = new URI("eu.etaxonomy.cdm.model.description.Modifier");
|
81
|
} catch (URISyntaxException e) {
|
82
|
e.printStackTrace();
|
83
|
}
|
84
|
countryVocabulary = TermVocabulary.NewInstance("Country", "Country", null, termSourceUri);
|
85
|
countryVocabulary.setUuid(UUID.fromString("116c51f1-e63a-46f7-a258-e1149a42868b"));
|
86
|
|
87
|
Modifier newDummyModifier = Modifier.NewInstance("Dummy Country", "Dummy Country", null);
|
88
|
countryVocabulary.addTerm(newDummyModifier);
|
89
|
CdmStore.getService(IVocabularyService.class).saveOrUpdate(countryVocabulary);
|
90
|
conversation.commit(true);
|
91
|
}
|
92
|
if (plantPartVocabulary == null) {
|
93
|
monitor.subTask("plantPartVocabulary empty");
|
94
|
URI termSourceUri = null;
|
95
|
try {
|
96
|
termSourceUri = new URI("eu.etaxonomy.cdm.model.description.Modifier");
|
97
|
} catch (URISyntaxException e) {
|
98
|
e.printStackTrace();
|
99
|
}
|
100
|
plantPartVocabulary = TermVocabulary.NewInstance("Plant Part", "Plant Part", null, termSourceUri);
|
101
|
plantPartVocabulary.setUuid(UUID.fromString("369914fe-d54b-4063-99ce-abc81d30ad35"));
|
102
|
Modifier newDummyModifier = Modifier.NewInstance("Dummy Plant Part", "Dummy Plant Part", null);
|
103
|
plantPartVocabulary.addTerm(newDummyModifier);
|
104
|
CdmStore.getService(IVocabularyService.class).saveOrUpdate(plantPartVocabulary);
|
105
|
conversation.commit(true);
|
106
|
}
|
107
|
if (humanGroupVocabulary == null) {
|
108
|
monitor.subTask("humanGroupVocabulary empty");
|
109
|
URI termSourceUri = null;
|
110
|
try {
|
111
|
termSourceUri = new URI("eu.etaxonomy.cdm.model.description.Modifier");
|
112
|
} catch (URISyntaxException e) {
|
113
|
e.printStackTrace();
|
114
|
}
|
115
|
humanGroupVocabulary = TermVocabulary.NewInstance("Human Group", "Human Group", null, termSourceUri);
|
116
|
humanGroupVocabulary.setUuid(UUID.fromString("ca46cea5-bdf7-438d-9cd8-e2793d2178dc"));
|
117
|
Modifier newDummyModifier = Modifier.NewInstance("Dummy Human Group", "Dummy Human Group", null);
|
118
|
Modifier newSubDummyModifier = Modifier.NewInstance("Dummy Ethnic Group", "Dummy Ethnic Group", null);
|
119
|
newDummyModifier.addIncludes(newSubDummyModifier);
|
120
|
humanGroupVocabulary.addTerm(newDummyModifier);
|
121
|
CdmStore.getService(IVocabularyService.class).saveOrUpdate(humanGroupVocabulary);
|
122
|
conversation.commit(true);
|
123
|
}
|
124
|
if(featureUseRecord == null) {
|
125
|
featureUseRecord = Feature.NewInstance("Use Record", "Use Record", null);
|
126
|
featureUseRecord.setUuid(UUID.fromString("8125a59d-b4d5-4485-89ea-67306297b599"));
|
127
|
featureUseRecord.isSupportsCategoricalData();
|
128
|
featureUseRecord.setSupportsCategoricalData(true);
|
129
|
TermVocabulary<Feature> featureVocabulary = (TermVocabulary<Feature>)CdmStore.getService(IVocabularyService.class).find((UUID.fromString("b187d555-f06f-4d65-9e53-da7c93f8eaa8")));
|
130
|
featureVocabulary.addTerm(featureUseRecord);
|
131
|
|
132
|
FeatureTree palmWebFeatureTree = CdmStore.getService(IFeatureTreeService.class).find(UUID.fromString("72ccce05-7cc8-4dab-8e47-bf3f5fd848a0"));
|
133
|
//List<FeatureTree> featureTrees = CdmStore.getService(IFeatureTreeService.class).list(FeatureTree.class, null, null, null, null);
|
134
|
FeatureNode useRecFeatureNode = FeatureNode.NewInstance(featureUseRecord);
|
135
|
|
136
|
palmWebFeatureTree.getRoot().addChild(useRecFeatureNode);
|
137
|
|
138
|
CdmStore.getService(IVocabularyService.class).saveOrUpdate(featureVocabulary);
|
139
|
CdmStore.getService(IFeatureTreeService.class).saveOrUpdate(palmWebFeatureTree);
|
140
|
conversation.commit(true);
|
141
|
|
142
|
}
|
143
|
|
144
|
|
145
|
conversation.close();
|
146
|
}
|
147
|
}
|