Project

General

Profile

« Previous | Next » 

Revision 6708

use shared method for looking up "docInfo" map -- both in Metacat replication and in D1 system metadata generation

View differences:

IdentifierManager.java
463 463
	    return replicas;
464 464
	}
465 465
    
466
    /**
467
     * return information on the document with localId.  These are the fields
468
     * from the xml_documents table.  They can be used to contstruct metadata 
469
     * about the object that is stored.
470
     * @param localId
471
     * @return
472
     * @throws McdbDocNotFoundException
473
     */
474
    public Hashtable<String, Object> getDocumentInfo(String localId)
475
        throws McdbDocNotFoundException
476
    {
477
        try
478
        {
479
            AccessionNumber acc = new AccessionNumber(localId, "NONE");
480
            localId = acc.getDocid();
481
        }
482
        catch(Exception e)
483
        {
484
            //do nothing. just try the localId as it is
485
        }
486
        Hashtable<String, Object> h = new Hashtable<String, Object>();
487
        String sql = "select docname, doctype, user_owner, user_updated, " +
488
            "server_location, rev, date_created, date_updated from " + 
489
            "xml_documents where docid like ?";
490
        DBConnection dbConn = null;
491
        int serialNumber = -1;
492
        try 
493
        {
494
            // Get a database connection from the pool
495
            dbConn = DBConnectionPool.getDBConnection("IdentifierManager.getDocumentInfo");
496
            serialNumber = dbConn.getCheckOutSerialNumber();
497

  
498
            // Execute the insert statement
499
            PreparedStatement stmt = dbConn.prepareStatement(sql);
500
            stmt.setString(1, localId);
501
            ResultSet rs = stmt.executeQuery();
502
            if (rs.next()) 
503
            {
504
                String docname = rs.getString(1);
505
                String doctype = rs.getString(2);
506
                String user_owner = rs.getString(3);
507
                String user_updated = rs.getString(4);
508
                String server_location = rs.getString(5);
509
                int rev = rs.getInt(6);
510
                String date_created = rs.getString(7);
511
                String date_updated = rs.getString(8);
512
                h.put("docid", localId);
513
                h.put("docname", docname);
514
                h.put("doctype", doctype);
515
                h.put("user_owner", user_owner);
516
                h.put("user_updated", user_updated);
517
                h.put("server_location", server_location);
518
                h.put("rev", new Integer(rev).toString());
519
                h.put("date_created", date_created);
520
                h.put("date_updated", date_updated);
521
                
522
                stmt.close();
523
            } 
524
            else
525
            {
526
                stmt.close();
527
                DBConnectionPool.returnDBConnection(dbConn, serialNumber);
528
                throw new McdbDocNotFoundException("2Could not find document " + localId);
529
            }
530
            
531
            String sql2 = "select principal_name, permission, perm_type, perm_order from xml_access " +
532
            "where docid like '" + localId + "'";
533
            logMetacat.debug("executing sql: " + sql2);
534
            PreparedStatement stmt2 = dbConn.prepareStatement(sql2);
535
            rs = stmt2.executeQuery();
536
            Vector accessVector = new Vector();
537
            while(rs.next())
538
            {
539
                Hashtable accessHash = new Hashtable();
540
                String principal_name = rs.getString(1);
541
                String permission = rs.getString(2);
542
                String permissionType = rs.getString(3);
543
                String permissionOrder = rs.getString(4);
544
                accessHash.put("principal_name", principal_name);
545
                accessHash.put("permission", permission);
546
                accessHash.put("permission_type", permissionType);
547
                accessHash.put("permission_order", permissionOrder);
548
                logMetacat.debug("accessHash: " + accessHash.toString());
549
                accessVector.add(accessHash);
550
            }
551
            h.put("access", accessVector);
552
        } 
553
        catch (SQLException e) 
554
        {
555
            e.printStackTrace();
556
            logMetacat.error("Error while getting document info for localid " + localId + " : "  
557
                    + e.getMessage());
558
        } 
559
        finally 
560
        {
561
            // Return database connection to the pool
562
            DBConnectionPool.returnDBConnection(dbConn, serialNumber);
563
        }
564
        return h;
565
    }
566 466
    
567 467
    /**
568 468
     * return the newest rev for a given localId

Also available in: Unified diff