1
|
/**
|
2
|
* Copyright (C) 2011 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.store;
|
10
|
|
11
|
import java.net.URI;
|
12
|
import java.net.URISyntaxException;
|
13
|
|
14
|
import org.eclipse.core.runtime.IProgressMonitor;
|
15
|
import org.eclipse.core.runtime.NullProgressMonitor;
|
16
|
|
17
|
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
|
18
|
import eu.etaxonomy.cdm.api.service.ITermService;
|
19
|
import eu.etaxonomy.cdm.api.service.IVocabularyService;
|
20
|
import eu.etaxonomy.cdm.model.common.DefinedTerm;
|
21
|
import eu.etaxonomy.cdm.model.common.MarkerType;
|
22
|
import eu.etaxonomy.cdm.model.common.TermType;
|
23
|
import eu.etaxonomy.cdm.model.common.TermVocabulary;
|
24
|
import eu.etaxonomy.cdm.model.description.Feature;
|
25
|
import eu.etaxonomy.cdm.model.description.State;
|
26
|
|
27
|
/**
|
28
|
* A store to handle all terms and vocabulary required for
|
29
|
* the UseObjects view and components.
|
30
|
* Whenever one of the terms is requested, all required terms are generated
|
31
|
* in the database as we consider the requests as an indicator that
|
32
|
* someone wants to use the terms.
|
33
|
* This
|
34
|
* @author a.theys
|
35
|
* @author a.mueller
|
36
|
* @created mar 13, 2012
|
37
|
*/
|
38
|
public class UseObjectStore {
|
39
|
|
40
|
private static boolean isInitialized;
|
41
|
|
42
|
private static MarkerType useMarkerType;
|
43
|
private static Feature useSummaryFeature;
|
44
|
private static Feature useRecordFeature;
|
45
|
|
46
|
|
47
|
public static void reset() {
|
48
|
isInitialized = false;
|
49
|
useMarkerType = null;
|
50
|
useSummaryFeature = null;
|
51
|
useRecordFeature = null;
|
52
|
}
|
53
|
|
54
|
public static MarkerType getUseMarkerType() {
|
55
|
initialize();
|
56
|
return useMarkerType;
|
57
|
}
|
58
|
|
59
|
public static Feature getUseSummaryFeature() {
|
60
|
initialize();
|
61
|
return useSummaryFeature;
|
62
|
}
|
63
|
|
64
|
public static Feature getUseRecordFeature() {
|
65
|
initialize();
|
66
|
return useRecordFeature;
|
67
|
}
|
68
|
|
69
|
|
70
|
private static void initialize(){
|
71
|
setupNecessaryItems(null);
|
72
|
isInitialized = true;
|
73
|
}
|
74
|
|
75
|
private static void setupNecessaryItems( IProgressMonitor monitor ) {
|
76
|
if (isInitialized){
|
77
|
return;
|
78
|
}
|
79
|
if (monitor == null){
|
80
|
//TODO can we use a better one?
|
81
|
monitor = new NullProgressMonitor();
|
82
|
}
|
83
|
|
84
|
ConversationHolder conversation = CdmStore.createConversation();
|
85
|
|
86
|
//retrieve terms and vocabularies from db
|
87
|
useRecordFeature = (Feature) CdmStore.getService(ITermService.class).find(UsageTermCollection.uuidUseRecordFeature);
|
88
|
useSummaryFeature = (Feature) CdmStore.getService(ITermService.class).find(UsageTermCollection.uuidUseSummaryFeature);
|
89
|
|
90
|
|
91
|
|
92
|
//create use marker type if not exists
|
93
|
createUseMarkerType(conversation);
|
94
|
|
95
|
//create state vocabulary if not exists
|
96
|
createStateVocabulary(monitor, conversation);
|
97
|
|
98
|
//create state vocabulary if not exists
|
99
|
createCountryVocabulary(monitor, conversation);
|
100
|
|
101
|
//create plant part vocabulary
|
102
|
createPlantVocabulary(monitor, conversation);
|
103
|
|
104
|
//create human group vocabulary
|
105
|
createHumanGroupVocabulary(monitor, conversation);
|
106
|
|
107
|
if(useRecordFeature == null || useSummaryFeature == null) {
|
108
|
TermVocabulary<Feature> featureVocabulary = CdmStore.getService(IVocabularyService.class).find((UsageTermCollection.uuidFeatureVocabulary));
|
109
|
// FeatureTree palmWebFeatureTree = CdmStore.getService(IFeatureTreeService.class).find(UsageTermCollection.uuidPalmWebFeatureTree);
|
110
|
|
111
|
if (useRecordFeature == null ) {
|
112
|
useRecordFeature = Feature.NewInstance(UsageTermCollection.useRecordFeatureLabel, UsageTermCollection.useRecordFeatureLabel, null);
|
113
|
useRecordFeature.setUuid(UsageTermCollection.uuidUseRecordFeature);
|
114
|
useRecordFeature.setSupportsCategoricalData(true);
|
115
|
featureVocabulary.addTerm(useRecordFeature);
|
116
|
|
117
|
// if (palmWebFeatureTree != null){
|
118
|
// FeatureNode useRecFeatureNode = FeatureNode.NewInstance(featureUseRecord);
|
119
|
// palmWebFeatureTree.getRoot().addChild(useRecFeatureNode);
|
120
|
// }else{
|
121
|
// StoreUtil.warn(getClass(), "No current feature tree available to add useRecord feature");
|
122
|
// }
|
123
|
}
|
124
|
if (useSummaryFeature == null) {
|
125
|
useSummaryFeature = Feature.NewInstance(UsageTermCollection.useSummaryFeatureLabel, UsageTermCollection.useSummaryFeatureLabel, null);
|
126
|
useSummaryFeature.setUuid(UsageTermCollection.uuidUseSummaryFeature);
|
127
|
useSummaryFeature.setSupportsTextData(true);
|
128
|
featureVocabulary.addTerm(useSummaryFeature);
|
129
|
// if (palmWebFeatureTree != null){
|
130
|
// FeatureNode useSumFeatureNode = FeatureNode.NewInstance(featureUseSummary);
|
131
|
// palmWebFeatureTree.getRoot().addChild(useSumFeatureNode);
|
132
|
// }else{
|
133
|
// StoreUtil.warn(getClass(), "No current feature tree available to add use summary feature");
|
134
|
// }
|
135
|
}
|
136
|
|
137
|
CdmStore.getService(IVocabularyService.class).saveOrUpdate(featureVocabulary);
|
138
|
// if (palmWebFeatureTree != null){
|
139
|
// CdmStore.getService(IFeatureTreeService.class).saveOrUpdate(palmWebFeatureTree);
|
140
|
// }
|
141
|
conversation.commit(true);
|
142
|
|
143
|
}
|
144
|
conversation.close();
|
145
|
}
|
146
|
|
147
|
|
148
|
private static void createHumanGroupVocabulary(IProgressMonitor monitor,ConversationHolder conversation) {
|
149
|
TermVocabulary<DefinedTerm> humanGroupVocabulary = CdmStore.getService(IVocabularyService.class).find(UsageTermCollection.uuidHumanGroupVocabulary);
|
150
|
if (humanGroupVocabulary == null){
|
151
|
monitor.subTask("create human group vocabulary");
|
152
|
URI termSourceUri = null;
|
153
|
try {
|
154
|
termSourceUri = new URI("eu.etaxonomy.cdm.model.description.DefinedTerm");
|
155
|
} catch (URISyntaxException e) {
|
156
|
e.printStackTrace();
|
157
|
}
|
158
|
|
159
|
humanGroupVocabulary = TermVocabulary.NewInstance(TermType.Modifier, UsageTermCollection.humanGroupLabel, UsageTermCollection.humanGroupLabel, null, termSourceUri);
|
160
|
humanGroupVocabulary.setUuid(UsageTermCollection.uuidHumanGroupVocabulary);
|
161
|
|
162
|
DefinedTerm newDummyModifier = DefinedTerm.NewInstance(TermType.Modifier, UsageTermCollection.notAvailableLabel, UsageTermCollection.notAvailableLabel, null);
|
163
|
newDummyModifier.setUuid(UsageTermCollection.uuidHumanGroupDummy);
|
164
|
|
165
|
DefinedTerm newSubDummyModifier = DefinedTerm.NewInstance(TermType.Modifier, UsageTermCollection.notAvailableLabel, UsageTermCollection.notAvailableLabel, null);
|
166
|
newSubDummyModifier.setUuid(UsageTermCollection.uuidEthnicGroupDummy);
|
167
|
newDummyModifier.addIncludes(newSubDummyModifier);
|
168
|
humanGroupVocabulary.addTerm(newDummyModifier);
|
169
|
|
170
|
CdmStore.getService(IVocabularyService.class).saveOrUpdate(humanGroupVocabulary);
|
171
|
conversation.commit(true);
|
172
|
}
|
173
|
}
|
174
|
|
175
|
|
176
|
private static void createPlantVocabulary(IProgressMonitor monitor, ConversationHolder conversation) {
|
177
|
TermVocabulary<DefinedTerm> plantPartVocabulary = CdmStore.getService(IVocabularyService.class).find(UsageTermCollection.uuidPlantPartVocabulary);
|
178
|
if (plantPartVocabulary == null){
|
179
|
monitor.subTask("create plant part vocabulary");
|
180
|
URI termSourceUri = null;
|
181
|
try {
|
182
|
termSourceUri = new URI("eu.etaxonomy.cdm.model.description.DefinedTerm");
|
183
|
} catch (URISyntaxException e) {
|
184
|
e.printStackTrace();
|
185
|
}
|
186
|
plantPartVocabulary = TermVocabulary.NewInstance(TermType.Modifier, UsageTermCollection.plantPartLabel, UsageTermCollection.plantPartLabel, null, termSourceUri);
|
187
|
plantPartVocabulary.setUuid(UsageTermCollection.uuidPlantPartVocabulary);
|
188
|
|
189
|
DefinedTerm newDummyModifier = DefinedTerm.NewInstance(TermType.Modifier, UsageTermCollection.notAvailableLabel, UsageTermCollection.notAvailableLabel, null);
|
190
|
newDummyModifier.setUuid(UsageTermCollection.uuidPlantPartDummy);
|
191
|
plantPartVocabulary.addTerm(newDummyModifier);
|
192
|
|
193
|
CdmStore.getService(IVocabularyService.class).saveOrUpdate(plantPartVocabulary);
|
194
|
conversation.commit(true);
|
195
|
}
|
196
|
}
|
197
|
|
198
|
|
199
|
private static void createCountryVocabulary(IProgressMonitor monitor, ConversationHolder conversation) {
|
200
|
TermVocabulary<DefinedTerm> countryVocabulary = CdmStore.getService(IVocabularyService.class).find(UsageTermCollection.uuidCountryVocabulary);
|
201
|
if (countryVocabulary == null){
|
202
|
monitor.subTask("create country vocabulary");
|
203
|
URI termSourceUri = null;
|
204
|
try {
|
205
|
termSourceUri = new URI("eu.etaxonomy.cdm.model.description.DefinedTerm");
|
206
|
} catch (URISyntaxException e) {
|
207
|
e.printStackTrace();
|
208
|
}
|
209
|
countryVocabulary = TermVocabulary.NewInstance(TermType.Modifier, UsageTermCollection.countryLabel, UsageTermCollection.countryLabel, null, termSourceUri);
|
210
|
countryVocabulary.setUuid(UsageTermCollection.uuidCountryVocabulary);
|
211
|
|
212
|
DefinedTerm newDummyModifier = DefinedTerm.NewInstance(TermType.Modifier, UsageTermCollection.notAvailableLabel, UsageTermCollection.notAvailableLabel, null);
|
213
|
newDummyModifier.setUuid(UsageTermCollection.uuidCountryDummy);
|
214
|
countryVocabulary.addTerm(newDummyModifier);
|
215
|
|
216
|
CdmStore.getService(IVocabularyService.class).saveOrUpdate(countryVocabulary);
|
217
|
conversation.commit(true);
|
218
|
}
|
219
|
}
|
220
|
|
221
|
|
222
|
private static void createStateVocabulary(IProgressMonitor monitor, ConversationHolder conversation) {
|
223
|
TermVocabulary<State> stateVocabulary = CdmStore.getService(IVocabularyService.class).find(UsageTermCollection.uuidUseCategoryVocabulary);
|
224
|
if (stateVocabulary == null){
|
225
|
monitor.subTask("create state vocabulary");
|
226
|
URI termSourceUri = null;
|
227
|
try {
|
228
|
termSourceUri = new URI("eu.etaxonomy.cdm.model.description.State");
|
229
|
} catch (URISyntaxException e) {
|
230
|
e.printStackTrace();
|
231
|
}
|
232
|
|
233
|
stateVocabulary = TermVocabulary.NewInstance(TermType.State, UsageTermCollection.useCategoryVocabularyLabel, UsageTermCollection.useCategoryVocabularyLabel, null, termSourceUri);
|
234
|
stateVocabulary.setUuid(UsageTermCollection.uuidUseCategoryVocabulary);
|
235
|
|
236
|
State newDummyState = State.NewInstance(UsageTermCollection.notAvailableLabel, UsageTermCollection.notAvailableLabel, null);
|
237
|
newDummyState.setUuid(UsageTermCollection.uuidUseCategoryDummy);
|
238
|
State newDummySubCat = State.NewInstance(UsageTermCollection.notAvailableLabel, UsageTermCollection.notAvailableLabel, null);
|
239
|
newDummySubCat.setUuid(UsageTermCollection.uuidUseSubCategoryDummy);
|
240
|
newDummyState.addIncludes(newDummySubCat);
|
241
|
|
242
|
stateVocabulary.addTerm(newDummyState);
|
243
|
|
244
|
CdmStore.getService(IVocabularyService.class).saveOrUpdate(stateVocabulary);
|
245
|
conversation.commit(true);
|
246
|
}
|
247
|
}
|
248
|
|
249
|
|
250
|
private static void createUseMarkerType(ConversationHolder conversation) {
|
251
|
useMarkerType = (MarkerType) CdmStore.getService(ITermService.class).find(UsageTermCollection.uuidUseMarkerType);
|
252
|
if (useMarkerType == null){
|
253
|
useMarkerType = MarkerType.NewInstance(UsageTermCollection.useMakerLabel, UsageTermCollection.useMakerLabel, null);
|
254
|
useMarkerType.setUuid( UsageTermCollection.uuidUseMarkerType);
|
255
|
TermVocabulary<MarkerType> markerTypeVocabulary = CdmStore.getService(IVocabularyService.class).find((UsageTermCollection.uuidMarkersVocabulary));
|
256
|
markerTypeVocabulary.addTerm(useMarkerType);
|
257
|
CdmStore.getService(IVocabularyService.class).saveOrUpdate(markerTypeVocabulary);
|
258
|
conversation.commit(true);
|
259
|
}
|
260
|
}
|
261
|
|
262
|
|
263
|
}
|