Revision 1563
Added by Jing Tao over 21 years ago
src/edu/ucsb/nceas/metacat/EmlSAXHandler.java | ||
---|---|---|
1307 | 1307 |
// and then when update to check if the user can update it or not |
1308 | 1308 |
deleteAccessSubTreeRecord(docid); |
1309 | 1309 |
writeAccessSubTreeIntoDB(accessSectionObj,TOPLEVEL); |
1310 |
|
|
1310 | 1311 |
//write access section into xml_access table |
1311 | 1312 |
writeGivenAccessRuleIntoDB(accessSectionObj, top, subSectionId); |
1313 |
// write relative online data file into xml_access too. |
|
1314 |
for (int i= 0; i<onlineDataFileIdVector.size(); i++) |
|
1315 |
{ |
|
1316 |
String id = (String)onlineDataFileIdVector.elementAt(i); |
|
1317 |
writeAccessRuleForRalatedDataFileIntoDB(accessSectionObj, id); |
|
1318 |
} |
|
1319 |
|
|
1312 | 1320 |
} |
1313 | 1321 |
else |
1314 | 1322 |
{ |
... | ... | |
1350 | 1358 |
comparingNodeStacks(newStack, oldStack); |
1351 | 1359 |
}//else |
1352 | 1360 |
}//if |
1361 |
// write accessobject into db |
|
1362 |
writeGivenAccessRuleIntoDB(accessObj, top, subSectionId); |
|
1363 |
// add access rule for related on line data id too. |
|
1364 |
for (int j= 0; j<onlineDataFileIdVector.size(); j++) |
|
1365 |
{ |
|
1366 |
String id = (String)onlineDataFileIdVector.elementAt(j); |
|
1367 |
writeAccessRuleForRalatedDataFileIntoDB(accessObj, id); |
|
1368 |
} |
|
1353 | 1369 |
|
1354 |
writeGivenAccessRuleIntoDB(accessObj, top, subSectionId); |
|
1370 |
|
|
1355 | 1371 |
//write the reference access into xml_accesssubtree too |
1356 | 1372 |
// write the top level access module into xml_accesssubtree to store info |
1357 | 1373 |
// and then when update to check if the user can update it or not |
... | ... | |
1657 | 1673 |
|
1658 | 1674 |
}//writeGivenAccessRuleIntoDB |
1659 | 1675 |
|
1676 |
|
|
1677 |
|
|
1678 |
/* Write a gaven access rule into db*/ |
|
1679 |
private void writeAccessRuleForRalatedDataFileIntoDB |
|
1680 |
(AccessSection accessSection, String dataId) |
|
1681 |
throws SAXException |
|
1682 |
{ |
|
1683 |
if (accessSection == null) |
|
1684 |
{ |
|
1685 |
throw new SAXException("The access object is null"); |
|
1686 |
} |
|
1687 |
// get rid of rev from dataId |
|
1688 |
dataId = MetaCatUtil.getDocIdFromString(dataId); |
|
1689 |
String permOrder = accessSection.getPermissionOrder(); |
|
1690 |
String sql = null; |
|
1691 |
PreparedStatement pstmt = null; |
|
1692 |
sql = "INSERT INTO xml_access (docid, principal_name, permission, "+ |
|
1693 |
"perm_type, perm_order, accessfileid) VALUES " + |
|
1694 |
" (?, ?, ?, ?, ?, ?)"; |
|
1695 |
|
|
1696 |
try |
|
1697 |
{ |
|
1698 |
|
|
1699 |
pstmt = connection.prepareStatement(sql); |
|
1700 |
// Increase DBConnection usage count |
|
1701 |
connection.increaseUsageCount(1); |
|
1702 |
// Bind the values to the query |
|
1703 |
pstmt.setString(1, dataId); |
|
1704 |
MetaCatUtil.debugMessage("Docid in accesstable: "+ docid, 35); |
|
1705 |
pstmt.setString(6, docid); |
|
1706 |
MetaCatUtil.debugMessage("Accessfileid in accesstable: "+ docid, 35); |
|
1707 |
pstmt.setString(5, permOrder); |
|
1708 |
MetaCatUtil.debugMessage("PermOder in accesstable: "+ permOrder, 35); |
|
1709 |
// if it is not top level, set subsection id |
|
1710 |
|
|
1711 |
Vector accessRules = accessSection.getAccessRules(); |
|
1712 |
// go through every rule |
|
1713 |
for (int i=0; i<accessRules.size(); i++) |
|
1714 |
{ |
|
1715 |
AccessRule rule = (AccessRule)accessRules.elementAt(i); |
|
1716 |
String permType = rule.getPermissionType(); |
|
1717 |
int permission = rule.getPermission(); |
|
1718 |
pstmt.setInt(3, permission); |
|
1719 |
MetaCatUtil.debugMessage("permission in accesstable: "+ permission, 35); |
|
1720 |
pstmt.setString(4, permType); |
|
1721 |
MetaCatUtil.debugMessage("Permtype in accesstable: "+ permType, 35); |
|
1722 |
// go through every principle in rule |
|
1723 |
Vector nameVector = rule.getPrincipal(); |
|
1724 |
for ( int j = 0; j < nameVector.size(); j++ ) |
|
1725 |
{ |
|
1726 |
String prName = (String)nameVector.elementAt(j); |
|
1727 |
pstmt.setString(2, prName); |
|
1728 |
MetaCatUtil.debugMessage("Principal in accesstable: "+prName, 35); |
|
1729 |
pstmt.execute(); |
|
1730 |
}//for |
|
1731 |
}//for |
|
1732 |
pstmt.close(); |
|
1733 |
}//try |
|
1734 |
catch (SQLException e) |
|
1735 |
{ |
|
1736 |
throw new |
|
1737 |
SAXException("EMLSAXHandler.writeAccessRuletoDB(): " + e.getMessage()); |
|
1738 |
}//catch |
|
1739 |
finally |
|
1740 |
{ |
|
1741 |
try |
|
1742 |
{ |
|
1743 |
pstmt.close(); |
|
1744 |
} |
|
1745 |
catch(SQLException ee) |
|
1746 |
{ |
|
1747 |
throw new |
|
1748 |
SAXException("EMLSAXHandler.writeAccessRuletoDB(): " + |
|
1749 |
ee.getMessage()); |
|
1750 |
} |
|
1751 |
}//finally |
|
1752 |
|
|
1753 |
}//writeAccessRuleForRalatedDataFileIntoDB |
|
1754 |
|
|
1755 |
|
|
1756 |
|
|
1757 |
|
|
1758 |
|
|
1660 | 1759 |
/* Delete from db all permission for resources related to @aclid if any.*/ |
1661 | 1760 |
private void deletePermissionsInAccessTable(String aclid) |
1662 | 1761 |
throws SAXException |
Also available in: Unified diff
Add code to handle access rule for online data.