Fixing the policy update issues

revert-70aa11f8
geethkokila 9 years ago
parent 703eebb715
commit c46c4f1be9

@ -135,18 +135,52 @@ public class PolicyManagerImpl implements PolicyManager {
try { try {
// Previous policy needs to be obtained before begining the transaction // Previous policy needs to be obtained before begining the transaction
Policy previousPolicy = getPolicy(policy.getId()); Policy previousPolicy = this.getPolicy(policy.getId());
PolicyManagementDAOFactory.beginTransaction(); PolicyManagementDAOFactory.beginTransaction();
// This will keep track of the policies updated. // This will keep track of the policies updated.
policyDAO.recordUpdatedPolicy(policy); policyDAO.recordUpdatedPolicy(policy);
List<ProfileFeature> existingFeaturesList = new ArrayList<>();
List<ProfileFeature> newFeaturesList = new ArrayList<>();
List<String> temp = new ArrayList<>();
List<ProfileFeature> updatedFeatureList = policy.getProfile().getProfileFeaturesList();
List<ProfileFeature> existingProfileFeaturesList = previousPolicy.getProfile().getProfileFeaturesList();
// Checks for the existing features
for (ProfileFeature feature : updatedFeatureList) {
for (ProfileFeature fe : existingProfileFeaturesList) {
if (feature.getFeatureCode().equalsIgnoreCase(fe.getFeatureCode())) {
existingFeaturesList.add(feature);
temp.add(feature.getFeatureCode());
}
}
}
// Checks for the new features
for (ProfileFeature feature : updatedFeatureList) {
if (!temp.contains(feature.getFeatureCode())) {
newFeaturesList.add(feature);
}
}
int profileId = previousPolicy.getProfile().getProfileId();
policy.getProfile().setProfileId(profileId);
policy.setProfileId(profileId);
Timestamp currentTimestamp = new Timestamp(Calendar.getInstance().getTime().getTime());
policy.getProfile().setUpdatedDate(currentTimestamp);
policyDAO.updatePolicy(policy); policyDAO.updatePolicy(policy);
profileDAO.updateProfile(policy.getProfile()); profileDAO.updateProfile(policy.getProfile());
featureDAO.updateProfileFeatures(policy.getProfile().getProfileFeaturesList(), policy.getProfile()
.getProfileId());
policyDAO.deleteAllPolicyRelatedConfigs(policy.getId());
featureDAO.updateProfileFeatures(existingFeaturesList, profileId);
if (!newFeaturesList.isEmpty()) {
featureDAO.addProfileFeatures(newFeaturesList, profileId);
}
policyDAO.deleteAllPolicyRelatedConfigs(policy.getId());
if (policy.getUsers() != null) { if (policy.getUsers() != null) {
@ -478,20 +512,24 @@ public class PolicyManagerImpl implements PolicyManager {
roleNames = policyDAO.getPolicyAppliedRoles(policyId); roleNames = policyDAO.getPolicyAppliedRoles(policyId);
userNames = policyDAO.getPolicyAppliedUsers(policyId); userNames = policyDAO.getPolicyAppliedUsers(policyId);
Profile profile = profileDAO.getProfile(policy.getProfileId());
policy.setProfile(profile); //Profile profile = profileDAO.getProfile(policy.getProfileId());
policy.setRoles(roleNames); policy.setRoles(roleNames);
policy.setUsers(userNames); policy.setUsers(userNames);
} catch (PolicyManagerDAOException e) { } catch (PolicyManagerDAOException e) {
throw new PolicyManagementException("Error occurred while getting the policy related to policy ID (" + throw new PolicyManagementException("Error occurred while getting the policy related to policy ID (" +
policyId + ")", e); policyId + ")", e);
} catch (ProfileManagerDAOException e) { // } catch (ProfileManagerDAOException e) {
throw new PolicyManagementException("Error occurred while getting the profile related to policy ID (" + // throw new PolicyManagementException("Error occurred while getting the profile related to policy ID (" +
policyId + ")", e); // policyId + ")", e);
} catch (SQLException e) { } catch (SQLException e) {
throw new PolicyManagementException("Error occurred while opening a connection to the data source", e); throw new PolicyManagementException("Error occurred while opening a connection to the data source", e);
// } catch (ProfileManagementException e) {
// throw new PolicyManagementException("Error occurred while getting the profile related to policy ID (" +
// policyId + ")", e);
} finally { } finally {
PolicyManagementDAOFactory.closeConnection(); PolicyManagementDAOFactory.closeConnection();
} }
@ -499,6 +537,20 @@ public class PolicyManagerImpl implements PolicyManager {
// This is done because connection close in below method too. // This is done because connection close in below method too.
deviceList = this.getPolicyAppliedDevicesIds(policyId); deviceList = this.getPolicyAppliedDevicesIds(policyId);
policy.setDevices(deviceList); policy.setDevices(deviceList);
try {
// PolicyManagementDAOFactory.openConnection();
Profile profile = profileManager.getProfile(policy.getProfileId());
policy.setProfile(profile);
} catch (ProfileManagementException e) {
throw new PolicyManagementException("Error occurred while getting the profile related to policy ID (" +
policyId + ")", e);
// } catch (SQLException e) {
// throw new PolicyManagementException("Error occurred while opening a connection to the data source", e);
// } finally {
// PolicyManagementDAOFactory.closeConnection();
}
return policy; return policy;
} }

@ -314,6 +314,11 @@ public class PolicyDAOTestCase extends BasePolicyManagementDAOTest {
users.add("Udara"); users.add("Udara");
users.add("Dileesha"); users.add("Dileesha");
policy.setUsers(users); policy.setUsers(users);
Profile profile2 = ProfileCreator.getProfile3(FeatureCreator.getFeatureList4());
Profile pf = new Profile();
pap.updatePolicy(policy); pap.updatePolicy(policy);
pap.activatePolicy(policy.getId()); pap.activatePolicy(policy.getId());
} }

Loading…
Cancel
Save