Project

General

Profile

Revision d94e59f0

IDd94e59f01097b42813b4832ede8848affd33e495
Parent 2ec82aef
Child c03c14f8

Added by Katja Luther about 4 years ago

ref #6619: integrate excel distribution update in taxeditor

View differences:

eu.etaxonomy.taxeditor.store/OSGI-INF/l10n/bundle.properties
176 176
viewCommandMapping.viewerName.TAXON_NODE_WIZARD = Taxon node Wizard
177 177
command.label.CHANGE_PASSWORD = Change password
178 178
wizard.name.22 = Output Model
179
wizard.name.23 = Excel Distribution Data Update
179 180
command.label.25 = Import Preferences
eu.etaxonomy.taxeditor.store/OSGI-INF/l10n/bundle_de.properties
177 177
viewCommandMapping.viewerName.TAXON_NODE_WIZARD = Taxonknoten-Wizard
178 178
command.label.CHANGE_PASSWORD = Kennwort ?ndern
179 179
wizard.name.22 = Output Model
180
wizard.name.23 = Excel Verbreitungsdaten Update
180 181
command.label.25 = Import Pr?ferenzen
eu.etaxonomy.taxeditor.store/plugin.xml
785 785
            id="eu.etaxonomy.taxeditor.io.import.abcd"
786 786
            name="%wizard.name.3">
787 787
      </wizard>
788
       <wizard
789
            category="eu.etaxonomy.taxeditor.import.category.cdm"
790
            class="eu.etaxonomy.taxeditor.io.wizard.ExcelDistributionUpdateWizard"
791
            id="eu.etaxonomy.taxeditor.io.import.excelDistribution"
792
            name="%wizard.name.23">
793
      </wizard>
788 794
      <wizard
789 795
            category="eu.etaxonomy.taxeditor.import.category.cdm"
790 796
            class="eu.etaxonomy.taxeditor.io.wizard.SddImportWizard"
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/io/AbstractIOManager.java
29 29
	protected ICdmRepository applicationConfiguration;
30 30

  
31 31
	public static enum TYPE {
32
		Jaxb, Tcs, Excel_Taxa, Endnote, Sdd, Abcd, SpecimenCdmExcel, Excel_Name, SpecimenSearch, Gbif
32
		Jaxb, Tcs, Excel_Taxa, Endnote, Sdd, Abcd, SpecimenCdmExcel, Excel_Name, SpecimenSearch, Gbif, Excel_Distribution
33 33
	}
34 34

  
35 35
	/**
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/io/ImportManager.java
36 36
import eu.etaxonomy.cdm.io.common.ImportConfiguratorBase;
37 37
import eu.etaxonomy.cdm.io.common.ImportResult;
38 38
import eu.etaxonomy.cdm.io.common.SortIndexUpdaterConfigurator;
39
import eu.etaxonomy.cdm.io.distribution.excelupdate.ExcelDistributionUpdateConfigurator;
39 40
import eu.etaxonomy.cdm.io.dwca.in.DwcaImportConfigurator;
40 41
import eu.etaxonomy.cdm.io.excel.taxa.NormalExplicitImportConfigurator;
41 42
import eu.etaxonomy.cdm.io.jaxb.JaxbImportConfigurator;
......
309 310
		    return Abcd206ImportConfigurator.NewInstance(null, null);
310 311
		case Gbif:
311 312
		    return DwcaImportConfigurator.NewInstance(null, null);
313
		case Excel_Distribution:
314
            return ExcelDistributionUpdateConfigurator.NewInstance(null, null, null);
312 315
		default:
313 316
			MessagingUtils.notImplementedMessage(this);
314 317
			throw new IllegalArgumentException("Import not supported yet");
......
516 519
                } else if (configurator instanceof CacheUpdaterConfigurator){
517 520
                    CacheUpdaterConfigurator config = (CacheUpdaterConfigurator) configurator;
518 521
                    ioService.updateCaches(config);
522
                } else if (configurator instanceof ExcelDistributionUpdateConfigurator){
523
                    ExcelDistributionUpdateConfigurator config = (ExcelDistributionUpdateConfigurator) configurator;
524
                    ioService.updateDistributionData(config);
519 525
                }
520 526

  
521 527
                monitor.done();
......
536 542

  
537 543
    }
538 544

  
545
    /**
546
     * @return
547
     */
548
    public ExcelDistributionUpdateConfigurator ExcelDistributionUpdateConfigurator() {
549
        return (ExcelDistributionUpdateConfigurator) getConfigurator(TYPE.Excel_Distribution);
550
    }
551

  
539 552

  
540 553

  
541 554

  
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/io/wizard/ExcelDistributionUpdateWizard.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.UUID;
17

  
18
import org.apache.commons.io.IOUtils;
19
import org.apache.log4j.Logger;
20
import org.eclipse.core.runtime.jobs.Job;
21
import org.eclipse.jface.viewers.IStructuredSelection;
22
import org.eclipse.ui.IWorkbench;
23

  
24
import eu.etaxonomy.cdm.database.DbSchemaValidation;
25
import eu.etaxonomy.cdm.io.distribution.excelupdate.ExcelDistributionUpdateConfigurator;
26
import eu.etaxonomy.taxeditor.store.CdmStore;
27

  
28
/**
29
 * @author k.luther
30
 * @date 03.05.2017
31
 *
32
 */
33
public class ExcelDistributionUpdateWizard extends AbstractImportWizard<ExcelDistributionUpdateConfigurator> {
34
    private ExcelDistributionUpdateConfigurator configurator;
35

  
36
    private ImportFromFileAndChooseVocIdWizardOage dataSourcePage;
37

  
38
    private static final Logger logger = Logger.getLogger(ExcelDistributionUpdateWizard.class);
39

  
40
    /* (non-Javadoc)
41
     * @see eu.etaxonomy.taxeditor.io.wizard.AbstractImportWizard#getConfigurator()
42
     */
43
    /** {@inheritDoc} */
44
    @Override
45
    public ExcelDistributionUpdateConfigurator getConfigurator() {
46
        return configurator;
47
    }
48

  
49
    /* (non-Javadoc)
50
     * @see org.eclipse.jface.wizard.Wizard#performFinish()
51
     */
52
    /** {@inheritDoc} */
53
    @Override
54
    public boolean performFinish() {
55
        URI source = dataSourcePage.getUri();
56
       // configurator.setSource(source);
57
        configurator.setDbSchemaValidation(DbSchemaValidation.CREATE);
58
        File file = new File(source);
59
        FileInputStream fis = null;
60

  
61
        try {
62
            fis = new FileInputStream(file);
63
        } catch (FileNotFoundException e) {
64
            logger.error("Error while reading file" + source.toString());
65
        }
66
        try {
67
            configurator.setStream(IOUtils.toByteArray(fis));
68
        } catch (IOException e) {
69
            // TODO Auto-generated catch block
70
            e.printStackTrace();
71
        }
72
        UUID vocUuid = dataSourcePage.getVocUuid();
73

  
74
        configurator.setAreaVocabularyUuid(vocUuid);
75
        Job job = CdmStore.getImportManager().createIOServiceJob(configurator);
76
        CdmStore.getImportManager().run(job);
77

  
78
        return true;
79
    }
80

  
81
    /* (non-Javadoc)
82
     * @see org.eclipse.ui.IWorkbenchWizard#init(org.eclipse.ui.IWorkbench, org.eclipse.jface.viewers.IStructuredSelection)
83
     */
84
    /** {@inheritDoc} */
85
    @Override
86
    public void init(IWorkbench workbench, IStructuredSelection selection) {
87
        super.init(workbench, selection);
88
        configurator =  CdmStore.getImportManager().ExcelDistributionUpdateConfigurator();
89

  
90
    }
91

  
92
    /* (non-Javadoc)
93
     * @see eu.etaxonomy.taxeditor.io.wizard.AbstractImportWizard#addPages()
94
     */
95
    /** {@inheritDoc} */
96
    @Override
97
    public void addPages() {
98
        super.addPages();
99

  
100
        dataSourcePage = new ImportFromFileAndChooseVocIdWizardOage("Choose NormalExplicit",
101
                "Please choose an xls file in the NormalExplicit format.", new String[]{"*.xlsx", "*.xls", "*.*"});
102
        addPage(dataSourcePage);
103
    }
104
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/io/wizard/ImportFromFileAndChooseVocIdWizardOage.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.util.List;
12
import java.util.UUID;
13

  
14
import org.eclipse.swt.SWT;
15
import org.eclipse.swt.events.SelectionAdapter;
16
import org.eclipse.swt.events.SelectionEvent;
17
import org.eclipse.swt.widgets.Combo;
18
import org.eclipse.swt.widgets.Composite;
19

  
20
import eu.etaxonomy.cdm.api.service.IVocabularyService;
21
import eu.etaxonomy.cdm.common.CdmUtils;
22
import eu.etaxonomy.cdm.model.common.DefinedTermBase;
23
import eu.etaxonomy.cdm.model.common.TermType;
24
import eu.etaxonomy.cdm.model.common.TermVocabulary;
25
import eu.etaxonomy.taxeditor.store.CdmStore;
26

  
27
/**
28
 * @author k.luther
29
 * @date 04.05.2017
30
 *
31
 */
32
public class ImportFromFileAndChooseVocIdWizardOage extends ImportFromFileDataSourceWizardPage {
33

  
34
    private Combo vocabularyCombo;
35
    UUID vocUuid;
36
    String[][] labelAndValues;
37
    /**
38
     * @param title
39
     * @param description
40
     * @param extensions
41
     */
42
    protected ImportFromFileAndChooseVocIdWizardOage(String title, String description, String[] extensions) {
43
        super(title, description, extensions);
44

  
45
    }
46

  
47
    @Override
48
    public void createControl(Composite parent) {
49
        super.createControl(parent);
50
        Composite composite = (Composite)getControl();
51
      //  final Composite composite = new Composite(parent, SWT.NULL);
52

  
53
        vocabularyCombo = new Combo(composite, SWT.DROP_DOWN);
54
        List<TermVocabulary<DefinedTermBase>> vocs = CdmStore.getService(IVocabularyService.class).findByTermType(TermType.NamedArea);
55
        for(TermVocabulary voc: vocs){
56
            vocabularyCombo.add(voc.getLabel());
57
        }
58
        getLabelAndValues(vocs);
59
        vocabularyCombo.addSelectionListener(new SelectionAdapter(){
60

  
61
            @Override
62
            public void widgetSelected(SelectionEvent e) {
63
                String name = vocabularyCombo.getText();
64

  
65
                for (String[] labelAndValue: labelAndValues){
66
                    if (labelAndValue[0].equals(name)){
67
                        String uuidString = labelAndValue[1];
68
                        vocUuid = UUID.fromString(uuidString);
69
                        if (text_source.getText() != null){
70
                            setPageComplete(true);
71
                        } else{
72
                            setPageComplete(false);
73
                        }
74
                    }
75
                }
76

  
77
            }
78

  
79
        });
80
        //setControl(composite);
81
    }
82

  
83
    public UUID getVocUuid() {
84
        return vocUuid;
85
    }
86

  
87
    public void setVocUuid(UUID vocUuid) {
88
        this.vocUuid = vocUuid;
89
    }
90

  
91
    /**
92
     * @return
93
     */
94
    private String[][] getLabelAndValues(List<TermVocabulary<DefinedTermBase>> vocs) {
95

  
96
        labelAndValues = new String[vocs.size()][2];
97
        for (int i = 0; i < vocs.size(); i++) {
98
            labelAndValues[i][0] = vocs.get(i).getLabel();
99
            labelAndValues[i][1] = vocs.get(i).getUuid().toString();
100
        }
101
        return labelAndValues;
102
    }
103

  
104
    @Override
105
    public boolean isPageComplete() {
106
        boolean result = CdmUtils.isNotBlank(text_source.getText()) && vocUuid != null;
107

  
108
        return result;
109
    }
110

  
111
}

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)