Project

General

Profile

« Previous | Next » 

Revision 3140

Added by berkley almost 18 years ago

added getalldocids function to get all docids that match a certain scope.

View differences:

src/edu/ucsb/nceas/metacat/MetaCatServlet.java
104 104
 * <br>
105 105
 * valtext -- XML text to be validated <br>
106 106
 * action=getaccesscontrol -- retrieve acl info for Metacat document <br>
107
 * action=getalldocids -- retrieves a list of all docids registered with the system<br>
108
 * scope --can limit the query by the scope of the id
107 109
 * action=getdoctypes -- retrieve all doctypes (publicID) <br>
108 110
 * action=getdtdschema -- retrieve a DTD or Schema file <br>
109 111
 * action=getdataguide -- retrieve a Data Guide <br>
......
699 701
                PrintWriter out = response.getWriter();
700 702
                handleGetMaxDocidAction(out, params, response);
701 703
                out.close();
704
            } else if (action.equals("getalldocids")) {
705
                PrintWriter out = response.getWriter();
706
                handleGetAllDocidsAction(out, params, response);
707
                out.close();
702 708
            } else if (action.equals("getrevisionanddoctype")) {
703 709
                PrintWriter out = response.getWriter();
704 710
                handleGetRevisionAndDocTypeAction(out, params);
......
2495 2501
        }
2496 2502

  
2497 2503
    }
2504
    
2505
    /**
2506
     * Handle the "getalldocids" action. return a list of all docids registered
2507
     * in the system
2508
     */
2509
    private void handleGetAllDocidsAction(PrintWriter out, Hashtable params,
2510
            HttpServletResponse response)
2511
    {
2512
        String scope = null;
2513
        if(params.get("scope") != null)
2514
        {
2515
          scope = ((String[]) params.get("scope"))[0];
2516
        }
2517
        
2518
        try {
2519
            DBUtil dbutil = new DBUtil();
2520
            Vector docids = dbutil.getAllDocids(scope);
2521
            out.println("<?xml version=\"1.0\"?>");
2522
            out.println("<idList>");
2523
            out.println("  <scope>" + scope + "</scope>");
2524
            for(int i=0; i<docids.size(); i++)
2525
            {
2526
              String docid = (String)docids.elementAt(i);
2527
              out.println("  <docid>" + docid + "</docid>");
2528
            }
2529
            out.println("</idList>");
2498 2530

  
2531
        } catch (Exception e) {
2532
            out.println("<?xml version=\"1.0\"?>");
2533
            out.println("<error>");
2534
            out.println(e.getMessage());
2535
            out.println("</error>");
2536
        }
2537
    }
2538

  
2499 2539
    /**
2500 2540
     * Handle the "getlastdocid" action. Get the latest docid with rev number
2501 2541
     * from db connection in XML format
src/edu/ucsb/nceas/metacat/DBUtil.java
405 405
  }
406 406
  
407 407
  /**
408
   * get the lastest Accession Number from a particular scope
409
   */
410
  public Vector getAllDocids(String scope)
411
        throws SQLException  {
412
    Vector resultVector = new Vector();
413
    String accnum = null;
414
    String sep = MetaCatUtil.getOption("accNumSeparator");
415
    PreparedStatement pstmt = null;
416
    DBConnection dbConn = null;
417
    int serialNumber = -1;
418
    try 
419
    {
420
      dbConn=DBConnectionPool.
421
                getDBConnection("DBUtil.getAllDocids");
422
      serialNumber=dbConn.getCheckOutSerialNumber();
423
      StringBuffer sb = new StringBuffer();
424
      
425
      sb.append("SELECT docid, rev FROM " +
426
                "( " +
427
                "SELECT docid, rev " + 
428
                "FROM xml_documents ");
429
      if(scope != null)
430
      {
431
        sb.append("WHERE docid LIKE ? ");
432
      }
433
      sb.append("UNION " + 
434
                "SELECT docid, rev " + 
435
                "FROM xml_revisions ");
436
      if(scope != null)
437
      {
438
        sb.append("WHERE docid LIKE ?");
439
      }
440
      sb.append(") subquery GROUP BY docid, rev");
441
      pstmt = dbConn.prepareStatement(sb.toString());
442

  
443
      if(scope != null)
444
      {
445
        pstmt.setString(1,scope + sep + "%");
446
        pstmt.setString(2,scope + sep + "%");
447
      }
448
      pstmt.execute();
449
      ResultSet rs = pstmt.getResultSet();
450
      
451
      long max = 0;
452
      String id = null;
453
      String rev = null;
454
      while(rs.next()){
455
    	  id = rs.getString(1);
456
        rev = rs.getString(2);
457
    	  if(id != null){
458
    		  //temp = temp.substring(id.indexOf(scope) + scope.length() + 1);
459
          resultVector.addElement(id + sep + rev);
460
        }
461
      }
462
      
463
      pstmt.close();
464

  
465
    } catch (SQLException e) {
466
      throw new SQLException("DBUtil.getAllDocids(). " + e.getMessage());
467
    }
468
    finally
469
    {
470
      try
471
      {
472
        pstmt.close();
473
      }//try
474
      finally
475
      {
476
        DBConnectionPool.returnDBConnection(dbConn, serialNumber);
477
      }//finally
478
    }//finally
479

  
480
    return resultVector;
481
  }
482
  
483
  /**
408 484
   * To a given docid, found a dataset docid which conatains the the given doicd
409 485
   * This will be done by searching xml_relation table
410 486
   * If couldn't find, null will be return

Also available in: Unified diff