Fixing transactional anomalies found in PolicyManagerImpl

revert-70aa11f8
prabathabey 9 years ago
parent 05c3d080e0
commit cd31662a96

@ -106,17 +106,17 @@ public class MonitoringManagerImpl implements MonitoringManager {
PolicyManagementDAOFactory.closeConnection(); PolicyManagementDAOFactory.closeConnection();
} }
PolicyManagementDAOFactory.beginTransaction();
//This was added because update query below that did not return the update table primary key. //This was added because update query below that did not return the update table primary key.
if (!complianceFeatures.isEmpty()) { if (!complianceFeatures.isEmpty()) {
PolicyManagementDAOFactory.beginTransaction();
monitoringDAO.setDeviceAsNoneCompliance(device.getId(), policy.getId()); monitoringDAO.setDeviceAsNoneCompliance(device.getId(), policy.getId());
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Compliance status primary key " + complianceData.getId()); log.debug("Compliance status primary key " + complianceData.getId());
} }
// complianceData.setId(cmf.getId()); // complianceData.setId(cmf.getId());
monitoringDAO.addNoneComplianceFeatures(complianceData.getId(), device.getId(), complianceFeatures); monitoringDAO.addNoneComplianceFeatures(complianceData.getId(), device.getId(), complianceFeatures);
PolicyManagementDAOFactory.commitTransaction();
complianceDecisionPoint.validateDevicePolicyCompliance(deviceIdentifier, complianceData); complianceDecisionPoint.validateDevicePolicyCompliance(deviceIdentifier, complianceData);
List<ProfileFeature> profileFeatures = policy.getProfile().getProfileFeaturesList(); List<ProfileFeature> profileFeatures = policy.getProfile().getProfileFeaturesList();
for (ComplianceFeature compFeature : complianceFeatures) { for (ComplianceFeature compFeature : complianceFeatures) {
@ -127,11 +127,12 @@ public class MonitoringManagerImpl implements MonitoringManager {
} }
} }
} else { } else {
PolicyManagementDAOFactory.beginTransaction();
monitoringDAO.setDeviceAsCompliance(device.getId(), policy.getId()); monitoringDAO.setDeviceAsCompliance(device.getId(), policy.getId());
//complianceData.setId(cmf.getId()); //complianceData.setId(cmf.getId());
monitoringDAO.deleteNoneComplianceData(complianceData.getId()); monitoringDAO.deleteNoneComplianceData(complianceData.getId());
PolicyManagementDAOFactory.commitTransaction();
} }
PolicyManagementDAOFactory.commitTransaction();
} else { } else {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("There is no policy applied to this device, hence compliance monitoring was not called."); log.debug("There is no policy applied to this device, hence compliance monitoring was not called.");

@ -765,12 +765,11 @@ public class PolicyManagerImpl implements PolicyManager {
public Policy getAppliedPolicyToDevice(DeviceIdentifier deviceIdentifier) throws PolicyManagementException { public Policy getAppliedPolicyToDevice(DeviceIdentifier deviceIdentifier) throws PolicyManagementException {
Policy policy; Policy policy;
try { try {
PolicyManagementDAOFactory.openConnection();
DeviceManagementProviderService service = new DeviceManagementProviderServiceImpl(); DeviceManagementProviderService service = new DeviceManagementProviderServiceImpl();
Device device = service.getDevice(deviceIdentifier); Device device = service.getDevice(deviceIdentifier);
//int policyId = policyDAO.getAppliedPolicyId(device.getId()); //int policyId = policyDAO.getAppliedPolicyId(device.getId());
PolicyManagementDAOFactory.openConnection();
policy = policyDAO.getAppliedPolicy(device.getId()); policy = policyDAO.getAppliedPolicy(device.getId());
} catch (DeviceManagementException e) { } catch (DeviceManagementException e) {
throw new PolicyManagementException("Error occurred while getting device id.", e); throw new PolicyManagementException("Error occurred while getting device id.", e);
} catch (PolicyManagerDAOException e) { } catch (PolicyManagerDAOException e) {

Loading…
Cancel
Save