From 215b8fb63061971189668bab2f7699a98cdb274b Mon Sep 17 00:00:00 2001 From: "tcdlpds@gmail.com" Date: Thu, 27 Aug 2020 03:07:51 +0530 Subject: [PATCH] Fix formatting issues --- .../mgt/core/mgt/impl/PolicyManagerImpl.java | 103 +----------------- 1 file changed, 2 insertions(+), 101 deletions(-) diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/mgt/impl/PolicyManagerImpl.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/mgt/impl/PolicyManagerImpl.java index 1ac0f519d1..e39f061a65 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/mgt/impl/PolicyManagerImpl.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/mgt/impl/PolicyManagerImpl.java @@ -89,7 +89,6 @@ public class PolicyManagerImpl implements PolicyManager { @Override public Policy addPolicy(Policy policy) throws PolicyManagementException { - try { PolicyManagementDAOFactory.beginTransaction(); if (policy.getProfile() != null && policy.getProfile().getProfileId() == 0) { @@ -107,19 +106,15 @@ public class PolicyManagerImpl implements PolicyManager { if (policy.getUsers() != null) { policyDAO.addPolicyToUser(policy.getUsers(), policy); } - if (policy.getRoles() != null) { policyDAO.addPolicyToRole(policy.getRoles(), policy); } - if (policy.getDevices() != null) { policyDAO.addPolicyToDevice(policy.getDevices(), policy); } - if (policy.getDeviceGroups() != null && !policy.getDeviceGroups().isEmpty()) { policyDAO.addDeviceGroupsToPolicy(policy); } - if (policy.getPolicyCriterias() != null) { List criteria = policy.getPolicyCriterias(); for (PolicyCriterion criterion : criteria) { @@ -139,7 +134,6 @@ public class PolicyManagerImpl implements PolicyManager { policyDAO.addPolicyCriteria(policy); policyDAO.addPolicyCriteriaProperties(policy.getPolicyCriterias()); } - if (policy.getCorrectiveActions() != null && !policy.getCorrectiveActions().isEmpty()) { if (log.isDebugEnabled()) { log.debug("Adding corrective actions for policy " + policy.getPolicyName() + @@ -147,17 +141,14 @@ public class PolicyManagerImpl implements PolicyManager { } policyDAO.addCorrectiveActionsOfPolicy(policy.getCorrectiveActions(), policy.getId()); } - if (policy.isActive()) { policyDAO.activatePolicy(policy.getId()); } PolicyManagementDAOFactory.commitTransaction(); - } catch (PolicyManagerDAOException e) { PolicyManagementDAOFactory.rollbackTransaction(); throw new PolicyManagementException("Error occurred while adding the policy (" + policy.getId() + " - " + policy.getPolicyName() + ")", e); - } catch (ProfileManagerDAOException e) { PolicyManagementDAOFactory.rollbackTransaction(); throw new PolicyManagementException("Error occurred while adding the profile related to policy (" + @@ -174,7 +165,6 @@ public class PolicyManagerImpl implements PolicyManager { @Override public Policy updatePolicy(Policy policy) throws PolicyManagementException { - try { // Previous policy needs to be obtained before beginning the transaction Policy previousPolicy = this.getPolicy(policy.getId()); @@ -183,15 +173,12 @@ public class PolicyManagerImpl implements PolicyManager { // This will keep track of the policies updated. policyDAO.recordUpdatedPolicy(policy); - List existingFeaturesList = new ArrayList<>(); List newFeaturesList = new ArrayList<>(); List featuresToDelete = new ArrayList<>(); List temp = new ArrayList<>(); List updateDFes = new ArrayList<>(); - List updatedFeatureList = policy.getProfile().getProfileFeaturesList(); - List existingProfileFeaturesList = previousPolicy.getProfile().getProfileFeaturesList(); // Checks for the existing features @@ -232,27 +219,20 @@ public class PolicyManagerImpl implements PolicyManager { if (!newFeaturesList.isEmpty()) { featureDAO.addProfileFeatures(newFeaturesList, profileId); } - if (!featuresToDelete.isEmpty()) { for (ProfileFeature pf : featuresToDelete) featureDAO.deleteProfileFeatures(pf.getId()); } - policyDAO.deleteCriteriaAndDeviceRelatedConfigs(policy.getId()); - - if (policy.getUsers() != null) { policyDAO.updateUserOfPolicy(policy.getUsers(), previousPolicy); } - if (policy.getRoles() != null) { policyDAO.updateRolesOfPolicy(policy.getRoles(), previousPolicy); } - if (policy.getDevices() != null) { policyDAO.addPolicyToDevice(policy.getDevices(), previousPolicy); } - if (policy.getDeviceGroups() != null && !policy.getDeviceGroups().isEmpty()) { policyDAO.addDeviceGroupsToPolicy(policy); } @@ -308,19 +288,15 @@ public class PolicyManagerImpl implements PolicyManager { log.debug("Updating corrective actions for policy " + policy.getPolicyName() + " having policy id " + policy.getId()); } - if (!correctiveActionsToUpdate.isEmpty()) { policyDAO.updateCorrectiveActionsOfPolicy(correctiveActionsToUpdate, previousPolicy.getId()); } - if (!correctiveActionsToAdd.isEmpty()) { policyDAO.addCorrectiveActionsOfPolicy(correctiveActionsToAdd, previousPolicy.getId()); } - if (!correctiveActionsToDelete.isEmpty()) { policyDAO.deleteCorrectiveActionsOfPolicy(correctiveActionsToDelete, previousPolicy.getId()); } - PolicyManagementDAOFactory.commitTransaction(); } catch (PolicyManagerDAOException e) { PolicyManagementDAOFactory.rollbackTransaction(); @@ -345,7 +321,6 @@ public class PolicyManagerImpl implements PolicyManager { public boolean updatePolicyPriorities(List policies) throws PolicyManagementException { boolean bool; try { -// List existingPolicies = this.getPolicies(); List existingPolicies; if (policyConfiguration.getCacheEnable()) { existingPolicies = PolicyCacheManagerImpl.getInstance().getAllPolicies(); @@ -405,7 +380,6 @@ public class PolicyManagerImpl implements PolicyManager { @Override public boolean deletePolicy(int policyId) throws PolicyManagementException { boolean bool; - List policies = this.getPolicies(); Policy pol = null; for (Policy p : policies) { @@ -433,7 +407,6 @@ public class PolicyManagerImpl implements PolicyManager { } featureDAO.deleteFeaturesOfProfile(policy.getProfileId()); - profileDAO.deleteProfile(policy.getProfileId()); PolicyManagementDAOFactory.commitTransaction(); return bool; @@ -491,7 +464,6 @@ public class PolicyManagerImpl implements PolicyManager { @Override public Policy addPolicyToDevice(List deviceIdentifierList, Policy policy) throws PolicyManagementException { - List deviceList = new ArrayList<>(); DeviceManagementProviderService deviceManagementService = PolicyManagementDataHolder .getInstance().getDeviceManagementService(); @@ -566,7 +538,6 @@ public class PolicyManagerImpl implements PolicyManager { @Override public Policy addPolicyToUser(List usernameList, Policy policy) throws PolicyManagementException { - try { PolicyManagementDAOFactory.beginTransaction(); if (policy.getId() == 0) { @@ -598,22 +569,17 @@ public class PolicyManagerImpl implements PolicyManager { @Override public Policy getPolicyByProfileID(int profileId) throws PolicyManagementException { - Policy policy; Profile profile; List deviceList; List roleNames; - try { PolicyManagementDAOFactory.openConnection(); policy = policyDAO.getPolicyByProfileID(profileId); - roleNames = policyDAO.getPolicyAppliedRoles(policy.getId()); profile = profileDAO.getProfile(profileId); policy.setProfile(profile); policy.setRoles(roleNames); - - } catch (PolicyManagerDAOException e) { throw new PolicyManagementException("Error occurred while getting the policy related to profile ID (" + profileId + ")", e); @@ -634,7 +600,6 @@ public class PolicyManagerImpl implements PolicyManager { @Override public Policy getPolicy(int policyId) throws PolicyManagementException { - Policy policy; List deviceList; List roleNames; @@ -642,13 +607,8 @@ public class PolicyManagerImpl implements PolicyManager { try { PolicyManagementDAOFactory.openConnection(); policy = policyDAO.getPolicy(policyId); - roleNames = policyDAO.getPolicyAppliedRoles(policyId); userNames = policyDAO.getPolicyAppliedUsers(policyId); - - //Profile profile = profileDAO.getProfile(policy.getProfileId()); - - policy.setRoles(roleNames); policy.setUsers(userNames); @@ -657,18 +617,11 @@ public class PolicyManagerImpl implements PolicyManager { " having policy id " + policy.getId()); } policy.setCorrectiveActions(policyDAO.getCorrectiveActionsOfPolicy(policyId)); - } catch (PolicyManagerDAOException e) { throw new PolicyManagementException("Error occurred while getting the policy related to policy ID (" + policyId + ")", e); -// } catch (ProfileManagerDAOException 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); -// } catch (ProfileManagementException e) { -// throw new PolicyManagementException("Error occurred while getting the profile related to policy ID (" + -// policyId + ")", e); } finally { PolicyManagementDAOFactory.closeConnection(); } @@ -678,24 +631,17 @@ public class PolicyManagerImpl implements PolicyManager { 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; } @Override public List getPolicies() throws PolicyManagementException { - List policyList; List profileList; try { @@ -718,20 +664,16 @@ public class PolicyManagerImpl implements PolicyManager { } // Following is done because connection close has been implemented in every method. - for (Policy policy : policyList) { policy.setDevices(this.getPolicyAppliedDevicesIds(policy.getId())); } - return policyList; } @Override public List getPoliciesOfDevice(DeviceIdentifier deviceIdentifier) throws PolicyManagementException { - List policyIdList; List policies = new ArrayList<>(); - DeviceManagementProviderService deviceManagementService = PolicyManagementDataHolder .getInstance().getDeviceManagementService(); Device device; @@ -754,7 +696,6 @@ public class PolicyManagerImpl implements PolicyManager { PolicyManagementDAOFactory.closeConnection(); } -// List tempPolicyList = this.getPolicies(); List tempPolicyList; if (policyConfiguration.getCacheEnable()) { tempPolicyList = PolicyCacheManagerImpl.getInstance().getAllPolicies(); @@ -777,9 +718,6 @@ public class PolicyManagerImpl implements PolicyManager { @Override public List getPoliciesOfDeviceType(String deviceTypeName) throws PolicyManagementException { List policies = new ArrayList<>(); -// try { - // List profileList = profileManager.getProfilesOfDeviceType(deviceTypeName); -// List allPolicies = this.getPolicies(); List allPolicies; if (policyConfiguration.getCacheEnable()) { allPolicies = PolicyCacheManagerImpl.getInstance().getAllPolicies(); @@ -792,28 +730,14 @@ public class PolicyManagerImpl implements PolicyManager { policies.add(policy); } } - -// for (Profile profile : profileList) { -// for (Policy policy : allPolicies) { -// if (policy.getProfileId() == profile.getProfileId()) { -// policy.setProfile(profile); -// policies.add(policy); -// } -// } -// } Collections.sort(policies); -// } catch (ProfileManagementException e) { -// throw new PolicyManagementException("Error occurred while getting all the profile features.", e); -// } return policies; } @Override public List getPoliciesOfRole(String roleName) throws PolicyManagementException { - List policies = new ArrayList<>(); List policyIdList; - try { PolicyManagementDAOFactory.openConnection(); policyIdList = policyDAO.getPolicyOfRole(roleName); @@ -825,7 +749,6 @@ public class PolicyManagerImpl implements PolicyManager { PolicyManagementDAOFactory.closeConnection(); } -// List tempPolicyList = this.getPolicies(); List tempPolicyList; if (policyConfiguration.getCacheEnable()) { tempPolicyList = PolicyCacheManagerImpl.getInstance().getAllPolicies(); @@ -846,10 +769,8 @@ public class PolicyManagerImpl implements PolicyManager { @Override public List getPoliciesOfUser(String username) throws PolicyManagementException { - List policies = new ArrayList<>(); List policyIdList; - try { PolicyManagementDAOFactory.openConnection(); policyIdList = policyDAO.getPolicyOfUser(username); @@ -860,7 +781,6 @@ public class PolicyManagerImpl implements PolicyManager { } finally { PolicyManagementDAOFactory.closeConnection(); } -// List tempPolicyList = this.getPolicies(); List tempPolicyList; if (policyConfiguration.getCacheEnable()) { tempPolicyList = PolicyCacheManagerImpl.getInstance().getAllPolicies(); @@ -881,7 +801,6 @@ public class PolicyManagerImpl implements PolicyManager { @Override public List getPolicyAppliedDevicesIds(int policyId) throws PolicyManagementException { - List deviceList = new ArrayList<>(); List deviceIds; DeviceManagementProviderService deviceManagementService = PolicyManagementDataHolder @@ -955,17 +874,11 @@ public class PolicyManagerImpl implements PolicyManager { @Override public UpdatedPolicyDeviceListBean applyChangesMadeToPolicies() throws PolicyManagementException { - List changedDeviceTypes = new ArrayList<>(); List updatedPolicies = new ArrayList<>(); List updatedPolicyIds = new ArrayList<>(); boolean transactionDone = false; try { - //HashMap map = policyDAO.getUpdatedPolicyIdandDeviceTypeId(); -// List activePolicies = new ArrayList<>(); -// List inactivePolicies = new ArrayList<>(); - -// List allPolicies = this.getPolicies(); List allPolicies; if (policyConfiguration.getCacheEnable()) { allPolicies = PolicyCacheManagerImpl.getInstance().getAllPolicies(); @@ -980,11 +893,6 @@ public class PolicyManagerImpl implements PolicyManager { changedDeviceTypes.add(policy.getProfile().getDeviceType()); } } -// if (policy.isActive()) { -// activePolicies.add(policy); -// } else { -// inactivePolicies.add(policy); -// } } PolicyManagementDAOFactory.beginTransaction(); transactionDone = true; @@ -1068,7 +976,6 @@ public class PolicyManagerImpl implements PolicyManager { @Override public boolean checkPolicyAvailable(DeviceIdentifier deviceIdentifier) throws PolicyManagementException { - boolean exist; DeviceManagementProviderService deviceManagementService = PolicyManagementDataHolder .getInstance().getDeviceManagementService(); @@ -1095,7 +1002,6 @@ public class PolicyManagerImpl implements PolicyManager { @Override public boolean setPolicyApplied(DeviceIdentifier deviceIdentifier) throws PolicyManagementException { - DeviceManagementProviderService deviceManagementService = PolicyManagementDataHolder .getInstance().getDeviceManagementService(); Device device; @@ -1105,7 +1011,6 @@ public class PolicyManagerImpl implements PolicyManager { throw new PolicyManagementException("Error occurred while getting the device details (" + deviceIdentifier.getId() + ")", e); } - try { PolicyManagementDAOFactory.openConnection(); policyDAO.setPolicyApplied(device.getId(), device.getEnrolmentInfo().getId()); @@ -1159,7 +1064,6 @@ public class PolicyManagerImpl implements PolicyManager { public Policy getAppliedPolicyToDevice(Device device) throws PolicyManagementException { Policy policy; try { - //int policyId = policyDAO.getAppliedPolicyId(device.getId()); PolicyManagementDAOFactory.openConnection(); policy = policyDAO.getAppliedPolicy(device.getId(), device.getEnrolmentInfo().getId()); } catch (PolicyManagerDAOException e) { @@ -1211,8 +1115,8 @@ public class PolicyManagerImpl implements PolicyManager { private void addPolicyRevokeOperation(List deviceIdentifiers) throws PolicyManagementException { try { - String type = null; - if (deviceIdentifiers.size() > 0) { + String type; + if (!deviceIdentifiers.isEmpty()) { type = deviceIdentifiers.get(0).getType(); PolicyManagementDataHolder.getInstance().getDeviceManagementService().addOperation(type, this.getPolicyRevokeOperation(), deviceIdentifiers); @@ -1264,11 +1168,9 @@ public class PolicyManagerImpl implements PolicyManager { } finally { PolicyManagementDAOFactory.closeConnection(); } - for (Policy policy : policyList) { policy.setDevices(this.getPolicyAppliedDevicesIds(policy.getId())); } - return policyList; } @@ -1283,7 +1185,6 @@ public class PolicyManagerImpl implements PolicyManager { policy.setRoles(policyDAO.getPolicyAppliedRoles(policy.getId())); policy.setUsers(policyDAO.getPolicyAppliedUsers(policy.getId())); policy.setPolicyCriterias(policyDAO.getPolicyCriteria(policy.getId())); - List deviceGroupWrappers = policyDAO.getDeviceGroupsOfPolicy(policy.getId()); if (!deviceGroupWrappers.isEmpty()) { deviceGroupWrappers = this.getDeviceGroupNames(deviceGroupWrappers);