ref #6241 change @date to @since in appimport
[cdmlib-apps.git] / app-import / src / main / java / eu / etaxonomy / cdm / app / greece / GreeceImageActivator.java
1 /**
2 * Copyright (C) 2016 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.greece;
10
11 import java.net.URI;
12 import java.util.UUID;
13
14 import org.apache.log4j.Logger;
15
16 import eu.etaxonomy.cdm.app.common.CdmDestinations;
17 import eu.etaxonomy.cdm.database.DatabaseTypeEnum;
18 import eu.etaxonomy.cdm.database.DbSchemaValidation;
19 import eu.etaxonomy.cdm.database.ICdmDataSource;
20 import eu.etaxonomy.cdm.io.common.CdmDefaultImport;
21 import eu.etaxonomy.cdm.io.common.IImportConfigurator.CHECK;
22 import eu.etaxonomy.cdm.io.common.ImportResult;
23 import eu.etaxonomy.cdm.io.media.in.MediaExcelImportConfigurator;
24 import eu.etaxonomy.cdm.model.name.NomenclaturalCode;
25 import eu.etaxonomy.cdm.model.reference.Reference;
26 import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
27
28 /**
29 *
30 * Import for Checklist of Greece.
31 *
32 * https://dev.e-taxonomy.eu/redmine/issues/6286
33 *
34 * @author a.mueller
35 * @since 13.12.2016
36 */
37 public class GreeceImageActivator {
38 @SuppressWarnings("unused")
39 private static final Logger logger = Logger.getLogger(GreeceImageActivator.class);
40
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_greece_checklist_production();
45
46 // private static final UUID sourceUuid = UUID.fromString("418b5885-08fb-4f1e-ac94-8f5c84b1683d");
47 private static final UUID sourceUuid = UUID.fromString("c3d300f0-86ef-4c65-8727-c594035ed7a7");
48 // private static final String fileName = "20171107_sent_1332_images.xlsx";
49 private static final String fileName = "20171110_Turland_433_others_59.xlsx";
50
51
52 //check - import
53 static final CHECK check = CHECK.IMPORT_WITHOUT_CHECK;
54
55 boolean doImages = true;
56
57 private void doImport(ICdmDataSource cdmDestination){
58
59 DbSchemaValidation schemaVal = cdmDestination.getDatabaseType() == DatabaseTypeEnum.H2 ? DbSchemaValidation.CREATE : DbSchemaValidation.VALIDATE;
60 URI source = greekChecklist(); //just any
61 //make Source
62 MediaExcelImportConfigurator config = MediaExcelImportConfigurator.NewInstance(source, cdmDestination);
63 config.setCheck(check);
64 config.setDbSchemaValidation(schemaVal);
65 config.setSourceReference(getSourceReference());
66 config.setNomenclaturalCode(NomenclaturalCode.ICNAFP);
67
68 CdmDefaultImport<MediaExcelImportConfigurator> myImport = new CdmDefaultImport<>();
69 ImportResult result = myImport.invoke(config);
70 System.out.println(result.createReport());
71
72 }
73
74
75 private URI greekChecklist(){
76 return URI.create("file:////BGBM-PESIHPC/Greece/images/" + fileName);
77 }
78
79
80 private Reference getSourceReference(){
81 Reference result = ReferenceFactory.newDatabase();
82 result.setTitle(fileName);
83 result.setUuid(sourceUuid);
84
85 return result;
86 }
87
88 /**
89 * @param args
90 */
91 public static void main(String[] args) {
92 GreeceImageActivator me = new GreeceImageActivator();
93 me.doImport(cdmDestination);
94 System.exit(0);
95 }
96 }