1
|
/**
|
2
|
* '$RCSfile$'
|
3
|
* Purpose: A class that gets Accession Number, check for uniqueness
|
4
|
* and register it into db
|
5
|
* Copyright: 2000 Regents of the University of California and the
|
6
|
* National Center for Ecological Analysis and Synthesis
|
7
|
* Authors: Jivka Bojilova, Matt Jones
|
8
|
*
|
9
|
* '$Author: tao $'
|
10
|
* '$Date: 2013-04-19 17:47:14 -0700 (Fri, 19 Apr 2013) $'
|
11
|
* '$Revision: 7595 $'
|
12
|
*
|
13
|
* This program is free software; you can redistribute it and/or modify
|
14
|
* it under the terms of the GNU General Public License as published by
|
15
|
* the Free Software Foundation; either version 2 of the License, or
|
16
|
* (at your option) any later version.
|
17
|
*
|
18
|
* This program is distributed in the hope that it will be useful,
|
19
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
20
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
21
|
* GNU General Public License for more details.
|
22
|
*
|
23
|
* You should have received a copy of the GNU General Public License
|
24
|
* along with this program; if not, write to the Free Software
|
25
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
26
|
*/
|
27
|
package edu.ucsb.nceas.metacat.common.query;
|
28
|
|
29
|
import java.io.IOException;
|
30
|
import java.io.InputStream;
|
31
|
import java.net.MalformedURLException;
|
32
|
import java.net.URL;
|
33
|
import java.util.List;
|
34
|
import java.util.Map;
|
35
|
import java.util.Set;
|
36
|
|
37
|
import org.apache.solr.client.solrj.impl.CommonsHttpSolrServer;
|
38
|
import org.apache.solr.client.solrj.response.QueryResponse;
|
39
|
import org.apache.solr.common.params.SolrParams;
|
40
|
import org.apache.solr.schema.SchemaField;
|
41
|
import org.dataone.cn.indexer.solrhttp.HTTPService;
|
42
|
import org.dataone.cn.indexer.solrhttp.SolrDoc;
|
43
|
import org.dataone.service.exceptions.NotFound;
|
44
|
import org.dataone.service.exceptions.NotImplemented;
|
45
|
import org.dataone.service.exceptions.UnsupportedType;
|
46
|
import org.dataone.service.types.v1.Subject;
|
47
|
|
48
|
import edu.ucsb.nceas.metacat.common.SolrQueryResponseTransformer;
|
49
|
|
50
|
/**
|
51
|
* The query service for the http solr server.
|
52
|
* @author tao
|
53
|
*
|
54
|
*/
|
55
|
public class HttpSolrQueryService extends SolrQueryService {
|
56
|
|
57
|
private String solrServerBaseURL = null;
|
58
|
private CommonsHttpSolrServer httpSolrServer = null;
|
59
|
|
60
|
/**
|
61
|
* Constructor
|
62
|
* @param httpSolrServer
|
63
|
*/
|
64
|
public HttpSolrQueryService(CommonsHttpSolrServer httpSolrServer) {
|
65
|
if(httpSolrServer == null) {
|
66
|
throw new NullPointerException("HttpSolrQueryService.constructor - The httpSolrServer parameter can't be null");
|
67
|
}
|
68
|
this.httpSolrServer = httpSolrServer;
|
69
|
this.solrServerBaseURL = httpSolrServer.getBaseURL();
|
70
|
}
|
71
|
|
72
|
/**
|
73
|
* Query the Solr server with specified query and user's identity. If the Subjects
|
74
|
* is null, there will be no access rules for the query. This is the for the http solr server.
|
75
|
* @param query the query string
|
76
|
* @param subjects the user's identity which sent the query
|
77
|
* @return the response
|
78
|
* @throws NotFound
|
79
|
* @throws IOException
|
80
|
* @throws Exception
|
81
|
*/
|
82
|
public InputStream query(String query, Set<Subject>subjects) throws NotFound, IOException {
|
83
|
StringBuffer accessFilter = generateAccessFilterParamsString(subjects);
|
84
|
if(accessFilter != null && accessFilter.length() != 0) {
|
85
|
query = solrServerBaseURL+"/select?"+query+"&"+FILTERQUERY+"="+accessFilter.toString();
|
86
|
query = HTTPService.escapeQueryChars(query);
|
87
|
} else {
|
88
|
throw new NotFound("0000", "HttpSolrQueryService.query - There is no identity (even user public) for the user who issued the query");
|
89
|
}
|
90
|
URL url = new URL(query);
|
91
|
return url.openStream();
|
92
|
}
|
93
|
|
94
|
/**
|
95
|
* Query the Solr server with specified query and user's identity. If the Subjects
|
96
|
* is null, there will be no access rules for the query. This is for the embedded solr server.
|
97
|
* @param query the query params.
|
98
|
* @param subjects the user's identity which sent the query
|
99
|
* @return the response
|
100
|
* @throws Exception
|
101
|
*/
|
102
|
public InputStream query(SolrParams query, Set<Subject>subjects) throws Exception {
|
103
|
throw new NotImplemented("0000", "HttpSolrQueryService - the method of query(SolrParams query, Set<Subject>subjects) is not for the HttpSolrQueryService. We donot need to implemente it");
|
104
|
}
|
105
|
|
106
|
|
107
|
/**
|
108
|
* Get the list of SolrDocs for the specified ids from the solr server.
|
109
|
* * Note: each id only can have one SolrDoc or null SolrDoc. If it is null, it
|
110
|
* wouldn't be added to the list.
|
111
|
* @param ids the specified ids
|
112
|
* @return the SolrDocs of the ids.
|
113
|
* @throws Exception
|
114
|
*/
|
115
|
public List<SolrDoc> query(List<String> ids) throws Exception {
|
116
|
return null;
|
117
|
}
|
118
|
|
119
|
|
120
|
/**
|
121
|
* Get the fields list of the index schema
|
122
|
* @return
|
123
|
* @throws Exception
|
124
|
*/
|
125
|
public Map<String, SchemaField> getIndexSchemaFields() throws Exception {
|
126
|
return null;
|
127
|
}
|
128
|
|
129
|
/**
|
130
|
* Get the version of the solr server.
|
131
|
* @return
|
132
|
*/
|
133
|
public String getSolrServerVersion() {
|
134
|
return null;
|
135
|
}
|
136
|
}
|