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
.ICdmApplicationConfiguration
;
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 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.
76 public class EuroMedActivator
{
77 private static final Logger logger
= Logger
.getLogger(EuroMedActivator
.class);
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();
84 static final ICdmDataSource cdmDestination
= CdmDestinations
.cdm_test_euroMed();
85 // static final ICdmDataSource cdmDestination = CdmDestinations.cdm_pesi_euromed();
87 // static final ICdmDataSource cdmDestination = CdmDestinations.cdm_test_local_euromed3();
88 // static final ICdmDataSource cdmDestination = CdmDestinations.cdm_test_local_mysql_test();
90 // static final ICdmDataSource cdmDestination = CdmDestinations.localH2();
92 static final boolean includePesiExport
= false;
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};
101 // set to zero for unlimited nameFacts
102 static final int maximumNumberOfNameFacts
= 0;
104 static final int partitionSize
= 2500;
107 static final CHECK check
= CHECK
.IMPORT_WITHOUT_CHECK
;
110 static final EDITOR editor
= EDITOR
.EDITOR_AS_EDITOR
;
113 static final NomenclaturalCode nomenclaturalCode
= NomenclaturalCode
.ICNAFP
;
116 static final boolean ignoreNull
= true;
118 static final boolean switchSpeciesGroup
= true;
120 static boolean useClassification
= true;
122 static boolean isSplitTdwgCodes
= false;
123 static boolean useEmAreaVocabulary
= true;
125 private final boolean removeHttpMapsAnchor
= true;
128 static final String infrGenericRankAbbrev
= "[unranked]";
129 static final String infrSpecificRankAbbrev
= "[unranked]";
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) ";
151 // **************** ALL *********************
153 boolean invers
= !(hbm2dll
== DbSchemaValidation
.CREATE
);
155 static final boolean doUser
= true;
157 static final boolean doAuthors
= true;
159 static final DO_REFERENCES doReferences
= DO_REFERENCES
.ALL
;
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;
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
);
176 static final boolean doMarker
= true;
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
183 BerlinModelImportConfigurator config
= BerlinModelImportConfigurator
.NewInstance(source
, destination
);
185 config
.setClassificationName(classificationName
);
187 config
.setClassificationUuid(classificationUuid
);
188 config
.setSourceSecId(sourceSecId
);
189 config
.setNomenclaturalCode(nomenclaturalCode
);
190 config
.setIgnoreNull(ignoreNull
);
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
);
205 config
.setDoMarker(doMarker ^ invers
);
206 config
.setDoUser(doUser ^ invers
);
208 config
.setUseClassification(useClassification
);
209 config
.setSourceRefUuid(BerlinModelTransformer
.uuidSourceRefEuroMed
);
210 config
.setEditor(editor
);
211 config
.setDbSchemaValidation(hbm2dll
);
213 // maximum number of name facts to import
214 config
.setMaximumNumberOfNameFacts(maximumNumberOfNameFacts
);
216 config
.setInfrGenericRankAbbrev(infrGenericRankAbbrev
);
217 config
.setInfrSpecificRankAbbrev(infrSpecificRankAbbrev
);
218 config
.setRemoveHttpMapsAnchor(removeHttpMapsAnchor
);
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
);
237 config
.setSplitTdwgCodes(isSplitTdwgCodes
);
238 config
.setUseEmAreaVocabulary(useEmAreaVocabulary
);
240 config
.setCheck(check
);
241 config
.setEditor(editor
);
242 config
.setRecordsPerTransaction(partitionSize
);
244 config
.setSwitchSpeciesGroup(switchSpeciesGroup
);
247 CdmDefaultImport
<BerlinModelImportConfigurator
> bmImport
= new CdmDefaultImport
<BerlinModelImportConfigurator
>();
248 bmImport
.invoke(config
);
250 renameRanks(config
, bmImport
);
252 createFeatureTree(config
, bmImport
);
254 changeCommonNameLabel(config
, bmImport
);
256 createUsersAndRoles(config
, bmImport
);
258 runTransmissionEngine(config
, bmImport
);
260 importShapefile(config
, bmImport
);
262 // markAreasAsHidden(config, bmImport); //has been moved to BM occurrence import
264 System
.out
.println("End import from BerlinModel ("+ source
.getDatabase() + ")...");
267 //Rename Ranks (still needed?)
268 private void renameRanks(BerlinModelImportConfigurator config
,
269 CdmDefaultImport
<BerlinModelImportConfigurator
> bmImport
) {
271 if (config
.isDoTaxonNames() && (config
.getCheck().isImport() ) ){
272 ICdmApplicationConfiguration app
= bmImport
.getCdmAppController();
273 TransactionStatus tx
= app
.startTransaction();
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
);
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
) {
291 logger
.error("Exception in renameRanks: " + e
.getMessage());
296 //create feature tree
297 private void createFeatureTree(BerlinModelImportConfigurator config
,
298 CdmDefaultImport
<BerlinModelImportConfigurator
> bmImport
)
300 if (config
.isDoFacts() && (config
.getCheck().isImport() ) ){
302 ICdmApplicationConfiguration app
= bmImport
.getCdmAppController();
303 TransactionStatus tx
= app
.startTransaction();
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
);
315 app
.commitTransaction(tx
);
316 } catch (Exception e
) {
318 logger
.error("Exception in createFeatureTree: " + e
.getMessage());
323 //Change common name label
324 private void changeCommonNameLabel(BerlinModelImportConfigurator config
,
325 CdmDefaultImport
<BerlinModelImportConfigurator
> bmImport
) {
326 if (config
.isDoFacts() && (config
.getCheck().isImport() ) ){
328 ICdmApplicationConfiguration app
= bmImport
.getCdmAppController();
329 TransactionStatus tx
= app
.startTransaction();
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
);
336 app
.commitTransaction(tx
);
337 } catch (Exception e
) {
339 logger
.error("Exception in changeCommonNameLabel: " + e
.getMessage());
344 //1. run transmission engine #3979
345 private void runTransmissionEngine(BerlinModelImportConfigurator config
,
346 CdmDefaultImport
<BerlinModelImportConfigurator
> bmImport
) {
348 if (doRunTransmissionEngine
&& (config
.getCheck().isImport() ) ){
350 ICdmApplicationConfiguration app
= bmImport
.getCdmAppController();
352 final List
<String
> term_init_strategy
= Arrays
.asList(new String
[]{
356 UUID uuidSuperAreaLevel
= BerlinModelTransformer
.uuidEuroMedAreaLevelFirst
;
357 NamedAreaLevel euroMedLevel1
= (NamedAreaLevel
)app
.getTermService().find(uuidSuperAreaLevel
);
359 Pager
<NamedArea
> areaPager
= app
.getTermService().list(
361 (NamedAreaType
) null,
364 (List
<OrderHint
>) null,
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?)
373 DefaultProgressMonitor
.NewInstance());
374 } catch (Exception e
) {
376 logger
.error("Exception in markAreasAsHidden: " + e
.getMessage());
381 // //5.Mark areas to be hidden #3979 .5
382 // private void markAreasAsHidden(BerlinModelImportConfigurator config,
383 // CdmDefaultImport<BerlinModelImportConfigurator> bmImport) {
385 // if (config.isDoOccurrence() && (config.getCheck().isImport())){
387 // ICdmApplicationConfiguration app = bmImport.getCdmAppController();
388 // TransactionStatus tx = app.startTransaction();
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);
399 // vocUserDefinedMarkerTypes.addTerm(hiddenAreaMarkerType);
400 // app.getVocabularyService().saveOrUpdate(vocUserDefinedMarkerTypes);
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);
411 // app.commitTransaction(tx);
412 // } catch (Exception e) {
413 // e.printStackTrace();
414 // logger.error("Exception in markAreasAsHidden: " + e.getMessage());
419 // private void hideArea(ICdmApplicationConfiguration 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);
425 //2. import shapefile attributes #3979 .2
426 private void importShapefile(BerlinModelImportConfigurator config
,
427 CdmDefaultImport
<BerlinModelImportConfigurator
> bmImport
) {
429 if (config
.isDoOccurrence() && (config
.getCheck().isImport())){
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;
437 ICdmApplicationConfiguration app
= bmImport
.getCdmAppController();
438 IEditGeoService geoService
= (IEditGeoService
)app
.getBean("editGeoService");
440 Map
<NamedArea
, String
> resultMap
;
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");
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
));
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
);
458 } catch (Exception e
) {
460 logger
.error("Exception in importShapefile: " + e
.getMessage());
465 //4. Create users and assign roles #3979
466 private void createUsersAndRoles(BerlinModelImportConfigurator config
,
467 CdmDefaultImport
<BerlinModelImportConfigurator
> bmImport
) {
470 if (config
.isDoRelTaxa() && (config
.getCheck().isImport())){
471 ICdmApplicationConfiguration app
= bmImport
.getCdmAppController();
472 TransactionStatus tx
= app
.startTransaction();
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
);
481 userEraabStraube
= users
.get(0);
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
);
490 app
.getUserService().saveOrUpdate(userEraabStraube
);
493 Group groupEditor
= app
.getGroupService().load(Group
.groupEditorUuid
);
494 groupEditor
.addMember(userEraabStraube
);
495 app
.getGroupService().saveOrUpdate(groupEditor
);
497 Group groupProjectManager
= app
.getGroupService().load(Group
.groupProjectManagerUuid
);
498 groupProjectManager
.addMember(userEraabStraube
);
499 app
.getGroupService().saveOrUpdate(groupProjectManager
);
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
);
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
);
513 String cichorieaeEditor
= "cichorieae-editor";
514 app
.getUserService().listByUsername(cichorieaeEditor
, MatchMode
.EXACT
, null, null, null, null, null);
516 if (users
.isEmpty()){
517 userCichEditor
= User
.NewInstance(cichorieaeEditor
, cichorieaeEditor
);
519 userCichEditor
= users
.get(0);
521 app
.getUserService().saveOrUpdate(userCichEditor
);
524 groupEditor
.addMember(userCichEditor
);
525 app
.getGroupService().saveOrUpdate(groupEditor
);
527 UUID uuidCichorieaeSubtree
= null;
528 UUID uuidCichorieae
= UUID
.fromString("63c7dbeb-b9a2-48b8-a75f-e3fe5e161f7c");
529 Taxon cich
= (Taxon
)app
.getTaxonService().find(uuidCichorieae
);
531 if (!cich
.getTaxonNodes().isEmpty()){
532 TaxonNode cichNode
= cich
.getTaxonNodes().iterator().next();
533 uuidCichorieaeSubtree
= cichNode
.getUuid();
537 String
[] cichorieaeRoles
= new String
[]{};
538 if (uuidCichorieaeSubtree
!= null){
539 cichorieaeRoles
= new String
[]{"TAXONNODE.[CREATE,READ,UPDATE,DELETE]{"+uuidCichorieaeSubtree
.toString()+"}"};
541 String message
= "Cichorieae node could not be found for cichorieae-editor role";
542 logger
.warn(message
);
543 System
.out
.println(message
);
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
);
551 app
.commitTransaction(tx
);
553 } catch (Exception e
) {
555 logger
.error("Exception in createUsersAndRoles: " + e
.getMessage());
560 * copied from {@link FirstDataInserter#checkGroup}
562 private Group
checkGroup(IGroupService groupService
, UUID groupUuid
, String groupName
, String
[] requiredAuthorities
) {
563 Group group
= groupService
.load(groupUuid
);
565 group
= Group
.NewInstance();
566 group
.setUuid(groupUuid
);
567 logger
.info("New Group '" + groupName
+ "' created");
569 group
.setName(groupName
); // force name
571 Set
<GrantedAuthority
> grantedAuthorities
= group
.getGrantedAuthorities();
573 for(String a
: requiredAuthorities
){
574 boolean isMissing
= true;
575 for(GrantedAuthority ga
: grantedAuthorities
){
576 if(a
.equals(ga
.getAuthority())){
582 GrantedAuthorityImpl newGa
= GrantedAuthorityImpl
.NewInstance();
583 newGa
.setAuthority(a
);
584 group
.addGrantedAuthority(newGa
);
585 logger
.info("New GrantedAuthority '" + a
+ "' added to '" + groupName
+ "'");
588 groupService
.saveOrUpdate(group
);
589 logger
.info("Check of group '" + groupName
+ "' done");
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
;
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);