1
|
/**
|
2
|
* Copyright (C) 2009 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.test.function;
|
11
|
|
12
|
import org.apache.log4j.Logger;
|
13
|
|
14
|
import eu.etaxonomy.cdm.api.application.CdmApplicationController;
|
15
|
import eu.etaxonomy.cdm.common.AccountStore;
|
16
|
import eu.etaxonomy.cdm.common.monitor.DefaultProgressMonitor;
|
17
|
import eu.etaxonomy.cdm.database.CdmDataSource;
|
18
|
import eu.etaxonomy.cdm.database.DatabaseTypeEnum;
|
19
|
import eu.etaxonomy.cdm.database.DbSchemaValidation;
|
20
|
import eu.etaxonomy.cdm.database.ICdmDataSource;
|
21
|
import eu.etaxonomy.cdm.database.update.CdmUpdater;
|
22
|
import eu.etaxonomy.cdm.model.name.NomenclaturalCode;
|
23
|
|
24
|
/**
|
25
|
* This class is meant for functional testing of model changes. It is not meant
|
26
|
* for running in maven.
|
27
|
* @author a.mueller
|
28
|
* @date 22.05.2015
|
29
|
*
|
30
|
*/
|
31
|
public class TestModelUpdate {
|
32
|
@SuppressWarnings("unused")
|
33
|
private static final Logger logger = Logger.getLogger(TestModelUpdate.class);
|
34
|
|
35
|
|
36
|
private void testSelectedDb(){
|
37
|
DbSchemaValidation schema = DbSchemaValidation.VALIDATE;
|
38
|
|
39
|
DatabaseTypeEnum dbType = DatabaseTypeEnum.MySQL;
|
40
|
|
41
|
|
42
|
String database = (schema == DbSchemaValidation.VALIDATE ? "cdm36" : "cdm40");
|
43
|
// database = "cdm36";
|
44
|
CdmDataSource dataSource = getDatasource(dbType, database);
|
45
|
|
46
|
|
47
|
try {
|
48
|
CdmUpdater updater = new CdmUpdater();
|
49
|
if (schema == DbSchemaValidation.VALIDATE){
|
50
|
updater.updateToCurrentVersion(dataSource, DefaultProgressMonitor.NewInstance());
|
51
|
}
|
52
|
} catch (Exception e) {
|
53
|
e.printStackTrace();
|
54
|
}
|
55
|
|
56
|
CdmApplicationController appCtr = CdmApplicationController.NewInstance(dataSource,schema);
|
57
|
|
58
|
// Classification classification = Classification.NewInstance("Me");
|
59
|
// Taxon taxon = Taxon.NewInstance(null, null);
|
60
|
// Person person = Person.NewInstance();
|
61
|
// TaxonNode node = classification.addChildTaxon(taxon, null, null);
|
62
|
// DefinedTerm lastScrutiny = (DefinedTerm)appCtr.getTermService().find(DefinedTerm.uuidLastScrutiny);
|
63
|
// TaxonNodeAgentRelation rel = node.addAgentRelation(lastScrutiny, person);
|
64
|
// appCtr.getClassificationService().save(classification);
|
65
|
|
66
|
// appCtr.getCommonService().createFullSampleData();
|
67
|
|
68
|
|
69
|
|
70
|
appCtr.close();
|
71
|
System.exit(0);
|
72
|
}
|
73
|
|
74
|
|
75
|
|
76
|
/**
|
77
|
* @param dbType
|
78
|
* @param database
|
79
|
* @return
|
80
|
*/
|
81
|
private CdmDataSource getDatasource(DatabaseTypeEnum dbType, String database) {
|
82
|
String server = "localhost";
|
83
|
String username = "edit";
|
84
|
String serverSql = "130.133.70.26";
|
85
|
|
86
|
if (dbType == DatabaseTypeEnum.MySQL){
|
87
|
return CdmDataSource.NewMySqlInstance(server, database, username, AccountStore.readOrStorePassword(server, database, username, null));
|
88
|
}else if (dbType == DatabaseTypeEnum.H2){
|
89
|
//H2
|
90
|
String path = "C:\\Users\\a.mueller\\.cdmLibrary\\writableResources\\h2\\LocalH2_" + database;
|
91
|
username = "sa";
|
92
|
CdmDataSource dataSource = CdmDataSource.NewH2EmbeddedInstance("cdmTest", username, "", path, NomenclaturalCode.ICNAFP);
|
93
|
return dataSource;
|
94
|
}else if (dbType == DatabaseTypeEnum.SqlServer2005){
|
95
|
server = serverSql;
|
96
|
username = "cdmupdater";
|
97
|
CdmDataSource dataSource = CdmDataSource.NewSqlServer2005Instance(server, database, 1433, username, AccountStore.readOrStorePassword(server, database, username, null));
|
98
|
return dataSource;
|
99
|
}else if (dbType == DatabaseTypeEnum.PostgreSQL){
|
100
|
server = serverSql;
|
101
|
username = "postgres";
|
102
|
CdmDataSource dataSource = CdmDataSource.NewPostgreSQLInstance(server, database, 5432, username, AccountStore.readOrStorePassword(server, database, username, null), null);
|
103
|
return dataSource;
|
104
|
}else{
|
105
|
throw new IllegalArgumentException("dbType not supported:" + dbType);
|
106
|
}
|
107
|
}
|
108
|
|
109
|
|
110
|
|
111
|
/**
|
112
|
* Updates the H2 test database in remote web-app.
|
113
|
* Requires that the local path to the database is adapted
|
114
|
*/
|
115
|
@SuppressWarnings("unused") //enable only if needed
|
116
|
private void updateRemoteWebappTestH2(){
|
117
|
String path = "C:\\Users\\a.mueller\\eclipse\\svn\\cdmlib-trunk\\cdmlib\\cdmlib-remote-webapp\\src\\test\\resources\\h2";
|
118
|
ICdmDataSource dataSource = CdmDataSource.NewH2EmbeddedInstance("cdmTest", "sa", "", path, NomenclaturalCode.ICNAFP);
|
119
|
|
120
|
|
121
|
try {
|
122
|
CdmUpdater updater = new CdmUpdater();
|
123
|
updater.updateToCurrentVersion(dataSource, DefaultProgressMonitor.NewInstance());
|
124
|
} catch (Exception e) {
|
125
|
e.printStackTrace();
|
126
|
}
|
127
|
|
128
|
//CdmPersistentDataSource.save(dataSource.getName(), dataSource);
|
129
|
CdmApplicationController appCtr;
|
130
|
appCtr = CdmApplicationController.NewInstance(dataSource,DbSchemaValidation.VALIDATE);
|
131
|
appCtr.close();
|
132
|
}
|
133
|
|
134
|
|
135
|
private void test(){
|
136
|
System.out.println("Start Datasource");
|
137
|
testSelectedDb();
|
138
|
|
139
|
// updateRemoteWebappTestH2();
|
140
|
|
141
|
System.out.println("\nEnd Datasource");
|
142
|
}
|
143
|
|
144
|
/**
|
145
|
* @param args
|
146
|
*/
|
147
|
public static void main(String[] args) {
|
148
|
TestModelUpdate cc = new TestModelUpdate();
|
149
|
cc.test();
|
150
|
}
|
151
|
|
152
|
}
|