|
|
|
@ -35,6 +35,7 @@
|
|
|
|
|
|
|
|
|
|
package org.wso2.carbon.policy.mgt.core.mgt.impl;
|
|
|
|
|
|
|
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
|
|
import org.apache.commons.logging.Log;
|
|
|
|
|
import org.apache.commons.logging.LogFactory;
|
|
|
|
|
import org.wso2.carbon.device.mgt.common.Device;
|
|
|
|
@ -57,18 +58,32 @@ import org.wso2.carbon.device.mgt.core.operation.mgt.CommandOperation;
|
|
|
|
|
import org.wso2.carbon.device.mgt.core.operation.mgt.OperationMgtConstants;
|
|
|
|
|
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
|
|
|
|
|
import org.wso2.carbon.device.mgt.core.service.GroupManagementProviderService;
|
|
|
|
|
import org.wso2.carbon.policy.mgt.common.*;
|
|
|
|
|
import org.wso2.carbon.policy.mgt.common.Criterion;
|
|
|
|
|
import org.wso2.carbon.policy.mgt.common.PolicyManagementException;
|
|
|
|
|
import org.wso2.carbon.policy.mgt.common.ProfileManagementException;
|
|
|
|
|
import org.wso2.carbon.policy.mgt.core.cache.impl.PolicyCacheManagerImpl;
|
|
|
|
|
import org.wso2.carbon.policy.mgt.core.dao.*;
|
|
|
|
|
import org.wso2.carbon.policy.mgt.core.dao.FeatureDAO;
|
|
|
|
|
import org.wso2.carbon.policy.mgt.core.dao.FeatureManagerDAOException;
|
|
|
|
|
import org.wso2.carbon.policy.mgt.core.dao.PolicyDAO;
|
|
|
|
|
import org.wso2.carbon.policy.mgt.core.dao.PolicyManagementDAOFactory;
|
|
|
|
|
import org.wso2.carbon.policy.mgt.core.dao.PolicyManagerDAOException;
|
|
|
|
|
import org.wso2.carbon.policy.mgt.core.dao.ProfileDAO;
|
|
|
|
|
import org.wso2.carbon.policy.mgt.core.dao.ProfileManagerDAOException;
|
|
|
|
|
import org.wso2.carbon.policy.mgt.core.internal.PolicyManagementDataHolder;
|
|
|
|
|
import org.wso2.carbon.policy.mgt.core.mgt.PolicyManager;
|
|
|
|
|
import org.wso2.carbon.policy.mgt.core.mgt.ProfileManager;
|
|
|
|
|
import org.wso2.carbon.policy.mgt.core.mgt.bean.UpdatedPolicyDeviceListBean;
|
|
|
|
|
import org.wso2.carbon.policy.mgt.core.util.PolicyManagementConstants;
|
|
|
|
|
import org.wso2.carbon.policy.mgt.core.util.PolicyManagerUtil;
|
|
|
|
|
|
|
|
|
|
import java.sql.SQLException;
|
|
|
|
|
import java.sql.Timestamp;
|
|
|
|
|
import java.util.*;
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.Calendar;
|
|
|
|
|
import java.util.Collections;
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
|
|
public class PolicyManagerImpl implements PolicyManager {
|
|
|
|
|
|
|
|
|
@ -101,7 +116,23 @@ public class PolicyManagerImpl implements PolicyManager {
|
|
|
|
|
profileDAO.addProfile(profile);
|
|
|
|
|
featureDAO.addProfileFeatures(profile.getProfileFeaturesList(), profile.getProfileId());
|
|
|
|
|
}
|
|
|
|
|
policy.setPolicyPayloadVersion("2.0");
|
|
|
|
|
policy = policyDAO.addPolicy(policy);
|
|
|
|
|
if (policy.getProfile() != null) {
|
|
|
|
|
Profile profile = policy.getProfile();
|
|
|
|
|
List<ProfileFeature> profileFeaturesList = profile.getProfileFeaturesList();
|
|
|
|
|
for (ProfileFeature profileFeature : profileFeaturesList) {
|
|
|
|
|
if (profileFeature.getCorrectiveActions() != null &&
|
|
|
|
|
!profileFeature.getCorrectiveActions().isEmpty()) {
|
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
|
log.debug("Adding corrective actions for policy " + policy.getPolicyName() +
|
|
|
|
|
" having policy id " + policy.getId());
|
|
|
|
|
}
|
|
|
|
|
policyDAO.addCorrectiveActionsOfPolicy(profileFeature.getCorrectiveActions(),
|
|
|
|
|
policy.getId(), profileFeature.getId());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (policy.getUsers() != null) {
|
|
|
|
|
policyDAO.addPolicyToUser(policy.getUsers(), policy);
|
|
|
|
@ -134,13 +165,7 @@ 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() +
|
|
|
|
|
" having policy id " + policy.getId());
|
|
|
|
|
}
|
|
|
|
|
policyDAO.addCorrectiveActionsOfPolicy(policy.getCorrectiveActions(), policy.getId());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (policy.isActive()) {
|
|
|
|
|
policyDAO.activatePolicy(policy.getId());
|
|
|
|
|
}
|
|
|
|
@ -178,6 +203,9 @@ public class PolicyManagerImpl implements PolicyManager {
|
|
|
|
|
List<ProfileFeature> featuresToDelete = new ArrayList<>();
|
|
|
|
|
List<String> temp = new ArrayList<>();
|
|
|
|
|
List<String> updateDFes = new ArrayList<>();
|
|
|
|
|
Map<Integer, List<CorrectiveAction>> updatedCorrectiveActionsMap = new HashMap<>();
|
|
|
|
|
Map<Integer, List<CorrectiveAction>> existingCorrectiveActionsMap = new HashMap<>();
|
|
|
|
|
|
|
|
|
|
List<ProfileFeature> updatedFeatureList = policy.getProfile().getProfileFeaturesList();
|
|
|
|
|
List<ProfileFeature> existingProfileFeaturesList = previousPolicy.getProfile().getProfileFeaturesList();
|
|
|
|
|
|
|
|
|
@ -212,7 +240,8 @@ public class PolicyManagerImpl implements PolicyManager {
|
|
|
|
|
Timestamp currentTimestamp = new Timestamp(Calendar.getInstance().getTime().getTime());
|
|
|
|
|
policy.getProfile().setUpdatedDate(currentTimestamp);
|
|
|
|
|
policy.setPriorityId(previousPolicy.getPriorityId());
|
|
|
|
|
policyDAO.updatePolicy(policy);
|
|
|
|
|
policy.setPolicyPayloadVersion(previousPolicy.getPolicyPayloadVersion());
|
|
|
|
|
Policy updatedPolicy = policyDAO.updatePolicy(policy);
|
|
|
|
|
profileDAO.updateProfile(policy.getProfile());
|
|
|
|
|
|
|
|
|
|
featureDAO.updateProfileFeatures(existingFeaturesList, profileId);
|
|
|
|
@ -251,7 +280,69 @@ public class PolicyManagerImpl implements PolicyManager {
|
|
|
|
|
policyDAO.addPolicyCriteria(policy);
|
|
|
|
|
policyDAO.addPolicyCriteriaProperties(policy.getPolicyCriterias());
|
|
|
|
|
}
|
|
|
|
|
String policyPayloadVersion = previousPolicy.getPolicyPayloadVersion();
|
|
|
|
|
float payloadVersion = 0f;
|
|
|
|
|
if (policyPayloadVersion != null && !StringUtils.isEmpty(policyPayloadVersion)) {
|
|
|
|
|
payloadVersion = Float.parseFloat(policyPayloadVersion);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
List<ProfileFeature> updatedFeatures = policy.getProfile().getProfileFeaturesList();
|
|
|
|
|
List<ProfileFeature> features = featureDAO.getFeaturesForProfile(profileId);
|
|
|
|
|
for (ProfileFeature updatedFeature : updatedFeatures) {
|
|
|
|
|
for (ProfileFeature feature : features) {
|
|
|
|
|
if (updatedFeature.getFeatureCode().equals(feature.getFeatureCode())) {
|
|
|
|
|
updatedFeature.setId(feature.getId());
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (updatedFeature.getCorrectiveActions() != null) {
|
|
|
|
|
updatedCorrectiveActionsMap.put(updatedFeature.getId(),
|
|
|
|
|
updatedFeature.getCorrectiveActions());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (ProfileFeature fe : existingProfileFeaturesList) {
|
|
|
|
|
if (fe.getCorrectiveActions() != null && !fe.getCorrectiveActions().isEmpty()) {
|
|
|
|
|
existingCorrectiveActionsMap.put(fe.getId(), fe.getCorrectiveActions());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (payloadVersion >= 2.0f) {
|
|
|
|
|
updateMultipleCorrectiveActions(updatedCorrectiveActionsMap,
|
|
|
|
|
existingCorrectiveActionsMap, policy, previousPolicy);
|
|
|
|
|
} else {
|
|
|
|
|
updateSingleCorrectiveActionList(policy, previousPolicy);
|
|
|
|
|
}
|
|
|
|
|
PolicyManagementDAOFactory.commitTransaction();
|
|
|
|
|
} catch (PolicyManagerDAOException e) {
|
|
|
|
|
PolicyManagementDAOFactory.rollbackTransaction();
|
|
|
|
|
throw new PolicyManagementException("Error occurred while updating the policy ("
|
|
|
|
|
+ policy.getId() + " - " + policy.getPolicyName() + ")", e);
|
|
|
|
|
} catch (ProfileManagerDAOException e) {
|
|
|
|
|
PolicyManagementDAOFactory.rollbackTransaction();
|
|
|
|
|
throw new PolicyManagementException("Error occurred while updating the profile (" +
|
|
|
|
|
policy.getProfile().getProfileName() + ")", e);
|
|
|
|
|
} catch (FeatureManagerDAOException e) {
|
|
|
|
|
PolicyManagementDAOFactory.rollbackTransaction();
|
|
|
|
|
throw new PolicyManagementException("Error occurred while updating the profile features (" +
|
|
|
|
|
policy.getProfile().getProfileName() + ")", e);
|
|
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
|
PolicyManagementDAOFactory.closeConnection();
|
|
|
|
|
}
|
|
|
|
|
return policy;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Using for update old type of corrective policies which has single corrective policy
|
|
|
|
|
* per single general policy
|
|
|
|
|
* @param policy updating new corrective policy
|
|
|
|
|
* @param previousPolicy previous corrective policy
|
|
|
|
|
* @throws PolicyManagerDAOException for errors occur while updating corrective actions
|
|
|
|
|
*/
|
|
|
|
|
private void updateSingleCorrectiveActionList(Policy policy, Policy previousPolicy)
|
|
|
|
|
throws PolicyManagerDAOException {
|
|
|
|
|
List<CorrectiveAction> updatedCorrectiveActions = policy.getCorrectiveActions();
|
|
|
|
|
List<CorrectiveAction> existingCorrectiveActions = previousPolicy.getCorrectiveActions();
|
|
|
|
|
List<CorrectiveAction> correctiveActionsToUpdate = new ArrayList<>();
|
|
|
|
@ -263,7 +354,8 @@ public class PolicyManagerImpl implements PolicyManager {
|
|
|
|
|
if (updatedCorrectiveActions != null) {
|
|
|
|
|
for (CorrectiveAction updatedCorrectiveAction : updatedCorrectiveActions) {
|
|
|
|
|
for (CorrectiveAction existingCorrectiveAction : existingCorrectiveActions) {
|
|
|
|
|
if (updatedCorrectiveAction.getActionType().equals(existingCorrectiveAction.getActionType())) {
|
|
|
|
|
if (updatedCorrectiveAction.getActionType()
|
|
|
|
|
.equals(existingCorrectiveAction.getActionType())) {
|
|
|
|
|
correctiveActionsToUpdate.add(updatedCorrectiveAction);
|
|
|
|
|
existingCorrectiveActionTypes.add(updatedCorrectiveAction.getActionType());
|
|
|
|
|
}
|
|
|
|
@ -272,7 +364,8 @@ public class PolicyManagerImpl implements PolicyManager {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (CorrectiveAction updatedCorrectiveAction : updatedCorrectiveActions) {
|
|
|
|
|
if (!existingCorrectiveActionTypes.contains(updatedCorrectiveAction.getActionType())) {
|
|
|
|
|
if (!existingCorrectiveActionTypes.contains(updatedCorrectiveAction
|
|
|
|
|
.getActionType())) {
|
|
|
|
|
correctiveActionsToAdd.add(updatedCorrectiveAction);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -288,33 +381,141 @@ 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());
|
|
|
|
|
policyDAO.updateCorrectiveActionsOfPolicy(correctiveActionsToUpdate,
|
|
|
|
|
previousPolicy.getId(), -1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!correctiveActionsToAdd.isEmpty()) {
|
|
|
|
|
policyDAO.addCorrectiveActionsOfPolicy(correctiveActionsToAdd, previousPolicy.getId());
|
|
|
|
|
policyDAO.addCorrectiveActionsOfPolicy(correctiveActionsToAdd,
|
|
|
|
|
previousPolicy.getId(), -1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!correctiveActionsToDelete.isEmpty()) {
|
|
|
|
|
policyDAO.deleteCorrectiveActionsOfPolicy(correctiveActionsToDelete, previousPolicy.getId());
|
|
|
|
|
policyDAO.deleteCorrectiveActionsOfPolicy(correctiveActionsToDelete,
|
|
|
|
|
previousPolicy.getId(), -1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
PolicyManagementDAOFactory.commitTransaction();
|
|
|
|
|
} catch (PolicyManagerDAOException e) {
|
|
|
|
|
PolicyManagementDAOFactory.rollbackTransaction();
|
|
|
|
|
throw new PolicyManagementException("Error occurred while updating the policy ("
|
|
|
|
|
+ policy.getId() + " - " + policy.getPolicyName() + ")", e);
|
|
|
|
|
} catch (ProfileManagerDAOException e) {
|
|
|
|
|
PolicyManagementDAOFactory.rollbackTransaction();
|
|
|
|
|
throw new PolicyManagementException("Error occurred while updating the profile (" +
|
|
|
|
|
policy.getProfile().getProfileName() + ")", e);
|
|
|
|
|
} catch (FeatureManagerDAOException e) {
|
|
|
|
|
PolicyManagementDAOFactory.rollbackTransaction();
|
|
|
|
|
throw new PolicyManagementException("Error occurred while updating the profile features (" +
|
|
|
|
|
policy.getProfile().getProfileName() + ")", e);
|
|
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
|
PolicyManagementDAOFactory.closeConnection();
|
|
|
|
|
/**
|
|
|
|
|
* Using for update new type of corrective policies which has multiple corrective policies
|
|
|
|
|
* per single general policy
|
|
|
|
|
* @param updatedCorrectiveActionsMap updated corrective actions <FeatureId, CorrectiveActionList>
|
|
|
|
|
* @param existingCorrectiveActionsMap existing corrective actions <FeatureId, CorrectiveActionList>
|
|
|
|
|
* @param policy updating policy
|
|
|
|
|
* @param previousPolicy for errors occur while updating corrective actions
|
|
|
|
|
* @throws PolicyManagerDAOException
|
|
|
|
|
*/
|
|
|
|
|
private void updateMultipleCorrectiveActions(
|
|
|
|
|
Map<Integer, List<CorrectiveAction>> updatedCorrectiveActionsMap,
|
|
|
|
|
Map<Integer, List<CorrectiveAction>> existingCorrectiveActionsMap,
|
|
|
|
|
Policy policy, Policy previousPolicy) throws PolicyManagerDAOException {
|
|
|
|
|
|
|
|
|
|
Map<Integer, List<CorrectiveAction>> correctiveActionsToUpdate = new HashMap<>();
|
|
|
|
|
Map<Integer, List<String>> existingCorrectiveActionTypes = new HashMap<>();
|
|
|
|
|
Map<Integer, List<String>> correctiveActionTypesToUpdate = new HashMap<>();
|
|
|
|
|
Map<Integer, List<CorrectiveAction>> correctiveActionsToAdd = new HashMap<>();
|
|
|
|
|
Map<Integer, List<CorrectiveAction>> correctiveActionsToDelete = new HashMap<>();
|
|
|
|
|
|
|
|
|
|
for (Integer featureId : updatedCorrectiveActionsMap.keySet()) {
|
|
|
|
|
List<CorrectiveAction> correctiveActionListToUpdate = new ArrayList<>();
|
|
|
|
|
List<CorrectiveAction> updatedCorrectiveActions = updatedCorrectiveActionsMap
|
|
|
|
|
.get(featureId);
|
|
|
|
|
for (CorrectiveAction updatedCorrectiveAction : updatedCorrectiveActions) {
|
|
|
|
|
List<CorrectiveAction> existingCorrectiveActions = existingCorrectiveActionsMap
|
|
|
|
|
.get(featureId);
|
|
|
|
|
if (existingCorrectiveActions != null) {
|
|
|
|
|
for (CorrectiveAction existingCorrectiveAction : existingCorrectiveActions) {
|
|
|
|
|
if (existingCorrectiveAction.getActionType().equals(updatedCorrectiveAction
|
|
|
|
|
.getActionType())) {
|
|
|
|
|
correctiveActionListToUpdate.add(updatedCorrectiveAction);
|
|
|
|
|
List<String> existingTypes = existingCorrectiveActionTypes
|
|
|
|
|
.get(featureId);
|
|
|
|
|
if (existingTypes == null) {
|
|
|
|
|
existingTypes = new ArrayList<>();
|
|
|
|
|
}
|
|
|
|
|
existingTypes.add(updatedCorrectiveAction.getActionType());
|
|
|
|
|
existingCorrectiveActionTypes.put(featureId, existingTypes);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
List<String> toUpdateTypes = correctiveActionTypesToUpdate.get(featureId);
|
|
|
|
|
if (toUpdateTypes == null) {
|
|
|
|
|
toUpdateTypes = new ArrayList<>();
|
|
|
|
|
}
|
|
|
|
|
toUpdateTypes.add(updatedCorrectiveAction.getActionType());
|
|
|
|
|
correctiveActionTypesToUpdate.put(featureId, toUpdateTypes);
|
|
|
|
|
}
|
|
|
|
|
if (!correctiveActionListToUpdate.isEmpty()) {
|
|
|
|
|
correctiveActionsToUpdate.put(featureId, correctiveActionListToUpdate);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
List<String> existingTypes = existingCorrectiveActionTypes.get(featureId);
|
|
|
|
|
for (CorrectiveAction updatedCorrectiveAction : updatedCorrectiveActions) {
|
|
|
|
|
if (existingTypes == null || !existingTypes.contains(updatedCorrectiveAction
|
|
|
|
|
.getActionType())) {
|
|
|
|
|
List<CorrectiveAction> correctiveActions = correctiveActionsToAdd
|
|
|
|
|
.get(featureId);
|
|
|
|
|
if (correctiveActions == null) {
|
|
|
|
|
correctiveActions = new ArrayList<>();
|
|
|
|
|
}
|
|
|
|
|
correctiveActions.add(updatedCorrectiveAction);
|
|
|
|
|
correctiveActionsToAdd.put(featureId, correctiveActions);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (Integer featureId : existingCorrectiveActionsMap.keySet()) {
|
|
|
|
|
List<CorrectiveAction> existingCorrectiveActions = existingCorrectiveActionsMap
|
|
|
|
|
.get(featureId);
|
|
|
|
|
List<String> actionTypesToUpdate = correctiveActionTypesToUpdate.get(featureId);
|
|
|
|
|
for (CorrectiveAction existingCorrectiveAction : existingCorrectiveActions) {
|
|
|
|
|
if (actionTypesToUpdate == null ||
|
|
|
|
|
!actionTypesToUpdate.contains(existingCorrectiveAction.getActionType())) {
|
|
|
|
|
List<CorrectiveAction> correctiveActionListToDelete = correctiveActionsToDelete
|
|
|
|
|
.get(featureId);
|
|
|
|
|
if (correctiveActionListToDelete == null) {
|
|
|
|
|
correctiveActionListToDelete = new ArrayList<>();
|
|
|
|
|
}
|
|
|
|
|
correctiveActionListToDelete.add(existingCorrectiveAction);
|
|
|
|
|
correctiveActionsToDelete.put(featureId, correctiveActionListToDelete);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
|
log.debug("Updating corrective actions for policy " + policy.getPolicyName() +
|
|
|
|
|
" having policy id " + policy.getId());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!correctiveActionsToUpdate.isEmpty()) {
|
|
|
|
|
for (Integer featureId : correctiveActionsToUpdate.keySet()) {
|
|
|
|
|
List<CorrectiveAction> correctiveActions = correctiveActionsToUpdate
|
|
|
|
|
.get(featureId);
|
|
|
|
|
policyDAO.updateCorrectiveActionsOfPolicy(correctiveActions,
|
|
|
|
|
previousPolicy.getId(), featureId);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!correctiveActionsToAdd.isEmpty()) {
|
|
|
|
|
for (Integer featureId : correctiveActionsToAdd.keySet()) {
|
|
|
|
|
List<CorrectiveAction> correctiveActions = correctiveActionsToAdd
|
|
|
|
|
.get(featureId);
|
|
|
|
|
policyDAO.addCorrectiveActionsOfPolicy(correctiveActions,
|
|
|
|
|
previousPolicy.getId(), featureId);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!correctiveActionsToDelete.isEmpty()) {
|
|
|
|
|
for (Integer featureId : correctiveActionsToDelete.keySet()) {
|
|
|
|
|
List<CorrectiveAction> correctiveActions = correctiveActionsToDelete
|
|
|
|
|
.get(featureId);
|
|
|
|
|
policyDAO.deleteCorrectiveActionsOfPolicy(correctiveActions,
|
|
|
|
|
previousPolicy.getId(), featureId);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return policy;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@ -616,7 +817,7 @@ public class PolicyManagerImpl implements PolicyManager {
|
|
|
|
|
log.debug("Retrieving corrective actions of policy " + policy.getPolicyName() +
|
|
|
|
|
" 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);
|
|
|
|
@ -637,6 +838,34 @@ public class PolicyManagerImpl implements PolicyManager {
|
|
|
|
|
throw new PolicyManagementException("Error occurred while getting the profile related to policy ID (" +
|
|
|
|
|
policyId + ")", e);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
PolicyManagementDAOFactory.openConnection();
|
|
|
|
|
List<CorrectiveAction> correctiveActionsOfPolicy = policyDAO
|
|
|
|
|
.getCorrectiveActionsOfPolicy(policyId);
|
|
|
|
|
String policyPayloadVersion = policy.getPolicyPayloadVersion();
|
|
|
|
|
float payloadVersion = 0f;
|
|
|
|
|
if (policyPayloadVersion != null && !StringUtils.isEmpty(policyPayloadVersion)) {
|
|
|
|
|
payloadVersion = Float.parseFloat(policyPayloadVersion);
|
|
|
|
|
}
|
|
|
|
|
if (payloadVersion >= 2.0f) {
|
|
|
|
|
setMultipleCorrectiveActions(correctiveActionsOfPolicy, policy.getProfile());
|
|
|
|
|
} else {
|
|
|
|
|
policy.setCorrectiveActions(getSingleCorrectiveAction
|
|
|
|
|
(correctiveActionsOfPolicy, policyId));
|
|
|
|
|
}
|
|
|
|
|
} catch (PolicyManagerDAOException e) {
|
|
|
|
|
String msg = "Error occurred while getting the corrective actions related to policy " +
|
|
|
|
|
"ID (" + policyId + ")";
|
|
|
|
|
log.error(msg, e);
|
|
|
|
|
throw new PolicyManagementException(msg, e);
|
|
|
|
|
} catch (SQLException e) {
|
|
|
|
|
String msg = "Error occurred while opening DB connection";
|
|
|
|
|
log.error(msg, e);
|
|
|
|
|
throw new PolicyManagementException(msg, e);
|
|
|
|
|
} finally {
|
|
|
|
|
PolicyManagementDAOFactory.closeConnection();
|
|
|
|
|
}
|
|
|
|
|
return policy;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -1174,17 +1403,41 @@ public class PolicyManagerImpl implements PolicyManager {
|
|
|
|
|
return policyList;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Build the list of policies which are included new and old types of corrective actions
|
|
|
|
|
* @param policyList queried policy list
|
|
|
|
|
* @param profileList queried profile list
|
|
|
|
|
* @throws PolicyManagerDAOException when failed to read policies from DB
|
|
|
|
|
* @throws GroupManagementException when failed to read policy groups from DB
|
|
|
|
|
*/
|
|
|
|
|
private void buildPolicyList(List<Policy> policyList, List<Profile> profileList)
|
|
|
|
|
throws PolicyManagerDAOException, GroupManagementException {
|
|
|
|
|
List<CorrectiveAction> allCorrectiveActions = policyDAO.getAllCorrectiveActions();
|
|
|
|
|
for (Policy policy : policyList) {
|
|
|
|
|
String policyPayloadVersion = policy.getPolicyPayloadVersion();
|
|
|
|
|
float payloadVersion = 0f;
|
|
|
|
|
if (policyPayloadVersion != null &&
|
|
|
|
|
!StringUtils.isEmpty(policyPayloadVersion)) {
|
|
|
|
|
payloadVersion = Float.parseFloat(policyPayloadVersion);
|
|
|
|
|
}
|
|
|
|
|
for (Profile profile : profileList) {
|
|
|
|
|
if (policy.getProfileId() == profile.getProfileId()) {
|
|
|
|
|
policy.setProfile(profile);
|
|
|
|
|
if (payloadVersion >= 2.0f && PolicyManagementConstants.GENERAL_POLICY_TYPE
|
|
|
|
|
.equals(policy.getPolicyType())) {
|
|
|
|
|
setMultipleCorrectiveActions(allCorrectiveActions, profile);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
policy.setRoles(policyDAO.getPolicyAppliedRoles(policy.getId()));
|
|
|
|
|
policy.setUsers(policyDAO.getPolicyAppliedUsers(policy.getId()));
|
|
|
|
|
policy.setPolicyCriterias(policyDAO.getPolicyCriteria(policy.getId()));
|
|
|
|
|
if (payloadVersion < 2.0f && PolicyManagementConstants.GENERAL_POLICY_TYPE
|
|
|
|
|
.equals(policy.getPolicyType())) {
|
|
|
|
|
policy.setCorrectiveActions
|
|
|
|
|
(getSingleCorrectiveAction(allCorrectiveActions, policy.getId()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
List<DeviceGroupWrapper> deviceGroupWrappers = policyDAO.getDeviceGroupsOfPolicy(policy.getId());
|
|
|
|
|
if (!deviceGroupWrappers.isEmpty()) {
|
|
|
|
|
deviceGroupWrappers = this.getDeviceGroupNames(deviceGroupWrappers);
|
|
|
|
@ -1194,8 +1447,44 @@ public class PolicyManagerImpl implements PolicyManager {
|
|
|
|
|
log.debug("Retrieving corrective actions for policy " + policy.getPolicyName() +
|
|
|
|
|
" having policy id " + policy.getId());
|
|
|
|
|
}
|
|
|
|
|
policy.setCorrectiveActions(policyDAO.getCorrectiveActionsOfPolicy(policy.getId()));
|
|
|
|
|
}
|
|
|
|
|
Collections.sort(policyList);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private List<CorrectiveAction> getSingleCorrectiveAction
|
|
|
|
|
(List<CorrectiveAction> allCorrectiveActions, int policyId) {
|
|
|
|
|
List<CorrectiveAction> correctiveActionsOfPolicy = new ArrayList<>();
|
|
|
|
|
for (CorrectiveAction correctiveAction : allCorrectiveActions) {
|
|
|
|
|
if (correctiveAction.getAssociatedGeneralPolicyId() != null &&
|
|
|
|
|
correctiveAction.getAssociatedGeneralPolicyId() == policyId) {
|
|
|
|
|
clearMetaDataValues(correctiveAction);
|
|
|
|
|
correctiveActionsOfPolicy.add(correctiveAction);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return correctiveActionsOfPolicy;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void setMultipleCorrectiveActions(List<CorrectiveAction> allCorrectiveActions,
|
|
|
|
|
Profile profile) {
|
|
|
|
|
for (ProfileFeature profileFeature : profile.getProfileFeaturesList()) {
|
|
|
|
|
List<CorrectiveAction> correctiveActionList = new ArrayList<>();
|
|
|
|
|
for (CorrectiveAction correctiveAction : allCorrectiveActions) {
|
|
|
|
|
if (correctiveAction.getFeatureId() != null &&
|
|
|
|
|
profileFeature.getId() == correctiveAction.getFeatureId()) {
|
|
|
|
|
clearMetaDataValues(correctiveAction);
|
|
|
|
|
correctiveActionList.add(correctiveAction);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
profileFeature.setCorrectiveActions(correctiveActionList);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Clear corrective action metadata values to avoid sending in payload
|
|
|
|
|
* @param correctiveAction list of corrective actions
|
|
|
|
|
*/
|
|
|
|
|
private void clearMetaDataValues(CorrectiveAction correctiveAction) {
|
|
|
|
|
correctiveAction.setAssociatedGeneralPolicyId(null); //avoiding send in payload
|
|
|
|
|
correctiveAction.setFeatureId(null); //avoiding send in payload
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|