Project

General

Profile

Download (4.83 KB) Statistics
| Branch: | Revision:
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.common.Language;
25
import eu.etaxonomy.cdm.model.name.NomenclaturalCode;
26
import eu.etaxonomy.cdm.model.reference.Reference;
27
import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
28

    
29
/**
30
 *
31
 * Import for new images for the Flora of Greece.
32
 *
33
 * https://dev.e-taxonomy.eu/redmine/issues/7075
34
 *
35
 * How to import:
36
 *
37
 *  <UL>
38
 *  <LI>In Excel file we should have 3 URI columns for large, medium and small.</LI>
39
 *    If they not exists create cells with something like "=WECHSELN(C2;"large";"medium")"  (German Excel version)
40
 *    Label these columns url_size1, url_size2 and url_size3</LI>
41
 *  <LI>If the medium and small versions of the images do not yet exist, create them in an according folder
42
 *    (you may need to ask for access to the server in Greece)</LI>
43
 *  <LI>Copy only the new images into a local folder (use date to
44
 *      determine new images if more images are in the original folder)</LI>
45
 *  <LI>Open IrfanView and open File->BatchConversion/Rename</LI>
46
 *  <LI>Use Advanced options for bulk resize and use the following parameters:</LI>
47
 *       <UL><LI> for small: -> Set one or both sides to width=210 (height=-empty-)</LI>
48
 *        <LI> for medium: -> Set short side to 350</LI>
49
 *        </UL>
50
 *  <LI>Select all images and move them to the "input files"</LI>
51
 *  <LI>Choose correct "Output folder for result files" (repeat for both sizes)</LI>
52
 *  <LI>Upload images in both folders to correct place in remote server</LI>
53
 *  <LI>Update the filename parameter in code below.</LI>
54
 *  <LI>Upload the Excel file to /BGBM-PESIHPC/Greece/images/  (see {@link #greekChecklist()}) below</LI>
55
 *  <LI>Run with localH2 to test if everything works, if yes
56
 *  <LI>Run
57
 *  </UL>
58
 *
59
 * @author a.mueller
60
 * @since 13.12.2016
61
 */
62
public class GreeceImageActivator {
63

    
64
    @SuppressWarnings("unused")
65
    private static final Logger logger = Logger.getLogger(GreeceImageActivator.class);
66

    
67
//    static final ICdmDataSource cdmDestination = CdmDestinations.localH2();
68
    static final ICdmDataSource cdmDestination = CdmDestinations.cdm_production_greece_checklist();
69

    
70
//    private static final UUID sourceUuid = UUID.fromString("a57e30c1-cb0b-438d-830e-f7c1c8cd1fb1");
71
    private static final UUID sourceUuid = UUID.fromString("47716558-a2c1-4108-a9f4-7da241b9c26e");
72

    
73
//    private static final String fileName = "20200507_fog_images.xlsx";
74
    private static final String fileName = "metadata_FoG_AK_Willing_correct.xlsx";
75

    
76

    
77
//    NOTE!!: Darauf achten, dass die Header case sensitiv sind und keine Leerzeichen am Ende sein sollten, trim funktioniert seltsamerweise nicht immer
78

    
79
    //check - import
80
    static final CHECK check = CHECK.IMPORT_WITHOUT_CHECK;
81

    
82
    private void doImport(ICdmDataSource cdmDestination){
83

    
84
        DbSchemaValidation schemaVal = cdmDestination.getDatabaseType() == DatabaseTypeEnum.H2 ? DbSchemaValidation.CREATE : DbSchemaValidation.VALIDATE;
85
        URI source = greekChecklist();  //just any
86
        //make Source
87
        MediaExcelImportConfigurator config = MediaExcelImportConfigurator.NewInstance(source, cdmDestination);
88
        config.setCheck(check);
89
        config.setDbSchemaValidation(schemaVal);
90
        config.setSourceReference(getSourceReference());
91
        config.setDescriptionLanguage(Language.uuidEnglish);
92
        config.setTitleLanguageUuid(Language.uuidEnglish);
93
        config.setNomenclaturalCode(NomenclaturalCode.ICNAFP);
94

    
95
        CdmDefaultImport<MediaExcelImportConfigurator> myImport = new CdmDefaultImport<>();
96
        ImportResult result = myImport.invoke(config);
97
        System.out.println(result.createReport());
98
    }
99

    
100
    private URI greekChecklist(){
101
        return URI.create("file:////BGBM-PESIHPC/Greece/images/" + fileName);
102
    }
103

    
104
    private Reference getSourceReference(){
105
        Reference result = ReferenceFactory.newDatabase();
106
        result.setTitle(fileName);
107
        result.setUuid(sourceUuid);
108

    
109
        return result;
110
    }
111

    
112
    public static void main(String[] args) {
113
        GreeceImageActivator me = new GreeceImageActivator();
114
        me.doImport(cdmDestination);
115
        System.exit(0);
116
    }
117
}
(4-4/9)