Project

General

Profile

Download (3.66 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
 * Copyright (C) 2014 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.view.dataimport;
10

    
11
import java.io.IOException;
12
import java.io.InputStream;
13
import java.util.ArrayList;
14
import java.util.Collection;
15

    
16
import org.apache.http.client.ClientProtocolException;
17
import org.eclipse.swt.widgets.Display;
18

    
19
import eu.etaxonomy.cdm.common.URI;
20
import eu.etaxonomy.cdm.ext.occurrence.OccurenceQuery;
21
import eu.etaxonomy.cdm.ext.occurrence.bioCase.BioCaseQueryServiceWrapper;
22
import eu.etaxonomy.cdm.io.common.CdmDefaultImport;
23
import eu.etaxonomy.cdm.io.specimen.abcd206.in.Abcd206ImportConfigurator;
24
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
25
import eu.etaxonomy.taxeditor.store.CdmStore;
26

    
27
/**
28
 * @author pplitzner
29
 * @date 25.02.2014
30
 */
31
public class BioCaseEditorInput extends DataImportEditorInput<SpecimenOrObservationBase<?>> {
32

    
33
    private final URI endPoint;
34

    
35
    /**
36
     * Constructs a new BioCaseEditorInput.
37
     * @param query The {@link OccurenceQuery} object holding all necessary parameters.
38
     * @param endPoint If the endPoint {@link URI} is <code>null</code> then the default endPoint is used
39
     * (<i>http://ww3.bgbm.org/biocase/pywrapper.cgi?dsa=Herbar</i>)
40
     */
41
    public BioCaseEditorInput(OccurenceQuery query, URI endPoint) {
42
        super();
43
        this.query = query;
44
        this.endPoint = endPoint;
45
    }
46

    
47
    @Override
48
    public void query(){
49
        String errorMessage = "Could not execute query " + query;
50

    
51
        Collection<SpecimenOrObservationBase<?>> results = new ArrayList<SpecimenOrObservationBase<?>>();
52
        try {
53
            //FIXME move ABCD import to cdmlib -> this will also get rid of the transient services
54
            InputStream resultStream;
55
            resultStream = new BioCaseQueryServiceWrapper().query(query, endPoint);
56
            Abcd206ImportConfigurator configurator = Abcd206ImportConfigurator.NewInstance(endPoint, null, false);
57
           /* TransientCdmRepository repo =
58
                    new TransientCdmRepository(CdmStore.getCurrentApplicationConfiguration());
59
            configurator.setCdmAppController(repo);
60
*/
61
            CdmDefaultImport<Abcd206ImportConfigurator> importer = new CdmDefaultImport<Abcd206ImportConfigurator>();
62
            importer.invoke(configurator);
63
           // results = repo.getUnits();
64
            setResults(results);
65
        } catch (ClientProtocolException e) {
66
            logger.error(errorMessage, e);
67
        } catch (IOException e) {
68
            logger.error(errorMessage, e);
69
        }
70

    
71
        setResults(results);
72

    
73
        Display.getDefault().asyncExec(new Runnable() {
74

    
75
            @Override
76
            public void run() {
77
                CdmStore.getContextManager().notifyContextRefresh();
78
            }
79
        });
80
    }
81

    
82
    @Override
83
    public int hashCode() {
84
        final int prime = 31;
85
        int result = 1;
86
        result = prime * result + ((query == null) ? 0 : query.hashCode());
87
        return result;
88
    }
89

    
90
    @Override
91
    public boolean equals(Object obj) {
92
        if (this == obj) {
93
            return true;
94
        }
95
        if (obj == null) {
96
            return false;
97
        }
98
        if (getClass() != obj.getClass()) {
99
            return false;
100
        }
101
        BioCaseEditorInput other = (BioCaseEditorInput) obj;
102
        if (query == null) {
103
            if (other.query != null) {
104
                return false;
105
            }
106
        } else if (!query.equals(other.query)) {
107
            return false;
108
        }
109
        return true;
110
    }
111
}
(1-1/7)