Revision 465
Added by berkley about 24 years ago
src/edu/ucsb/nceas/metacat/DocumentImpl.java | ||
---|---|---|
52 | 52 |
private String docid = null; |
53 | 53 |
private String docname = null; |
54 | 54 |
private String doctype = null; |
55 |
private String doctitle = null; |
|
56 |
private String createdate = null; |
|
57 |
private String updatedate = null; |
|
55 | 58 |
private String system_id = null; |
56 | 59 |
private long rootnodeid; |
57 | 60 |
private ElementNode rootNode = null; |
58 |
private String doctitle = null; |
|
59 | 61 |
private TreeSet nodeRecordList = null; |
60 | 62 |
|
61 | 63 |
/** |
... | ... | |
67 | 69 |
*/ |
68 | 70 |
public DocumentImpl(Connection conn, String docid) throws McdbException |
69 | 71 |
{ |
70 |
try { |
|
72 |
try {
|
|
71 | 73 |
this.conn = conn; |
72 | 74 |
this.docid = docid; |
73 | 75 |
|
... | ... | |
144 | 146 |
public long getRootNodeID() { |
145 | 147 |
return rootnodeid; |
146 | 148 |
} |
149 |
|
|
150 |
/** |
|
151 |
* get the creation date |
|
152 |
*/ |
|
153 |
public String getCreateDate() { |
|
154 |
return createdate; |
|
155 |
} |
|
156 |
|
|
157 |
/** |
|
158 |
* get the update date |
|
159 |
*/ |
|
160 |
public String getUpdateDate() { |
|
161 |
return updatedate; |
|
162 |
} |
|
147 | 163 |
|
148 | 164 |
/** |
149 | 165 |
* Get the document identifier (docid) |
... | ... | |
151 | 167 |
public String getDocID() { |
152 | 168 |
return docid; |
153 | 169 |
} |
170 |
|
|
171 |
/** |
|
172 |
*get the document title |
|
173 |
*/ |
|
174 |
public String getDocTitle() { |
|
175 |
return doctitle; |
|
176 |
} |
|
154 | 177 |
|
155 | 178 |
|
156 | 179 |
/** |
... | ... | |
338 | 361 |
|
339 | 362 |
try { |
340 | 363 |
pstmt = |
341 |
conn.prepareStatement("SELECT docname,doctype,rootnodeid " + |
|
342 |
"FROM xml_documents " + |
|
364 |
conn.prepareStatement("SELECT docname, doctype, rootnodeid,doctitle, " + |
|
365 |
"date_created, date_updated " + |
|
366 |
"FROM xml_documents " + |
|
343 | 367 |
"WHERE docid LIKE ?"); |
344 | 368 |
// Bind the values to the query |
345 | 369 |
pstmt.setString(1, docid); |
... | ... | |
351 | 375 |
this.docname = rs.getString(1); |
352 | 376 |
this.doctype = rs.getString(2); |
353 | 377 |
this.rootnodeid = rs.getLong(3); |
378 |
this.doctitle = rs.getString(4); |
|
379 |
this.createdate = rs.getString(5); |
|
380 |
this.updatedate = rs.getString(6); |
|
354 | 381 |
} |
355 | 382 |
pstmt.close(); |
356 | 383 |
|
... | ... | |
516 | 543 |
* |
517 | 544 |
* @param title the new title for the document |
518 | 545 |
*/ |
546 |
|
|
519 | 547 |
public void setTitle( String title ) { |
520 | 548 |
this.doctitle = title; |
521 | 549 |
try { |
src/edu/ucsb/nceas/metacat/metacatURL.java | ||
---|---|---|
20 | 20 |
{ |
21 | 21 |
private String[][] params = new String[200][2]; |
22 | 22 |
private String urlType = null; |
23 |
private String url; |
|
23 | 24 |
|
24 | 25 |
/** |
25 | 26 |
* This constructor takes a string url and parses it according to the |
... | ... | |
36 | 37 |
*/ |
37 | 38 |
public metacatURL(String url) throws MalformedURLException |
38 | 39 |
{ |
40 |
this.url = url; |
|
39 | 41 |
parseURL(url); |
40 | 42 |
} |
41 | 43 |
|
... | ... | |
152 | 154 |
} |
153 | 155 |
|
154 | 156 |
/** |
157 |
* returns a string representation of this metacatURL |
|
158 |
*/ |
|
159 |
public String toString() |
|
160 |
{ |
|
161 |
return this.url; |
|
162 |
} |
|
163 |
|
|
164 |
/** |
|
155 | 165 |
* Prints the parameters neatly to system.out |
156 | 166 |
*/ |
157 | 167 |
public void printParams() |
src/edu/ucsb/nceas/metacat/QuerySpecification.java | ||
---|---|---|
296 | 296 |
* This method prints sql based upon the <returnfield> tag in the |
297 | 297 |
* pathquery document. This allows for customization of the |
298 | 298 |
* returned fields |
299 |
* @param doclist the list of document ids to search by |
|
299 | 300 |
*/ |
300 |
public String printExtendedSQL() |
|
301 |
public String printExtendedSQL(String doclist)
|
|
301 | 302 |
{ |
302 | 303 |
StringBuffer self = new StringBuffer(); |
303 | 304 |
self.append("select xml_nodes.docid, xml_index.path, xml_nodes.nodedata "); |
... | ... | |
322 | 323 |
} |
323 | 324 |
} |
324 | 325 |
self.append(") AND xml_nodes.docid in ("); |
325 |
self.append(query.printSQL()); |
|
326 |
//self.append(query.printSQL()); |
|
327 |
self.append(doclist); |
|
326 | 328 |
self.append(")"); |
327 | 329 |
self.append(" AND xml_nodes.nodetype = 'TEXT'"); |
328 | 330 |
|
329 | 331 |
//System.out.println(self.toString()); |
330 | 332 |
return self.toString(); |
331 | 333 |
} |
334 |
|
|
335 |
public static String printRelationSQL(String docid) |
|
336 |
{ |
|
337 |
StringBuffer self = new StringBuffer(); |
|
338 |
self.append("select subject, relationship, object from xml_relation "); |
|
339 |
self.append("where subject like '").append(docid).append("'"); |
|
340 |
return self.toString(); |
|
341 |
} |
|
332 | 342 |
|
333 | 343 |
/** |
334 |
* |
|
344 |
* Prints sql that returns all relations in the database.
|
|
335 | 345 |
*/ |
336 | 346 |
public static String printPackageSQL() |
337 | 347 |
{ |
... | ... | |
356 | 366 |
} |
357 | 367 |
|
358 | 368 |
/** |
369 |
* Prints sql that returns all relations in the database that were input |
|
370 |
* under a specific docid |
|
371 |
* @param docid the docid to search for. |
|
372 |
*/ |
|
373 |
public static String printPackageSQL(String docid) |
|
374 |
{ |
|
375 |
StringBuffer self = new StringBuffer(); |
|
376 |
self.append("select z.nodedata, x.nodedata, y.nodedata from "); |
|
377 |
self.append("(select nodeid, parentnodeid from xml_index where path like "); |
|
378 |
self.append("'package/relation/subject') s, (select nodeid, parentnodeid "); |
|
379 |
self.append("from xml_index where path like "); |
|
380 |
self.append("'package/relation/relationship') rel, "); |
|
381 |
self.append("(select nodeid, parentnodeid from xml_index where path like "); |
|
382 |
self.append("'package/relation/object') o, "); |
|
383 |
self.append("xml_nodes x, xml_nodes y, xml_nodes z "); |
|
384 |
self.append("where s.parentnodeid = rel.parentnodeid "); |
|
385 |
self.append("and rel.parentnodeid = o.parentnodeid "); |
|
386 |
self.append("and x.parentnodeid in rel.nodeid "); |
|
387 |
self.append("and y.parentnodeid in o.nodeid "); |
|
388 |
self.append("and z.parentnodeid in s.nodeid "); |
|
389 |
self.append("and z.docid like '").append(docid).append("'"); |
|
390 |
|
|
391 |
return self.toString(); |
|
392 |
} |
|
393 |
|
|
394 |
/** |
|
395 |
* Returns all of the relations that has a certain docid in the subject |
|
396 |
* or the object. |
|
397 |
* |
|
398 |
* @param docid the docid to search for |
|
399 |
*/ |
|
400 |
public static String printPackageSQL(String subDocidURL, String objDocidURL) |
|
401 |
{ |
|
402 |
StringBuffer self = new StringBuffer(); |
|
403 |
self.append("select z.nodedata, x.nodedata, y.nodedata from "); |
|
404 |
self.append("(select nodeid, parentnodeid from xml_index where path like "); |
|
405 |
self.append("'package/relation/subject') s, (select nodeid, parentnodeid "); |
|
406 |
self.append("from xml_index where path like "); |
|
407 |
self.append("'package/relation/relationship') rel, "); |
|
408 |
self.append("(select nodeid, parentnodeid from xml_index where path like "); |
|
409 |
self.append("'package/relation/object') o, "); |
|
410 |
self.append("xml_nodes x, xml_nodes y, xml_nodes z "); |
|
411 |
self.append("where s.parentnodeid = rel.parentnodeid "); |
|
412 |
self.append("and rel.parentnodeid = o.parentnodeid "); |
|
413 |
self.append("and x.parentnodeid in rel.nodeid "); |
|
414 |
self.append("and y.parentnodeid in o.nodeid "); |
|
415 |
self.append("and z.parentnodeid in s.nodeid "); |
|
416 |
self.append("and (z.nodedata like '"); |
|
417 |
self.append(subDocidURL); |
|
418 |
self.append("' or y.nodedata like '"); |
|
419 |
self.append(objDocidURL); |
|
420 |
self.append("')"); |
|
421 |
return self.toString(); |
|
422 |
} |
|
423 |
|
|
424 |
public static String printGetDocByDoctypeSQL(String docid) |
|
425 |
{ |
|
426 |
StringBuffer self = new StringBuffer(); |
|
427 |
|
|
428 |
self.append("SELECT docid,docname,doctype,doctitle,"); |
|
429 |
self.append("date_created, date_updated "); |
|
430 |
self.append("FROM xml_documents WHERE docid IN ("); |
|
431 |
self.append(docid).append(")"); |
|
432 |
return self.toString(); |
|
433 |
} |
|
434 |
|
|
435 |
/** |
|
359 | 436 |
* create a String description of the query that this instance represents. |
360 | 437 |
* This should become a way to get the XML serialization of the query. |
361 | 438 |
*/ |
... | ... | |
578 | 655 |
|
579 | 656 |
/** |
580 | 657 |
* '$Log$ |
658 |
* 'Revision 1.15 2000/09/15 19:52:12 berkley |
|
659 |
* 'Added functionality for package specifications. metacatservlet now contains a new action called getrelateddocument that handles retrieving related documents using the metacatURL specification (metacatURL.java). DBQuery contains new code in runQuery that embeds relation tags in the returned hashtable describing the documents related to each docid. querySpecification contains a new method which prints the sql that does the relation query. |
|
660 |
* ' |
|
581 | 661 |
* 'Revision 1.14 2000/08/31 21:20:39 berkley |
582 | 662 |
* 'changed xslf for new returnfield scheme. the returnfields are now returned as <param name="<returnfield>"> tags. |
583 | 663 |
* 'hThe sql for the returnfield query was redone to fix a previous problem with slow queries |
src/edu/ucsb/nceas/metacat/DBQuery.java | ||
---|---|---|
41 | 41 |
|
42 | 42 |
private Connection conn = null; |
43 | 43 |
private String parserName = null; |
44 |
|
|
44 |
private MetaCatUtil util = new MetaCatUtil(); |
|
45 | 45 |
/** |
46 | 46 |
* the main routine used to test the DBQuery utility. |
47 | 47 |
* <p> |
... | ... | |
116 | 116 |
this.parserName = parserName; |
117 | 117 |
} |
118 | 118 |
|
119 |
public Hashtable findDocuments(Reader xmlquery, String user, String group) |
|
120 |
{ |
|
121 |
return findDocuments(xmlquery, user, group, null); |
|
122 |
} |
|
123 |
|
|
119 | 124 |
/** |
120 | 125 |
* routine to search the elements and attributes looking to match query |
121 | 126 |
* |
122 | 127 |
* @param xmlquery the xml serialization of the query (@see pathquery.dtd) |
128 |
* @param user the username of the user |
|
129 |
* @param group the group of the user |
|
130 |
* @param returndoc an array of document types to backtrack against. |
|
123 | 131 |
*/ |
124 |
public Hashtable findDocuments(Reader xmlquery, String user, String group)
|
|
125 |
//throws Exception
|
|
132 |
public Hashtable findDocuments(Reader xmlquery, String user, String group,
|
|
133 |
String[] returndoc)
|
|
126 | 134 |
{ |
127 | 135 |
Hashtable docListResult = new Hashtable(); |
128 | 136 |
PreparedStatement pstmt; |
... | ... | |
136 | 144 |
String fielddata = null; |
137 | 145 |
String relation = null; |
138 | 146 |
StringBuffer document = null; |
139 |
|
|
147 |
Vector returndocVec = new Vector(); |
|
148 |
|
|
149 |
if(returndoc != null) |
|
150 |
{//add the returndoc elements to a vector for easier manipulation |
|
151 |
for(int i=0; i<returndoc.length; i++) |
|
152 |
{ |
|
153 |
returndocVec.add(new String((String)returndoc[i])); |
|
154 |
} |
|
155 |
} |
|
156 |
|
|
140 | 157 |
try { |
141 | 158 |
// Get the XML query and covert it into a SQL statment |
142 | 159 |
QuerySpecification qspec = new QuerySpecification(xmlquery, |
... | ... | |
157 | 174 |
createDate = rs.getString(5); |
158 | 175 |
updateDate = rs.getString(6); |
159 | 176 |
|
177 |
if(returndocVec.size() != 0 && !returndocVec.contains(doctype)) |
|
178 |
{ //there are returndocs to match (backtracking can now be performed). |
|
179 |
//System.out.println("olddoctype: " + doctype); |
|
180 |
StringBuffer btBuf = new StringBuffer(); |
|
181 |
btBuf.append("select object from xml_relation where "); |
|
182 |
btBuf.append("objdoctype in ("); |
|
183 |
//build the doctype list for the backtracking sql statement |
|
184 |
for(int i=0; i<returndocVec.size(); i++) |
|
185 |
{ |
|
186 |
btBuf.append("'").append((String)returndocVec.get(i)).append("'"); |
|
187 |
if(i != (returndocVec.size() - 1)) |
|
188 |
{ |
|
189 |
btBuf.append(", "); |
|
190 |
} |
|
191 |
} |
|
192 |
btBuf.append(") "); |
|
193 |
btBuf.append("and subject like '"); |
|
194 |
btBuf.append("metacat://docid#").append(docid).append("'"); |
|
195 |
pstmt = conn.prepareStatement(btBuf.toString()); |
|
196 |
pstmt.execute(); |
|
197 |
ResultSet btrs = pstmt.getResultSet(); |
|
198 |
boolean hasBtRows = btrs.next(); |
|
199 |
if(hasBtRows) |
|
200 |
{ //there was a backtrackable document found |
|
201 |
DocumentImpl xmldoc = null; |
|
202 |
//System.out.println("document found is: " + btrs.getString(1)); |
|
203 |
metacatURL objURL = new metacatURL(btrs.getString(1)); |
|
204 |
try |
|
205 |
{ |
|
206 |
xmldoc = new DocumentImpl(conn, objURL.getParam(0)[1]); |
|
207 |
} |
|
208 |
catch(Exception e) |
|
209 |
{ |
|
210 |
System.out.println("Error getting document: " + e.getMessage()); |
|
211 |
} |
|
212 |
|
|
213 |
docid = xmldoc.getDocID(); |
|
214 |
docname = xmldoc.getDocname(); |
|
215 |
doctype = xmldoc.getDoctype(); |
|
216 |
doctitle = xmldoc.getDocTitle(); |
|
217 |
createDate = xmldoc.getCreateDate(); |
|
218 |
updateDate = xmldoc.getUpdateDate(); |
|
219 |
//System.out.println("docname: " + docname + " doctype: " + doctype + |
|
220 |
// " doctitle: " + doctitle + " createdate: " + |
|
221 |
// createDate + " updatedate: " + updateDate); |
|
222 |
} |
|
223 |
btrs.close(); |
|
224 |
} |
|
225 |
|
|
160 | 226 |
document = new StringBuffer(); |
161 |
|
|
162 |
document.append("<docid>").append(docid).append("</docid>"); |
|
163 |
if (docname != null) { |
|
164 |
document.append("<docname>" + docname + "</docname>"); |
|
227 |
//System.out.println("packagdoctype: " + util.getOption("packagedoctype")); |
|
228 |
if(!doctype.equals(util.getOption("packagedoctype"))) |
|
229 |
{ |
|
230 |
document.append("<docid>").append(docid).append("</docid>"); |
|
231 |
if (docname != null) { |
|
232 |
document.append("<docname>" + docname + "</docname>"); |
|
233 |
} |
|
234 |
if (doctype != null) { |
|
235 |
document.append("<doctype>" + doctype + "</doctype>"); |
|
236 |
} |
|
237 |
if (doctitle != null) { |
|
238 |
document.append("<doctitle>" + doctitle + "</doctitle>"); |
|
239 |
} |
|
240 |
if(createDate != null) { |
|
241 |
document.append("<createdate>" + createDate + "</createdate>"); |
|
242 |
} |
|
243 |
if(updateDate != null) { |
|
244 |
document.append("<updatedate>" + updateDate + "</updatedate>"); |
|
245 |
} |
|
246 |
// Store the document id and the root node id |
|
247 |
docListResult.put(docid,(String)document.toString()); |
|
165 | 248 |
} |
166 |
if (doctype != null) { |
|
167 |
document.append("<doctype>" + doctype + "</doctype>"); |
|
168 |
} |
|
169 |
if (doctitle != null) { |
|
170 |
document.append("<doctitle>" + doctitle + "</doctitle>"); |
|
171 |
} |
|
172 |
if(createDate != null) { |
|
173 |
document.append("<createdate>" + createDate + "</createdate>"); |
|
174 |
} |
|
175 |
if(updateDate != null) { |
|
176 |
document.append("<updatedate>" + updateDate + "</updatedate>"); |
|
177 |
} |
|
178 | 249 |
|
179 |
// Store the document id and the root node id |
|
180 |
docListResult.put(docid,(String)document.toString()); |
|
181 |
|
|
182 | 250 |
// Advance to the next record in the cursor |
183 | 251 |
tableHasRows = rs.next(); |
184 | 252 |
} |
... | ... | |
187 | 255 |
{ |
188 | 256 |
Vector extendedFields = new Vector(qspec.getReturnFieldList()); |
189 | 257 |
Vector results = new Vector(); |
190 |
pstmt = conn.prepareStatement(qspec.printExtendedSQL()); |
|
258 |
Enumeration keylist = docListResult.keys(); |
|
259 |
StringBuffer doclist = new StringBuffer(); |
|
260 |
while(keylist.hasMoreElements()) |
|
261 |
{ |
|
262 |
doclist.append("'"); |
|
263 |
doclist.append((String)keylist.nextElement()); |
|
264 |
doclist.append("',"); |
|
265 |
} |
|
266 |
doclist.deleteCharAt(doclist.length()-1); //remove the last comma |
|
267 |
pstmt = conn.prepareStatement(qspec.printExtendedSQL( |
|
268 |
doclist.toString())); |
|
191 | 269 |
pstmt.execute(); |
192 | 270 |
rs = pstmt.getResultSet(); |
193 | 271 |
tableHasRows = rs.next(); |
... | ... | |
219 | 297 |
} |
220 | 298 |
} |
221 | 299 |
|
222 |
pstmt = conn.prepareStatement(qspec.printPackageSQL()); |
|
223 |
pstmt.execute(); |
|
224 |
rs = pstmt.getResultSet(); |
|
225 |
tableHasRows = rs.next(); |
|
226 |
String[][] relations = new String[2000][3]; |
|
227 |
int relLength=0; |
|
228 |
while(tableHasRows) |
|
300 |
//this loop adds the relation data to the resultdoc |
|
301 |
//this code might be able to be added to the backtracking code above |
|
302 |
Enumeration docidkeys = docListResult.keys(); |
|
303 |
while(docidkeys.hasMoreElements()) |
|
229 | 304 |
{ |
230 |
relations[relLength][0] = rs.getString(1).trim(); |
|
231 |
relations[relLength][1] = rs.getString(2).trim(); |
|
232 |
relations[relLength][2] = rs.getString(3).trim(); |
|
233 |
relLength++; |
|
234 |
|
|
235 |
//this get's direct relations from the data. i.e. those relations |
|
236 |
//where the docid of the current document is in the subject tag. |
|
237 |
|
|
238 |
docid = rs.getString(1); |
|
239 |
metacatURL murl = new metacatURL(docid); |
|
240 |
if(murl.getURLType().equals("metacat")) |
|
241 |
{//we only want to process metacat urls here. |
|
242 |
String[] tempparam = murl.getParam(0); |
|
243 |
if(tempparam[0].equals("docid")) |
|
244 |
{ |
|
245 |
docid = tempparam[1]; |
|
246 |
document = new StringBuffer(); |
|
247 |
document.append("<relation>"); |
|
248 |
document.append("<relationtype>").append(rs.getString(2)); |
|
249 |
document.append("</relationtype>"); |
|
250 |
document.append("<relationdoc>").append(rs.getString(3)); |
|
251 |
document.append("</relationdoc>"); |
|
252 |
document.append("</relation>"); |
|
253 |
tableHasRows = rs.next(); |
|
254 |
if(docListResult.containsKey(docid)) |
|
305 |
String docidkey = (String)docidkeys.nextElement(); |
|
306 |
pstmt = conn.prepareStatement( |
|
307 |
qspec.printRelationSQL("metacat://docid#" + docidkey)); |
|
308 |
pstmt.execute(); |
|
309 |
rs = pstmt.getResultSet(); |
|
310 |
tableHasRows = rs.next(); |
|
311 |
while(tableHasRows) |
|
312 |
{ |
|
313 |
String sub = rs.getString(1); |
|
314 |
String rel = rs.getString(2); |
|
315 |
String obj = rs.getString(3); |
|
316 |
metacatURL murl = new metacatURL(sub); |
|
317 |
if(murl.getURLType().equals("metacat")) |
|
318 |
{//we only want to process metacat urls here. |
|
319 |
String[] tempparam = murl.getParam(0); |
|
320 |
if(tempparam[0].equals("docid") && tempparam[1].equals(docidkey)) |
|
255 | 321 |
{ |
256 |
String removedelement = (String)docListResult.remove(docid); |
|
257 |
docListResult.put(docid, removedelement + document.toString()); |
|
322 |
document = new StringBuffer(); |
|
323 |
document.append("<relation>"); |
|
324 |
document.append("<relationtype>").append(rel); |
|
325 |
document.append("</relationtype>"); |
|
326 |
document.append("<relationdoc>").append(obj); |
|
327 |
document.append("</relationdoc>"); |
|
328 |
document.append("</relation>"); |
|
329 |
|
|
330 |
String removedelement = (String)docListResult.remove(docidkey); |
|
331 |
docListResult.put(docidkey, removedelement + document.toString()); |
|
332 |
|
|
258 | 333 |
} |
259 |
else |
|
260 |
{ |
|
261 |
docListResult.put(docid, document.toString()); |
|
262 |
} |
|
263 | 334 |
} |
264 |
else |
|
265 |
{ |
|
266 |
//throw new Exception("Error in url. The first parameter must " + |
|
267 |
// "be the docid."); |
|
268 |
System.err.println("DBQuery: error in url"); |
|
269 |
} |
|
335 |
tableHasRows = rs.next(); |
|
270 | 336 |
} |
271 | 337 |
} |
272 |
|
|
273 |
//this loop handles transitive relations. i.e. if two relation tags |
|
274 |
//both have the same object then the subject of each are related. |
|
275 |
for(int i=0; i<relLength; i++) |
|
276 |
{ |
|
277 |
for(int j=0; j<relLength; j++) |
|
278 |
{ |
|
279 |
if(i != j) |
|
280 |
{ |
|
281 |
if(relations[i][2].equals(relations[j][2])) |
|
282 |
{//the objects are the same. |
|
283 |
metacatURL murl = new metacatURL(relations[i][0]); |
|
284 |
//relations[i][0] contains the docid of document that |
|
285 |
//the new document is related to. |
|
286 |
String[] tempparam = murl.getParam(0); |
|
287 |
if(tempparam[0].equals("docid")) |
|
288 |
{ |
|
289 |
docid = tempparam[1]; |
|
290 |
document = new StringBuffer(); |
|
291 |
document.append("<relation>"); |
|
292 |
document.append("<relationtype>").append(relations[j][1]); |
|
293 |
document.append("</relationtype>"); |
|
294 |
document.append("<relationdoc>").append(relations[j][0]); |
|
295 |
//the relation is to the subject of the new document |
|
296 |
//instead of the object. |
|
297 |
// direct relation transitive relation |
|
298 |
// |-----------------| |-----------------| |
|
299 |
// subject -> (object = object) -> subject |
|
300 |
document.append("</relationdoc>"); |
|
301 |
document.append("</relation>"); |
|
302 |
if(docListResult.containsKey(docid)) |
|
303 |
{ |
|
304 |
String removedelement = (String)docListResult.remove(docid); |
|
305 |
docListResult.put(docid, removedelement + |
|
306 |
document.toString()); |
|
307 |
} |
|
308 |
else |
|
309 |
{ |
|
310 |
docListResult.put(docid, document.toString()); |
|
311 |
} |
|
312 |
} |
|
313 |
} |
|
314 |
} |
|
315 |
} |
|
316 |
} |
|
317 |
|
|
318 | 338 |
pstmt.close(); |
319 | 339 |
} catch (SQLException e) { |
320 | 340 |
System.err.println("Error getting id: " + e.getMessage()); |
... | ... | |
695 | 715 |
|
696 | 716 |
/** |
697 | 717 |
* '$Log$ |
718 |
* 'Revision 1.20 2000/09/15 19:52:11 berkley |
|
719 |
* 'Added functionality for package specifications. metacatservlet now contains a new action called getrelateddocument that handles retrieving related documents using the metacatURL specification (metacatURL.java). DBQuery contains new code in runQuery that embeds relation tags in the returned hashtable describing the documents related to each docid. querySpecification contains a new method which prints the sql that does the relation query. |
|
720 |
* ' |
|
698 | 721 |
* 'Revision 1.19 2000/09/12 17:37:07 bojilova |
699 | 722 |
* 'added check from "read" permission on "query" and "squery" actions |
700 | 723 |
* 'for connected user or for "public" connection |
src/edu/ucsb/nceas/metacat/MetaCatServlet.java | ||
---|---|---|
103 | 103 |
// in defaultdocpath dir |
104 | 104 |
private String executescript = null; |
105 | 105 |
|
106 |
|
|
107 | 106 |
/** |
108 | 107 |
* Initialize the servlet by creating appropriate database connections |
109 | 108 |
*/ |
... | ... | |
335 | 334 |
PrintWriter out = response.getWriter(); |
336 | 335 |
out.println("Error: action not registered. Please report this error."); |
337 | 336 |
} |
338 |
|
|
337 |
util.closeConnections(); |
|
339 | 338 |
// Close the stream to the client |
340 | 339 |
//out.close(); |
341 | 340 |
} |
... | ... | |
414 | 413 |
{ |
415 | 414 |
String xmlquery = ((String[])params.get("query"))[0]; |
416 | 415 |
String qformat = ((String[])params.get("qformat"))[0]; |
417 |
Hashtable doclist = runQuery(xmlquery, user, group); |
|
418 |
String resultdoc = createResultDocument(doclist, transformQuery(xmlquery)); |
|
416 |
String resultdoc = null; |
|
417 |
String[] returndoc = null; |
|
418 |
if(params.contains("returndoc")) |
|
419 |
{ |
|
420 |
returndoc = (String[])params.get("returndoc"); |
|
421 |
} |
|
422 |
|
|
423 |
Hashtable doclist = runQuery(xmlquery, user, group, returndoc); |
|
424 |
//String resultdoc = createResultDocument(doclist, transformQuery(xmlquery)); |
|
419 | 425 |
|
426 |
resultdoc = createResultDocument(doclist, transformQuery(xmlquery)); |
|
427 |
|
|
420 | 428 |
//format and transform the results |
421 | 429 |
if(qformat.equals("html")) { |
422 | 430 |
transformResultset(resultdoc, response, out); |
... | ... | |
440 | 448 |
HttpServletResponse response, String user, String group) |
441 | 449 |
{ |
442 | 450 |
//create the query and run it |
451 |
String[] returndoc = null; |
|
452 |
if(params.containsKey("returndoc")) |
|
453 |
{ |
|
454 |
returndoc = (String[])params.get("returndoc"); |
|
455 |
} |
|
443 | 456 |
String xmlquery = DBQuery.createSQuery(params); |
444 |
Hashtable doclist = runQuery(xmlquery, user, group); |
|
445 |
String qformat = ((String[])params.get("qformat"))[0]; |
|
446 |
String resultdoc = createResultDocument(doclist, transformQuery(params)); |
|
457 |
Hashtable doclist = runQuery(xmlquery, user, group, returndoc); |
|
458 |
String qformat = ((String[])params.get("qformat"))[0]; |
|
459 |
String resultdoc = null; |
|
460 |
|
|
461 |
resultdoc = createResultDocument(doclist, transformQuery(params)); |
|
447 | 462 |
|
448 | 463 |
//format and transform the results |
449 | 464 |
if(qformat.equals("html")) { |
... | ... | |
494 | 509 |
* |
495 | 510 |
* @param xmlquery the query to run |
496 | 511 |
*/ |
497 |
private Hashtable runQuery(String xmlquery, String user, String group) |
|
512 |
private Hashtable runQuery(String xmlquery, String user, String group, |
|
513 |
String[] returndoc) |
|
498 | 514 |
{ |
499 | 515 |
Hashtable doclist=null; |
500 | 516 |
Connection conn = null; |
... | ... | |
502 | 518 |
{ |
503 | 519 |
conn = util.getConnection(); |
504 | 520 |
DBQuery queryobj = new DBQuery(conn, saxparser); |
505 |
doclist = queryobj.findDocuments(new StringReader(xmlquery),user,group); |
|
521 |
doclist = queryobj.findDocuments(new StringReader(xmlquery),user,group, |
|
522 |
returndoc); |
|
506 | 523 |
util.returnConnection(conn); |
507 | 524 |
return doclist; |
508 | 525 |
} |
... | ... | |
544 | 561 |
|
545 | 562 |
/** |
546 | 563 |
* Transforms a hashtable of documents to an xml or html result. |
564 |
* If there is a returndoc, then it only displays documents of |
|
565 |
* whatever type returndoc represents. If a result is found in a document |
|
566 |
* that is not of type returndoc then this attempts to find a relation |
|
567 |
* between this document and one that satifies the returndoc doctype. |
|
547 | 568 |
* |
548 | 569 |
* @param doclist- the hashtable to transform |
549 | 570 |
* @param xmlquery- the query that returned the dolist result |
571 |
* @param resultdoc- the document type to backtrack to. |
|
550 | 572 |
*/ |
551 | 573 |
protected String createResultDocument(Hashtable doclist, String xmlquery) |
552 | 574 |
{ |
... | ... | |
558 | 580 |
String document = null; |
559 | 581 |
resultset.append("<?xml version=\"1.0\"?>\n"); |
560 | 582 |
resultset.append("<resultset>\n"); |
561 |
|
|
583 |
|
|
562 | 584 |
resultset.append(" <query>" + xmlquery + "</query>"); |
563 |
|
|
585 |
|
|
564 | 586 |
Enumeration doclistkeys = doclist.keys(); |
565 | 587 |
while (doclistkeys.hasMoreElements()) |
566 | 588 |
{ |
... | ... | |
648 | 670 |
String[] murlParams = murl.getParam(0); |
649 | 671 |
if(murlParams[0].equals("docid")) |
650 | 672 |
{//the docid should be first |
651 |
murl.printParams(); |
|
673 |
//murl.printParams();
|
|
652 | 674 |
docid = murlParams[1]; //get the docid value |
653 | 675 |
conn = util.getConnection(); |
654 | 676 |
xmldoc = new DocumentImpl(conn, docid); |
... | ... | |
796 | 818 |
accNumber = null; |
797 | 819 |
} |
798 | 820 |
newdocid = DocumentImpl.write(conn, xml, doAction, accNumber, |
799 |
user, group); |
|
821 |
user, group); |
|
822 |
DocumentImpl xmldoc = new DocumentImpl(conn, newdocid); |
|
823 |
|
|
824 |
//if this is a package file then write the package info to |
|
825 |
//the xml_relation table. relationHandler checks to see |
|
826 |
//if it is a package file so you don't have to do it here. |
|
827 |
relationHandler rth = new relationHandler(xmldoc); |
|
828 |
|
|
800 | 829 |
} catch (NullPointerException npe) { |
801 | 830 |
newdocid = DocumentImpl.write(conn,xml,doAction,null,user,group); |
802 | 831 |
} |
Also available in: Unified diff
Added backtrack functionality. Backtracking works by passing a returndoc parameter. There can be more than one. If a document that is hit by a query is not of type returndoc then it searches the database for a related file of type returndoc. If one is found it is displayed, if no relation is found, the original is displayed.
Support was also added for an index of relations. the table xml_relation handles the all of the relation indexing.