Project

General

Profile

« Previous | Next » 

Revision dbffc954

Added by Andreas Müller about 6 years ago

cleanup

View differences:

app-import/src/main/java/eu/etaxonomy/cdm/app/caryophyllales/CdmLightExportActivator.java
1
/**
2
* Copyright (C) 2017 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.caryophyllales;
10

  
11
import java.io.File;
12
import java.io.FileNotFoundException;
13
import java.io.FileOutputStream;
14
import java.io.IOException;
15
import java.net.URI;
16
import java.util.Map;
17

  
18
import org.apache.log4j.Logger;
19

  
20
import eu.etaxonomy.cdm.api.application.CdmApplicationController;
21
import eu.etaxonomy.cdm.app.common.CdmDestinations;
22
import eu.etaxonomy.cdm.app.util.TestDatabase;
23
import eu.etaxonomy.cdm.database.DbSchemaValidation;
24
import eu.etaxonomy.cdm.database.ICdmDataSource;
25
import eu.etaxonomy.cdm.io.cdmLight.CdmLightExportConfigurator;
26
import eu.etaxonomy.cdm.io.common.CdmDefaultExport;
27
import eu.etaxonomy.cdm.io.common.ExportResult;
28
import eu.etaxonomy.cdm.io.common.ExportResultType;
29

  
30
/**
31
 * @author k.luther
32
 * @date 24.03.2017
33
 *
34
 */
35
public class CdmLightExportActivator {
36
private static final ICdmDataSource cdmSource = CdmDestinations.cdm_local_caryophyllales_nepenthaceae();
37

  
38
    // Export:
39
    private static String exportFileName = "file://C://Users//k.luther//Documents//Caryophyllales//OutputModel";
40

  
41

  
42
    private static final Logger logger = Logger.getLogger(CdmLightExportActivator.class);
43

  
44
    private ExportResult invokeExport(ICdmDataSource sourceParam, URI uri) {
45
//      String server = "localhost";
46
//      String database = "EDITimport";
47
//      String username = "edit";
48
//      sourceParam = CdmDataSource.NewMySqlInstance(server, database, username, AccountStore.readOrStorePassword(server, database, username, null));
49

  
50
        CdmLightExportConfigurator cdmlightExportConfigurator = new CdmLightExportConfigurator(null);
51

  
52
        CdmDefaultExport<CdmLightExportConfigurator> cdmLightExport = new CdmDefaultExport<>();
53

  
54

  
55
        // invoke export
56
        logger.debug("Invoking OutputModel export");
57
        ExportResult result = cdmLightExport.invoke(cdmlightExportConfigurator);
58
        return result;
59

  
60
    }
61
    public static String chooseFile(String[] args) {
62
        if(args == null) {
63
            return null;
64
        }
65
        for (String dest: args){
66
            if (dest.endsWith(".xml")){
67
                return args[0];
68
            }
69
        }
70
        return null;
71
    }
72

  
73

  
74
    private CdmApplicationController initDb(ICdmDataSource db) {
75

  
76
        // Init source DB
77
        CdmApplicationController appCtrInit = TestDatabase.initDb(db, DbSchemaValidation.VALIDATE, false);
78

  
79
        return appCtrInit;
80
    }
81

  
82

  
83
    // Load test data to DB
84
    private void loadTestData(CdmApplicationController appCtrInit) {
85
        TestDatabase.loadTestData("", appCtrInit);
86
    }
87

  
88

  
89
    /**
90
     * @param args
91
     */
92
    public static void main(String[] args) {
93

  
94
        CdmLightExportActivator sc = new CdmLightExportActivator();
95
        ICdmDataSource source = CdmDestinations.chooseDestination(args) != null ? CdmDestinations.chooseDestination(args) : cdmSource;
96
      //  String file = chooseFile(args);
97

  
98
        try {
99

  
100
            sc.initDb(source);  //does this make sense here (it starts the appControler even if it is not needed later
101

  
102
            ExportResult result = sc.invokeExport(source, null);
103
            if (result.getExportData().getType().equals(ExportResultType.MAP_BYTE_ARRAY)){
104
                Map<String, byte[]> map = (Map<String, byte[]>)result.getExportData();
105

  
106
                for (String key:map.keySet()){
107
                    byte[] data =map.get(key);
108
                    String fileEnding =".csv";
109
                    File myFile = new File(exportFileName+File.separator + key + fileEnding);
110
                    FileOutputStream stream = new FileOutputStream(myFile);
111
                    try {
112
                        stream.write(data);
113
                        stream.close();
114
                    } catch (IOException e) {
115
                        // TODO Auto-generated catch block
116
                        e.printStackTrace();
117
                    }
118
                }
119
            }
120
        } catch (FileNotFoundException e) {
121
            // TODO Auto-generated catch block
122
            e.printStackTrace();
123
        }
124
    }
125
}
app-import/src/main/java/eu/etaxonomy/cdm/app/caryophyllales/OutputmodelExportActivator.java
1
/**
2
* Copyright (C) 2017 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.caryophyllales;
10

  
11
import java.io.File;
12
import java.io.FileNotFoundException;
13
import java.io.FileOutputStream;
14
import java.io.IOException;
15
import java.net.URI;
16
import java.util.Map;
17

  
18
import org.apache.log4j.Logger;
19

  
20
import eu.etaxonomy.cdm.api.application.CdmApplicationController;
21
import eu.etaxonomy.cdm.app.common.CdmDestinations;
22
import eu.etaxonomy.cdm.app.util.TestDatabase;
23
import eu.etaxonomy.cdm.database.DbSchemaValidation;
24
import eu.etaxonomy.cdm.database.ICdmDataSource;
25
import eu.etaxonomy.cdm.io.cdmLight.CdmLightExportConfigurator;
26
import eu.etaxonomy.cdm.io.common.CdmDefaultExport;
27
import eu.etaxonomy.cdm.io.common.ExportResult;
28
import eu.etaxonomy.cdm.io.common.ExportResultType;
29

  
30
/**
31
 * @author k.luther
32
 * @date 24.03.2017
33
 *
34
 */
35
public class OutputmodelExportActivator {
36
private static final ICdmDataSource cdmSource = CdmDestinations.cdm_local_caryophyllales_nepenthaceae();
37

  
38
    // Export:
39
    private static String exportFileName = "file://C://Users//k.luther//Documents//Caryophyllales//OutputModel";
40

  
41

  
42
    private static final Logger logger = Logger.getLogger(OutputmodelExportActivator.class);
43

  
44
    private ExportResult invokeExport(ICdmDataSource sourceParam, URI uri) {
45
//      String server = "localhost";
46
//      String database = "EDITimport";
47
//      String username = "edit";
48
//      sourceParam = CdmDataSource.NewMySqlInstance(server, database, username, AccountStore.readOrStorePassword(server, database, username, null));
49

  
50
        CdmLightExportConfigurator cdmlightExportConfigurator = new CdmLightExportConfigurator(null);
51

  
52
        CdmDefaultExport<CdmLightExportConfigurator> cdmLightExport = new CdmDefaultExport<>();
53

  
54

  
55
        // invoke export
56
        logger.debug("Invoking OutputModel export");
57
        ExportResult result = cdmLightExport.invoke(cdmlightExportConfigurator);
58
        return result;
59

  
60
    }
61
    public static String chooseFile(String[] args) {
62
        if(args == null) {
63
            return null;
64
        }
65
        for (String dest: args){
66
            if (dest.endsWith(".xml")){
67
                return args[0];
68
            }
69
        }
70
        return null;
71
    }
72

  
73

  
74
    private CdmApplicationController initDb(ICdmDataSource db) {
75

  
76
        // Init source DB
77
        CdmApplicationController appCtrInit = TestDatabase.initDb(db, DbSchemaValidation.VALIDATE, false);
78

  
79
        return appCtrInit;
80
    }
81

  
82

  
83
    // Load test data to DB
84
    private void loadTestData(CdmApplicationController appCtrInit) {
85
        TestDatabase.loadTestData("", appCtrInit);
86
    }
87

  
88

  
89
    /**
90
     * @param args
91
     */
92
    public static void main(String[] args) {
93

  
94
        OutputmodelExportActivator sc = new OutputmodelExportActivator();
95
        ICdmDataSource source = CdmDestinations.chooseDestination(args) != null ? CdmDestinations.chooseDestination(args) : cdmSource;
96
      //  String file = chooseFile(args);
97

  
98
        try {
99

  
100
            sc.initDb(source);  //does this make sense here (it starts the appControler even if it is not needed later
101

  
102
            ExportResult result = sc.invokeExport(source, null);
103
            if (result.getExportData().getType().equals(ExportResultType.MAP_BYTE_ARRAY)){
104
                Map<String, byte[]> map = (Map<String, byte[]>)result.getExportData();
105

  
106
                for (String key:map.keySet()){
107
                    byte[] data =map.get(key);
108
                    String fileEnding =".csv";
109
                    File myFile = new File(exportFileName+File.separator + key + fileEnding);
110
                    FileOutputStream stream = new FileOutputStream(myFile);
111
                    try {
112
                        stream.write(data);
113
                        stream.close();
114
                    } catch (IOException e) {
115
                        // TODO Auto-generated catch block
116
                        e.printStackTrace();
117
                    }
118
                }
119
            }
120
        } catch (FileNotFoundException e) {
121
            // TODO Auto-generated catch block
122
            e.printStackTrace();
123
        }
124
    }
125
}
app-import/src/main/java/eu/etaxonomy/cdm/app/caryophyllales/TaxonExcelCaryophyllalesActivator.java
13 13
import eu.etaxonomy.cdm.model.name.NomenclaturalCode;
14 14

  
15 15

  
16

  
17

  
18

  
19

  
20

  
21

  
22 16
public class TaxonExcelCaryophyllalesActivator {
23 17

  
24 18

  
......
45 39

  
46 40
	    	//export.invoke(csvNameExportConfigurator.getNewState());
47 41
	    	CdmDefaultExport<CsvNameExportConfigurator> normalExplicitImport =
48
				new CdmDefaultExport<CsvNameExportConfigurator>();
42
				new CdmDefaultExport<>();
49 43

  
50 44
			// invoke import
51 45
			//logger.debug("Invoking Normal Explicit Excel import");
app-import/src/main/java/eu/etaxonomy/cdm/app/caryophyllales/TcsSources.java
1 1
/**
2 2
* Copyright (C) 2007 EDIT
3
* European Distributed Institute of Taxonomy 
3
* European Distributed Institute of Taxonomy
4 4
* http://www.e-taxonomy.eu
5
* 
5
*
6 6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7 7
* See LICENSE.TXT at the top of this package for the full license terms.
8 8
*/
......
20 20
import eu.etaxonomy.cdm.app.sdd.SDDSources;
21 21

  
22 22
/**
23
 * @author a.mueller
24
 * @created 20.06.2008
25
 * @version 1.0
23
 * @author k.luther
24
 * @created May 2014
26 25
 */
27 26
public class TcsSources {
28 27
	private static final Logger logger = Logger.getLogger(TcsSources.class);
29
	
30
	
28

  
29

  
31 30
	public static URI normalExplicit(){
32 31
		try {
33 32
//			URL url = new File(("C:\\localCopy\\eclipse\\cdmlib\\trunk\\app-import\\src\\main\\resources\\excel\\NormalExplicit.xls")).toURL();
34
			
33

  
35 34
			// FIXME what is this????
36 35
			URL url = new File("D:\\NormalExplicit.xls").toURI().toURL();
37 36

  
38
			
37

  
39 38
//			URL url = new TcsSources().getClass().getResource("excel/NormalExplicit.xls");
40 39
			boolean exists = new File(url.getFile()).exists();
41
			if (! exists) throw new RuntimeException("File not found: " + url);
40
			if (! exists) {
41
                throw new RuntimeException("File not found: " + url);
42
            }
42 43
			URI uri = url.toURI();
43 44
			return uri;
44 45
		} catch (MalformedURLException e1) {
......
51 52
		}
52 53

  
53 54
	}
54
	
55

  
55 56
	public static String arecaceae(){
56 57
		//	Monocots rdf
57 58
		String sourceUrl = "http://dev.e-taxonomy.eu/trac/attachment/wiki/SampleDataConversion/Monocotyledonae/arecaceae.rdf?format=raw";
58 59
		logger.debug("TcsSource " +  sourceUrl);
59 60
		return sourceUrl;
60
		
61

  
61 62
	}
62
	
63

  
63 64
	public static String taxonX_local(){
64 65
		//		Monocots rdf
65 66
		//String sourceUrl = "file:C:/localCopy/eclipse/cdmlib/app-import/src/main/resources/palm_tn_29336.xml";
......
73 74
		File sourceDir = new File("target/classes/taxonX/"); //palm_tc_14495.xml
74 75
		return sourceDir;
75 76
	}
76
	
77

  
77 78
	public static String arecaceae_local(){
78 79
		//		Monocots rdf
79 80
		//String sourceUrl = "file:C:/localCopy/eclipse/cdmlib/app-import/src/main/resources/arecaceae.rdf";
80 81
		URL url = new SDDSources().getClass().getResource("/arecaceae.rdf");
81 82
		String sourceUrl = url.toString();
82 83
		return sourceUrl;
83
		
84

  
84 85
	}
85 86

  
86 87

  
......
88 89
		//		tcsXmlTest.xml
89 90
		URL url = new TcsSources().getClass().getResource("/tcs/Cichorium_tcs.xml");
90 91
		String sourceUrl = url.toString();
91
		return sourceUrl;	
92
		return sourceUrl;
92 93
	}
93 94

  
94 95
	public static String tcsXml_nyctaginaceae(){
......
98 99
		} catch (MalformedURLException e) {
99 100
			throw new RuntimeException(e);
100 101
		}
101
		
102

  
102 103
	}
103 104

  
104
	
105
	
105

  
106

  
106 107
	public static String tcsXml_localPath(){
107 108
		File file = new File("C:\\localCopy\\Data\\tdwg\\Cichorium_tcs.xml");
108 109
		String sourceUrl;
......
113 114
			throw new RuntimeException(e);
114 115
		}
115 116
		return sourceUrl;
116
		
117
	}	
118
	
117

  
118
	}
119

  
119 120
	public static String tcsXmlTest_local2(){
120 121
		//		tcsXmlTest.xml
121 122
		URL url = new TcsSources().getClass().getResource("/TcsXmlImportConfiguratorTest-input.xml");
122 123
		String sourceUrl = url.toString();
123
		return sourceUrl;	
124
		return sourceUrl;
124 125
	}
125
	
126

  
126 127
	public static String tcsRdf_globis(){
127 128
		//		globis.rdf.xml
128 129
		//String sourceUrl = "file:C:/Dokumente und Einstellungen/a.kohlbecker.BGBM/Desktop/globis.rdf.xml";
......
130 131
		URL resourceUrl = new TcsSources().getClass().getResource(sourceUrl);
131 132
		logger.debug("TcsRdfSource " +  resourceUrl.toString());
132 133
		return resourceUrl.toString();
133
		
134
	}	
135
	
136 134

  
137
	
135
	}
136

  
137

  
138

  
138 139
}
app-import/src/main/java/eu/etaxonomy/cdm/app/caryophyllales/XlsSources.java
1 1
/**
2 2
* Copyright (C) 2007 EDIT
3
* European Distributed Institute of Taxonomy 
3
* European Distributed Institute of Taxonomy
4 4
* http://www.e-taxonomy.eu
5
* 
5
*
6 6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7 7
* See LICENSE.TXT at the top of this package for the full license terms.
8 8
*/
......
20 20

  
21 21

  
22 22
/**
23
 * @author a.mueller
24
 * @created 20.06.2008
25
 * @version 1.0
23
 * @author k.luther
24
 * @created Jun 2015
26 25
 */
27 26
public class XlsSources {
28
	private static final Logger logger = Logger.getLogger(XlsSources.class);
29
	
30
	
27
	@SuppressWarnings("unused")
28
    private static final Logger logger = Logger.getLogger(XlsSources.class);
29

  
30

  
31 31
	public static URI normalExplicit(){
32 32
		try {
33 33
//			URL url = new File(("C:\\localCopy\\eclipse\\cdmlib\\trunk\\app-import\\src\\main\\resources\\excel\\NormalExplicit.xls")).toURL();
34
			
34

  
35 35
			// FIXME what is this????
36 36
			URL url = new File("D:\\NormalExplicit.xls").toURI().toURL();
37 37

  
38
			
39 38
//			URL url = new TcsSources().getClass().getResource("excel/NormalExplicit.xls");
40 39
			boolean exists = new File(url.getFile()).exists();
41
			if (! exists) throw new RuntimeException("File not found: " + url);
40
			if (! exists) {
41
                throw new RuntimeException("File not found: " + url);
42
            }
42 43
			URI uri = url.toURI();
43 44
			return uri;
44 45
		} catch (MalformedURLException e1) {
......
51 52
		}
52 53

  
53 54
	}
54
	
55

  
55 56
	public static String xls_nyctaginaceae(){
56 57
		try {
57 58
			File file = new File("C:\\Users\\k.luther\\Documents\\Caryophyllales\\Arenaria_ThePlantList.xls");
......
59 60
		} catch (MalformedURLException e) {
60 61
			throw new RuntimeException(e);
61 62
		}
62
		
63

  
63 64
	}
64 65

  
65
	
66

  
66 67
}

Also available in: Unified diff