Project

General

Profile

Download (10.2 KB) Statistics
| Branch: | Revision:
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.app.cuba;
11

    
12
import java.net.URI;
13
import java.util.UUID;
14

    
15
import org.apache.log4j.Logger;
16

    
17
import eu.etaxonomy.cdm.api.application.ICdmApplicationConfiguration;
18
import eu.etaxonomy.cdm.api.service.ITermService;
19
import eu.etaxonomy.cdm.app.common.CdmDestinations;
20
import eu.etaxonomy.cdm.database.DbSchemaValidation;
21
import eu.etaxonomy.cdm.database.ICdmDataSource;
22
import eu.etaxonomy.cdm.io.common.CdmDefaultImport;
23
import eu.etaxonomy.cdm.io.common.IImportConfigurator.CHECK;
24
import eu.etaxonomy.cdm.io.cuba.CubaImportConfigurator;
25
import eu.etaxonomy.cdm.model.agent.Person;
26
import eu.etaxonomy.cdm.model.description.Feature;
27
import eu.etaxonomy.cdm.model.description.FeatureNode;
28
import eu.etaxonomy.cdm.model.description.FeatureTree;
29
import eu.etaxonomy.cdm.model.reference.Reference;
30
import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
31

    
32
/**
33
 * @author a.mueller
34
 * @created 04.01.2016
35
 */
36
public class CubaActivator {
37
	private static final Logger logger = Logger.getLogger(CubaActivator.class);
38

    
39
	//database validation status (create, update, validate ...)
40
	static DbSchemaValidation hbm2dll = DbSchemaValidation.CREATE;
41

    
42
//    static final ICdmDataSource cdmDestination = CdmDestinations.localH2();
43
//  static final ICdmDataSource cdmDestination = CdmDestinations.cdm_test_local_mysql_test();
44
    static final ICdmDataSource cdmDestination = CdmDestinations.cdm_cuba_production();
45

    
46
	boolean invers = false;
47

    
48
	boolean include = !invers;
49
	boolean exists = true;
50

    
51
    boolean doAsteraceae = include && false;
52
    boolean doConvolvulaceae = include && exists;   //x
53
    boolean doCyperaceae = include && exists;   //x
54
    boolean doDicotA_C = include && false;
55
    boolean doDicotD_M = include && false;
56
    boolean doDicotN_Z = include && false;
57
    boolean doEuphorbiaceae = include && false;
58
    boolean doFabaceae = include && exists;
59
    boolean doGymnospermae = include && false;
60
    boolean doLamVerbenaceae = include && false;
61
    boolean doMalpighiaceae = include && exists;
62
    boolean doMelastomataceae = include && exists;
63
    boolean doMonocots = include && exists;
64
    boolean doMyrtaceae = include && exists;
65
    boolean doOrchidaceae = include && false;
66
    boolean doRubiaceae = include && exists;
67
    boolean doUrticaceae = include && exists;
68

    
69

    
70

    
71

    
72
	//feature tree uuid
73
	public static final UUID featureTreeUuid = UUID.fromString("dad6b9b5-693f-4367-a7aa-076cc9c99476");
74

    
75
	//classification
76
	static final UUID classificationUuid = UUID.fromString("5de394de-9c76-4b97-b04d-71be31c7f44b");
77
	private static final String classificationName = "Flora of Cuba";
78

    
79
	static final String sourceReferenceTitle = "Cuba import";
80

    
81
	//check - import
82
	static final CHECK check = CHECK.IMPORT_WITHOUT_CHECK;
83

    
84
	boolean doVocabularies = (hbm2dll == DbSchemaValidation.CREATE);
85
	static final boolean doTaxa = true;
86
	static final boolean doDeduplicate = false;
87

    
88

    
89
	private void doImport(ICdmDataSource cdmDestination){
90

    
91
	    URI source = monocots();  //just any
92

    
93
		//make Source
94
		CubaImportConfigurator config= CubaImportConfigurator.NewInstance(source, cdmDestination);
95
		config.setClassificationUuid(classificationUuid);
96
        config.setClassificationName(classificationName);
97
        config.setCheck(check);
98
//		config.setDoDistribution(doDistribution);
99
		config.setDoTaxa(doTaxa);
100
		config.setDbSchemaValidation(hbm2dll);
101
		config.setSourceReferenceTitle(sourceReferenceTitle);
102
		config.setDoVocabularies(doVocabularies);
103

    
104
		CdmDefaultImport<CubaImportConfigurator> myImport = new CdmDefaultImport<CubaImportConfigurator>();
105

    
106

    
107
		//...
108
        if (doAsteraceae){
109
            doSource(asteraceae(), config, myImport, doVocabularies);
110
        }
111
        if (doConvolvulaceae){
112
            doSource(convolvulaceae(), config, myImport, doVocabularies);
113
        }
114
        if (doCyperaceae){
115
            doSource(cyperaceae(), config, myImport, doVocabularies);
116
        }
117
        if (doDicotA_C){
118
            doSource(dicotA_C(), config, myImport, doVocabularies);
119
        }
120
        if (doDicotD_M){
121
            doSource(dicotD_M(), config, myImport, doVocabularies);
122
        }
123
        if (doDicotN_Z){
124
            doSource(dicotN_Z(), config, myImport, doVocabularies);
125
        }
126
        if (doEuphorbiaceae){
127
            doSource(euphorbiaceae(), config, myImport, doVocabularies);
128
        }
129
        if (doFabaceae){
130
            doSource(fabaceae(), config, myImport, doVocabularies);
131
        }
132
        if (doGymnospermae){
133
            doSource(gymnospermae(), config, myImport, doVocabularies);
134
        }
135
        if (doLamVerbenaceae){
136
            doSource(lamVerbenaceae(), config, myImport, doVocabularies);
137
        }
138
        if (doMalpighiaceae){
139
            doSource(malpighiaceae(), config, myImport, doVocabularies);
140
        }
141
        if (doMelastomataceae){
142
            doSource(melastomataceae(), config, myImport, doVocabularies);
143
        }
144
        if (doMonocots){
145
            doSource(monocots(), config, myImport, doVocabularies);
146
        }
147
        if (doMyrtaceae){
148
            doSource(myrtaceae(), config, myImport, doVocabularies);
149
        }
150
        if (doOrchidaceae){
151
            doSource(orchidaceae(), config, myImport, doVocabularies);
152
        }
153
        if (doRubiaceae){
154
            doSource(rubiaceae(), config, myImport, doVocabularies);
155
        }
156
        if (doUrticaceae){
157
            doSource(urticaceae(), config, myImport, doVocabularies);
158
        }
159

    
160

    
161

    
162
		//deduplicate
163
		if (doDeduplicate){
164
			ICdmApplicationConfiguration app = myImport.getCdmAppController();
165
			int count = app.getAgentService().deduplicate(Person.class, null, null);
166
			logger.warn("Deduplicated " + count + " persons.");
167
//			count = app.getAgentService().deduplicate(Team.class, null, null);
168
//			logger.warn("Deduplicated " + count + " teams.");
169
			count = app.getReferenceService().deduplicate(Reference.class, null, null);
170
			logger.warn("Deduplicated " + count + " references.");
171
		}
172

    
173

    
174
		System.exit(0);
175

    
176
	}
177

    
178
    /**
179
     * @param source
180
     * @param config
181
     * @param myImport
182
     */
183
    private void doSource(URI source, CubaImportConfigurator config,
184
            CdmDefaultImport<CubaImportConfigurator> myImport, boolean doVocabularies) {
185
        config.setSource(source);
186
        String message = "Start import from ("+ source.toString() + ") ...";
187
        System.out.println(message);
188
        logger.warn(message);
189
        config.setSourceReference(getSourceReference(sourceReferenceTitle));
190
        config.setDoVocabularies(doVocabularies);
191
        myImport.invoke(config);
192

    
193
        if (doVocabularies){
194
            FeatureTree tree = makeFeatureNodes(myImport.getCdmAppController().getTermService());
195
            myImport.getCdmAppController().getFeatureTreeService().saveOrUpdate(tree);
196
            this.doVocabularies = false;
197
        }
198
        System.out.println("End import from ("+ source.toString() + ")...");
199
    }
200

    
201
	private Reference<?> getSourceReference(String string) {
202
		Reference<?> result = ReferenceFactory.newGeneric();
203
		result.setTitleCache(string, true);
204
		return result;
205
	}
206

    
207
	private FeatureTree makeFeatureNodes(ITermService service){
208
//		CyprusTransformer transformer = new CyprusTransformer();
209

    
210
		FeatureTree result = FeatureTree.NewInstance(featureTreeUuid);
211
		result.setTitleCache("Cuba Feature Tree", true);
212
		FeatureNode root = result.getRoot();
213
		FeatureNode newNode;
214

    
215
//		newNode = FeatureNode.NewInstance(Feature.STATUS());
216
//		root.addChild(newNode);
217

    
218
		newNode = FeatureNode.NewInstance(Feature.DISTRIBUTION());
219
		root.addChild(newNode);
220

    
221
//		newNode = FeatureNode.NewInstance(Feature.SYSTEMATICS());
222
//		root.addChild(newNode);
223

    
224
		//user defined features
225
//		String [] featureList = new String[]{"Red Book", "Endemism"};
226
//		addFeataureNodesByStringList(featureList, root, transformer, service);
227

    
228
		return result;
229
	}
230

    
231

    
232
	//Monocots
233
	public static URI monocots() {
234
	    return URI.create("file:////BGBM-PESIHPC/Cuba/Monocot.xlsx");
235
	}
236
	//Cyperaceae
237
	public static URI cyperaceae() {
238
	    return URI.create("file:////BGBM-PESIHPC/Cuba/Cyper_Poaceae.xlsx");
239
	}
240
    //Fabaceae
241
    public static URI fabaceae() {
242
        return URI.create("file:////BGBM-PESIHPC/Cuba/Fabaceae.xlsx");
243
    }
244
    //Urticaceae
245
    public static URI urticaceae() {
246
        return URI.create("file:////BGBM-PESIHPC/Cuba/Urticaceae.xlsx");
247
    }
248
    //Asteraceae
249
    public static URI asteraceae() {
250
        return URI.create("file:////BGBM-PESIHPC/Cuba/Asteraceae.xlsx");
251
    }
252
    //Convolvulaceae
253
    public static URI convolvulaceae() {
254
        return URI.create("file:////BGBM-PESIHPC/Cuba/Convolvulaceae.xlsx");
255
    }
256
    //dicot A-C
257
    public static URI dicotA_C() {
258
        return URI.create("file:////BGBM-PESIHPC/Cuba/dicotA_C.xlsx");
259
    }
260
    //dicot D-M
261
    public static URI dicotD_M() {
262
        return URI.create("file:////BGBM-PESIHPC/Cuba/dicotD_M.xlsx");
263
    }
264
    //dicot N-Z
265
    public static URI dicotN_Z() {
266
        return URI.create("file:////BGBM-PESIHPC/Cuba/dicotN_Z.xlsx");
267
    }
268
    //Euphorbiaceae
269
    public static URI euphorbiaceae() {
270
        return URI.create("file:////BGBM-PESIHPC/Cuba/Euphorbiaceae.xlsx");
271
    }
272
    //Gymnospermae
273
    public static URI gymnospermae() {
274
        return URI.create("file:////BGBM-PESIHPC/Cuba/gymnospermae.xlsx");
275
    }
276
    //Lam.Verbenaceae
277
    public static URI lamVerbenaceae() {
278
        return URI.create("file:////BGBM-PESIHPC/Cuba/Lam_Verbenaceae.xlsx");
279
    }
280
    //Malpighiaceae
281
    public static URI malpighiaceae() {
282
        return URI.create("file:////BGBM-PESIHPC/Cuba/Malpighiaceae.xlsx");
283
    }
284
    //Melastomataceae
285
    public static URI melastomataceae() {
286
        return URI.create("file:////BGBM-PESIHPC/Cuba/Melastomataceae.xlsx");
287
    }
288
    //Myrtaceae
289
    public static URI myrtaceae() {
290
        return URI.create("file:////BGBM-PESIHPC/Cuba/Myrtaceae.xlsx");
291
    }
292
    //Orchidaceae
293
    public static URI orchidaceae() {
294
        return URI.create("file:////BGBM-PESIHPC/Cuba/Orchidaceae.xlsx");
295
    }
296
    //Rubiaceae
297
    public static URI rubiaceae() {
298
        return URI.create("file:////BGBM-PESIHPC/Cuba/Rubiaceae.xlsx");
299
    }
300

    
301
	/**
302
	 * @param args
303
	 */
304
	public static void main(String[] args) {
305
	    CubaActivator me = new CubaActivator();
306
		me.doImport(cdmDestination);
307
	}
308

    
309
}
    (1-1/1)