|
|
@ -35,6 +35,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
package org.wso2.carbon.policy.mgt.core.mgt.impl;
|
|
|
|
package org.wso2.carbon.policy.mgt.core.mgt.impl;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import org.apache.commons.collections.map.HashedMap;
|
|
|
|
import org.apache.commons.logging.Log;
|
|
|
|
import org.apache.commons.logging.Log;
|
|
|
|
import org.apache.commons.logging.LogFactory;
|
|
|
|
import org.apache.commons.logging.LogFactory;
|
|
|
|
import org.wso2.carbon.device.mgt.common.Device;
|
|
|
|
import org.wso2.carbon.device.mgt.common.Device;
|
|
|
@ -101,6 +102,18 @@ public class PolicyManagerImpl implements PolicyManager {
|
|
|
|
|
|
|
|
|
|
|
|
profileDAO.addProfile(profile);
|
|
|
|
profileDAO.addProfile(profile);
|
|
|
|
featureDAO.addProfileFeatures(profile.getProfileFeaturesList(), profile.getProfileId());
|
|
|
|
featureDAO.addProfileFeatures(profile.getProfileFeaturesList(), profile.getProfileId());
|
|
|
|
|
|
|
|
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());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
policy = policyDAO.addPolicy(policy);
|
|
|
|
policy = policyDAO.addPolicy(policy);
|
|
|
|
|
|
|
|
|
|
|
@ -140,13 +153,13 @@ public class PolicyManagerImpl implements PolicyManager {
|
|
|
|
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() +
|
|
|
|
" having policy id " + policy.getId());
|
|
|
|
" having policy id " + policy.getId());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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());
|
|
|
@ -189,6 +202,8 @@ public class PolicyManagerImpl implements PolicyManager {
|
|
|
|
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<>();
|
|
|
|
|
|
|
|
Map<Integer, List<CorrectiveAction>> updatedCorrectiveActionsMap = new HashMap<>();
|
|
|
|
|
|
|
|
Map<Integer, List<CorrectiveAction>> existingCorrectiveActionsMap = new HashMap<>();
|
|
|
|
|
|
|
|
|
|
|
|
List<ProfileFeature> updatedFeatureList = policy.getProfile().getProfileFeaturesList();
|
|
|
|
List<ProfileFeature> updatedFeatureList = policy.getProfile().getProfileFeaturesList();
|
|
|
|
|
|
|
|
|
|
|
@ -196,7 +211,9 @@ public class PolicyManagerImpl implements PolicyManager {
|
|
|
|
|
|
|
|
|
|
|
|
// Checks for the existing features
|
|
|
|
// Checks for the existing features
|
|
|
|
for (ProfileFeature feature : updatedFeatureList) {
|
|
|
|
for (ProfileFeature feature : updatedFeatureList) {
|
|
|
|
|
|
|
|
updatedCorrectiveActionsMap.put(feature.getId(), feature.getCorrectiveActions());
|
|
|
|
for (ProfileFeature fe : existingProfileFeaturesList) {
|
|
|
|
for (ProfileFeature fe : existingProfileFeaturesList) {
|
|
|
|
|
|
|
|
existingCorrectiveActionsMap.put(fe.getId(), fe.getCorrectiveActions());
|
|
|
|
if (feature.getFeatureCode().equalsIgnoreCase(fe.getFeatureCode())) {
|
|
|
|
if (feature.getFeatureCode().equalsIgnoreCase(fe.getFeatureCode())) {
|
|
|
|
existingFeaturesList.add(feature);
|
|
|
|
existingFeaturesList.add(feature);
|
|
|
|
temp.add(feature.getFeatureCode());
|
|
|
|
temp.add(feature.getFeatureCode());
|
|
|
@ -272,23 +289,39 @@ public class PolicyManagerImpl implements PolicyManager {
|
|
|
|
policyDAO.addPolicyCriteriaProperties(policy.getPolicyCriterias());
|
|
|
|
policyDAO.addPolicyCriteriaProperties(policy.getPolicyCriterias());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
List<CorrectiveAction> updatedCorrectiveActions = policy.getCorrectiveActions();
|
|
|
|
/*List<CorrectiveAction> updatedCorrectiveActions = policy.getCorrectiveActions();
|
|
|
|
List<CorrectiveAction> existingCorrectiveActions = previousPolicy.getCorrectiveActions();
|
|
|
|
List<CorrectiveAction> existingCorrectiveActions = previousPolicy.getCorrectiveActions();*/
|
|
|
|
List<CorrectiveAction> correctiveActionsToUpdate = new ArrayList<>();
|
|
|
|
|
|
|
|
List<CorrectiveAction> correctiveActionsToDelete = new ArrayList<>();
|
|
|
|
//Iterate all corrective actions in the new policy payload against it's features
|
|
|
|
List<CorrectiveAction> correctiveActionsToAdd = new ArrayList<>();
|
|
|
|
for (Integer featureId : updatedCorrectiveActionsMap.keySet()) {
|
|
|
|
List<String> correctiveActionTypesToUpdate = new ArrayList<>();
|
|
|
|
List<CorrectiveAction> correctiveActionsToUpdate = new ArrayList<>();
|
|
|
|
List<String> existingCorrectiveActionTypes = new ArrayList<>();
|
|
|
|
List<CorrectiveAction> correctiveActionsToDelete = new ArrayList<>();
|
|
|
|
|
|
|
|
List<CorrectiveAction> correctiveActionsToAdd = new ArrayList<>();
|
|
|
|
if (updatedCorrectiveActions != null) {
|
|
|
|
|
|
|
|
for (CorrectiveAction updatedCorrectiveAction : updatedCorrectiveActions) {
|
|
|
|
List<String> correctiveActionTypesToUpdate = new ArrayList<>();
|
|
|
|
|
|
|
|
List<String> existingCorrectiveActionTypes = new ArrayList<>();
|
|
|
|
|
|
|
|
List<CorrectiveAction> updatedCorrectiveActions = updatedCorrectiveActionsMap.get(featureId);
|
|
|
|
|
|
|
|
//Check this feature already have a corrective action
|
|
|
|
|
|
|
|
if (existingCorrectiveActionsMap.containsKey(featureId)) {
|
|
|
|
|
|
|
|
//Existing corrective actions of the selected feature
|
|
|
|
|
|
|
|
List<CorrectiveAction> existingCorrectiveActions = existingCorrectiveActionsMap.get(featureId);
|
|
|
|
|
|
|
|
for (CorrectiveAction updatedCorrectiveAction : updatedCorrectiveActions) {
|
|
|
|
|
|
|
|
for (CorrectiveAction existingCorrectiveAction : existingCorrectiveActions) {
|
|
|
|
|
|
|
|
if (updatedCorrectiveAction.getActionType().equals(existingCorrectiveAction.getActionType())) {
|
|
|
|
|
|
|
|
//If old action type is same as new action type, put them into
|
|
|
|
|
|
|
|
// updating list
|
|
|
|
|
|
|
|
correctiveActionsToUpdate.add(updatedCorrectiveAction);
|
|
|
|
|
|
|
|
existingCorrectiveActionTypes.add(updatedCorrectiveAction.getActionType());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//Newly added action types added to this list
|
|
|
|
|
|
|
|
correctiveActionTypesToUpdate.add(updatedCorrectiveAction.getActionType());
|
|
|
|
|
|
|
|
}
|
|
|
|
for (CorrectiveAction existingCorrectiveAction : existingCorrectiveActions) {
|
|
|
|
for (CorrectiveAction existingCorrectiveAction : existingCorrectiveActions) {
|
|
|
|
if (updatedCorrectiveAction.getActionType().equals(existingCorrectiveAction.getActionType())) {
|
|
|
|
if (!correctiveActionTypesToUpdate.contains(existingCorrectiveAction.getActionType())) {
|
|
|
|
correctiveActionsToUpdate.add(updatedCorrectiveAction);
|
|
|
|
correctiveActionsToDelete.add(existingCorrectiveAction);
|
|
|
|
existingCorrectiveActionTypes.add(updatedCorrectiveAction.getActionType());
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
correctiveActionTypesToUpdate.add(updatedCorrectiveAction.getActionType());
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
for (CorrectiveAction updatedCorrectiveAction : updatedCorrectiveActions) {
|
|
|
|
for (CorrectiveAction updatedCorrectiveAction : updatedCorrectiveActions) {
|
|
|
@ -296,31 +329,43 @@ public class PolicyManagerImpl implements PolicyManager {
|
|
|
|
correctiveActionsToAdd.add(updatedCorrectiveAction);
|
|
|
|
correctiveActionsToAdd.add(updatedCorrectiveAction);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (CorrectiveAction existingCorrectiveAction : existingCorrectiveActions) {
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
if (!correctiveActionTypesToUpdate.contains(existingCorrectiveAction.getActionType())) {
|
|
|
|
log.debug("Updating corrective actions for policy " + policy.getPolicyName() +
|
|
|
|
correctiveActionsToDelete.add(existingCorrectiveAction);
|
|
|
|
" having policy id " + policy.getId());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
if (!correctiveActionsToUpdate.isEmpty()) {
|
|
|
|
log.debug("Updating corrective actions for policy " + policy.getPolicyName() +
|
|
|
|
policyDAO.updateCorrectiveActionsOfPolicy(correctiveActionsToUpdate,
|
|
|
|
" having policy id " + policy.getId());
|
|
|
|
previousPolicy.getId(), featureId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (!correctiveActionsToUpdate.isEmpty()) {
|
|
|
|
if (!correctiveActionsToAdd.isEmpty()) {
|
|
|
|
policyDAO.updateCorrectiveActionsOfPolicy(correctiveActionsToUpdate, previousPolicy.getId());
|
|
|
|
policyDAO.addCorrectiveActionsOfPolicy(correctiveActionsToAdd,
|
|
|
|
}
|
|
|
|
previousPolicy.getId(), featureId);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (!correctiveActionsToAdd.isEmpty()) {
|
|
|
|
if (!correctiveActionsToDelete.isEmpty()) {
|
|
|
|
policyDAO.addCorrectiveActionsOfPolicy(correctiveActionsToAdd, previousPolicy.getId());
|
|
|
|
policyDAO.deleteCorrectiveActionsOfPolicy(correctiveActionsToDelete,
|
|
|
|
|
|
|
|
previousPolicy.getId(), featureId);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (!correctiveActionsToDelete.isEmpty()) {
|
|
|
|
|
|
|
|
policyDAO.deleteCorrectiveActionsOfPolicy(correctiveActionsToDelete, previousPolicy.getId());
|
|
|
|
/*for (CorrectiveAction updatedCorrectiveAction : updatedCorrectiveActions) {
|
|
|
|
|
|
|
|
if (!existingCorrectiveActionTypes.contains(updatedCorrectiveAction.getActionType())) {
|
|
|
|
|
|
|
|
correctiveActionsToAdd.add(updatedCorrectiveAction);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (CorrectiveAction existingCorrectiveAction : existingCorrectiveActions) {
|
|
|
|
|
|
|
|
if (!correctiveActionTypesToUpdate.contains(existingCorrectiveAction.getActionType())) {
|
|
|
|
|
|
|
|
correctiveActionsToDelete.add(existingCorrectiveAction);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
PolicyManagementDAOFactory.commitTransaction();
|
|
|
|
PolicyManagementDAOFactory.commitTransaction();
|
|
|
|
} catch (PolicyManagerDAOException e) {
|
|
|
|
} catch (PolicyManagerDAOException e) {
|
|
|
|
PolicyManagementDAOFactory.rollbackTransaction();
|
|
|
|
PolicyManagementDAOFactory.rollbackTransaction();
|
|
|
@ -656,7 +701,6 @@ public class PolicyManagerImpl implements PolicyManager {
|
|
|
|
log.debug("Retrieving corrective actions of policy " + policy.getPolicyName() +
|
|
|
|
log.debug("Retrieving corrective actions of policy " + policy.getPolicyName() +
|
|
|
|
" having policy id " + policy.getId());
|
|
|
|
" having policy id " + policy.getId());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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 (" +
|
|
|
@ -681,6 +725,10 @@ public class PolicyManagerImpl implements PolicyManager {
|
|
|
|
// PolicyManagementDAOFactory.openConnection();
|
|
|
|
// PolicyManagementDAOFactory.openConnection();
|
|
|
|
Profile profile = profileManager.getProfile(policy.getProfileId());
|
|
|
|
Profile profile = profileManager.getProfile(policy.getProfileId());
|
|
|
|
policy.setProfile(profile);
|
|
|
|
policy.setProfile(profile);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (ProfileFeature profileFeature : policy.getProfile().getProfileFeaturesList()) {
|
|
|
|
|
|
|
|
profileFeature.setCorrectiveActions(policyDAO.getCorrectiveActionsOfPolicy(policyId, profileFeature.getId()));
|
|
|
|
|
|
|
|
}
|
|
|
|
} 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);
|
|
|
@ -688,8 +736,12 @@ public class PolicyManagerImpl implements PolicyManager {
|
|
|
|
// 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);
|
|
|
|
// } finally {
|
|
|
|
// } finally {
|
|
|
|
// PolicyManagementDAOFactory.closeConnection();
|
|
|
|
// PolicyManagementDAOFactory.closeConnection();
|
|
|
|
|
|
|
|
} catch (PolicyManagerDAOException e) {
|
|
|
|
|
|
|
|
throw new PolicyManagementException("Error occurred while getting the corrective " +
|
|
|
|
|
|
|
|
"actions related to policy ID (" + policyId + ")", e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return policy;
|
|
|
|
return policy;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -1278,6 +1330,10 @@ public class PolicyManagerImpl implements PolicyManager {
|
|
|
|
for (Profile profile : profileList) {
|
|
|
|
for (Profile profile : profileList) {
|
|
|
|
if (policy.getProfileId() == profile.getProfileId()) {
|
|
|
|
if (policy.getProfileId() == profile.getProfileId()) {
|
|
|
|
policy.setProfile(profile);
|
|
|
|
policy.setProfile(profile);
|
|
|
|
|
|
|
|
for (ProfileFeature profileFeature : profile.getProfileFeaturesList()) {
|
|
|
|
|
|
|
|
profileFeature.setCorrectiveActions(policyDAO
|
|
|
|
|
|
|
|
.getCorrectiveActionsOfPolicy(policy.getId(), profileFeature.getId()));
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
policy.setRoles(policyDAO.getPolicyAppliedRoles(policy.getId()));
|
|
|
|
policy.setRoles(policyDAO.getPolicyAppliedRoles(policy.getId()));
|
|
|
@ -1293,7 +1349,6 @@ public class PolicyManagerImpl implements PolicyManager {
|
|
|
|
log.debug("Retrieving corrective actions for policy " + policy.getPolicyName() +
|
|
|
|
log.debug("Retrieving corrective actions for policy " + policy.getPolicyName() +
|
|
|
|
" having policy id " + policy.getId());
|
|
|
|
" having policy id " + policy.getId());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
policy.setCorrectiveActions(policyDAO.getCorrectiveActionsOfPolicy(policy.getId()));
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Collections.sort(policyList);
|
|
|
|
Collections.sort(policyList);
|
|
|
|
}
|
|
|
|
}
|
|
|
|