Project

General

Profile

« Previous | Next » 

Revision 743

Added by Matt Jones over 23 years ago

Modifications that change the package handling behavior of metacat. Package
membership is now determined by an identifier being used as either the subject
or object in a triple. One can not request arbitrary returndocs -- only
those types that have package information embedded can be "returndoctype"
document types. Right now only one "returndoctype" field can be provided.
This needs to be changed to support multiple potential returndoctype fields.

Packages are now defined by triple elements in the eml-dataset-2.0 module,
and so changes reflect this.

Added a new column (packagetype) to xml_relation that defines the document type
of the package for that record.

In addition, I changed the behavior of metacat queries when "back tracing" is
requested. If a "returndoc" element is present in the pathquery, then the
documents are searched, and any hits are traced back to the package with
which the hit document is linked, if it is of type returndoc. Thus, any
hit returns all of the package documents with which the hit document is
associated. If a hit does not have an associated package, no record is
returned for that hit (this is different from previous metacat behavior).
If no returndoc parameter is provided, all docs are searched and all hits
returned.

A new query parameter was added to pathquery that allows us to filter which
document types are searched (independent of the back tracing feature). If
one or more "filterdoctype" element is included, only documents which are
in that list of types will be searched. If you search for doctype A, but
request that doctype B be returned, only documents of type B that have a
package member of type A and match the search criteria will be returned.

To implement this I had to modify many html files, and change substantial
code in DBQuery, QuerySepcification, and MetaCatServlet.

These changes break the URL handling code that was present previously --
now all identifiers are assumed to be from the metacat system, not in
URL format. This probably needs to be revisited.

View differences:

lib/metacat.html
36 36
    
37 37
    <FRAME SRC="contents.html" BORDER=0 NAME="left">
38 38

  
39
    <FRAME SRC="@servlet-path@?action=query&query=NCEAS%25&qformat=html&doctype=-//NCEAS//eml-dataset//EN" BORDER=0 NAME="right">
39
    <FRAME SRC="@servlet-path@?action=query&query=NCEAS%25&qformat=html&returndoctype=-//NCEAS//eml-dataset-2.0//EN" BORDER=0 NAME="right">
40 40

  
41 41
    </FRAMESET>
42 42
  </FRAMESET>
lib/queform.html
46 46
  <input type="radio" name="qformat" value="html" checked>HTML
47 47
  <br />
48 48
  Return: &nbsp;
49
  <select name=doctype>
49
  <select name="returndoctype">
50
  <option value="-//NCEAS//eml-dataset-2.0//EN">eml-dataset-2.0
50 51
  <option value="-//NCEAS//eml-dataset//EN">eml-dataset
51 52
  <option value="any">Any
52 53
  </select>
lib/filtertest.html
1
<!--
2
  *  '$RCSfile$'
3
  *      Authors: Matt Jones
4
  *    Copyright: 2000 Regents of the University of California and the
5
  *               National Center for Ecological Analysis and Synthesis
6
  *  For Details: http://www.nceas.ucsb.edu/
7
  *
8
  *   '$Author$'
9
  *     '$Date$'
10
  * '$Revision$'
11
  * 
12
  * This is an HTML document for displaying examples of the use of 
13
  * Oracle XML tools for query only
14
  *
15
  * This program is free software; you can redistribute it and/or modify
16
  * it under the terms of the GNU General Public License as published by
17
  * the Free Software Foundation; either version 2 of the License, or
18
  * (at your option) any later version.
19
  *
20
  * This program is distributed in the hope that it will be useful,
21
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
22
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23
  * GNU General Public License for more details.
24
  *
25
  * You should have received a copy of the GNU General Public License
26
  * along with this program; if not, write to the Free Software
27
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
28
-->
29
<html>
30
<head>
31
<title>MetaCat</title>
32
<link rel="stylesheet" type="text/css" href="@html-path@/style/rowcol.css">
33
</head>
34
<body class="emlbody">
35
<table width="100%">
36
<tr><td colspan="2">
37
<b>MetaCat Query</b> -- a simple database query against MetaCat
38
</td></tr>
39
<tr><td width="40%" valign="top">
40
<form action="@servlet-path@" target="right" method="POST">
41
  <input type="hidden" name="action" value="query">
42
  <input type="text" name="anyfield" value="%" size="15">
43
  <input type="submit" value="Run query"><br />
44
  Format: 
45
  <input type="radio" name="qformat" value="xml">XML
46
  <input type="radio" name="qformat" value="html" checked>HTML
47
  <br />
48
  Search only (filter): &nbsp;
49
  <select name="filterdoctype">
50
  <option value="-//NCEAS//eml-dataset-2.0//EN">eml-dataset-2.0
51
  <option value="-//NCEAS//eml-dataset//EN">eml-dataset
52
  </select>
53
</form>
54
<a href="login.html" target="_top">Login</a>
55
</td>
56
<td valign="top">
57
<font size="-1">
58
For the test database, some valid values for the search that produce document
59
results include "Value1" and "lakename" and maybe "122W"
60
<p>
61
To view results that are XML formatted in this demo, it is easiest to use 
62
Internet Explorer 5. Although Netscape browsers will allow you to 
63
download XML documents, only IE5 will display XML at this time.
64
</font>
65
</td>
66
</tr>
67
</table>
68
</body>
69
</html>
0 70

  
lib/contents.html
46 46
  <input type="radio" name="qformat" value="html" checked>HTML
47 47
  <br />
48 48
  Return: &nbsp;
49
  <select name=doctype>
49
  <select name=returndoctype>
50
  <option value="-//NCEAS//eml-dataset-2.0//EN">eml-dataset-2.0
50 51
  <option value="-//NCEAS//eml-dataset//EN">eml-dataset
51 52
  <option value="any">Any
52 53
  </select>
lib/marinenoredir.html
38 38

  
39 39
Please click 
40 40
<a href="http://dev.nceas.ucsb.edu@html-path@/servlet/marine?
41
action=query&anyfield=%&doctype=any&qformat=html&returnfield=surname&
41
action=query&anyfield=%&returndoctype=any&qformat=html&returnfield=surname&
42 42
returnfield=givenname&returnfield=organizationname">  
43 43
 here.</a> if you are not automatically redirected.
44 44

  
lib/knbquery.html
13 13
    <input type="hidden" name="operator" value="UNION" >
14 14
    <input type="hidden" name="returnfield" value="/download/date" >
15 15
    <input type="hidden" name="returnfield" value="/download/param" >
16
    <input type="hidden" name="doctype" value="download">
16
    <input type="hidden" name="filterdoctype" value="download">
17 17
    <input type="text" name="anyfield">
18 18
    <input type="submit">
19 19
  </form>
lib/metacat.properties
19 19
saxparser=org.apache.xerces.parsers.SAXParser
20 20
servletpath=@servlet-path@
21 21
htmlpath=@html-path@
22
packagedoctype=-//NCEAS//package//EN
22
packagedoctype=-//NCEAS//eml-dataset-2.0//EN
23 23
accessdoctype=-//NCEAS//eml-access//EN
24 24
server=@server@
25 25
authclass=edu.ucsb.nceas.metacat.AuthLdap
lib/index.html
36 36
    
37 37
    <FRAME SRC="queform.html" BORDER=0 NAME="left">
38 38

  
39
    <FRAME SRC="@servlet-path@?action=query&query=NCEAS%25&qformat=html&doctype=-//NCEAS//eml-dataset//EN" BORDER=0 NAME="right">
39
    <FRAME SRC="@servlet-path@?action=query&query=NCEAS%25&qformat=html&returndoctype=-//NCEAS//eml-dataset-2.0//EN" BORDER=0 NAME="right">
40 40

  
41 41
    </FRAMESET>
42 42
  </FRAMESET>
lib/marine.html
35 35

  
36 36
<script language="JavaScript">
37 37
 window.location="http://@server@@servlet-path@?" +
38
  "action=query&anyfield=%&doctype=any&qformat=html&" +
38
  "action=query&anyfield=%&returndoctype=any&qformat=html&" +
39 39
  "returnfield=resource/dataset/originator/individualName/surName&" +
40 40
  "returnfield=resource/dataset/originator/individualName/givenName&" + 
41 41
  "returnfield=resource/dataset/originator/organizationName&" +
......
52 52
<noscript>
53 53
Please click 
54 54
<a href="http://@server@@servlet-path@?
55
action=query&anyfield=%&doctype=any&qformat=html&
55
action=query&anyfield=%&returndoctype=any&qformat=html&
56 56
returnfield=resource/dataset/originator/individualName/surName&
57 57
returnfield=resource/dataset/originator/individualName/givenName&
58 58
returnfield=resource/dataset/originator/organizationName&
......
65 65

  
66 66
Please click 
67 67
<a href="http://@server@@servlet-path@??
68
action=query&anyfield=%&doctype=any&qformat=html&
68
action=query&anyfield=%&returndoctype=any&qformat=html&
69 69
returnfield=resource/dataset/originator/individualName/surName&
70 70
returnfield=resource/dataset/originator/individualName/givenName&
71 71
returnfield=resource/dataset/originator/organizationName&
src/xmltables_postgres.sql
214 214
	relationid    INT8 default nextval('xml_relation_id_seq')  PRIMARY KEY, -- unique id
215 215
	docid         VARCHAR(250) ,         -- the docid of the package file
216 216
	                                      -- that this relation came from
217
        packagetype   VARCHAR(250),          -- the type of the package
217 218
	subject       VARCHAR(512) NOT NULL, -- the subject of the relation
218 219
	subdoctype    VARCHAR(128),         	-- the doctype of the subject
219 220
	relationship  VARCHAR(128)  NOT NULL,-- the relationship type
src/loaddtd.sql
28 28
INSERT INTO xml_catalog (entry_type, public_id, system_id)
29 29
    VALUES ('DTD', '-//NCEAS//resource//EN',
30 30
            'http://dev.nceas.ucsb.edu/dtd/schemas/resource.dtd');
31
INSERT INTO xml_catalog (entry_type, public_id, system_id)
32
    VALUES ('DTD', '-//NCEAS//eml-dataset-2.0//EN',
33
            'http://dev.nceas.ucsb.edu/metadata/dtd/eml-dataset-2.0.dtd');
src/xmltables.sql
235 235

  
236 236
CREATE TABLE xml_relation (
237 237
	relationid    NUMBER(20) PRIMARY KEY, -- unique id
238
	docid         VARCHAR2(250) ,         -- the docid of the package file
238
	docid         VARCHAR2(250),          -- the docid of the package file
239 239
	                                      -- that this relation came from
240
        packagetype   VARCHAR2(250),          -- the type of the package
240 241
	subject       VARCHAR2(512) NOT NULL, -- the subject of the relation
241
	subdoctype    VARCHAR2(128),         	-- the doctype of the subject
242
	subdoctype    VARCHAR2(128),          -- the doctype of the subject
242 243
	relationship  VARCHAR2(128)  NOT NULL,-- the relationship type
243 244
	object        VARCHAR2(512) NOT NULL, -- the object of the relation
244 245
	objdoctype    VARCHAR2(128),          -- the doctype of the object
src/edu/ucsb/nceas/metacat/QuerySpecification.java
54 54
 
55 55
  // Query data structures
56 56
  private String meta_file_id;
57
// DOCTITLE attr cleared from the db
58
//  private String querytitle;
59
  private Vector doctypeList;
57
  private Vector returnDocList;
58
  private Vector filterDocList;
60 59
  private Vector returnFieldList;
61 60
  private Vector ownerList;
62 61
  private Vector siteList;
......
82 81
    super();
83 82
    
84 83
    // Initialize the class variables
85
    doctypeList = new Vector();
84
    returnDocList = new Vector();
85
    filterDocList = new Vector();
86 86
    elementStack = new Stack();
87 87
    queryStack   = new Stack();
88 88
    returnFieldList = new Vector();
......
272 272
    String currentTag = currentNode.getTagName();
273 273
    if (currentTag.equals("meta_file_id")) {
274 274
      meta_file_id = inputString;
275
// DOCTITLE attr cleared from the db
276
//    } else if (currentTag.equals("querytitle")) {
277
//      querytitle = inputString;
278 275
    } else if (currentTag.equals("value")) {
279 276
      currentValue = inputString;
280 277
    } else if (currentTag.equals("pathexpr")) {
281 278
      currentPathexpr = inputString;
282 279
    } else if (currentTag.equals("returndoctype")) {
283
      doctypeList.add(inputString);
280
      returnDocList.add(inputString);
284 281
    } else if (currentTag.equals("returnfield")) {
285 282
      returnFieldList.add(inputString);
286 283
      containsExtendedSQL = true;
284
    } else if (currentTag.equals("filterdoctype")) {
285
      filterDocList.add(inputString);
287 286
    } else if (currentTag.equals("owner")) {
288 287
      ownerList.add(inputString);
289 288
    } else if (currentTag.equals("site")) {
......
291 290
    }
292 291
  }
293 292

  
294

  
295 293
  /**
296 294
   * create a SQL serialization of the query that this instance represents
297 295
   */
......
308 306
    self.append(") ");
309 307
 
310 308
    // Add SQL to filter for doctypes requested in the query
311
    // This is an implicit OR for the list of doctypes
312
    if (!doctypeList.isEmpty()) {
309
    // This is an implicit OR for the list of doctypes. Only doctypes in this
310
    // list will be searched if the tag is present
311
    if (!filterDocList.isEmpty()) {
313 312
      boolean firstdoctype = true;
314 313
      self.append(" AND ("); 
315
      Enumeration en = doctypeList.elements();
314
      Enumeration en = filterDocList.elements();
316 315
      while (en.hasMoreElements()) {
317 316
        String currentDoctype = (String)en.nextElement();
318 317
        if (firstdoctype) {
......
324 323
      }
325 324
      self.append(") ");
326 325
    }
327
    
326

  
328 327
    // Add SQL to filter for owners requested in the query
329 328
    // This is an implicit OR for the list of owners
330 329
    if (!ownerList.isEmpty()) {
......
411 410
    StringBuffer self = new StringBuffer();
412 411
    self.append("select subject, relationship, object, subdoctype, ");
413 412
    self.append("objdoctype from xml_relation ");
414
    self.append("where subject like '").append(docid).append("'");
413
    self.append("where docid like '").append(docid).append("'");
415 414
    return self.toString();
416 415
  }
417 416
   
......
423 422
    StringBuffer self = new StringBuffer();
424 423
    self.append("select z.nodedata, x.nodedata, y.nodedata from ");
425 424
    self.append("(select nodeid, parentnodeid from xml_index where path like ");
426
    self.append("'package/relation/subject') s, (select nodeid, parentnodeid ");
425
    self.append("'triple/subject') s, (select nodeid, parentnodeid ");
427 426
    self.append("from xml_index where path like ");
428
    self.append("'package/relation/relationship') rel, ");
427
    self.append("'triple/relationship') rel, ");
429 428
    self.append("(select nodeid, parentnodeid from xml_index where path like ");
430
    self.append("'package/relation/object') o, ");
429
    self.append("'triple/object') o, ");
431 430
    self.append("xml_nodes x, xml_nodes y, xml_nodes z ");
432 431
    self.append("where s.parentnodeid = rel.parentnodeid ");
433 432
    self.append("and rel.parentnodeid = o.parentnodeid ");
......
450 449
    StringBuffer self = new StringBuffer();
451 450
    self.append("select z.nodedata, x.nodedata, y.nodedata from ");
452 451
    self.append("(select nodeid, parentnodeid from xml_index where path like ");
453
    self.append("'package/relation/subject') s, (select nodeid, parentnodeid ");
452
    self.append("'triple/subject') s, (select nodeid, parentnodeid ");
454 453
    self.append("from xml_index where path like ");
455
    self.append("'package/relation/relationship') rel, ");
454
    self.append("'triple/relationship') rel, ");
456 455
    self.append("(select nodeid, parentnodeid from xml_index where path like ");
457
    self.append("'package/relation/object') o, ");
456
    self.append("'triple/object') o, ");
458 457
    self.append("xml_nodes x, xml_nodes y, xml_nodes z ");
459 458
    self.append("where s.parentnodeid = rel.parentnodeid ");
460 459
    self.append("and rel.parentnodeid = o.parentnodeid ");
......
477 476
    StringBuffer self = new StringBuffer();
478 477
    self.append("select z.nodedata, x.nodedata, y.nodedata from ");
479 478
    self.append("(select nodeid, parentnodeid from xml_index where path like ");
480
    self.append("'package/relation/subject') s, (select nodeid, parentnodeid ");
479
    self.append("'triple/subject') s, (select nodeid, parentnodeid ");
481 480
    self.append("from xml_index where path like ");
482
    self.append("'package/relation/relationship') rel, ");
481
    self.append("'triple/relationship') rel, ");
483 482
    self.append("(select nodeid, parentnodeid from xml_index where path like ");
484
    self.append("'package/relation/object') o, ");
483
    self.append("'triple/object') o, ");
485 484
    self.append("xml_nodes x, xml_nodes y, xml_nodes z ");
486 485
    self.append("where s.parentnodeid = rel.parentnodeid ");
487 486
    self.append("and rel.parentnodeid = o.parentnodeid ");
src/edu/ucsb/nceas/metacat/DBQuery.java
112 112
          result.append("<resultset>\n"); 
113 113
  // following line removed by Dan Higgins to avoid insertion of query XML inside returned XML doc
114 114
  //        result.append("  <query>" + xmlfile + "</query>\n"); 
115
          if(!showRuntime)
115
          if (!showRuntime)
116 116
          {
117 117
            Enumeration doclist = nodelist.keys();
118 118
            while (doclist.hasMoreElements()) {
......
138 138
          }
139 139
          //System.out.println(result);
140 140
          //write into a file "result.txt"
141
          if(!showRuntime)
141
          if (!showRuntime)
142 142
          {
143 143
            File f = new File("./result.txt");
144 144
            FileWriter fw = new FileWriter(f);
......
199 199
  public Hashtable findDocuments(Reader xmlquery, String user, String group,
200 200
                                 String[] returndoc, boolean useXMLIndex)
201 201
  {
202
    //System.out.println("in finddocuments");
203 202
      Hashtable   docListResult = new Hashtable();
204 203
      PreparedStatement pstmt = null;
205 204
      String docid = null;
206 205
      String docname = null;
207 206
      String doctype = null;
208
// DOCTITLE attr cleared from the db
209
//      String doctitle = null;
210 207
      String createDate = null;
211 208
      String updateDate = null;
212 209
      String fieldname = null;
......
217 214
      StringBuffer document = null; 
218 215
      Vector returndocVec = new Vector();
219 216
      
220
      if(returndoc != null)
221
      {//add the returndoc elements to a vector for easier manipulation
217
      //add the returndoc elements to a vector for easier manipulation
218
      if (returndoc != null)
219
      {
222 220
        for(int i=0; i<returndoc.length; i++)
223 221
        {
224 222
          returndocVec.add(new String((String)returndoc[i]));
......
226 224
      }
227 225
      
228 226
      try {
229
        if(conn == null || conn.isClosed())
230
        {
227
        if (conn == null || conn.isClosed()) {
231 228
          dbconn = util.openDBConnection();
232
        }
233
        else
234
        {
229
        } else {
235 230
          dbconn = conn;
236 231
        }
237 232
        // Get the XML query and covert it into a SQL statment
238 233
        QuerySpecification qspec = new QuerySpecification(xmlquery, 
239 234
                                   parserName, 
240 235
                                   util.getOption("accNumSeparator"));
241
       // System.out.println(qspec.printSQL());
242 236
        pstmt = dbconn.prepareStatement( qspec.printSQL(useXMLIndex) );
243 237

  
244 238
        // Execute the SQL query using the JDBC connection
......
255 249
          }
256 250
          docname = rs.getString(2);
257 251
          doctype = rs.getString(3);
258
// DOCTITLE attr cleared from the db
259
//          doctitle = rs.getString(4);
260 252
          createDate = rs.getString(4);
261 253
          updateDate = rs.getString(5);
262 254
          rev = rs.getInt(6);
263
          
264
          //System.out.println("vec.size = " + returndocVec.size());
265
          if(returndocVec.size() != 0 && !returndocVec.contains(doctype))
266
          { //there are returndocs to match (backtracking can now be performed). 
267
            //System.out.println("olddoctype: " + doctype);
255

  
256
          //if there are returndocs to match, backtracking can be performed
257
          // If no package exists, do not return the document
258
          if (returndocVec.size() != 0 && !returndocVec.contains(doctype))
259
          { 
260
            String sep = util.getOption("accNumSeparator");
268 261
            StringBuffer btBuf = new StringBuffer();
269
            btBuf.append("select object from xml_relation where ");
270
            btBuf.append("objdoctype in (");
262
            btBuf.append("select docid from xml_relation where ");
263

  
271 264
            //build the doctype list for the backtracking sql statement
265
            btBuf.append("packagetype in (");
272 266
            for(int i=0; i<returndocVec.size(); i++)
273 267
            {
274 268
              btBuf.append("'").append((String)returndocVec.get(i)).append("'");
275
              if(i != (returndocVec.size() - 1))
269
              if (i != (returndocVec.size() - 1))
276 270
              {
277 271
                btBuf.append(", ");
278 272
              } 
279 273
            }
280 274
            btBuf.append(") ");
281
            btBuf.append("and subject like '");
282
            //btBuf.append("metacat://").append(util.getOption("server"));
283
            //btBuf.append("?docid=").append(docid).append("'");
284
            btBuf.append("%docid=").append(docid).append("'");
285
            //System.out.println("sql: " + btBuf.toString());
275

  
276
            btBuf.append("and (subject like '");
277
            btBuf.append(docid).append(sep).append(rev).append("'");
278
            btBuf.append("or object like '");
279
            btBuf.append(docid).append(sep).append(rev).append("')");
286 280
            
287
            PreparedStatement npstmt = dbconn.prepareStatement(btBuf.toString());
281
            PreparedStatement npstmt = dbconn.
282
                                       prepareStatement(btBuf.toString());
288 283
            npstmt.execute();
289 284
            ResultSet btrs = npstmt.getResultSet();
290 285
            boolean hasBtRows = btrs.next();
291
            if(hasBtRows)
286
            while (hasBtRows)
292 287
            { //there was a backtrackable document found
293 288
              DocumentImpl xmldoc = null;
294
              //System.out.println("document found is: " + btrs.getString(1));
295
              MetacatURL objURL = new MetacatURL(btrs.getString(1));
289
              String packageDocid = btrs.getString(1);
290
              //MetacatURL objURL = new MetacatURL(packageDocid);
296 291
              try
297 292
              {
298
                xmldoc = new DocumentImpl(dbconn, objURL.getParam(0)[1]);
293
                //xmldoc = new DocumentImpl(dbconn, objURL.getParam(0)[1]);
294
                xmldoc = new DocumentImpl(dbconn, packageDocid);
299 295
              }
300 296
              catch(Exception e)
301 297
              {
......
306 302
              docid   = xmldoc.getDocID();
307 303
              docname = xmldoc.getDocname();
308 304
              doctype = xmldoc.getDoctype();
309
// DOCTITLE attr cleared from the db
310
//              doctitle = xmldoc.getDocTitle();
311 305
              createDate = xmldoc.getCreateDate();
312 306
              updateDate = xmldoc.getUpdateDate();
313
              //System.out.println("docname: " + docname + " doctype: " + doctype + 
314
              //                   " doctitle: " + doctitle + " createdate: " +
315
              //                   createDate + " updatedate: " + updateDate);
307
              rev = xmldoc.getRev();
308

  
309
              document = new StringBuffer();
310

  
311
              String completeDocid = docid + util.getOption("accNumSeparator");
312
              completeDocid += rev;
313
              document.append("<docid>").append(completeDocid);
314
              document.append("</docid>");
315
              if (docname != null) {
316
                document.append("<docname>" + docname + "</docname>");
317
              }
318
              if (doctype != null) {
319
                document.append("<doctype>" + doctype + "</doctype>");
320
              }
321
              if (createDate != null) {
322
                document.append("<createdate>" + createDate + "</createdate>");
323
              }
324
              if (updateDate != null) {
325
                document.append("<updatedate>" + updateDate + "</updatedate>");
326
              }
327
              // Store the document id and the root node id
328
              docListResult.put(docid,(String)document.toString());
329
         
330
              // Get the next package document linked to our hit
331
              hasBtRows = btrs.next();
316 332
            }
317 333
            npstmt.close();
318 334
            btrs.close();
319
          }
335
          } else {
320 336
          
321
          document = new StringBuffer();
322
          //System.out.println("packagdoctype: " + util.getOption("packagedoctype"));
323
          //if(!doctype.equals(util.getOption("packagedoctype")))
324
          {
337
            document = new StringBuffer();
338

  
325 339
            String completeDocid = docid + util.getOption("accNumSeparator");
326 340
            completeDocid += rev;
327 341
            document.append("<docid>").append(completeDocid).append("</docid>");
......
331 345
            if (doctype != null) {
332 346
              document.append("<doctype>" + doctype + "</doctype>");
333 347
            }
334
// DOCTITLE attr cleared from the db
335
//            if (doctitle != null) {
336
//              document.append("<doctitle>" + doctitle + "</doctitle>");
337
//            }
338
            if(createDate != null) {
348
            if (createDate != null) {
339 349
              document.append("<createdate>" + createDate + "</createdate>");
340 350
            }
341
            if(updateDate != null) {
351
            if (updateDate != null) {
342 352
              document.append("<updatedate>" + updateDate + "</updatedate>");
343 353
            }
344 354
            // Store the document id and the root node id
345 355
            docListResult.put(docid,(String)document.toString());
356
  
346 357
          }
347 358

  
348 359
          // Advance to the next record in the cursor
......
351 362
        rs.close();
352 363
        //pstmt.close();
353 364
        
354
        if(qspec.containsExtendedSQL())
365
        if (qspec.containsExtendedSQL())
355 366
        {
356 367
          Vector extendedFields = new Vector(qspec.getReturnFieldList());
357 368
          Vector results = new Vector();
......
390 401
            document.append("</param>");
391 402

  
392 403
            tableHasRows = rs.next();
393
            if(docListResult.containsKey(docid))
404
            if (docListResult.containsKey(docid))
394 405
            {
395 406
              String removedelement = (String)docListResult.remove(docid);
396 407
              docListResult.put(docid, removedelement + document.toString());
......
411 422
          //String connstring = "metacat://"+util.getOption("server")+"?docid=";
412 423
          String connstring = "%docid=";
413 424
          String docidkey = (String)docidkeys.nextElement();
414
          //System.out.println("relationsql: " + qspec.printRelationSQL(
415
          //                                           connstring + docidkey));
425

  
416 426
          pstmt.close();
417
          pstmt = dbconn.prepareStatement(
418
                  qspec.printRelationSQL(connstring + docidkey));
427
          pstmt = dbconn.prepareStatement(qspec.printRelationSQL(docidkey));
419 428
          pstmt.execute();
420 429
          rs = pstmt.getResultSet();
421 430
          tableHasRows = rs.next();
......
427 436
            String subDT = rs.getString(4);
428 437
            String objDT = rs.getString(5);
429 438
            
430
            MetacatURL murl = new MetacatURL(sub);
431
            if(murl.getProtocol().equals("metacat"))
432
            {//we only want to process metacat urls here.
433
              String[] tempparam = murl.getParam(0);
434
              if(tempparam[0].equals("docid") && tempparam[1].equals(docidkey))
435
              {
439
            //MetacatURL murl = new MetacatURL(sub);
440
            //we only want to process metacat urls here.
441
            //if (murl.getProtocol().equals("metacat")) {
442
              //String[] tempparam = murl.getParam(0);
443
              //if (tempparam[0].equals("docid") && tempparam[1].equals(docidkey))
444
              //{
436 445
                document = new StringBuffer();
437
                document.append("<relation>");
438
                document.append("<relationtype>").append(rel);
439
                document.append("</relationtype>");
440
                document.append("<relationdoc>").append(obj);
441
                document.append("</relationdoc>");
442
                document.append("<relationdoctype>").append(objDT);
443
                document.append("</relationdoctype>");
444
                document.append("</relation>");
446
                document.append("<triple>");
447
                document.append("<subject>").append(sub);
448
                document.append("</subject>");
449
                if (!subDT.equals("null")) {
450
                  document.append("<subjectdoctype>").append(subDT);
451
                  document.append("</subjectdoctype>");
452
                }
453
                document.append("<relationship>").append(rel);
454
                document.append("</relationship>");
455
                document.append("<object>").append(obj);
456
                document.append("</object>");
457
                if (!objDT.equals("null")) {
458
                  document.append("<objectdoctype>").append(objDT);
459
                  document.append("</objectdoctype>");
460
                }
461
                document.append("</triple>");
445 462
                
446 463
                String removedelement = (String)docListResult.remove(docidkey);
447
                docListResult.put(docidkey, removedelement + document.toString());
464
                docListResult.put(docidkey, removedelement + 
465
                                  document.toString());
448 466
                
449
              }
450
            }
467
              //}
468
            //}
451 469
            tableHasRows = rs.next();
452 470
          }
453 471
          rs.close();
......
530 548
   * to the pathquery.dtd and is appropriate for submission to the DBQuery
531 549
   * structured query engine
532 550
   *
533
   * @param params The list of parameters that  should be included in the query
551
   * @param params The list of parameters that should be included in the query
534 552
   */
535 553
  public static String createSQuery(Hashtable params)
536 554
  { 
......
538 556
    Enumeration elements;
539 557
    Enumeration keys;
540 558
    String doctype = null;
559
    String filterDoctype = null;
541 560
    String casesensitive = null;
542 561
    String searchmode = null;
543 562
    Object nextkey;
544 563
    Object nextelement;
545 564
    //add the xml headers
546 565
    query.append("<?xml version=\"1.0\"?>\n");
547
    query.append("<pathquery version=\"1.0\"><meta_file_id>");
548
    
549
    if(params.containsKey("meta_file_id"))
566
    query.append("<pathquery version=\"1.0\">\n");
567

  
568
    if (params.containsKey("meta_file_id"))
550 569
    {
570
      query.append("<meta_file_id>");
551 571
      query.append( ((String[])params.get("meta_file_id"))[0]);
552 572
      query.append("</meta_file_id>");
553 573
    }
554
    else
555
    {
556
      query.append("unspecified</meta_file_id>");
557
    }
558 574
    
559
// DOCTITLE attr cleared from the db
560
//    query.append("<querytitle>");
561
//    if(params.containsKey("querytitle"))
562
//    {
563
//      query.append(((String[])params.get("querytitle"))[0]);
564
//      query.append("</querytitle>");
565
//    }
566
//    else
567
//    {
568
//      query.append("unspecified</querytitle>");
569
//    }
570
    
571
    if(params.containsKey("doctype"))
575
    if (params.containsKey("returndoctype"))
572 576
    {
573
      doctype = ((String[])params.get("doctype"))[0]; 
577
      doctype = ((String[])params.get("returndoctype"))[0]; 
574 578
    }
575 579
    else
576 580
    {
577 581
      doctype = "ANY";  
578 582
    }
583

  
584
    if (params.containsKey("filterdoctype"))
585
    {
586
      String[] filterDoctypes = ((String[])params.get("filterdoctype"));
587
      for(int i=0; i<filterDoctypes.length; i++)
588
      {
589
        query.append("<filterdoctype>").append(filterDoctypes[i]);
590
        query.append("</filterdoctype>");
591
      }
592
    }
579 593
    
580
    if(params.containsKey("returnfield"))
594
    if (params.containsKey("returnfield"))
581 595
    {
582 596
      String[] returnfield = ((String[])params.get("returnfield"));
583 597
      for(int i=0; i<returnfield.length; i++)
......
587 601
      }
588 602
    }
589 603
    
590
    if(params.containsKey("owner"))
604
    if (params.containsKey("owner"))
591 605
    {
592 606
      String[] owner = ((String[])params.get("owner"));
593 607
      for(int i=0; i<owner.length; i++)
......
597 611
      }
598 612
    }
599 613
    
600
    if(params.containsKey("site"))
614
    if (params.containsKey("site"))
601 615
    {
602 616
      String[] site = ((String[])params.get("site"));
603 617
      for(int i=0; i<site.length; i++)
......
607 621
      }
608 622
    }
609 623
    
610
    //if you don't limit the query by doctype, then it just creates
611
    //an empty returndoctype tag.
624
    // back trace to doctype
612 625
    if (!doctype.equals("any") && 
613 626
        !doctype.equals("ANY") &&
614 627
        !doctype.equals("") ) 
......
616 629
       query.append("<returndoctype>");
617 630
       query.append(doctype).append("</returndoctype>");
618 631
    }
619
    else
620
    { 
621
      query.append("<returndoctype></returndoctype>");
622
    }
623 632
    
624 633
    //allows the dynamic switching of boolean operators
625
    if(params.containsKey("operator"))
634
    if (params.containsKey("operator"))
626 635
    {
627 636
      query.append("<querygroup operator=\"" + 
628 637
                ((String[])params.get("operator"))[0] + "\">");
......
632 641
      query.append("<querygroup operator=\"UNION\">"); 
633 642
    }
634 643
        
635
    if(params.containsKey("casesensitive"))
644
    if (params.containsKey("casesensitive"))
636 645
    {
637 646
      casesensitive = ((String[])params.get("casesensitive"))[0]; 
638 647
    }
......
641 650
      casesensitive = "false"; 
642 651
    }
643 652
    
644
    if(params.containsKey("searchmode"))
653
    if (params.containsKey("searchmode"))
645 654
    {
646 655
      searchmode = ((String[])params.get("searchmode"))[0]; 
647 656
    }
......
654 663
    //free text search.  It does not have a <pathexpr>
655 664
    //tag.  This allows for a free text search within the structured
656 665
    //query.  This is useful if the INTERSECT operator is used.
657
    if(params.containsKey("anyfield"))
666
    if (params.containsKey("anyfield"))
658 667
    {
659 668
       String[] anyfield = ((String[])params.get("anyfield"));
660 669
       //allow for more than one value for anyfield
661 670
       for(int i=0; i<anyfield.length; i++)
662 671
       {
663
         if(!anyfield[i].equals(""))
672
         if (!anyfield[i].equals(""))
664 673
         {
665 674
           query.append("<queryterm casesensitive=\"" + casesensitive + 
666 675
                        "\" " + "searchmode=\"" + searchmode + "\"><value>" +
......
683 692
      //make sure we aren't querying for any of these
684 693
      //parameters since the are already in the query
685 694
      //in one form or another.
686
      if(!nextkey.toString().equals("doctype") && 
695
      if (!nextkey.toString().equals("returndoctype") && 
696
         !nextkey.toString().equals("filterdoctype")  &&
687 697
         !nextkey.toString().equals("action")  &&
688 698
         !nextkey.toString().equals("qformat") && 
689 699
         !nextkey.toString().equals("anyfield") &&
......
695 705
        //allow for more than value per field name
696 706
        for(int i=0; i<((String[])nextelement).length; i++)
697 707
        {
698
          if(!((String[])nextelement)[i].equals(""))
708
          if (!((String[])nextelement)[i].equals(""))
699 709
          {
700 710
            query.append("<queryterm casesensitive=\"" + casesensitive +"\" " + 
701 711
                         "searchmode=\"" + searchmode + "\">" +
......
728 738
     StringBuffer xmlquery = new StringBuffer();
729 739
     xmlquery.append("<?xml version=\"1.0\"?>\n");
730 740
     xmlquery.append("<pathquery version=\"1.0\">");
731
     xmlquery.append("<meta_file_id>Unspecified</meta_file_id>");
732
// DOCTITLE attr cleared from the db
733
//     xmlquery.append("<querytitle>Unspecified</querytitle>");
734 741

  
735 742
     if (!doctype.equals("any") && !doctype.equals("ANY")) {
736 743
       xmlquery.append("<returndoctype>");
......
741 748
     //chad added - 8/14
742 749
     //the if statement allows a query to gracefully handle a null 
743 750
     //query.  Without this if a nullpointerException is thrown.
744
     if(!value.equals(""))
751
     if (!value.equals(""))
745 752
     {
746 753
       xmlquery.append("<queryterm casesensitive=\"false\" ");
747 754
       xmlquery.append("searchmode=\"contains\">");
src/edu/ucsb/nceas/metacat/MetaCatServlet.java
481 481
    String qformat = ((String[])params.get("qformat"))[0];
482 482
    String resultdoc = null;
483 483
    String[] returndoc = null;
484
    if(params.contains("returndoc"))
484
    if(params.contains("returndoctype"))
485 485
    {
486
      returndoc = (String[])params.get("returndoc");
486
      returndoc = (String[])params.get("returndoctype");
487 487
    }
488 488
    
489 489
    Hashtable doclist = runQuery(xmlquery, user, group, returndoc);
......
515 515
  {
516 516
    //create the query and run it
517 517
    String[] returndoc = null;
518
    if(params.containsKey("returndoc"))
518
    if(params.containsKey("returndoctype"))
519 519
    {
520
      returndoc = (String[])params.get("returndoc");
520
      returndoc = (String[])params.get("returndoctype");
521
      if (((String)returndoc[0]).equals("any") ||
522
          ((String)returndoc[0]).equals("ANY") ||
523
          ((String)returndoc[0]).equals("")) {
524
        returndoc = null;
525
      }
521 526
    }
522 527
    String xmlquery = DBQuery.createSQuery(params);
523 528
    Hashtable doclist = runQuery(xmlquery, user, group, returndoc);
src/edu/ucsb/nceas/metacat/RelationHandler.java
48 48
    }
49 49
    catch(Exception e)
50 50
    {
51
      System.out.println("unable to get db connection in relationhandler." + 
51
      MetaCatUtil.debugMessage("unable to get db connection in " + 
52 52
                         "relationhandler: " + e.getMessage());
53 53
    }
54 54
    this.xmldoc = xmldoc;
......
65 65
   */ 
66 66
  public void run()
67 67
  {
68
    MetaCatUtil.debugMessage("Running relation handler!");
68 69
    Connection dbconn = null;
69 70
    String docid = xmldoc.getDocID();
71
    String packagetype = xmldoc.getDoctype();
70 72
    // deletes all of the relations with a docid of @docid.
71 73
    deleteRelations(docid);
72 74
    //pseudo-code algorithm
......
79 81
    {
80 82
      dbconn = MetacatReplication.getDBConnection("RelationHandler." +
81 83
                                                  "run");
84

  
82 85
      PreparedStatement pstmt = dbconn.prepareStatement(
83 86
                                QuerySpecification.printPackageSQL(docid));
84 87
      pstmt.execute();
......
89 92
      while(hasmorerows)
90 93
      {
91 94
        String subject = rs.getString(1);
95
        String relationship = rs.getString(2);
96
        String object = rs.getString(3);
97

  
92 98
        String subjectDoctype = null;
93 99
        String paramDocid = null;
94 100
        URL subjectMurl = null;
95 101

  
96
        try
97
        {
98
          subjectMurl = new URL(subject);
99
          subjectDoctype = null;
100
          Hashtable murlParams = util.parseQuery(subjectMurl.getQuery());
101
          paramDocid = (String)murlParams.get("docid"); 
102
        }
103
        catch(MalformedURLException murle)
104
        { //assume this is just a docid not a url
105
          paramDocid = subject;
106
        }
107
        
108
        DocumentImpl subDoc = new DocumentImpl(dbconn, paramDocid);
109
        subjectDoctype = subDoc.getDoctype();
110
        String relationship = rs.getString(2);
111
        String object = rs.getString(3);
112
      
113
        //compare r to each relation in xml_relation
114
        
115
        pstmt = dbconn.prepareStatement("select subject, subdoctype, " +
116
                                      "relationship, object, objdoctype " +
117
                                      "from xml_relation");
118
        pstmt.execute();
119
        //get each relation in xml_relation for comparison
120
        ResultSet relations = pstmt.getResultSet();
121
        boolean hasmorerelations = relations.next();
122
        while(hasmorerelations)
123
        {
124
          String currentSub = relations.getString(1);
125
          String currentSubDoctype = relations.getString(2);
126
          String currentRelationship = relations.getString(3);
127
          String currentObj = relations.getString(4);
128
          String currentObjDoctype = relations.getString(5);
129
         
130
          if(object.equals(currentObj))
131
          {//there is a transitive relation so add a new relation to the table
132
            StringBuffer insertTransRelation = new StringBuffer();
133
            insertTransRelation.append("insert into xml_relation (docid, ");
134
            insertTransRelation.append(" subject, ");
135
            insertTransRelation.append("subdoctype, relationship, object, ");
136
            insertTransRelation.append("objdoctype) values ('");
137
            insertTransRelation.append(docid).append("', '");
138
            insertTransRelation.append(currentSub).append("', '");
139
            insertTransRelation.append(currentSubDoctype).append("', ");
140
            insertTransRelation.append("'hasTransitiveRelationTo', '");
141
            insertTransRelation.append(subject).append("', '");
142
            insertTransRelation.append(subjectDoctype).append("')");
143
            //System.out.println("sql1: " + insertTransRelation.toString());
144
            pstmt = dbconn.prepareStatement(insertTransRelation.toString());
145
            pstmt.execute(); 
146
            
147
            insertTransRelation = new StringBuffer();
148
            //put the same relation in with the subject and object switched
149
            insertTransRelation.append("insert into xml_relation (docid, ");
150
            insertTransRelation.append(" subject, ");
151
            insertTransRelation.append("subdoctype, relationship, object, ");
152
            insertTransRelation.append("objdoctype) values ('");
153
            insertTransRelation.append(docid).append("', '");
154
            insertTransRelation.append(subject).append("', '"); 
155
            insertTransRelation.append(subjectDoctype).append("', ");
156
            insertTransRelation.append("'hasTransitiveRelationTo', '");
157
            insertTransRelation.append(currentSub).append("', '");
158
            insertTransRelation.append(currentSubDoctype).append("')");
159
            //System.out.println("sql2: " + insertTransRelation.toString());
160
            pstmt = dbconn.prepareStatement(insertTransRelation.toString());
161
            pstmt.execute();
162
          }
163
          
164
          hasmorerelations = relations.next(); 
165
        }
166
        
167 102
        //get the current relations information
168 103
        String subDocid = null;
169 104
        String objDocid = null;
......
179 114
            subDocid = (String)subMurlParams.get("docid");
180 115
            if(subMurl.getProtocol().equals("metacat"))
181 116
            {
182
              subDoc = new DocumentImpl(dbconn, subDocid);
117
              DocumentImpl subDoc = new DocumentImpl(dbconn, subDocid);
183 118
              subDoctype = subDoc.getDoctype();
184 119
            }
185 120
          }
......
220 155
        //now that the comparisons are done, the new relation can be put
221 156
        //into xml_relation
222 157
        StringBuffer insertStmt = new StringBuffer();
223
        insertStmt.append("insert into xml_relation (docid, subject, ");
224
        insertStmt.append("subdoctype, ");
158
        insertStmt.append("insert into xml_relation (docid, packagetype, ");
159
        insertStmt.append("subject, subdoctype, ");
225 160
        insertStmt.append("relationship, object, objdoctype) values ('");
226 161
        insertStmt.append(docid).append("', '");
162
        insertStmt.append(packagetype).append("', '");
227 163
        insertStmt.append(subject).append("', '");
228 164
        insertStmt.append(subDoctype).append("', '");
229 165
        insertStmt.append(relationship).append("', '");
......
244 180
    } 
245 181
    catch(Exception e) 
246 182
    { 
247
      System.out.println("Error in relationHandler.run: " + e.getMessage());
248
      util.debugMessage("Error in relationHandler.run: " + e.getMessage());
249
      e.printStackTrace(System.out);
183
      MetaCatUtil.debugMessage("Error in relationHandler.run: " + 
184
                               e.getMessage());
250 185
      btThread = null;
251 186
      try 
252 187
      { 
......
270 205
    }
271 206
    catch(Exception ee)
272 207
    {
273
      System.out.println("error in relationHandler.deleteRelations: " +
208
      MetaCatUtil.debugMessage("error in relationHandler.deleteRelations: " +
274 209
                          ee.getMessage());
275 210
    }
276 211
    
......
284 219
    }
285 220
    catch(Exception e)
286 221
    {
287
      System.out.println("error in RelationHandler.deleteRelations(): " + 
222
      MetaCatUtil.debugMessage("error in RelationHandler.deleteRelations(): " + 
288 223
                          e.getMessage());
289
      e.printStackTrace(System.out);
290 224
      try 
291 225
      { 
292 226
        dbconn.rollback();
......
294 228
      } 
295 229
      catch (SQLException sqle) {}
296 230
    }
297
    
298 231
  }
299 232
}
src/xmltables-sqlserver.sql
216 216
	relationid    NUMBER(20) PRIMARY KEY, -- unique id
217 217
	docid         VARCHAR2(250) ,         -- the docid of the package file
218 218
	                                      -- that this relation came from
219
        packagetype   VARCHAR2(250),          -- the type of the package
219 220
	subject       VARCHAR2(512) NOT NULL, -- the subject of the relation
220 221
	subdoctype    VARCHAR2(128),         	-- the doctype of the subject
221 222
	relationship  VARCHAR2(128)  NOT NULL,-- the relationship type
bin/loadxml
20 20
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21 21

  
22 22
PARSER=/usr/local/devtools/xerces-1_1_3/xerces.jar
23
PDIR=/home/computer/jones/projects/pbi/development/xmltodb
23
PDIR=/home/computer/$USER/development/xmltodb
24 24
JDBC=${ORACLE_HOME}/jdbc/lib/classes111.zip
25 25

  
26 26
export CPATH=$PDIR/build/metacat.jar:$PARSER:$JDBC
bin/xml2sql
20 20
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21 21

  
22 22
PARSER=/usr/local/devtools/xerces-1_1_3/xerces.jar
23
PDIR=/home/computer/jones/projects/pbi/development/xmltodb
23
PDIR=/home/computer/$USER/development/xmltodb
24 24
JDBC=${ORACLE_HOME}/jdbc/lib/classes111.zip
25 25

  
26 26
export CPATH=$PDIR/build/metacat.jar:$PARSER:$JDBC
bin/valxml
20 20
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21 21

  
22 22
PARSER=/usr/local/devtools/xerces-1_1_3/xerces.jar
23
PDIR=/home/computer/jones/projects/pbi/development/xmltodb
23
PDIR=/home/computer/$USER/development/xmltodb
24 24
JDBC=${ORACLE_HOME}/jdbc/lib/classes111.zip
25 25

  
26 26
export CPATH=$PDIR/build/metacat.jar:$PARSER:$JDBC
bin/queryxml
20 20
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21 21

  
22 22
PARSER=/usr/local/devtools/xerces-1_1_3/xerces.jar
23
PDIR=/home/computer/jones/projects/pbi/development/xmltodb
23
PDIR=/home/computer/$USER/development/xmltodb
24 24
JDBC=${ORACLE_HOME}/jdbc/lib/classes111.zip
25 25

  
26 26
export CPATH=$PDIR/build/metacat.jar:$PARSER:$JDBC
bin/squeryxml
20 20
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21 21

  
22 22
PARSER=/usr/local/devtools/xerces-1_1_3/xerces.jar
23
PDIR=/home/computer/jones/projects/pbi/development/xmltodb
23
PDIR=/home/computer/$USER/development/xmltodb
24 24
JDBC=${ORACLE_HOME}/jdbc/lib/classes111.zip
25 25

  
26 26
export CPATH=$PDIR/build/metacat.jar:$PARSER:$JDBC
bin/readxml
20 20
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21 21

  
22 22
PARSER=/usr/local/devtools/xerces-1_1_3/xerces.jar
23
PDIR=/home/computer/jones/projects/pbi/development/xmltodb
23
PDIR=/home/computer/$USER/development/xmltodb
24 24
JDBC=${ORACLE_HOME}/jdbc/lib/classes111.zip
25 25

  
26 26
export CPATH=$PDIR/build/metacat.jar:$PARSER:$JDBC

Also available in: Unified diff