Revision 605013a7
Added by Andreas Müller over 2 years ago
cdmlib-persistence/src/test/java/eu/etaxonomy/cdm/test/function/Datasource.java | ||
---|---|---|
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.database.CdmDataSource; |
|
15 |
import eu.etaxonomy.cdm.database.CdmPersistentDataSource; |
|
16 |
|
|
17 |
public class Datasource { |
|
18 |
private static final Logger logger = Logger.getLogger(Datasource.class); |
|
19 |
|
|
20 |
private void test(){ |
|
21 |
System.out.println("Start Datasource"); |
|
22 |
|
|
23 |
int port = -1; |
|
24 |
String username = ""; |
|
25 |
String pwd = ""; |
|
26 |
String server = "87.106.XXX.XXX"; |
|
27 |
|
|
28 |
CdmPersistentDataSource defaultDataSource = CdmPersistentDataSource.save( |
|
29 |
"mysql_cichorieae", CdmDataSource.NewMySqlInstance(server , "cdm_edit_cichorieae",port, username, pwd)); |
|
30 |
|
|
31 |
// logger.warn(defaultDataSource.getDatabase()); |
|
32 |
// logger.warn(defaultDataSource.getPort()); |
|
33 |
// logger.warn(defaultDataSource.getServer()); |
|
34 |
|
|
35 |
defaultDataSource = CdmPersistentDataSource.save( |
|
36 |
"mysql_cichorieae", CdmDataSource.NewSqlServer2005Instance(server, "cdm_edit_cichorieae", port, username, pwd)); |
|
37 |
|
|
38 |
logger.warn(defaultDataSource.getDatabase()); |
|
39 |
logger.warn(defaultDataSource.getPort()); |
|
40 |
logger.warn(defaultDataSource.getServer()); |
|
41 |
|
|
42 |
defaultDataSource = CdmPersistentDataSource.save( |
|
43 |
"mysql_cichorieae", CdmDataSource.NewMySqlInstance("192.168.2.10", "cdm_edit_cichorieae", 3306, username, "XXX")); |
|
44 |
|
|
45 |
defaultDataSource = CdmPersistentDataSource.save( |
|
46 |
"mysql_cichorieae", CdmDataSource.NewMySqlInstance(server, "cdm_edit_cichorieae", port, username, pwd)); |
|
47 |
|
|
48 |
|
|
49 |
try { |
|
50 |
logger.warn("Connect: " + defaultDataSource.testConnection()); |
|
51 |
} catch (Exception e) { |
|
52 |
logger.warn("Could not connect", e); |
|
53 |
} |
|
54 |
|
|
55 |
|
|
56 |
|
|
57 |
System.out.println("\nEnd Datasource"); |
|
58 |
} |
|
59 |
|
|
60 |
/** |
|
61 |
* @param args |
|
62 |
*/ |
|
63 |
public static void main(String[] args) { |
|
64 |
Datasource cc = new Datasource(); |
|
65 |
cc.test(); |
|
66 |
} |
|
67 |
|
|
68 |
} |
cdmlib-persistence/src/test/java/eu/etaxonomy/cdm/test/function/TestCdmApplicationUtils.java | ||
---|---|---|
6 | 6 |
* The contents of this file are subject to the Mozilla Public License Version 1.1 |
7 | 7 |
* See LICENSE.TXT at the top of this package for the full license terms. |
8 | 8 |
*/ |
9 |
|
|
10 | 9 |
package eu.etaxonomy.cdm.test.function; |
11 | 10 |
|
12 | 11 |
import java.io.IOException; |
... | ... | |
18 | 17 |
/** |
19 | 18 |
* @author a.mueller |
20 | 19 |
* @since 20.11.2008 |
21 |
* @version 1.0 |
|
22 | 20 |
*/ |
23 | 21 |
public class TestCdmApplicationUtils { |
24 | 22 |
|
... | ... | |
29 | 27 |
return true; |
30 | 28 |
} |
31 | 29 |
|
32 |
/** |
|
33 |
* @param args |
|
34 |
*/ |
|
35 | 30 |
public static void main(String[] args) { |
36 | 31 |
TestCdmApplicationUtils me = new TestCdmApplicationUtils(); |
37 | 32 |
try { |
... | ... | |
41 | 36 |
throw new RuntimeException(e); |
42 | 37 |
} |
43 | 38 |
} |
44 |
} |
|
39 |
} |
cdmlib-persistence/src/test/java/eu/etaxonomy/cdm/test/function/TestScript.java | ||
---|---|---|
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 |
package eu.etaxonomy.cdm.test.function; |
|
10 |
|
|
11 |
import org.apache.log4j.Logger; |
|
12 |
|
|
13 |
import eu.etaxonomy.cdm.database.CdmDataSource; |
|
14 |
import eu.etaxonomy.cdm.database.CdmPersistentDataSource; |
|
15 |
|
|
16 |
public class TestScript { |
|
17 |
private static final Logger logger = Logger.getLogger(TestScript.class); |
|
18 |
|
|
19 |
private void test(){ |
|
20 |
System.out.println("Start Datasource"); |
|
21 |
|
|
22 |
int port = -1; |
|
23 |
String username = ""; |
|
24 |
String pwd = ""; |
|
25 |
String server = "87.106.XXX.XXX"; |
|
26 |
|
|
27 |
CdmPersistentDataSource defaultDataSource = CdmPersistentDataSource.save( |
|
28 |
"mysql_cichorieae", CdmDataSource.NewMySqlInstance(server , "cdm_edit_cichorieae",port, username, pwd)); |
|
29 |
|
|
30 |
// logger.warn(defaultDataSource.getDatabase()); |
|
31 |
// logger.warn(defaultDataSource.getPort()); |
|
32 |
// logger.warn(defaultDataSource.getServer()); |
|
33 |
|
|
34 |
defaultDataSource = CdmPersistentDataSource.save( |
|
35 |
"mysql_cichorieae", CdmDataSource.NewSqlServer2005Instance(server, "cdm_edit_cichorieae", port, username, pwd)); |
|
36 |
|
|
37 |
logger.warn(defaultDataSource.getDatabase()); |
|
38 |
logger.warn(defaultDataSource.getPort()); |
|
39 |
logger.warn(defaultDataSource.getServer()); |
|
40 |
|
|
41 |
defaultDataSource = CdmPersistentDataSource.save( |
|
42 |
"mysql_cichorieae", CdmDataSource.NewMySqlInstance("192.168.2.10", "cdm_edit_cichorieae", 3306, username, "XXX")); |
|
43 |
|
|
44 |
defaultDataSource = CdmPersistentDataSource.save( |
|
45 |
"mysql_cichorieae", CdmDataSource.NewMySqlInstance(server, "cdm_edit_cichorieae", port, username, pwd)); |
|
46 |
|
|
47 |
try { |
|
48 |
logger.warn("Connect: " + defaultDataSource.testConnection()); |
|
49 |
} catch (Exception e) { |
|
50 |
logger.warn("Could not connect", e); |
|
51 |
} |
|
52 |
|
|
53 |
System.out.println("\nEnd Datasource"); |
|
54 |
} |
|
55 |
|
|
56 |
public static void main(String[] args) { |
|
57 |
TestScript cc = new TestScript(); |
|
58 |
cc.test(); |
|
59 |
} |
|
60 |
} |
cdmlib-remote/src/test/java/eu/etaxonomy/cdm/test/function/TestScript.java | ||
---|---|---|
10 | 10 |
package eu.etaxonomy.cdm.test.function; |
11 | 11 |
|
12 | 12 |
import java.io.IOException; |
13 |
import java.util.HashSet; |
|
14 |
import java.util.Map; |
|
15 |
import java.util.Set; |
|
13 | 16 |
import java.util.UUID; |
14 | 17 |
|
15 | 18 |
import javax.servlet.http.HttpServletResponse; |
16 | 19 |
|
17 | 20 |
import org.apache.log4j.Logger; |
21 |
import org.springframework.web.servlet.ModelAndView; |
|
18 | 22 |
|
19 | 23 |
import eu.etaxonomy.cdm.api.application.CdmApplicationController; |
24 |
import eu.etaxonomy.cdm.api.service.dto.DistributionInfoDTO.InfoPart; |
|
20 | 25 |
import eu.etaxonomy.cdm.config.AccountStore; |
21 | 26 |
import eu.etaxonomy.cdm.database.CdmDataSource; |
22 | 27 |
import eu.etaxonomy.cdm.database.DbSchemaValidation; |
23 | 28 |
import eu.etaxonomy.cdm.database.ICdmDataSource; |
24 |
import eu.etaxonomy.cdm.model.agent.TeamOrPersonBase; |
|
25 |
import eu.etaxonomy.cdm.model.taxon.TaxonBase; |
|
26 |
import eu.etaxonomy.cdm.remote.controller.TaxonPortalController; |
|
27 |
import eu.etaxonomy.cdm.remote.editor.UuidList; |
|
29 |
import eu.etaxonomy.cdm.ext.geo.CondensedDistributionRecipe; |
|
30 |
import eu.etaxonomy.cdm.model.location.NamedAreaLevel; |
|
31 |
import eu.etaxonomy.cdm.remote.controller.DescriptionListController; |
|
28 | 32 |
import eu.etaxonomy.cdm.remote.io.application.CdmRemoteApplicationController; |
29 | 33 |
|
30 | 34 |
/** |
... | ... | |
33 | 37 |
*/ |
34 | 38 |
public class TestScript { |
35 | 39 |
|
36 |
private static final Logger logger = Logger.getLogger(TestScript.class); |
|
40 |
@SuppressWarnings("unused") |
|
41 |
private static final Logger logger = Logger.getLogger(TestScript.class); |
|
37 | 42 |
|
38 | 43 |
|
39 | 44 |
private void testNewConfigControler(){ |
... | ... | |
58 | 63 |
// dataSource = CdmDataSource.NewMySqlInstance(server, database, username, AccountStore.readOrStorePassword(server, database, username, null)); |
59 | 64 |
|
60 | 65 |
// server = "160.45.63.171"; |
61 |
// database = "cdm_production_campanulaceae";
|
|
66 |
// database = "cdm_production_flora_malesiana_prospective";
|
|
62 | 67 |
// username = "edit"; |
63 | 68 |
// dataSource = CdmDataSource.NewMySqlInstance(server, database, username, AccountStore.readOrStorePassword(server, database, username, null)); |
64 | 69 |
|
65 |
|
|
66 |
// server = "test.e-taxonomy.eu"; |
|
67 |
// database = "cdm_rem_conf_am"; |
|
68 |
// username = "edit"; |
|
69 |
// dataSource = CdmDataSource.NewMySqlInstance(server, database, username, AccountStore.readOrStorePassword(server, database, username, null)); |
|
70 |
server = "test.e-taxonomy.eu"; |
|
71 |
database = "cdm_rem_conf_am"; |
|
72 |
username = "edit"; |
|
73 |
dataSource = CdmDataSource.NewMySqlInstance(server, database, username, AccountStore.readOrStorePassword(server, database, username, null)); |
|
70 | 74 |
|
71 | 75 |
// String server = "localhost"; |
72 | 76 |
// String database = "testCDM"; |
... | ... | |
91 | 95 |
// dataSource = CdmDataSource.NewH2EmbeddedInstance(database, username, "sa"); |
92 | 96 |
|
93 | 97 |
|
94 |
server = "160.45.63.201"; |
|
95 |
database = "cdm_integration_cichorieae"; |
|
96 |
username = "edit"; |
|
97 |
dataSource = CdmDataSource.NewMySqlInstance(server, database, username, AccountStore.readOrStorePassword(server, database, username, null)); |
|
98 |
// server = "160.45.63.201";
|
|
99 |
// database = "cdm_integration_cichorieae";
|
|
100 |
// username = "edit";
|
|
101 |
// dataSource = CdmDataSource.NewMySqlInstance(server, database, username, AccountStore.readOrStorePassword(server, database, username, null));
|
|
98 | 102 |
|
99 | 103 |
CdmApplicationController appCtr = CdmRemoteApplicationController.NewRemoteInstance(dataSource, schema); |
100 | 104 |
|
... | ... | |
117 | 121 |
|
118 | 122 |
private void doTemporary(CdmApplicationController appCtr) throws IOException { |
119 | 123 |
|
120 |
UUID taxonUUID = UUID.fromString("85176c77-e4b6-4899-a08b-e257ab09350a"); |
|
121 |
boolean includeTaxonomicChildren = true; |
|
122 |
UuidList relationshipUuids = new UuidList(); |
|
123 |
UuidList relationshipInversUuids = new UuidList(); |
|
124 |
boolean includeTaxonDescriptions = true; |
|
125 |
boolean includeOccurrences = true; |
|
126 |
boolean includeTaxonNameDescriptions = true; |
|
124 |
} |
|
125 |
|
|
126 |
private void doGetDistributionInfo(CdmApplicationController appCtr) throws IOException { |
|
127 |
|
|
128 |
UUID descUUID = UUID.fromString("2debf5ee-cb57-40bc-af89-173d1d17cefe"); |
|
129 |
Set<InfoPart> parts = new HashSet<>(); |
|
130 |
parts.add(InfoPart.tree); |
|
131 |
parts.add(InfoPart.mapUriParams); |
|
132 |
Set<NamedAreaLevel> omitLevels = new HashSet<>(); |
|
133 |
NamedAreaLevel areaLevel = (NamedAreaLevel)appCtr.getTermService().find(UUID.fromString("38efa5fd-d7f0-451c-9de9-e6cce41e2225")); |
|
134 |
omitLevels.add(areaLevel); |
|
127 | 135 |
HttpServletResponse response = null; |
128 |
TaxonPortalController taxonPortalController = (TaxonPortalController) appCtr.getBean("taxonPortalController"); |
|
136 |
DescriptionListController descriptionListController = (DescriptionListController) appCtr.getBean("descriptionListController"); |
|
137 |
CondensedDistributionRecipe recipe = CondensedDistributionRecipe.EuroPlusMed; |
|
129 | 138 |
|
130 |
TaxonBase<?> taxon = taxonPortalController.doGet(taxonUUID, null, response); |
|
131 |
TeamOrPersonBase<?> secAuthor = taxon.getSec().getAuthorship(); |
|
139 |
ModelAndView mav = descriptionListController.doGetDistributionInfo(descUUID, parts, false, false, null, |
|
140 |
omitLevels, null, null, recipe, null, response ); |
|
141 |
Map<String, Object> model = mav.getModel(); |
|
142 |
System.out.println(model); |
|
132 | 143 |
|
133 | 144 |
} |
134 | 145 |
|
cdmlib-services/src/test/java/eu/etaxonomy/cdm/test/function/Datasource.java | ||
---|---|---|
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 java.io.IOException; |
|
13 |
import java.sql.ResultSet; |
|
14 |
import java.sql.SQLException; |
|
15 |
import java.util.ArrayList; |
|
16 |
import java.util.Arrays; |
|
17 |
import java.util.List; |
|
18 |
import java.util.UUID; |
|
19 |
|
|
20 |
import org.apache.log4j.Logger; |
|
21 |
import org.hibernate.Query; |
|
22 |
import org.hibernate.Session; |
|
23 |
import org.springframework.transaction.TransactionStatus; |
|
24 |
|
|
25 |
import eu.etaxonomy.cdm.api.application.CdmApplicationController; |
|
26 |
import eu.etaxonomy.cdm.api.application.CdmApplicationUtils; |
|
27 |
import eu.etaxonomy.cdm.api.service.ITaxonNodeService; |
|
28 |
import eu.etaxonomy.cdm.api.service.ITaxonService; |
|
29 |
import eu.etaxonomy.cdm.api.service.UpdateResult; |
|
30 |
import eu.etaxonomy.cdm.api.service.config.TaxonDeletionConfigurator; |
|
31 |
import eu.etaxonomy.cdm.api.service.description.AggregationMode; |
|
32 |
import eu.etaxonomy.cdm.api.service.description.DistributionAggregationConfiguration; |
|
33 |
import eu.etaxonomy.cdm.api.service.description.StructuredDescriptionAggregationConfiguration; |
|
34 |
import eu.etaxonomy.cdm.api.service.dto.GroupedTaxonDTO; |
|
35 |
import eu.etaxonomy.cdm.common.monitor.DefaultProgressMonitor; |
|
36 |
import eu.etaxonomy.cdm.config.AccountStore; |
|
37 |
import eu.etaxonomy.cdm.database.CdmDataSource; |
|
38 |
import eu.etaxonomy.cdm.database.CdmPersistentDataSource; |
|
39 |
import eu.etaxonomy.cdm.database.DataSourceNotFoundException; |
|
40 |
import eu.etaxonomy.cdm.database.DatabaseTypeEnum; |
|
41 |
import eu.etaxonomy.cdm.database.DbSchemaValidation; |
|
42 |
import eu.etaxonomy.cdm.database.ICdmDataSource; |
|
43 |
import eu.etaxonomy.cdm.filter.TaxonNodeFilter; |
|
44 |
import eu.etaxonomy.cdm.model.agent.Person; |
|
45 |
import eu.etaxonomy.cdm.model.description.DescriptiveDataSet; |
|
46 |
import eu.etaxonomy.cdm.model.description.Distribution; |
|
47 |
import eu.etaxonomy.cdm.model.description.PresenceAbsenceTerm; |
|
48 |
import eu.etaxonomy.cdm.model.description.TaxonDescription; |
|
49 |
import eu.etaxonomy.cdm.model.location.NamedArea; |
|
50 |
import eu.etaxonomy.cdm.model.name.HybridRelationshipType; |
|
51 |
import eu.etaxonomy.cdm.model.name.IBotanicalName; |
|
52 |
import eu.etaxonomy.cdm.model.name.NameRelationshipType; |
|
53 |
import eu.etaxonomy.cdm.model.name.Rank; |
|
54 |
import eu.etaxonomy.cdm.model.name.TaxonName; |
|
55 |
import eu.etaxonomy.cdm.model.name.TaxonNameFactory; |
|
56 |
import eu.etaxonomy.cdm.model.reference.Reference; |
|
57 |
import eu.etaxonomy.cdm.model.reference.ReferenceFactory; |
|
58 |
import eu.etaxonomy.cdm.model.taxon.Classification; |
|
59 |
import eu.etaxonomy.cdm.model.taxon.Taxon; |
|
60 |
import eu.etaxonomy.cdm.model.taxon.TaxonNode; |
|
61 |
import eu.etaxonomy.cdm.model.term.DefinedTermBase; |
|
62 |
import eu.etaxonomy.cdm.model.term.TermTree; |
|
63 |
import eu.etaxonomy.cdm.model.term.init.TermNotFoundException; |
|
64 |
|
|
65 |
public class Datasource { |
|
66 |
private static final Logger logger = Logger.getLogger(Datasource.class); |
|
67 |
|
|
68 |
|
|
69 |
private void testNewConfigControler(){ |
|
70 |
|
|
71 |
DbSchemaValidation schema = DbSchemaValidation.VALIDATE; |
|
72 |
|
|
73 |
String server; |
|
74 |
String database; |
|
75 |
String username; |
|
76 |
ICdmDataSource dataSource; |
|
77 |
|
|
78 |
// List<CdmPersistentDataSource> lsDataSources = CdmPersistentDataSource.getAllDataSources(); |
|
79 |
// System.out.println(lsDataSources); |
|
80 |
// dataSource = lsDataSources.get(1); |
|
81 |
|
|
82 |
// DatabaseTypeEnum dbType = DatabaseTypeEnum.MySQL; |
|
83 |
|
|
84 |
// server = "localhost"; |
|
85 |
// database = "cdm_test"; |
|
86 |
//// database = "cdm_production_edaphobase"; |
|
87 |
// username = "edit"; |
|
88 |
// dataSource = CdmDataSource.NewMySqlInstance(server, database, username, AccountStore.readOrStorePassword(server, database, username, null)); |
|
89 |
|
|
90 |
// server = "160.45.63.171"; |
|
91 |
// database = "xxx"; |
|
92 |
// username = "edit"; |
|
93 |
// dataSource = CdmDataSource.NewMySqlInstance(server, database, username, AccountStore.readOrStorePassword(server, database, username, null)); |
|
94 |
|
|
95 |
|
|
96 |
server = "test.e-taxonomy.eu"; |
|
97 |
database = "cdm_rem_conf_am"; |
|
98 |
username = "edit"; |
|
99 |
dataSource = CdmDataSource.NewMySqlInstance(server, database, username, AccountStore.readOrStorePassword(server, database, username, null)); |
|
100 |
|
|
101 |
// String server = "localhost"; |
|
102 |
// String database = "testCDM"; |
|
103 |
// String username = "postgres"; |
|
104 |
// dataSource = CdmDataSource.NewInstance(DatabaseTypeEnum.PostgreSQL, server, database, DatabaseTypeEnum.PostgreSQL.getDefaultPort(), username, AccountStore.readOrStorePassword(server, database, username, null)); |
|
105 |
|
|
106 |
|
|
107 |
// //SQLServer |
|
108 |
// server = "BGBM-PESISQL"; |
|
109 |
// database = "cdm36"; |
|
110 |
// int port = 1433; |
|
111 |
// username = "cdmupdater"; |
|
112 |
// dataSource = CdmDataSource.NewSqlServer2012Instance(server, database, port, username, AccountStore.readOrStorePassword(server, database, username, null)); |
|
113 |
// |
|
114 |
// //H2 |
|
115 |
// String path = "C:\\Users\\a.mueller\\.cdmLibrary\\writableResources\\h2\\LocalH2"; |
|
116 |
//// String path = "C:\\Users\\pesiimport\\.cdmLibrary\\writableResources\\h2\\LocalH2"; |
|
117 |
//// String path = "C:\\Users\\a.mueller\\eclipse\\svn\\cdmlib-trunk\\cdmlib-remote-webapp\\src\\test\\resources\\h2"; |
|
118 |
// username = "sa"; |
|
119 |
// dataSource = CdmDataSource.NewH2EmbeddedInstance("cdm", username, "", path); |
|
120 |
|
|
121 |
// dataSource = CdmDataSource.NewH2EmbeddedInstance(database, username, "sa"); |
|
122 |
|
|
123 |
|
|
124 |
// server = "160.45.63.201"; |
|
125 |
// database = "cdm_integration_cichorieae"; |
|
126 |
// username = "edit"; |
|
127 |
// dataSource = CdmDataSource.NewMySqlInstance(server, database, username, AccountStore.readOrStorePassword(server, database, username, null)); |
|
128 |
|
|
129 |
//CdmPersistentDataSource.save(dataSource.getName(), dataSource); |
|
130 |
CdmApplicationController appCtr; |
|
131 |
appCtr = CdmApplicationController.NewInstance(dataSource, schema); |
|
132 |
|
|
133 |
// appCtr.getOccurrenceService().findRootUnitDTOs(UUID.fromString("2debf5ee-cb57-40bc-af89-173d1d17cefe")); |
|
134 |
// aggregateDDS(appCtr); |
|
135 |
aggregateDistribution(appCtr); |
|
136 |
|
|
137 |
appCtr.close(); |
|
138 |
System.exit(0); |
|
139 |
} |
|
140 |
|
|
141 |
private void aggregateDistribution(CdmApplicationController app){ |
|
142 |
|
|
143 |
System.out.println("agg distr"); |
|
144 |
DefaultProgressMonitor monitor = DefaultProgressMonitor.NewInstance(); |
|
145 |
|
|
146 |
UUID descriptaceaeUuid = UUID.fromString("5a37c47c-347c-49f8-88ba-2720b194dfb9"); |
|
147 |
|
|
148 |
TaxonNodeFilter filter = TaxonNodeFilter.NewSubtreeInstance(descriptaceaeUuid); |
|
149 |
filter.setIncludeUnpublished(true); |
|
150 |
List<AggregationMode> aggregationModes = AggregationMode.byToParent(); |
|
151 |
TermTree<PresenceAbsenceTerm> statusOrder = null; |
|
152 |
List<UUID> superAreas = new ArrayList<>(); |
|
153 |
DistributionAggregationConfiguration config = DistributionAggregationConfiguration.NewInstance(aggregationModes, superAreas, filter, statusOrder, monitor); |
|
154 |
config.setAdaptBatchSize(false); |
|
155 |
UpdateResult result = config.getTaskInstance().invoke(config, app); |
|
156 |
System.out.println(result); |
|
157 |
} |
|
158 |
|
|
159 |
private void aggregateDDS(CdmApplicationController app){ |
|
160 |
|
|
161 |
System.out.println("find dds"); |
|
162 |
DescriptiveDataSet dds = app.getDescriptiveDataSetService().find(21); |
|
163 |
UUID facciniaSubtreeUuid = UUID.fromString("cf0bc346-a203-4ad7-ad25-477098361db6"); |
|
164 |
UUID arenarioAdamssubtreeUuid = UUID.fromString("0215e668-0a65-42cd-85e0-d97ce78e758b"); |
|
165 |
|
|
166 |
TaxonNodeFilter filter = TaxonNodeFilter.NewSubtreeInstance(arenarioAdamssubtreeUuid); |
|
167 |
filter.setIncludeUnpublished(true); |
|
168 |
|
|
169 |
DefaultProgressMonitor monitor = DefaultProgressMonitor.NewInstance(); |
|
170 |
StructuredDescriptionAggregationConfiguration config = StructuredDescriptionAggregationConfiguration.NewInstance(filter, monitor); |
|
171 |
config.setDatasetUuid(dds.getUuid()); |
|
172 |
config.setAggregationMode(AggregationMode.byWithinTaxonAndToParent()); |
|
173 |
config.setAdaptBatchSize(false); |
|
174 |
UpdateResult result = config.getTaskInstance().invoke(config, app); |
|
175 |
System.out.println(result); |
|
176 |
|
|
177 |
// app.getLongRunningTasksService().invoke(config); |
|
178 |
} |
|
179 |
|
|
180 |
private void listClassification(CdmApplicationController appCtr, List<String> propertyPaths) { |
|
181 |
try { |
|
182 |
List<Classification> list = appCtr.getClassificationService().list(null, null, null, null, propertyPaths); |
|
183 |
} catch (Exception e) { |
|
184 |
e.printStackTrace(); |
|
185 |
logger.warn(e.getMessage()); |
|
186 |
} |
|
187 |
} |
|
188 |
|
|
189 |
private void testGroupedTaxa(CdmApplicationController appCtr) { |
|
190 |
UUID classificationUuid = UUID.fromString("91231ebf-1c7a-47b9-a56c-b45b33137244"); |
|
191 |
UUID taxonUuid1 = UUID.fromString("3bae1c86-1235-4e2e-be63-c7f8c4410527"); |
|
192 |
UUID taxonUuid2 = UUID.fromString("235d3872-defe-4b92-bf2f-75a7c91510de"); |
|
193 |
List<UUID> taxonUuids = Arrays.asList(new UUID[]{taxonUuid1, taxonUuid2}); |
|
194 |
Rank maxRank = DefinedTermBase.getTermByClassAndUUID(Rank.class, UUID.fromString("af5f2481-3192-403f-ae65-7c957a0f02b6")); |
|
195 |
Rank minRank = DefinedTermBase.getTermByClassAndUUID(Rank.class, UUID.fromString("78786e16-2a70-48af-a608-494023b91904")); |
|
196 |
List<GroupedTaxonDTO> groupedTaxa = appCtr.getClassificationService().groupTaxaByHigherTaxon(taxonUuids, classificationUuid, minRank, maxRank); |
|
197 |
System.out.println(groupedTaxa); |
|
198 |
} |
|
199 |
|
|
200 |
private void addPerson(CdmApplicationController appCtr) { |
|
201 |
TransactionStatus tx = appCtr.startTransaction(); |
|
202 |
appCtr.getAgentService().save(Person.NewInstance()); |
|
203 |
appCtr.commitTransaction(tx); |
|
204 |
} |
|
205 |
|
|
206 |
private void deleteHighLevelNode(CdmApplicationController appCtr) { |
|
207 |
TransactionStatus tx = appCtr.startTransaction(); |
|
208 |
ITaxonNodeService service = appCtr.getTaxonNodeService(); |
|
209 |
TaxonNode node = service.find(60554); |
|
210 |
// service.delete(node); |
|
211 |
ITaxonService taxonService = appCtr.getTaxonService(); |
|
212 |
Taxon taxon = node.getTaxon(); |
|
213 |
//try { |
|
214 |
taxonService.deleteTaxon(taxon.getUuid(), new TaxonDeletionConfigurator(), node.getClassification().getUuid()); |
|
215 |
|
|
216 |
/*} catch (DataChangeNoRollbackException e) { |
|
217 |
e.printStackTrace(); |
|
218 |
}*/ |
|
219 |
try { |
|
220 |
appCtr.commitTransaction(tx); |
|
221 |
} catch (Exception e) { |
|
222 |
// TODO Auto-generated catch block |
|
223 |
e.printStackTrace(); |
|
224 |
} |
|
225 |
TaxonNode node2 = service.find(60554); |
|
226 |
|
|
227 |
|
|
228 |
} |
|
229 |
|
|
230 |
// private void insertSomeData(CdmApplicationController appCtr) { |
|
231 |
// Classification cl = Classification.NewInstance("myClass"); |
|
232 |
// TaxonNode node1 = cl.addChildTaxon(Taxon.NewInstance(TaxonNameFactory.NewBotanicalInstance(null), null), null, null); |
|
233 |
// appCtr.getClassificationService().save(cl); |
|
234 |
// |
|
235 |
// Taxon t2 = Taxon.NewInstance(null, null); |
|
236 |
// t2.setTitleCache("Taxon2", true); |
|
237 |
// TaxonNode node2 = node1.addChildTaxon(t2, null, null); |
|
238 |
// |
|
239 |
// Taxon t3 = Taxon.NewInstance(null, null); |
|
240 |
// t3.setTitleCache("Taxon3", true); |
|
241 |
// TaxonNode node3 = node1.addChildTaxon(t3, 0, null, null); |
|
242 |
// |
|
243 |
// appCtr.getTaxonNodeService().saveOrUpdate(node1); |
|
244 |
// |
|
245 |
// cl.addChildNode(node3, 0, null, null); |
|
246 |
// appCtr.getTaxonNodeService().saveOrUpdate(node3); |
|
247 |
// appCtr.getClassificationService().saveOrUpdate(cl); |
|
248 |
// |
|
249 |
// TermTree<Feature> ft1 = TermTree.NewInstance(); |
|
250 |
// FeatureNode fn1 = TermNode.NewInstance((Feature)null); |
|
251 |
// ft1.getRoot().addChild(fn1); |
|
252 |
// appCtr.getFeatureNodeService().save(fn1); |
|
253 |
// |
|
254 |
// TermNode fn2 = TermNode.NewInstance((Feature)null); |
|
255 |
// fn1.addChild(fn2); |
|
256 |
// |
|
257 |
// TermNode fn3 = TermNode.NewInstance((Feature)null); |
|
258 |
// fn1.addChild(fn2, 0); |
|
259 |
// |
|
260 |
// appCtr.getFeatureNodeService().saveOrUpdate(fn1); |
|
261 |
// |
|
262 |
// ft1.getRoot().addChild(fn3, 0); |
|
263 |
// appCtr.getFeatureNodeService().saveOrUpdate(fn3); |
|
264 |
// appCtr.getFeatureTreeService().saveOrUpdate(ft1); |
|
265 |
// } |
|
266 |
|
|
267 |
private void testDatabaseChange() throws DataSourceNotFoundException{ |
|
268 |
CdmApplicationController appCtr; |
|
269 |
appCtr = CdmApplicationController.NewInstance(); |
|
270 |
|
|
271 |
// DatabaseTypeEnum dbType = DatabaseTypeEnum.MySQL; |
|
272 |
// String server = "192.168.2.10"; |
|
273 |
// String database = "cdm_test_andreas"; |
|
274 |
// String user = "edit"; |
|
275 |
// String pwd = "wp5"; |
|
276 |
// |
|
277 |
DatabaseTypeEnum dbType = DatabaseTypeEnum.SqlServer2005; |
|
278 |
String server = "LAPTOPHP"; |
|
279 |
String database = "cdmTest"; |
|
280 |
String username = "edit"; |
|
281 |
String password = ""; |
|
282 |
|
|
283 |
ICdmDataSource dataSource = CdmDataSource.NewInstance(DatabaseTypeEnum.SqlServer2005, "LAPTOPHP", "cdmTest", DatabaseTypeEnum.SqlServer2005.getDefaultPort(), "edit", ""); |
|
284 |
|
|
285 |
appCtr.getDatabaseService().saveDataSource("testSqlServer", dataSource); |
|
286 |
try { |
|
287 |
appCtr.getDatabaseService().connectToDatabase(dbType, server, database, username, password); |
|
288 |
} catch (TermNotFoundException e) { |
|
289 |
// TODO Auto-generated catch block |
|
290 |
e.printStackTrace(); |
|
291 |
} |
|
292 |
|
|
293 |
appCtr.close(); |
|
294 |
} |
|
295 |
|
|
296 |
private void testSqlServer2005(){ |
|
297 |
DatabaseTypeEnum databaseTypeEnum = DatabaseTypeEnum.SqlServer2005; |
|
298 |
String server = "LAPTOPHP"; |
|
299 |
String database = "cdmTest"; |
|
300 |
String username = "edit"; |
|
301 |
String password = ""; |
|
302 |
|
|
303 |
ICdmDataSource dataSource = CdmDataSource.NewInstance(databaseTypeEnum, server, database, databaseTypeEnum.getDefaultPort(), username, password); |
|
304 |
|
|
305 |
CdmPersistentDataSource ds = CdmPersistentDataSource.save("testSqlServer", dataSource); |
|
306 |
|
|
307 |
CdmApplicationController appCtr = CdmApplicationController.NewInstance(ds); |
|
308 |
Person agent = Person.NewInstance(); |
|
309 |
appCtr.getAgentService().save(agent); |
|
310 |
TaxonName tn = TaxonNameFactory.NewBotanicalInstance(null); |
|
311 |
appCtr.getNameService().save(tn); |
|
312 |
appCtr.close(); |
|
313 |
|
|
314 |
} |
|
315 |
|
|
316 |
private void testLocalHsql(){ |
|
317 |
CdmApplicationController appCtr = null; |
|
318 |
try { |
|
319 |
CdmPersistentDataSource ds = CdmPersistentDataSource.NewLocalHsqlInstance(); |
|
320 |
appCtr = CdmApplicationController.NewInstance(ds); |
|
321 |
List<?> l = appCtr.getNameService().list(null,5, 1,null,null); |
|
322 |
System.out.println(l); |
|
323 |
//Agent agent = new Agent(); |
|
324 |
//appCtr.getAgentService().saveAgent(agent); |
|
325 |
appCtr.close(); |
|
326 |
} catch (RuntimeException e) { |
|
327 |
logger.error("Runtime Exception"); |
|
328 |
e.printStackTrace(); |
|
329 |
if (appCtr != null){ |
|
330 |
appCtr.close(); |
|
331 |
} |
|
332 |
|
|
333 |
} catch (DataSourceNotFoundException e) { |
|
334 |
logger.error("Runtime Exception"); |
|
335 |
e.printStackTrace(); |
|
336 |
} |
|
337 |
} |
|
338 |
|
|
339 |
private void testLocalH2(){ |
|
340 |
|
|
341 |
DbSchemaValidation validation = DbSchemaValidation.CREATE; |
|
342 |
ICdmDataSource ds = |
|
343 |
CdmDataSource.NewH2EmbeddedInstance("cdm", "sa", "", null); |
|
344 |
// ds = |
|
345 |
// CdmPersistentDataSource.NewInstance("localH2"); |
|
346 |
CdmApplicationController appCtr = CdmApplicationController.NewInstance(ds, validation); |
|
347 |
|
|
348 |
boolean exists = appCtr.getUserService().userExists("admin"); |
|
349 |
try { |
|
350 |
IBotanicalName name = TaxonNameFactory.NewBotanicalInstance(null); |
|
351 |
String nameCache = "testName"; |
|
352 |
name.setNameCache(nameCache); |
|
353 |
name.setTitleCache(nameCache, true); |
|
354 |
Reference ref = ReferenceFactory.newGeneric(); |
|
355 |
ref.setTitleCache("mySec", true); |
|
356 |
Taxon taxon = Taxon.NewInstance(name, ref); |
|
357 |
TaxonDescription description = TaxonDescription.NewInstance(); |
|
358 |
taxon.addDescription(description); |
|
359 |
NamedArea area1 = appCtr.getTermService().getAreaByTdwgAbbreviation("GER"); |
|
360 |
Distribution distribution = Distribution.NewInstance(area1, PresenceAbsenceTerm.PRESENT()); |
|
361 |
description.addElement(distribution); |
|
362 |
|
|
363 |
List<Distribution> distrList = new ArrayList<Distribution>(); |
|
364 |
distrList.add(distribution); |
|
365 |
List<NamedArea> areaList = new ArrayList<NamedArea>(); |
|
366 |
areaList.add(area1); |
|
367 |
|
|
368 |
// distribution.getInDescription().get |
|
369 |
appCtr.getTaxonService().save(taxon); |
|
370 |
|
|
371 |
System.out.println(taxon.getDescriptions().size()); |
|
372 |
|
|
373 |
TransactionStatus txStatus = appCtr.startTransaction(); |
|
374 |
|
|
375 |
Session session = appCtr.getSessionFactory().getCurrentSession(); |
|
376 |
|
|
377 |
//String hqlQuery = "from DescriptionBase d join d.elements as e " |
|
378 |
// String hqlQuery = "from Taxon t join t.descriptions as d "+ |
|
379 |
// " inner join d.elements e on e member of d " |
|
380 |
// + |
|
381 |
// "";//" where e.area = :namedArea " ; |
|
382 |
String hqlQuery = "Select t from Distribution e join e.inDescription d join d.taxon t join t.name n "+ |
|
383 |
" WHERE e.area in (:namedArea) AND n.nameCache = :nameCache "; |
|
384 |
Query query = session.createQuery(hqlQuery); |
|
385 |
|
|
386 |
//query.setEntity("namedArea", area1); |
|
387 |
query.setParameter("nameCache", nameCache); |
|
388 |
query.setParameterList("namedArea", areaList); |
|
389 |
List resultList = query.list(); |
|
390 |
//List list = appCtr.getCommonService().getHqlResult(hqlQuery); |
|
391 |
|
|
392 |
for (Object o:resultList){ |
|
393 |
System.out.println(o); |
|
394 |
} |
|
395 |
appCtr.commitTransaction(txStatus); |
|
396 |
|
|
397 |
//System.out.println(l); |
|
398 |
//Agent agent = new Agent(); |
|
399 |
//appCtr.getAgentService().saveAgent(agent); |
|
400 |
appCtr.close(); |
|
401 |
} catch (RuntimeException e) { |
|
402 |
logger.error("Runtime Exception"); |
|
403 |
e.printStackTrace(); |
|
404 |
appCtr.close(); |
|
405 |
|
|
406 |
} |
|
407 |
} |
|
408 |
|
|
409 |
private boolean testWritableResourceDirectory() throws IOException{ |
|
410 |
CdmApplicationUtils.getWritableResourceDir(); |
|
411 |
return true; |
|
412 |
} |
|
413 |
|
|
414 |
private boolean testH2(){ |
|
415 |
// testLocalH2(); |
|
416 |
// if (true)return true; |
|
417 |
|
|
418 |
DbSchemaValidation validation = DbSchemaValidation.CREATE; |
|
419 |
ICdmDataSource ds = |
|
420 |
CdmDataSource.NewH2EmbeddedInstance("cdm", "sa", "", null); |
|
421 |
//CdmDataSource.NewH2EmbeddedInstance("cdm", "sa", ""); |
|
422 |
// ds = |
|
423 |
// CdmPersistentDataSource.NewInstance("localH2"); |
|
424 |
CdmApplicationController appCtr = CdmApplicationController.NewInstance(ds, validation); |
|
425 |
try { |
|
426 |
TaxonName botName1 = TaxonNameFactory.NewBotanicalInstance(Rank.SPECIES()); |
|
427 |
TaxonName botName2 = TaxonNameFactory.NewBotanicalInstance(Rank.SPECIES()); |
|
428 |
IBotanicalName hybridName = TaxonNameFactory.NewBotanicalInstance(Rank.SPECIES()); |
|
429 |
botName1.addRelationshipToName(botName2, NameRelationshipType.ORTHOGRAPHIC_VARIANT(), null, null); |
|
430 |
UUID uuid1 = botName1.getUuid(); |
|
431 |
UUID uuid2 = botName2.getUuid(); |
|
432 |
try { |
|
433 |
Logger loggerTrace = Logger.getLogger("org.hibernate.type"); |
|
434 |
//loggerTrace.setLevel(Level.TRACE); |
|
435 |
System.out.println(logger.getName()); |
|
436 |
|
|
437 |
appCtr.getNameService().save(botName1); |
|
438 |
ResultSet rs = ds.executeQuery("Select count(*) as n FROM NameRelationship"); |
|
439 |
rs.next(); |
|
440 |
int c = rs.getInt("n"); |
|
441 |
System.out.println("Begin :" + c); |
|
442 |
|
|
443 |
botName1.removeRelationToTaxonName(botName2); |
|
444 |
botName1.setSpecificEpithet("DELETED"); |
|
445 |
botName2.addHybridParent(hybridName, HybridRelationshipType.FIRST_PARENT(), null); |
|
446 |
|
|
447 |
TransactionStatus tx = appCtr.startTransaction(); |
|
448 |
appCtr.getNameService().saveOrUpdate(botName2); |
|
449 |
rs = ds.executeQuery("Select count(*) as n FROM NameRelationship"); |
|
450 |
rs.next(); |
|
451 |
c = rs.getInt("n"); |
|
452 |
System.out.println("End: " + c); |
|
453 |
|
|
454 |
appCtr.commitTransaction(tx); |
|
455 |
|
|
456 |
appCtr.getNameService().saveOrUpdate(botName1); |
|
457 |
|
|
458 |
rs = ds.executeQuery("Select count(*) as n FROM NameRelationship"); |
|
459 |
rs.next(); |
|
460 |
c = rs.getInt("n"); |
|
461 |
System.out.println("End: " + c); |
|
462 |
|
|
463 |
} catch (SQLException e) { |
|
464 |
// TODO Auto-generated catch block |
|
465 |
e.printStackTrace(); |
|
466 |
} |
|
467 |
|
|
468 |
|
|
469 |
//Agent agent = new Agent(); |
|
470 |
//appCtr.getAgentService().saveAgent(agent); |
|
471 |
appCtr.close(); |
|
472 |
return true; |
|
473 |
} catch (RuntimeException e) { |
|
474 |
logger.error("Runtime Exception"); |
|
475 |
e.printStackTrace(); |
|
476 |
appCtr.close(); |
|
477 |
|
|
478 |
} |
|
479 |
return false; |
|
480 |
} |
|
481 |
|
|
482 |
private void test(){ |
|
483 |
System.out.println("Start Datasource"); |
|
484 |
testNewConfigControler(); |
|
485 |
//testDatabaseChange(); |
|
486 |
|
|
487 |
//testSqlServer(); |
|
488 |
|
|
489 |
//CdmUtils.findLibrary(au.com.bytecode.opencsv.CSVReader.class); |
|
490 |
//testPostgreServer(); |
|
491 |
//testLocalHsql(); |
|
492 |
//testLocalH2(); |
|
493 |
//testWritableResourceDirectory(); |
|
494 |
// testH2(); |
|
495 |
System.out.println("\nEnd Datasource"); |
|
496 |
} |
|
497 |
|
|
498 |
/** |
|
499 |
* @param args |
|
500 |
*/ |
|
501 |
public static void main(String[] args) { |
|
502 |
Datasource cc = new Datasource(); |
|
503 |
cc.test(); |
|
504 |
} |
|
505 |
|
|
506 |
} |
cdmlib-services/src/test/java/eu/etaxonomy/cdm/test/function/TestAgentService.java | ||
---|---|---|
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 |
package eu.etaxonomy.cdm.test.function; |
|
10 |
|
|
11 |
import java.util.List; |
|
12 |
|
|
13 |
import org.junit.AfterClass; |
|
14 |
import org.junit.Assert; |
|
15 |
import org.junit.BeforeClass; |
|
16 |
import org.junit.Ignore; |
|
17 |
import org.junit.Test; |
|
18 |
|
|
19 |
import eu.etaxonomy.cdm.api.application.CdmApplicationController; |
|
20 |
import eu.etaxonomy.cdm.database.CdmDataSource; |
|
21 |
import eu.etaxonomy.cdm.database.DbSchemaValidation; |
|
22 |
import eu.etaxonomy.cdm.model.agent.Person; |
|
23 |
import eu.etaxonomy.cdm.model.agent.Team; |
|
24 |
import eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache; |
|
25 |
|
|
26 |
/** |
|
27 |
* <h2>NOTE</h2> |
|
28 |
* This is a test for sole development purposes, it is not |
|
29 |
* touched by mvn test since it is not matching the "\/**\/*Test" pattern, |
|
30 |
* but it should be annotate with @Ignore when running the project as junit suite in eclipse |
|
31 |
* |
|
32 |
* @author nho |
|
33 |
*/ |
|
34 |
@Ignore /* IGNORE in Suite */ |
|
35 |
public class TestAgentService { |
|
36 |
|
|
37 |
static CdmApplicationController appController; |
|
38 |
|
|
39 |
@BeforeClass |
|
40 |
public static void setUpBeforeClass() throws Exception { |
|
41 |
// CdmDataSource dataSource = CdmDataSource.NewMySqlInstance("localhost", "test", -1, "", ""); |
|
42 |
CdmDataSource dataSource = CdmDataSource.NewH2EmbeddedInstance("TestAgentService", "sa", ""); |
|
43 |
appController = CdmApplicationController.NewInstance(dataSource, DbSchemaValidation.UPDATE); |
|
44 |
} |
|
45 |
|
|
46 |
@AfterClass |
|
47 |
public static void tearDownAfterClass() throws Exception { |
|
48 |
appController.close(); |
|
49 |
} |
|
50 |
|
|
51 |
@Test |
|
52 |
public void testGetTeamOrPersonBaseUuidAndNomenclaturalTitle(){ |
|
53 |
List<UuidAndTitleCache<Team>> result = appController.getAgentService().getTeamUuidAndNomenclaturalTitle(); |
|
54 |
|
|
55 |
Assert.assertNotNull(result); |
|
56 |
Assert.assertTrue(result.size() > 0); |
|
57 |
} |
|
58 |
|
|
59 |
@Test |
|
60 |
public void testGetPersonUuidAndNomenclaturalTitle(){ |
|
61 |
List<UuidAndTitleCache<Person>> result = appController.getAgentService().getUuidAndTitleCache(Person.class, null, null); |
|
62 |
|
|
63 |
Assert.assertNotNull(result); |
|
64 |
Assert.assertTrue(result.size() > 0); |
|
65 |
} |
|
66 |
} |
cdmlib-services/src/test/java/eu/etaxonomy/cdm/test/function/TestConversationEnabled.java | ||
---|---|---|
1 |
/** |
|
2 |
* Copyright (C) 2007 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 java.util.Collection; |
|
13 |
|
|
14 |
import org.apache.log4j.Logger; |
|
15 |
import org.junit.Ignore; |
|
16 |
|
|
17 |
import eu.etaxonomy.cdm.api.conversation.ConversationHolder; |
|
18 |
import eu.etaxonomy.cdm.api.conversation.IConversationEnabled; |
|
19 |
import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeEvent; |
|
20 |
import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap; |
|
21 |
|
|
22 |
/** |
|
23 |
* <h2>NOTE</h2> |
|
24 |
* This is a test for sole development purposes, it is not |
|
25 |
* touched by mvn test since it is not matching the "\/**\/*Test" pattern, |
|
26 |
* but it should be annotate with @Ignore when running the project a s junit suite in eclipse |
|
27 |
* |
|
28 |
* @author n.hoffmann |
|
29 |
* @since 25.03.2009 |
|
30 |
* @version 1.0 |
|
31 |
*/ |
|
32 |
@Ignore |
|
33 |
public class TestConversationEnabled implements IConversationEnabled { |
|
34 |
private static final Logger logger = Logger |
|
35 |
.getLogger(TestConversationEnabled.class); |
|
36 |
|
|
37 |
ConversationHolder conversationHolder; |
|
38 |
|
|
39 |
/* (non-Javadoc) |
|
40 |
* @see eu.etaxonomy.cdm.api.conversation.IConversationEnabled#getConversationHolder() |
|
41 |
*/ |
|
42 |
public ConversationHolder getConversationHolder() { |
|
43 |
// TODO Auto-generated method stub |
|
44 |
return null; |
|
45 |
} |
|
46 |
|
|
47 |
|
|
48 |
/* (non-Javadoc) |
|
49 |
* @see eu.etaxonomy.cdm.persistence.hibernate.ICdmPostDataChangeObserver#update(eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap) |
|
50 |
*/ |
|
51 |
public void update(CdmDataChangeMap changeEvents) { |
|
52 |
Collection<CdmDataChangeEvent> events = changeEvents.getAllEvents(); |
|
53 |
for(CdmDataChangeEvent event : events){ |
|
54 |
logger.warn("CdmCrudEvent fired: " + event.getEventType() + " : " + event.getEntity()); |
|
55 |
} |
|
56 |
} |
|
57 |
} |
cdmlib-services/src/test/java/eu/etaxonomy/cdm/test/function/TestLocationServiceImpl.java | ||
---|---|---|
1 |
/** |
|
2 |
* Copyright (C) 2007 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 |
|
|
13 |
import java.io.FileNotFoundException; |
|
14 |
|
|
15 |
import org.apache.log4j.Logger; |
|
16 |
import org.junit.Ignore; |
|
17 |
import org.junit.Test; |
|
18 |
import org.unitils.spring.annotation.SpringBeanByType; |
|
19 |
|
|
20 |
import eu.etaxonomy.cdm.api.application.CdmApplicationController; |
|
21 |
import eu.etaxonomy.cdm.api.conversation.ConversationHolder; |
|
22 |
import eu.etaxonomy.cdm.api.service.ILocationService; |
|
23 |
import eu.etaxonomy.cdm.api.service.ILocationService.NamedAreaVocabularyType; |
|
24 |
import eu.etaxonomy.cdm.database.CdmDataSource; |
|
25 |
import eu.etaxonomy.cdm.database.DbSchemaValidation; |
|
26 |
import eu.etaxonomy.cdm.database.ICdmDataSource; |
|
27 |
import eu.etaxonomy.cdm.model.taxon.Taxon; |
|
28 |
import eu.etaxonomy.cdm.test.integration.CdmIntegrationTest; |
|
29 |
|
|
30 |
/** |
|
31 |
* <h2>NOTE</h2> |
|
32 |
* This is a test for sole development purposes, it is not |
|
33 |
* touched by mvn test since it is not matching the "\/**\/*Test" pattern, |
|
34 |
* but it should be annotate with @Ignore when running the project a s junit suite in eclipse |
|
35 |
* |
|
36 |
* @author n.hoffman |
|
37 |
* @since 12.05.2009 |
|
38 |
*/ |
|
39 |
@Ignore |
|
40 |
public class TestLocationServiceImpl extends CdmIntegrationTest{ |
|
41 |
|
|
42 |
@SuppressWarnings("unused") |
|
43 |
private static final Logger logger = Logger.getLogger(TestLocationServiceImpl.class); |
|
44 |
|
|
45 |
@SpringBeanByType |
|
46 |
private ILocationService locationService; |
|
47 |
|
|
48 |
@Ignore |
|
49 |
@Test |
|
50 |
public void testGetTopLevelContinentAreas(){ |
|
51 |
locationService.getTopLevelNamedAreasByVocabularyType(NamedAreaVocabularyType.CONTINENT); |
|
52 |
} |
|
53 |
|
|
54 |
@Test |
|
55 |
public void testGetTopLevelTdwgAreas(){ |
|
56 |
locationService.getTopLevelNamedAreasByVocabularyType(NamedAreaVocabularyType.TDWG_AREA); |
|
57 |
} |
|
58 |
|
|
59 |
@Ignore |
|
60 |
@Test |
|
61 |
public void testGetTopLevelCoutryAreas(){ |
|
62 |
locationService.getTopLevelNamedAreasByVocabularyType(NamedAreaVocabularyType.COUNTRY); |
|
63 |
} |
|
64 |
|
|
65 |
@Ignore |
|
66 |
@Test |
|
67 |
public void testGetTopLevelWaterbodyAreas(){ |
|
68 |
locationService.getTopLevelNamedAreasByVocabularyType(NamedAreaVocabularyType.WATERBODY); |
|
69 |
} |
|
70 |
|
|
71 |
public void testNewDatasourceClass(){ |
|
72 |
// String server = "192.168.2.10"; |
|
73 |
// String database = "cdm_test_andreasM"; |
|
74 |
// String username = "edit"; |
|
75 |
// String password = CdmUtils.readInputLine("Password: "); |
|
76 |
DbSchemaValidation dbSchemaValidation = DbSchemaValidation.CREATE; |
|
77 |
|
|
78 |
// ICdmDataSource datasource = CdmDataSource.NewMySqlInstance(server, database, username, password); |
|
79 |
ICdmDataSource datasource = CdmDataSource.NewH2EmbeddedInstance("test", "sa", "", null); |
|
80 |
CdmApplicationController appCtr = CdmApplicationController.NewInstance(datasource, dbSchemaValidation); |
|
81 |
|
|
82 |
ConversationHolder conversation = appCtr.NewConversation(); |
|
83 |
conversation.bind(); |
|
84 |
|
|
85 |
Taxon taxon = Taxon.NewInstance(null, null); |
|
86 |
|
|
87 |
} |
|
88 |
|
|
89 |
/* (non-Javadoc) |
|
90 |
* @see eu.etaxonomy.cdm.test.integration.CdmIntegrationTest#createTestData() |
|
91 |
*/ |
|
92 |
@Override |
|
93 |
public void createTestDataSet() throws FileNotFoundException { |
|
94 |
// TODO Auto-generated method stub |
|
95 |
|
|
96 |
} |
|
97 |
} |
cdmlib-services/src/test/java/eu/etaxonomy/cdm/test/function/TestScript.java | ||
---|---|---|
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 java.io.IOException; |
|
13 |
import java.sql.ResultSet; |
|
14 |
import java.sql.SQLException; |
|
15 |
import java.util.ArrayList; |
|
16 |
import java.util.Arrays; |
|
17 |
import java.util.List; |
|
18 |
import java.util.UUID; |
|
19 |
|
|
20 |
import org.apache.log4j.Logger; |
|
21 |
import org.hibernate.Query; |
|
22 |
import org.hibernate.Session; |
|
23 |
import org.springframework.transaction.TransactionStatus; |
|
24 |
|
|
25 |
import eu.etaxonomy.cdm.api.application.CdmApplicationController; |
|
26 |
import eu.etaxonomy.cdm.api.application.CdmApplicationUtils; |
|
27 |
import eu.etaxonomy.cdm.api.service.ITaxonNodeService; |
|
28 |
import eu.etaxonomy.cdm.api.service.ITaxonService; |
|
29 |
import eu.etaxonomy.cdm.api.service.UpdateResult; |
|
30 |
import eu.etaxonomy.cdm.api.service.config.TaxonDeletionConfigurator; |
|
31 |
import eu.etaxonomy.cdm.api.service.description.AggregationMode; |
|
32 |
import eu.etaxonomy.cdm.api.service.description.DistributionAggregationConfiguration; |
|
33 |
import eu.etaxonomy.cdm.api.service.description.StructuredDescriptionAggregationConfiguration; |
|
34 |
import eu.etaxonomy.cdm.api.service.dto.GroupedTaxonDTO; |
|
35 |
import eu.etaxonomy.cdm.common.monitor.DefaultProgressMonitor; |
|
36 |
import eu.etaxonomy.cdm.config.AccountStore; |
|
37 |
import eu.etaxonomy.cdm.database.CdmDataSource; |
|
38 |
import eu.etaxonomy.cdm.database.CdmPersistentDataSource; |
|
39 |
import eu.etaxonomy.cdm.database.DataSourceNotFoundException; |
|
40 |
import eu.etaxonomy.cdm.database.DatabaseTypeEnum; |
|
41 |
import eu.etaxonomy.cdm.database.DbSchemaValidation; |
|
42 |
import eu.etaxonomy.cdm.database.ICdmDataSource; |
|
43 |
import eu.etaxonomy.cdm.filter.TaxonNodeFilter; |
|
44 |
import eu.etaxonomy.cdm.model.agent.Person; |
|
45 |
import eu.etaxonomy.cdm.model.description.DescriptiveDataSet; |
|
46 |
import eu.etaxonomy.cdm.model.description.Distribution; |
|
47 |
import eu.etaxonomy.cdm.model.description.PresenceAbsenceTerm; |
|
48 |
import eu.etaxonomy.cdm.model.description.TaxonDescription; |
|
49 |
import eu.etaxonomy.cdm.model.location.NamedArea; |
|
50 |
import eu.etaxonomy.cdm.model.name.HybridRelationshipType; |
|
51 |
import eu.etaxonomy.cdm.model.name.IBotanicalName; |
|
52 |
import eu.etaxonomy.cdm.model.name.NameRelationshipType; |
|
53 |
import eu.etaxonomy.cdm.model.name.Rank; |
|
54 |
import eu.etaxonomy.cdm.model.name.TaxonName; |
|
55 |
import eu.etaxonomy.cdm.model.name.TaxonNameFactory; |
|
56 |
import eu.etaxonomy.cdm.model.reference.Reference; |
|
57 |
import eu.etaxonomy.cdm.model.reference.ReferenceFactory; |
|
58 |
import eu.etaxonomy.cdm.model.taxon.Classification; |
|
59 |
import eu.etaxonomy.cdm.model.taxon.Taxon; |
|
60 |
import eu.etaxonomy.cdm.model.taxon.TaxonNode; |
|
61 |
import eu.etaxonomy.cdm.model.term.DefinedTermBase; |
|
62 |
import eu.etaxonomy.cdm.model.term.TermTree; |
|
63 |
import eu.etaxonomy.cdm.model.term.init.TermNotFoundException; |
|
64 |
|
|
65 |
public class TestScript { |
|
66 |
private static final Logger logger = Logger.getLogger(TestScript.class); |
|
67 |
|
|
68 |
|
|
69 |
private void testNewConfigControler(){ |
|
70 |
|
|
71 |
DbSchemaValidation schema = DbSchemaValidation.VALIDATE; |
|
72 |
|
|
73 |
String server; |
|
74 |
String database; |
|
75 |
String username; |
|
76 |
ICdmDataSource dataSource; |
|
77 |
|
|
78 |
// List<CdmPersistentDataSource> lsDataSources = CdmPersistentDataSource.getAllDataSources(); |
|
79 |
// System.out.println(lsDataSources); |
|
80 |
// dataSource = lsDataSources.get(1); |
|
81 |
|
|
82 |
// DatabaseTypeEnum dbType = DatabaseTypeEnum.MySQL; |
|
83 |
|
|
84 |
server = "localhost"; |
|
85 |
database = "cdm_bupleurum"; |
|
86 |
// database = "cdm_production_edaphobase"; |
|
87 |
username = "edit"; |
|
88 |
dataSource = CdmDataSource.NewMySqlInstance(server, database, username, AccountStore.readOrStorePassword(server, database, username, null)); |
|
89 |
|
|
90 |
// server = "160.45.63.171"; |
|
91 |
// database = "cdm_production_salvador"; |
|
92 |
// username = "edit"; |
|
93 |
// dataSource = CdmDataSource.NewMySqlInstance(server, database, username, AccountStore.readOrStorePassword(server, database, username, null)); |
|
94 |
|
|
95 |
// server = "test.e-taxonomy.eu"; |
|
96 |
// database = "cdm_rem_conf_am"; |
|
97 |
// username = "edit"; |
|
98 |
// dataSource = CdmDataSource.NewMySqlInstance(server, database, username, AccountStore.readOrStorePassword(server, database, username, null)); |
|
99 |
|
|
100 |
// String server = "localhost"; |
|
101 |
// String database = "testCDM"; |
|
102 |
// String username = "postgres"; |
|
103 |
// dataSource = CdmDataSource.NewInstance(DatabaseTypeEnum.PostgreSQL, server, database, DatabaseTypeEnum.PostgreSQL.getDefaultPort(), username, AccountStore.readOrStorePassword(server, database, username, null)); |
|
104 |
|
|
105 |
// //SQLServer |
|
106 |
// server = "BGBM-PESISQL"; |
|
107 |
// database = "cdm36"; |
|
108 |
// int port = 1433; |
|
109 |
// username = "cdmupdater"; |
|
110 |
// dataSource = CdmDataSource.NewSqlServer2012Instance(server, database, port, username, AccountStore.readOrStorePassword(server, database, username, null)); |
|
111 |
// |
|
112 |
// //H2 |
|
113 |
// String path = "C:\\Users\\a.mueller\\.cdmLibrary\\writableResources\\h2\\LocalH2"; |
|
114 |
//// String path = "C:\\Users\\pesiimport\\.cdmLibrary\\writableResources\\h2\\LocalH2"; |
|
115 |
//// String path = "C:\\Users\\a.mueller\\eclipse\\svn\\cdmlib-trunk\\cdmlib-remote-webapp\\src\\test\\resources\\h2"; |
|
116 |
// username = "sa"; |
|
117 |
// dataSource = CdmDataSource.NewH2EmbeddedInstance("cdm", username, "", path); |
|
118 |
|
|
119 |
// dataSource = CdmDataSource.NewH2EmbeddedInstance(database, username, "sa"); |
|
120 |
|
|
121 |
|
|
122 |
// server = "160.45.63.201"; |
|
123 |
// database = "cdm_integration_cichorieae"; |
|
124 |
// username = "edit"; |
|
125 |
// dataSource = CdmDataSource.NewMySqlInstance(server, database, username, AccountStore.readOrStorePassword(server, database, username, null)); |
|
126 |
|
|
127 |
//CdmPersistentDataSource.save(dataSource.getName(), dataSource); |
|
128 |
CdmApplicationController appCtr; |
|
129 |
appCtr = CdmApplicationController.NewInstance(dataSource, schema); |
|
130 |
|
|
131 |
doTemporary(appCtr); |
|
132 |
|
|
133 |
appCtr.close(); |
|
134 |
System.exit(0); |
|
135 |
} |
|
136 |
|
|
137 |
private void doTemporary(CdmApplicationController appCtr) { |
|
138 |
//xx |
|
139 |
} |
|
140 |
|
|
141 |
private void aggregateDistribution(CdmApplicationController app){ |
|
142 |
|
|
143 |
System.out.println("agg distr"); |
|
144 |
DefaultProgressMonitor monitor = DefaultProgressMonitor.NewInstance(); |
|
145 |
|
|
146 |
UUID descriptaceaeUuid = UUID.fromString("5a37c47c-347c-49f8-88ba-2720b194dfb9"); |
|
147 |
|
|
148 |
TaxonNodeFilter filter = TaxonNodeFilter.NewSubtreeInstance(descriptaceaeUuid); |
|
149 |
filter.setIncludeUnpublished(true); |
|
150 |
List<AggregationMode> aggregationModes = AggregationMode.byToParent(); |
|
151 |
TermTree<PresenceAbsenceTerm> statusOrder = null; |
|
152 |
List<UUID> superAreas = new ArrayList<>(); |
|
153 |
DistributionAggregationConfiguration config = DistributionAggregationConfiguration.NewInstance(aggregationModes, superAreas, filter, statusOrder, monitor); |
|
154 |
config.setAdaptBatchSize(false); |
|
155 |
UpdateResult result = config.getTaskInstance().invoke(config, app); |
|
156 |
System.out.println(result); |
|
157 |
} |
|
158 |
|
|
159 |
private void aggregateDDS(CdmApplicationController app){ |
|
160 |
|
|
161 |
System.out.println("find dds"); |
|
162 |
DescriptiveDataSet dds = app.getDescriptiveDataSetService().find(21); |
|
163 |
UUID facciniaSubtreeUuid = UUID.fromString("cf0bc346-a203-4ad7-ad25-477098361db6"); |
|
164 |
UUID arenarioAdamssubtreeUuid = UUID.fromString("0215e668-0a65-42cd-85e0-d97ce78e758b"); |
|
165 |
|
|
166 |
TaxonNodeFilter filter = TaxonNodeFilter.NewSubtreeInstance(arenarioAdamssubtreeUuid); |
|
167 |
filter.setIncludeUnpublished(true); |
|
168 |
|
|
169 |
DefaultProgressMonitor monitor = DefaultProgressMonitor.NewInstance(); |
|
170 |
StructuredDescriptionAggregationConfiguration config = StructuredDescriptionAggregationConfiguration.NewInstance(filter, monitor); |
|
171 |
config.setDatasetUuid(dds.getUuid()); |
|
172 |
config.setAggregationMode(AggregationMode.byWithinTaxonAndToParent()); |
|
173 |
config.setAdaptBatchSize(false); |
|
174 |
UpdateResult result = config.getTaskInstance().invoke(config, app); |
|
175 |
System.out.println(result); |
|
176 |
|
|
177 |
// app.getLongRunningTasksService().invoke(config); |
|
178 |
} |
|
179 |
|
|
180 |
private void listClassification(CdmApplicationController appCtr, List<String> propertyPaths) { |
|
181 |
try { |
|
182 |
List<Classification> list = appCtr.getClassificationService().list(null, null, null, null, propertyPaths); |
|
183 |
} catch (Exception e) { |
|
184 |
e.printStackTrace(); |
|
185 |
logger.warn(e.getMessage()); |
|
186 |
} |
|
187 |
} |
|
188 |
|
|
189 |
private void testGroupedTaxa(CdmApplicationController appCtr) { |
|
190 |
UUID classificationUuid = UUID.fromString("91231ebf-1c7a-47b9-a56c-b45b33137244"); |
|
191 |
UUID taxonUuid1 = UUID.fromString("3bae1c86-1235-4e2e-be63-c7f8c4410527"); |
|
192 |
UUID taxonUuid2 = UUID.fromString("235d3872-defe-4b92-bf2f-75a7c91510de"); |
|
193 |
List<UUID> taxonUuids = Arrays.asList(new UUID[]{taxonUuid1, taxonUuid2}); |
|
194 |
Rank maxRank = DefinedTermBase.getTermByClassAndUUID(Rank.class, UUID.fromString("af5f2481-3192-403f-ae65-7c957a0f02b6")); |
|
195 |
Rank minRank = DefinedTermBase.getTermByClassAndUUID(Rank.class, UUID.fromString("78786e16-2a70-48af-a608-494023b91904")); |
|
196 |
List<GroupedTaxonDTO> groupedTaxa = appCtr.getClassificationService().groupTaxaByHigherTaxon(taxonUuids, classificationUuid, minRank, maxRank); |
|
197 |
System.out.println(groupedTaxa); |
|
198 |
} |
|
199 |
|
|
200 |
private void addPerson(CdmApplicationController appCtr) { |
|
201 |
TransactionStatus tx = appCtr.startTransaction(); |
|
202 |
appCtr.getAgentService().save(Person.NewInstance()); |
|
203 |
appCtr.commitTransaction(tx); |
|
204 |
} |
|
205 |
|
|
206 |
private void deleteHighLevelNode(CdmApplicationController appCtr) { |
|
207 |
TransactionStatus tx = appCtr.startTransaction(); |
|
208 |
ITaxonNodeService service = appCtr.getTaxonNodeService(); |
|
209 |
TaxonNode node = service.find(60554); |
|
210 |
// service.delete(node); |
|
211 |
ITaxonService taxonService = appCtr.getTaxonService(); |
|
212 |
Taxon taxon = node.getTaxon(); |
|
213 |
//try { |
|
214 |
taxonService.deleteTaxon(taxon.getUuid(), new TaxonDeletionConfigurator(), node.getClassification().getUuid()); |
|
215 |
|
|
216 |
/*} catch (DataChangeNoRollbackException e) { |
|
217 |
e.printStackTrace(); |
|
218 |
}*/ |
|
219 |
try { |
|
220 |
appCtr.commitTransaction(tx); |
|
221 |
} catch (Exception e) { |
|
222 |
// TODO Auto-generated catch block |
|
223 |
e.printStackTrace(); |
|
224 |
} |
|
225 |
TaxonNode node2 = service.find(60554); |
|
226 |
|
|
227 |
|
|
228 |
} |
|
229 |
|
|
230 |
// private void insertSomeData(CdmApplicationController appCtr) { |
|
231 |
// Classification cl = Classification.NewInstance("myClass"); |
|
232 |
// TaxonNode node1 = cl.addChildTaxon(Taxon.NewInstance(TaxonNameFactory.NewBotanicalInstance(null), null), null, null); |
|
233 |
// appCtr.getClassificationService().save(cl); |
|
234 |
// |
|
235 |
// Taxon t2 = Taxon.NewInstance(null, null); |
|
236 |
// t2.setTitleCache("Taxon2", true); |
|
237 |
// TaxonNode node2 = node1.addChildTaxon(t2, null, null); |
|
238 |
// |
|
239 |
// Taxon t3 = Taxon.NewInstance(null, null); |
|
240 |
// t3.setTitleCache("Taxon3", true); |
|
241 |
// TaxonNode node3 = node1.addChildTaxon(t3, 0, null, null); |
|
242 |
// |
|
243 |
// appCtr.getTaxonNodeService().saveOrUpdate(node1); |
|
244 |
// |
|
245 |
// cl.addChildNode(node3, 0, null, null); |
|
246 |
// appCtr.getTaxonNodeService().saveOrUpdate(node3); |
|
247 |
// appCtr.getClassificationService().saveOrUpdate(cl); |
|
248 |
// |
|
249 |
// TermTree<Feature> ft1 = TermTree.NewInstance(); |
|
250 |
// FeatureNode fn1 = TermNode.NewInstance((Feature)null); |
|
251 |
// ft1.getRoot().addChild(fn1); |
|
252 |
// appCtr.getFeatureNodeService().save(fn1); |
|
253 |
// |
|
254 |
// TermNode fn2 = TermNode.NewInstance((Feature)null); |
|
255 |
// fn1.addChild(fn2); |
|
256 |
// |
|
257 |
// TermNode fn3 = TermNode.NewInstance((Feature)null); |
|
258 |
// fn1.addChild(fn2, 0); |
|
259 |
// |
|
260 |
// appCtr.getFeatureNodeService().saveOrUpdate(fn1); |
|
261 |
// |
|
262 |
// ft1.getRoot().addChild(fn3, 0); |
|
263 |
// appCtr.getFeatureNodeService().saveOrUpdate(fn3); |
|
264 |
// appCtr.getFeatureTreeService().saveOrUpdate(ft1); |
|
265 |
// } |
|
266 |
|
|
267 |
private void testDatabaseChange() throws DataSourceNotFoundException{ |
|
268 |
CdmApplicationController appCtr; |
|
269 |
appCtr = CdmApplicationController.NewInstance(); |
|
270 |
|
|
271 |
// DatabaseTypeEnum dbType = DatabaseTypeEnum.MySQL; |
|
272 |
// String server = "192.168.2.10"; |
|
273 |
// String database = "cdm_test_andreas"; |
|
274 |
// String user = "edit"; |
|
275 |
// String pwd = "wp5"; |
|
276 |
// |
|
277 |
DatabaseTypeEnum dbType = DatabaseTypeEnum.SqlServer2005; |
|
278 |
String server = "LAPTOPHP"; |
|
279 |
String database = "cdmTest"; |
|
280 |
String username = "edit"; |
|
281 |
String password = ""; |
|
282 |
|
|
283 |
ICdmDataSource dataSource = CdmDataSource.NewInstance(DatabaseTypeEnum.SqlServer2005, "LAPTOPHP", "cdmTest", DatabaseTypeEnum.SqlServer2005.getDefaultPort(), "edit", ""); |
|
284 |
|
|
285 |
appCtr.getDatabaseService().saveDataSource("testSqlServer", dataSource); |
|
286 |
try { |
|
287 |
appCtr.getDatabaseService().connectToDatabase(dbType, server, database, username, password); |
|
288 |
} catch (TermNotFoundException e) { |
|
289 |
// TODO Auto-generated catch block |
|
290 |
e.printStackTrace(); |
|
291 |
} |
|
292 |
|
|
293 |
appCtr.close(); |
|
294 |
} |
|
295 |
|
|
296 |
private void testSqlServer2005(){ |
|
297 |
DatabaseTypeEnum databaseTypeEnum = DatabaseTypeEnum.SqlServer2005; |
|
298 |
String server = "LAPTOPHP"; |
|
299 |
String database = "cdmTest"; |
|
300 |
String username = "edit"; |
|
301 |
String password = ""; |
|
302 |
|
|
303 |
ICdmDataSource dataSource = CdmDataSource.NewInstance(databaseTypeEnum, server, database, databaseTypeEnum.getDefaultPort(), username, password); |
|
304 |
|
|
305 |
CdmPersistentDataSource ds = CdmPersistentDataSource.save("testSqlServer", dataSource); |
|
306 |
|
|
307 |
CdmApplicationController appCtr = CdmApplicationController.NewInstance(ds); |
|
308 |
Person agent = Person.NewInstance(); |
|
309 |
appCtr.getAgentService().save(agent); |
|
310 |
TaxonName tn = TaxonNameFactory.NewBotanicalInstance(null); |
|
311 |
appCtr.getNameService().save(tn); |
|
312 |
appCtr.close(); |
|
313 |
|
|
314 |
} |
|
315 |
|
|
316 |
private void testLocalHsql(){ |
|
317 |
CdmApplicationController appCtr = null; |
|
318 |
try { |
|
319 |
CdmPersistentDataSource ds = CdmPersistentDataSource.NewLocalHsqlInstance(); |
|
320 |
appCtr = CdmApplicationController.NewInstance(ds); |
|
321 |
List<?> l = appCtr.getNameService().list(null,5, 1,null,null); |
|
322 |
System.out.println(l); |
|
323 |
//Agent agent = new Agent(); |
|
324 |
//appCtr.getAgentService().saveAgent(agent); |
|
325 |
appCtr.close(); |
|
326 |
} catch (RuntimeException e) { |
|
327 |
logger.error("Runtime Exception"); |
|
328 |
e.printStackTrace(); |
|
329 |
if (appCtr != null){ |
|
330 |
appCtr.close(); |
|
331 |
} |
|
332 |
|
|
333 |
} catch (DataSourceNotFoundException e) { |
|
334 |
logger.error("Runtime Exception"); |
|
335 |
e.printStackTrace(); |
|
336 |
} |
|
337 |
} |
|
338 |
|
|
339 |
private void testLocalH2(){ |
|
340 |
|
|
341 |
DbSchemaValidation validation = DbSchemaValidation.CREATE; |
|
342 |
ICdmDataSource ds = |
|
343 |
CdmDataSource.NewH2EmbeddedInstance("cdm", "sa", "", null); |
|
344 |
// ds = |
|
345 |
// CdmPersistentDataSource.NewInstance("localH2"); |
|
346 |
CdmApplicationController appCtr = CdmApplicationController.NewInstance(ds, validation); |
|
347 |
|
|
348 |
boolean exists = appCtr.getUserService().userExists("admin"); |
|
349 |
try { |
|
350 |
IBotanicalName name = TaxonNameFactory.NewBotanicalInstance(null); |
|
351 |
String nameCache = "testName"; |
|
352 |
name.setNameCache(nameCache); |
|
353 |
name.setTitleCache(nameCache, true); |
|
354 |
Reference ref = ReferenceFactory.newGeneric(); |
|
355 |
ref.setTitleCache("mySec", true); |
|
356 |
Taxon taxon = Taxon.NewInstance(name, ref); |
|
357 |
TaxonDescription description = TaxonDescription.NewInstance(); |
|
358 |
taxon.addDescription(description); |
|
359 |
NamedArea area1 = appCtr.getTermService().getAreaByTdwgAbbreviation("GER"); |
|
360 |
Distribution distribution = Distribution.NewInstance(area1, PresenceAbsenceTerm.PRESENT()); |
|
361 |
description.addElement(distribution); |
|
362 |
|
|
363 |
List<Distribution> distrList = new ArrayList<Distribution>(); |
|
364 |
distrList.add(distribution); |
|
365 |
List<NamedArea> areaList = new ArrayList<NamedArea>(); |
|
366 |
areaList.add(area1); |
|
367 |
|
|
368 |
// distribution.getInDescription().get |
|
369 |
appCtr.getTaxonService().save(taxon); |
|
370 |
|
|
371 |
System.out.println(taxon.getDescriptions().size()); |
|
372 |
|
|
373 |
TransactionStatus txStatus = appCtr.startTransaction(); |
|
374 |
|
|
375 |
Session session = appCtr.getSessionFactory().getCurrentSession(); |
|
376 |
|
|
377 |
//String hqlQuery = "from DescriptionBase d join d.elements as e " |
|
378 |
// String hqlQuery = "from Taxon t join t.descriptions as d "+ |
|
379 |
// " inner join d.elements e on e member of d " |
|
380 |
// + |
|
381 |
// "";//" where e.area = :namedArea " ; |
|
382 |
String hqlQuery = "Select t from Distribution e join e.inDescription d join d.taxon t join t.name n "+ |
|
383 |
" WHERE e.area in (:namedArea) AND n.nameCache = :nameCache "; |
|
384 |
Query query = session.createQuery(hqlQuery); |
|
385 |
|
|
386 |
//query.setEntity("namedArea", area1); |
|
387 |
query.setParameter("nameCache", nameCache); |
|
388 |
query.setParameterList("namedArea", areaList); |
|
389 |
List resultList = query.list(); |
|
390 |
//List list = appCtr.getCommonService().getHqlResult(hqlQuery); |
|
391 |
|
|
392 |
for (Object o:resultList){ |
|
393 |
System.out.println(o); |
|
394 |
} |
|
395 |
appCtr.commitTransaction(txStatus); |
|
396 |
|
|
397 |
//System.out.println(l); |
|
398 |
//Agent agent = new Agent(); |
|
399 |
//appCtr.getAgentService().saveAgent(agent); |
|
400 |
appCtr.close(); |
|
401 |
} catch (RuntimeException e) { |
|
402 |
logger.error("Runtime Exception"); |
|
403 |
e.printStackTrace(); |
|
404 |
appCtr.close(); |
|
405 |
|
|
406 |
} |
|
407 |
} |
|
408 |
|
|
409 |
private boolean testWritableResourceDirectory() throws IOException{ |
|
410 |
CdmApplicationUtils.getWritableResourceDir(); |
|
411 |
return true; |
|
412 |
} |
|
413 |
|
|
414 |
private boolean testH2(){ |
|
415 |
// testLocalH2(); |
|
416 |
// if (true)return true; |
|
417 |
|
|
418 |
DbSchemaValidation validation = DbSchemaValidation.CREATE; |
|
419 |
ICdmDataSource ds = |
|
420 |
CdmDataSource.NewH2EmbeddedInstance("cdm", "sa", "", null); |
|
421 |
//CdmDataSource.NewH2EmbeddedInstance("cdm", "sa", ""); |
|
422 |
// ds = |
|
423 |
// CdmPersistentDataSource.NewInstance("localH2"); |
|
424 |
CdmApplicationController appCtr = CdmApplicationController.NewInstance(ds, validation); |
|
425 |
try { |
|
426 |
TaxonName botName1 = TaxonNameFactory.NewBotanicalInstance(Rank.SPECIES()); |
|
427 |
TaxonName botName2 = TaxonNameFactory.NewBotanicalInstance(Rank.SPECIES()); |
|
428 |
IBotanicalName hybridName = TaxonNameFactory.NewBotanicalInstance(Rank.SPECIES()); |
|
429 |
botName1.addRelationshipToName(botName2, NameRelationshipType.ORTHOGRAPHIC_VARIANT(), null, null); |
|
430 |
UUID uuid1 = botName1.getUuid(); |
|
431 |
UUID uuid2 = botName2.getUuid(); |
|
432 |
try { |
|
433 |
Logger loggerTrace = Logger.getLogger("org.hibernate.type"); |
|
434 |
//loggerTrace.setLevel(Level.TRACE); |
|
435 |
System.out.println(logger.getName()); |
|
436 |
|
|
437 |
appCtr.getNameService().save(botName1); |
|
438 |
ResultSet rs = ds.executeQuery("Select count(*) as n FROM NameRelationship"); |
|
439 |
rs.next(); |
|
440 |
int c = rs.getInt("n"); |
|
441 |
System.out.println("Begin :" + c); |
|
442 |
|
|
443 |
botName1.removeRelationToTaxonName(botName2); |
|
444 |
botName1.setSpecificEpithet("DELETED"); |
Also available in: Unified diff
cleanup and renaming some functional test classes