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
.salvador
;
12 import java
.lang
.reflect
.Method
;
13 import java
.util
.List
;
14 import java
.util
.UUID
;
16 import org
.apache
.log4j
.Logger
;
17 import org
.springframework
.transaction
.TransactionStatus
;
19 import eu
.etaxonomy
.cdm
.api
.application
.ICdmRepository
;
20 import eu
.etaxonomy
.cdm
.app
.berlinModelImport
.BerlinModelSources
;
21 import eu
.etaxonomy
.cdm
.app
.common
.CdmDestinations
;
22 import eu
.etaxonomy
.cdm
.database
.DbSchemaValidation
;
23 import eu
.etaxonomy
.cdm
.database
.ICdmDataSource
;
24 import eu
.etaxonomy
.cdm
.io
.berlinModel
.in
.BerlinModelImportConfigurator
;
25 import eu
.etaxonomy
.cdm
.io
.common
.CdmDefaultImport
;
26 import eu
.etaxonomy
.cdm
.io
.common
.IImportConfigurator
;
27 import eu
.etaxonomy
.cdm
.io
.common
.IImportConfigurator
.CHECK
;
28 import eu
.etaxonomy
.cdm
.io
.common
.IImportConfigurator
.DO_REFERENCES
;
29 import eu
.etaxonomy
.cdm
.io
.common
.ImportResult
;
30 import eu
.etaxonomy
.cdm
.io
.common
.Source
;
31 import eu
.etaxonomy
.cdm
.model
.common
.GrantedAuthorityImpl
;
32 import eu
.etaxonomy
.cdm
.model
.common
.Group
;
33 import eu
.etaxonomy
.cdm
.model
.common
.User
;
34 import eu
.etaxonomy
.cdm
.model
.name
.INonViralName
;
35 import eu
.etaxonomy
.cdm
.model
.name
.NomenclaturalCode
;
36 import eu
.etaxonomy
.cdm
.persistence
.hibernate
.permission
.Role
;
40 * TODO add the following to a wiki page:
41 * 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
42 * you must set the mysql system variable lower_case_table_names = 0 in order to create data base with table compatible names.
48 public class SalvadorActivator
{
49 private static final Logger logger
= Logger
.getLogger(SalvadorActivator
.class);
51 //database validation status (create, update, validate ...)
52 static DbSchemaValidation hbm2dll
= DbSchemaValidation
.CREATE
;
53 static final Source berlinModelSource
= BerlinModelSources
.El_Salvador();
54 // static final ICdmDataSource cdmDestination = CdmDestinations.localH2();
55 // static final ICdmDataSource cdmDestination = CdmDestinations.cdm_salvador_preview();
56 static final ICdmDataSource cdmDestination
= CdmDestinations
.cdm_salvador_production();
57 static final UUID treeUuid
= UUID
.fromString("b010c84d-6049-45f4-9f13-c065101eaa26");
58 static final UUID secUuid
= UUID
.fromString("d03ef02a-f226-4cb1-bdb4-f6c154f08a34");
59 static final int sourceSecId
= 7331;
61 static final UUID featureTreeUuid
= UUID
.fromString("9d0e5628-2eda-43ed-bc59-138a7e39ce56");
62 static final Object
[] featureKeyList
= new Integer
[]{302, 303, 306, 307, 309, 310, 311, 312, 1500, 1800, 1900, 1950, 1980, 2000};
63 static boolean isIgnore0AuthorTeam
= true; //special case for Salvador.
64 static boolean doExport
= false;
65 static boolean useClassification
= true;
68 static final CHECK check
= CHECK
.IMPORT_WITHOUT_CHECK
;
69 static final IImportConfigurator
.EDITOR editor
= IImportConfigurator
.EDITOR
.EDITOR_AS_EDITOR
;
72 static final NomenclaturalCode nomenclaturalCode
= NomenclaturalCode
.ICNAFP
;
75 static final boolean ignoreNull
= true;
77 static final boolean isSalvador
= true;
79 // ****************** ALL *****************************************
82 static final boolean doAuthors
= true;
84 static final DO_REFERENCES doReferences
= DO_REFERENCES
.ALL
;
86 static final boolean doTaxonNames
= true;
87 static final boolean doRelNames
= true;
88 static final boolean doNameStatus
= true;
89 static final boolean doTypes
= false; //Types do not exist in El_Salvador DB
90 static final boolean doNameFacts
= false; //Name Facts do not exist in El_Salvador DB
93 static final boolean doTaxa
= true;
94 static final boolean doRelTaxa
= true;
95 static final boolean doFacts
= true;
96 static final boolean doOccurences
= false; //Occurrences do not exist in El_Salvador DB
97 static final boolean doCommonNames
= false; //CommonNames do not exist in Salvador DB
100 static final boolean doMarker
= false; //#3937 markers must not be imported
101 static final boolean doUser
= true;
104 static String factFilter
= " factCategoryFk NOT IN ("
105 // + "302, 303, 306, 307, 309, 311, 310, "
106 + "1980, 1500, 1950, 1700, 350) ";
109 // ************************ NONE **************************************** //
112 // static final boolean doAuthors = false;
114 // static final DO_REFERENCES doReferences = DO_REFERENCES.CONCEPT_REFERENCES;
116 // static final boolean doTaxonNames = false;
117 // static final boolean doRelNames = false;
118 // static final boolean doNameStatus = false;
119 // static final boolean doTypes = false;
120 // static final boolean doNameFacts = false;
123 // static final boolean doTaxa = false;
124 // static final boolean doRelTaxa = false;
125 // static final boolean doFacts = false;
126 // static final boolean doOccurences = false;
127 // static final boolean doCommonNames = false;
130 // static final boolean doMarker = false;
131 // static final boolean doUser = true;
134 public ImportResult
doImport(ICdmDataSource destination
){
135 System
.out
.println("Start import from BerlinModel("+ berlinModelSource
.getDatabase() + ") ...");
137 //make BerlinModel Source
138 Source source
= berlinModelSource
;
140 BerlinModelImportConfigurator config
= BerlinModelImportConfigurator
.NewInstance(source
, destination
);
142 config
.setClassificationUuid(treeUuid
);
143 config
.setSecUuid(secUuid
);
144 config
.setSourceSecId(sourceSecId
);
145 config
.setNomenclaturalCode(nomenclaturalCode
);
146 config
.setIgnoreNull(ignoreNull
);
148 config
.setDoAuthors(doAuthors
);
149 config
.setDoReferences(doReferences
);
150 config
.setDoTaxonNames(doTaxonNames
);
151 config
.setDoRelNames(doRelNames
);
152 config
.setDoNameStatus(doNameStatus
);
153 config
.setDoTypes(doTypes
);
154 config
.setDoNameFacts(doNameFacts
);
156 config
.setDoTaxa(doTaxa
);
157 config
.setDoRelTaxa(doRelTaxa
);
158 config
.setDoFacts(doFacts
);
159 config
.setDoOccurrence(doOccurences
);
160 config
.setDoCommonNames(doCommonNames
);
162 config
.setDoMarker(doMarker
);
163 config
.setDoUser(doUser
);
165 config
.setTaxonNoteAsFeature(true);
167 config
.setDbSchemaValidation(hbm2dll
);
169 config
.setCheck(check
);
170 config
.setEditor(editor
);
171 config
.setIgnore0AuthorTeam(isIgnore0AuthorTeam
);
172 config
.setUseClassification(useClassification
);
174 config
.setNamerelationshipTypeMethod(getHandleNameRelationshipTypeMethod());
175 config
.setUserTransformationMethod(getTransformUsernameMethod());
176 config
.setSalvador(isSalvador
);
177 config
.setFactFilter(factFilter
);
179 config
.setFeatureTreeUuid(featureTreeUuid
);
180 config
.setFeatureTreeTitle("Salvador Portal Feature Tree");
183 CdmDefaultImport
<BerlinModelImportConfigurator
> bmImport
= new CdmDefaultImport
<>();
184 ImportResult result
= bmImport
.invoke(config
);
186 addUsers(config
, bmImport
);
188 System
.out
.println("End import from BerlinModel ("+ source
.getDatabase() + ")...");
196 private void addUsers(BerlinModelImportConfigurator config
, CdmDefaultImport
<BerlinModelImportConfigurator
> bmImport
) {
197 if (config
.isDoUser()){
198 ICdmRepository app
= bmImport
.getCdmAppController();
199 TransactionStatus tx
= app
.startTransaction(false);
202 Group adminGroup
= Group
.NewInstance("Admins");
203 GrantedAuthorityImpl roleAdmin
= app
.getGrantedAuthorityService().findAuthorityString(Role
.ROLE_ADMIN
.getAuthority());
204 adminGroup
.addGrantedAuthority(roleAdmin
);
206 // UserDetails wgbDetails = app.getUserService().loadUserByUsername("w.berendsohn");
207 List
<User
> users
= app
.getUserService().listByUsername("w.berendsohn", null, null, null, null, null, null);
208 for (User user
: users
){
209 adminGroup
.addMember(user
);
211 users
= app
.getUserService().listByUsername("admin", null, null, null, null, null, null);
212 for (User user
: users
){
213 adminGroup
.addMember(user
);
215 app
.getGroupService().saveOrUpdate(adminGroup
);
218 List
<Group
> editorGroups
= app
.getGroupService().listByName("Editor", null, null, null, null, null, null);
219 for (Group editorGroup
: editorGroups
){
220 users
= app
.getUserService().listByUsername("k.gruber", null, null, null, null, null, null);
221 for (User user
: users
){
222 editorGroup
.addMember(user
);
225 app
.commitTransaction(tx
);
235 public static void main(String
[] args
) {
236 SalvadorActivator activator
= new SalvadorActivator();
237 ICdmDataSource destination
= CdmDestinations
.chooseDestination(args
) != null ? CdmDestinations
.chooseDestination(args
) : cdmDestination
;
239 activator
.doImport(destination
);
240 if (doExport
== true){
241 SalvadorExport export
= new SalvadorExport();
242 export
.doExport(destination
);
248 private Method
getHandleNameRelationshipTypeMethod(){
249 String methodName
= "handleNameRelationshipType";
251 Method method
= this.getClass().getDeclaredMethod(methodName
, Integer
.class, INonViralName
.class, INonViralName
.class);
252 method
.setAccessible(true);
254 } catch (Exception e
) {
255 logger
.error("Problem creating Method: " + methodName
);
261 //used by BerlinModelImportConfigurator
262 @SuppressWarnings("unused")
263 private static boolean handleNameRelationshipType(Integer relQualifierFk
, INonViralName nameTo
, INonViralName nameFrom
){
264 if (relQualifierFk
== 72){
265 nameTo
.getHomotypicalGroup().merge(nameFrom
.getHomotypicalGroup());
271 private Method
getTransformUsernameMethod(){
272 String methodName
= "transformUsername";
274 Method method
= this.getClass().getDeclaredMethod(methodName
, String
.class);
275 method
.setAccessible(true);
277 } catch (Exception e
) {
278 logger
.error("Problem creating Method: " + methodName
);
283 //used by BerlinModelImportConfigurator
284 @SuppressWarnings("unused")
285 private static String
transformUsername(String nameToBeTransformed
){
286 if (nameToBeTransformed
== null){
288 }else if ("W.G.Berendsohn".equals(nameToBeTransformed
)){
290 }else if(nameToBeTransformed
.startsWith("fs") || nameToBeTransformed
.equals("BGBM\\fs")){
291 return "Frank Specht";
293 return nameToBeTransformed
;