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 new images for the flora of greece.
|
31
|
*
|
32
|
* https://dev.e-taxonomy.eu/redmine/issues/7075
|
33
|
*
|
34
|
* How to import:
|
35
|
*
|
36
|
* <UL>
|
37
|
* <LI>In Excel file we should have 3 URI columns for large, medium and small.</LI>
|
38
|
* If they not exists create cells with something like "=WECHSELN(C2;"large";"medium")" (German Excel version)
|
39
|
* Label these columns url_size1, url_size2 and url_size3</LI>
|
40
|
* <LI>If the medium and small versions of the images do not yet exist, create them in an according folder
|
41
|
* (you may need to ask for access to the server in Greece)</LI>
|
42
|
* <LI>Copy only the new images into a local folder (use date to
|
43
|
* determine new images if more images are in the original folder)</LI>
|
44
|
* <LI>Open IrfanView and open File->BatchConversion/Rename</LI>
|
45
|
* <LI>Use Advanced options for bulk resize and use the following parameters:</LI>
|
46
|
* <UL><LI> for small: -> Set one or both sides to width=210 (height=-empty-)</LI>
|
47
|
* <LI> for medium: -> Set short side to 350</LI>
|
48
|
* </UL>
|
49
|
* <LI>Select all images and move them to the "input files"</LI>
|
50
|
* <LI>Choose correct "Output folder for result files" (repeat for both sizes)</LI>
|
51
|
* <LI>Upload images in both folders to correct place in remote server</LI>
|
52
|
* <LI>Update the filename parameter in code below.</LI>
|
53
|
* <LI>Upload the Excel file to /BGBM-PESIHPC/Greece/images/ (see {@link #greekChecklist()}) below</LI>
|
54
|
* <LI>Run with localH2 to test if everything works, if yes
|
55
|
* <LI>Run
|
56
|
* </UL>
|
57
|
*
|
58
|
* @author a.mueller
|
59
|
* @since 13.12.2016
|
60
|
*/
|
61
|
public class GreeceImageActivator {
|
62
|
|
63
|
@SuppressWarnings("unused")
|
64
|
private static final Logger logger = Logger.getLogger(GreeceImageActivator.class);
|
65
|
|
66
|
static final ICdmDataSource cdmDestination = CdmDestinations.localH2();
|
67
|
// static final ICdmDataSource cdmDestination = CdmDestinations.cdm_production_greece_checklist();
|
68
|
|
69
|
private static final UUID sourceUuid = UUID.fromString("40449942-87ff-4f3a-b909-729a80001b47");
|
70
|
// private static final UUID sourceUuid = UUID.fromString("9e6a3815-fb8d-46c3-a250-6d8a350d03fc");
|
71
|
|
72
|
private static final String fileName = "20191230_FoG_images.xlsx";
|
73
|
// private static final String fileName = "20190926_fog_images.xlsx";
|
74
|
|
75
|
|
76
|
// NOTE!!: Darauf achten, dass die Header case sensitiv sind und keine Leerzeichen am Ende sein sollten, trim funktioniert seltsamerweise nicht immer
|
77
|
|
78
|
//check - import
|
79
|
static final CHECK check = CHECK.IMPORT_WITHOUT_CHECK;
|
80
|
|
81
|
private void doImport(ICdmDataSource cdmDestination){
|
82
|
|
83
|
DbSchemaValidation schemaVal = cdmDestination.getDatabaseType() == DatabaseTypeEnum.H2 ? DbSchemaValidation.CREATE : DbSchemaValidation.VALIDATE;
|
84
|
URI source = greekChecklist(); //just any
|
85
|
//make Source
|
86
|
MediaExcelImportConfigurator config = MediaExcelImportConfigurator.NewInstance(source, cdmDestination);
|
87
|
config.setCheck(check);
|
88
|
config.setDbSchemaValidation(schemaVal);
|
89
|
config.setSourceReference(getSourceReference());
|
90
|
config.setNomenclaturalCode(NomenclaturalCode.ICNAFP);
|
91
|
|
92
|
CdmDefaultImport<MediaExcelImportConfigurator> myImport = new CdmDefaultImport<>();
|
93
|
ImportResult result = myImport.invoke(config);
|
94
|
System.out.println(result.createReport());
|
95
|
}
|
96
|
|
97
|
private URI greekChecklist(){
|
98
|
return URI.create("file:////BGBM-PESIHPC/Greece/images/" + fileName);
|
99
|
}
|
100
|
|
101
|
private Reference getSourceReference(){
|
102
|
Reference result = ReferenceFactory.newDatabase();
|
103
|
result.setTitle(fileName);
|
104
|
result.setUuid(sourceUuid);
|
105
|
|
106
|
return result;
|
107
|
}
|
108
|
|
109
|
public static void main(String[] args) {
|
110
|
GreeceImageActivator me = new GreeceImageActivator();
|
111
|
me.doImport(cdmDestination);
|
112
|
System.exit(0);
|
113
|
}
|
114
|
}
|