Project

General

Profile

« Previous | Next » 

Revision fb09cec0

Added by Andreas Müller about 1 year ago

make commandline debugging available in cdmlib-remote

View differences:

cdmlib-remote/src/test/java/eu/etaxonomy/cdm/remote/io/application/CdmRemoteApplicationController.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
package eu.etaxonomy.cdm.remote.io.application;
10

  
11
import org.apache.log4j.Logger;
12
import org.springframework.core.io.ClassPathResource;
13
import org.springframework.core.io.Resource;
14

  
15
import eu.etaxonomy.cdm.common.monitor.IProgressMonitor;
16
import eu.etaxonomy.cdm.database.DataSourceNotFoundException;
17
import eu.etaxonomy.cdm.database.DbSchemaValidation;
18
import eu.etaxonomy.cdm.database.ICdmDataSource;
19
import eu.etaxonomy.cdm.io.api.application.CdmIoApplicationController;
20
import eu.etaxonomy.cdm.persistence.hibernate.HibernateConfiguration;
21

  
22
//for now we need this controller only within test therefore it is only in test modul
23
public class CdmRemoteApplicationController extends CdmIoApplicationController {
24

  
25
    @SuppressWarnings("unused")
26
	private static final Logger logger = Logger.getLogger(CdmRemoteApplicationController.class);
27

  
28

  
29
	public static final String DEFAULT_APPLICATION_CONTEXT_RESOURCE = "/eu/etaxonomy/cdm/applicationContext-test.xml";
30

  
31

  
32
	public static CdmRemoteApplicationController NewRemoteInstance() {
33
		return CdmRemoteApplicationController.NewRemoteInstance(null, null);
34
	}
35

  
36
	public static CdmRemoteApplicationController NewRemoteInstance(ICdmDataSource dataSource, DbSchemaValidation dbSchemaValidation) {
37
	    try {
38
            dataSource = dataSource == null? getDefaultDatasource() : dataSource;
39
        } catch (DataSourceNotFoundException e) {
40
            throw new RuntimeException(e);
41
        }
42
	    dbSchemaValidation = dbSchemaValidation == null? defaultDbSchemaValidation : dbSchemaValidation;
43
	    return CdmRemoteApplicationController.NewRemoteInstance(dataSource, dbSchemaValidation, null, false);
44
	}
45

  
46
    public static CdmRemoteApplicationController NewRemoteInstance(ICdmDataSource dataSource, DbSchemaValidation dbSchemaValidation,
47
            HibernateConfiguration hibernateConfig, boolean omitTermLoading) {
48
        return new CdmRemoteApplicationController(getClasspathResource(),dataSource, dbSchemaValidation,
49
                hibernateConfig, omitTermLoading, null);
50
    }
51

  
52
// *************************************** CONSTRUCTOR ***********************************************************/
53

  
54
	protected CdmRemoteApplicationController(Resource applicationContextResource, ICdmDataSource dataSource,
55
	        DbSchemaValidation dbSchemaValidation, HibernateConfiguration hibernateConfig,
56
			boolean omitTermLoading, IProgressMonitor progressMonitor) {
57
		super(applicationContextResource, dataSource, dbSchemaValidation, hibernateConfig,
58
		        omitTermLoading, progressMonitor);
59
	}
60

  
61

  
62
    protected static ClassPathResource getClasspathResource() {
63
        return new ClassPathResource(DEFAULT_APPLICATION_CONTEXT_RESOURCE);
64
    }
65
}
cdmlib-remote/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.Set;
19
import java.util.UUID;
20

  
21
import javax.servlet.http.HttpServletResponse;
22

  
23
import org.apache.log4j.Logger;
24
import org.hibernate.Query;
25
import org.hibernate.Session;
26
import org.springframework.transaction.TransactionStatus;
27

  
28
import eu.etaxonomy.cdm.api.application.CdmApplicationController;
29
import eu.etaxonomy.cdm.api.application.CdmApplicationUtils;
30
import eu.etaxonomy.cdm.api.service.ITaxonNodeService;
31
import eu.etaxonomy.cdm.api.service.ITaxonService;
32
import eu.etaxonomy.cdm.api.service.ITermService;
33
import eu.etaxonomy.cdm.api.service.UpdateResult;
34
import eu.etaxonomy.cdm.api.service.config.TaxonDeletionConfigurator;
35
import eu.etaxonomy.cdm.api.service.description.AggregationMode;
36
import eu.etaxonomy.cdm.api.service.description.DistributionAggregationConfiguration;
37
import eu.etaxonomy.cdm.api.service.description.StructuredDescriptionAggregationConfiguration;
38
import eu.etaxonomy.cdm.api.service.dto.GroupedTaxonDTO;
39
import eu.etaxonomy.cdm.api.util.TaxonRelationshipEdge;
40
import eu.etaxonomy.cdm.common.monitor.DefaultProgressMonitor;
41
import eu.etaxonomy.cdm.config.AccountStore;
42
import eu.etaxonomy.cdm.database.CdmDataSource;
43
import eu.etaxonomy.cdm.database.CdmPersistentDataSource;
44
import eu.etaxonomy.cdm.database.DataSourceNotFoundException;
45
import eu.etaxonomy.cdm.database.DatabaseTypeEnum;
46
import eu.etaxonomy.cdm.database.DbSchemaValidation;
47
import eu.etaxonomy.cdm.database.ICdmDataSource;
48
import eu.etaxonomy.cdm.filter.TaxonNodeFilter;
49
import eu.etaxonomy.cdm.model.agent.Person;
50
import eu.etaxonomy.cdm.model.description.DescriptiveDataSet;
51
import eu.etaxonomy.cdm.model.description.Distribution;
52
import eu.etaxonomy.cdm.model.description.PresenceAbsenceTerm;
53
import eu.etaxonomy.cdm.model.description.TaxonDescription;
54
import eu.etaxonomy.cdm.model.location.NamedArea;
55
import eu.etaxonomy.cdm.model.name.HybridRelationshipType;
56
import eu.etaxonomy.cdm.model.name.IBotanicalName;
57
import eu.etaxonomy.cdm.model.name.NameRelationshipType;
58
import eu.etaxonomy.cdm.model.name.Rank;
59
import eu.etaxonomy.cdm.model.name.TaxonName;
60
import eu.etaxonomy.cdm.model.name.TaxonNameFactory;
61
import eu.etaxonomy.cdm.model.reference.Reference;
62
import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
63
import eu.etaxonomy.cdm.model.taxon.Classification;
64
import eu.etaxonomy.cdm.model.taxon.Taxon;
65
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
66
import eu.etaxonomy.cdm.model.term.DefinedTermBase;
67
import eu.etaxonomy.cdm.model.term.TermTree;
68
import eu.etaxonomy.cdm.model.term.init.TermNotFoundException;
69
import eu.etaxonomy.cdm.persistence.dao.initializer.EntityInitStrategy;
70
import eu.etaxonomy.cdm.remote.controller.MediaPortalController;
71
import eu.etaxonomy.cdm.remote.controller.TaxonPortalController;
72
import eu.etaxonomy.cdm.remote.controller.TaxonPortalController.EntityMediaContext;
73
import eu.etaxonomy.cdm.remote.controller.util.ControllerUtils;
74
import eu.etaxonomy.cdm.remote.editor.UuidList;
75
import eu.etaxonomy.cdm.remote.io.application.CdmRemoteApplicationController;
76

  
77
/**
78
 * @author a.mueller
79
 * @since 08.11.2021
80
 */
81
public class TestScript {
82

  
83
	private static final Logger logger = Logger.getLogger(TestScript.class);
84

  
85

  
86
	private void testNewConfigControler(){
87

  
88
		DbSchemaValidation schema = DbSchemaValidation.VALIDATE;
89

  
90
		String server;
91
		String database;
92
		String username;
93
		ICdmDataSource dataSource;
94

  
95
//      List<CdmPersistentDataSource> lsDataSources = CdmPersistentDataSource.getAllDataSources();
96
//     System.out.println(lsDataSources);
97
//     dataSource = lsDataSources.get(1);
98

  
99
//		DatabaseTypeEnum dbType = DatabaseTypeEnum.MySQL;
100

  
101
//		server = "localhost";
102
//		database = "cdm_bupleurum";
103
////		database = "cdm_production_edaphobase";
104
//		username = "edit";
105
//		dataSource = CdmDataSource.NewMySqlInstance(server, database, username, AccountStore.readOrStorePassword(server, database, username, null));
106

  
107
		server = "160.45.63.171";
108
		database = "cdm_production_campanulaceae";
109
		username = "edit";
110
		dataSource = CdmDataSource.NewMySqlInstance(server, database, username, AccountStore.readOrStorePassword(server, database, username, null));
111

  
112

  
113
//		server = "test.e-taxonomy.eu";
114
//		database = "cdm_rem_conf_am";
115
//		username = "edit";
116
//		dataSource = CdmDataSource.NewMySqlInstance(server, database, username, AccountStore.readOrStorePassword(server, database, username, null));
117

  
118
//		String server = "localhost";
119
//		String database = "testCDM";
120
//		String username = "postgres";
121
//		dataSource = CdmDataSource.NewInstance(DatabaseTypeEnum.PostgreSQL, server, database, DatabaseTypeEnum.PostgreSQL.getDefaultPort(), username, AccountStore.readOrStorePassword(server, database, username, null));
122

  
123

  
124
//		//SQLServer
125
//		server = "BGBM-PESISQL";
126
//		database = "cdm36";
127
//		int port = 1433;
128
//		username = "cdmupdater";
129
//		dataSource = CdmDataSource.NewSqlServer2012Instance(server, database, port, username, AccountStore.readOrStorePassword(server, database, username, null));
130
//
131
//		//H2
132
//        String path = "C:\\Users\\a.mueller\\.cdmLibrary\\writableResources\\h2\\LocalH2";
133
////		String path = "C:\\Users\\pesiimport\\.cdmLibrary\\writableResources\\h2\\LocalH2";
134
////      String path = "C:\\Users\\a.mueller\\eclipse\\svn\\cdmlib-trunk\\cdmlib-remote-webapp\\src\\test\\resources\\h2";
135
//		username = "sa";
136
//    	dataSource = CdmDataSource.NewH2EmbeddedInstance("cdm", username, "", path);
137

  
138
//    	dataSource = CdmDataSource.NewH2EmbeddedInstance(database, username, "sa");
139

  
140

  
141
//       server = "160.45.63.201";
142
//       database = "cdm_integration_cichorieae";
143
//       username = "edit";
144
//       dataSource = CdmDataSource.NewMySqlInstance(server, database, username, AccountStore.readOrStorePassword(server, database, username, null));
145

  
146
		CdmApplicationController appCtr = CdmRemoteApplicationController.NewRemoteInstance(dataSource, schema);
147

  
148
		try {
149
            doTemporary(appCtr);
150
        } catch (IOException e) {
151
            // TODO Auto-generated catch block
152
            e.printStackTrace();
153
        }
154

  
155
//		List<UuidAndTitleCache<TaxonBase>> list = appCtr.getTaxonService().getUuidAndTitleCache(null, 10, "Abies alba%");
156
//		System.out.println(list);
157
//		appCtr.getOccurrenceService().findRootUnitDTOs(UUID.fromString("2debf5ee-cb57-40bc-af89-173d1d17cefe"));
158
//		aggregateDDS(appCtr);
159
//		aggregateDistribution(appCtr);
160

  
161
		appCtr.close();
162
		System.exit(0);
163
	}
164

  
165
    private void doTemporary(CdmApplicationController appCtr) throws IOException {
166

  
167
        UUID taxonUUID = UUID.fromString("cdcacbda-11c0-4cb8-a2e0-8d7abc5ae756");
168
        boolean includeTaxonomicChildren = true;
169
        UuidList relationshipUuids = new UuidList();
170
        UuidList relationshipInversUuids = new UuidList();
171
        boolean includeTaxonDescriptions = true;
172
        boolean includeOccurrences = true;
173
        boolean includeTaxonNameDescriptions = true;
174
        HttpServletResponse response = null;
175
        TaxonPortalController taxonPortalController = (TaxonPortalController) appCtr.getBean("taxonPortalController");
176
        ITermService termService = appCtr.getTermService();
177

  
178
        EntityInitStrategy taxonInitStrategy = includeTaxonomicChildren? TaxonPortalController.TAXON_WITH_CHILDNODES_INIT_STRATEGY : TaxonPortalController.TAXON_INIT_STRATEGY;
179
        EntityMediaContext<Taxon> entityMediaContext = taxonPortalController.loadMediaForTaxonAndRelated(taxonUUID,
180
                relationshipUuids, relationshipInversUuids,
181
                includeTaxonDescriptions, includeOccurrences, includeTaxonNameDescriptions,
182
                response, taxonInitStrategy.getPropertyPaths(),
183
                MediaPortalController.MEDIA_INIT_STRATEGY.getPropertyPaths());
184

  
185
        if(includeTaxonomicChildren){
186
            Set<TaxonRelationshipEdge> includeRelationships = ControllerUtils.loadIncludeRelationships(relationshipUuids, relationshipInversUuids, termService);
187
            entityMediaContext.setMedia(
188
                    taxonPortalController.addTaxonomicChildrenMedia(includeTaxonDescriptions, includeOccurrences, includeTaxonNameDescriptions, entityMediaContext.getEntity(), includeRelationships, entityMediaContext.getMedia())
189
                            );
190
        }
191
    }
192

  
193
    private void aggregateDistribution(CdmApplicationController app){
194

  
195
        System.out.println("agg distr");
196
        DefaultProgressMonitor monitor = DefaultProgressMonitor.NewInstance();
197

  
198
        UUID descriptaceaeUuid = UUID.fromString("5a37c47c-347c-49f8-88ba-2720b194dfb9");
199

  
200
        TaxonNodeFilter filter = TaxonNodeFilter.NewSubtreeInstance(descriptaceaeUuid);
201
        filter.setIncludeUnpublished(true);
202
        List<AggregationMode> aggregationModes = AggregationMode.byToParent();
203
        TermTree<PresenceAbsenceTerm> statusOrder = null;
204
        List<UUID> superAreas = new ArrayList<>();
205
        DistributionAggregationConfiguration config = DistributionAggregationConfiguration.NewInstance(aggregationModes, superAreas, filter, statusOrder, monitor);
206
        config.setAdaptBatchSize(false);
207
        UpdateResult result = config.getTaskInstance().invoke(config, app);
208
        System.out.println(result);
209
    }
210

  
211
	private void aggregateDDS(CdmApplicationController app){
212

  
213
	    System.out.println("find dds");
214
	    DescriptiveDataSet dds = app.getDescriptiveDataSetService().find(21);
215
	    UUID facciniaSubtreeUuid = UUID.fromString("cf0bc346-a203-4ad7-ad25-477098361db6");
216
	    UUID arenarioAdamssubtreeUuid = UUID.fromString("0215e668-0a65-42cd-85e0-d97ce78e758b");
217

  
218
	    TaxonNodeFilter filter = TaxonNodeFilter.NewSubtreeInstance(arenarioAdamssubtreeUuid);
219
	    filter.setIncludeUnpublished(true);
220

  
221
	    DefaultProgressMonitor monitor = DefaultProgressMonitor.NewInstance();
222
	    StructuredDescriptionAggregationConfiguration config = StructuredDescriptionAggregationConfiguration.NewInstance(filter, monitor);
223
        config.setDatasetUuid(dds.getUuid());
224
        config.setAggregationMode(AggregationMode.byWithinTaxonAndToParent());
225
        config.setAdaptBatchSize(false);
226
        UpdateResult result = config.getTaskInstance().invoke(config, app);
227
        System.out.println(result);
228

  
229
//	    app.getLongRunningTasksService().invoke(config);
230
	}
231

  
232
    private void listClassification(CdmApplicationController appCtr, List<String> propertyPaths) {
233
        try {
234
            List<Classification> list = appCtr.getClassificationService().list(null, null, null, null, propertyPaths);
235
        } catch (Exception e) {
236
            e.printStackTrace();
237
            logger.warn(e.getMessage());
238
        }
239
    }
240

  
241
    private void testGroupedTaxa(CdmApplicationController appCtr) {
242
        UUID classificationUuid = UUID.fromString("91231ebf-1c7a-47b9-a56c-b45b33137244");
243
		UUID taxonUuid1 = UUID.fromString("3bae1c86-1235-4e2e-be63-c7f8c4410527");
244
		UUID taxonUuid2 = UUID.fromString("235d3872-defe-4b92-bf2f-75a7c91510de");
245
		List<UUID> taxonUuids = Arrays.asList(new UUID[]{taxonUuid1, taxonUuid2});
246
		Rank maxRank = DefinedTermBase.getTermByClassAndUUID(Rank.class, UUID.fromString("af5f2481-3192-403f-ae65-7c957a0f02b6"));
247
		Rank minRank = DefinedTermBase.getTermByClassAndUUID(Rank.class, UUID.fromString("78786e16-2a70-48af-a608-494023b91904"));
248
        List<GroupedTaxonDTO> groupedTaxa = appCtr.getClassificationService().groupTaxaByHigherTaxon(taxonUuids, classificationUuid, minRank, maxRank);
249
        System.out.println(groupedTaxa);
250
    }
251

  
252
    private void addPerson(CdmApplicationController appCtr) {
253
        TransactionStatus tx = appCtr.startTransaction();
254
		appCtr.getAgentService().save(Person.NewInstance());
255
		appCtr.commitTransaction(tx);
256
    }
257

  
258
	private void deleteHighLevelNode(CdmApplicationController appCtr) {
259
		TransactionStatus tx = appCtr.startTransaction();
260
		ITaxonNodeService service = appCtr.getTaxonNodeService();
261
		TaxonNode node = service.find(60554);
262
//		service.delete(node);
263
		ITaxonService taxonService = appCtr.getTaxonService();
264
		Taxon taxon = node.getTaxon();
265
		//try {
266
			taxonService.deleteTaxon(taxon.getUuid(), new TaxonDeletionConfigurator(), node.getClassification().getUuid());
267

  
268
		/*} catch (DataChangeNoRollbackException e) {
269
			e.printStackTrace();
270
		}*/
271
		try {
272
			appCtr.commitTransaction(tx);
273
		} catch (Exception e) {
274
			// TODO Auto-generated catch block
275
			e.printStackTrace();
276
		}
277
		TaxonNode node2 = service.find(60554);
278

  
279

  
280
	}
281

  
282
//	private void insertSomeData(CdmApplicationController appCtr) {
283
//		Classification cl = Classification.NewInstance("myClass");
284
//		TaxonNode node1 = cl.addChildTaxon(Taxon.NewInstance(TaxonNameFactory.NewBotanicalInstance(null), null), null, null);
285
//		appCtr.getClassificationService().save(cl);
286
//
287
//		Taxon t2 = Taxon.NewInstance(null, null);
288
//		t2.setTitleCache("Taxon2", true);
289
//		TaxonNode node2 = node1.addChildTaxon(t2, null, null);
290
//
291
//		Taxon t3 = Taxon.NewInstance(null, null);
292
//		t3.setTitleCache("Taxon3", true);
293
//		TaxonNode node3 = node1.addChildTaxon(t3, 0, null, null);
294
//
295
//		appCtr.getTaxonNodeService().saveOrUpdate(node1);
296
//
297
//		cl.addChildNode(node3, 0, null, null);
298
//		appCtr.getTaxonNodeService().saveOrUpdate(node3);
299
//		appCtr.getClassificationService().saveOrUpdate(cl);
300
//
301
//		TermTree<Feature> ft1 = TermTree.NewInstance();
302
//		FeatureNode fn1 = TermNode.NewInstance((Feature)null);
303
//		ft1.getRoot().addChild(fn1);
304
//		appCtr.getFeatureNodeService().save(fn1);
305
//
306
//		TermNode fn2 = TermNode.NewInstance((Feature)null);
307
//		fn1.addChild(fn2);
308
//
309
//		TermNode fn3 = TermNode.NewInstance((Feature)null);
310
//		fn1.addChild(fn2, 0);
311
//
312
//		appCtr.getFeatureNodeService().saveOrUpdate(fn1);
313
//
314
//		ft1.getRoot().addChild(fn3, 0);
315
//		appCtr.getFeatureNodeService().saveOrUpdate(fn3);
316
//		appCtr.getFeatureTreeService().saveOrUpdate(ft1);
317
//	}
318

  
319
	private void testDatabaseChange() throws DataSourceNotFoundException{
320
		CdmApplicationController appCtr;
321
		appCtr = CdmApplicationController.NewInstance();
322

  
323
//		DatabaseTypeEnum dbType = DatabaseTypeEnum.MySQL;
324
//		String server = "192.168.2.10";
325
//		String database = "cdm_test_andreas";
326
//		String user = "edit";
327
//		String pwd = "wp5";
328
//
329
		DatabaseTypeEnum dbType = DatabaseTypeEnum.SqlServer2005;
330
		String server = "LAPTOPHP";
331
		String database = "cdmTest";
332
		String username = "edit";
333
		String password = "";
334

  
335
		ICdmDataSource dataSource = CdmDataSource.NewInstance(DatabaseTypeEnum.SqlServer2005, "LAPTOPHP", "cdmTest", DatabaseTypeEnum.SqlServer2005.getDefaultPort(), "edit", "");
336

  
337
		appCtr.getDatabaseService().saveDataSource("testSqlServer", dataSource);
338
		try {
339
			appCtr.getDatabaseService().connectToDatabase(dbType, server, database, username, password);
340
		} catch (TermNotFoundException e) {
341
			// TODO Auto-generated catch block
342
			e.printStackTrace();
343
		}
344

  
345
		appCtr.close();
346
	}
347

  
348
	private void testSqlServer2005(){
349
		DatabaseTypeEnum databaseTypeEnum = DatabaseTypeEnum.SqlServer2005;
350
		String server = "LAPTOPHP";
351
		String database = "cdmTest";
352
		String username = "edit";
353
		String password = "";
354

  
355
		ICdmDataSource dataSource = CdmDataSource.NewInstance(databaseTypeEnum, server, database, databaseTypeEnum.getDefaultPort(), username, password);
356

  
357
		CdmPersistentDataSource ds = CdmPersistentDataSource.save("testSqlServer", dataSource);
358

  
359
		CdmApplicationController appCtr = CdmApplicationController.NewInstance(ds);
360
		Person agent = Person.NewInstance();
361
		appCtr.getAgentService().save(agent);
362
		TaxonName tn = TaxonNameFactory.NewBotanicalInstance(null);
363
		appCtr.getNameService().save(tn);
364
		appCtr.close();
365

  
366
	}
367

  
368
	private void testLocalHsql(){
369
		CdmApplicationController appCtr = null;
370
		try {
371
			CdmPersistentDataSource ds = CdmPersistentDataSource.NewLocalHsqlInstance();
372
			appCtr = CdmApplicationController.NewInstance(ds);
373
			List<?> l = appCtr.getNameService().list(null,5, 1,null,null);
374
			System.out.println(l);
375
			//Agent agent = new Agent();
376
			//appCtr.getAgentService().saveAgent(agent);
377
			appCtr.close();
378
		} catch (RuntimeException e) {
379
			logger.error("Runtime Exception");
380
			e.printStackTrace();
381
			if (appCtr != null){
382
			    appCtr.close();
383
			}
384

  
385
		} catch (DataSourceNotFoundException e) {
386
			logger.error("Runtime Exception");
387
			e.printStackTrace();
388
		}
389
	}
390

  
391
	private void testLocalH2(){
392

  
393
		DbSchemaValidation validation = DbSchemaValidation.CREATE;
394
		ICdmDataSource ds =
395
			CdmDataSource.NewH2EmbeddedInstance("cdm", "sa", "", null);
396
//			ds =
397
//				 CdmPersistentDataSource.NewInstance("localH2");
398
		CdmApplicationController appCtr = CdmApplicationController.NewInstance(ds, validation);
399

  
400
		boolean exists = appCtr.getUserService().userExists("admin");
401
		try {
402
			IBotanicalName name = TaxonNameFactory.NewBotanicalInstance(null);
403
			String nameCache = "testName";
404
			name.setNameCache(nameCache);
405
			name.setTitleCache(nameCache, true);
406
			Reference ref = ReferenceFactory.newGeneric();
407
			ref.setTitleCache("mySec", true);
408
			Taxon taxon = Taxon.NewInstance(name, ref);
409
			TaxonDescription description = TaxonDescription.NewInstance();
410
			taxon.addDescription(description);
411
			NamedArea area1 = appCtr.getTermService().getAreaByTdwgAbbreviation("GER");
412
			Distribution distribution = Distribution.NewInstance(area1, PresenceAbsenceTerm.PRESENT());
413
			description.addElement(distribution);
414

  
415
			List<Distribution> distrList = new ArrayList<Distribution>();
416
			distrList.add(distribution);
417
			List<NamedArea> areaList = new ArrayList<NamedArea>();
418
			areaList.add(area1);
419

  
420
		//	distribution.getInDescription().get
421
			appCtr.getTaxonService().save(taxon);
422

  
423
			System.out.println(taxon.getDescriptions().size());
424

  
425
			TransactionStatus txStatus = appCtr.startTransaction();
426

  
427
			Session session = appCtr.getSessionFactory().getCurrentSession();
428

  
429
			//String hqlQuery = "from DescriptionBase d join d.elements  as e "
430
//				String hqlQuery = "from Taxon t join t.descriptions  as d "+
431
//				 " inner join d.elements e on e member of d "
432
//				+
433
//				"";//" where e.area = :namedArea " ;
434
			String hqlQuery = "Select t from Distribution e join e.inDescription d join d.taxon t join t.name n "+
435
				" WHERE e.area in (:namedArea) AND n.nameCache = :nameCache ";
436
			Query query = session.createQuery(hqlQuery);
437

  
438
			//query.setEntity("namedArea", area1);
439
			query.setParameter("nameCache", nameCache);
440
			query.setParameterList("namedArea", areaList);
441
			List resultList = query.list();
442
			//List list = appCtr.getCommonService().getHqlResult(hqlQuery);
443

  
444
			for (Object o:resultList){
445
				System.out.println(o);
446
			}
447
			appCtr.commitTransaction(txStatus);
448

  
449
			//System.out.println(l);
450
			//Agent agent = new Agent();
451
			//appCtr.getAgentService().saveAgent(agent);
452
			appCtr.close();
453
		} catch (RuntimeException e) {
454
			logger.error("Runtime Exception");
455
			e.printStackTrace();
456
			appCtr.close();
457

  
458
		}
459
	}
460

  
461
	private boolean testWritableResourceDirectory() throws IOException{
462
		CdmApplicationUtils.getWritableResourceDir();
463
		return true;
464
	}
465

  
466
	private boolean testH2(){
467
//		testLocalH2();
468
//		if (true)return true;
469

  
470
		DbSchemaValidation validation = DbSchemaValidation.CREATE;
471
		ICdmDataSource ds =
472
			CdmDataSource.NewH2EmbeddedInstance("cdm", "sa", "", null);
473
			//CdmDataSource.NewH2EmbeddedInstance("cdm", "sa", "");
474
//		ds =
475
//			 CdmPersistentDataSource.NewInstance("localH2");
476
		CdmApplicationController appCtr = CdmApplicationController.NewInstance(ds, validation);
477
		try {
478
		    TaxonName botName1 = TaxonNameFactory.NewBotanicalInstance(Rank.SPECIES());
479
			TaxonName botName2 = TaxonNameFactory.NewBotanicalInstance(Rank.SPECIES());
480
			IBotanicalName hybridName = TaxonNameFactory.NewBotanicalInstance(Rank.SPECIES());
481
			botName1.addRelationshipToName(botName2, NameRelationshipType.ORTHOGRAPHIC_VARIANT(), null, null);
482
			UUID uuid1 = botName1.getUuid();
483
			UUID uuid2 = botName2.getUuid();
484
			try {
485
				Logger loggerTrace = Logger.getLogger("org.hibernate.type");
486
				//loggerTrace.setLevel(Level.TRACE);
487
				System.out.println(logger.getName());
488

  
489
				appCtr.getNameService().save(botName1);
490
				ResultSet rs = ds.executeQuery("Select count(*) as n FROM NameRelationship");
491
				rs.next();
492
				int c = rs.getInt("n");
493
				System.out.println("Begin :" + c);
494

  
495
				botName1.removeRelationToTaxonName(botName2);
496
				botName1.setSpecificEpithet("DELETED");
497
				botName2.addHybridParent(hybridName, HybridRelationshipType.FIRST_PARENT(), null);
498

  
499
				TransactionStatus tx = appCtr.startTransaction();
500
				appCtr.getNameService().saveOrUpdate(botName2);
501
				rs = ds.executeQuery("Select count(*) as n FROM NameRelationship");
502
				rs.next();
503
				c = rs.getInt("n");
504
				System.out.println("End: " + c);
505

  
506
				appCtr.commitTransaction(tx);
507

  
508
				appCtr.getNameService().saveOrUpdate(botName1);
509

  
510
				rs = ds.executeQuery("Select count(*) as n FROM NameRelationship");
511
				rs.next();
512
				c = rs.getInt("n");
513
				System.out.println("End: " + c);
514

  
515
			} catch (SQLException e) {
516
				// TODO Auto-generated catch block
517
				e.printStackTrace();
518
			}
519

  
520

  
521
			//Agent agent = new Agent();
522
			//appCtr.getAgentService().saveAgent(agent);
523
			appCtr.close();
524
			return true;
525
		} catch (RuntimeException e) {
526
			logger.error("Runtime Exception");
527
			e.printStackTrace();
528
			appCtr.close();
529

  
530
		}
531
		return false;
532
	}
533

  
534
	private void test(){
535
		System.out.println("Start Datasource");
536
		testNewConfigControler();
537
    	//testDatabaseChange();
538

  
539
		//testSqlServer();
540

  
541
		//CdmUtils.findLibrary(au.com.bytecode.opencsv.CSVReader.class);
542
		//testPostgreServer();
543
		//testLocalHsql();
544
		//testLocalH2();
545
		//testWritableResourceDirectory();
546
//		testH2();
547
		System.out.println("\nEnd Datasource");
548
	}
549

  
550
	public static void  main(String[] args) {
551
	    TestScript cc = new TestScript();
552
    	cc.test();
553
	}
554

  
555
}
cdmlib-remote/src/test/resources/eu/etaxonomy/cdm/applicationRemoteContext.xml
1
<?xml version="1.0" encoding="UTF-8"?>
2
<beans xmlns="http://www.springframework.org/schema/beans"
3
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4
	xmlns:context="http://www.springframework.org/schema/context"
5
	xmlns:tx="http://www.springframework.org/schema/tx"
6
	xsi:schemaLocation="http://www.springframework.org/schema/beans 
7
    http://www.springframework.org/schema/beans/spring-beans-4.3.xsd
8
    http://www.springframework.org/schema/context
9
    http://www.springframework.org/schema/context/spring-context-4.3.xsd
10
    http://www.springframework.org/schema/tx 
11
    http://www.springframework.org/schema/tx/spring-tx-4.3.xsd">
12

  
13
<!-- Until now this is mostly a quick and dirty copy of cdmlib-remote-webapp applicationContext.xml to 
14
   make debugging from commandline possible in cdmlib-remote  -->
15

  
16
  <!-- 
17
    NOTE: 
18
    For a detailed overview on the spring MVC and application context configuration and 
19
    bootstrapping of this web application see: 
20
    http://dev.e-taxonomy.eu/redmine/projects/edit/wiki/cdmlib-remote-webappConfigurationAndBootstrapping
21
  -->
22
  
23
  <context:annotation-config />
24

  
25
  <!-- include default application context and customization -->
26
  <import resource="classpath:/eu/etaxonomy/cdm/defaultApplicationContext.xml" />
27
  <bean id="persistentTermInitializer" class="eu.etaxonomy.cdm.database.PersistentTermInitializer">
28
    <property name="omit" value="false" />
29
  </bean>
30
  <context:component-scan base-package="eu/etaxonomy/cdm/ext" />
31

  
32
  <import resource="classpath:/eu/etaxonomy/cdm/remote.xml"/>
33
  <context:component-scan base-package="eu/etaxonomy/cdm/io"/>
34

  
35
  <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
36
    <property name="properties">
37
      <props>
38
        <prop key="eu.etaxonomy.cdm.base.path">${user.home}/.cdmLibrary/</prop>
39
        <prop key="eu.etaxonomy.cdm.search.index.path">${user.home}/.cdmLibrary/index/</prop>
40
      </props>
41
    </property>
42
  </bean>
43

  
44
  <!-- enable the configuration of transactional behavior based on annotations -->
45
  <tx:annotation-driven transaction-manager="transactionManager" />
46

  
47
  <!-- import additional beans into the root context -->
48
<!--   <import resource="applicationContext.views.xml" /> -->
49

  
50
  <!-- import configuration of the datasource bean -->
51
<!--   <import resource="datasources/configurable.xml" /> -->
52
  
53
  <!-- bootstrap the Web Configuration -->
54
  <bean class="eu.etaxonomy.cdm.remote.config.MultiWebSecurityConfiguration" />
55
  
56
<!--   <bean class="eu.etaxonomy.cdm.opt.config.LoggingConfigurer" /> -->
57
  
58
<!--   <bean class="eu.etaxonomy.cdm.opt.config.EhCacheDiskStoreConfiguration" /> -->
59

  
60
  <!-- OAI-PMH TODO externalize? -->
61
  <bean name="taxonOaiPmhController"
62
    class="eu.etaxonomy.cdm.remote.controller.oaipmh.TaxonOaiPmhController">
63
    <property name="cachingModel" ref="taxonOaiPmhCacheMapping" />
64
  </bean>
65

  
66
  <bean name="taxonOaiPmhCacheMapping"
67
    class="org.springmodules.cache.provider.ehcache.EhCacheCachingModel">
68
    <property name="cacheName"
69
      value="eu.etaxonomy.cdm.remote.controller.TaxonOaiPmhController.resumptionToken" />
70
  </bean>
71

  
72
  <bean id="serializableFactory" class="org.springmodules.cache.serializable.XStreamSerializableFactory" />
73

  
74
  <bean id="cacheProviderFacade" class="org.springmodules.cache.provider.ehcache.EhCacheFacade">
75
    <!-- 
76
        the cacheManager is provided by the eu.etaxonomy.cdm.api.config.EhCacheConfiguration
77
        in cdmlib-services
78
     -->
79
    <property name="cacheManager" ref="cacheManager" />
80
    <property name="serializableFactory" ref="serializableFactory" />
81
  </bean>
82
  
83
  
84

  
85
<!--     <context:property-override location="classpath:eu/etaxonomy/cdm/override.properties"/> -->
86
   
87
    <!-- 
88
        This applicationContext is not a full cdm application context. It only covers the remote components 
89
        without service and persistence. The cacheManager is usually provided via a Java config class in
90
        eu/etaxonomy/cdm/service/api/conf which cannot be used in this context. Therefore we are 
91
        using the EhCacheManagerFactoryBean here to initialize the cacheManager bean.
92
     -->
93
<!--     <bean id="cacheManager" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean"> -->
94
<!--       <property name="configLocation" value="classpath:/eu/etaxonomy/cdm/remote/ehcache.xml"/> -->
95
<!--       <property name="shared" value="true"/> -->
96
<!--     </bean>  -->
97

  
98
    <context:component-scan base-package="eu/etaxonomy/cdm/remote/controller"/> 
99
</beans>

Also available in: Unified diff