Project

General

Profile

Download (4.17 KB) Statistics
| Branch: | Tag: | Revision:
1
// $Id$
2
/**
3
 * Copyright (C) 2014 EDIT
4
 * European Distributed Institute of Taxonomy
5
 * http://www.e-taxonomy.eu
6
 *
7
 * The contents of this file are subject to the Mozilla Public License Version 1.1
8
 * See LICENSE.TXT at the top of this package for the full license terms.
9
 */
10
package eu.etaxonomy.taxeditor.view.dataimport;
11

    
12
import java.io.IOException;
13
import java.io.InputStream;
14
import java.net.URI;
15
import java.util.ArrayList;
16
import java.util.Collection;
17

    
18
import org.apache.http.client.ClientProtocolException;
19
import org.eclipse.swt.widgets.Display;
20

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

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

    
35
    private final URI endPoint;
36

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

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

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

    
73
        setResults(results);
74

    
75
        Display.getDefault().asyncExec(new Runnable() {
76

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

    
84
    /* (non-Javadoc)
85
     * @see org.eclipse.ui.IEditorInput#getName()
86
     */
87
    @Override
88
    public String getName() {
89
        return "[BioCASE] " + query.toString();
90
    }
91

    
92
    /* (non-Javadoc)
93
     * @see org.eclipse.ui.IEditorInput#getToolTipText()
94
     */
95
    @Override
96
    public String getToolTipText() {
97
        return "[BioCASE] " + query.toString();
98
    }
99

    
100
    /* (non-Javadoc)
101
     * @see java.lang.Object#hashCode()
102
     */
103
    @Override
104
    public int hashCode() {
105
        final int prime = 31;
106
        int result = 1;
107
        result = prime * result + ((query == null) ? 0 : query.hashCode());
108
        return result;
109
    }
110

    
111
    /* (non-Javadoc)
112
     * @see java.lang.Object#equals(java.lang.Object)
113
     */
114
    @Override
115
    public boolean equals(Object obj) {
116
        if (this == obj) {
117
            return true;
118
        }
119
        if (obj == null) {
120
            return false;
121
        }
122
        if (getClass() != obj.getClass()) {
123
            return false;
124
        }
125
        BioCaseEditorInput other = (BioCaseEditorInput) obj;
126
        if (query == null) {
127
            if (other.query != null) {
128
                return false;
129
            }
130
        } else if (!query.equals(other.query)) {
131
            return false;
132
        }
133
        return true;
134
    }
135
}
(1-1/15)