2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
10 package eu
.etaxonomy
.cdm
.app
.berlinModelImport
;
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
;
21 import java
.util
.UUID
;
23 import org
.apache
.log4j
.Logger
;
24 import org
.springframework
.security
.core
.GrantedAuthority
;
25 import org
.springframework
.transaction
.TransactionStatus
;
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
;
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
70 * dump and restore the resulting data bas under another operation systen
71 * you must set the mysql system variable lower_case_table_names = 0 in order to create data base with table compatible names.
75 public class EuroMedActivator
{
76 private static final Logger logger
= Logger
.getLogger(EuroMedActivator
.class);
78 //database validation status (create, update, validate ...)
79 static DbSchemaValidation hbm2dll
= DbSchemaValidation
.VALIDATE
;
80 // static final Source berlinModelSource = BerlinModelSources.euroMed_Pub2();
81 static final Source berlinModelSource
= BerlinModelSources
.euroMed_BGBM42();
82 // static final Source berlinModelSource = BerlinModelSources.euroMed_PESI3();
84 static final ICdmDataSource cdmDestination
= CdmDestinations
.localH2();
85 // static final ICdmDataSource cdmDestination = CdmDestinations.cdm_local_euromed();
86 // static final ICdmDataSource cdmDestination = CdmDestinations.cdm_local_euromed2();
87 // static final ICdmDataSource cdmDestination = CdmDestinations.cdm_test_euroMed();
88 // static final ICdmDataSource cdmDestination = CdmDestinations.cdm_euroMed_production();
91 static final CHECK check
= CHECK
.IMPORT_WITHOUT_CHECK
;
93 static final boolean doUser
= true;
95 static final boolean doAuthors
= true;
97 static final DO_REFERENCES doReferences
= DO_REFERENCES
.ALL
;
99 static final boolean doTaxonNames
= true;
100 static final boolean doRelNames
= true;
101 static final boolean doNameStatus
= true;
102 static final boolean doNameFacts
= true;
105 static final boolean doTaxa
= true;
106 static final boolean doFacts
= true;
107 static final boolean doRelTaxa
= true;
108 static final boolean doOccurrences
= false;
109 static final boolean doOccurrenceSources
= false;
110 static final boolean doCommonNames
= false; //currently takes very long
112 //serious types do not exist in E+M except for name types which are handled in name relations
113 static final boolean doTypes
= false; //serious types do not exist in E+M except for name types which are handled in name relations
116 static final boolean doRunTransmissionEngine
= false; // (hbm2dll == DbSchemaValidation.VALIDATE);
119 static final boolean doMarker
= false; //no relevant markers exist
121 boolean invers
= !(hbm2dll
== DbSchemaValidation
.CREATE
);
123 boolean doPreliminaryRefDetailsWithNames
= true;
125 boolean logNotMatchingOldNames
= false;
126 boolean logMatchingNotExportedOldNames
= false; //true
127 boolean checkOldNameIsSynonym
= true;
129 static final boolean includePesiExport
= false;
131 static final int sourceSecId
= 7000000; //500000
132 static final UUID classificationUuid
= UUID
.fromString("314a68f9-8449-495a-91c2-92fde8bcf344");
133 static final boolean useSingleClassification
= true;
134 static final String classificationName
= "Euro+Med 2018";
135 static final UUID featureTreeUuid
= UUID
.fromString("6a5e1c2b-ec0d-46c8-9c7d-a2059267ffb7");
136 static final Object
[] featureKeyList
= new Integer
[]{1, 31, 4, 98, 41};
138 // set to zero for unlimited nameFacts
139 static final int maximumNumberOfNameFacts
= 0;
141 static final int partitionSize
= 2500;
145 static final EDITOR editor
= EDITOR
.EDITOR_AS_EDITOR
;
148 static final NomenclaturalCode nomenclaturalCode
= NomenclaturalCode
.ICNAFP
;
151 static final boolean ignoreNull
= false;
153 static final boolean switchSpeciesGroup
= true;
155 static boolean useClassification
= true;
157 static boolean isSplitTdwgCodes
= false;
158 static boolean useEmAreaVocabulary
= true;
160 private final boolean removeHttpMapsAnchor
= true;
163 static final String infrGenericRankAbbrev
= "[unranked]";
164 static final String infrSpecificRankAbbrev
= "[unranked]";
166 static boolean useLastScrutinyAsSec
= true;
167 static boolean warnForDifferingSynonymReference
= false;
170 static String taxonTable
= "v_cdm_exp_taxaAll";
171 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
;
172 static String relPTaxonIdQuery
= " SELECT r.RelPTaxonId "
173 + " FROM RelPTaxon AS r "
174 + " INNER JOIN v_cdm_exp_taxaDirect AS a ON r.PTNameFk2 = a.PTNameFk AND r.PTRefFk2 = a.PTRefFk "
175 + " INNER JOIN PTaxon As pt1 ON pt1.PTNameFk = r.PTNameFk1 AND pt1.PTRefFk = r.PTRefFk1 "
176 + " WHERE r.RelPTaxonID NOT IN (1874890,1874959,1874932,1874793,1874956,1874971,1874902,1874696) " //Relations to unpublished Kew genus taxa of Bethulaceae which are not imported anymore, but Bethalaceae is still imported
177 + " AND NOT (pt1.PTRefFk = 8000000 AND pt1.publishFlag = 0) ";
178 static String nameIdTable
= " v_cdm_exp_namesAll ";
179 static String referenceIdTable
= " v_cdm_exp_refAll ";
180 static String refDetailFilter
= " RefDetailID IN (SELECT RefDetailID FROM v_cdm_exp_RefDetail) ";
181 static String factFilter
= " factId IN ( SELECT factId FROM v_cdm_exp_factsAll WHERE FactCategoryFk NOT IN (12, 14, 249, 251))";
182 static String occurrenceFilter
= " occurrenceId IN ( SELECT occurrenceId FROM v_cdm_exp_occurrenceAll )";
183 static String occurrenceSourceFilter
= " occurrenceFk IN ( SELECT occurrenceId FROM v_cdm_exp_occurrenceAll )";
184 static String commonNameFilter
= " commonNameId IN ( SELECT commonNameId FROM v_cdm_exp_commonNamesAll )";
185 static String webMarkerFilter
= " TableNameFk <> 500 OR ( RIdentifierFk IN (SELECT RIdentifier FROM v_cdm_exp_taxaAll)) ";
186 static String authorTeamFilter
= " authorTeamId IN (SELECT drvTab.authorTeamId FROM (SELECT authorTeamId FROM v_cdm_exp_authorTeamsAll) as drvTab) ";
187 static String authorFilter
= " authorId IN (SELECT drvTab.authorId FROM (SELECT authorId FROM v_cdm_exp_authorsAll) as drvTab) ";
191 // **************** ALL *********************
196 public void importEm2CDM (Source source
, ICdmDataSource destination
, DbSchemaValidation hbm2dll
){
197 System
.out
.println("Start import from BerlinModel("+ berlinModelSource
.getDatabase() + ") to " + cdmDestination
.getDatabase() + " ...");
198 //make BerlinModel Source
200 BerlinModelImportConfigurator config
= BerlinModelImportConfigurator
.NewInstance(source
, destination
);
202 config
.setClassificationName(classificationName
);
204 config
.setClassificationUuid(classificationUuid
);
205 config
.setSourceSecId(sourceSecId
);
206 config
.setNomenclaturalCode(nomenclaturalCode
);
207 config
.setIgnoreNull(ignoreNull
);
209 config
.setDoAuthors(doAuthors ^ invers
);
210 config
.setDoReferences(invers ? doReferences
.invers() : doReferences
);
211 config
.setDoTaxonNames(doTaxonNames ^ invers
);
212 config
.setDoRelNames(doRelNames ^ invers
);
213 config
.setDoNameStatus(doNameStatus ^ invers
);
214 config
.setDoTypes(doTypes
); //always false
215 config
.setDoNameFacts(doNameFacts ^ invers
);
216 config
.setDoTaxa(doTaxa ^ invers
);
217 config
.setDoRelTaxa(doRelTaxa ^ invers
);
218 config
.setDoFacts(doFacts ^ invers
);
219 config
.setDoOccurrence(doOccurrences ^ invers
);
220 config
.setDoOccurrenceSources(doOccurrenceSources ^ invers
);
221 config
.setDoCommonNames(doCommonNames ^ invers
);
223 config
.setDoMarker(doMarker
);
224 config
.setDoUser(doUser ^ invers
);
226 config
.setEuroMed(true);
228 config
.setLogNotMatchingOldNames(logNotMatchingOldNames
);
229 config
.setLogMatchingNotExportedOldNames(logMatchingNotExportedOldNames
);
230 config
.setCheckOldNameIsSynonym(checkOldNameIsSynonym
);
232 config
.setUseClassification(useClassification
);
233 config
.setSourceRefUuid(BerlinModelTransformer
.uuidSourceRefEuroMed
);
234 config
.setEditor(editor
);
235 config
.setDbSchemaValidation(hbm2dll
);
236 config
.setUseLastScrutinyAsSec(useLastScrutinyAsSec
);
237 config
.setWarnForDifferingSynonymReference(warnForDifferingSynonymReference
);
239 // maximum number of name facts to import
240 config
.setMaximumNumberOfNameFacts(maximumNumberOfNameFacts
);
242 config
.setInfrGenericRankAbbrev(infrGenericRankAbbrev
);
243 config
.setInfrSpecificRankAbbrev(infrSpecificRankAbbrev
);
244 config
.setRemoveHttpMapsAnchor(removeHttpMapsAnchor
);
246 config
.setDoPreliminaryRefDetailsWithNames(doPreliminaryRefDetailsWithNames
);
249 config
.setTaxonTable(taxonTable
);
250 config
.setClassificationQuery(classificationQuery
);
251 config
.setRelTaxaIdQuery(relPTaxonIdQuery
);
252 config
.setNameIdTable(nameIdTable
);
253 config
.setReferenceIdTable(referenceIdTable
);
254 config
.setAuthorTeamFilter(authorTeamFilter
);
255 config
.setAuthorFilter(authorFilter
);
256 config
.setFactFilter(factFilter
);
257 config
.setRefDetailFilter(refDetailFilter
);
258 config
.setCommonNameFilter(commonNameFilter
);
259 config
.setOccurrenceFilter(occurrenceFilter
);
260 config
.setOccurrenceSourceFilter(occurrenceSourceFilter
);
261 config
.setWebMarkerFilter(webMarkerFilter
);
262 config
.setUseSingleClassification(useSingleClassification
);
265 config
.setSplitTdwgCodes(isSplitTdwgCodes
);
266 config
.setUseEmAreaVocabulary(useEmAreaVocabulary
);
268 config
.setCheck(check
);
269 config
.setEditor(editor
);
270 config
.setRecordsPerTransaction(partitionSize
);
272 config
.setSwitchSpeciesGroup(switchSpeciesGroup
);
275 CdmDefaultImport
<BerlinModelImportConfigurator
> bmImport
= new CdmDefaultImport
<>();
276 bmImport
.invoke(config
);
278 renameRanks(config
, bmImport
);
280 createFeatureTree(config
, bmImport
);
282 changeCommonNameLabel(config
, bmImport
);
284 createUsersAndRoles(config
, bmImport
);
286 runTransmissionEngine(config
, bmImport
);
288 importShapefile(config
, bmImport
);
290 // markAreasAsHidden(config, bmImport); //has been moved to BM occurrence import
292 System
.out
.println("End import from BerlinModel ("+ source
.getDatabase() + ")...");
295 //Rename Ranks (still needed?)
296 private void renameRanks(BerlinModelImportConfigurator config
,
297 CdmDefaultImport
<BerlinModelImportConfigurator
> bmImport
) {
299 if (config
.isDoTaxonNames() && (config
.getCheck().isImport() ) ){
300 ICdmRepository app
= bmImport
.getCdmAppController();
301 TransactionStatus tx
= app
.startTransaction();
303 Rank sectBot
= (Rank
)app
.getTermService().find(Rank
.SECTION_BOTANY().getUuid());
304 Representation repr
= sectBot
.getRepresentation(Language
.ENGLISH());
305 repr
.setAbbreviatedLabel(repr
.getAbbreviatedLabel().replace("(bot.)", "").trim());
306 repr
.setLabel(repr
.getLabel().replace("(Botany)", "").trim());
307 sectBot
.setTitleCache(null, false); //to definitely update the titleCache also
308 app
.getTermService().saveOrUpdate(sectBot
);
310 Rank subSectBot
= (Rank
)app
.getTermService().find(Rank
.SECTION_BOTANY().getUuid());
311 repr
= subSectBot
.getRepresentation(Language
.ENGLISH());
312 repr
.setAbbreviatedLabel(repr
.getAbbreviatedLabel().replace("(bot.)", "").trim());
313 repr
.setLabel(repr
.getLabel().replace("(Botany)", "").trim());
314 subSectBot
.setTitleCache(null, false); //to definitely update the titleCache also
315 app
.getTermService().saveOrUpdate(subSectBot
);
316 app
.commitTransaction(tx
);
317 } catch (Exception e
) {
319 logger
.error("Exception in renameRanks: " + e
.getMessage());
324 //create feature tree
325 private void createFeatureTree(BerlinModelImportConfigurator config
,
326 CdmDefaultImport
<BerlinModelImportConfigurator
> bmImport
){
327 if (config
.isDoFacts() && (config
.getCheck().isImport() ) ){
329 ICdmRepository app
= bmImport
.getCdmAppController();
330 TransactionStatus tx
= app
.startTransaction();
333 FeatureTree tree
= TreeCreator
.flatTree(featureTreeUuid
, config
.getFeatureMap(), featureKeyList
);
334 tree
.setTitleCache("Euro+Med Feature Tree", true);
335 FeatureNode imageNode
= FeatureNode
.NewInstance(Feature
.IMAGE());
336 tree
.getRoot().addChild(imageNode
);
337 FeatureNode distributionNode
= FeatureNode
.NewInstance(Feature
.DISTRIBUTION());
338 tree
.getRoot().addChild(distributionNode
, 1);
339 FeatureNode commonNameNode
= FeatureNode
.NewInstance(Feature
.COMMON_NAME());
340 tree
.getRoot().addChild(commonNameNode
, 2);
341 app
.getFeatureTreeService().saveOrUpdate(tree
);
343 app
.commitTransaction(tx
);
344 } catch (Exception e
) {
346 logger
.error("Exception in createFeatureTree: " + e
.getMessage());
351 //Change common name label
352 private void changeCommonNameLabel(BerlinModelImportConfigurator config
,
353 CdmDefaultImport
<BerlinModelImportConfigurator
> bmImport
) {
354 if (config
.isDoFacts() && (config
.getCheck().isImport() ) ){
356 ICdmRepository app
= bmImport
.getCdmAppController();
357 TransactionStatus tx
= app
.startTransaction();
359 DefinedTermBase
<?
> commonNameFeature
= app
.getTermService().find(Feature
.COMMON_NAME().getUuid());
360 commonNameFeature
.setLabel("Common Names", Language
.ENGLISH());
361 commonNameFeature
.setTitleCache(null, false); //to definitely update the titleCache also
362 app
.getTermService().saveOrUpdate(commonNameFeature
);
364 app
.commitTransaction(tx
);
365 } catch (Exception e
) {
367 logger
.error("Exception in changeCommonNameLabel: " + e
.getMessage());
372 //1. run transmission engine #3979
373 private void runTransmissionEngine(BerlinModelImportConfigurator config
,
374 CdmDefaultImport
<BerlinModelImportConfigurator
> bmImport
) {
376 if (doRunTransmissionEngine
&& (config
.getCheck().isImport() ) ){
378 ICdmRepository app
= bmImport
.getCdmAppController();
380 final List
<String
> term_init_strategy
= Arrays
.asList(new String
[]{
384 UUID uuidSuperAreaLevel
= BerlinModelTransformer
.uuidEuroMedAreaLevelFirst
;
385 NamedAreaLevel euroMedLevel1
= (NamedAreaLevel
)app
.getTermService().find(uuidSuperAreaLevel
);
387 Pager
<NamedArea
> areaPager
= app
.getTermService().list(
389 (NamedAreaType
) null,
392 (List
<OrderHint
>) null,
394 TransmissionEngineDistribution transmissionEngineDistribution
= (TransmissionEngineDistribution
)app
.getBean("transmissionEngineDistribution");
395 transmissionEngineDistribution
.accumulate(
396 AggregationMode
.byAreasAndRanks
,
397 areaPager
.getRecords(),
398 Rank
.UNRANKED_INFRASPECIFIC(), //or do we even want to start from lower (UNKNOWN?)
401 DefaultProgressMonitor
.NewInstance());
402 } catch (Exception e
) {
404 logger
.error("Exception in markAreasAsHidden: " + e
.getMessage());
409 // //5.Mark areas to be hidden #3979 .5
410 // private void markAreasAsHidden(BerlinModelImportConfigurator config,
411 // CdmDefaultImport<BerlinModelImportConfigurator> bmImport) {
413 // if (config.isDoOccurrence() && (config.getCheck().isImport())){
415 // ICdmRepository app = bmImport.getCdmAppController();
416 // TransactionStatus tx = app.startTransaction();
418 // MarkerType hiddenAreaMarkerType = MarkerType.NewInstance("Used to hide distributions for the named areas in publications", "Hidden Area", null);
419 // hiddenAreaMarkerType.setUuid(BerlinModelTransformer.uuidHiddenArea);
420 // @SuppressWarnings("unchecked")
421 // TermVocabulary<MarkerType> vocUserDefinedMarkerTypes = app.getVocabularyService().find(CdmImportBase.uuidUserDefinedMarkerTypeVocabulary);
422 // if (vocUserDefinedMarkerTypes == null){
423 // String message = "Marker type vocabulary could not be found. Hidden areas not added.";
424 // logger.error(message);
425 // System.out.println(message);
427 // vocUserDefinedMarkerTypes.addTerm(hiddenAreaMarkerType);
428 // app.getVocabularyService().saveOrUpdate(vocUserDefinedMarkerTypes);
430 // //Add hidden area marker to Rs(C) and Rs(N)
431 // hideArea(app, hiddenAreaMarkerType, BerlinModelTransformer.uuidRs);
432 // hideArea(app, hiddenAreaMarkerType, BerlinModelTransformer.uuidRs_B);
433 // hideArea(app, hiddenAreaMarkerType, BerlinModelTransformer.uuidRs_C);
434 // hideArea(app, hiddenAreaMarkerType, BerlinModelTransformer.uuidRs_E);
435 // hideArea(app, hiddenAreaMarkerType, BerlinModelTransformer.uuidRs_N);
436 // hideArea(app, hiddenAreaMarkerType, BerlinModelTransformer.uuidRs_K);
437 // hideArea(app, hiddenAreaMarkerType, BerlinModelTransformer.uuidRs_W);
439 // app.commitTransaction(tx);
440 // } catch (Exception e) {
441 // e.printStackTrace();
442 // logger.error("Exception in markAreasAsHidden: " + e.getMessage());
447 // private void hideArea(ICdmRepository app, MarkerType hiddenAreaMarkerType, UUID areaUuid) {
448 // NamedArea area = (NamedArea)app.getTermService().find(areaUuid);
449 // area.addMarker(Marker.NewInstance(hiddenAreaMarkerType, true));
450 // app.getTermService().saveOrUpdate(area);
453 //2. import shapefile attributes #3979 .2
454 private void importShapefile(BerlinModelImportConfigurator config
,
455 CdmDefaultImport
<BerlinModelImportConfigurator
> bmImport
) {
457 if (config
.isDoOccurrence() && (config
.getCheck().isImport())){
460 UUID areaVocabularyUuid
= BerlinModelTransformer
.uuidVocEuroMedAreas
;
461 List
<String
> idSearchFields
= Arrays
.asList(new String
[]{"EMAREA","PARENT"});
462 String wmsLayerName
= "euromed_2013";
463 Set
<UUID
> areaUuidSet
= null;
465 ICdmRepository app
= bmImport
.getCdmAppController();
466 IEditGeoService geoService
= (IEditGeoService
)app
.getBean("editGeoService");
468 Map
<NamedArea
, String
> resultMap
;
470 InputStream in
= EuroMedActivator
.class.getResourceAsStream("/euromed/euromed_2013.csv");
471 Reader reader
= new InputStreamReader(in
, "UTF-8");
473 resultMap
= geoService
.mapShapeFileToNamedAreas(
474 reader
, idSearchFields
, wmsLayerName
, areaVocabularyUuid
, areaUuidSet
);
475 Map
<String
, String
> flatResultMap
= new HashMap
<>(resultMap
.size());
476 for(NamedArea area
: resultMap
.keySet()){
477 flatResultMap
.put(area
.getTitleCache() + " [" + area
.getUuid() + "]", resultMap
.get(area
));
479 } catch (IOException e
) {
480 String message
= "IOException when reading from mapping file or creating result map.";
481 logger
.error(message
);
482 System
.out
.println(message
);
484 } catch (Exception e
) {
486 logger
.error("Exception in importShapefile: " + e
.getMessage());
491 //4. Create users and assign roles #3979
492 private void createUsersAndRoles(BerlinModelImportConfigurator config
,
493 CdmDefaultImport
<BerlinModelImportConfigurator
> bmImport
) {
496 if (config
.isDoRelTaxa() && (config
.getCheck().isImport())){
497 ICdmRepository app
= bmImport
.getCdmAppController();
498 TransactionStatus tx
= app
.startTransaction();
501 String eraabstraube
= "eraabstraube";
502 List
<User
> users
= app
.getUserService().listByUsername(eraabstraube
, MatchMode
.EXACT
, null, null, null, null, null);
503 User userEraabStraube
;
504 if (users
.isEmpty()){
505 userEraabStraube
= User
.NewInstance(eraabstraube
, eraabstraube
);
507 userEraabStraube
= users
.get(0);
509 if (userEraabStraube
.getPerson() == null){
510 Person eckhard
= Person
.NewInstance();
511 eckhard
.setFamilyName("von Raab-Straube");
512 eckhard
.setGivenName("Eckhard");
513 eckhard
.setPrefix("Dr.");
514 userEraabStraube
.setPerson(eckhard
);
516 app
.getUserService().saveOrUpdate(userEraabStraube
);
519 Group groupEditor
= app
.getGroupService().load(Group
.GROUP_EDITOR_UUID
);
520 groupEditor
.addMember(userEraabStraube
);
521 app
.getGroupService().saveOrUpdate(groupEditor
);
523 Group groupProjectManager
= app
.getGroupService().load(Group
.GROUP_PROJECT_MANAGER_UUID
);
524 groupProjectManager
.addMember(userEraabStraube
);
525 app
.getGroupService().saveOrUpdate(groupProjectManager
);
527 String
[] publishRoles
= new String
[]{Role
.ROLE_PUBLISH
.toString()};
528 Group groupPublisher
= checkGroup(app
.getGroupService(), Group
.GROUP_PUBLISHER_UUID
, "Publisher", publishRoles
);
529 groupPublisher
.addMember(userEraabStraube
);
530 app
.getGroupService().saveOrUpdate(groupPublisher
);
532 UUID uuidEuroMedPlantBaseGroup
= UUID
.fromString("91be42ea-ad04-4458-9836-389277e773db");
533 String
[] emPlantBaseRoles
= new String
[]{"TAXONNODE.[CREATE,READ,UPDATE,DELETE]"};
534 Group euroMedPlantbase
= checkGroup(app
.getGroupService(), uuidEuroMedPlantBaseGroup
, "Euro+Med Plantbase", emPlantBaseRoles
);
535 euroMedPlantbase
.addMember(userEraabStraube
);
536 app
.getGroupService().saveOrUpdate(euroMedPlantbase
);
539 String cichorieaeEditor
= "cichorieae-editor";
540 app
.getUserService().listByUsername(cichorieaeEditor
, MatchMode
.EXACT
, null, null, null, null, null);
542 if (users
.isEmpty()){
543 userCichEditor
= User
.NewInstance(cichorieaeEditor
, cichorieaeEditor
);
545 userCichEditor
= users
.get(0);
547 app
.getUserService().saveOrUpdate(userCichEditor
);
550 groupEditor
.addMember(userCichEditor
);
551 app
.getGroupService().saveOrUpdate(groupEditor
);
553 UUID uuidCichorieaeSubtree
= null;
554 UUID uuidCichorieae
= UUID
.fromString("63c7dbeb-b9a2-48b8-a75f-e3fe5e161f7c");
555 Taxon cich
= (Taxon
)app
.getTaxonService().find(uuidCichorieae
);
557 if (!cich
.getTaxonNodes().isEmpty()){
558 TaxonNode cichNode
= cich
.getTaxonNodes().iterator().next();
559 uuidCichorieaeSubtree
= cichNode
.getUuid();
563 String
[] cichorieaeRoles
= new String
[]{};
564 if (uuidCichorieaeSubtree
!= null){
565 cichorieaeRoles
= new String
[]{"TAXONNODE.[CREATE,READ,UPDATE,DELETE]{"+uuidCichorieaeSubtree
.toString()+"}"};
567 String message
= "Cichorieae node could not be found for cichorieae-editor role";
568 logger
.warn(message
);
569 System
.out
.println(message
);
571 UUID uuidCichorieaeGroup
= UUID
.fromString("a630938d-dd4f-48c2-9406-91def487b11e");
572 String cichorieaeGroupName
= "Cichorieae";
573 Group cichorieaeGroup
= checkGroup(app
.getGroupService(), uuidCichorieaeGroup
, cichorieaeGroupName
, cichorieaeRoles
);
574 cichorieaeGroup
.addMember(userCichEditor
);
575 app
.getGroupService().saveOrUpdate(cichorieaeGroup
);
577 app
.commitTransaction(tx
);
579 } catch (Exception e
) {
581 logger
.error("Exception in createUsersAndRoles: " + e
.getMessage());
586 * copied from {@link FirstDataInserter#checkGroup}
588 private Group
checkGroup(IGroupService groupService
, UUID groupUuid
, String groupName
, String
[] requiredAuthorities
) {
589 Group group
= groupService
.load(groupUuid
);
591 group
= Group
.NewInstance();
592 group
.setUuid(groupUuid
);
593 logger
.info("New Group '" + groupName
+ "' created");
595 group
.setName(groupName
); // force name
597 Set
<GrantedAuthority
> grantedAuthorities
= group
.getGrantedAuthorities();
599 for(String a
: requiredAuthorities
){
600 boolean isMissing
= true;
601 for(GrantedAuthority ga
: grantedAuthorities
){
602 if(a
.equals(ga
.getAuthority())){
608 GrantedAuthorityImpl newGa
= GrantedAuthorityImpl
.NewInstance(a
);
609 group
.addGrantedAuthority(newGa
);
610 logger
.info("New GrantedAuthority '" + a
+ "' added to '" + groupName
+ "'");
613 groupService
.saveOrUpdate(group
);
614 logger
.info("Check of group '" + groupName
+ "' done");
622 public static void main(String
[] args
) {
623 EuroMedActivator importActivator
= new EuroMedActivator();
624 Source source
= berlinModelSource
;
625 ICdmDataSource cdmRepository
= CdmDestinations
.chooseDestination(args
) != null ? CdmDestinations
.chooseDestination(args
) : cdmDestination
;
627 importActivator
.importEm2CDM(source
, cdmRepository
, hbm2dll
);
628 if (includePesiExport
){
629 //not available from here since E+M was moved to app-import
630 // PesiExportActivatorEM exportActivator = new PesiExportActivatorEM();
631 // exportActivator.doExport(cdmRepository);