Project

General

Profile

Download (3.72 KB) Statistics
| Branch: | Tag: | Revision:
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.taxeditor.io.wizard;
10

    
11
import java.io.File;
12
import java.io.FileInputStream;
13
import java.io.FileNotFoundException;
14
import java.io.IOException;
15
import java.util.ArrayList;
16
import java.util.List;
17

    
18
import org.apache.commons.io.IOUtils;
19
import org.apache.log4j.Logger;
20
import org.eclipse.core.runtime.jobs.Job;
21
import org.eclipse.jface.viewers.IStructuredSelection;
22
import org.eclipse.ui.IWorkbench;
23

    
24
import eu.etaxonomy.cdm.common.URI;
25
import eu.etaxonomy.cdm.database.DbSchemaValidation;
26
import eu.etaxonomy.cdm.io.common.IImportConfigurator.SOURCE_TYPE;
27
import eu.etaxonomy.cdm.io.reference.ris.in.RisReferenceImportConfigurator;
28
import eu.etaxonomy.taxeditor.store.CdmStore;
29

    
30
/**
31
 * @author k.luther
32
 * @date 12.05.2017
33
 */
34
public class RISImportWizard extends AbstractImportWizard<RisReferenceImportConfigurator>{
35
    private RisReferenceImportConfigurator configurator;
36

    
37
    private ImportFromFileDataSourceWizardPage dataSourcePage;
38

    
39
    private static final Logger logger = Logger.getLogger(ExcelDistributionUpdateWizard.class);
40

    
41
    @Override
42
    public RisReferenceImportConfigurator getConfigurator() {
43
        return configurator;
44
    }
45

    
46
    @Override
47
    public boolean performFinish() {
48
        URI source = dataSourcePage.getUri();
49
       // configurator.setSource(source);
50
//        try {
51
//            configurator = RisReferenceImportConfigurator.NewInstance(source, null);
52
//        } catch (MalformedURLException e1) {
53
//            // TODO Auto-generated catch block
54
//            e1.printStackTrace();
55
//        } catch (IOException e1) {
56
//            // TODO Auto-generated catch block
57
//            e1.printStackTrace();
58
//        }
59
        configurator.setDbSchemaValidation(DbSchemaValidation.CREATE);
60
        File file = source.toFile();
61
       FileInputStream fis;
62

    
63
        try {
64
            fis = new FileInputStream(file);
65
            byte[] data;
66
            data = IOUtils.toByteArray(fis);
67
            configurator.setStream(data);
68
//TODO: workaround, needs to be changed to source as byte array
69
            Job job = CdmStore.getImportManager().createIOServiceJob(configurator, data, SOURCE_TYPE.INPUTSTREAM);
70
            CdmStore.getImportManager().run(job);
71
        } catch (FileNotFoundException e) {
72
            logger.error("Error while reading file" + source.toString());
73
        } catch (IOException e){
74

    
75
        }
76

    
77
        //CdmStore.getImportManager().runMoniteredOperation(configurator, new File(source), SOURCE_TYPE.INPUTSTREAM);
78

    
79
        return true;
80
    }
81

    
82
    @Override
83
    public void init(IWorkbench workbench, IStructuredSelection selection) {
84
        super.init(workbench, selection);
85
        configurator = RisReferenceImportConfigurator.NewInstance();
86
    }
87

    
88
    @Override
89
    public void addPages() {
90
        //addConfiguratorPage();
91
        addDataSourcePage();
92
    }
93
    
94
    @Override
95
    protected void addConfiguratorPage(){
96
        List<String> ignoreMethods = new ArrayList<>();
97
        ignoreMethods.add("setIgnoreNull");
98
        ignoreMethods.add("setInteractWithUser");
99
        ignoreMethods.add("setUseClassification");
100
        pageConfiguration = GenericConfiguratorWizardPage.Import(CONFIGURATION_PAGE, getConfigurator(), ignoreMethods, "Ris Import");
101
        addPage(pageConfiguration);
102
    }
103

    
104
    private void addDataSourcePage(){
105
        dataSourcePage = new ImportFromFileDataSourceWizardPage("Choose Ris File",
106
                "Please choose an xls file in the Distribution Update format.", new String[]{"*.txt"});
107
        addPage(dataSourcePage);
108
    }
109
}
(25-25/30)