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.e4.in.excel.distribution;
|
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 javax.inject.Inject;
|
21
|
|
22
|
import org.apache.commons.io.IOUtils;
|
23
|
import org.apache.log4j.Logger;
|
24
|
import org.eclipse.core.runtime.jobs.Job;
|
25
|
import org.eclipse.e4.core.contexts.ContextInjectionFactory;
|
26
|
import org.eclipse.e4.core.contexts.IEclipseContext;
|
27
|
import org.eclipse.e4.ui.workbench.modeling.EPartService;
|
28
|
|
29
|
import eu.etaxonomy.cdm.database.DbSchemaValidation;
|
30
|
import eu.etaxonomy.cdm.io.distribution.excelupdate.ExcelDistributionUpdateConfigurator;
|
31
|
import eu.etaxonomy.taxeditor.io.e4.in.AbstractImportWizardE4;
|
32
|
import eu.etaxonomy.taxeditor.io.e4.in.GenericConfiguratorWizardPageE4;
|
33
|
import eu.etaxonomy.taxeditor.io.e4.in.ImportFromFileAndChooseVocIdWizardPageE4;
|
34
|
import eu.etaxonomy.taxeditor.l10n.Messages;
|
35
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
36
|
|
37
|
/**
|
38
|
* @author k.luther
|
39
|
* @date 03.05.2017
|
40
|
*
|
41
|
*/
|
42
|
public class ExcelDistributionUpdateWizardE4 extends AbstractImportWizardE4<ExcelDistributionUpdateConfigurator> {
|
43
|
|
44
|
|
45
|
private ExcelDistributionUpdateConfigurator configurator;
|
46
|
|
47
|
private ImportFromFileAndChooseVocIdWizardPageE4 dataSourcePage;
|
48
|
|
49
|
private static final Logger logger = Logger.getLogger(ExcelDistributionUpdateWizardE4.class);
|
50
|
|
51
|
@Inject
|
52
|
public ExcelDistributionUpdateWizardE4(IEclipseContext context, EPartService partService) {
|
53
|
super(context, partService);
|
54
|
}
|
55
|
|
56
|
/** {@inheritDoc} */
|
57
|
@Override
|
58
|
public ExcelDistributionUpdateConfigurator getConfigurator() {
|
59
|
return configurator;
|
60
|
}
|
61
|
|
62
|
/** {@inheritDoc} */
|
63
|
@Override
|
64
|
public boolean performFinish() {
|
65
|
URI source = dataSourcePage.getUri();
|
66
|
// configurator.setSource(source);
|
67
|
configurator.setDbSchemaValidation(DbSchemaValidation.CREATE);
|
68
|
File file = new File(source);
|
69
|
FileInputStream fis = null;
|
70
|
|
71
|
try {
|
72
|
fis = new FileInputStream(file);
|
73
|
} catch (FileNotFoundException e) {
|
74
|
logger.error("Error while reading file" + source.toString());
|
75
|
}
|
76
|
try {
|
77
|
configurator.setStream(IOUtils.toByteArray(fis));
|
78
|
} catch (IOException e) {
|
79
|
// TODO Auto-generated catch block
|
80
|
e.printStackTrace();
|
81
|
}
|
82
|
UUID vocUuid = dataSourcePage.getVocUuid();
|
83
|
|
84
|
configurator.setAreaVocabularyUuid(vocUuid);
|
85
|
//CdmStore.getImportManager().runMoniteredOperation(configurator, new File(source), SOURCE_TYPE.INPUTSTREAM);
|
86
|
Job job = CdmStore.getImportManager().createIOServiceJob(configurator);
|
87
|
CdmStore.getImportManager().run(job);
|
88
|
|
89
|
return true;
|
90
|
}
|
91
|
|
92
|
/** {@inheritDoc} */
|
93
|
@Override
|
94
|
public void init() {
|
95
|
configurator = CdmStore.getImportManager().ExcelDistributionUpdateConfigurator();
|
96
|
|
97
|
}
|
98
|
|
99
|
/** {@inheritDoc} */
|
100
|
@Override
|
101
|
public void addPages() {
|
102
|
addDataSourcePage();
|
103
|
addConfiguratorPage();
|
104
|
|
105
|
}
|
106
|
@Override
|
107
|
protected void addConfiguratorPage(){
|
108
|
List<String> ignoreMethods = new ArrayList<>();
|
109
|
ignoreMethods.add("setIgnoreNull");
|
110
|
ignoreMethods.add("setInteractWithUser");
|
111
|
ignoreMethods.add("setUseClassification");
|
112
|
pageConfiguration = ContextInjectionFactory.make(GenericConfiguratorWizardPageE4.class, context);
|
113
|
pageConfiguration.initImport(getConfigurator(), ignoreMethods, Messages.ExcelDistributionUpdateWizard_ConfiguratorWizard_label);
|
114
|
addPage(pageConfiguration);
|
115
|
}
|
116
|
|
117
|
private void addDataSourcePage(){
|
118
|
dataSourcePage = ContextInjectionFactory.make(ImportFromFileAndChooseVocIdWizardPageE4.class, context);
|
119
|
addPage(dataSourcePage);
|
120
|
}
|
121
|
|
122
|
|
123
|
}
|