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
|
import java.util.UUID;
|
18
|
|
19
|
import org.apache.commons.io.IOUtils;
|
20
|
import org.apache.log4j.Logger;
|
21
|
import org.eclipse.core.runtime.jobs.Job;
|
22
|
import org.eclipse.jface.viewers.IStructuredSelection;
|
23
|
import org.eclipse.ui.IWorkbench;
|
24
|
|
25
|
import eu.etaxonomy.cdm.common.URI;
|
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
|
public class ExcelDistributionUpdateWizard extends AbstractImportWizard<ExcelDistributionUpdateConfigurator> {
|
36
|
private ExcelDistributionUpdateConfigurator configurator;
|
37
|
|
38
|
private static final Logger logger = Logger.getLogger(ExcelDistributionUpdateWizard.class);
|
39
|
|
40
|
private ImportFromFileAndChooseVocIdWizardPage dataSourcePage;
|
41
|
|
42
|
@Override
|
43
|
public ExcelDistributionUpdateConfigurator getConfigurator() {
|
44
|
return configurator;
|
45
|
}
|
46
|
|
47
|
@Override
|
48
|
public boolean performFinish() {
|
49
|
URI source = dataSourcePage.getUri();
|
50
|
// configurator.setSource(source);
|
51
|
configurator.setDbSchemaValidation(DbSchemaValidation.CREATE);
|
52
|
File file = new File(source);
|
53
|
FileInputStream fis = null;
|
54
|
|
55
|
try {
|
56
|
fis = new FileInputStream(file);
|
57
|
} catch (FileNotFoundException e) {
|
58
|
logger.error("Error while reading file" + source.toString());
|
59
|
}
|
60
|
try {
|
61
|
configurator.setStream(IOUtils.toByteArray(fis));
|
62
|
} catch (IOException e) {
|
63
|
// TODO Auto-generated catch block
|
64
|
e.printStackTrace();
|
65
|
}
|
66
|
UUID vocUuid = dataSourcePage.getVocUuid();
|
67
|
|
68
|
configurator.setAreaVocabularyUuid(vocUuid);
|
69
|
//CdmStore.getImportManager().runMoniteredOperation(configurator, new File(source), SOURCE_TYPE.INPUTSTREAM);
|
70
|
Job job = CdmStore.getImportManager().createIOServiceJob(configurator);
|
71
|
CdmStore.getImportManager().run(job);
|
72
|
|
73
|
return true;
|
74
|
}
|
75
|
|
76
|
@Override
|
77
|
public void init(IWorkbench workbench, IStructuredSelection selection) {
|
78
|
super.init(workbench, selection);
|
79
|
configurator = CdmStore.getImportManager().ExcelDistributionUpdateConfigurator();
|
80
|
|
81
|
}
|
82
|
|
83
|
@Override
|
84
|
public void addPages() {
|
85
|
addConfiguratorPage();
|
86
|
addDataSourcePage();
|
87
|
}
|
88
|
|
89
|
@Override
|
90
|
protected void addConfiguratorPage(){
|
91
|
List<String> ignoreMethods = new ArrayList<>();
|
92
|
ignoreMethods.add("setIgnoreNull");
|
93
|
ignoreMethods.add("setInteractWithUser");
|
94
|
ignoreMethods.add("setUseClassification");
|
95
|
pageConfiguration = GenericConfiguratorWizardPage.Import(CONFIGURATION_PAGE, getConfigurator(), ignoreMethods, Messages.ExcelDistributionUpdateWizard_ConfiguratorWizard_label);
|
96
|
addPage(pageConfiguration);
|
97
|
}
|
98
|
|
99
|
private void addDataSourcePage(){
|
100
|
dataSourcePage = new ImportFromFileAndChooseVocIdWizardPage("Choose Excel File",
|
101
|
"Please choose an xls file in the Distribution Update format.", new String[]{"*.xlsx", "*.xls", "*.*"});
|
102
|
addPage(dataSourcePage);
|
103
|
}
|
104
|
}
|