Project

General

Profile

« Previous | Next » 

Revision c5e6fc74

Added by Andreas Kohlbecker over 8 years ago

separating query protocol implementation from checklist clients

View differences:

src/main/java/org/bgbm/biovel/drf/occurrences/GBIFOccurrencesClient.java
12 12

  
13 13
import org.apache.http.HttpHost;
14 14
import org.bgbm.biovel.drf.checklist.DRFChecklistException;
15
import org.bgbm.biovel.drf.rest.ServiceProviderInfo;
15
import org.bgbm.biovel.drf.client.ServiceProviderInfo;
16
import org.bgbm.biovel.drf.query.RestClient;
16 17
import org.bgbm.biovel.drf.utils.CSVUtils;
17 18
import org.bgbm.biovel.drf.utils.JSONUtils;
18 19
import org.json.simple.JSONArray;
19 20
import org.json.simple.JSONObject;
20 21

  
21
public class GBIFOccurrencesClient extends BaseOccurrencesClient {
22
public class GBIFOccurrencesClient extends BaseOccurrencesClient<RestClient> {
22 23

  
23 24

  
25
    /**
26
     *
27
     */
28
    private static final HttpHost HTTP_HOST = new HttpHost("api.gbif.org",80);
24 29
    public static final String ID = "gbif";
25 30
    public static final String LABEL = "GBIF Occurrence Bank";
26 31
    public static final String URL = "http://uat.gbif.org/developer/species";
......
34 39
    private final Map<String, JSONObject> orgCacheMap = new HashMap<String, JSONObject>();
35 40
    public final static List<String> nameidList = new ArrayList<String>();
36 41

  
42

  
43
    /**
44
     * {@inheritDoc}
45
     */
37 46
    @Override
38
    public HttpHost getHost() {
39
        // TODO Auto-generated method stub
40
        return new HttpHost("api.gbif.org",80);
47
    public void initQueryClient() {
48
        queryClient = new RestClient(HTTP_HOST);
49

  
41 50
    }
42 51

  
43 52
    @Override
......
46 55
        return 0;
47 56
    }
48 57

  
49

  
50 58
    @Override
51 59
    public ServiceProviderInfo buildServiceProviderInfo() {
52 60
        ServiceProviderInfo ocbankInfo = CINFO;
......
56 64
    @Override
57 65
    public String getOccurrences(String nameid) throws DRFChecklistException {
58 66

  
59
        URI namesUri = buildUriFromQueryString(nameid, "/" + CINFO.getVersion() + "/species/match", "name", null);
60
        String nameResponse = processRESTService(namesUri);
67
        URI namesUri = queryClient.buildUriFromQueryString(nameid, "/" + CINFO.getVersion() + "/species/match", "name", null);
68
        String nameResponse = queryClient.processRESTService(namesUri);
61 69
        JSONObject nameJsonResponse = JSONUtils.parseJsonToObject(nameResponse);
62 70
        StringBuilder occurrences = new StringBuilder();
63 71
        if(nameJsonResponse.get("usageKey") != null) {
......
75 83
                int count = 0;
76 84
                do {
77 85
                    paramMap.put("offset", Integer.toString(offset));
78
                    URI occUri = buildUriFromQueryString(usageKey, "/" + CINFO.getVersion() + "/occurrence/search", "taxonKey", paramMap);
86
                    URI occUri = queryClient.buildUriFromQueryString(usageKey, "/" + CINFO.getVersion() + "/occurrence/search", "taxonKey", paramMap);
79 87

  
80
                    String occResponse = processRESTService(occUri);
88
                    String occResponse = queryClient.processRESTService(occUri);
81 89

  
82 90
                    JSONObject jsonOccResponse = JSONUtils.parseJsonToObject(occResponse);
83 91
                    JSONArray results = (JSONArray) jsonOccResponse.get("results");
......
210 218
                                String datasetKey = (String) jsonOccurence.get("datasetKey");
211 219
                                datasetJsonResponse = datasetCacheMap.get(datasetKey);
212 220
                                if(datasetJsonResponse == null) {
213
                                    URI datasetUri = buildUriFromQueryString("/" + CINFO.getVersion() + "/dataset/" + datasetKey, null);
214
                                    String datasetResponse = processRESTService(datasetUri);
221
                                    URI datasetUri = queryClient.buildUriFromQueryString("/" + CINFO.getVersion() + "/dataset/" + datasetKey, null);
222
                                    String datasetResponse = queryClient.processRESTService(datasetUri);
215 223
                                    datasetJsonResponse = JSONUtils.parseJsonToObject(datasetResponse);
216 224
                                    datasetCacheMap.put(datasetKey, datasetJsonResponse);
217 225
                                }
......
222 230
                                String owningOrganizationKey = (String) datasetJsonResponse.get("owningOrganizationKey");
223 231
                                orgJsonResponse = orgCacheMap.get(owningOrganizationKey);
224 232
                                if(orgJsonResponse == null) {
225
                                    URI orgUri = buildUriFromQueryString("/" + CINFO.getVersion() + "/organization/" + owningOrganizationKey, null);
226
                                    String orgResponse = processRESTService(orgUri);
233
                                    URI orgUri = queryClient.buildUriFromQueryString("/" + CINFO.getVersion() + "/organization/" + owningOrganizationKey, null);
234
                                    String orgResponse = queryClient.processRESTService(orgUri);
227 235
                                    orgJsonResponse = JSONUtils.parseJsonToObject(orgResponse);
228 236
                                    orgCacheMap.put(owningOrganizationKey, orgJsonResponse);
229 237
                                }
......
267 275
        return occurrences.toString();
268 276
    }
269 277

  
270

  
271

  
272

  
273 278
}

Also available in: Unified diff