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.editor.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
|
|
20
|
import eu.etaxonomy.cdm.ext.occurrence.bioCase.BioCaseQueryServiceWrapper;
|
21
|
import eu.etaxonomy.cdm.io.common.CdmDefaultImport;
|
22
|
import eu.etaxonomy.cdm.io.specimen.abcd206.in.Abcd206ImportConfigurator;
|
23
|
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
|
24
|
import eu.etaxonomy.taxeditor.editor.view.dataimport.transientServices.TransientCdmRepository;
|
25
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
26
|
|
27
|
/**
|
28
|
* @author pplitzner
|
29
|
* @date Sep 3, 2014
|
30
|
*
|
31
|
*/
|
32
|
public class SpecimenImportView extends DataImportView<SpecimenOrObservationBase<?>> {
|
33
|
|
34
|
public static final String ID = "eu.etaxonomy.taxeditor.editor.view.dataimport.SpecimenImportView"; //$NON-NLS-1$
|
35
|
|
36
|
private URI endPoint;
|
37
|
|
38
|
public SpecimenImportView() {
|
39
|
}
|
40
|
|
41
|
/**
|
42
|
* @param endPoint
|
43
|
*/
|
44
|
public void setEndpoint(URI endPoint) {
|
45
|
this.endPoint = endPoint;
|
46
|
}
|
47
|
|
48
|
/* (non-Javadoc)
|
49
|
* @see eu.etaxonomy.taxeditor.editor.view.dataimport.DataImportView#getTextForTableItem(java.lang.Object)
|
50
|
*/
|
51
|
@Override
|
52
|
protected String getTextForTableItem(SpecimenOrObservationBase<?> item) {
|
53
|
return item.getTitleCache();
|
54
|
}
|
55
|
|
56
|
/* (non-Javadoc)
|
57
|
* @see eu.etaxonomy.taxeditor.editor.view.dataimport.DataImportView#query()
|
58
|
*/
|
59
|
@Override
|
60
|
public void query() {
|
61
|
String errorMessage = "Could not execute query " + query;
|
62
|
|
63
|
Collection<SpecimenOrObservationBase<?>> results = new ArrayList<SpecimenOrObservationBase<?>>();
|
64
|
try {
|
65
|
//FIXME move ABCD import to cdmlib -> this will also get rid of the transient services
|
66
|
InputStream resultStream;
|
67
|
resultStream = new BioCaseQueryServiceWrapper().query(query, endPoint);
|
68
|
Abcd206ImportConfigurator configurator = Abcd206ImportConfigurator.NewInstance(resultStream, null, false);
|
69
|
TransientCdmRepository repo =
|
70
|
new TransientCdmRepository(CdmStore.getCurrentApplicationConfiguration());
|
71
|
configurator.setCdmAppController(repo);
|
72
|
|
73
|
CdmDefaultImport<Abcd206ImportConfigurator> importer = new CdmDefaultImport<Abcd206ImportConfigurator>();
|
74
|
importer.invoke(configurator);
|
75
|
results = repo.getUnits();
|
76
|
setResults(results);
|
77
|
} catch (ClientProtocolException e) {
|
78
|
logger.error(errorMessage, e);
|
79
|
} catch (IOException e) {
|
80
|
logger.error(errorMessage, e);
|
81
|
}
|
82
|
|
83
|
setResults(results);
|
84
|
|
85
|
}
|
86
|
|
87
|
}
|