Project

General

Profile

Download (3.8 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.net.URI;
14
import java.util.ArrayList;
15
import java.util.Collection;
16

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

    
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
 */
32
public class BioCaseEditorInput extends DataImportEditorInput<SpecimenOrObservationBase<?>> {
33

    
34
    private final URI endPoint;
35

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

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

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

    
72
        setResults(results);
73

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

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

    
83
    /* (non-Javadoc)
84
     * @see java.lang.Object#hashCode()
85
     */
86
    @Override
87
    public int hashCode() {
88
        final int prime = 31;
89
        int result = 1;
90
        result = prime * result + ((query == null) ? 0 : query.hashCode());
91
        return result;
92
    }
93

    
94
    /* (non-Javadoc)
95
     * @see java.lang.Object#equals(java.lang.Object)
96
     */
97
    @Override
98
    public boolean equals(Object obj) {
99
        if (this == obj) {
100
            return true;
101
        }
102
        if (obj == null) {
103
            return false;
104
        }
105
        if (getClass() != obj.getClass()) {
106
            return false;
107
        }
108
        BioCaseEditorInput other = (BioCaseEditorInput) obj;
109
        if (query == null) {
110
            if (other.query != null) {
111
                return false;
112
            }
113
        } else if (!query.equals(other.query)) {
114
            return false;
115
        }
116
        return true;
117
    }
118
}
(1-1/7)