Project

General

Profile

Download (3.17 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2009 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.cdm.ext.sru;
10

    
11
import java.io.IOException;
12
import java.io.InputStream;
13
import java.net.URI;
14
import java.net.URISyntaxException;
15
import java.util.ArrayList;
16
import java.util.HashMap;
17
import java.util.List;
18
import java.util.Map;
19

    
20
import org.apache.http.NameValuePair;
21
import org.apache.http.message.BasicNameValuePair;
22

    
23
import eu.etaxonomy.cdm.ext.common.SchemaAdapterBase;
24
import eu.etaxonomy.cdm.ext.common.ServiceWrapperBase;
25
import eu.etaxonomy.cdm.model.reference.Reference;
26

    
27

    
28
/**
29
 * @author a.kohlbecker
30
 \* @since 24.08.2010
31
 *
32
 */
33
public class SruServiceWrapper extends ServiceWrapperBase<Reference> {
34

    
35
	private String sruVersion = "1.1";
36

    
37
	/**
38
	 * The GRIB sru service is available at "http://gso.gbv.de/sru/DB=1.83/"
39
	 * The documentation is found at http://bhleurope.gbv.de/#sru from where the following text has been retrieved:
40
	 * <p>
41
	 * General information about Search/Retrieve via URL (SRU) is available in
42
	 * the official SRU specification (http://www.loc.gov/standards/sru/). The SRU-Interface of GRIB supports some
43
	 * specific search keys. Please do not use the (dc) fields but only the
44
	 * (pica) search fields:
45
	 * <dl>
46
	 * <dt>PPN</dt>
47
	 * <dd>Internal record id without prefix 'grib:ppn:' (This may change)</dd>
48
	 * <dt>DST</dt>
49
	 * <dd>Digitization status (8300-8305: 8300=not digitized, 8301=should be digitized, 8302=will be digitized, 8305=document available)</dd>
50
	 * <dt>URL</dt>
51
	 * <dd>URL of a digitized object</dd>
52
	 * <dt>??? (not defined yet)</td>
53
	 * <dd>Stable identifier of a record (PICA+ field 006Y)</dd>
54
	 * </dl>
55
	 * </p>
56
	 * @param cqlQuery
57
	 *            an <b>URL encoded</b> CQL Query string see
58
	 *            {@link http://www.loc.gov/standards/sru/specs/cql.html} for documentation
59
	 * @param recordSchema
60
	 * @return
61
	 */
62
	public List<Reference> doSearchRetrieve(String cqlQuery, String recordSchema){
63

    
64
		List<NameValuePair> pairs = new ArrayList<NameValuePair>();
65

    
66
		SchemaAdapterBase<Reference> schemaAdapter = schemaAdapterMap.get(recordSchema);
67
		if(schemaAdapter == null){
68
			logger.error("No SchemaAdapter found for " + recordSchema);
69
		}
70

    
71
		String sruOperation = "searchRetrieve";
72

    
73
		pairs.add(new BasicNameValuePair("operation", sruOperation));
74
		pairs.add(new BasicNameValuePair("version", sruVersion));
75
		pairs.add(new BasicNameValuePair("query", cqlQuery));
76
		pairs.add(new BasicNameValuePair("recordSchema", recordSchema));
77

    
78
		Map<String, String> requestHeaders = new HashMap<String, String>();
79
		requestHeaders.put("Accept-Charset", "UTF-8");
80

    
81
		try {
82
			URI requestUri = createUri(null, pairs);
83

    
84

    
85
			InputStream stream = executeHttpGet(requestUri, requestHeaders);
86
			return schemaAdapter.getCmdEntities(stream);
87

    
88
		} catch (IOException e) {
89
			// thrown by doHttpGet
90
			logger.error(e);
91
		} catch (URISyntaxException e) {
92
			// thrown by createUri
93
			logger.error(e);
94
		}
95

    
96
		return null;
97

    
98
	}
99

    
100

    
101

    
102
}
    (1-1/1)