Fix formatting issues

revert-70ac1926
tcdlpds@gmail.com 4 years ago
parent eecb3704d5
commit 215b8fb630

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

Loading…
Cancel
Save