Project

General

Profile

« Previous | Next » 

Revision f12ac52e

Added by Katja Luther over 5 years ago

some changes for specimen import

View differences:

eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/io/wizard/ExcelNormalExplicitTaxaImportWizard.java
13 13
import java.io.FileInputStream;
14 14
import java.io.FileNotFoundException;
15 15
import java.net.URI;
16
import org.apache.log4j.Logger;
17 16

  
17
import org.apache.log4j.Logger;
18 18
import org.eclipse.core.runtime.jobs.Job;
19 19
import org.eclipse.jface.viewers.IStructuredSelection;
20 20
import org.eclipse.jface.viewers.TreeSelection;
......
24 24
import eu.etaxonomy.cdm.io.common.IImportConfigurator.SOURCE_TYPE;
25 25
import eu.etaxonomy.cdm.io.excel.taxa.NormalExplicitImportConfigurator;
26 26
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
27

  
28 27
import eu.etaxonomy.taxeditor.store.CdmStore;
29 28

  
30 29

  
......
68 67
		} catch (FileNotFoundException e) {
69 68
			logger.error("Error while reading file" + source.toString());
70 69
		}
71
			
72
	    Job job = CdmStore.getImportManager().createIOServiceJob(configurator,file , SOURCE_TYPE.INPUTSTREAM);
70

  
71
	    Job job = CdmStore.getImportManager().createIOServiceJob(configurator,fis , SOURCE_TYPE.INPUTSTREAM);
73 72
	    CdmStore.getImportManager().run(job);
74
		
73

  
75 74
		return true;
76 75
	}
77 76

  
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/dataimport/SaveImportedSpecimenAction.java
9 9
import java.util.HashSet;
10 10
import java.util.List;
11 11
import java.util.Set;
12
import java.util.UUID;
13 12

  
14 13
import org.apache.http.client.ClientProtocolException;
15 14
import org.apache.log4j.Logger;
16 15
import org.eclipse.core.runtime.jobs.Job;
17 16
import org.eclipse.jface.action.Action;
18
import org.eclipse.jface.text.source.Annotation;
19
import org.eclipse.swt.widgets.Event;
20 17
import org.eclipse.swt.widgets.Table;
21 18
import org.eclipse.swt.widgets.TableItem;
22 19
import org.eclipse.ui.IWorkbenchPart;
......
24 21
import org.eclipse.ui.PlatformUI;
25 22

  
26 23
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
27
import eu.etaxonomy.cdm.api.service.IClassificationService;
28
import eu.etaxonomy.cdm.api.service.IOccurrenceService;
29 24
import eu.etaxonomy.cdm.api.service.ITermService;
30 25
import eu.etaxonomy.cdm.ext.occurrence.OccurenceQuery;
31 26
import eu.etaxonomy.cdm.ext.occurrence.gbif.DataSetResponse;
......
33 28
import eu.etaxonomy.cdm.ext.occurrence.gbif.GbifQueryServiceWrapper;
34 29
import eu.etaxonomy.cdm.ext.occurrence.gbif.GbifResponse;
35 30
import eu.etaxonomy.cdm.io.specimen.abcd206.in.Abcd206ImportConfigurator;
36
import eu.etaxonomy.cdm.io.specimen.gbif.in.*;
31
import eu.etaxonomy.cdm.io.specimen.gbif.in.GbifImportConfigurator;
37 32
import eu.etaxonomy.cdm.model.common.DefinedTermBase;
38
import eu.etaxonomy.cdm.model.common.ICdmBase;
39
import eu.etaxonomy.cdm.model.name.TaxonNameBase;
40
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
41
import eu.etaxonomy.cdm.model.taxon.Classification;
42 33
import eu.etaxonomy.taxeditor.store.CdmStore;
43
import eu.etaxonomy.taxeditor.ui.dialog.selection.SelectionDialogFactory;
44 34

  
45 35
public class SaveImportedSpecimenAction extends Action {
46 36

  
47 37
    private final Logger logger = Logger.getLogger(SaveImportedSpecimenAction.class);
48
    
38

  
49 39
    private Comparator<GbifResponse> comparator;
50 40

  
51 41
    /* (non-Javadoc)
......
63 53
            Set<String[]> unitIdsGbif = new HashSet<String[]>();
64 54
            Set<String[]> unitIdsBioCase = new HashSet<String[]>();
65 55
            List<GbifResponse> biocaseResponses = new ArrayList<GbifResponse>();
66
            
56

  
67 57
            for(TableItem item:table.getItems()){
68 58
                if(item.getChecked()){
69 59
                    //Save Specimen
......
77 67
                for (GbifResponse response:checkedResults){
78 68
                	if (response != null){
79 69
                		tripleId = response.getTripleID();
80
                		
70

  
81 71
                		if (response.getDataSetProtocol().equals(GbifDataSetProtocol.BIOCASE)){
82 72
                			biocaseResponses.add(response);
83
                			
73

  
84 74
                		}else{
85 75
                			unitIdsGbif.add(tripleId);
86 76
                		}
87
                		
88
	                		
77

  
78

  
89 79
                	}
90 80
                }
91
                Collections.sort(biocaseResponses, getComparator()); 
81
                Collections.sort(biocaseResponses, getComparator());
92 82
                URI dataSetUri = null;
93 83
                Abcd206ImportConfigurator configuratorAbcd;
94
                
84

  
95 85
                List<Abcd206ImportConfigurator> abcdConfigurators = new ArrayList<Abcd206ImportConfigurator>();
96 86
                DataSetResponse dataSetResponse;
97 87
                OccurenceQuery bioCaseOccurrenceQuery = null;
......
109 99
                	if (!response.getDataSetUri().equals(dataSetUri)){
110 100
                		configuratorAbcd = Abcd206ImportConfigurator.NewInstance(dataSetUri, null, false);
111 101
                		configuratorAbcd.addMediaAsMediaSpecimen(true);
102
                		configuratorAbcd.setIgnoreAuthorship(true);
103
                		configuratorAbcd.setMoveNewTaxaToDefaultClassification(false);
112 104
                		if (configuratorAbcd != null){
113 105
                			abcdConfigurators.add(configuratorAbcd);
114 106
                		}
......
118 110
                		if (dataImportView.getClassification() != null){
119 111
                			configuratorAbcd.setClassificationUuid(dataImportView.getClassification().getUuid());
120 112
                		}
121
                		
113

  
122 114
                	}
123 115
                	tripleId = response.getTripleID();
124 116
                	unitIdsBioCase.add(tripleId);
125 117
                }
126
              
118

  
127 119
                OccurenceQuery query = new OccurenceQuery(unitIdsGbif);
128 120
                GbifImportConfigurator configurator = GbifImportConfigurator.newInstance(query);
129 121
                configurator.setSourceReferenceTitle("Import Gbif data");
130
                
131
               
132
                
122

  
123

  
124

  
133 125
                //  configurator.setQuery(query);
134
               
126

  
135 127
               Job bioCaseJob = CdmStore.getImportManager().createIOServiceJob(abcdConfigurators);
136 128
               CdmStore.getImportManager().run(bioCaseJob);
137
               
129

  
138 130
               Job gbifJob = CdmStore.getImportManager().createIOServiceJob(configurator);
139 131
               CdmStore.getImportManager().run(gbifJob);
140
               
141
               
142
                
132

  
133

  
134

  
143 135
            }
144 136
        }
145
 
146
    
137

  
138

  
147 139
    private void persistTerm(DefinedTermBase<?> term, ITermService termService, ConversationHolder conversation){
148 140
        if(term!=null){
149 141
            //if the term does not exist in the DB save it
......
152 144
            }
153 145
        }
154 146
    }
155
     
147

  
156 148
    /* (non-Javadoc)
157 149
     * @see org.eclipse.jface.action.Action#getText()
158 150
     */
......
160 152
    public String getText() {
161 153
        return "Import";
162 154
    }
163
    
155

  
164 156
    private Comparator<GbifResponse> getComparator(){
165 157
    	if (comparator == null){
166 158
    		comparator = new GbifResponseComparator();
167 159
    	}
168 160
    	return comparator;
169 161
    }
170
    
171
    
162

  
163

  
172 164
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/dataimport/SpecimenImportView.java
15 15
import java.util.Collection;
16 16

  
17 17
import org.apache.http.client.ClientProtocolException;
18
import org.eclipse.core.runtime.jobs.Job;
18
import org.w3c.dom.Element;
19
import org.w3c.dom.NodeList;
19 20

  
20 21
import eu.etaxonomy.cdm.ext.occurrence.bioCase.BioCaseQueryServiceWrapper;
21
import eu.etaxonomy.cdm.io.common.CdmDefaultImport;
22
import eu.etaxonomy.cdm.io.common.IImportConfigurator.SOURCE_TYPE;
22
import eu.etaxonomy.cdm.io.specimen.abcd206.in.Abcd206DataHolder;
23 23
import eu.etaxonomy.cdm.io.specimen.abcd206.in.Abcd206ImportConfigurator;
24
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
25
import eu.etaxonomy.taxeditor.store.CdmStore;
24
import eu.etaxonomy.cdm.io.specimen.abcd206.in.Abcd206ImportParser;
25
import eu.etaxonomy.cdm.io.specimen.abcd206.in.Abcd206ImportState;
26
import eu.etaxonomy.cdm.io.specimen.abcd206.in.Abcd206XMLFieldGetter;
27
import eu.etaxonomy.cdm.io.specimen.abcd206.in.AbcdParseUtility;
28
import eu.etaxonomy.cdm.io.specimen.abcd206.in.UnitAssociationWrapper;
26 29

  
27 30
/**
28 31
 * @author pplitzner
29 32
 * @date Sep 3, 2014
30 33
 *
31 34
 */
32
public class SpecimenImportView extends DataImportView<SpecimenOrObservationBase<?>> {
35
public class SpecimenImportView extends DataImportView<Abcd206DataHolder> {
33 36

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

  
......
49 52
     * @see eu.etaxonomy.taxeditor.view.dataimport.DataImportView#getTextForTableItem(java.lang.Object)
50 53
     */
51 54
    @Override
52
    protected String getTextForTableItem(SpecimenOrObservationBase<?> item) {
53
        return item.getTitleCache();
55
    protected String getTextForTableItem(Abcd206DataHolder item) {
56
        //TODO: define a suitable toString method
57
        return item.toString();
54 58
    }
55 59

  
56 60
    /* (non-Javadoc)
......
60 64
    public void query() {
61 65
        String errorMessage = "Could not execute query " + query;
62 66

  
63
        Collection<SpecimenOrObservationBase<?>> results = new ArrayList<SpecimenOrObservationBase<?>>();
67
        Collection<Abcd206DataHolder> results = new ArrayList<Abcd206DataHolder>();
64 68
        try {
65 69
            //FIXME move ABCD import to cdmlib -> this will also get rid of the transient services
66 70
            InputStream resultStream;
67 71
            resultStream = new BioCaseQueryServiceWrapper().query(query, endPoint);
68 72
            Abcd206ImportConfigurator configurator = Abcd206ImportConfigurator.NewInstance(null, null);
69
//            TransientCdmRepository repo =
73
            configurator.setSourceUri(endPoint);
74

  
75
            //            TransientCdmRepository repo =
70 76
//                    new TransientCdmRepository(CdmStore.getCurrentApplicationConfiguration());
71 77
            //configurator.setCdmAppController(repo);
78

  
79
            //TODO: do not query all data but with the selected triple IDs -> see GbifResponseImportView
72 80
            configurator.setAddMediaAsMediaSpecimen(true);
73 81
            configurator.setAllowReuseOtherClassifications(true);
74
            
75
            Job job = CdmStore.getImportManager().createIOServiceJob(configurator, resultStream, SOURCE_TYPE.INPUTSTREAM);
76
            CdmStore.getImportManager().run(job);
77
            
82
            configurator.setMoveNewTaxaToDefaultClassification(false);
83
            UnitAssociationWrapper unitAssociationWrapper = AbcdParseUtility.parseUnitsNodeList(resultStream, null);
84
            NodeList unitsList = unitAssociationWrapper.getAssociatedUnits();
85
            Abcd206DataHolder dataHolder = new Abcd206DataHolder();
86
            Abcd206XMLFieldGetter abcdFieldGetter = new Abcd206XMLFieldGetter(dataHolder, unitAssociationWrapper.getPrefix());
87
            Abcd206ImportState state = new Abcd206ImportState(configurator);
88
            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);
94
            }
95

  
96
//            Job job = CdmStore.getImportManager().createIOServiceJob(configurator, resultStream, SOURCE_TYPE.INPUTSTREAM);
97
//            CdmStore.getImportManager().run(job);
98

  
78 99
            setResults(results);
79 100
        } catch (ClientProtocolException e) {
80 101
            logger.error(errorMessage, e);
......
82 103
            logger.error(errorMessage, e);
83 104
        }
84 105

  
85
        setResults(results);
106
       // setResults(results);
86 107

  
87 108
    }
88 109

  
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/dataimport/SpecimenSearchWizard.java
33 33
import eu.etaxonomy.cdm.ext.occurrence.OccurenceQuery;
34 34
import eu.etaxonomy.cdm.ext.occurrence.bioCase.BioCaseQueryServiceWrapper;
35 35
import eu.etaxonomy.cdm.io.specimen.abcd206.in.Abcd206ImportConfigurator;
36

  
37 36
import eu.etaxonomy.cdm.io.specimen.abcd206.in.AbcdParseUtility;
38 37
import eu.etaxonomy.cdm.io.specimen.abcd206.in.SpecimenImportReport;
39 38
import eu.etaxonomy.cdm.io.specimen.abcd206.in.UnitAssociationWrapper;
......
80 79
        configurator.setAddMediaAsMediaSpecimen(true);
81 80
        configurator.setDbSchemaValidation(DbSchemaValidation.CREATE);
82 81
        configurator.setIgnoreAuthorship(true);
83
      
82
        configurator.setMoveNewTaxaToDefaultClassification(false);
83

  
84

  
84 85
        //Job job = CdmStore.getImportManager().createIOServiceJob(configurator, new File(source), SOURCE_TYPE.INPUTSTREAM);
85 86
        //CdmStore.getImportManager().run(job);
86 87
        try {
......
96 97
                NodeList nodeList = unitNodesList.getAssociatedUnits();
97 98
                String prefix = unitNodesList.getPrefix();
98 99
                String associationType = unitNodesList.getAssociationType();
99
                URI uri =AbcdParseUtility.parseFirstUri(nodeList, report);
100
                String content = AbcdParseUtility.parseFirstTextContent(nodeList);
101
                System.out.println(content);
100
                if (nodeList != null){
101
                    URI uri =AbcdParseUtility.parseFirstUri(nodeList, report);
102
                    String content = AbcdParseUtility.parseFirstTextContent(nodeList);
103
                    System.out.println(content);
104
                }
105

  
102 106

  
103 107

  
104 108
                SpecimenImportView specimenImportView = new SpecimenImportView();
......
115 119

  
116 120
            } else{
117 121
                try {
118
                	
122

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

  
......
134 138
            e.printStackTrace();
135 139
        }
136 140
       // CdmStore.getImportManager().run(configurator);
137
    
141

  
138 142
//        try {
139 143
//            switch (providerSelectionPage.getQueryType()) {
140 144
//            case BIOCASE:
......
162 166
////                }
163 167
////            });
164 168
            Job queryJob = new QueryJob("Query specimen provider", dataImportView);
165
            queryJob.schedule();
169
           queryJob.schedule();
166 170

  
167 171
        return true;
168 172
    }

Also available in: Unified diff