1
|
/**
|
2
|
* Copyright (C) 2007 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.taxa;
|
10
|
|
11
|
import java.io.File;
|
12
|
import java.io.FileInputStream;
|
13
|
import java.io.FileNotFoundException;
|
14
|
import java.io.IOException;
|
15
|
import eu.etaxonomy.cdm.common.URI;
|
16
|
import java.util.ArrayList;
|
17
|
import java.util.List;
|
18
|
|
19
|
import javax.inject.Inject;
|
20
|
import javax.inject.Named;
|
21
|
|
22
|
import org.apache.commons.io.IOUtils;
|
23
|
import org.apache.logging.log4j.LogManager;import org.apache.logging.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.core.di.annotations.Optional;
|
28
|
import org.eclipse.e4.ui.services.IServiceConstants;
|
29
|
import org.eclipse.e4.ui.workbench.modeling.EPartService;
|
30
|
import org.eclipse.jface.viewers.IStructuredSelection;
|
31
|
import org.eclipse.jface.viewers.TreeSelection;
|
32
|
|
33
|
import eu.etaxonomy.cdm.database.DbSchemaValidation;
|
34
|
import eu.etaxonomy.cdm.io.common.IImportConfigurator.SOURCE_TYPE;
|
35
|
import eu.etaxonomy.cdm.io.excel.taxa.NormalExplicitImportConfigurator;
|
36
|
import eu.etaxonomy.cdm.persistence.dto.TaxonNodeDto;
|
37
|
import eu.etaxonomy.taxeditor.io.e4.in.AbstractImportWizardE4;
|
38
|
import eu.etaxonomy.taxeditor.io.e4.in.GenericConfiguratorWizardPageE4;
|
39
|
import eu.etaxonomy.taxeditor.io.e4.in.ImportFromFileDataSourceWithReferenceWizardPage;
|
40
|
import eu.etaxonomy.taxeditor.l10n.Messages;
|
41
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
42
|
|
43
|
|
44
|
/**
|
45
|
* @author pplitzner
|
46
|
* @since Oct 5, 2017
|
47
|
*/
|
48
|
public class ExcelNormalExplicitTaxaImportWizardE4 extends AbstractImportWizardE4<NormalExplicitImportConfigurator>{
|
49
|
|
50
|
private NormalExplicitImportConfigurator configurator;
|
51
|
|
52
|
private ImportFromFileDataSourceWithReferenceWizardPage dataSourcePage;
|
53
|
private static final Logger logger = LogManager.getLogger(ExcelNormalExplicitTaxaImportWizardE4.class);
|
54
|
|
55
|
@Inject
|
56
|
public ExcelNormalExplicitTaxaImportWizardE4(IEclipseContext context, EPartService partService,
|
57
|
@Optional@Named(IServiceConstants.ACTIVE_SELECTION)IStructuredSelection selection) {
|
58
|
super(context, partService, selection);
|
59
|
}
|
60
|
|
61
|
@Override
|
62
|
public NormalExplicitImportConfigurator getConfigurator() {
|
63
|
return configurator;
|
64
|
}
|
65
|
|
66
|
@Override
|
67
|
public boolean performFinish() {
|
68
|
URI source = dataSourcePage.getUri();
|
69
|
configurator.setSource(source);
|
70
|
configurator.setDbSchemaValidation(DbSchemaValidation.CREATE);
|
71
|
configurator.setSourceReferenceTitle(dataSourcePage.getTextReferenceString().getText());
|
72
|
File file = new File(source.getJavaUri());
|
73
|
FileInputStream fis = null;
|
74
|
|
75
|
try {
|
76
|
fis = new FileInputStream(file);
|
77
|
} catch (FileNotFoundException e) {
|
78
|
logger.error("Error while reading file" + source.toString());
|
79
|
}
|
80
|
try {
|
81
|
configurator.setStream(IOUtils.toByteArray(fis));
|
82
|
} catch (IOException e) {
|
83
|
// TODO Auto-generated catch block
|
84
|
e.printStackTrace();
|
85
|
}
|
86
|
Job job = CdmStore.getImportManager().createIOServiceJob(configurator,file , SOURCE_TYPE.INPUTSTREAM);
|
87
|
CdmStore.getImportManager().run(job);
|
88
|
|
89
|
return true;
|
90
|
}
|
91
|
|
92
|
@Override
|
93
|
public void init() {
|
94
|
configurator = CdmStore.getImportManager().NormalExplicitConfigurator();
|
95
|
if (selection instanceof TreeSelection && !selection.isEmpty()){
|
96
|
TaxonNodeDto node = (TaxonNodeDto)selection.getFirstElement();
|
97
|
configurator.setParentUUID(node.getTaxonUuid());
|
98
|
configurator.setClassificationUuid(node.getClassificationUUID());
|
99
|
}
|
100
|
}
|
101
|
|
102
|
@Override
|
103
|
public void addPages() {
|
104
|
dataSourcePage = ContextInjectionFactory.make(ImportFromFileDataSourceWithReferenceWizardPage.class, context);
|
105
|
dataSourcePage.setTitle("Choose NormalExplicit");
|
106
|
dataSourcePage.setDescription("Please choose an xls file in the NormalExplicit format.");
|
107
|
dataSourcePage.setExtensions(new String[]{"*.xlsx", "*.xls", "*.*"});
|
108
|
addPage(dataSourcePage);
|
109
|
super.addPages();
|
110
|
}
|
111
|
|
112
|
@Override
|
113
|
protected void addConfiguratorPage(){
|
114
|
List<String> ignoreMethods = new ArrayList<>();
|
115
|
ignoreMethods.add("setIgnoreNull");
|
116
|
ignoreMethods.add("setInteractWithUser");
|
117
|
ignoreMethods.add("setUseClassification");
|
118
|
ignoreMethods.add("setRegisterAuditing");
|
119
|
ignoreMethods.add("setDeduplicateAuthors");
|
120
|
ignoreMethods.add("setDeduplicateReferences");
|
121
|
pageConfiguration = ContextInjectionFactory.make(GenericConfiguratorWizardPageE4.class, context);
|
122
|
pageConfiguration.initImport(getConfigurator(), ignoreMethods, Messages.ExcelTaxonUpdateWizard_ConfiguratorWizard_label);
|
123
|
addPage(pageConfiguration);
|
124
|
}
|
125
|
}
|