Project

General

Profile

Download (3.14 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
 * @author a.kohlbecker
29
 * @since 24.08.2010
30
 */
31
public class SruServiceWrapper extends ServiceWrapperBase<Reference> {
32

    
33
	private String sruVersion = "1.1";
34

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

    
62
		List<NameValuePair> pairs = new ArrayList<NameValuePair>();
63

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

    
69
		String sruOperation = "searchRetrieve";
70

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

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

    
79
		try {
80
			URI requestUri = createUri(null, pairs);
81

    
82
			InputStream stream = executeHttpGet(requestUri, requestHeaders);
83
			return schemaAdapter.getCmdEntities(stream);
84

    
85
		} catch (IOException e) {
86
			// thrown by doHttpGet
87
			logger.error(e);
88
		} catch (URISyntaxException e) {
89
			// thrown by createUri
90
			logger.error(e);
91
		}
92

    
93
		return null;
94
	}
95
}
    (1-1/1)