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