Revision 0d19c47e
Added by Katja Luther over 7 years ago
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/dataimport/SaveImportedSpecimenAction.java | ||
---|---|---|
1 | 1 |
package eu.etaxonomy.taxeditor.view.dataimport; |
2 | 2 |
|
3 |
import java.io.IOException; |
|
4 |
import java.net.URI; |
|
5 |
import java.util.ArrayList; |
|
3 | 6 |
import java.util.Collection; |
7 |
import java.util.Collections; |
|
8 |
import java.util.Comparator; |
|
4 | 9 |
import java.util.HashSet; |
10 |
import java.util.List; |
|
5 | 11 |
import java.util.Set; |
6 | 12 |
|
13 |
import org.apache.http.client.ClientProtocolException; |
|
7 | 14 |
import org.apache.log4j.Logger; |
8 | 15 |
import org.eclipse.core.runtime.jobs.Job; |
9 | 16 |
import org.eclipse.jface.action.Action; |
17 |
import org.eclipse.jface.text.source.Annotation; |
|
10 | 18 |
import org.eclipse.swt.widgets.Table; |
11 | 19 |
import org.eclipse.swt.widgets.TableItem; |
12 | 20 |
import org.eclipse.ui.IWorkbenchPart; |
... | ... | |
17 | 25 |
import eu.etaxonomy.cdm.api.service.IOccurrenceService; |
18 | 26 |
import eu.etaxonomy.cdm.api.service.ITermService; |
19 | 27 |
import eu.etaxonomy.cdm.ext.occurrence.OccurenceQuery; |
28 |
import eu.etaxonomy.cdm.ext.occurrence.gbif.DataSetResponse; |
|
20 | 29 |
import eu.etaxonomy.cdm.ext.occurrence.gbif.GbifDataSetProtocol; |
30 |
import eu.etaxonomy.cdm.ext.occurrence.gbif.GbifQueryServiceWrapper; |
|
21 | 31 |
import eu.etaxonomy.cdm.ext.occurrence.gbif.GbifResponse; |
22 |
import eu.etaxonomy.cdm.io.dwca.in.DwcaImportConfigurator; |
|
32 |
import eu.etaxonomy.cdm.io.specimen.abcd206.in.Abcd206ImportConfigurator; |
|
33 |
import eu.etaxonomy.cdm.io.specimen.gbif.in.*; |
|
23 | 34 |
import eu.etaxonomy.cdm.model.common.DefinedTermBase; |
24 | 35 |
import eu.etaxonomy.cdm.model.common.ICdmBase; |
25 | 36 |
import eu.etaxonomy.cdm.model.name.TaxonNameBase; |
... | ... | |
29 | 40 |
public class SaveImportedSpecimenAction extends Action { |
30 | 41 |
|
31 | 42 |
private final Logger logger = Logger.getLogger(SaveImportedSpecimenAction.class); |
43 |
|
|
44 |
private Comparator<GbifResponse> comparator; |
|
32 | 45 |
|
33 | 46 |
/* (non-Javadoc) |
34 | 47 |
* @see org.eclipse.jface.action.Action#run() |
... | ... | |
42 | 55 |
Table table = dataImportView.getTable(); |
43 | 56 |
Collection<GbifResponse> checkedResults = new HashSet<GbifResponse>(); |
44 | 57 |
Object data; |
45 |
Set<String[]> unitIds = new HashSet<String[]>(); |
|
58 |
Set<String[]> unitIdsGbif = new HashSet<String[]>(); |
|
59 |
Set<String[]> unitIdsBioCase = new HashSet<String[]>(); |
|
60 |
List<GbifResponse> biocaseResponses = new ArrayList<GbifResponse>(); |
|
61 |
|
|
46 | 62 |
for(TableItem item:table.getItems()){ |
47 | 63 |
if(item.getChecked()){ |
48 | 64 |
//Save Specimen |
... | ... | |
52 | 68 |
} |
53 | 69 |
} |
54 | 70 |
} |
71 |
String[] tripleId ; |
|
55 | 72 |
for (GbifResponse response:checkedResults){ |
56 | 73 |
if (response != null){ |
57 |
/*String[] tripleId = response.getTripleID(); |
|
58 |
unitIds.add(tripleId); |
|
59 |
*/ |
|
74 |
tripleId = response.getTripleID(); |
|
75 |
|
|
76 |
if (response.getDataSetProtocol().equals(GbifDataSetProtocol.BIOCASE)){ |
|
77 |
biocaseResponses.add(response); |
|
78 |
|
|
79 |
}else{ |
|
80 |
unitIdsGbif.add(tripleId); |
|
81 |
} |
|
82 |
|
|
83 |
|
|
60 | 84 |
} |
61 | 85 |
} |
86 |
Collections.sort(biocaseResponses, getComparator()); |
|
87 |
URI dataSetUri = null; |
|
88 |
Abcd206ImportConfigurator configuratorAbcd; |
|
89 |
List<Abcd206ImportConfigurator> abcdConfigurators = new ArrayList<Abcd206ImportConfigurator>(); |
|
90 |
DataSetResponse dataSetResponse; |
|
91 |
OccurenceQuery bioCaseOccurrenceQuery = null; |
|
92 |
for (GbifResponse response: biocaseResponses){ |
|
93 |
try { |
|
94 |
dataSetResponse = new GbifQueryServiceWrapper().queryOriginalDataSet(response); |
|
95 |
dataSetUri = dataSetResponse.getEndpoint(); |
|
96 |
} catch (ClientProtocolException e) { |
|
97 |
// TODO Auto-generated catch block |
|
98 |
e.printStackTrace(); |
|
99 |
} catch (IOException e) { |
|
100 |
// TODO Auto-generated catch block |
|
101 |
e.printStackTrace(); |
|
102 |
} |
|
103 |
if (!response.getDataSetUri().equals(dataSetUri)){ |
|
104 |
configuratorAbcd = Abcd206ImportConfigurator.NewInstance(dataSetUri, null, false); |
|
105 |
if (configuratorAbcd != null){ |
|
106 |
abcdConfigurators.add(configuratorAbcd); |
|
107 |
} |
|
108 |
unitIdsBioCase = new HashSet<String[]>(); |
|
109 |
bioCaseOccurrenceQuery = new OccurenceQuery(unitIdsBioCase); |
|
110 |
configuratorAbcd.setOccurenceQuery(bioCaseOccurrenceQuery); |
|
111 |
} |
|
112 |
tripleId = response.getTripleID(); |
|
113 |
unitIdsBioCase.add(tripleId); |
|
114 |
} |
|
115 |
|
|
116 |
OccurenceQuery query = new OccurenceQuery(unitIdsGbif); |
|
117 |
GbifImportConfigurator configurator = GbifImportConfigurator.newInstance(query); |
|
118 |
configurator.setSourceReferenceTitle("Import Gbif data"); |
|
62 | 119 |
|
63 |
DwcaImportConfigurator configurator = DwcaImportConfigurator.NewInstance(null, null); |
|
64 |
/* OccurenceQuery query = new OccurenceQuery(unitIds); |
|
65 |
configurator.setQuery(query); |
|
66 |
*/ |
|
67 |
/*Job job = CdmStore.getImportManager().createIOServiceJob(configurator); |
|
68 |
CdmStore.getImportManager().run(job); |
|
69 |
*/ |
|
120 |
|
|
121 |
|
|
122 |
// configurator.setQuery(query); |
|
123 |
|
|
124 |
Job bioCaseJob = CdmStore.getImportManager().createIOServiceJob(abcdConfigurators); |
|
125 |
CdmStore.getImportManager().run(bioCaseJob); |
|
126 |
|
|
127 |
Job gbifJob = CdmStore.getImportManager().createIOServiceJob(configurator); |
|
128 |
CdmStore.getImportManager().run(gbifJob); |
|
129 |
|
|
130 |
|
|
70 | 131 |
|
71 | 132 |
} |
72 | 133 |
} |
... | ... | |
80 | 141 |
} |
81 | 142 |
} |
82 | 143 |
} |
83 |
|
|
84 |
|
|
144 |
|
|
85 | 145 |
/* (non-Javadoc) |
86 | 146 |
* @see org.eclipse.jface.action.Action#getText() |
87 | 147 |
*/ |
... | ... | |
89 | 149 |
public String getText() { |
90 | 150 |
return "Import"; |
91 | 151 |
} |
92 |
|
|
152 |
|
|
153 |
private Comparator<GbifResponse> getComparator(){ |
|
154 |
if (comparator == null){ |
|
155 |
comparator = new GbifResponseComparator(); |
|
156 |
} |
|
157 |
return comparator; |
|
158 |
} |
|
159 |
|
|
160 |
|
|
93 | 161 |
} |
Also available in: Unified diff
changes for gbif/abcd import from webservice