1
|
/**
|
2
|
* Copyright (C) 2007 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
|
|
10
|
package eu.etaxonomy.cdm.app.berlinModelImport;
|
11
|
|
12
|
import java.io.IOException;
|
13
|
import java.io.InputStream;
|
14
|
import java.io.InputStreamReader;
|
15
|
import java.io.Reader;
|
16
|
import java.util.Arrays;
|
17
|
import java.util.HashMap;
|
18
|
import java.util.List;
|
19
|
import java.util.Map;
|
20
|
import java.util.Set;
|
21
|
import java.util.UUID;
|
22
|
|
23
|
import org.apache.log4j.Logger;
|
24
|
import org.springframework.security.core.GrantedAuthority;
|
25
|
import org.springframework.transaction.TransactionStatus;
|
26
|
|
27
|
import eu.etaxonomy.cdm.api.application.FirstDataInserter;
|
28
|
import eu.etaxonomy.cdm.api.application.ICdmRepository;
|
29
|
import eu.etaxonomy.cdm.api.service.IGroupService;
|
30
|
import eu.etaxonomy.cdm.api.service.description.TransmissionEngineDistribution;
|
31
|
import eu.etaxonomy.cdm.api.service.description.TransmissionEngineDistribution.AggregationMode;
|
32
|
import eu.etaxonomy.cdm.api.service.pager.Pager;
|
33
|
import eu.etaxonomy.cdm.app.common.CdmDestinations;
|
34
|
import eu.etaxonomy.cdm.common.monitor.DefaultProgressMonitor;
|
35
|
import eu.etaxonomy.cdm.database.DbSchemaValidation;
|
36
|
import eu.etaxonomy.cdm.database.ICdmDataSource;
|
37
|
import eu.etaxonomy.cdm.ext.geo.IEditGeoService;
|
38
|
import eu.etaxonomy.cdm.io.berlinModel.BerlinModelTransformer;
|
39
|
import eu.etaxonomy.cdm.io.berlinModel.in.BerlinModelImportConfigurator;
|
40
|
import eu.etaxonomy.cdm.io.common.CdmDefaultImport;
|
41
|
import eu.etaxonomy.cdm.io.common.IImportConfigurator.CHECK;
|
42
|
import eu.etaxonomy.cdm.io.common.IImportConfigurator.DO_REFERENCES;
|
43
|
import eu.etaxonomy.cdm.io.common.IImportConfigurator.EDITOR;
|
44
|
import eu.etaxonomy.cdm.io.common.Source;
|
45
|
import eu.etaxonomy.cdm.model.agent.Person;
|
46
|
import eu.etaxonomy.cdm.model.common.DefinedTermBase;
|
47
|
import eu.etaxonomy.cdm.model.common.GrantedAuthorityImpl;
|
48
|
import eu.etaxonomy.cdm.model.common.Group;
|
49
|
import eu.etaxonomy.cdm.model.common.Language;
|
50
|
import eu.etaxonomy.cdm.model.common.Representation;
|
51
|
import eu.etaxonomy.cdm.model.common.User;
|
52
|
import eu.etaxonomy.cdm.model.description.Feature;
|
53
|
import eu.etaxonomy.cdm.model.description.FeatureNode;
|
54
|
import eu.etaxonomy.cdm.model.description.FeatureTree;
|
55
|
import eu.etaxonomy.cdm.model.location.NamedArea;
|
56
|
import eu.etaxonomy.cdm.model.location.NamedAreaLevel;
|
57
|
import eu.etaxonomy.cdm.model.location.NamedAreaType;
|
58
|
import eu.etaxonomy.cdm.model.name.NomenclaturalCode;
|
59
|
import eu.etaxonomy.cdm.model.name.Rank;
|
60
|
import eu.etaxonomy.cdm.model.taxon.Taxon;
|
61
|
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
|
62
|
import eu.etaxonomy.cdm.persistence.hibernate.permission.Role;
|
63
|
import eu.etaxonomy.cdm.persistence.query.MatchMode;
|
64
|
import eu.etaxonomy.cdm.persistence.query.OrderHint;
|
65
|
|
66
|
|
67
|
/**
|
68
|
* TODO add the following to a wiki page:
|
69
|
* HINT: If you are about to import into a mysql data base running under windows and if you wish to dump and restore the resulting data bas under another operation systen
|
70
|
* you must set the mysql system variable lower_case_table_names = 0 in order to create data base with table compatible names.
|
71
|
*
|
72
|
*
|
73
|
* @author a.mueller
|
74
|
*
|
75
|
*/
|
76
|
public class EuroMedActivator {
|
77
|
private static final Logger logger = Logger.getLogger(EuroMedActivator.class);
|
78
|
|
79
|
//database validation status (create, update, validate ...)
|
80
|
static DbSchemaValidation hbm2dll = DbSchemaValidation.VALIDATE;
|
81
|
static final Source berlinModelSource = BerlinModelSources.euroMed_BGBM42();
|
82
|
// static final Source berlinModelSource = BerlinModelSources.euroMed_PESI3();
|
83
|
|
84
|
static final ICdmDataSource cdmDestination = CdmDestinations.cdm_test_euroMed();
|
85
|
// static final ICdmDataSource cdmDestination = CdmDestinations.cdm_pesi_euromed();
|
86
|
|
87
|
// static final ICdmDataSource cdmDestination = CdmDestinations.cdm_test_local_euromed3();
|
88
|
// static final ICdmDataSource cdmDestination = CdmDestinations.cdm_test_local_mysql_test();
|
89
|
|
90
|
// static final ICdmDataSource cdmDestination = CdmDestinations.localH2();
|
91
|
|
92
|
static final boolean includePesiExport = false;
|
93
|
|
94
|
static final int sourceSecId = 7000000; //500000
|
95
|
static final UUID classificationUuid = UUID.fromString("314a68f9-8449-495a-91c2-92fde8bcf344");
|
96
|
static final boolean useSingleClassification = true;
|
97
|
static final String classificationName = "Euro+Med 2014";
|
98
|
static final UUID featureTreeUuid = UUID.fromString("6a5e1c2b-ec0d-46c8-9c7d-a2059267ffb7");
|
99
|
static final Object[] featureKeyList = new Integer[]{1, 31, 4, 98, 41};
|
100
|
|
101
|
// set to zero for unlimited nameFacts
|
102
|
static final int maximumNumberOfNameFacts = 0;
|
103
|
|
104
|
static final int partitionSize = 2500;
|
105
|
|
106
|
//check - import
|
107
|
static final CHECK check = CHECK.IMPORT_WITHOUT_CHECK;
|
108
|
|
109
|
//editor - import
|
110
|
static final EDITOR editor = EDITOR.EDITOR_AS_EDITOR;
|
111
|
|
112
|
//NomenclaturalCode
|
113
|
static final NomenclaturalCode nomenclaturalCode = NomenclaturalCode.ICNAFP;
|
114
|
|
115
|
//ignore null
|
116
|
static final boolean ignoreNull = true;
|
117
|
|
118
|
static final boolean switchSpeciesGroup = true;
|
119
|
|
120
|
static boolean useClassification = true;
|
121
|
|
122
|
static boolean isSplitTdwgCodes = false;
|
123
|
static boolean useEmAreaVocabulary = true;
|
124
|
|
125
|
private final boolean removeHttpMapsAnchor = true;
|
126
|
|
127
|
|
128
|
static final String infrGenericRankAbbrev = "[unranked]";
|
129
|
static final String infrSpecificRankAbbrev = "[unranked]";
|
130
|
|
131
|
|
132
|
static String taxonTable = "v_cdm_exp_taxaAll";
|
133
|
static String classificationQuery = " SELECT DISTINCT t.PTRefFk, r.RefCache FROM PTaxon t INNER JOIN Reference r ON t.PTRefFk = r.RefId WHERE t.PTRefFk = " + sourceSecId;
|
134
|
static String relPTaxonIdQuery = " SELECT r.RelPTaxonId " +
|
135
|
" FROM RelPTaxon AS r INNER JOIN v_cdm_exp_taxaDirect AS a ON r.PTNameFk2 = a.PTNameFk AND r.PTRefFk2 = a.PTRefFk" +
|
136
|
" WHERE r.RelPTaxonID NOT IN (1883791,1883800,1883823,1883852,1883853,1883864,1883896,1883921,1883943,1883944,1883955,1883972,1884008,1884030,1884031,1884035) " + //Unpublished Kew taxa which are not imported anymore
|
137
|
" "; // AND r.RelQualifierFk =1
|
138
|
static String nameIdTable = " v_cdm_exp_namesAll ";
|
139
|
static String referenceIdTable = " v_cdm_exp_refAll ";
|
140
|
static String refDetailFilter = " RefDetailID IN (SELECT RefDetailID FROM v_cdm_exp_RefDetail) ";
|
141
|
static String factFilter = " factId IN ( SELECT factId FROM v_cdm_exp_factsAll WHERE FactCategoryFk NOT IN (12, 14, 249, 251))";
|
142
|
static String occurrenceFilter = " occurrenceId IN ( SELECT occurrenceId FROM v_cdm_exp_occurrenceAll )";
|
143
|
static String occurrenceSourceFilter = " occurrenceFk IN ( SELECT occurrenceId FROM v_cdm_exp_occurrenceAll )";
|
144
|
static String commonNameFilter = " commonNameId IN ( SELECT commonNameId FROM v_cdm_exp_commonNamesAll )";
|
145
|
static String webMarkerFilter = " TableNameFk <> 500 OR ( RIdentifierFk IN (SELECT RIdentifier FROM v_cdm_exp_taxaAll)) ";
|
146
|
static String authorTeamFilter = null; // " authorTeamId IN (SELECT authorTeamId FROM v_cdm_exp_authorTeamsAll) ";
|
147
|
static String authorFilter = null; // " authorId IN (SELECT authorId FROM v_cdm_exp_authorsAll) ";
|
148
|
|
149
|
|
150
|
|
151
|
// **************** ALL *********************
|
152
|
|
153
|
boolean invers = !(hbm2dll == DbSchemaValidation.CREATE);
|
154
|
|
155
|
static final boolean doUser = true;
|
156
|
// //authors
|
157
|
static final boolean doAuthors = true;
|
158
|
//references
|
159
|
static final DO_REFERENCES doReferences = DO_REFERENCES.ALL;
|
160
|
//names
|
161
|
static final boolean doTaxonNames = true;
|
162
|
static final boolean doRelNames = true;
|
163
|
static final boolean doNameStatus = true;
|
164
|
static final boolean doTypes = false; //serious types do not exist in E+M
|
165
|
static final boolean doNameFacts = true;
|
166
|
|
167
|
//taxa
|
168
|
static final boolean doTaxa = true;
|
169
|
static final boolean doFacts = true;
|
170
|
static final boolean doCommonNames = true;
|
171
|
static final boolean doOccurences = true;
|
172
|
static final boolean doRelTaxa = false;
|
173
|
static final boolean doRunTransmissionEngine = (hbm2dll == DbSchemaValidation.VALIDATE);
|
174
|
|
175
|
//etc.
|
176
|
static final boolean doMarker = true;
|
177
|
|
178
|
|
179
|
public void importEm2CDM (Source source, ICdmDataSource destination, DbSchemaValidation hbm2dll){
|
180
|
System.out.println("Start import from BerlinModel("+ berlinModelSource.getDatabase() + ") to " + cdmDestination.getDatabase() + " ...");
|
181
|
//make BerlinModel Source
|
182
|
|
183
|
BerlinModelImportConfigurator config = BerlinModelImportConfigurator.NewInstance(source, destination);
|
184
|
|
185
|
config.setClassificationName(classificationName);
|
186
|
|
187
|
config.setClassificationUuid(classificationUuid);
|
188
|
config.setSourceSecId(sourceSecId);
|
189
|
config.setNomenclaturalCode(nomenclaturalCode);
|
190
|
config.setIgnoreNull(ignoreNull);
|
191
|
|
192
|
config.setDoAuthors(doAuthors ^ invers);
|
193
|
config.setDoReferences(invers ? doReferences.invers() : doReferences);
|
194
|
config.setDoTaxonNames(doTaxonNames ^ invers);
|
195
|
config.setDoRelNames(doRelNames ^ invers);
|
196
|
config.setDoNameStatus(doNameStatus ^ invers);
|
197
|
config.setDoTypes(doTypes); //always false
|
198
|
config.setDoNameFacts(doNameFacts ^ invers);
|
199
|
config.setDoTaxa(doTaxa ^ invers);
|
200
|
config.setDoRelTaxa(doRelTaxa ^ invers);
|
201
|
config.setDoFacts(doFacts ^ invers);
|
202
|
config.setDoOccurrence(doOccurences ^ invers);
|
203
|
config.setDoCommonNames(doCommonNames ^ invers);
|
204
|
|
205
|
config.setDoMarker(doMarker ^ invers);
|
206
|
config.setDoUser(doUser ^ invers);
|
207
|
|
208
|
config.setUseClassification(useClassification);
|
209
|
config.setSourceRefUuid(BerlinModelTransformer.uuidSourceRefEuroMed);
|
210
|
config.setEditor(editor);
|
211
|
config.setDbSchemaValidation(hbm2dll);
|
212
|
|
213
|
// maximum number of name facts to import
|
214
|
config.setMaximumNumberOfNameFacts(maximumNumberOfNameFacts);
|
215
|
|
216
|
config.setInfrGenericRankAbbrev(infrGenericRankAbbrev);
|
217
|
config.setInfrSpecificRankAbbrev(infrSpecificRankAbbrev);
|
218
|
config.setRemoveHttpMapsAnchor(removeHttpMapsAnchor);
|
219
|
|
220
|
// filter
|
221
|
config.setTaxonTable(taxonTable);
|
222
|
config.setClassificationQuery(classificationQuery);
|
223
|
config.setRelTaxaIdQuery(relPTaxonIdQuery);
|
224
|
config.setNameIdTable(nameIdTable);
|
225
|
config.setReferenceIdTable(referenceIdTable);
|
226
|
config.setAuthorTeamFilter(authorTeamFilter);
|
227
|
config.setAuthorFilter(authorFilter);
|
228
|
config.setFactFilter(factFilter);
|
229
|
config.setRefDetailFilter(refDetailFilter);
|
230
|
config.setCommonNameFilter(commonNameFilter);
|
231
|
config.setOccurrenceFilter(occurrenceFilter);
|
232
|
config.setOccurrenceSourceFilter(occurrenceSourceFilter);
|
233
|
config.setWebMarkerFilter(webMarkerFilter);
|
234
|
config.setUseSingleClassification(useSingleClassification);
|
235
|
|
236
|
//TDWG codes
|
237
|
config.setSplitTdwgCodes(isSplitTdwgCodes);
|
238
|
config.setUseEmAreaVocabulary(useEmAreaVocabulary);
|
239
|
|
240
|
config.setCheck(check);
|
241
|
config.setEditor(editor);
|
242
|
config.setRecordsPerTransaction(partitionSize);
|
243
|
|
244
|
config.setSwitchSpeciesGroup(switchSpeciesGroup);
|
245
|
|
246
|
// invoke import
|
247
|
CdmDefaultImport<BerlinModelImportConfigurator> bmImport = new CdmDefaultImport<BerlinModelImportConfigurator>();
|
248
|
bmImport.invoke(config);
|
249
|
|
250
|
renameRanks(config, bmImport);
|
251
|
|
252
|
createFeatureTree(config, bmImport);
|
253
|
|
254
|
changeCommonNameLabel(config, bmImport);
|
255
|
|
256
|
createUsersAndRoles(config, bmImport);
|
257
|
|
258
|
runTransmissionEngine(config, bmImport);
|
259
|
|
260
|
importShapefile(config, bmImport);
|
261
|
|
262
|
// markAreasAsHidden(config, bmImport); //has been moved to BM occurrence import
|
263
|
|
264
|
System.out.println("End import from BerlinModel ("+ source.getDatabase() + ")...");
|
265
|
}
|
266
|
|
267
|
//Rename Ranks (still needed?)
|
268
|
private void renameRanks(BerlinModelImportConfigurator config,
|
269
|
CdmDefaultImport<BerlinModelImportConfigurator> bmImport) {
|
270
|
|
271
|
if (config.isDoTaxonNames() && (config.getCheck().isImport() ) ){
|
272
|
ICdmRepository app = bmImport.getCdmAppController();
|
273
|
TransactionStatus tx = app.startTransaction();
|
274
|
try {
|
275
|
Rank sectBot = (Rank)app.getTermService().find(Rank.SECTION_BOTANY().getUuid());
|
276
|
Representation repr = sectBot.getRepresentation(Language.ENGLISH());
|
277
|
repr.setAbbreviatedLabel(repr.getAbbreviatedLabel().replace("(bot.)", "").trim());
|
278
|
repr.setLabel(repr.getLabel().replace("(Botany)", "").trim());
|
279
|
sectBot.setTitleCache(null, false); //to definetely update the titleCache also
|
280
|
app.getTermService().saveOrUpdate(sectBot);
|
281
|
|
282
|
Rank subSectBot = (Rank)app.getTermService().find(Rank.SECTION_BOTANY().getUuid());
|
283
|
repr = subSectBot.getRepresentation(Language.ENGLISH());
|
284
|
repr.setAbbreviatedLabel(repr.getAbbreviatedLabel().replace("(bot.)", "").trim());
|
285
|
repr.setLabel(repr.getLabel().replace("(Botany)", "").trim());
|
286
|
subSectBot.setTitleCache(null, false); //to definetely update the titleCache also
|
287
|
app.getTermService().saveOrUpdate(subSectBot);
|
288
|
app.commitTransaction(tx);
|
289
|
} catch (Exception e) {
|
290
|
e.printStackTrace();
|
291
|
logger.error("Exception in renameRanks: " + e.getMessage());
|
292
|
}
|
293
|
}
|
294
|
}
|
295
|
|
296
|
//create feature tree
|
297
|
private void createFeatureTree(BerlinModelImportConfigurator config,
|
298
|
CdmDefaultImport<BerlinModelImportConfigurator> bmImport)
|
299
|
{
|
300
|
if (config.isDoFacts() && (config.getCheck().isImport() ) ){
|
301
|
try {
|
302
|
ICdmRepository app = bmImport.getCdmAppController();
|
303
|
TransactionStatus tx = app.startTransaction();
|
304
|
|
305
|
//make feature tree
|
306
|
FeatureTree tree = TreeCreator.flatTree(featureTreeUuid, config.getFeatureMap(), featureKeyList);
|
307
|
FeatureNode imageNode = FeatureNode.NewInstance(Feature.IMAGE());
|
308
|
tree.getRoot().addChild(imageNode);
|
309
|
FeatureNode distributionNode = FeatureNode.NewInstance(Feature.DISTRIBUTION());
|
310
|
tree.getRoot().addChild(distributionNode, 1);
|
311
|
FeatureNode commonNameNode = FeatureNode.NewInstance(Feature.COMMON_NAME());
|
312
|
tree.getRoot().addChild(commonNameNode, 2);
|
313
|
app.getFeatureTreeService().saveOrUpdate(tree);
|
314
|
|
315
|
app.commitTransaction(tx);
|
316
|
} catch (Exception e) {
|
317
|
e.printStackTrace();
|
318
|
logger.error("Exception in createFeatureTree: " + e.getMessage());
|
319
|
}
|
320
|
}
|
321
|
}
|
322
|
|
323
|
//Change common name label
|
324
|
private void changeCommonNameLabel(BerlinModelImportConfigurator config,
|
325
|
CdmDefaultImport<BerlinModelImportConfigurator> bmImport) {
|
326
|
if (config.isDoFacts() && (config.getCheck().isImport() ) ){
|
327
|
try {
|
328
|
ICdmRepository app = bmImport.getCdmAppController();
|
329
|
TransactionStatus tx = app.startTransaction();
|
330
|
|
331
|
DefinedTermBase<?> commonNameFeature = app.getTermService().find(Feature.COMMON_NAME().getUuid());
|
332
|
commonNameFeature.setLabel("Common Names", Language.ENGLISH());
|
333
|
commonNameFeature.setTitleCache(null, false); //to definitely update the titleCache also
|
334
|
app.getTermService().saveOrUpdate(commonNameFeature);
|
335
|
|
336
|
app.commitTransaction(tx);
|
337
|
} catch (Exception e) {
|
338
|
e.printStackTrace();
|
339
|
logger.error("Exception in changeCommonNameLabel: " + e.getMessage());
|
340
|
}
|
341
|
}
|
342
|
}
|
343
|
|
344
|
//1. run transmission engine #3979
|
345
|
private void runTransmissionEngine(BerlinModelImportConfigurator config,
|
346
|
CdmDefaultImport<BerlinModelImportConfigurator> bmImport) {
|
347
|
|
348
|
if (doRunTransmissionEngine && (config.getCheck().isImport() ) ){
|
349
|
try {
|
350
|
ICdmRepository app = bmImport.getCdmAppController();
|
351
|
|
352
|
final List<String> term_init_strategy = Arrays.asList(new String []{
|
353
|
"representations"
|
354
|
});
|
355
|
|
356
|
UUID uuidSuperAreaLevel = BerlinModelTransformer.uuidEuroMedAreaLevelFirst;
|
357
|
NamedAreaLevel euroMedLevel1 = (NamedAreaLevel)app.getTermService().find(uuidSuperAreaLevel);
|
358
|
|
359
|
Pager<NamedArea> areaPager = app.getTermService().list(
|
360
|
euroMedLevel1,
|
361
|
(NamedAreaType) null,
|
362
|
null,
|
363
|
null,
|
364
|
(List<OrderHint>) null,
|
365
|
term_init_strategy);
|
366
|
TransmissionEngineDistribution transmissionEngineDistribution = (TransmissionEngineDistribution)app.getBean("transmissionEngineDistribution");
|
367
|
transmissionEngineDistribution.accumulate(
|
368
|
AggregationMode.byAreasAndRanks,
|
369
|
areaPager.getRecords(),
|
370
|
Rank.UNRANKED_INFRASPECIFIC(), //or do we even want to start from lower (UNKNOWN?)
|
371
|
Rank.GENUS(),
|
372
|
null,
|
373
|
DefaultProgressMonitor.NewInstance());
|
374
|
} catch (Exception e) {
|
375
|
e.printStackTrace();
|
376
|
logger.error("Exception in markAreasAsHidden: " + e.getMessage());
|
377
|
}
|
378
|
}
|
379
|
}
|
380
|
|
381
|
// //5.Mark areas to be hidden #3979 .5
|
382
|
// private void markAreasAsHidden(BerlinModelImportConfigurator config,
|
383
|
// CdmDefaultImport<BerlinModelImportConfigurator> bmImport) {
|
384
|
//
|
385
|
// if (config.isDoOccurrence() && (config.getCheck().isImport())){
|
386
|
// try {
|
387
|
// ICdmRepository app = bmImport.getCdmAppController();
|
388
|
// TransactionStatus tx = app.startTransaction();
|
389
|
//
|
390
|
// MarkerType hiddenAreaMarkerType = MarkerType.NewInstance("Used to hide distributions for the named areas in publications", "Hidden Area", null);
|
391
|
// hiddenAreaMarkerType.setUuid(BerlinModelTransformer.uuidHiddenArea);
|
392
|
// @SuppressWarnings("unchecked")
|
393
|
// TermVocabulary<MarkerType> vocUserDefinedMarkerTypes = app.getVocabularyService().find(CdmImportBase.uuidUserDefinedMarkerTypeVocabulary);
|
394
|
// if (vocUserDefinedMarkerTypes == null){
|
395
|
// String message = "Marker type vocabulary could not be found. Hidden areas not added.";
|
396
|
// logger.error(message);
|
397
|
// System.out.println(message);
|
398
|
// }else{
|
399
|
// vocUserDefinedMarkerTypes.addTerm(hiddenAreaMarkerType);
|
400
|
// app.getVocabularyService().saveOrUpdate(vocUserDefinedMarkerTypes);
|
401
|
//
|
402
|
// //Add hidden area marker to Rs(C) and Rs(N)
|
403
|
// hideArea(app, hiddenAreaMarkerType, BerlinModelTransformer.uuidRs);
|
404
|
// hideArea(app, hiddenAreaMarkerType, BerlinModelTransformer.uuidRs_B);
|
405
|
// hideArea(app, hiddenAreaMarkerType, BerlinModelTransformer.uuidRs_C);
|
406
|
// hideArea(app, hiddenAreaMarkerType, BerlinModelTransformer.uuidRs_E);
|
407
|
// hideArea(app, hiddenAreaMarkerType, BerlinModelTransformer.uuidRs_N);
|
408
|
// hideArea(app, hiddenAreaMarkerType, BerlinModelTransformer.uuidRs_K);
|
409
|
// hideArea(app, hiddenAreaMarkerType, BerlinModelTransformer.uuidRs_W);
|
410
|
// }
|
411
|
// app.commitTransaction(tx);
|
412
|
// } catch (Exception e) {
|
413
|
// e.printStackTrace();
|
414
|
// logger.error("Exception in markAreasAsHidden: " + e.getMessage());
|
415
|
// }
|
416
|
// }
|
417
|
// }
|
418
|
//
|
419
|
// private void hideArea(ICdmRepository app, MarkerType hiddenAreaMarkerType, UUID areaUuid) {
|
420
|
// NamedArea area = (NamedArea)app.getTermService().find(areaUuid);
|
421
|
// area.addMarker(Marker.NewInstance(hiddenAreaMarkerType, true));
|
422
|
// app.getTermService().saveOrUpdate(area);
|
423
|
// }
|
424
|
|
425
|
//2. import shapefile attributes #3979 .2
|
426
|
private void importShapefile(BerlinModelImportConfigurator config,
|
427
|
CdmDefaultImport<BerlinModelImportConfigurator> bmImport) {
|
428
|
|
429
|
if (config.isDoOccurrence() && (config.getCheck().isImport())){
|
430
|
|
431
|
try {
|
432
|
UUID areaVocabularyUuid = BerlinModelTransformer.uuidVocEuroMedAreas;
|
433
|
List<String> idSearchFields = Arrays.asList(new String[]{"EMAREA","PARENT"});
|
434
|
String wmsLayerName = "euromed_2013";
|
435
|
Set<UUID> areaUuidSet = null;
|
436
|
|
437
|
ICdmRepository app = bmImport.getCdmAppController();
|
438
|
IEditGeoService geoService = (IEditGeoService)app.getBean("editGeoService");
|
439
|
|
440
|
Map<NamedArea, String> resultMap;
|
441
|
try {
|
442
|
// URL url = ClassLoader.getSystemResource("myConfig.txt");
|
443
|
// FileReader fileReader = new FileReader(url.getFile());
|
444
|
InputStream in = EuroMedActivator.class.getResourceAsStream("/euromed/euromed_2013.csv");
|
445
|
Reader reader = new InputStreamReader(in, "UTF-8");
|
446
|
|
447
|
resultMap = geoService.mapShapeFileToNamedAreas(
|
448
|
reader, idSearchFields , wmsLayerName , areaVocabularyUuid, areaUuidSet);
|
449
|
Map<String, String> flatResultMap = new HashMap<String, String>(resultMap.size());
|
450
|
for(NamedArea area : resultMap.keySet()){
|
451
|
flatResultMap.put(area.getTitleCache() + " [" + area.getUuid() + "]", resultMap.get(area));
|
452
|
}
|
453
|
} catch (IOException e) {
|
454
|
String message = "IOException when reading from mapping file or creating result map.";
|
455
|
logger.error(message);
|
456
|
System.out.println(message);
|
457
|
}
|
458
|
} catch (Exception e) {
|
459
|
e.printStackTrace();
|
460
|
logger.error("Exception in importShapefile: " + e.getMessage());
|
461
|
}
|
462
|
}
|
463
|
}
|
464
|
|
465
|
//4. Create users and assign roles #3979
|
466
|
private void createUsersAndRoles(BerlinModelImportConfigurator config,
|
467
|
CdmDefaultImport<BerlinModelImportConfigurator> bmImport) {
|
468
|
|
469
|
try {
|
470
|
if (config.isDoRelTaxa() && (config.getCheck().isImport())){
|
471
|
ICdmRepository app = bmImport.getCdmAppController();
|
472
|
TransactionStatus tx = app.startTransaction();
|
473
|
|
474
|
//eraabstraube
|
475
|
String eraabstraube = "eraabstraube";
|
476
|
List<User> users = app.getUserService().listByUsername(eraabstraube, MatchMode.EXACT, null, null, null, null, null);
|
477
|
User userEraabStraube;
|
478
|
if (users.isEmpty()){
|
479
|
userEraabStraube = User.NewInstance(eraabstraube, eraabstraube);
|
480
|
}else{
|
481
|
userEraabStraube = users.get(0);
|
482
|
}
|
483
|
if (userEraabStraube.getPerson() == null){
|
484
|
Person eckhard = Person.NewInstance();
|
485
|
eckhard.setLastname("von Raab-Straube");
|
486
|
eckhard.setFirstname("Eckhard");
|
487
|
eckhard.setPrefix("Dr.");
|
488
|
userEraabStraube.setPerson(eckhard);
|
489
|
}
|
490
|
app.getUserService().saveOrUpdate(userEraabStraube);
|
491
|
|
492
|
//groups
|
493
|
Group groupEditor = app.getGroupService().load(Group.groupEditorUuid);
|
494
|
groupEditor.addMember(userEraabStraube);
|
495
|
app.getGroupService().saveOrUpdate(groupEditor);
|
496
|
|
497
|
Group groupProjectManager = app.getGroupService().load(Group.groupProjectManagerUuid);
|
498
|
groupProjectManager.addMember(userEraabStraube);
|
499
|
app.getGroupService().saveOrUpdate(groupProjectManager);
|
500
|
|
501
|
String[] publishRoles = new String[]{Role.ROLE_PUBLISH.toString()};
|
502
|
Group groupPublisher = checkGroup(app.getGroupService(), Group.groupPublisherUuid, "Publisher", publishRoles);
|
503
|
groupPublisher.addMember(userEraabStraube);
|
504
|
app.getGroupService().saveOrUpdate(groupPublisher);
|
505
|
|
506
|
UUID uuidEuroMedPlantBaseGroup = UUID.fromString("91be42ea-ad04-4458-9836-389277e773db");
|
507
|
String[] emPlantBaseRoles = new String[]{"TAXONNODE.[CREATE,READ,UPDATE,DELETE]"};
|
508
|
Group euroMedPlantbase = checkGroup(app.getGroupService(), uuidEuroMedPlantBaseGroup, "Euro+Med Plantbase", emPlantBaseRoles);
|
509
|
euroMedPlantbase.addMember(userEraabStraube);
|
510
|
app.getGroupService().saveOrUpdate(euroMedPlantbase);
|
511
|
|
512
|
//cichorieae-editor
|
513
|
String cichorieaeEditor = "cichorieae-editor";
|
514
|
app.getUserService().listByUsername(cichorieaeEditor, MatchMode.EXACT, null, null, null, null, null);
|
515
|
User userCichEditor;
|
516
|
if (users.isEmpty()){
|
517
|
userCichEditor = User.NewInstance(cichorieaeEditor, cichorieaeEditor);
|
518
|
}else{
|
519
|
userCichEditor = users.get(0);
|
520
|
}
|
521
|
app.getUserService().saveOrUpdate(userCichEditor);
|
522
|
|
523
|
//groups
|
524
|
groupEditor.addMember(userCichEditor);
|
525
|
app.getGroupService().saveOrUpdate(groupEditor);
|
526
|
|
527
|
UUID uuidCichorieaeSubtree = null;
|
528
|
UUID uuidCichorieae = UUID.fromString("63c7dbeb-b9a2-48b8-a75f-e3fe5e161f7c");
|
529
|
Taxon cich = (Taxon)app.getTaxonService().find(uuidCichorieae);
|
530
|
if (cich != null){
|
531
|
if (!cich.getTaxonNodes().isEmpty()){
|
532
|
TaxonNode cichNode = cich.getTaxonNodes().iterator().next();
|
533
|
uuidCichorieaeSubtree = cichNode.getUuid();
|
534
|
}
|
535
|
}
|
536
|
|
537
|
String[] cichorieaeRoles = new String[]{};
|
538
|
if (uuidCichorieaeSubtree != null){
|
539
|
cichorieaeRoles = new String[]{"TAXONNODE.[CREATE,READ,UPDATE,DELETE]{"+uuidCichorieaeSubtree.toString()+"}"};
|
540
|
}else{
|
541
|
String message = "Cichorieae node could not be found for cichorieae-editor role";
|
542
|
logger.warn(message);
|
543
|
System.out.println(message);
|
544
|
}
|
545
|
UUID uuidCichorieaeGroup = UUID.fromString("a630938d-dd4f-48c2-9406-91def487b11e");
|
546
|
String cichorieaeGroupName = "Cichorieae";
|
547
|
Group cichorieaeGroup = checkGroup(app.getGroupService(), uuidCichorieaeGroup, cichorieaeGroupName, cichorieaeRoles);
|
548
|
cichorieaeGroup.addMember(userCichEditor);
|
549
|
app.getGroupService().saveOrUpdate(cichorieaeGroup);
|
550
|
|
551
|
app.commitTransaction(tx);
|
552
|
}
|
553
|
} catch (Exception e) {
|
554
|
e.printStackTrace();
|
555
|
logger.error("Exception in createUsersAndRoles: " + e.getMessage());
|
556
|
}
|
557
|
}
|
558
|
|
559
|
/**
|
560
|
* copied from {@link FirstDataInserter#checkGroup}
|
561
|
*/
|
562
|
private Group checkGroup(IGroupService groupService, UUID groupUuid, String groupName, String[] requiredAuthorities) {
|
563
|
Group group = groupService.load(groupUuid);
|
564
|
if(group == null){
|
565
|
group = Group.NewInstance();
|
566
|
group.setUuid(groupUuid);
|
567
|
logger.info("New Group '" + groupName + "' created");
|
568
|
}
|
569
|
group.setName(groupName); // force name
|
570
|
|
571
|
Set<GrantedAuthority> grantedAuthorities = group.getGrantedAuthorities();
|
572
|
|
573
|
for(String a : requiredAuthorities){
|
574
|
boolean isMissing = true;
|
575
|
for(GrantedAuthority ga : grantedAuthorities){
|
576
|
if(a.equals(ga.getAuthority())){
|
577
|
isMissing = false;
|
578
|
break;
|
579
|
}
|
580
|
}
|
581
|
if(isMissing){
|
582
|
GrantedAuthorityImpl newGa = GrantedAuthorityImpl.NewInstance();
|
583
|
newGa.setAuthority(a);
|
584
|
group.addGrantedAuthority(newGa);
|
585
|
logger.info("New GrantedAuthority '" + a + "' added to '" + groupName + "'");
|
586
|
}
|
587
|
}
|
588
|
groupService.saveOrUpdate(group);
|
589
|
logger.info("Check of group '" + groupName + "' done");
|
590
|
return group;
|
591
|
}
|
592
|
|
593
|
|
594
|
/**
|
595
|
* @param args
|
596
|
*/
|
597
|
public static void main(String[] args) {
|
598
|
EuroMedActivator importActivator = new EuroMedActivator();
|
599
|
Source source = berlinModelSource;
|
600
|
ICdmDataSource cdmRepository = CdmDestinations.chooseDestination(args) != null ? CdmDestinations.chooseDestination(args) : cdmDestination;
|
601
|
|
602
|
importActivator.importEm2CDM(source, cdmRepository, hbm2dll);
|
603
|
if (includePesiExport){
|
604
|
//not available from here since E+M was moved to app-import
|
605
|
// PesiExportActivatorEM exportActivator = new PesiExportActivatorEM();
|
606
|
// exportActivator.doExport(cdmRepository);
|
607
|
}
|
608
|
|
609
|
}
|
610
|
|
611
|
}
|