1 |
7713
|
tao
|
/**
|
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 |
7714
|
tao
|
import org.apache.commons.logging.Log;
|
38 |
|
|
import org.apache.commons.logging.LogFactory;
|
39 |
7713
|
tao
|
import org.apache.solr.client.solrj.impl.CommonsHttpSolrServer;
|
40 |
7716
|
tao
|
import org.apache.solr.client.solrj.util.ClientUtils;
|
41 |
7714
|
tao
|
|
42 |
7713
|
tao
|
import org.apache.solr.common.params.SolrParams;
|
43 |
|
|
import org.apache.solr.schema.SchemaField;
|
44 |
|
|
import org.dataone.service.exceptions.NotFound;
|
45 |
|
|
import org.dataone.service.exceptions.NotImplemented;
|
46 |
|
|
import org.dataone.service.types.v1.Subject;
|
47 |
|
|
|
48 |
|
|
|
49 |
7714
|
tao
|
|
50 |
7713
|
tao
|
/**
|
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 |
7714
|
tao
|
private static Log log = LogFactory.getLog(HttpSolrQueryService.class);
|
60 |
7713
|
tao
|
/**
|
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 |
7714
|
tao
|
* Query the Solr server with specified query string and the user's identity. This is the for the http solr server.
|
74 |
|
|
* It is hard to transform the SolrQueryReponse object to the InputStream object for the HttpSolrServer
|
75 |
|
|
* since the transform needs the SolrCore. We have to open the solr url directly to get the InputStream.
|
76 |
7713
|
tao
|
* @param query the query string
|
77 |
|
|
* @param subjects the user's identity which sent the query
|
78 |
|
|
* @return the response
|
79 |
|
|
* @throws NotFound
|
80 |
|
|
* @throws IOException
|
81 |
|
|
* @throws Exception
|
82 |
|
|
*/
|
83 |
|
|
public InputStream query(String query, Set<Subject>subjects) throws NotFound, IOException {
|
84 |
|
|
StringBuffer accessFilter = generateAccessFilterParamsString(subjects);
|
85 |
|
|
if(accessFilter != null && accessFilter.length() != 0) {
|
86 |
|
|
query = solrServerBaseURL+"/select?"+query+"&"+FILTERQUERY+"="+accessFilter.toString();
|
87 |
7716
|
tao
|
query = ClientUtils.escapeQueryChars(query);
|
88 |
7713
|
tao
|
} else {
|
89 |
|
|
throw new NotFound("0000", "HttpSolrQueryService.query - There is no identity (even user public) for the user who issued the query");
|
90 |
|
|
}
|
91 |
7714
|
tao
|
log.info("==========HttpSolrQueryService.query - the final url for querying the solr http server is "+query);
|
92 |
7713
|
tao
|
URL url = new URL(query);
|
93 |
7714
|
tao
|
|
94 |
7713
|
tao
|
return url.openStream();
|
95 |
|
|
}
|
96 |
|
|
|
97 |
|
|
/**
|
98 |
|
|
* Query the Solr server with specified query and user's identity. If the Subjects
|
99 |
|
|
* is null, there will be no access rules for the query. This is for the embedded solr server.
|
100 |
|
|
* @param query the query params.
|
101 |
|
|
* @param subjects the user's identity which sent the query
|
102 |
|
|
* @return the response
|
103 |
|
|
* @throws Exception
|
104 |
|
|
*/
|
105 |
|
|
public InputStream query(SolrParams query, Set<Subject>subjects) throws Exception {
|
106 |
|
|
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");
|
107 |
|
|
}
|
108 |
|
|
|
109 |
|
|
|
110 |
|
|
|
111 |
|
|
|
112 |
|
|
/**
|
113 |
|
|
* Get the fields list of the index schema
|
114 |
|
|
* @return
|
115 |
|
|
* @throws Exception
|
116 |
|
|
*/
|
117 |
|
|
public Map<String, SchemaField> getIndexSchemaFields() throws Exception {
|
118 |
|
|
return null;
|
119 |
|
|
}
|
120 |
|
|
|
121 |
|
|
/**
|
122 |
|
|
* Get the version of the solr server.
|
123 |
|
|
* @return
|
124 |
|
|
*/
|
125 |
|
|
public String getSolrServerVersion() {
|
126 |
|
|
return null;
|
127 |
|
|
}
|
128 |
7716
|
tao
|
|
129 |
|
|
|
130 |
7713
|
tao
|
}
|