Project

General

Profile

« Previous | Next » 

Revision 672

Added by bojilova over 23 years ago

included implementation for public "read" access as specified from the access file

View differences:

src/edu/ucsb/nceas/metacat/AccessControlList.java
78 78
  private int    permission;
79 79
  private String permType;
80 80
  private String permOrder;
81
  private String publicAcc;
81 82
  private String beginTime;
82 83
  private String endTime;
83 84
  private int    ticketCount;
......
209 210
    }
210 211
    if ( currentNode.getTagName().equals("resource") ) {
211 212
      permOrder = currentNode.getAttribute("order");
213
      publicAcc = currentNode.getAttribute("public");
212 214
    }
213 215
    elementStack.push(currentNode); 
214 216
  }
......
349 351
      ticketCount = 0;
350 352

  
351 353
    } else if ( leaving.getTagName().equals("resource") ) {
352
      // reset the resource identifier
354

  
355
      // update public access for the list of resources
356
      try {
357
        updatePublicAccess(publicAcc);
358
      } catch (SQLException sqle) {
359
        throw new SAXException(sqle);
360
      }
361
      
362
      // reset the resource
353 363
      resourceID = new Vector();
354 364
      resourceURL = new Vector();
355 365
      permOrder = null;
366
      publicAcc = null;
356 367
    }
357 368

  
358 369
  }
......
444 455
  private void insertPermissions( String permType ) 
445 456
          throws SQLException 
446 457
  {
447
    PreparedStatement pstmt = null;
458
    PreparedStatement pstmt;
448 459
 
449 460
    try {
450 461
      pstmt = conn.prepareStatement(
......
471 482
          pstmt.execute();
472 483
        }
473 484
      }
485
      pstmt.close();
474 486

  
475 487
    } catch (SQLException e) {
476 488
      throw new 
477 489
      SQLException("AccessControlList.insertPermissions(): " + e.getMessage());
478
    } finally {
490
    }
491
  }
492

  
493
  /** Update into db public read access for the list of resources */
494
  private void updatePublicAccess(String publicAcc) 
495
          throws SQLException 
496
  {
497
    try {
498
      PreparedStatement pstmt;
499
      pstmt = conn.prepareStatement(
500
              "UPDATE xml_documents SET public_access = ?" +
501
              " WHERE docid LIKE ?");
502
      // Bind the values to the query
503
      if ( publicAcc.toUpperCase().equals("YES") ) {
504
        pstmt.setInt(1, 1);
505
      } else {
506
        pstmt.setInt(1, 0);
507
      }
508
      for ( int i = 0; i < resourceID.size(); i++ ) {
509
        pstmt.setString(2, (String)resourceID.elementAt(i));
510
        pstmt.execute();
511
      }
479 512
      pstmt.close();
513

  
514
    } catch (SQLException e) {
515
      throw new 
516
      SQLException("AccessControlList.updatePublicAccess(): " + e.getMessage());
480 517
    }
481 518
  }
482 519

  

Also available in: Unified diff