Revision 745
Added by Matt Jones over 23 years ago
src/edu/ucsb/nceas/metacat/QuerySpecification.java | ||
---|---|---|
50 | 50 |
*/ |
51 | 51 |
public class QuerySpecification extends DefaultHandler { |
52 | 52 |
|
53 |
/** flag determining whether extended query terms are present */ |
|
53 | 54 |
private boolean containsExtendedSQL=false; |
54 |
|
|
55 |
// Query data structures |
|
55 |
/** Identifier for this query document */ |
|
56 | 56 |
private String meta_file_id; |
57 |
/** Title of this query */ |
|
58 |
private String queryTitle; |
|
59 |
/** List of document types to be returned using package back tracing */ |
|
57 | 60 |
private Vector returnDocList; |
61 |
/** List of document types to be searched */ |
|
58 | 62 |
private Vector filterDocList; |
63 |
/** List of fields to be returned in result set */ |
|
59 | 64 |
private Vector returnFieldList; |
65 |
/** List of users owning documents to be searched */ |
|
60 | 66 |
private Vector ownerList; |
67 |
/** List of sites/scopes used to constrain search */ |
|
61 | 68 |
private Vector siteList; |
69 |
/** The root query group that contains the recursive query constraints */ |
|
62 | 70 |
private QueryGroup query = null; |
63 | 71 |
|
72 |
// Query data structures used temporarily during XML parsing |
|
64 | 73 |
private Stack elementStack; |
65 | 74 |
private Stack queryStack; |
66 | 75 |
private String currentValue; |
... | ... | |
166 | 175 |
} |
167 | 176 |
|
168 | 177 |
/** |
178 |
* Accessor method to return the identifier of this Query |
|
179 |
*/ |
|
180 |
public String getIdentifier() |
|
181 |
{ |
|
182 |
return meta_file_id; |
|
183 |
} |
|
184 |
|
|
185 |
/** |
|
186 |
* method to set the identifier of this query |
|
187 |
*/ |
|
188 |
public void setIdentifier(String id) { |
|
189 |
this.meta_file_id = id; |
|
190 |
} |
|
191 |
|
|
192 |
/** |
|
193 |
* Accessor method to return the title of this Query |
|
194 |
*/ |
|
195 |
public String getQueryTitle() |
|
196 |
{ |
|
197 |
return queryTitle; |
|
198 |
} |
|
199 |
|
|
200 |
/** |
|
201 |
* method to set the title of this query |
|
202 |
*/ |
|
203 |
public void setQueryTitle(String title) |
|
204 |
{ |
|
205 |
this.queryTitle = title; |
|
206 |
} |
|
207 |
|
|
208 |
/** |
|
209 |
* Accessor method to return a vector of the return document types as |
|
210 |
* defined in the <returndoctype> tag in the pathquery dtd. |
|
211 |
*/ |
|
212 |
public Vector getReturnDocList() |
|
213 |
{ |
|
214 |
return this.returnDocList; |
|
215 |
} |
|
216 |
|
|
217 |
/** |
|
218 |
* method to set the list of return docs of this query |
|
219 |
*/ |
|
220 |
public void setReturnDocList(Vector returnDocList) |
|
221 |
{ |
|
222 |
this.returnDocList = returnDocList; |
|
223 |
} |
|
224 |
|
|
225 |
/** |
|
226 |
* Accessor method to return a vector of the filter doc types as |
|
227 |
* defined in the <filterdoctype> tag in the pathquery dtd. |
|
228 |
*/ |
|
229 |
public Vector getFilterDocList() |
|
230 |
{ |
|
231 |
return this.filterDocList; |
|
232 |
} |
|
233 |
|
|
234 |
/** |
|
235 |
* method to set the list of filter docs of this query |
|
236 |
*/ |
|
237 |
public void setFilterDocList(Vector filterDocList) |
|
238 |
{ |
|
239 |
this.filterDocList = filterDocList; |
|
240 |
} |
|
241 |
|
|
242 |
/** |
|
169 | 243 |
* Accessor method to return a vector of the extended return fields as |
170 | 244 |
* defined in the <returnfield> tag in the pathquery dtd. |
171 | 245 |
*/ |
... | ... | |
175 | 249 |
} |
176 | 250 |
|
177 | 251 |
/** |
252 |
* method to set the list of fields to be returned by this query |
|
253 |
*/ |
|
254 |
public void setReturnFieldList(Vector returnFieldList) |
|
255 |
{ |
|
256 |
this.returnFieldList = returnFieldList; |
|
257 |
} |
|
258 |
|
|
259 |
/** |
|
260 |
* Accessor method to return a vector of the owner fields as |
|
261 |
* defined in the <owner> tag in the pathquery dtd. |
|
262 |
*/ |
|
263 |
public Vector getOwnerList() |
|
264 |
{ |
|
265 |
return this.ownerList; |
|
266 |
} |
|
267 |
|
|
268 |
/** |
|
269 |
* method to set the list of owners used to constrain this query |
|
270 |
*/ |
|
271 |
public void setOwnerList(Vector ownerList) |
|
272 |
{ |
|
273 |
this.ownerList = ownerList; |
|
274 |
} |
|
275 |
|
|
276 |
/** |
|
277 |
* Accessor method to return a vector of the site fields as |
|
278 |
* defined in the <site> tag in the pathquery dtd. |
|
279 |
*/ |
|
280 |
public Vector getSiteList() |
|
281 |
{ |
|
282 |
return this.siteList; |
|
283 |
} |
|
284 |
|
|
285 |
/** |
|
286 |
* method to set the list of sites used to constrain this query |
|
287 |
*/ |
|
288 |
public void setSiteList(Vector siteList) |
|
289 |
{ |
|
290 |
this.siteList = siteList; |
|
291 |
} |
|
292 |
|
|
293 |
/** |
|
294 |
* get the QueryGroup used to express query constraints |
|
295 |
*/ |
|
296 |
public QueryGroup getQueryGroup() |
|
297 |
{ |
|
298 |
return query; |
|
299 |
} |
|
300 |
|
|
301 |
/** |
|
178 | 302 |
* Set up the SAX parser for reading the XML serialized query |
179 | 303 |
*/ |
180 | 304 |
private XMLReader initializeParser() { |
... | ... | |
272 | 396 |
String currentTag = currentNode.getTagName(); |
273 | 397 |
if (currentTag.equals("meta_file_id")) { |
274 | 398 |
meta_file_id = inputString; |
399 |
} else if (currentTag.equals("querytitle")) { |
|
400 |
queryTitle = inputString; |
|
275 | 401 |
} else if (currentTag.equals("value")) { |
276 | 402 |
currentValue = inputString; |
277 | 403 |
} else if (currentTag.equals("pathexpr")) { |
278 | 404 |
currentPathexpr = inputString; |
279 | 405 |
} else if (currentTag.equals("returndoctype")) { |
280 | 406 |
returnDocList.add(inputString); |
407 |
} else if (currentTag.equals("filterdoctype")) { |
|
408 |
filterDocList.add(inputString); |
|
281 | 409 |
} else if (currentTag.equals("returnfield")) { |
282 | 410 |
returnFieldList.add(inputString); |
283 | 411 |
containsExtendedSQL = true; |
src/edu/ucsb/nceas/metacat/DBQuery.java | ||
---|---|---|
176 | 176 |
this.parserName = parserName; |
177 | 177 |
} |
178 | 178 |
|
179 |
public Hashtable findDocuments(Reader xmlquery, String user, String group, |
|
180 |
boolean useXMLIndex) |
|
179 |
/** |
|
180 |
* routine to search the elements and attributes looking to match query |
|
181 |
* |
|
182 |
* @param xmlquery the xml serialization of the query (@see pathquery.dtd) |
|
183 |
* @param user the username of the user |
|
184 |
* @param group the group of the user |
|
185 |
*/ |
|
186 |
public Hashtable findDocuments(Reader xmlquery, String user, String group) |
|
181 | 187 |
{ |
182 |
return findDocuments(xmlquery, user, group, null, useXMLIndex);
|
|
188 |
return findDocuments(xmlquery, user, group, true);
|
|
183 | 189 |
} |
184 |
|
|
185 |
public Hashtable findDocuments(Reader xmlquery, String user, String group, |
|
186 |
String[] returndoc) |
|
187 |
{ |
|
188 |
return findDocuments(xmlquery, user, group, returndoc, true); |
|
189 |
} |
|
190 | 190 |
|
191 | 191 |
/** |
192 | 192 |
* routine to search the elements and attributes looking to match query |
... | ... | |
194 | 194 |
* @param xmlquery the xml serialization of the query (@see pathquery.dtd) |
195 | 195 |
* @param user the username of the user |
196 | 196 |
* @param group the group of the user |
197 |
* @param returndoc an array of document types to backtrack against.
|
|
197 |
* @param useXMLIndex flag whether to search using the path index
|
|
198 | 198 |
*/ |
199 | 199 |
public Hashtable findDocuments(Reader xmlquery, String user, String group, |
200 |
String[] returndoc, boolean useXMLIndex)
|
|
200 |
boolean useXMLIndex) |
|
201 | 201 |
{ |
202 | 202 |
Hashtable docListResult = new Hashtable(); |
203 | 203 |
PreparedStatement pstmt = null; |
... | ... | |
212 | 212 |
Connection dbconn = null; |
213 | 213 |
int rev = 0; |
214 | 214 |
StringBuffer document = null; |
215 |
Vector returndocVec = new Vector(); |
|
216 | 215 |
|
217 |
//add the returndoc elements to a vector for easier manipulation |
|
218 |
if (returndoc != null) |
|
219 |
{ |
|
220 |
for(int i=0; i<returndoc.length; i++) |
|
221 |
{ |
|
222 |
returndocVec.add(new String((String)returndoc[i])); |
|
223 |
} |
|
224 |
} |
|
225 |
|
|
226 | 216 |
try { |
227 | 217 |
if (conn == null || conn.isClosed()) { |
228 | 218 |
dbconn = util.openDBConnection(); |
... | ... | |
253 | 243 |
updateDate = rs.getString(5); |
254 | 244 |
rev = rs.getInt(6); |
255 | 245 |
|
256 |
//if there are returndocs to match, backtracking can be performed |
|
257 |
// If no package exists, do not return the document |
|
246 |
// if there are returndocs to match, backtracking can be performed |
|
247 |
// otherwise, just return the document that was hit |
|
248 |
Vector returndocVec = qspec.getReturnDocList(); |
|
258 | 249 |
if (returndocVec.size() != 0 && !returndocVec.contains(doctype)) |
259 | 250 |
{ |
251 |
MetaCatUtil.debugMessage("Back tracing now..."); |
|
260 | 252 |
String sep = util.getOption("accNumSeparator"); |
261 | 253 |
StringBuffer btBuf = new StringBuffer(); |
262 | 254 |
btBuf.append("select docid from xml_relation where "); |
src/edu/ucsb/nceas/metacat/MetaCatServlet.java | ||
---|---|---|
480 | 480 |
String xmlquery = ((String[])params.get("query"))[0]; |
481 | 481 |
String qformat = ((String[])params.get("qformat"))[0]; |
482 | 482 |
String resultdoc = null; |
483 |
String[] returndoc = null; |
|
484 |
if(params.contains("returndoctype")) |
|
485 |
{ |
|
486 |
returndoc = (String[])params.get("returndoctype"); |
|
487 |
} |
|
488 | 483 |
|
489 |
Hashtable doclist = runQuery(xmlquery, user, group, returndoc);
|
|
484 |
Hashtable doclist = runQuery(xmlquery, user, group); |
|
490 | 485 |
|
491 | 486 |
resultdoc = createResultDocument(doclist, transformQuery(xmlquery)); |
492 | 487 |
|
... | ... | |
513 | 508 |
HttpServletResponse response, String user, String group) |
514 | 509 |
{ |
515 | 510 |
//create the query and run it |
516 |
String[] returndoc = null; |
|
517 |
if(params.containsKey("returndoctype")) |
|
518 |
{ |
|
519 |
returndoc = (String[])params.get("returndoctype"); |
|
520 |
if (((String)returndoc[0]).equals("any") || |
|
521 |
((String)returndoc[0]).equals("ANY") || |
|
522 |
((String)returndoc[0]).equals("")) { |
|
523 |
returndoc = null; |
|
524 |
} |
|
525 |
} |
|
526 | 511 |
String xmlquery = DBQuery.createSQuery(params); |
527 |
Hashtable doclist = runQuery(xmlquery, user, group, returndoc);
|
|
512 |
Hashtable doclist = runQuery(xmlquery, user, group); |
|
528 | 513 |
String qformat = ((String[])params.get("qformat"))[0]; |
529 | 514 |
String resultdoc = null; |
530 | 515 |
|
... | ... | |
579 | 564 |
* |
580 | 565 |
* @param xmlquery the query to run |
581 | 566 |
*/ |
582 |
private Hashtable runQuery(String xmlquery, String user, String group, |
|
583 |
String[] returndoc) |
|
567 |
private Hashtable runQuery(String xmlquery, String user, String group) |
|
584 | 568 |
{ |
585 | 569 |
Hashtable doclist=null; |
586 | 570 |
Connection conn = null; |
... | ... | |
588 | 572 |
{ |
589 | 573 |
conn = util.getConnection(); |
590 | 574 |
DBQuery queryobj = new DBQuery(conn, saxparser); |
591 |
doclist = queryobj.findDocuments(new StringReader(xmlquery),user,group, |
|
592 |
returndoc); |
|
575 |
doclist = queryobj.findDocuments(new StringReader(xmlquery),user,group); |
|
593 | 576 |
util.returnConnection(conn); |
594 | 577 |
return doclist; |
595 | 578 |
} |
Also available in: Unified diff
Fixed bug in metacat where return doctypes were not being properly
back traced. Changed DBQuery.findDocuments() so that it no longer
takes a returndoc array, but instead retrieves the returndoc array
fromthe QUERYSpecification. The QuerySpecification was augmented
with a whole bunch of get/set accessor methods.