Project

General

Profile

Download (4.1 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.net.URI;
16
import java.util.ArrayList;
17
import java.util.List;
18
import java.util.UUID;
19

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

    
26
import eu.etaxonomy.cdm.database.DbSchemaValidation;
27
import eu.etaxonomy.cdm.io.distribution.excelupdate.ExcelDistributionUpdateConfigurator;
28
import eu.etaxonomy.taxeditor.l10n.Messages;
29
import eu.etaxonomy.taxeditor.store.CdmStore;
30

    
31
/**
32
 * @author k.luther
33
 * @date 03.05.2017
34
 *
35
 */
36
public class ExcelDistributionUpdateWizard extends AbstractImportWizard<ExcelDistributionUpdateConfigurator> {
37
    private ExcelDistributionUpdateConfigurator configurator;
38

    
39
    private ImportFromFileAndChooseVocIdWizardOage dataSourcePage;
40

    
41
    private static final Logger logger = Logger.getLogger(ExcelDistributionUpdateWizard.class);
42

    
43
    /* (non-Javadoc)
44
     * @see eu.etaxonomy.taxeditor.io.wizard.AbstractImportWizard#getConfigurator()
45
     */
46
    /** {@inheritDoc} */
47
    @Override
48
    public ExcelDistributionUpdateConfigurator getConfigurator() {
49
        return configurator;
50
    }
51

    
52
    /* (non-Javadoc)
53
     * @see org.eclipse.jface.wizard.Wizard#performFinish()
54
     */
55
    /** {@inheritDoc} */
56
    @Override
57
    public boolean performFinish() {
58
        URI source = dataSourcePage.getUri();
59
       // configurator.setSource(source);
60
        configurator.setDbSchemaValidation(DbSchemaValidation.CREATE);
61
        File file = new File(source);
62
        FileInputStream fis = null;
63

    
64
        try {
65
            fis = new FileInputStream(file);
66
        } catch (FileNotFoundException e) {
67
            logger.error("Error while reading file" + source.toString());
68
        }
69
        try {
70
            configurator.setStream(IOUtils.toByteArray(fis));
71
        } catch (IOException e) {
72
            // TODO Auto-generated catch block
73
            e.printStackTrace();
74
        }
75
        UUID vocUuid = dataSourcePage.getVocUuid();
76

    
77
        configurator.setAreaVocabularyUuid(vocUuid);
78
        //CdmStore.getImportManager().runMoniteredOperation(configurator, new File(source), SOURCE_TYPE.INPUTSTREAM);
79
        Job job = CdmStore.getImportManager().createIOServiceJob(configurator);
80
        CdmStore.getImportManager().run(job);
81

    
82
        return true;
83
    }
84

    
85
    /* (non-Javadoc)
86
     * @see org.eclipse.ui.IWorkbenchWizard#init(org.eclipse.ui.IWorkbench, org.eclipse.jface.viewers.IStructuredSelection)
87
     */
88
    /** {@inheritDoc} */
89
    @Override
90
    public void init(IWorkbench workbench, IStructuredSelection selection) {
91
        super.init(workbench, selection);
92
        configurator =  CdmStore.getImportManager().ExcelDistributionUpdateConfigurator();
93

    
94
    }
95

    
96
    /* (non-Javadoc)
97
     * @see eu.etaxonomy.taxeditor.io.wizard.AbstractImportWizard#addPages()
98
     */
99
    /** {@inheritDoc} */
100
    @Override
101
    public void addPages() {
102
        addConfiguratorPage();
103
        addDataSourcePage();
104

    
105

    
106
    }
107
    @Override
108
    protected void addConfiguratorPage(){
109
        List<String> ignoreMethods = new ArrayList<>();
110
        ignoreMethods.add("setIgnoreNull");
111
        ignoreMethods.add("setInteractWithUser");
112
        ignoreMethods.add("setUseClassification");
113
        pageConfiguration = GenericConfiguratorWizardPage.Import(CONFIGURATION_PAGE, getConfigurator(), ignoreMethods, Messages.ExcelDistributionUpdateWizard_ConfiguratorWizard_label);
114
        addPage(pageConfiguration);
115
    }
116

    
117
    private void addDataSourcePage(){
118
        dataSourcePage = new ImportFromFileAndChooseVocIdWizardOage("Choose Excel File",
119
                "Please choose an xls file in the Distribution Update format.", new String[]{"*.xlsx", "*.xls", "*.*"});
120
        addPage(dataSourcePage);
121
    }
122

    
123

    
124
}
(15-15/30)