1
|
package eu.etaxonomy.taxeditor.view.dataimport;
|
2
|
|
3
|
import java.util.Collection;
|
4
|
import java.util.HashSet;
|
5
|
import java.util.Set;
|
6
|
|
7
|
import org.apache.log4j.Logger;
|
8
|
import org.eclipse.core.runtime.jobs.Job;
|
9
|
import org.eclipse.jface.action.Action;
|
10
|
import org.eclipse.swt.widgets.Table;
|
11
|
import org.eclipse.swt.widgets.TableItem;
|
12
|
import org.eclipse.ui.IWorkbenchPart;
|
13
|
import org.eclipse.ui.IWorkbenchWindow;
|
14
|
import org.eclipse.ui.PlatformUI;
|
15
|
|
16
|
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
|
17
|
import eu.etaxonomy.cdm.api.service.IOccurrenceService;
|
18
|
import eu.etaxonomy.cdm.api.service.ITermService;
|
19
|
import eu.etaxonomy.cdm.ext.occurrence.OccurenceQuery;
|
20
|
import eu.etaxonomy.cdm.ext.occurrence.gbif.GbifDataSetProtocol;
|
21
|
import eu.etaxonomy.cdm.ext.occurrence.gbif.GbifResponse;
|
22
|
import eu.etaxonomy.cdm.io.dwca.in.DwcaImportConfigurator;
|
23
|
import eu.etaxonomy.cdm.model.common.DefinedTermBase;
|
24
|
import eu.etaxonomy.cdm.model.common.ICdmBase;
|
25
|
import eu.etaxonomy.cdm.model.name.TaxonNameBase;
|
26
|
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
|
27
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
28
|
|
29
|
public class SaveImportedSpecimenAction extends Action {
|
30
|
|
31
|
private final Logger logger = Logger.getLogger(SaveImportedSpecimenAction.class);
|
32
|
|
33
|
/* (non-Javadoc)
|
34
|
* @see org.eclipse.jface.action.Action#run()
|
35
|
*/
|
36
|
@Override
|
37
|
public void run() {
|
38
|
final IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
|
39
|
IWorkbenchPart activePart = window.getActivePage().getActivePart();
|
40
|
if(activePart instanceof DataImportView<?>){
|
41
|
DataImportView<?> dataImportView = (DataImportView<?>)activePart;
|
42
|
Table table = dataImportView.getTable();
|
43
|
Collection<GbifResponse> checkedResults = new HashSet<GbifResponse>();
|
44
|
Object data;
|
45
|
Set<String[]> unitIds = new HashSet<String[]>();
|
46
|
for(TableItem item:table.getItems()){
|
47
|
if(item.getChecked()){
|
48
|
//Save Specimen
|
49
|
data = item.getData();
|
50
|
if(data instanceof GbifResponse){
|
51
|
checkedResults.add((GbifResponse)item.getData());
|
52
|
}
|
53
|
}
|
54
|
}
|
55
|
for (GbifResponse response:checkedResults){
|
56
|
if (response != null){
|
57
|
System.err.println("response: " + response.getDataSetUri() + " " + response.getDataSetProtocol());
|
58
|
|
59
|
String[] tripleId = response.getTripleID();
|
60
|
unitIds.add(tripleId);
|
61
|
|
62
|
}
|
63
|
}
|
64
|
|
65
|
DwcaImportConfigurator configurator = DwcaImportConfigurator.NewInstance(null, null);
|
66
|
OccurenceQuery query = new OccurenceQuery(unitIds);
|
67
|
configurator.setQuery(query);
|
68
|
|
69
|
Job job = CdmStore.getImportManager().createIOServiceJob(configurator);
|
70
|
CdmStore.getImportManager().run(job);
|
71
|
|
72
|
|
73
|
}
|
74
|
}
|
75
|
|
76
|
|
77
|
private void persistTerm(DefinedTermBase<?> term, ITermService termService, ConversationHolder conversation){
|
78
|
if(term!=null){
|
79
|
//if the term does not exist in the DB save it
|
80
|
if(termService.find(term.getUuid())==null){
|
81
|
termService.saveOrUpdate(term);
|
82
|
}
|
83
|
}
|
84
|
}
|
85
|
|
86
|
|
87
|
/* (non-Javadoc)
|
88
|
* @see org.eclipse.jface.action.Action#getText()
|
89
|
*/
|
90
|
@Override
|
91
|
public String getText() {
|
92
|
return "Import";
|
93
|
}
|
94
|
|
95
|
}
|