Project

General

Profile

« Previous | Next » 

Revision 6019

rollback the accessDAO changes - leaving well enough alone.

View differences:

src/edu/ucsb/nceas/metacat/Eml200SAXHandler.java
52 52
import org.xml.sax.Attributes;
53 53
import org.xml.sax.SAXException;
54 54

  
55
import edu.ucsb.nceas.metacat.accesscontrol.AccessControlForSingleFile;
56 55
import edu.ucsb.nceas.metacat.accesscontrol.AccessControlInterface;
57 56
import edu.ucsb.nceas.metacat.accesscontrol.AccessRule;
58 57
import edu.ucsb.nceas.metacat.accesscontrol.AccessSection;
59
import edu.ucsb.nceas.metacat.accesscontrol.XMLAccessDAO;
60 58
import edu.ucsb.nceas.metacat.database.DBConnection;
61 59
import edu.ucsb.nceas.metacat.database.DBConnectionPool;
62 60
import edu.ucsb.nceas.metacat.properties.PropertyService;
......
2081 2079
    }//writeTopAccessRuletoDB
2082 2080

  
2083 2081
    /* Write a gaven access rule into db */
2084
    private void writeGivenAccessRuleIntoDB(String permOrder, Vector<AccessRule> accessRules,
2082
    private void writeGivenAccessRuleIntoDB(String permOrder, Vector accessRules,
2085 2083
                     String dataId, String subTreeId) throws SAXException
2086 2084
    {
2087 2085
      if (permOrder == null || permOrder.trim().equals("") || dataId == null ||
......
2092 2090
                                  " write to xml_access table");
2093 2091
        throw new SAXException("The access object is null");
2094 2092
      }
2095
       try {
2096
           AccessControlForSingleFile acfsf = new AccessControlForSingleFile(dataId);
2093
       // get rid of rev from dataId
2094
       //dataId = MetacatUtil.getDocIdFromString(dataId);
2095
       //String permOrder = accessSection.getPermissionOrder();
2096
       String sql = null;
2097
       PreparedStatement pstmt = null;
2098
       sql = "INSERT INTO xml_access (docid, principal_name, permission, "
2099
               + "perm_type, perm_order, accessfileid, subtreeid) VALUES "
2100
               + " (?, ?, ?, ?, ?, ?, ?)";
2101

  
2102
       try
2103
       {
2104

  
2105
           pstmt = connection.prepareStatement(sql);
2106
           // Increase DBConnection usage count
2107
           connection.increaseUsageCount(1);
2108
           // Bind the values to the query
2109
           pstmt.setString(1, dataId);
2110
           logMetacat.info("Docid in accesstable: " + docid);
2111
           pstmt.setString(6, docid);
2112
           logMetacat.info("Accessfileid in accesstable: " + docid);
2113
           pstmt.setString(5, permOrder);
2114
           logMetacat.info("PermOder in accesstable: " + permOrder);
2115
           pstmt.setString(7, subTreeId);
2116
           logMetacat.info("subtree id in accesstable: " + subTreeId);
2117
           // if it is not top level, set s id
2118

  
2119
           //Vector accessRules = accessSection.getAccessRules();
2097 2120
           // go through every rule
2098
           for (int i = 0; i < accessRules.size(); i++) {
2099
               AccessRule rule = accessRules.elementAt(i);
2121
           for (int i = 0; i < accessRules.size(); i++)
2122
           {
2123
               AccessRule rule = (AccessRule) accessRules.elementAt(i);
2100 2124
               String permType = rule.getPermissionType();
2101 2125
               int permission = rule.getPermission();
2102
               logMetacat.info("permission in accesstable: " + permission);
2103
               logMetacat.info("Permtype in accesstable: " + permType);
2126
               pstmt.setInt(3, permission);
2127
               logMetacat.info("permission in accesstable: "
2128
                       + permission);
2129
               pstmt.setString(4, permType);
2130
               logMetacat.info(
2131
                       "Permtype in accesstable: " + permType);
2104 2132
               // go through every principle in rule
2105 2133
               Vector nameVector = rule.getPrincipal();
2106
               for (int j = 0; j < nameVector.size(); j++) {
2134
               for (int j = 0; j < nameVector.size(); j++)
2135
               {
2107 2136
                   String prName = (String) nameVector.elementAt(j);
2108
					logMetacat.debug("Principal in accesstable: " + prName);
2109
					XMLAccessDAO dao = new XMLAccessDAO();
2110
					dao.setAccessFileId(docid);
2111
					dao.setDocId(dataId);
2112
					dao.setPermission(new Long(permission));
2113
					dao.setPermOrder(permOrder);
2114
					dao.setPermType(permType);
2115
					dao.setPrincipalName(prName);
2116
					dao.setSubTreeId(subTreeId);
2117
					// insert if it does not exist
2118
					if (!acfsf.accessControlExists(dao)) {
2119
						acfsf.insertPermissions(dao);
2120
					}
2137
                   pstmt.setString(2, prName);
2138
                   logMetacat.info("Principal in accesstable: "
2139
                           + prName);
2140
                   logMetacat.debug("running sql: " + pstmt.toString());
2141
                   pstmt.execute();
2121 2142
               }//for
2122 2143
           }//for
2123
           
2144
           pstmt.close();
2124 2145
       }//try
2125
       catch (Exception e) {
2146
       catch (SQLException e)
2147
       {
2126 2148
           throw new SAXException("EMLSAXHandler.writeAccessRuletoDB(): "
2127 2149
                   + e.getMessage());
2128 2150
       }//catch
2151
       finally
2152
       {
2153
           try
2154
           {
2155
               pstmt.close();
2156
           }
2157
           catch (SQLException ee)
2158
           {
2159
               throw new SAXException("EMLSAXHandler.writeAccessRuletoDB(): "
2160
                       + ee.getMessage());
2161
           }
2162
       }//finally
2129 2163

  
2130 2164
    }//writeGivenAccessRuleIntoDB
2131 2165

  
src/edu/ucsb/nceas/metacat/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