Project

General

Profile

« Previous | Next » 

Revision f4fa11df

Added by Katja Luther over 5 years ago

adapt taxeditor for specimen imports of algae and obeservations

View differences:

eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/dataimport/DataImportView.java
60 60

  
61 61
    protected Collection<T> results = new ArrayList<T>();
62 62

  
63
    protected boolean updated = false;
64

  
63 65
    protected OccurenceQuery query;
64 66

  
65 67
    private static ConversationHolder conversationHolder;
66 68

  
67 69
    private SaveImportedSpecimenAction saveImportedSpecimenAction;
68
    
70

  
69 71
    private Text textClassification;
70 72
    private Classification classification;
71 73
    /**
......
125 127
        table = checkboxTableViewer.getTable();
126 128
        toolkit.paintBordersFor(table);
127 129

  
128
        
129
        
130

  
131

  
130 132
        createActions();
131 133
        initializeToolBar();
132 134
        initializeMenu();
......
170 172
     */
171 173
    public void setResults(Collection<T> results) {
172 174
        this.results = results;
175
        updated=false;
173 176
    }
174 177

  
175 178
    /* (non-Javadoc)
......
190 193
    }
191 194

  
192 195
    protected void refresh(){
193
       // getTable().removeAll();
194
        for(T item:results){
195
            TableItem tableItem = new TableItem(getTable(), SWT.NONE);
196
            tableItem.setText(getTextForTableItem(item));
197
            tableItem.setData(item);
196

  
197
        if (!updated){
198
            if (getTable() != null){
199
                getTable().removeAll();
200
            }
201
            for(T item:results){
202
                TableItem tableItem = new TableItem(getTable(), SWT.NONE);
203
                tableItem.setText(getTextForTableItem(item));
204
                tableItem.setData(item);
205
            }
206
            updated = true;
198 207
        }
199 208
    }
200 209

  
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/dataimport/GbifResponseImportView.java
9 9
package eu.etaxonomy.taxeditor.view.dataimport;
10 10

  
11 11
import java.io.IOException;
12
import java.io.InputStream;
13 12
import java.net.URISyntaxException;
14
import java.util.ArrayList;
15 13
import java.util.Collection;
16
import java.util.Comparator;
17
import java.util.HashSet;
18
import java.util.Set;
19 14

  
20 15
import org.apache.http.client.ClientProtocolException;
21
import org.eclipse.core.runtime.jobs.Job;
22 16

  
23
import eu.etaxonomy.cdm.ext.occurrence.bioCase.BioCaseQueryServiceWrapper;
24
import eu.etaxonomy.cdm.ext.occurrence.gbif.GbifDataSetProtocol;
25 17
import eu.etaxonomy.cdm.ext.occurrence.gbif.GbifQueryServiceWrapper;
26 18
import eu.etaxonomy.cdm.ext.occurrence.gbif.GbifResponse;
27
import eu.etaxonomy.cdm.io.common.CdmDefaultImport;
28
import eu.etaxonomy.cdm.io.common.IImportConfigurator.SOURCE_TYPE;
29
import eu.etaxonomy.cdm.io.dwca.in.DwcaImportConfigurator;
30
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
31
import eu.etaxonomy.taxeditor.store.CdmStore;
32 19

  
33 20
/**
34 21
 * @author pplitzner
......
62 49
        try{
63 50
            //Collection<GbifResponse> results = new GbifQueryServiceWrapper().query(query);
64 51
            //setResults(results);
65
            
52

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

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

  
71 58
                setResults(results);
72
               
73
               
74
//               
59

  
60

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

  
77 64
            } catch (ClientProtocolException e) {
78 65
                logger.error(errorMessage, e);
79 66
            } catch (IOException e) {
......
96 83
//        }
97 84

  
98 85
  //  }
99
    
100
   
101
    
102 86

  
103
	
87

  
88

  
89

  
90

  
104 91

  
105 92
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/dataimport/SaveImportedSpecimenAction.java
23 23
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
24 24
import eu.etaxonomy.cdm.api.service.ITermService;
25 25
import eu.etaxonomy.cdm.ext.occurrence.OccurenceQuery;
26
import eu.etaxonomy.cdm.ext.occurrence.bioCase.BioCaseResponse;
26 27
import eu.etaxonomy.cdm.ext.occurrence.gbif.DataSetResponse;
27 28
import eu.etaxonomy.cdm.ext.occurrence.gbif.GbifDataSetProtocol;
28 29
import eu.etaxonomy.cdm.ext.occurrence.gbif.GbifQueryServiceWrapper;
......
49 50
            DataImportView<?> dataImportView = (DataImportView<?>)activePart;
50 51
            Table table = dataImportView.getTable();
51 52
            Collection<GbifResponse> checkedResults = new HashSet<GbifResponse>();
53
            Collection<BioCaseResponse> checkedAbcdResults = new HashSet<BioCaseResponse>();
52 54
            Object data;
53 55
            Set<String[]> unitIdsGbif = new HashSet<String[]>();
54 56
            Set<String[]> unitIdsBioCase = new HashSet<String[]>();
......
61 63
                	 if(data instanceof GbifResponse){
62 64
                		 checkedResults.add((GbifResponse)item.getData());
63 65
                	 }
66
                	 if(data instanceof BioCaseResponse){
67
                	     checkedAbcdResults.add((BioCaseResponse)data);
68
                     }
64 69
                }
65 70
            }
66 71
            String[] tripleId ;
......
79 84
                	}
80 85
                }
81 86
                Collections.sort(biocaseResponses, getComparator());
82
                URI dataSetUri = null;
83
                Abcd206ImportConfigurator configuratorAbcd;
84 87

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

  
95
                   // if (!response.getDataSetUri().equals(dataSetUri)){
96
                        dataSetUri = response.getDataSetUri();
97
                        configuratorAbcd = Abcd206ImportConfigurator.NewInstance(dataSetUri, null, false);
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

  
110
                    //}
111
                    tripleId = response.getTripleID();
112
                    unitIdsBioCase.add(tripleId);
113

  
114
                }
115

  
116

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

  
88 134
                for (GbifResponse response: biocaseResponses){
89 135
                	try {
90 136
						dataSetResponse = new GbifQueryServiceWrapper().queryOriginalDataSet(response);
......
107 153
                		unitIdsBioCase = new HashSet<String[]>();
108 154
                		bioCaseOccurrenceQuery = new OccurenceQuery(unitIdsBioCase);
109 155
                		configuratorAbcd.setOccurenceQuery(bioCaseOccurrenceQuery);
156
                		configuratorAbcd.setGetSiblings(true);
110 157
                		if (dataImportView.getClassification() != null){
111 158
                			configuratorAbcd.setClassificationUuid(dataImportView.getClassification().getUuid());
112 159
                		}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/dataimport/SpecimenImportView.java
19 19
import org.w3c.dom.NodeList;
20 20

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

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

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

  
......
52 54
     * @see eu.etaxonomy.taxeditor.view.dataimport.DataImportView#getTextForTableItem(java.lang.Object)
53 55
     */
54 56
    @Override
55
    protected String getTextForTableItem(Abcd206DataHolder item) {
56
        //TODO: define a suitable toString method
57
        return item.toString();
57
    protected String getTextForTableItem(BioCaseResponse item) {
58
        //TODO: could be defined in user preferences...
59
        String name = null;
60
        if(!((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()).getFieldNumber() + " - "+ ((Abcd206DataHolder)item.getAbcdDataHolder()).getKindOfUnit();
66
        }else {
67
            return ((Abcd206DataHolder)item.getAbcdDataHolder()).getCollectionCode() + " - "+ ((Abcd206DataHolder)item.getAbcdDataHolder()).getFieldNumber() + " - "+ ((Abcd206DataHolder)item.getAbcdDataHolder()).getKindOfUnit();
68
        }
58 69
    }
59 70

  
60 71
    /* (non-Javadoc)
......
64 75
    public void query() {
65 76
        String errorMessage = "Could not execute query " + query;
66 77

  
67
        Collection<Abcd206DataHolder> results = new ArrayList<Abcd206DataHolder>();
78
        Collection<BioCaseResponse> results = new ArrayList<BioCaseResponse>();
68 79
        try {
69 80
            //FIXME move ABCD import to cdmlib -> this will also get rid of the transient services
70 81
            InputStream resultStream;
......
86 97
            Abcd206XMLFieldGetter abcdFieldGetter = new Abcd206XMLFieldGetter(dataHolder, unitAssociationWrapper.getPrefix());
87 98
            Abcd206ImportState state = new Abcd206ImportState(configurator);
88 99
            state.setDataHolder(dataHolder);
89
            for (int i = 0; i <unitsList.getLength(); i++){
90
                Element item = (Element) unitsList.item(i);
91
                //dataHolder = new Abcd206DataHolder();
92
                Abcd206ImportParser.setUnitPropertiesXML(item, abcdFieldGetter, state);
93
                results.add(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
                    Abcd206ImportParser.setUnitPropertiesXML(item, abcdFieldGetter, state);
106
                    String[] tripleIdBioCase = new String[3];
107
                    tripleIdBioCase[0] =dataHolder.getUnitID();
108
                    tripleIdBioCase[1] = dataHolder.getInstitutionCode();
109
                    tripleIdBioCase[2] = dataHolder.getCollectionCode();
110

  
111
                    response = new BioCaseResponse(dataHolder, endPoint, tripleIdBioCase );
112
                    results.add(response);
113
                }
94 114
            }
95 115

  
96 116
//            Job job = CdmStore.getImportManager().createIOServiceJob(configurator, resultStream, SOURCE_TYPE.INPUTSTREAM);
......
107 127

  
108 128
    }
109 129

  
130

  
131

  
110 132
}

Also available in: Unified diff