Project

General

Profile

« Previous | Next » 

Revision 6019

rollback the accessDAO changes - leaving well enough alone.

View differences:

Eml210SAXHandler.java
46 46
import org.xml.sax.Attributes;
47 47
import org.xml.sax.SAXException;
48 48

  
49
import edu.ucsb.nceas.metacat.accesscontrol.AccessControlForSingleFile;
50 49
import edu.ucsb.nceas.metacat.accesscontrol.AccessControlInterface;
51 50
import edu.ucsb.nceas.metacat.accesscontrol.AccessRule;
52 51
import edu.ucsb.nceas.metacat.accesscontrol.AccessSection;
53
import edu.ucsb.nceas.metacat.accesscontrol.XMLAccessDAO;
54 52
import edu.ucsb.nceas.metacat.database.DBConnection;
55 53
import edu.ucsb.nceas.metacat.database.DBConnectionPool;
56 54
import edu.ucsb.nceas.metacat.properties.PropertyService;
......
1427 1425
			throw new SAXException("The access object is null");
1428 1426
		}
1429 1427

  
1430
		String currentDocId = null;
1431
		String accessFileId = null;
1432 1428
		String permOrder = accessSection.getPermissionOrder();
1429
		String sql = null;
1430
		PreparedStatement pstmt = null;
1433 1431
		if (topLevel) {
1434
			currentDocId = docid;
1432
			sql = "INSERT INTO xml_access (docid, principal_name, permission, "
1433
					+ "perm_type, perm_order, accessfileid) VALUES "
1434
					+ " (?, ?, ?, ?, ?, ?)";
1435 1435
		} else {
1436
			currentDocId = accessSection.getDataFileName();
1437
			accessFileId = docid;
1438
			// for subtree should specify the
1439
			if (subSectionId == null) {
1440
				throw new SAXException("The subsection is null");
1441
			}
1436
			sql = "INSERT INTO xml_access (docid,principal_name, "
1437
					+ "permission, perm_type, perm_order, accessfileid, subtreeid"
1438
					+ ") VALUES" + " (?, ?, ?, ?, ?, ?, ?)";
1442 1439
		}
1443 1440
		try {
1444 1441

  
1445
			AccessControlForSingleFile acfsf = new AccessControlForSingleFile(currentDocId);
1442
			pstmt = connection.prepareStatement(sql);
1443
			// Increase DBConnection usage count
1444
			connection.increaseUsageCount(1);
1445
			// Bind the values to the query
1446
			pstmt.setString(6, docid);
1447
			logMetacat.debug("Accessfileid in accesstable: " + docid);
1448
			pstmt.setString(5, permOrder);
1449
			logMetacat.debug("PermOder in accesstable: " + permOrder);
1450
			// if it is not top level, set subsection id
1451
			if (topLevel) {
1452
				pstmt.setString(1, docid);
1453
				logMetacat.debug("Docid in accesstable: " + docid);
1454
			}
1455
			if (!topLevel) {
1456
				pstmt.setString(1, accessSection.getDataFileName());
1457
				logMetacat.debug("Docid in accesstable: " + inlineDataFileName);
1458

  
1459
				// for subtree should specify the
1460
				if (subSectionId == null) {
1461
					throw new SAXException("The subsection is null");
1462
				}
1463

  
1464
				pstmt.setString(7, subSectionId);
1465
				logMetacat.debug("SubSectionId in accesstable: " + subSectionId);
1466
			}
1467

  
1446 1468
			Vector<AccessRule> accessRules = accessSection.getAccessRules();
1447 1469
			// go through every rule
1448 1470
			for (int i = 0; i < accessRules.size(); i++) {
1449 1471
				AccessRule rule = accessRules.elementAt(i);
1450 1472
				String permType = rule.getPermissionType();
1451 1473
				int permission = rule.getPermission();
1474
				pstmt.setInt(3, permission);
1452 1475
				logMetacat.debug("permission in accesstable: " + permission);
1476
				pstmt.setString(4, permType);
1453 1477
				logMetacat.debug("Permtype in accesstable: " + permType);
1454 1478
				// go through every principle in rule
1455 1479
				Vector<String> nameVector = rule.getPrincipal();
1456 1480
				for (int j = 0; j < nameVector.size(); j++) {
1457 1481
					String prName = nameVector.elementAt(j);
1482
					pstmt.setString(2, prName);
1458 1483
					logMetacat.debug("Principal in accesstable: " + prName);
1459
					XMLAccessDAO dao = new XMLAccessDAO();
1460
					dao.setAccessFileId(accessFileId);
1461
					dao.setDocId(currentDocId);
1462
					dao.setPermission(new Long(permission));
1463
					dao.setPermOrder(permOrder);
1464
					dao.setPermType(permType);
1465
					dao.setPrincipalName(prName);
1466
					dao.setSubTreeId(subSectionId);
1467
					// insert if it does not exist
1468
					if (!acfsf.accessControlExists(dao)) {
1469
						acfsf.insertPermissions(dao);
1470
					}
1471
					
1484
					logMetacat.debug("running sql: " + pstmt.toString());
1485
					pstmt.execute();
1472 1486
				}// for
1473 1487
			}// for
1488
			pstmt.close();
1474 1489
		}// try
1475
		catch (Exception e) {
1490
		catch (SQLException e) {
1476 1491
			throw new SAXException("EMLSAXHandler.writeAccessRuletoDB(): "
1477 1492
					+ e.getMessage());
1478 1493
		}// catch
1494
		finally {
1495
			try {
1496
				pstmt.close();
1497
			} catch (SQLException ee) {
1498
				throw new SAXException("EMLSAXHandler.writeAccessRuletoDB(): "
1499
						+ ee.getMessage());
1500
			}
1501
		}// finally
1479 1502

  
1480 1503
	}// writeGivenAccessRuleIntoDB
1481 1504

  
1505
	/* Write a gaven access rule into db */
1506
	private void writeAccessRuleForRelatedDataFileIntoDB(AccessSection accessSection,
1507
			String dataId) throws SAXException {
1508
		if (accessSection == null) {
1509
			throw new SAXException("The access object is null");
1510
		}
1511
		// get rid of rev from dataId
1512
		// dataId = MetacatUtil.getDocIdFromString(dataId);
1513
		String permOrder = accessSection.getPermissionOrder();
1514
		String sql = null;
1515
		PreparedStatement pstmt = null;
1516
		sql = "INSERT INTO xml_access (docid, principal_name, permission, "
1517
				+ "perm_type, perm_order, accessfileid) VALUES " + " (?, ?, ?, ?, ?, ?)";
1518

  
1519
		try {
1520

  
1521
			pstmt = connection.prepareStatement(sql);
1522
			// Increase DBConnection usage count
1523
			connection.increaseUsageCount(1);
1524
			// Bind the values to the query
1525
			pstmt.setString(1, dataId);
1526
			logMetacat.debug("Docid in accesstable: " + docid);
1527
			pstmt.setString(6, docid);
1528
			logMetacat.debug("Accessfileid in accesstable: " + docid);
1529
			pstmt.setString(5, permOrder);
1530
			logMetacat.debug("PermOder in accesstable: " + permOrder);
1531
			// if it is not top level, set subsection id
1532

  
1533
			Vector<AccessRule> accessRules = accessSection.getAccessRules();
1534
			// go through every rule
1535
			for (int i = 0; i < accessRules.size(); i++) {
1536
				AccessRule rule = accessRules.elementAt(i);
1537
				String permType = rule.getPermissionType();
1538
				int permission = rule.getPermission();
1539
				pstmt.setInt(3, permission);
1540
				logMetacat.debug("permission in accesstable: " + permission);
1541
				pstmt.setString(4, permType);
1542
				logMetacat.debug("Permtype in accesstable: " + permType);
1543
				// go through every principle in rule
1544
				Vector<String> nameVector = rule.getPrincipal();
1545
				for (int j = 0; j < nameVector.size(); j++) {
1546
					String prName = nameVector.elementAt(j);
1547
					pstmt.setString(2, prName);
1548
					logMetacat.debug("Principal in accesstable: " + prName);
1549
					logMetacat.debug("running sql: " + pstmt.toString());
1550
					pstmt.execute();
1551
				}// for
1552
			}// for
1553
			pstmt.close();
1554
		}// try
1555
		catch (SQLException e) {
1556
			throw new SAXException("EMLSAXHandler.writeAccessRuletoDB(): "
1557
					+ e.getMessage());
1558
		}// catch
1559
		finally {
1560
			try {
1561
				pstmt.close();
1562
			} catch (SQLException ee) {
1563
				throw new SAXException("EMLSAXHandler.writeAccessRuletoDB(): "
1564
						+ ee.getMessage());
1565
			}
1566
		}// finally
1567

  
1568
	}// writeAccessRuleForRalatedDataFileIntoDB
1569

  
1482 1570
	/* Delete from db all permission for resources related to @aclid if any. */
1483 1571
	private void deletePermissionsInAccessTable(String aclid) throws SAXException {
1484 1572
		Statement stmt = null;

Also available in: Unified diff