Project

General

Profile

« Previous | Next » 

Revision 6749

remove old access rules for a data object when they are being updated by rules contained in an EML document. Now the OnlineDataAccessTest EML 2.1.0 tests pass.
http://bugzilla.ecoinformatics.org/show_bug.cgi?id=5560

View differences:

src/edu/ucsb/nceas/metacat/Eml210SAXHandler.java
1430 1430
					}
1431 1431
				}
1432 1432
				
1433
				// clear previous versions first
1434
				deleteAccessRule(accessSection, false);
1435
				
1436
				// now write the new ones
1433 1437
				String subSectionId = Integer.toString(distributionSection.getDistributionId());
1434 1438
				writeGivenAccessRuleIntoDB(accessSection, false, subSectionId);
1435 1439
			}
......
1438 1442
		
1439 1443
		
1440 1444
	}
1445
	
1446
	/**
1447
	 *  delete existing access for given access rule
1448
	 *  
1449
	 */
1450
	private void deleteAccessRule(AccessSection accessSection, boolean topLevel) throws SAXException {
1451
		
1452
		if (accessSection == null) {
1453
			throw new SAXException("The access object is null");
1454
		}
1455
		
1456
		PreparedStatement pstmt = null;
1441 1457

  
1458
		String sql = null;
1459
		sql = "DELETE FROM xml_access WHERE guid = ?";
1460
			
1461
		try {
1462

  
1463
			pstmt = connection.prepareStatement(sql);
1464
			// Increase DBConnection usage count
1465
			connection.increaseUsageCount(1);
1466
			// Bind the values to the query
1467
			String guid = null;
1468
			if (topLevel) {
1469
				try {
1470
					guid = IdentifierManager.getInstance().getGUID(docid, Integer.valueOf(revision));
1471
				} catch (NumberFormatException e) {
1472
					throw new SAXException(e.getMessage(), e);
1473
				} catch (McdbDocNotFoundException e) {
1474
					// register the default mapping now
1475
					guid = docid + "." + revision;
1476
					IdentifierManager.getInstance().createMapping(guid, guid);
1477
				}
1478
			} else {
1479
				guid = accessSection.getDataFileName();
1480
				
1481
			}
1482
			pstmt.setString(1, guid);
1483
			logMetacat.debug("guid in accesstable: " + guid);
1484
			
1485
			logMetacat.debug("running sql: " + pstmt.toString());
1486
			pstmt.execute();
1487
			
1488
			pstmt.close();
1489
		}// try
1490
		catch (SQLException e) {
1491
			throw new SAXException("EMLSAXHandler.deleteAccessRule(): "
1492
					+ e.getMessage());
1493
		}// catch
1494
		finally {
1495
			try {
1496
				pstmt.close();
1497
			} catch (SQLException ee) {
1498
				throw new SAXException("EMLSAXHandler.deleteAccessRule(): "
1499
						+ ee.getMessage());
1500
			}
1501
		}// finally
1502

  
1503
	}
1504

  
1442 1505
	/* Write a given access rule into db */
1443 1506
	private void writeGivenAccessRuleIntoDB(AccessSection accessSection,
1444 1507
			boolean topLevel, String subSectionId) throws SAXException {
......
1535 1598

  
1536 1599
	}// writeGivenAccessRuleIntoDB
1537 1600

  
1538
	
1539

  
1540 1601
	/* Delete from db all permission for resources related to the document, if any */
1541 1602
	private void deletePermissionsInAccessTable() throws SAXException {
1542 1603
		PreparedStatement pstmt = null;
1543 1604
		try {
1605
			
1544 1606
			String sql = "DELETE FROM xml_access " +
1545
					"WHERE accessfileid IN (SELECT guid from identifier where docid = ? and rev = ?)";
1607
					// the file defines access for another file
1608
					"WHERE accessfileid IN " +
1609
						"(SELECT guid from identifier where docid = ? and rev = ?) " +
1610
					// the described file has other versions describing it	
1611
					"OR guid IN " +
1612
						"(SELECT xa.guid from xml_access xa, identifier id" +
1613
						" WHERE xa.accessfileid = id.guid " +
1614
						" AND id.docid = ?" +
1615
						" AND id.rev = ?)";
1546 1616
			// delete all acl records for resources related to @aclid if any
1547 1617
			pstmt = connection.prepareStatement(sql);
1548 1618
			pstmt.setString(1, docid);
1549 1619
			pstmt.setInt(2, Integer.valueOf(revision));
1620
			// second part of query
1621
			pstmt.setString(3, docid);
1622
			pstmt.setInt(4, Integer.valueOf(revision));
1550 1623
			// Increase DBConnection usage count
1551 1624
			connection.increaseUsageCount(1);
1552 1625
			logMetacat.debug("running sql: " + sql);

Also available in: Unified diff