2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
10 package eu
.etaxonomy
.cdm
.app
.common
;
13 import java
.util
.List
;
14 import java
.util
.UUID
;
16 import org
.apache
.log4j
.Logger
;
17 import org
.springframework
.core
.io
.ClassPathResource
;
18 import org
.springframework
.transaction
.TransactionStatus
;
20 import eu
.etaxonomy
.cdm
.api
.application
.CdmApplicationController
;
21 import eu
.etaxonomy
.cdm
.common
.monitor
.DefaultProgressMonitor
;
22 import eu
.etaxonomy
.cdm
.common
.monitor
.IProgressMonitor
;
23 import eu
.etaxonomy
.cdm
.database
.DbSchemaValidation
;
24 import eu
.etaxonomy
.cdm
.database
.ICdmDataSource
;
25 import eu
.etaxonomy
.cdm
.io
.common
.CdmDefaultImport
;
26 import eu
.etaxonomy
.cdm
.io
.common
.IImportConfigurator
.CHECK
;
27 import eu
.etaxonomy
.cdm
.io
.sdd
.in
.SDDImportConfigurator
;
28 import eu
.etaxonomy
.cdm
.model
.description
.CategoricalData
;
29 import eu
.etaxonomy
.cdm
.model
.description
.DescriptionElementBase
;
30 import eu
.etaxonomy
.cdm
.model
.description
.Modifier
;
31 import eu
.etaxonomy
.cdm
.model
.description
.State
;
32 import eu
.etaxonomy
.cdm
.model
.description
.StateData
;
33 import eu
.etaxonomy
.cdm
.model
.description
.TaxonDescription
;
34 import eu
.etaxonomy
.cdm
.model
.media
.Media
;
35 import eu
.etaxonomy
.cdm
.model
.media
.MediaRepresentation
;
36 import eu
.etaxonomy
.cdm
.model
.media
.MediaRepresentationPart
;
37 import eu
.etaxonomy
.cdm
.model
.name
.NomenclaturalCode
;
38 import eu
.etaxonomy
.cdm
.model
.name
.NonViralName
;
39 import eu
.etaxonomy
.cdm
.model
.name
.TaxonNameBase
;
40 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
41 import eu
.etaxonomy
.cdm
.persistence
.query
.MatchMode
;
44 * @author a.babadshanjan
47 public class TestActivator
{
48 @SuppressWarnings("unused")
49 private static final Logger logger
= Logger
.getLogger(TestActivator
.class);
51 //static final Source faunaEuropaeaSource = FaunaEuropaeaSources.faunEu();
52 // static final ICdmDataSource cdmDestination = CdmDestinations.cdm_test_local_mysql();
53 // static final ICdmDataSource cdmDestination = CdmDestinations.localH2();
54 // static final ICdmDataSource cdmDestination = CdmDestinations.cdm_flora_central_africa_production();
55 // static final ICdmDataSource cdmDestination = CdmDestinations.cdm_edit_cichorieae_preview();
56 static final ICdmDataSource cdmDestination
= CdmDestinations
.cdm_cyprus_production();
59 static final int limitSave
= 2000;
61 static final CHECK check
= CHECK
.IMPORT_WITHOUT_CHECK
;
62 // static final CHECK check = CHECK.CHECK_ONLY;
63 // static DbSchemaValidation dbSchemaValidation = DbSchemaValidation.NONE;
64 // static DbSchemaValidation dbSchemaValidation = DbSchemaValidation.UPDATE;
65 static DbSchemaValidation dbSchemaValidation
= DbSchemaValidation
.VALIDATE
;
66 static final NomenclaturalCode nomenclaturalCode
= NomenclaturalCode
.ICBN
;
73 public static void main(String
[] args
) {
75 ICdmDataSource destination
= cdmDestination
;
77 CdmApplicationController app
;
79 // applicationEventMulticaster
80 // app = CdmIoApplicationController.NewInstance(destination, dbSchemaValidation);
82 IProgressMonitor progressMonitor
= DefaultProgressMonitor
.NewInstance();
83 String resourcePath
= "/eu/etaxonomy/cdm/appimportTestApplicationContext.xml";
84 ClassPathResource resource
= new ClassPathResource(resourcePath
);
85 // ApplicationListener<?> listener = new AppImportApplicationListener();
86 // List<ApplicationListener> listeners = new ArrayList<ApplicationListener>();
87 // listeners.add(listener);
88 // app = CdmApplicationController.NewInstance(resource, destination, dbSchemaValidation, false, progressMonitor, listeners);
89 app
= CdmApplicationController
.NewInstance(resource
, destination
, dbSchemaValidation
, false, progressMonitor
);
97 TransactionStatus tx
= app
.startTransaction();
99 State state
= (State
)app
.getTermService().find(UUID
.fromString("881b9c80-626d-47a6-b308-a63ee5f4178f"));
100 Modifier modifier
= (Modifier
)app
.getTermService().find(UUID
.fromString("efc38dad-205c-4028-ad9d-ae509a14b37a"));
101 CategoricalData cd
= CategoricalData
.NewInstance();
102 StateData stateData
= StateData
.NewInstance();
103 stateData
.setState(state
);
104 stateData
.addModifier(modifier
);
106 StateData stateData2
= StateData
.NewInstance();
107 stateData2
.setState(state
);
108 stateData2
.addModifier(modifier
);
110 cd
.addState(stateData2
);
112 app
.getDescriptionService().saveDescriptionElement(cd
);
113 System
.out
.println("Saved");
115 app
.commitTransaction(tx
);
117 URI uri
= URI
.create("file:///C:/localCopy/Data/xper/Cichorieae-DA2.sdd.xml");
118 SDDImportConfigurator configurator
= SDDImportConfigurator
.NewInstance(uri
, destination
);
119 CdmDefaultImport
<SDDImportConfigurator
> myImport
= new CdmDefaultImport
<SDDImportConfigurator
>();
121 myImport
.setCdmAppController(app
);
123 boolean r
= myImport
.invoke(configurator
);
124 System
.out
.println(r
);
130 // app.changeDataSource(destination);
131 // ICdmDataSource cdmDestination = CdmDestinations.cdm_edit_cichorieae_preview();
132 // app.changeDataSource(cdmDestination);
133 // ITaxonServiceConfigurator<?> conf = TaxonServiceConfiguratorImpl.NewInstance();
134 // conf.setDoSynonyms(true);
135 // conf.setDoTaxa(true);
136 // conf.setMatchMode(MatchMode.BEGINNING);
137 // conf.setTitleSearchString("L*");
138 // conf.setPageNumber(0);
139 // conf.setPageSize(50);
140 // Set<NamedArea> areas = new HashSet<NamedArea>();
141 // areas.add(TdwgArea.getAreaByTdwgAbbreviation("GER"));
142 // //conf.setNamedAreas(areas);
144 // Pager<IdentifiableEntity> taxaAndSyn = app.getTaxonService().findTaxaAndNames(conf);
145 // List<IdentifiableEntity> taxList = taxaAndSyn.getRecords();
147 // for (IdentifiableEntity<?> ent: taxList){
149 // System.err.println(ent.getTitleCache());
154 System
.out
.println("End importing Fauna Europaea data");