cleanup
[cdmlib-apps.git] / app-import / src / main / java / eu / etaxonomy / cdm / app / salvador / TestSalvadorAreaMapping.java
1 /**
2 * Copyright (C) 2017 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.app.salvador;
10
11 import java.util.EnumSet;
12 import java.util.HashSet;
13 import java.util.Set;
14 import java.util.UUID;
15
16 import org.apache.log4j.Logger;
17 import org.springframework.aop.framework.Advised;
18 import org.springframework.aop.support.AopUtils;
19
20 import eu.etaxonomy.cdm.api.service.dto.DistributionInfoDTO.InfoPart;
21 import eu.etaxonomy.cdm.app.common.CdmDestinations;
22 import eu.etaxonomy.cdm.database.DbSchemaValidation;
23 import eu.etaxonomy.cdm.database.ICdmDataSource;
24 import eu.etaxonomy.cdm.ext.geo.EditGeoService;
25 import eu.etaxonomy.cdm.io.api.application.CdmIoApplicationController;
26
27 /**
28 * @author a.mueller
29 * @since 08.07.2017
30 */
31 public class TestSalvadorAreaMapping {
32 @SuppressWarnings("unused")
33 private static final Logger logger = Logger.getLogger(TestSalvadorAreaMapping.class);
34
35 //database validation status (create, update, validate ...)
36 static DbSchemaValidation hbm2dll = DbSchemaValidation.VALIDATE;
37
38 // static final ICdmDataSource cdmDestination = CdmDestinations.cdm_test_local_mysql_test();
39 // static final ICdmDataSource cdmDestination = CdmDestinations.cdm_salvador_preview();
40 static final ICdmDataSource cdmDestination = CdmDestinations.cdm_production_salvador();
41
42 protected void doTest(ICdmDataSource cdmDestination){
43
44 CdmIoApplicationController app = CdmIoApplicationController.NewInstance(cdmDestination, hbm2dll);
45 try {
46 doTest2(app);
47 } catch (Exception e) {
48 e.printStackTrace();
49 }
50 }
51
52 private void doTest2(CdmIoApplicationController app) {
53 UUID taxonUuid = UUID.fromString("eae896f0-3194-4b7b-a502-ad1d54ec36e6");
54 // Taxon taxon = (Taxon)app.getTaxonService().find(taxonUuid);
55 Object geoServiceObj = app.getBean("editGeoService");
56 EditGeoService geoService;
57 try {
58 geoService = getTargetObject(geoServiceObj);
59
60
61 Set<InfoPart> partSet = new HashSet<>();
62 partSet.add(InfoPart.mapUriParams);
63
64 EnumSet<InfoPart> parts = EnumSet.copyOf(partSet);
65 geoService.composeDistributionInfoFor(parts, taxonUuid, false, false, null, true,
66 null, null,
67 null, null, null, null, false);
68 } catch (Exception e) {
69 e.printStackTrace();
70 }
71 }
72
73 protected <T> T getTargetObject(Object proxy) throws Exception {
74 while( (AopUtils.isJdkDynamicProxy(proxy))) {
75 return (T) getTargetObject(((Advised)proxy).getTargetSource().getTarget());
76 }
77 return (T) proxy; // expected to be cglib proxy then, which is simply a specialized class
78 }
79
80
81 /**
82 * @param args
83 */
84 public static void main(String[] args) {
85 TestSalvadorAreaMapping me = new TestSalvadorAreaMapping();
86 me.doTest(cdmDestination);
87
88 System.exit(0);
89 }
90 }