1
2
3
4
5
6
7
8
9
10
11 package org.astrogrid.dataservice.impl.sec;
12
13 import java.io.IOException;
14 import java.net.MalformedURLException;
15 import java.net.URL;
16 import java.rmi.RemoteException;
17 import java.security.Principal;
18 import javax.xml.parsers.ParserConfigurationException;
19 import javax.xml.rpc.ServiceException;
20 import org.astrogrid.dataservice.impl.sec.SEC_Port;
21 import org.astrogrid.dataservice.impl.sec.SEC_Service;
22 import org.astrogrid.dataservice.impl.sec.SEC_ServiceLocator;
23 import org.astrogrid.dataservice.queriers.DefaultPlugin;
24 import org.astrogrid.dataservice.queriers.Querier;
25 import org.astrogrid.dataservice.queriers.QuerierPluginException;
26 import org.astrogrid.dataservice.queriers.VotableDomResults;
27 import org.astrogrid.tableserver.jdbc.StdSqlMaker;
28 import org.astrogrid.dataservice.queriers.status.QuerierQuerying;
29 import org.astrogrid.query.Query;
30 import org.xml.sax.SAXException;
31
32 /*** Datacenter querier that performs queries against SEC webservice.
33 * @author Kevin Benson kmb@mssl.ucl.ac.uk
34 * @author mch
35 */
36 public class EgsoQuerierPlugin extends DefaultPlugin {
37
38 public final static String SEC_URL = "http://radiosun.ts.astro.it/sec/sec_server.php";
39
40 /*** WSDL-generated binding to the service */
41 protected SEC_Port secPort;
42
43 public EgsoQuerierPlugin() throws ServiceException, MalformedURLException {
44 SEC_Service service = new SEC_ServiceLocator();
45 secPort = service.getSECPort(new URL(SEC_URL));
46 }
47
48 /*** Called by the querier plugin mechanism to do the query.
49 * The EGSO service takes an SQL string and returns a VOTable.
50 */
51 public void askQuery(Principal user, Query query, Querier querier) throws IOException {
52
53
54 StdSqlMaker ssm = new StdSqlMaker();
55
56 String sql = ssm.makeSql(query);
57
58 querier.setStatus(new QuerierQuerying(querier.getStatus(), sql));
59
60 try {
61
62 String resultsVot = secPort.sql(sql);
63 VotableDomResults results = new VotableDomResults(querier, resultsVot);
64 if (!aborted) {
65 results.send(query.getResultsDef(), querier.getUser());
66 }
67 }
68 catch (RemoteException e) {
69 throw new QuerierPluginException(e+" from PAL to EGSO, Submitting '"+sql+"' to EGSO service at "+SEC_URL,e);
70 }
71 catch (SAXException e) {
72 throw new QuerierPluginException(e+" parsing results from submitting '"+sql+"' to EGSO service at "+SEC_URL,e);
73 }
74 catch (ParserConfigurationException e) {
75 throw new QuerierPluginException(e+", Server Configuration Error",e);
76 }
77 }
78
79 /*** Returns just the number of matches rather than the list of matches */
80 public long getCount(Principal user, Query query, Querier querier) throws IOException {
81
82 StdSqlMaker ssm = new StdSqlMaker();
83 String sql = ssm.makeCountSql(query);
84
85 querier.setStatus(new QuerierQuerying(querier.getStatus(), sql));
86
87 try {
88
89 String resultsVot = secPort.sql(sql);
90 VotableDomResults results = new VotableDomResults(querier, resultsVot);
91 if (!aborted) {
92 throw new UnsupportedOperationException("Not done yet");
93 }
94 return -1;
95 }
96 catch (RemoteException e) {
97 throw new QuerierPluginException(e+" from PAL to EGSO, Submitting '"+sql+"' to EGSO service at "+SEC_URL,e);
98 }
99 catch (SAXException e) {
100 throw new QuerierPluginException(e+" parsing results from submitting '"+sql+"' to EGSO service at "+SEC_URL,e);
101 }
102 catch (ParserConfigurationException e) {
103 throw new QuerierPluginException(e+", Server Configuration Error",e);
104 }
105 }
106
107 /*** Returns the formats that this plugin can provide. Asks the results class; override in subclasse if nec */
108 public String[] getFormats() {
109 return VotableDomResults.listFormats();
110 }
111
112
113
114 }
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200