2 * Copyright (C) 2017 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
9 package eu
.etaxonomy
.taxeditor
.io
.e4
.in
.ris
;
12 import java
.io
.FileInputStream
;
13 import java
.io
.FileNotFoundException
;
14 import java
.io
.IOException
;
16 import java
.util
.ArrayList
;
17 import java
.util
.List
;
19 import javax
.inject
.Inject
;
21 import org
.apache
.commons
.io
.IOUtils
;
22 import org
.apache
.log4j
.Logger
;
23 import org
.eclipse
.core
.runtime
.jobs
.Job
;
24 import org
.eclipse
.e4
.core
.contexts
.ContextInjectionFactory
;
25 import org
.eclipse
.e4
.core
.contexts
.IEclipseContext
;
26 import org
.eclipse
.e4
.ui
.workbench
.modeling
.EPartService
;
28 import eu
.etaxonomy
.cdm
.database
.DbSchemaValidation
;
29 import eu
.etaxonomy
.cdm
.io
.common
.IImportConfigurator
.SOURCE_TYPE
;
30 import eu
.etaxonomy
.cdm
.io
.reference
.ris
.in
.RisReferenceImportConfigurator
;
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
.ImportFromFileDataSourceWizardPageE4
;
34 import eu
.etaxonomy
.taxeditor
.io
.wizard
.ExcelDistributionUpdateWizard
;
35 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
42 public class RISImportWizardE4
extends AbstractImportWizardE4
<RisReferenceImportConfigurator
>{
44 private RisReferenceImportConfigurator configurator
;
46 private ImportFromFileDataSourceWizardPageE4 dataSourcePage
;
48 private static final Logger logger
= Logger
.getLogger(ExcelDistributionUpdateWizard
.class);
51 public RISImportWizardE4(IEclipseContext context
, EPartService partService
) {
52 super(context
, partService
);
57 public RisReferenceImportConfigurator
getConfigurator() {
63 public boolean performFinish() {
64 URI source
= dataSourcePage
.getUri();
65 configurator
.setDbSchemaValidation(DbSchemaValidation
.CREATE
);
66 File file
= new File(source
);
70 fis
= new FileInputStream(file
);
72 data
= IOUtils
.toByteArray(fis
);
73 configurator
.setStream(data
);
74 //TODO: workaround, needs to be changed to source as byte array
75 Job job
= CdmStore
.getImportManager().createIOServiceJob(configurator
, data
, SOURCE_TYPE
.INPUTSTREAM
);
76 CdmStore
.getImportManager().run(job
);
77 } catch (FileNotFoundException e
) {
78 logger
.error("Error while reading file" + source
.toString());
79 } catch (IOException e
){
89 configurator
= RisReferenceImportConfigurator
.NewInstance();
95 public void addPages() {
99 protected void addConfiguratorPage(){
100 List
<String
> ignoreMethods
= new ArrayList
<>();
101 ignoreMethods
.add("setIgnoreNull");
102 ignoreMethods
.add("setInteractWithUser");
103 ignoreMethods
.add("setUseClassification");
104 pageConfiguration
= ContextInjectionFactory
.make(GenericConfiguratorWizardPageE4
.class, context
);
105 pageConfiguration
.initImport(getConfigurator(), ignoreMethods
, "Ris Import");
106 addPage(pageConfiguration
);
109 private void addDataSourcePage(){
110 dataSourcePage
= ContextInjectionFactory
.make(ImportFromFileDataSourceWizardPageE4
.class, context
);
111 dataSourcePage
.setTitle("Choose Ris File");
112 dataSourcePage
.setDescription("Please choose an xls file in the Distribution Update format.");
113 dataSourcePage
.setExtensions(new String
[]{"*.txt"});
114 addPage(dataSourcePage
);