Project

General

Profile

Revision b6042ee0

IDb6042ee0fc64d583815be634fb411df96eeb1ed8
Parent e93aa9cd
Child fad2c580

Added by Patrick Plitzner over 2 years ago

ref #6913 Remove data import view

View differences:

eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/dataimport/DataImportView.java
1
/**
2
* Copyright (C) 2013 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.util.ArrayList;
12
import java.util.Collection;
13

  
14
import org.apache.log4j.Logger;
15
import org.eclipse.core.runtime.IProgressMonitor;
16
import org.eclipse.jface.action.IMenuManager;
17
import org.eclipse.jface.action.IToolBarManager;
18
import org.eclipse.jface.viewers.CheckboxTableViewer;
19
import org.eclipse.jface.wizard.IWizard;
20
import org.eclipse.jface.wizard.WizardDialog;
21
import org.eclipse.swt.SWT;
22
import org.eclipse.swt.events.SelectionAdapter;
23
import org.eclipse.swt.events.SelectionEvent;
24
import org.eclipse.swt.layout.GridData;
25
import org.eclipse.swt.layout.GridLayout;
26
import org.eclipse.swt.widgets.Button;
27
import org.eclipse.swt.widgets.Composite;
28
import org.eclipse.swt.widgets.Display;
29
import org.eclipse.swt.widgets.Event;
30
import org.eclipse.swt.widgets.Label;
31
import org.eclipse.swt.widgets.Listener;
32
import org.eclipse.swt.widgets.Table;
33
import org.eclipse.swt.widgets.TableItem;
34
import org.eclipse.swt.widgets.Text;
35
import org.eclipse.ui.IMemento;
36
import org.eclipse.ui.PlatformUI;
37
import org.eclipse.ui.forms.widgets.FormToolkit;
38
import org.eclipse.ui.part.ViewPart;
39
import org.eclipse.wb.swt.ResourceManager;
40

  
41
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
42
import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
43
import eu.etaxonomy.cdm.ext.occurrence.OccurenceQuery;
44
import eu.etaxonomy.cdm.model.taxon.Classification;
45
import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap;
46
import eu.etaxonomy.taxeditor.databaseAdmin.wizard.ImportPreferencesWizard;
47
import eu.etaxonomy.taxeditor.model.IContextListener;
48
import eu.etaxonomy.taxeditor.model.IPartContentHasDetails;
49
import eu.etaxonomy.taxeditor.model.IPartContentHasFactualData;
50
import eu.etaxonomy.taxeditor.model.IPartContentHasSupplementalData;
51
import eu.etaxonomy.taxeditor.store.CdmStore;
52
import eu.etaxonomy.taxeditor.ui.dialog.selection.SelectionDialogFactory;
53

  
54
/**
55
 * View which shows a list of "data" that can be imported into the CDM
56
 * @author pplitzner
57
 * @date Sep 3, 2014
58
 *
59
 * @param <T> the CDM type that will be handled by this view
60
 */
61

  
62
public abstract class DataImportView<T> extends ViewPart implements IPartContentHasFactualData,
63
IConversationEnabled, IPartContentHasDetails, IPartContentHasSupplementalData, IContextListener, Listener{
64

  
65
    protected final Logger logger = Logger.getLogger(DataImportView.class);
66

  
67
    protected Collection<T> results = new ArrayList<T>();
68

  
69
    protected boolean updated = false;
70

  
71
    protected OccurenceQuery query;
72

  
73
    private static ConversationHolder conversationHolder;
74

  
75
    private SaveImportedSpecimenAction saveImportedSpecimenAction;
76

  
77
    private Text textClassification;
78
    private Classification classification;
79

  
80
    private Text textReferenceString;
81

  
82
    private Button toggleButton;
83
    private boolean state;
84

  
85
    private Button openConfigurator;
86
    /**
87
	 * @return the classification
88
	 */
89
	public Classification getClassification() {
90
		return classification;
91
	}
92

  
93
	/**
94
	 * @param classification the classification to set
95
	 */
96
	public void setClassification(Classification classification) {
97
		this.classification = classification;
98
	}
99
	private Button btnBrowseClassification;
100
    private Button btnClear;
101

  
102
    private final FormToolkit toolkit = new FormToolkit(Display.getCurrent());
103

  
104
    private Table table;
105

  
106
    /**
107
     * Constructs a new DataImportEditor and registers it to listen to context changes
108
     */
109
    public DataImportView() {
110
        CdmStore.getContextManager().addContextListener(this);
111
        if(CdmStore.isActive()){
112
            initConversation();
113
        }
114
    }
115

  
116
    /**
117
     * Create contents of the view part.
118
     * @param parent
119
     */
120
    @Override
121
    public void createPartControl(Composite parent) {
122
//    	final Composite composite = new Composite(parent, SWT.NONE);
123
//
124
//		GridLayout gridLayout = new GridLayout();
125
//		gridLayout.numColumns = 3;
126
//		composite.setLayout(gridLayout);
127
//		composite.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));
128
        Composite composite = new Composite(parent, SWT.NONE);
129
        composite.setLayout(new GridLayout(2, false));
130

  
131
        Composite composite_1 = new Composite(composite, SWT.NONE);
132
        GridData gd_composite_1 = new GridData(SWT.LEFT, SWT.TOP, false, false, 1, 1);
133
        gd_composite_1.widthHint = 280;
134
        composite_1.setLayoutData(gd_composite_1);
135
        composite_1.setLayout(new GridLayout(3, false));
136

  
137
    	Label label = new Label(composite_1, SWT.TOP);
138
		label.setText("Classification");
139
		label.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 3, 1));
140
		textClassification = new Text(composite_1, SWT.BORDER);
141
		textClassification.setEnabled(false);
142
		GridData gd_textClassification = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
143
		gd_textClassification.widthHint = 118;
144
		textClassification.setLayoutData(new GridData(SWT.FILL, SWT.LEFT, true, true));
145
		btnBrowseClassification = new Button(composite_1, SWT.NONE);
146
		btnBrowseClassification.setImage(ResourceManager.getPluginImage("eu.etaxonomy.taxeditor.store", "icons/open.gif"));
147
		btnBrowseClassification.addListener(SWT.Selection, this);
148
		btnClear = new Button(composite_1, SWT.NONE);
149
		btnClear.setImage(ResourceManager.getPluginImage("eu.etaxonomy.taxeditor.store", "icons/trash.gif"));
150
		btnClear.addListener(SWT.Selection, this);
151
		//source reference
152

  
153
        Label labelRef = new Label(composite_1, SWT.NONE);
154
        labelRef.setText("Default import souce reference");
155
        labelRef.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 3, 1));
156
        textReferenceString = new Text(composite_1, SWT.NONE);
157
        textReferenceString.setEnabled(true);
158
        GridData gd_textReferenceString = new GridData(SWT.LEFT, SWT.CENTER, true, true, 3, 1);
159
        gd_textReferenceString.widthHint = 229;
160
        textReferenceString.setLayoutData(gd_textReferenceString);
161

  
162
        //open configuration
163
        openConfigurator = new Button(composite_1, SWT.PUSH);
164
        openConfigurator.setText("Configuration");
165
        new Label(composite_1, SWT.NONE);
166
        new Label(composite_1, SWT.NONE);
167
        openConfigurator.addSelectionListener(new SelectionAdapter(){
168
            @Override
169
            public void widgetSelected(SelectionEvent e) {
170

  
171
                IWizard wizard = new ImportPreferencesWizard();
172
                WizardDialog dialog = new WizardDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), wizard);
173
                dialog.open();
174
            }
175
        });
176

  
177
      //checkbox table for result
178
        Composite composite_2 = new Composite(composite, SWT.NONE);
179
        GridData gd_composite_2 = new GridData(SWT.LEFT, SWT.TOP, true, true, 1, 1);
180
        gd_composite_2.heightHint = 454;
181
        gd_composite_2.widthHint = 403;
182
        composite_2.setLayoutData(gd_composite_2);
183
       composite_2.setLayout(new GridLayout(2, false));
184

  
185

  
186
       CheckboxTableViewer checkboxTableViewer = CheckboxTableViewer.newCheckList(composite_2, SWT.BORDER | SWT.FULL_SELECTION);
187

  
188

  
189
       table = checkboxTableViewer.getTable();
190
       GridData gd_table = new GridData(SWT.LEFT, SWT.TOP, true, true, 1, 1);
191
       gd_table.heightHint = 444;
192
       gd_table.widthHint = 312;
193
       table.setLayoutData(gd_table);
194
       toolkit.paintBordersFor(table);
195
       //toggle button
196
       toggleButton = new Button(composite_2, SWT.PUSH);
197
       GridData gd_toggleButton = new GridData(SWT.LEFT, SWT.TOP, false, false, 1, 1);
198
       gd_toggleButton.widthHint = 56;
199
       toggleButton.setLayoutData(gd_toggleButton);
200
       toggleButton.setText("Toggle");
201
       toggleButton.addSelectionListener(new SelectionAdapter(){
202
           @Override
203
           public void widgetSelected(SelectionEvent e) {
204
               state = state ? false : true;
205
               for (TableItem item: getTable().getItems()){
206
                       item.setChecked(state);
207
               }
208

  
209
           }
210
       });
211
        createActions();
212
        initializeToolBar();
213
        initializeMenu();
214
    }
215

  
216
    /**
217
     * Create the actions.
218
     */
219
    private void createActions() {
220
        saveImportedSpecimenAction = new SaveImportedSpecimenAction();
221
    }
222

  
223
    /**
224
     * Initialize the toolbar.
225
     */
226
    private void initializeToolBar() {
227
        IToolBarManager tbm = getViewSite().getActionBars().getToolBarManager();
228
        tbm.add(saveImportedSpecimenAction);
229
    }
230

  
231
    /**
232
     * Initialize the menu.
233
     */
234
    private void initializeMenu() {
235
        IMenuManager manager = getViewSite().getActionBars().getMenuManager();
236
    }
237

  
238
    public Table getTable() {
239
        return table;
240
    }
241

  
242
    /**
243
     * @param query the query to set
244
     */
245
    public void setQuery(OccurenceQuery query) {
246
        this.query = query;
247
    }
248

  
249
    /**
250
     * @param results the results to set
251
     */
252
    public void setResults(Collection<T> results) {
253
        this.results = results;
254
        updated=false;
255
    }
256

  
257
    /* (non-Javadoc)
258
     * @see eu.etaxonomy.taxeditor.annotatedlineeditor.AnnotatedLineEditor#dispose()
259
     */
260
    @Override
261
    public void dispose() {
262
        super.dispose();
263
        CdmStore.getContextManager().removeContextListener(this);
264
    }
265

  
266
    /* (non-Javadoc)
267
     * @see eu.etaxonomy.taxeditor.model.IContextListener#contextRefresh(org.eclipse.core.runtime.IProgressMonitor)
268
     */
269
    @Override
270
    public void contextRefresh(IProgressMonitor monitor) {
271
        refresh();
272
    }
273

  
274
    protected void refresh(){
275

  
276
        if (!updated){
277
            if (getTable() != null){
278
                getTable().removeAll();
279
            }
280
            for(T item:results){
281
                TableItem tableItem = new TableItem(getTable(), SWT.NONE);
282
                tableItem.setText(getTextForTableItem(item));
283
                tableItem.setData(item);
284
            }
285
            updated = true;
286
        }
287
    }
288

  
289
    public abstract void query();
290

  
291

  
292
    /* (non-Javadoc)
293
     * @see eu.etaxonomy.cdm.persistence.hibernate.ICdmPostDataChangeObserver#update(eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap)
294
     */
295
    @Override
296
    public void update(CdmDataChangeMap changeEvents) {
297
        //nothing
298
    }
299

  
300
    /**
301
     * Returns the text label of the given item.
302
     * @param item the item for which the label should be returns
303
     * @return the label of the item
304
     */
305
    protected abstract String getTextForTableItem(T item);
306

  
307
    /* (non-Javadoc)
308
     * @see org.eclipse.ui.part.WorkbenchPart#setFocus()
309
     */
310
    @Override
311
    public void setFocus() {
312
        getTable().setFocus();
313
        //make sure to bind again if maybe in another view the conversation was unbound
314
        if(getConversationHolder()!=null && !getConversationHolder().isBound()){
315
            getConversationHolder().bind();
316
        }
317
    }
318

  
319
    /* (non-Javadoc)
320
     * @see eu.etaxonomy.taxeditor.model.IContextListener#contextAboutToStop(org.eclipse.ui.IMemento, org.eclipse.core.runtime.IProgressMonitor)
321
     */
322
    @Override
323
    public void contextAboutToStop(IMemento memento, IProgressMonitor monitor) {
324
    }
325

  
326
    /* (non-Javadoc)
327
     * @see eu.etaxonomy.taxeditor.model.IContextListener#contextStop(org.eclipse.ui.IMemento, org.eclipse.core.runtime.IProgressMonitor)
328
     */
329
    @Override
330
    public void contextStop(IMemento memento, IProgressMonitor monitor) {
331
//        derivateSearchCompositeController.setEnabled(false);
332
//        derivateSearchCompositeController.reset();
333
    }
334

  
335
    /* (non-Javadoc)
336
     * @see eu.etaxonomy.taxeditor.model.IContextListener#contextStart(org.eclipse.ui.IMemento, org.eclipse.core.runtime.IProgressMonitor)
337
     */
338
    @Override
339
    public void contextStart(IMemento memento, IProgressMonitor monitor) {
340
        initConversation();
341
//        derivateSearchCompositeController.setEnabled(true);
342
    }
343

  
344
    private void initConversation(){
345
        if(conversationHolder==null){
346
            conversationHolder = CdmStore.createConversation();
347
        }
348
    }
349

  
350
    /* (non-Javadoc)
351
     * @see eu.etaxonomy.taxeditor.model.IContextListener#workbenchShutdown(org.eclipse.ui.IMemento, org.eclipse.core.runtime.IProgressMonitor)
352
     */
353
    @Override
354
    public void workbenchShutdown(IMemento memento, IProgressMonitor monitor) {
355
        if(getConversationHolder()!=null && getConversationHolder().isBound() && !getConversationHolder().isClosed()) {
356
            getConversationHolder().close();
357
        }
358
    }
359

  
360
    /**
361
     * @return the conversationHolder
362
     */
363
    @Override
364
    public ConversationHolder getConversationHolder() {
365
        if(CdmStore.isActive() && conversationHolder==null){
366
            initConversation();
367
        }
368
        return conversationHolder;
369
    }
370
    @Override
371
	public void handleEvent(Event event) {
372
	    if(event.widget==btnBrowseClassification){
373
	        classification = SelectionDialogFactory.getSelectionFromDialog(Classification.class, getSite().getShell(), null, null);
374
	        if(classification!=null){
375
	            textClassification.setText(classification.getTitleCache());
376
	        }
377
	    }
378
	    else if(event.widget==btnClear){
379
	        classification = null;
380
	        textClassification.setText("");
381
	    }
382
	}
383

  
384
    /**
385
     * @return
386
     */
387
    public String getReferenceString() {
388

  
389
        return textReferenceString.getText();
390
    }
391
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/dataimport/GbifResponseImportView.java
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.net.URISyntaxException;
13
import java.util.Collection;
14

  
15
import org.apache.http.client.ClientProtocolException;
16

  
17
import eu.etaxonomy.cdm.ext.occurrence.gbif.GbifQueryServiceWrapper;
18
import eu.etaxonomy.cdm.ext.occurrence.gbif.GbifResponse;
19

  
20
/**
21
 * @author pplitzner
22
 * @date Sep 5, 2014
23
 *
24
 */
25
public class GbifResponseImportView extends DataImportView<GbifResponse> {
26

  
27

  
28
    public static final String ID = "eu.etaxonomy.taxeditor.view.dataimport.GbifResponseImportView";
29

  
30
    /* (non-Javadoc)
31
     * @see eu.etaxonomy.taxeditor.view.dataimport.DataImportView#getTextForTableItem(java.lang.Object)
32
     */
33
    @Override
34
    protected String getTextForTableItem(GbifResponse item) {
35
        String text = "";
36
        if(item.getDataSetProtocol()!=null){
37
            text += "["+item.getDataSetProtocol()+"] ";
38
        }
39
        text += item.getDerivedUnitFacade().innerDerivedUnit().generateTitle();
40
        return text;
41
    }
42

  
43
    /* (non-Javadoc)
44
     * @see eu.etaxonomy.taxeditor.view.dataimport.DataImportView#query()
45
     */
46
    @Override
47
    public void query() {
48
        String errorMessage = "Could not execute query " + query;
49
        try{
50
            //Collection<GbifResponse> results = new GbifQueryServiceWrapper().query(query);
51
            //setResults(results);
52

  
53
           // String errorMessage = "Could not execute query " + query;
54

  
55
       //     Collection<SpecimenOrObservationBase<?>> results = new ArrayList<SpecimenOrObservationBase<?>>();
56
                Collection<GbifResponse> results = new GbifQueryServiceWrapper().query(query);
57

  
58
                setResults(results);
59

  
60

  
61
//
62
               // results = repo.getUnits();
63

  
64
            } catch (ClientProtocolException e) {
65
                logger.error(errorMessage, e);
66
            } catch (IOException e) {
67
                logger.error(errorMessage, e);
68
            } catch (URISyntaxException e) {
69
				// TODO Auto-generated catch block
70
				e.printStackTrace();
71
			}
72
        }
73

  
74
//            setResults(results);
75
//
76
//        }
77
//        } catch (ClientProtocolException e) {
78
//            logger.error(errorMessage, e);
79
//        } catch (IOException e) {
80
//            logger.error(errorMessage, e);
81
//        } catch (URISyntaxException e) {
82
//            logger.error(errorMessage, e);
83
//        }
84

  
85
  //  }
86

  
87

  
88

  
89

  
90

  
91

  
92
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/dataimport/SaveImportedSpecimenAction.java
1
package eu.etaxonomy.taxeditor.view.dataimport;
2

  
3
import java.net.URI;
4
import java.util.ArrayList;
5
import java.util.Collection;
6
import java.util.Collections;
7
import java.util.Comparator;
8
import java.util.HashSet;
9
import java.util.List;
10
import java.util.Set;
11

  
12
import org.apache.log4j.Logger;
13
import org.eclipse.core.runtime.jobs.Job;
14
import org.eclipse.jface.action.Action;
15
import org.eclipse.swt.widgets.Table;
16
import org.eclipse.swt.widgets.TableItem;
17
import org.eclipse.ui.IWorkbenchPart;
18
import org.eclipse.ui.IWorkbenchWindow;
19
import org.eclipse.ui.PlatformUI;
20

  
21
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
22
import eu.etaxonomy.cdm.api.service.ITermService;
23
import eu.etaxonomy.cdm.ext.occurrence.OccurenceQuery;
24
import eu.etaxonomy.cdm.ext.occurrence.bioCase.BioCaseResponse;
25
import eu.etaxonomy.cdm.ext.occurrence.gbif.DataSetResponse;
26
import eu.etaxonomy.cdm.ext.occurrence.gbif.GbifDataSetProtocol;
27
import eu.etaxonomy.cdm.ext.occurrence.gbif.GbifResponse;
28
import eu.etaxonomy.cdm.io.specimen.abcd206.in.Abcd206ImportConfigurator;
29
import eu.etaxonomy.cdm.io.specimen.gbif.in.GbifImportConfigurator;
30
import eu.etaxonomy.cdm.model.common.DefinedTermBase;
31
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
32
import eu.etaxonomy.taxeditor.store.CdmStore;
33

  
34
public class SaveImportedSpecimenAction extends Action {
35

  
36
    private final Logger logger = Logger.getLogger(SaveImportedSpecimenAction.class);
37

  
38
    private Comparator<GbifResponse> comparator;
39

  
40
    /* (non-Javadoc)
41
     * @see org.eclipse.jface.action.Action#run()
42
     */
43
    @Override
44
    public void run() {
45
        final IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
46
        IWorkbenchPart activePart = window.getActivePage().getActivePart();
47
        if(activePart instanceof DataImportView<?>){
48
            DataImportView<?> dataImportView = (DataImportView<?>)activePart;
49
            Table table = dataImportView.getTable();
50
            Collection<GbifResponse> checkedResults = new HashSet<GbifResponse>();
51
            Collection<BioCaseResponse> checkedAbcdResults = new HashSet<BioCaseResponse>();
52
            Object data;
53
            Set<String[]> unitIdsGbif = new HashSet<String[]>();
54
            Set<String[]> unitIdsBioCase = new HashSet<String[]>();
55
            List<GbifResponse> biocaseResponses = new ArrayList<GbifResponse>();
56

  
57
            for(TableItem item:table.getItems()){
58
                if(item.getChecked()){
59
                    //Save Specimen
60
                	 data = item.getData();
61
                	 if(data instanceof GbifResponse){
62
                		 checkedResults.add((GbifResponse)item.getData());
63
                	 }
64
                	 if(data instanceof BioCaseResponse){
65
                	     checkedAbcdResults.add((BioCaseResponse)data);
66
                     }
67
                }
68
            }
69
            String[] tripleId ;
70
                for (GbifResponse response:checkedResults){
71
                	if (response != null){
72
                		tripleId = response.getTripleID();
73

  
74
                		if (response.getDataSetProtocol().equals(GbifDataSetProtocol.BIOCASE)){
75
                			biocaseResponses.add(response);
76

  
77
                		}else{
78
                			unitIdsGbif.add(tripleId);
79
                		}
80

  
81

  
82
                	}
83
                }
84
                Collections.sort(biocaseResponses, getComparator());
85

  
86
                Abcd206ImportConfigurator configuratorAbcd;
87
                List<Abcd206ImportConfigurator> abcdConfigurators = new ArrayList<Abcd206ImportConfigurator>();
88
                DataSetResponse dataSetResponse;
89
                OccurenceQuery bioCaseOccurrenceQuery = null;
90
                URI dataSetUri = null;
91
                for (BioCaseResponse response:checkedAbcdResults){
92

  
93
                    if (!response.getDataSetUri().equals(dataSetUri)){
94
                        dataSetUri = response.getDataSetUri();
95

  
96
                        configuratorAbcd = PreferencesUtil.getAbcdImportConfigurationPreference(true);
97
                        configuratorAbcd.setSourceUri(dataSetUri);
98
//                        configuratorAbcd.addMediaAsMediaSpecimen(true);
99
//                        configuratorAbcd.setIgnoreAuthorship(true);
100
//                        configuratorAbcd.setMoveNewTaxaToDefaultClassification(false);
101

  
102
                        unitIdsBioCase = new HashSet<String[]>();
103
                        bioCaseOccurrenceQuery = new OccurenceQuery(unitIdsBioCase);
104
                        configuratorAbcd.setOccurenceQuery(bioCaseOccurrenceQuery);
105
                       // configuratorAbcd.setGetSiblings(true);
106
                        if (dataImportView.getClassification() != null){
107
                            configuratorAbcd.setClassificationUuid(dataImportView.getClassification().getUuid());
108
                        }
109
                        if (dataImportView.getReferenceString() != null){
110
                            configuratorAbcd.setSourceReferenceTitle(dataImportView.getReferenceString());
111
                        }
112
                        abcdConfigurators.add(configuratorAbcd);
113

  
114
                    }
115
                    tripleId = response.getTripleID();
116
                    unitIdsBioCase.add(tripleId);
117

  
118

  
119
                }
120

  
121

  
122
//                if (!unitIdsBioCase.isEmpty()){
123
//                    configuratorAbcd = Abcd206ImportConfigurator.NewInstance(dataSetUri, null, false);
124
//                    configuratorAbcd.addMediaAsMediaSpecimen(true);
125
//                    configuratorAbcd.setIgnoreAuthorship(true);
126
//                    configuratorAbcd.setMoveNewTaxaToDefaultClassification(false);
127
//                    if (configuratorAbcd != null){
128
//                        abcdConfigurators.add(configuratorAbcd);
129
//                    }
130
////                    unitIdsBioCase = new HashSet<String[]>();
131
//                    bioCaseOccurrenceQuery = new OccurenceQuery(unitIdsBioCase);
132
//                    configuratorAbcd.setOccurenceQuery(bioCaseOccurrenceQuery);
133
//                    configuratorAbcd.setGetSiblings(true);
134
//                    if (dataImportView.getClassification() != null){
135
//                        configuratorAbcd.setClassificationUuid(dataImportView.getClassification().getUuid());
136
//                    }
137
//                }
138

  
139
//                for (GbifResponse response: biocaseResponses){
140
//                	try {
141
//						dataSetResponse = new GbifQueryServiceWrapper().queryOriginalDataSet(response);
142
//						dataSetUri = dataSetResponse.getEndpoint();
143
//					} catch (ClientProtocolException e) {
144
//						// TODO Auto-generated catch block
145
//						e.printStackTrace();
146
//					} catch (IOException e) {
147
//						// TODO Auto-generated catch block
148
//						e.printStackTrace();
149
//					}
150
//                	if (!response.getDataSetUri().equals(dataSetUri)){
151
//                		configuratorAbcd = Abcd206ImportConfigurator.NewInstance(dataSetUri, null, false);
152
//                		configuratorAbcd.addMediaAsMediaSpecimen(true);
153
//                		configuratorAbcd.setIgnoreAuthorship(true);
154
//                		configuratorAbcd.setMoveNewTaxaToDefaultClassification(false);
155
//                		if (configuratorAbcd != null){
156
//                			abcdConfigurators.add(configuratorAbcd);
157
//                		}
158
//                		unitIdsBioCase = new HashSet<String[]>();
159
//                		bioCaseOccurrenceQuery = new OccurenceQuery(unitIdsBioCase);
160
//                		configuratorAbcd.setOccurenceQuery(bioCaseOccurrenceQuery);
161
//                		configuratorAbcd.setGetSiblings(true);
162
//                		if (dataImportView.getClassification() != null){
163
//                			configuratorAbcd.setClassificationUuid(dataImportView.getClassification().getUuid());
164
//                		}
165
//
166
//                	}
167
//                	tripleId = response.getTripleID();
168
//                	unitIdsBioCase.add(tripleId);
169
//                }
170

  
171

  
172

  
173

  
174
                //  configurator.setQuery(query);
175
                if (!checkedAbcdResults.isEmpty()){
176
                    Job bioCaseJob = CdmStore.getImportManager().createIOServiceJob(abcdConfigurators);
177
                    CdmStore.getImportManager().run(bioCaseJob);
178
                }
179

  
180
               if (!unitIdsGbif.isEmpty()){
181
                   OccurenceQuery query = new OccurenceQuery(unitIdsGbif);
182
                   GbifImportConfigurator configurator = GbifImportConfigurator.newInstance(query);
183
                   configurator.setSourceReferenceTitle("Import Gbif data");
184

  
185
                   Job gbifJob = CdmStore.getImportManager().createIOServiceJob(configurator);
186
                   CdmStore.getImportManager().run(gbifJob);
187
               }
188

  
189

  
190

  
191
            }
192
        }
193

  
194

  
195
    private void persistTerm(DefinedTermBase<?> term, ITermService termService, ConversationHolder conversation){
196
        if(term!=null){
197
            //if the term does not exist in the DB save it
198
            if(termService.find(term.getUuid())==null){
199
                termService.saveOrUpdate(term);
200
            }
201
        }
202
    }
203

  
204
    /* (non-Javadoc)
205
     * @see org.eclipse.jface.action.Action#getText()
206
     */
207
    @Override
208
    public String getText() {
209
        return "Import";
210
    }
211

  
212
    private Comparator<GbifResponse> getComparator(){
213
    	if (comparator == null){
214
    		comparator = new GbifResponseComparator();
215
    	}
216
    	return comparator;
217
    }
218

  
219

  
220
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/dataimport/SpecimenImportView.java
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.w3c.dom.Element;
19
import org.w3c.dom.NodeList;
20

  
21
import eu.etaxonomy.cdm.ext.occurrence.bioCase.BioCaseQueryServiceWrapper;
22
import eu.etaxonomy.cdm.ext.occurrence.bioCase.BioCaseResponse;
23
import eu.etaxonomy.cdm.io.specimen.abcd206.in.Abcd206DataHolder;
24
import eu.etaxonomy.cdm.io.specimen.abcd206.in.Abcd206ImportConfigurator;
25
import eu.etaxonomy.cdm.io.specimen.abcd206.in.Abcd206ImportParser;
26
import eu.etaxonomy.cdm.io.specimen.abcd206.in.Abcd206ImportState;
27
import eu.etaxonomy.cdm.io.specimen.abcd206.in.Abcd206XMLFieldGetter;
28
import eu.etaxonomy.cdm.io.specimen.abcd206.in.AbcdParseUtility;
29
import eu.etaxonomy.cdm.io.specimen.abcd206.in.Identification;
30
import eu.etaxonomy.cdm.io.specimen.abcd206.in.UnitAssociationWrapper;
31

  
32
/**
33
 * @author pplitzner
34
 * @date Sep 3, 2014
35
 *
36
 */
37
public class SpecimenImportView extends DataImportView<BioCaseResponse> {
38

  
39
    public static final String ID = "eu.etaxonomy.taxeditor.view.dataimport.SpecimenImportView"; //$NON-NLS-1$
40

  
41
    private URI endPoint;
42

  
43
    public SpecimenImportView() {
44
    }
45

  
46
    /**
47
     * @param endPoint
48
     */
49
    public void setEndpoint(URI endPoint) {
50
        this.endPoint = endPoint;
51
    }
52

  
53
    /* (non-Javadoc)
54
     * @see eu.etaxonomy.taxeditor.view.dataimport.DataImportView#getTextForTableItem(java.lang.Object)
55
     */
56
    @Override
57
    protected String getTextForTableItem(BioCaseResponse item) {
58
        //TODO: could be defined in user preferences...
59
        String name = null;
60
        if(!(((Abcd206DataHolder)item.getAbcdDataHolder()).getIdentificationList() == null) && !((Abcd206DataHolder)item.getAbcdDataHolder()).getIdentificationList().isEmpty()){
61
           Identification identification =  ((Abcd206DataHolder)item.getAbcdDataHolder()).getIdentificationList().iterator().next();
62
           name = identification.getScientificName();
63
        }
64
        if (name != null){
65
            return name +" - "+((Abcd206DataHolder)item.getAbcdDataHolder()).getCollectionCode() + " - "+ ((Abcd206DataHolder)item.getAbcdDataHolder()).getUnitID() + " - "+ ((Abcd206DataHolder)item.getAbcdDataHolder()).getKindOfUnit();
66
        }else {
67
            return ((Abcd206DataHolder)item.getAbcdDataHolder()).getCollectionCode() + " - "+ ((Abcd206DataHolder)item.getAbcdDataHolder()).getUnitID() + " - "+ ((Abcd206DataHolder)item.getAbcdDataHolder()).getKindOfUnit();
68
        }
69
    }
70

  
71
    /* (non-Javadoc)
72
     * @see eu.etaxonomy.taxeditor.view.dataimport.DataImportView#query()
73
     */
74
    @Override
75
    public void query() {
76
        String errorMessage = "Could not execute query " + query;
77

  
78
        Collection<BioCaseResponse> results = new ArrayList<BioCaseResponse>();
79
        try {
80
            //FIXME move ABCD import to cdmlib -> this will also get rid of the transient services
81
            InputStream resultStream;
82
            resultStream = new BioCaseQueryServiceWrapper().query(query, endPoint);
83
            Abcd206ImportConfigurator configurator = Abcd206ImportConfigurator.NewInstance(null, null);
84
            configurator.setSourceUri(endPoint);
85

  
86
            //            TransientCdmRepository repo =
87
//                    new TransientCdmRepository(CdmStore.getCurrentApplicationConfiguration());
88
            //configurator.setCdmAppController(repo);
89

  
90
            //TODO: do not query all data but with the selected triple IDs -> see GbifResponseImportView
91
            configurator.setAddMediaAsMediaSpecimen(true);
92
            configurator.setAllowReuseOtherClassifications(true);
93
            configurator.setMoveNewTaxaToDefaultClassification(false);
94
            UnitAssociationWrapper unitAssociationWrapper = AbcdParseUtility.parseUnitsNodeList(resultStream, null);
95
            NodeList unitsList = unitAssociationWrapper.getAssociatedUnits();
96
            Abcd206DataHolder dataHolder = new Abcd206DataHolder();
97
            Abcd206XMLFieldGetter abcdFieldGetter = new Abcd206XMLFieldGetter(dataHolder, unitAssociationWrapper.getPrefix());
98
            Abcd206ImportState state = new Abcd206ImportState(configurator);
99
            state.setDataHolder(dataHolder);
100
            BioCaseResponse response = null;
101
            if (unitsList != null){
102
                for (int i = 0; i <unitsList.getLength(); i++){
103
                    Element item = (Element) unitsList.item(i);
104
                    dataHolder = new Abcd206DataHolder();
105
                    abcdFieldGetter = new Abcd206XMLFieldGetter(dataHolder, unitAssociationWrapper.getPrefix());
106
                    state.setPrefix(unitAssociationWrapper.getPrefix());
107
                    Abcd206ImportParser.setUnitPropertiesXML(item, abcdFieldGetter, state);
108
                    String[] tripleIdBioCase = new String[3];
109
                    tripleIdBioCase[0] =dataHolder.getUnitID();
110
                    tripleIdBioCase[1] = dataHolder.getInstitutionCode();
111
                    tripleIdBioCase[2] = dataHolder.getCollectionCode();
112

  
113
                    response = new BioCaseResponse(dataHolder, endPoint, tripleIdBioCase );
114
                    results.add(response);
115
                }
116
            }
117

  
118
//            Job job = CdmStore.getImportManager().createIOServiceJob(configurator, resultStream, SOURCE_TYPE.INPUTSTREAM);
119
//            CdmStore.getImportManager().run(job);
120

  
121
            setResults(results);
122
        } catch (ClientProtocolException e) {
123
            logger.error(errorMessage, e);
124
        } catch (IOException e) {
125
            logger.error(errorMessage, e);
126
        }
127

  
128
       // setResults(results);
129

  
130
    }
131

  
132

  
133

  
134
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/dataimport/SpecimenSearchWizard.java
1
/**
2
* Copyright (C) 2013 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

  
15
import org.apache.log4j.Logger;
16
import org.eclipse.core.runtime.IProgressMonitor;
17
import org.eclipse.core.runtime.IStatus;
18
import org.eclipse.core.runtime.Status;
19
import org.eclipse.core.runtime.jobs.Job;
20
import org.eclipse.jface.viewers.IStructuredSelection;
21
import org.eclipse.jface.wizard.Wizard;
22
import org.eclipse.swt.widgets.Display;
23
import org.eclipse.ui.IImportWizard;
24
import org.eclipse.ui.IWorkbench;
25
import org.eclipse.ui.IWorkbenchPage;
26
import org.eclipse.ui.IWorkbenchWindow;
27
import org.eclipse.ui.PartInitException;
28
import org.eclipse.ui.PlatformUI;
29
import org.w3c.dom.NodeList;
30

  
31
import eu.etaxonomy.cdm.database.DbSchemaValidation;
32
import eu.etaxonomy.cdm.ext.common.ServiceWrapperBase;
33
import eu.etaxonomy.cdm.ext.occurrence.OccurenceQuery;
34
import eu.etaxonomy.cdm.ext.occurrence.bioCase.BioCaseQueryServiceWrapper;
35
import eu.etaxonomy.cdm.io.specimen.abcd206.in.Abcd206ImportConfigurator;
36
import eu.etaxonomy.cdm.io.specimen.abcd206.in.AbcdParseUtility;
37
import eu.etaxonomy.cdm.io.specimen.abcd206.in.SpecimenImportReport;
38
import eu.etaxonomy.cdm.io.specimen.abcd206.in.UnitAssociationWrapper;
39
import eu.etaxonomy.taxeditor.store.CdmStore;
40

  
41
/**
42
 * Wizard for querying specimen provider.
43
 * @author pplitzner
44
 * @date 11.09.2013
45
 *
46
 */
47
public class SpecimenSearchWizard extends Wizard implements IImportWizard {
48
    private static final Logger logger = Logger.getLogger(SpecimenSearchWizard.class);
49

  
50
    private OccurenceQuery query = null;
51
    private SpecimenProviderSelectionWizardPage providerSelectionPage;
52
    private SpecimenSearchWizardPage searchPage;
53

  
54
    /**
55
     * Creates a new SpecimenSearchWizard
56
     */
57
    public SpecimenSearchWizard() {
58
        //default constructor needed for RCP extension points
59

  
60
        //check if connected to a data source. If not this will open an error dialog
61
        CdmStore.getCurrentApplicationConfiguration();
62
        this.setWindowTitle("Search Specimens");
63
    }
64

  
65

  
66
    /* (non-Javadoc)
67
     * @see org.eclipse.jface.wizard.Wizard#performFinish()
68
     */
69
    @Override
70
    public boolean performFinish() {
71
        searchPage.getController().saveLastSate();
72
        providerSelectionPage.getController().saveLastState();
73
        ServiceWrapperBase serviceWrapper;
74
        DataImportView<?> dataImportView = null;
75
        query = searchPage.getQuery();
76
        Abcd206ImportConfigurator configurator =  CdmStore.getImportManager().AbcdConfigurator();
77
        configurator.setOccurenceQuery(query);
78
        configurator.setSourceUri(providerSelectionPage.getEndPoint());
79
        configurator.setAddMediaAsMediaSpecimen(true);
80
        configurator.setDbSchemaValidation(DbSchemaValidation.CREATE);
81
        configurator.setIgnoreAuthorship(true);
82
        configurator.setMoveNewTaxaToDefaultClassification(false);
83

  
84

  
85
        //Job job = CdmStore.getImportManager().createIOServiceJob(configurator, new File(source), SOURCE_TYPE.INPUTSTREAM);
86
        //CdmStore.getImportManager().run(job);
87
        try {
88
            serviceWrapper = providerSelectionPage.getQueryServiceWrapper();
89
            InputStream stream = null;
90

  
91
            final IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
92
            IWorkbenchPage activePart = window.getActivePage();
93
            if (providerSelectionPage.getQueryType().equals(QueryType.BIOCASE)){
94
                stream =((BioCaseQueryServiceWrapper) serviceWrapper).query(query, configurator.getSourceUri());
95
                SpecimenImportReport report = new SpecimenImportReport();
96
                UnitAssociationWrapper unitNodesList = AbcdParseUtility.parseUnitsNodeList(stream, report);
97
                NodeList nodeList = unitNodesList.getAssociatedUnits();
98
                String prefix = unitNodesList.getPrefix();
99
                String associationType = unitNodesList.getAssociationType();
100
                if (nodeList != null){
101
                    URI uri =AbcdParseUtility.parseFirstUri(nodeList, report);
102
                    String content = AbcdParseUtility.parseFirstTextContent(nodeList);
103
                    System.out.println(content);
104
                }
105

  
106

  
107

  
108
                SpecimenImportView specimenImportView = new SpecimenImportView();
109
                try {
110
                    specimenImportView = (SpecimenImportView) activePart.showView(SpecimenImportView.ID);
111
                    specimenImportView.setEndpoint(providerSelectionPage.getEndPoint());
112
                    specimenImportView.setQuery(query);
113
                    dataImportView = specimenImportView;
114
                } catch (PartInitException e) {
115
                    // TODO Auto-generated catch block
116
                    e.printStackTrace();
117

  
118
                }
119

  
120
            } else{
121
                try {
122

  
123
                    dataImportView = (GbifResponseImportView) activePart.showView(GbifResponseImportView.ID, "query_"+query.toString().replaceAll(",", ""), IWorkbenchPage.VIEW_ACTIVATE);
124
                    dataImportView.setQuery(query);
125
                    	//	(GbifResponseImportView) activePart.showView(GbifResponseImportView.ID);getWorkbench().getActiveWorkbenchWindow().getActivePage()
126
                         // .showView(GbifResponseImportView.ID, "query_"+query.toString().replaceAll(",", ""),IWorkbenchPage.VIEW_ACTIVATE);
127

  
128
                } catch (PartInitException e) {
129
                    // TODO Auto-generated catch block
130
                    e.printStackTrace();
131
                }
132

  
133
            }
134

  
135

  
136
        } catch (IOException e) {
137
            // TODO Auto-generated catch block
138
            e.printStackTrace();
139
        }
140
       // CdmStore.getImportManager().run(configurator);
141

  
142
//        try {
143
//            switch (providerSelectionPage.getQueryType()) {
144
//            case BIOCASE:
145
//                SpecimenImportView specimenImportView = (SpecimenImportView) TaxeditorEditorPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getActivePage()
146
//                        .showView(SpecimenImportView.ID, "query_"+query.toString().replaceAll(",", ""),IWorkbenchPage.VIEW_ACTIVATE);
147
//                specimenImportView.setEndpoint(providerSelectionPage.getEndPoint());
148
//                dataImportView = specimenImportView;
149
//                break;
150
//            case GBIF:
151
//                dataImportView = (GbifResponseImportView) TaxeditorEditorPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getActivePage()
152
//                .showView(GbifResponseImportView.ID, "query_"+query.toString().replaceAll(",", ""),IWorkbenchPage.VIEW_ACTIVATE);
153
//                break;
154
//            }
155
//        } catch ( PartInitException e ) {
156
//            logger.error("Could not open import view for query: " + query.toString(), e);
157
//        }
158
//        if(dataImportView!=null){
159
//            dataImportView.setQuery(query);
160
////            dataImportView.query();
161
////            Display.getDefault().asyncExec(new Runnable() {
162
////
163
////                @Override
164
////                public void run() {
165
////                    CdmStore.getContextManager().notifyContextRefresh();
166
////                }
167
////            });
168
            Job queryJob = new QueryJob("Query specimen provider", dataImportView);
169
           queryJob.schedule();
170

  
171
        return true;
172
    }
173

  
174
    /* (non-Javadoc)
175
     * @see org.eclipse.jface.wizard.Wizard#addPages()
176
     */
177
    @Override
178
    public void addPages() {
179
        addPage(providerSelectionPage);
180
        addPage(searchPage);
181
    }
182

  
183
    /* (non-Javadoc)
184
     * @see org.eclipse.ui.IWorkbenchWizard#init(org.eclipse.ui.IWorkbench, org.eclipse.jface.viewers.IStructuredSelection)
185
     */
186
    @Override
187
    public void init(IWorkbench workbench, IStructuredSelection selection) {
188
        providerSelectionPage = new SpecimenProviderSelectionWizardPage("Select specimen provider");
189
        searchPage = new SpecimenSearchWizardPage("Specimen Search");
190
    }
191

  
192
    private class QueryJob extends Job{
193

  
194
        private final DataImportView<?> view;
195

  
196
        /**
197
         * @param name
198
         */
199
        public QueryJob(String name, DataImportView<?> view) {
200
            super(name);
201
            this.view = view;
202
        }
203

  
204
        /* (non-Javadoc)
205
         * @see org.eclipse.core.runtime.jobs.Job#run(org.eclipse.core.runtime.IProgressMonitor)
206
         */
207
        @Override
208
        protected IStatus run(IProgressMonitor monitor) {
209
            view.getConversationHolder().bind();
210
            view.query();
211
            Display.getDefault().asyncExec(new Runnable() {
212

  
213
                @Override
214
                public void run() {
215
                    CdmStore.getContextManager().notifyContextRefresh();
216
                }
217
            });
218
            return Status.OK_STATUS;
219
        }
220

  
221
    }
222
}

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)