Merge branch 'develop' into feature/cdm-4.7
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / io / wizard / RISImportWizard.java
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
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.database.DbSchemaValidation;
26 import eu.etaxonomy.cdm.io.common.IImportConfigurator.SOURCE_TYPE;
27 import eu.etaxonomy.cdm.io.reference.ris.in.RisReferenceImportConfigurator;
28 import eu.etaxonomy.taxeditor.store.CdmStore;
29
30 /**
31 * @author k.luther
32 * @date 12.05.2017
33 *
34 */
35 public class RISImportWizard extends AbstractImportWizard<RisReferenceImportConfigurator>{
36 private RisReferenceImportConfigurator configurator;
37
38 private ImportFromFileDataSourceWizardPage dataSourcePage;
39
40 private static final Logger logger = Logger.getLogger(ExcelDistributionUpdateWizard.class);
41
42 /* (non-Javadoc)
43 * @see eu.etaxonomy.taxeditor.io.wizard.AbstractImportWizard#getConfigurator()
44 */
45 /** {@inheritDoc} */
46 @Override
47 public RisReferenceImportConfigurator getConfigurator() {
48 return configurator;
49 }
50
51 /* (non-Javadoc)
52 * @see org.eclipse.jface.wizard.Wizard#performFinish()
53 */
54 /** {@inheritDoc} */
55 @Override
56 public boolean performFinish() {
57 URI source = dataSourcePage.getUri();
58 // configurator.setSource(source);
59 // try {
60 // configurator = RisReferenceImportConfigurator.NewInstance(source, null);
61 // } catch (MalformedURLException e1) {
62 // // TODO Auto-generated catch block
63 // e1.printStackTrace();
64 // } catch (IOException e1) {
65 // // TODO Auto-generated catch block
66 // e1.printStackTrace();
67 // }
68 configurator.setDbSchemaValidation(DbSchemaValidation.CREATE);
69 File file = new File(source);
70 FileInputStream fis;
71
72 try {
73 fis = new FileInputStream(file);
74 byte[] data;
75 data = IOUtils.toByteArray(fis);
76 configurator.setStream(data);
77 //TODO: workaround, needs to be changed to source as byte array
78 Job job = CdmStore.getImportManager().createIOServiceJob(configurator, data, SOURCE_TYPE.INPUTSTREAM);
79 CdmStore.getImportManager().run(job);
80 } catch (FileNotFoundException e) {
81 logger.error("Error while reading file" + source.toString());
82 } catch (IOException e){
83
84 }
85
86 //CdmStore.getImportManager().runMoniteredOperation(configurator, new File(source), SOURCE_TYPE.INPUTSTREAM);
87
88
89 return true;
90 }
91
92 /* (non-Javadoc)
93 * @see org.eclipse.ui.IWorkbenchWizard#init(org.eclipse.ui.IWorkbench, org.eclipse.jface.viewers.IStructuredSelection)
94 */
95 /** {@inheritDoc} */
96 @Override
97 public void init(IWorkbench workbench, IStructuredSelection selection) {
98 super.init(workbench, selection);
99 configurator = RisReferenceImportConfigurator.NewInstance();
100
101 }
102
103 /* (non-Javadoc)
104 * @see eu.etaxonomy.taxeditor.io.wizard.AbstractImportWizard#addPages()
105 */
106 /** {@inheritDoc} */
107 @Override
108 public void addPages() {
109 //addConfiguratorPage();
110 addDataSourcePage();
111
112
113 }
114 @Override
115 protected void addConfiguratorPage(){
116 List<String> ignoreMethods = new ArrayList<>();
117 ignoreMethods.add("setIgnoreNull");
118 ignoreMethods.add("setInteractWithUser");
119 ignoreMethods.add("setUseClassification");
120 pageConfiguration = GenericConfiguratorWizardPage.Import(CONFIGURATION_PAGE, getConfigurator(), ignoreMethods, "Ris Import");
121 addPage(pageConfiguration);
122 }
123
124 private void addDataSourcePage(){
125 dataSourcePage = new ImportFromFileDataSourceWizardPage("Choose Ris File",
126 "Please choose an xls file in the Distribution Update format.", new String[]{"*.txt"});
127 addPage(dataSourcePage);
128 }
129
130 }