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