Project

General

Profile

Download (6.94 KB) Statistics
| Branch: | Tag: | Revision:
1
package org.bgbm.biovel.drf.checklist;
2

    
3

    
4
import java.rmi.RemoteException;
5
import java.util.List;
6

    
7
import javax.xml.rpc.ServiceException;
8

    
9
import org.apache.http.HttpHost;
10
import org.bgbm.biovel.drf.checklist.pesi.PESINameServiceLocator;
11
import org.bgbm.biovel.drf.checklist.pesi.PESINameServicePortType;
12
import org.bgbm.biovel.drf.checklist.pesi.PESIRecord;
13
import org.bgbm.biovel.drf.tnr.msg.AcceptedName;
14
import org.bgbm.biovel.drf.tnr.msg.NameType;
15
import org.bgbm.biovel.drf.tnr.msg.ScrutinyType;
16
import org.bgbm.biovel.drf.tnr.msg.SourceType;
17
import org.bgbm.biovel.drf.tnr.msg.TaxonNameType;
18
import org.bgbm.biovel.drf.tnr.msg.TnrMsg;
19
import org.bgbm.biovel.drf.tnr.msg.TnrMsg.Query;
20
import org.bgbm.biovel.drf.tnr.msg.TnrResponse;
21
import org.bgbm.biovel.drf.tnr.msg.TnrResponse.Synonym;
22

    
23

    
24
public class PESIClient extends BaseChecklistClient {
25

    
26
	public static final String ID = "pesi";
27
	public static final String LABEL = "PESI";
28
	public static final String URL = "http://www.eu-nomen.eu/portal/index.php";
29
	public static final String DATA_AGR_URL = "";
30
	
31
		
32
	public PESIClient() {
33
		super();
34

    
35
	}
36

    
37
	@Override
38
	public HttpHost getHost() {
39
		// TODO Auto-generated method stub
40
		return new HttpHost("http://www.eu-nomen.eu",80);
41
	}
42

    
43

    
44
	@Override
45
	public ServiceProviderInfo buildServiceProviderInfo() {
46
		ServiceProviderInfo checklistInfo = new ServiceProviderInfo(ID,LABEL,URL,DATA_AGR_URL);
47
		setChecklistInfo(checklistInfo);
48
		return checklistInfo;
49
	}
50

    
51

    
52
	@Override	
53
	public void resolveNames(TnrMsg tnrMsg) throws DRFChecklistException {
54
		List<TnrMsg.Query> queryList = tnrMsg.getQuery();
55
		if(queryList.size() ==  0) {
56
			throw new DRFChecklistException("PESI query list is empty");
57
		}
58

    
59
		if(queryList.size() > 1) {
60
			throw new DRFChecklistException("PESI query list has more than one query");
61
		}
62
		Query query = queryList.get(0);
63

    
64
		//http://www.catalogueoflife.org/col/webservice?response=full&name={sciName}
65
		
66
		String name = query.getTnrRequest().getTaxonName().getName().getNameComplete();
67

    
68
		PESINameServiceLocator pesins = new PESINameServiceLocator();
69
				
70
		PESINameServicePortType pesinspt;
71
		try {
72
			pesinspt = pesins.getPESINameServicePort();
73
		} catch (ServiceException e) {
74
			// TODO Auto-generated catch block
75
			e.printStackTrace();
76
			throw new DRFChecklistException("Error in accessing PESINameService");
77
		}		
78
		updateQueryWithResponse(query,pesinspt,name,getServiceProviderInfo());			
79
	}
80
	
81

    
82
	@Override
83
	public int getMaxPageSize() {		
84
		return 10;
85
	}
86

    
87

    
88

    
89
	private void updateQueryWithResponse(Query query , 
90
			PESINameServicePortType pesinspt,
91
			String name,
92
			ServiceProviderInfo ci) throws DRFChecklistException {
93
		
94
		try {
95
			String nameGUID = pesinspt.getGUID(name);
96
			System.out.println("nameGUID : " + nameGUID);
97
			PESIRecord record = pesinspt.getPESIRecordByGUID(nameGUID);
98
			if(record != null) {	
99
				TnrResponse tnrResponse = new TnrResponse();
100

    
101
				tnrResponse.setChecklist(ci.getLabel());
102
				tnrResponse.setChecklistUrl(ci.getUrl());
103
				
104
				String accNameGUID = record.getValid_guid();
105
				
106
				// case when accepted name
107
				if(record.getGUID().equals(record.getValid_guid())) {
108
					AcceptedName accName = generateAccName(record);
109
					tnrResponse.setAcceptedName(accName);	
110
				} else {
111
					// case when synonym							
112
					PESIRecord accNameRecord = pesinspt.getPESIRecordByGUID(accNameGUID);
113
					AcceptedName accName = generateAccName(accNameRecord);
114
					tnrResponse.setAcceptedName(accName);					
115
				}
116
				
117
				PESIRecord[] records = pesinspt.getPESISynonymsByGUID(accNameGUID);
118
				if(records != null && records.length > 0) {
119
					generateSynonyms(records,tnrResponse);
120
				}
121
				if(query != null) {
122
					query.getTnrResponse().add(tnrResponse);
123
				}
124
			}
125
		}  catch (RemoteException e) {
126
			// TODO Auto-generated catch block
127
			e.printStackTrace();
128
			throw new DRFChecklistException("Error in getGUID method in PESINameService");
129
		}
130

    
131
	}	
132

    
133
	private AcceptedName generateAccName(PESIRecord taxon) {
134
		AcceptedName accName = new AcceptedName();
135
		TaxonNameType taxonName = new TaxonNameType();
136
		NameType name = new NameType();
137
		
138
		String resName = taxon.getScientificname();
139
		name.setNameComplete(resName + " " + taxon.getAuthority());
140

    
141
		name.setNameCanonical(resName);
142
		name.setNameStatus(taxon.getStatus());
143
		
144
		taxonName.setRank(taxon.getRank());
145
		taxonName.setAuthorship(taxon.getAuthority());
146
		taxonName.setName(name);
147
		
148
		accName.setTaxonName(taxonName);
149
					
150
		AcceptedName.Info info = new AcceptedName.Info();
151
		info.setUrl(taxon.getUrl());
152
		accName.setInfo(info);
153
		
154
		
155
		//FIXME : To fill in		
156
		String sourceUrl = taxon.getUrl();
157
	    String sourceDatasetID = "";
158
	    String sourceDatasetName = "";
159
	    String sourceName = "";
160

    
161
	    SourceType source = new SourceType();
162
	    source.setDatasetID(sourceDatasetID);
163
	    source.setDatasetName(sourceDatasetName);
164
	    source.setName(sourceName);
165
	    source.setUrl(sourceUrl);
166
	    accName.setSource(source);
167
	    
168
	    //FIXME : To fill in		
169
	    String accordingTo = taxon.getAuthority();            
170
	    String modified = "";            
171
	    
172
	    ScrutinyType scrutiny = new ScrutinyType();	    
173
		scrutiny.setAccordingTo(accordingTo);
174
		scrutiny.setModified(modified);
175
		accName.setScrutiny(scrutiny);
176

    
177
		AcceptedName.Classification c = new AcceptedName.Classification();
178
		c.setKingdom(taxon.getKingdom());
179
		c.setPhylum(taxon.getPhylum());
180
		c.setClazz("");
181
		c.setOrder(taxon.getOrder());
182
		c.setFamily(taxon.getFamily());
183
		c.setGenus(taxon.getGenus());
184
		accName.setClassification(c);				
185
		
186
		return accName;
187
	}
188

    
189

    
190
	private void generateSynonyms(PESIRecord[] synonyms, TnrResponse tnrResponse) {
191
				
192
		for(PESIRecord synRecord : synonyms) {
193
			TnrResponse.Synonym synonym = new Synonym();
194

    
195
			TaxonNameType taxonName = new TaxonNameType();
196
			NameType name = new NameType();
197
			
198
			String resName = synRecord.getScientificname();
199
			name.setNameComplete(resName + " " + synRecord.getAuthority());
200
			
201
			name.setNameCanonical(resName);
202
			name.setNameStatus(synRecord.getStatus());
203
			
204
			taxonName.setRank(synRecord.getRank());
205
			taxonName.setAuthorship(synRecord.getAuthority());
206
			taxonName.setName(name);
207
			
208
			synonym.setTaxonName(taxonName);
209
			
210
			Synonym.Info info = new Synonym.Info();
211
			info.setUrl(synRecord.getUrl());
212
			synonym.setInfo(info);
213
						
214
			//FIXME : To fill in		
215
			String sourceUrl = synRecord.getUrl();
216
		    String sourceDatasetID =  "";
217
		    String sourceDatasetName = "";
218
		    String sourceName = "";
219

    
220
		    SourceType source = new SourceType();
221
		    source.setDatasetID(sourceDatasetID);
222
		    source.setDatasetName(sourceDatasetName);
223
		    source.setName(sourceName);
224
		    source.setUrl(sourceUrl);
225
		    synonym.setSource(source);
226
		    
227
		    //FIXME : To fill in					
228
		    String accordingTo = synRecord.getAuthority();                 
229
		    String modified = "";            
230
		    
231
		    ScrutinyType scrutiny = new ScrutinyType();	    
232
			scrutiny.setAccordingTo(accordingTo);
233
			scrutiny.setModified(modified);
234
			synonym.setScrutiny(scrutiny);
235
			
236
			tnrResponse.getSynonym().add(synonym);
237
		}
238
	}
239
}
240

    
241

    
(7-7/9)