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
.CREATE
;
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();
90 static final CHECK check
= CHECK
.CHECK_ONLY
;
92 static final boolean doUser
= true;
94 static final boolean doAuthors
= true;
96 static final DO_REFERENCES doReferences
= DO_REFERENCES
.ALL
;
98 static final boolean doTaxonNames
= true;
99 static final boolean doRelNames
= true;
100 static final boolean doNameStatus
= true;
101 static final boolean doNameFacts
= true;
104 static final boolean doTaxa
= true;
105 static final boolean doFacts
= true;
106 static final boolean doRelTaxa
= true;
107 static final boolean doOccurrences
= false;
108 static final boolean doOccurrenceSources
= true;
109 static final boolean doCommonNames
= true; //currently takes very long
111 //serious types do not exist in E+M except for name types which are handled in name relations
112 static final boolean doTypes
= false; //serious types do not exist in E+M except for name types which are handled in name relations
115 static final boolean doRunTransmissionEngine
= false; // (hbm2dll == DbSchemaValidation.VALIDATE);
118 static final boolean doMarker
= false; //no relevant markers exist
120 boolean invers
= !(hbm2dll
== DbSchemaValidation
.CREATE
);
122 boolean doPreliminaryRefDetailsWithNames
= true;
124 boolean logNotMatchingOldNames
= false;
125 boolean logMatchingNotExportedOldNames
= false; //true
126 boolean checkOldNameIsSynonym
= true;
128 static final boolean includePesiExport
= false;
130 static final int sourceSecId
= 7000000; //500000
131 static final UUID classificationUuid
= UUID
.fromString("314a68f9-8449-495a-91c2-92fde8bcf344");
132 static final boolean useSingleClassification
= true;
133 static final String classificationName
= "Euro+Med 2018";
134 static final UUID featureTreeUuid
= UUID
.fromString("6a5e1c2b-ec0d-46c8-9c7d-a2059267ffb7");
135 static final Object
[] featureKeyList
= new Integer
[]{1, 31, 4, 98, 41};
137 // set to zero for unlimited nameFacts
138 static final int maximumNumberOfNameFacts
= 0;
140 static final int partitionSize
= 2500;
144 static final EDITOR editor
= EDITOR
.EDITOR_AS_EDITOR
;
147 static final NomenclaturalCode nomenclaturalCode
= NomenclaturalCode
.ICNAFP
;
150 static final boolean ignoreNull
= true;
152 static final boolean switchSpeciesGroup
= true;
154 static boolean useClassification
= true;
156 static boolean isSplitTdwgCodes
= false;
157 static boolean useEmAreaVocabulary
= true;
159 private final boolean removeHttpMapsAnchor
= true;
162 static final String infrGenericRankAbbrev
= "[unranked]";
163 static final String infrSpecificRankAbbrev
= "[unranked]";
165 static boolean useLastScrutinyAsSec
= true;
166 static boolean warnForDifferingSynonymReference
= false;
169 static String taxonTable
= "v_cdm_exp_taxaAll";
170 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
;
171 static String relPTaxonIdQuery
= " SELECT r.RelPTaxonId "
172 + " FROM RelPTaxon AS r "
173 + " INNER JOIN v_cdm_exp_taxaDirect AS a ON r.PTNameFk2 = a.PTNameFk AND r.PTRefFk2 = a.PTRefFk "
174 + " INNER JOIN PTaxon As pt1 ON pt1.PTNameFk = r.PTNameFk1 AND pt1.PTRefFk = r.PTRefFk1 "
175 + " 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
176 + " AND NOT (pt1.PTRefFk = 8000000 AND pt1.publishFlag = 0) ";
177 static String nameIdTable
= " v_cdm_exp_namesAll ";
178 static String referenceIdTable
= " v_cdm_exp_refAll ";
179 static String refDetailFilter
= " RefDetailID IN (SELECT RefDetailID FROM v_cdm_exp_RefDetail) ";
180 static String factFilter
= " factId IN ( SELECT factId FROM v_cdm_exp_factsAll WHERE FactCategoryFk NOT IN (12, 14, 249, 251))";
181 static String occurrenceFilter
= " occurrenceId IN ( SELECT occurrenceId FROM v_cdm_exp_occurrenceAll )";
182 static String occurrenceSourceFilter
= " occurrenceFk IN ( SELECT occurrenceId FROM v_cdm_exp_occurrenceAll )";
183 static String commonNameFilter
= " commonNameId IN ( SELECT commonNameId FROM v_cdm_exp_commonNamesAll )";
184 static String webMarkerFilter
= " TableNameFk <> 500 OR ( RIdentifierFk IN (SELECT RIdentifier FROM v_cdm_exp_taxaAll)) ";
185 static String authorTeamFilter
= null; //*/ " authorTeamId IN (SELECT authorTeamId FROM v_cdm_exp_authorTeamsAll) ";
186 static String authorFilter
= null; //*/ " authorId IN (SELECT authorId FROM v_cdm_exp_authorsAll) ";
190 // **************** ALL *********************
195 public void importEm2CDM (Source source
, ICdmDataSource destination
, DbSchemaValidation hbm2dll
){
196 System
.out
.println("Start import from BerlinModel("+ berlinModelSource
.getDatabase() + ") to " + cdmDestination
.getDatabase() + " ...");
197 //make BerlinModel Source
199 BerlinModelImportConfigurator config
= BerlinModelImportConfigurator
.NewInstance(source
, destination
);
201 config
.setClassificationName(classificationName
);
203 config
.setClassificationUuid(classificationUuid
);
204 config
.setSourceSecId(sourceSecId
);
205 config
.setNomenclaturalCode(nomenclaturalCode
);
206 config
.setIgnoreNull(ignoreNull
);
208 config
.setDoAuthors(doAuthors ^ invers
);
209 config
.setDoReferences(invers ? doReferences
.invers() : doReferences
);
210 config
.setDoTaxonNames(doTaxonNames ^ invers
);
211 config
.setDoRelNames(doRelNames ^ invers
);
212 config
.setDoNameStatus(doNameStatus ^ invers
);
213 config
.setDoTypes(doTypes
); //always false
214 config
.setDoNameFacts(doNameFacts ^ invers
);
215 config
.setDoTaxa(doTaxa ^ invers
);
216 config
.setDoRelTaxa(doRelTaxa ^ invers
);
217 config
.setDoFacts(doFacts ^ invers
);
218 config
.setDoOccurrence(doOccurrences ^ invers
);
219 config
.setDoOccurrenceSources(doOccurrenceSources ^ invers
);
220 config
.setDoCommonNames(doCommonNames ^ invers
);
222 config
.setDoMarker(doMarker
);
223 config
.setDoUser(doUser ^ invers
);
225 config
.setEuroMed(true);
227 config
.setUseClassification(useClassification
);
228 config
.setSourceRefUuid(BerlinModelTransformer
.uuidSourceRefEuroMed
);
229 config
.setEditor(editor
);
230 config
.setDbSchemaValidation(hbm2dll
);
231 config
.setUseLastScrutinyAsSec(useLastScrutinyAsSec
);
232 config
.setWarnForDifferingSynonymReference(warnForDifferingSynonymReference
);
234 // maximum number of name facts to import
235 config
.setMaximumNumberOfNameFacts(maximumNumberOfNameFacts
);
237 config
.setInfrGenericRankAbbrev(infrGenericRankAbbrev
);
238 config
.setInfrSpecificRankAbbrev(infrSpecificRankAbbrev
);
239 config
.setRemoveHttpMapsAnchor(removeHttpMapsAnchor
);
241 config
.setDoPreliminaryRefDetailsWithNames(doPreliminaryRefDetailsWithNames
);
244 config
.setTaxonTable(taxonTable
);
245 config
.setClassificationQuery(classificationQuery
);
246 config
.setRelTaxaIdQuery(relPTaxonIdQuery
);
247 config
.setNameIdTable(nameIdTable
);
248 config
.setReferenceIdTable(referenceIdTable
);
249 config
.setAuthorTeamFilter(authorTeamFilter
);
250 config
.setAuthorFilter(authorFilter
);
251 config
.setFactFilter(factFilter
);
252 config
.setRefDetailFilter(refDetailFilter
);
253 config
.setCommonNameFilter(commonNameFilter
);
254 config
.setOccurrenceFilter(occurrenceFilter
);
255 config
.setOccurrenceSourceFilter(occurrenceSourceFilter
);
256 config
.setWebMarkerFilter(webMarkerFilter
);
257 config
.setUseSingleClassification(useSingleClassification
);
260 config
.setSplitTdwgCodes(isSplitTdwgCodes
);
261 config
.setUseEmAreaVocabulary(useEmAreaVocabulary
);
263 config
.setCheck(check
);
264 config
.setEditor(editor
);
265 config
.setRecordsPerTransaction(partitionSize
);
267 config
.setSwitchSpeciesGroup(switchSpeciesGroup
);
270 CdmDefaultImport
<BerlinModelImportConfigurator
> bmImport
= new CdmDefaultImport
<>();
271 bmImport
.invoke(config
);
273 renameRanks(config
, bmImport
);
275 createFeatureTree(config
, bmImport
);
277 changeCommonNameLabel(config
, bmImport
);
279 createUsersAndRoles(config
, bmImport
);
281 runTransmissionEngine(config
, bmImport
);
283 importShapefile(config
, bmImport
);
285 // markAreasAsHidden(config, bmImport); //has been moved to BM occurrence import
287 System
.out
.println("End import from BerlinModel ("+ source
.getDatabase() + ")...");
290 //Rename Ranks (still needed?)
291 private void renameRanks(BerlinModelImportConfigurator config
,
292 CdmDefaultImport
<BerlinModelImportConfigurator
> bmImport
) {
294 if (config
.isDoTaxonNames() && (config
.getCheck().isImport() ) ){
295 ICdmRepository app
= bmImport
.getCdmAppController();
296 TransactionStatus tx
= app
.startTransaction();
298 Rank sectBot
= (Rank
)app
.getTermService().find(Rank
.SECTION_BOTANY().getUuid());
299 Representation repr
= sectBot
.getRepresentation(Language
.ENGLISH());
300 repr
.setAbbreviatedLabel(repr
.getAbbreviatedLabel().replace("(bot.)", "").trim());
301 repr
.setLabel(repr
.getLabel().replace("(Botany)", "").trim());
302 sectBot
.setTitleCache(null, false); //to definitely update the titleCache also
303 app
.getTermService().saveOrUpdate(sectBot
);
305 Rank subSectBot
= (Rank
)app
.getTermService().find(Rank
.SECTION_BOTANY().getUuid());
306 repr
= subSectBot
.getRepresentation(Language
.ENGLISH());
307 repr
.setAbbreviatedLabel(repr
.getAbbreviatedLabel().replace("(bot.)", "").trim());
308 repr
.setLabel(repr
.getLabel().replace("(Botany)", "").trim());
309 subSectBot
.setTitleCache(null, false); //to definitely update the titleCache also
310 app
.getTermService().saveOrUpdate(subSectBot
);
311 app
.commitTransaction(tx
);
312 } catch (Exception e
) {
314 logger
.error("Exception in renameRanks: " + e
.getMessage());
319 //create feature tree
320 private void createFeatureTree(BerlinModelImportConfigurator config
,
321 CdmDefaultImport
<BerlinModelImportConfigurator
> bmImport
){
322 if (config
.isDoFacts() && (config
.getCheck().isImport() ) ){
324 ICdmRepository app
= bmImport
.getCdmAppController();
325 TransactionStatus tx
= app
.startTransaction();
328 FeatureTree tree
= TreeCreator
.flatTree(featureTreeUuid
, config
.getFeatureMap(), featureKeyList
);
329 tree
.setTitleCache("Euro+Med Feature Tree", true);
330 FeatureNode imageNode
= FeatureNode
.NewInstance(Feature
.IMAGE());
331 tree
.getRoot().addChild(imageNode
);
332 FeatureNode distributionNode
= FeatureNode
.NewInstance(Feature
.DISTRIBUTION());
333 tree
.getRoot().addChild(distributionNode
, 1);
334 FeatureNode commonNameNode
= FeatureNode
.NewInstance(Feature
.COMMON_NAME());
335 tree
.getRoot().addChild(commonNameNode
, 2);
336 app
.getFeatureTreeService().saveOrUpdate(tree
);
338 app
.commitTransaction(tx
);
339 } catch (Exception e
) {
341 logger
.error("Exception in createFeatureTree: " + e
.getMessage());
346 //Change common name label
347 private void changeCommonNameLabel(BerlinModelImportConfigurator config
,
348 CdmDefaultImport
<BerlinModelImportConfigurator
> bmImport
) {
349 if (config
.isDoFacts() && (config
.getCheck().isImport() ) ){
351 ICdmRepository app
= bmImport
.getCdmAppController();
352 TransactionStatus tx
= app
.startTransaction();
354 DefinedTermBase
<?
> commonNameFeature
= app
.getTermService().find(Feature
.COMMON_NAME().getUuid());
355 commonNameFeature
.setLabel("Common Names", Language
.ENGLISH());
356 commonNameFeature
.setTitleCache(null, false); //to definitely update the titleCache also
357 app
.getTermService().saveOrUpdate(commonNameFeature
);
359 app
.commitTransaction(tx
);
360 } catch (Exception e
) {
362 logger
.error("Exception in changeCommonNameLabel: " + e
.getMessage());
367 //1. run transmission engine #3979
368 private void runTransmissionEngine(BerlinModelImportConfigurator config
,
369 CdmDefaultImport
<BerlinModelImportConfigurator
> bmImport
) {
371 if (doRunTransmissionEngine
&& (config
.getCheck().isImport() ) ){
373 ICdmRepository app
= bmImport
.getCdmAppController();
375 final List
<String
> term_init_strategy
= Arrays
.asList(new String
[]{
379 UUID uuidSuperAreaLevel
= BerlinModelTransformer
.uuidEuroMedAreaLevelFirst
;
380 NamedAreaLevel euroMedLevel1
= (NamedAreaLevel
)app
.getTermService().find(uuidSuperAreaLevel
);
382 Pager
<NamedArea
> areaPager
= app
.getTermService().list(
384 (NamedAreaType
) null,
387 (List
<OrderHint
>) null,
389 TransmissionEngineDistribution transmissionEngineDistribution
= (TransmissionEngineDistribution
)app
.getBean("transmissionEngineDistribution");
390 transmissionEngineDistribution
.accumulate(
391 AggregationMode
.byAreasAndRanks
,
392 areaPager
.getRecords(),
393 Rank
.UNRANKED_INFRASPECIFIC(), //or do we even want to start from lower (UNKNOWN?)
396 DefaultProgressMonitor
.NewInstance());
397 } catch (Exception e
) {
399 logger
.error("Exception in markAreasAsHidden: " + e
.getMessage());
404 // //5.Mark areas to be hidden #3979 .5
405 // private void markAreasAsHidden(BerlinModelImportConfigurator config,
406 // CdmDefaultImport<BerlinModelImportConfigurator> bmImport) {
408 // if (config.isDoOccurrence() && (config.getCheck().isImport())){
410 // ICdmRepository app = bmImport.getCdmAppController();
411 // TransactionStatus tx = app.startTransaction();
413 // MarkerType hiddenAreaMarkerType = MarkerType.NewInstance("Used to hide distributions for the named areas in publications", "Hidden Area", null);
414 // hiddenAreaMarkerType.setUuid(BerlinModelTransformer.uuidHiddenArea);
415 // @SuppressWarnings("unchecked")
416 // TermVocabulary<MarkerType> vocUserDefinedMarkerTypes = app.getVocabularyService().find(CdmImportBase.uuidUserDefinedMarkerTypeVocabulary);
417 // if (vocUserDefinedMarkerTypes == null){
418 // String message = "Marker type vocabulary could not be found. Hidden areas not added.";
419 // logger.error(message);
420 // System.out.println(message);
422 // vocUserDefinedMarkerTypes.addTerm(hiddenAreaMarkerType);
423 // app.getVocabularyService().saveOrUpdate(vocUserDefinedMarkerTypes);
425 // //Add hidden area marker to Rs(C) and Rs(N)
426 // hideArea(app, hiddenAreaMarkerType, BerlinModelTransformer.uuidRs);
427 // hideArea(app, hiddenAreaMarkerType, BerlinModelTransformer.uuidRs_B);
428 // hideArea(app, hiddenAreaMarkerType, BerlinModelTransformer.uuidRs_C);
429 // hideArea(app, hiddenAreaMarkerType, BerlinModelTransformer.uuidRs_E);
430 // hideArea(app, hiddenAreaMarkerType, BerlinModelTransformer.uuidRs_N);
431 // hideArea(app, hiddenAreaMarkerType, BerlinModelTransformer.uuidRs_K);
432 // hideArea(app, hiddenAreaMarkerType, BerlinModelTransformer.uuidRs_W);
434 // app.commitTransaction(tx);
435 // } catch (Exception e) {
436 // e.printStackTrace();
437 // logger.error("Exception in markAreasAsHidden: " + e.getMessage());
442 // private void hideArea(ICdmRepository app, MarkerType hiddenAreaMarkerType, UUID areaUuid) {
443 // NamedArea area = (NamedArea)app.getTermService().find(areaUuid);
444 // area.addMarker(Marker.NewInstance(hiddenAreaMarkerType, true));
445 // app.getTermService().saveOrUpdate(area);
448 //2. import shapefile attributes #3979 .2
449 private void importShapefile(BerlinModelImportConfigurator config
,
450 CdmDefaultImport
<BerlinModelImportConfigurator
> bmImport
) {
452 if (config
.isDoOccurrence() && (config
.getCheck().isImport())){
455 UUID areaVocabularyUuid
= BerlinModelTransformer
.uuidVocEuroMedAreas
;
456 List
<String
> idSearchFields
= Arrays
.asList(new String
[]{"EMAREA","PARENT"});
457 String wmsLayerName
= "euromed_2013";
458 Set
<UUID
> areaUuidSet
= null;
460 ICdmRepository app
= bmImport
.getCdmAppController();
461 IEditGeoService geoService
= (IEditGeoService
)app
.getBean("editGeoService");
463 Map
<NamedArea
, String
> resultMap
;
465 InputStream in
= EuroMedActivator
.class.getResourceAsStream("/euromed/euromed_2013.csv");
466 Reader reader
= new InputStreamReader(in
, "UTF-8");
468 resultMap
= geoService
.mapShapeFileToNamedAreas(
469 reader
, idSearchFields
, wmsLayerName
, areaVocabularyUuid
, areaUuidSet
);
470 Map
<String
, String
> flatResultMap
= new HashMap
<>(resultMap
.size());
471 for(NamedArea area
: resultMap
.keySet()){
472 flatResultMap
.put(area
.getTitleCache() + " [" + area
.getUuid() + "]", resultMap
.get(area
));
474 } catch (IOException e
) {
475 String message
= "IOException when reading from mapping file or creating result map.";
476 logger
.error(message
);
477 System
.out
.println(message
);
479 } catch (Exception e
) {
481 logger
.error("Exception in importShapefile: " + e
.getMessage());
486 //4. Create users and assign roles #3979
487 private void createUsersAndRoles(BerlinModelImportConfigurator config
,
488 CdmDefaultImport
<BerlinModelImportConfigurator
> bmImport
) {
491 if (config
.isDoRelTaxa() && (config
.getCheck().isImport())){
492 ICdmRepository app
= bmImport
.getCdmAppController();
493 TransactionStatus tx
= app
.startTransaction();
496 String eraabstraube
= "eraabstraube";
497 List
<User
> users
= app
.getUserService().listByUsername(eraabstraube
, MatchMode
.EXACT
, null, null, null, null, null);
498 User userEraabStraube
;
499 if (users
.isEmpty()){
500 userEraabStraube
= User
.NewInstance(eraabstraube
, eraabstraube
);
502 userEraabStraube
= users
.get(0);
504 if (userEraabStraube
.getPerson() == null){
505 Person eckhard
= Person
.NewInstance();
506 eckhard
.setFamilyName("von Raab-Straube");
507 eckhard
.setGivenName("Eckhard");
508 eckhard
.setPrefix("Dr.");
509 userEraabStraube
.setPerson(eckhard
);
511 app
.getUserService().saveOrUpdate(userEraabStraube
);
514 Group groupEditor
= app
.getGroupService().load(Group
.GROUP_EDITOR_UUID
);
515 groupEditor
.addMember(userEraabStraube
);
516 app
.getGroupService().saveOrUpdate(groupEditor
);
518 Group groupProjectManager
= app
.getGroupService().load(Group
.GROUP_PROJECT_MANAGER_UUID
);
519 groupProjectManager
.addMember(userEraabStraube
);
520 app
.getGroupService().saveOrUpdate(groupProjectManager
);
522 String
[] publishRoles
= new String
[]{Role
.ROLE_PUBLISH
.toString()};
523 Group groupPublisher
= checkGroup(app
.getGroupService(), Group
.GROUP_PUBLISHER_UUID
, "Publisher", publishRoles
);
524 groupPublisher
.addMember(userEraabStraube
);
525 app
.getGroupService().saveOrUpdate(groupPublisher
);
527 UUID uuidEuroMedPlantBaseGroup
= UUID
.fromString("91be42ea-ad04-4458-9836-389277e773db");
528 String
[] emPlantBaseRoles
= new String
[]{"TAXONNODE.[CREATE,READ,UPDATE,DELETE]"};
529 Group euroMedPlantbase
= checkGroup(app
.getGroupService(), uuidEuroMedPlantBaseGroup
, "Euro+Med Plantbase", emPlantBaseRoles
);
530 euroMedPlantbase
.addMember(userEraabStraube
);
531 app
.getGroupService().saveOrUpdate(euroMedPlantbase
);
534 String cichorieaeEditor
= "cichorieae-editor";
535 app
.getUserService().listByUsername(cichorieaeEditor
, MatchMode
.EXACT
, null, null, null, null, null);
537 if (users
.isEmpty()){
538 userCichEditor
= User
.NewInstance(cichorieaeEditor
, cichorieaeEditor
);
540 userCichEditor
= users
.get(0);
542 app
.getUserService().saveOrUpdate(userCichEditor
);
545 groupEditor
.addMember(userCichEditor
);
546 app
.getGroupService().saveOrUpdate(groupEditor
);
548 UUID uuidCichorieaeSubtree
= null;
549 UUID uuidCichorieae
= UUID
.fromString("63c7dbeb-b9a2-48b8-a75f-e3fe5e161f7c");
550 Taxon cich
= (Taxon
)app
.getTaxonService().find(uuidCichorieae
);
552 if (!cich
.getTaxonNodes().isEmpty()){
553 TaxonNode cichNode
= cich
.getTaxonNodes().iterator().next();
554 uuidCichorieaeSubtree
= cichNode
.getUuid();
558 String
[] cichorieaeRoles
= new String
[]{};
559 if (uuidCichorieaeSubtree
!= null){
560 cichorieaeRoles
= new String
[]{"TAXONNODE.[CREATE,READ,UPDATE,DELETE]{"+uuidCichorieaeSubtree
.toString()+"}"};
562 String message
= "Cichorieae node could not be found for cichorieae-editor role";
563 logger
.warn(message
);
564 System
.out
.println(message
);
566 UUID uuidCichorieaeGroup
= UUID
.fromString("a630938d-dd4f-48c2-9406-91def487b11e");
567 String cichorieaeGroupName
= "Cichorieae";
568 Group cichorieaeGroup
= checkGroup(app
.getGroupService(), uuidCichorieaeGroup
, cichorieaeGroupName
, cichorieaeRoles
);
569 cichorieaeGroup
.addMember(userCichEditor
);
570 app
.getGroupService().saveOrUpdate(cichorieaeGroup
);
572 app
.commitTransaction(tx
);
574 } catch (Exception e
) {
576 logger
.error("Exception in createUsersAndRoles: " + e
.getMessage());
581 * copied from {@link FirstDataInserter#checkGroup}
583 private Group
checkGroup(IGroupService groupService
, UUID groupUuid
, String groupName
, String
[] requiredAuthorities
) {
584 Group group
= groupService
.load(groupUuid
);
586 group
= Group
.NewInstance();
587 group
.setUuid(groupUuid
);
588 logger
.info("New Group '" + groupName
+ "' created");
590 group
.setName(groupName
); // force name
592 Set
<GrantedAuthority
> grantedAuthorities
= group
.getGrantedAuthorities();
594 for(String a
: requiredAuthorities
){
595 boolean isMissing
= true;
596 for(GrantedAuthority ga
: grantedAuthorities
){
597 if(a
.equals(ga
.getAuthority())){
603 GrantedAuthorityImpl newGa
= GrantedAuthorityImpl
.NewInstance(a
);
604 group
.addGrantedAuthority(newGa
);
605 logger
.info("New GrantedAuthority '" + a
+ "' added to '" + groupName
+ "'");
608 groupService
.saveOrUpdate(group
);
609 logger
.info("Check of group '" + groupName
+ "' done");
617 public static void main(String
[] args
) {
618 EuroMedActivator importActivator
= new EuroMedActivator();
619 Source source
= berlinModelSource
;
620 ICdmDataSource cdmRepository
= CdmDestinations
.chooseDestination(args
) != null ? CdmDestinations
.chooseDestination(args
) : cdmDestination
;
622 importActivator
.importEm2CDM(source
, cdmRepository
, hbm2dll
);
623 if (includePesiExport
){
624 //not available from here since E+M was moved to app-import
625 // PesiExportActivatorEM exportActivator = new PesiExportActivatorEM();
626 // exportActivator.doExport(cdmRepository);