Change policy

4.x.x
Pahansith 5 years ago
parent eecb3704d5
commit e486db868e

@ -126,12 +126,6 @@ public class PolicyWrapper {
@NotNull
private String policyType;
@ApiModelProperty(
name = "correctiveActions",
value = "List of corrective actions to be applied when the policy is violated"
)
private List<CorrectiveAction> correctiveActions;
public String getPolicyType() {
return policyType;
}
@ -219,12 +213,4 @@ public class PolicyWrapper {
public void setDeviceGroups(List<DeviceGroupWrapper> deviceGroups) {
this.deviceGroups = deviceGroups;
}
public List<CorrectiveAction> getCorrectiveActions() {
return correctiveActions;
}
public void setCorrectiveActions(List<CorrectiveAction> correctiveActions) {
this.correctiveActions = correctiveActions;
}
}

@ -21,8 +21,10 @@ package org.wso2.carbon.device.mgt.jaxrs.beans;
import com.google.gson.Gson;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import org.wso2.carbon.device.mgt.common.policy.mgt.CorrectiveAction;
import java.io.Serializable;
import java.util.List;
@ApiModel(value = "ProfileFeature", description = "This class carries all information related to profile "
+ "features")
@ -57,6 +59,10 @@ public class ProfileFeature implements Serializable {
value = "The payload which is submitted to each feature",
required = true)
private String payLoad;
@ApiModelProperty(name = "correctiveActions",
value = "List of corrective actions to be applied when the policy is violated",
required = true)
private List<CorrectiveAction> correctiveActions;
public int getId() {
return id;
@ -109,4 +115,12 @@ public class ProfileFeature implements Serializable {
public void setContent(Object content) {
this.content = content;
}
public List<CorrectiveAction> getCorrectiveActions() {
return correctiveActions;
}
public void setCorrectiveActions(List<CorrectiveAction> correctiveActions) {
this.correctiveActions = correctiveActions;
}
}

@ -140,7 +140,6 @@ public class PolicyManagementServiceImpl implements PolicyManagementService {
policy.setPolicyName(policyWrapper.getPolicyName());
policy.setDescription(policyWrapper.getDescription());
policy.setProfile(DeviceMgtUtil.convertProfile(policyWrapper.getProfile()));
policy.setCorrectiveActions(policyWrapper.getCorrectiveActions());
policy.setOwnershipType(policyWrapper.getOwnershipType());
policy.setActive(policyWrapper.isActive());
policy.setRoles(policyWrapper.getRoles());

@ -60,6 +60,7 @@ public class DeviceMgtUtil {
profileFeature.setDeviceType(mdmProfileFeature.getDeviceTypeId());
profileFeature.setFeatureCode(mdmProfileFeature.getFeatureCode());
profileFeature.setId(mdmProfileFeature.getId());
profileFeature.setCorrectiveActions(mdmProfileFeature.getCorrectiveActions());
return profileFeature;
}

@ -201,13 +201,6 @@ public class Policy implements Comparable<Policy>, Serializable {
example = "GENERAL")
private String policyType;
@ApiModelProperty(
name = "correctiveActions",
value = "List of corrective actions to be applied when the policy is violated",
example = "[{'actionType': 'POLICY', 'policyId': 1}]"
)
private List<CorrectiveAction> correctiveActions;
@XmlElement
public int getId() {
return id;
@ -379,16 +372,6 @@ public class Policy implements Comparable<Policy>, Serializable {
this.policyType = policyType;
}
@XmlElement
public List<CorrectiveAction> getCorrectiveActions() {
return correctiveActions;
}
public void setCorrectiveActions(
List<CorrectiveAction> correctiveActions) {
this.correctiveActions = correctiveActions;
}
@Override
public int compareTo(Policy o) {
if (this.priorityId == o.priorityId)

@ -22,6 +22,7 @@ import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import java.io.Serializable;
import java.util.List;
@ApiModel(value = "ProfileFeature", description = "This class carries all information related to profile "
+ "features")
@ -64,6 +65,11 @@ public class ProfileFeature implements Serializable {
example = "{\\\"enabled\\\":false}")
private Object content;
@ApiModelProperty(name = "correctiveActions",
value = "List of corrective actions to be applied when the policy is violated",
required = true)
private List<CorrectiveAction> correctiveActions;
public int getId() {
return id;
}
@ -103,4 +109,12 @@ public class ProfileFeature implements Serializable {
public void setContent(Object content) {
this.content = content;
}
public List<CorrectiveAction> getCorrectiveActions() {
return correctiveActions;
}
public void setCorrectiveActions(List<CorrectiveAction> correctiveActions) {
this.correctiveActions = correctiveActions;
}
}

@ -77,7 +77,8 @@ public interface PolicyDAO {
* @param policyId is used uniquely identify the policy to which corrective actions are to be added
* @throws PolicyManagerDAOException is thrown when there is an error in adding corrective actions to database
*/
void addCorrectiveActionsOfPolicy(List<CorrectiveAction> correctiveActions, int policyId)
void addCorrectiveActionsOfPolicy(List<CorrectiveAction> correctiveActions, int policyId,
int featureId)
throws PolicyManagerDAOException;
/**
@ -86,7 +87,7 @@ public interface PolicyDAO {
* @return list of retrieved {@link CorrectiveAction}
* @throws PolicyManagerDAOException is thrown when there is an error in retrieving corrective actions to database
*/
List<CorrectiveAction> getCorrectiveActionsOfPolicy(int policyId) throws PolicyManagerDAOException;
List<CorrectiveAction> getCorrectiveActionsOfPolicy(int policyId, int featureId) throws PolicyManagerDAOException;
/**
* This method is used to update corrective actions of policy in the database based on the policy ID
@ -94,7 +95,8 @@ public interface PolicyDAO {
* @param policyId is used uniquely identify the policy to which corrective actions are to be updated
* @throws PolicyManagerDAOException is thrown when there is an error in updating corrective actions to database
*/
void updateCorrectiveActionsOfPolicy(List<CorrectiveAction> correctiveActions, int policyId)
void updateCorrectiveActionsOfPolicy(List<CorrectiveAction> correctiveActions, int policyId,
int featureId)
throws PolicyManagerDAOException;
/**
@ -103,7 +105,8 @@ public interface PolicyDAO {
* @param policyId is used uniquely identify the policy to which corrective actions are to be deleted
* @throws PolicyManagerDAOException is thrown when there is an error in deleting corrective actions to database
*/
void deleteCorrectiveActionsOfPolicy(List<CorrectiveAction> correctiveActions, int policyId)
void deleteCorrectiveActionsOfPolicy(List<CorrectiveAction> correctiveActions, int policyId,
int featureId)
throws PolicyManagerDAOException;
Policy updateUserOfPolicy(List<String> usersToAdd, Policy policy) throws PolicyManagerDAOException;

@ -263,19 +263,21 @@ public class PolicyDAOImpl implements PolicyDAO {
}
@Override
public void addCorrectiveActionsOfPolicy(List<CorrectiveAction> correctiveActions, int policyId)
public void addCorrectiveActionsOfPolicy(List<CorrectiveAction> correctiveActions,
int policyId, int featureId)
throws PolicyManagerDAOException {
try {
Connection conn = this.getConnection();
String query = "INSERT INTO DM_POLICY_CORRECTIVE_ACTION " +
"(ACTION_TYPE, " +
"CORRECTIVE_POLICY_ID, " +
"POLICY_ID) VALUES (?, ?, ?)";
"POLICY_ID, FEATURE_ID) VALUES (?, ?, ?, ?)";
try (PreparedStatement insertStmt = conn.prepareStatement(query)) {
for (CorrectiveAction correctiveAction : correctiveActions) {
insertStmt.setString(1, correctiveAction.getActionType());
insertStmt.setInt(2, correctiveAction.getPolicyId());
insertStmt.setInt(3, policyId);
insertStmt.setInt(4, featureId);
insertStmt.addBatch();
}
insertStmt.executeBatch();
@ -288,17 +290,18 @@ public class PolicyDAOImpl implements PolicyDAO {
}
@Override
public List<CorrectiveAction> getCorrectiveActionsOfPolicy(int policyId) throws PolicyManagerDAOException {
public List<CorrectiveAction> getCorrectiveActionsOfPolicy(int policyId, int featureId) throws PolicyManagerDAOException {
try {
Connection conn = this.getConnection();
String query = "SELECT " +
"ACTION_TYPE, " +
"CORRECTIVE_POLICY_ID " +
"FROM DM_POLICY_CORRECTIVE_ACTION " +
"WHERE POLICY_ID = ?";
"WHERE POLICY_ID = ? AND FEATURE_ID = ?";
try (PreparedStatement selectStmt = conn.prepareStatement(query)) {
List<CorrectiveAction> correctiveActions = new ArrayList<>();
selectStmt.setInt(1, policyId);
selectStmt.setInt(2, featureId);
try (ResultSet rs = selectStmt.executeQuery()) {
CorrectiveAction correctiveAction;
while (rs.next()) {
@ -318,19 +321,21 @@ public class PolicyDAOImpl implements PolicyDAO {
}
@Override
public void updateCorrectiveActionsOfPolicy(List<CorrectiveAction> correctiveActions, int policyId)
public void updateCorrectiveActionsOfPolicy(List<CorrectiveAction> correctiveActions,
int policyId, int featureId)
throws PolicyManagerDAOException {
try {
Connection conn = this.getConnection();
String query = "UPDATE DM_POLICY_CORRECTIVE_ACTION " +
"SET CORRECTIVE_POLICY_ID = ? " +
"WHERE ACTION_TYPE = ? " +
"AND POLICY_ID = ?";
"AND POLICY_ID = ? AND FEATURE_ID = ?";
try (PreparedStatement updateStmt = conn.prepareStatement(query)) {
for (CorrectiveAction correctiveAction : correctiveActions) {
updateStmt.setInt(1, correctiveAction.getPolicyId());
updateStmt.setString(2, correctiveAction.getActionType());
updateStmt.setInt(3, policyId);
updateStmt.setInt(4, featureId);
updateStmt.addBatch();
}
updateStmt.executeBatch();
@ -343,17 +348,19 @@ public class PolicyDAOImpl implements PolicyDAO {
}
@Override
public void deleteCorrectiveActionsOfPolicy(List<CorrectiveAction> correctiveActions, int policyId)
public void deleteCorrectiveActionsOfPolicy(List<CorrectiveAction> correctiveActions,
int policyId, int featureId)
throws PolicyManagerDAOException {
try {
Connection conn = this.getConnection();
String query = "DELETE FROM DM_POLICY_CORRECTIVE_ACTION " +
"WHERE ACTION_TYPE = ? " +
"AND POLICY_ID = ?";
"AND POLICY_ID = ? AND FEATURE_ID = ?";
try (PreparedStatement deleteStmt = conn.prepareStatement(query)) {
for (CorrectiveAction correctiveAction : correctiveActions) {
deleteStmt.setString(1, correctiveAction.getActionType());
deleteStmt.setInt(2, policyId);
deleteStmt.setInt(3, featureId);
deleteStmt.addBatch();
}
deleteStmt.executeBatch();

@ -35,6 +35,7 @@
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.LogFactory;
import org.wso2.carbon.device.mgt.common.Device;
@ -101,6 +102,18 @@ public class PolicyManagerImpl implements PolicyManager {
profileDAO.addProfile(profile);
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);
@ -140,13 +153,13 @@ public class PolicyManagerImpl implements PolicyManager {
policyDAO.addPolicyCriteriaProperties(policy.getPolicyCriterias());
}
if (policy.getCorrectiveActions() != null && !policy.getCorrectiveActions().isEmpty()) {
/*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());
@ -189,6 +202,8 @@ 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();
@ -196,7 +211,9 @@ public class PolicyManagerImpl implements PolicyManager {
// Checks for the existing features
for (ProfileFeature feature : updatedFeatureList) {
updatedCorrectiveActionsMap.put(feature.getId(), feature.getCorrectiveActions());
for (ProfileFeature fe : existingProfileFeaturesList) {
existingCorrectiveActionsMap.put(fe.getId(), fe.getCorrectiveActions());
if (feature.getFeatureCode().equalsIgnoreCase(fe.getFeatureCode())) {
existingFeaturesList.add(feature);
temp.add(feature.getFeatureCode());
@ -272,23 +289,39 @@ public class PolicyManagerImpl implements PolicyManager {
policyDAO.addPolicyCriteriaProperties(policy.getPolicyCriterias());
}
List<CorrectiveAction> updatedCorrectiveActions = policy.getCorrectiveActions();
List<CorrectiveAction> existingCorrectiveActions = previousPolicy.getCorrectiveActions();
List<CorrectiveAction> correctiveActionsToUpdate = new ArrayList<>();
List<CorrectiveAction> correctiveActionsToDelete = new ArrayList<>();
List<CorrectiveAction> correctiveActionsToAdd = new ArrayList<>();
List<String> correctiveActionTypesToUpdate = new ArrayList<>();
List<String> existingCorrectiveActionTypes = new ArrayList<>();
if (updatedCorrectiveActions != null) {
for (CorrectiveAction updatedCorrectiveAction : updatedCorrectiveActions) {
/*List<CorrectiveAction> updatedCorrectiveActions = policy.getCorrectiveActions();
List<CorrectiveAction> existingCorrectiveActions = previousPolicy.getCorrectiveActions();*/
//Iterate all corrective actions in the new policy payload against it's features
for (Integer featureId : updatedCorrectiveActionsMap.keySet()) {
List<CorrectiveAction> correctiveActionsToUpdate = new ArrayList<>();
List<CorrectiveAction> correctiveActionsToDelete = new ArrayList<>();
List<CorrectiveAction> correctiveActionsToAdd = new ArrayList<>();
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) {
if (updatedCorrectiveAction.getActionType().equals(existingCorrectiveAction.getActionType())) {
correctiveActionsToUpdate.add(updatedCorrectiveAction);
existingCorrectiveActionTypes.add(updatedCorrectiveAction.getActionType());
if (!correctiveActionTypesToUpdate.contains(existingCorrectiveAction.getActionType())) {
correctiveActionsToDelete.add(existingCorrectiveAction);
}
}
correctiveActionTypesToUpdate.add(updatedCorrectiveAction.getActionType());
}
for (CorrectiveAction updatedCorrectiveAction : updatedCorrectiveActions) {
@ -296,31 +329,43 @@ public class PolicyManagerImpl implements PolicyManager {
correctiveActionsToAdd.add(updatedCorrectiveAction);
}
}
}
for (CorrectiveAction existingCorrectiveAction : existingCorrectiveActions) {
if (!correctiveActionTypesToUpdate.contains(existingCorrectiveAction.getActionType())) {
correctiveActionsToDelete.add(existingCorrectiveAction);
if (log.isDebugEnabled()) {
log.debug("Updating corrective actions for policy " + policy.getPolicyName() +
" having policy id " + policy.getId());
}
}
if (log.isDebugEnabled()) {
log.debug("Updating corrective actions for policy " + policy.getPolicyName() +
" having policy id " + policy.getId());
}
if (!correctiveActionsToUpdate.isEmpty()) {
policyDAO.updateCorrectiveActionsOfPolicy(correctiveActionsToUpdate,
previousPolicy.getId(), featureId);
}
if (!correctiveActionsToUpdate.isEmpty()) {
policyDAO.updateCorrectiveActionsOfPolicy(correctiveActionsToUpdate, previousPolicy.getId());
}
if (!correctiveActionsToAdd.isEmpty()) {
policyDAO.addCorrectiveActionsOfPolicy(correctiveActionsToAdd,
previousPolicy.getId(), featureId);
}
if (!correctiveActionsToAdd.isEmpty()) {
policyDAO.addCorrectiveActionsOfPolicy(correctiveActionsToAdd, previousPolicy.getId());
if (!correctiveActionsToDelete.isEmpty()) {
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();
} catch (PolicyManagerDAOException e) {
PolicyManagementDAOFactory.rollbackTransaction();
@ -656,7 +701,6 @@ 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 (" +
@ -681,6 +725,10 @@ public class PolicyManagerImpl implements PolicyManager {
// PolicyManagementDAOFactory.openConnection();
Profile profile = profileManager.getProfile(policy.getProfileId());
policy.setProfile(profile);
for (ProfileFeature profileFeature : policy.getProfile().getProfileFeaturesList()) {
profileFeature.setCorrectiveActions(policyDAO.getCorrectiveActionsOfPolicy(policyId, profileFeature.getId()));
}
} catch (ProfileManagementException e) {
throw new PolicyManagementException("Error occurred while getting the profile related to policy ID (" +
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);
// } finally {
// PolicyManagementDAOFactory.closeConnection();
} catch (PolicyManagerDAOException e) {
throw new PolicyManagementException("Error occurred while getting the corrective " +
"actions related to policy ID (" + policyId + ")", e);
}
return policy;
}
@ -1278,6 +1330,10 @@ public class PolicyManagerImpl implements PolicyManager {
for (Profile profile : profileList) {
if (policy.getProfileId() == profile.getProfileId()) {
policy.setProfile(profile);
for (ProfileFeature profileFeature : profile.getProfileFeaturesList()) {
profileFeature.setCorrectiveActions(policyDAO
.getCorrectiveActionsOfPolicy(policy.getId(), profileFeature.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() +
" having policy id " + policy.getId());
}
policy.setCorrectiveActions(policyDAO.getCorrectiveActionsOfPolicy(policy.getId()));
}
Collections.sort(policyList);
}

@ -145,8 +145,7 @@ public class PolicyManagerUtil {
policyOperation.setEnabled(true);
policyOperation.setType(org.wso2.carbon.device.mgt.common.operation.mgt.Operation.Type.POLICY);
policyOperation.setCode(PolicyOperation.POLICY_OPERATION_CODE);
if (policy.getPolicyType() != null &&
/*if (policy.getPolicyType() != null &&
PolicyManagementConstants.GENERAL_POLICY_TYPE.equals(policy.getPolicyType()) &&
policy.getCorrectiveActions() != null) {
for (CorrectiveAction correctiveAction : policy.getCorrectiveActions()) {
@ -184,13 +183,63 @@ public class PolicyManagerUtil {
break;
}
}
}
}*/
policyOperation.setProfileOperations(createProfileOperations(effectiveFeatures));
if (policy.getPolicyType() != null &&
PolicyManagementConstants.GENERAL_POLICY_TYPE.equals(policy.getPolicyType())) {
setCorrectiveActions(effectiveFeatures, policyOperation, policy);
}
policyOperation.setPayLoad(policyOperation.getProfileOperations());
return policyOperation;
}
private static void setCorrectiveActions(List<ProfileFeature> features,
PolicyOperation policyOperation, Policy policy) throws PolicyTransformException {
List<ProfileFeature> effectiveFeatures = new ArrayList<>(features);
for (ProfileFeature effectiveFeature : features) {
if (effectiveFeature.getCorrectiveActions() != null) {
for (CorrectiveAction correctiveAction : effectiveFeature.getCorrectiveActions()) {
if (PolicyManagementConstants.POLICY_CORRECTIVE_ACTION_TYPE
.equalsIgnoreCase(correctiveAction.getActionType())) {
PolicyAdministratorPoint pap = new PolicyAdministratorPointImpl();
try {
Policy correctivePolicy = pap.getPolicy(correctiveAction.getPolicyId());
if (correctivePolicy == null || !PolicyManagementConstants.CORRECTIVE_POLICY_TYPE
.equalsIgnoreCase(correctivePolicy.getPolicyType() )) {
String msg = "No corrective policy was found for the policy " + policy.getPolicyName() +
" and policy ID " + policy.getId();
log.error(msg);
throw new PolicyTransformException(msg);
} else {
List<ProfileOperation> correctiveProfileOperations = createProfileOperations(
correctivePolicy.getProfile().getProfileFeaturesList());
ProfileFeature correctivePolicyFeature = new ProfileFeature();
correctivePolicyFeature.setProfileId(correctivePolicy.getProfileId());
correctivePolicyFeature.setContent(new Gson().toJson(correctiveProfileOperations));
correctivePolicyFeature.setDeviceType(correctivePolicy.getProfile().getDeviceType());
correctivePolicyFeature.setFeatureCode(
PolicyManagementConstants.CORRECTIVE_POLICY_FEATURE_CODE);
correctivePolicyFeature.setId(correctivePolicy.getId());
List<ProfileOperation> profileOperations = policyOperation.getProfileOperations();
effectiveFeatures.add(correctivePolicyFeature);
}
} catch (PolicyManagementException e) {
String msg = "Error occurred while retrieving corrective policy for policy " +
policy.getPolicyName() + " and policy ID " + policy.getId();
log.error(msg, e);
throw new PolicyTransformException(msg, e);
}
// Currently only supported POLICY corrective action type so the break is added. This should be
// removed when we start supporting other corrective action types
break;
}
}
}
}
}
public static List<ProfileOperation> createProfileOperations(List<ProfileFeature> effectiveFeatures) {
List<ProfileOperation> profileOperations = new ArrayList<>();
for (ProfileFeature feature : effectiveFeatures) {

@ -205,10 +205,16 @@ CREATE TABLE IF NOT EXISTS DM_POLICY_CORRECTIVE_ACTION (
ACTION_TYPE VARCHAR(45) NOT NULL,
CORRECTIVE_POLICY_ID INT(11) DEFAULT NULL,
POLICY_ID INT(11) NOT NULL,
FEATURE_ID INT(11) NOT NULL,
PRIMARY KEY (ID),
CONSTRAINT FK_DM_POLICY_DM_POLICY_CORRECTIVE_ACTION
FOREIGN KEY (POLICY_ID )
REFERENCES DM_POLICY (ID )
FOREIGN KEY (POLICY_ID)
REFERENCES DM_POLICY (ID)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT FK_DM_POLICY_DM_POLICY_CORRECTIVE_ACTION
FOREIGN KEY (FEATURE_ID)
REFERENCES DM_PROFILE_FEATURES (ID)
ON DELETE NO ACTION
ON UPDATE NO ACTION
);

@ -85,11 +85,17 @@ CREATE TABLE IF NOT EXISTS `WSO2CDM`.`DM_POLICY_CORRECTIVE_ACTION` (
`ACTION_TYPE` VARCHAR(45) NOT NULL,
`CORRECTIVE_POLICY_ID` INT(11) DEFAULT NULL,
`POLICY_ID` INT(11) NOT NULL,
`FEATURE_ID` INT(11) NOT NULL,
PRIMARY KEY (ID),
CONSTRAINT FK_DM_POLICY_DM_POLICY_CORRECTIVE_ACTION
FOREIGN KEY (POLICY_ID)
REFERENCES DM_POLICY (ID)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT FK_DM_POLICY_DM_POLICY_CORRECTIVE_ACTION
FOREIGN KEY (FEATURE_ID)
REFERENCES DM_PROFILE_FEATURES (ID)
ON DELETE NO ACTION
ON UPDATE NO ACTION
)ENGINE = InnoDB
DEFAULT CHARACTER SET = latin1;

@ -199,10 +199,16 @@ CREATE TABLE IF NOT EXISTS DM_POLICY_CORRECTIVE_ACTION (
ACTION_TYPE VARCHAR(45) NOT NULL,
CORRECTIVE_POLICY_ID INT(11) DEFAULT NULL,
POLICY_ID INT(11) NOT NULL,
FEATURE_ID INT(11) NOT NULL,
PRIMARY KEY (ID),
CONSTRAINT FK_DM_POLICY_DM_POLICY_CORRECTIVE_ACTION
FOREIGN KEY (POLICY_ID )
REFERENCES DM_POLICY (ID )
FOREIGN KEY (POLICY_ID)
REFERENCES DM_POLICY (ID)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT FK_DM_POLICY_DM_POLICY_CORRECTIVE_ACTION
FOREIGN KEY (FEATURE_ID)
REFERENCES DM_PROFILE_FEATURES (ID)
ON DELETE NO ACTION
ON UPDATE NO ACTION
);

@ -249,11 +249,17 @@ CREATE TABLE DM_POLICY_CORRECTIVE_ACTION (
ACTION_TYPE VARCHAR(45) NOT NULL,
CORRECTIVE_POLICY_ID INTEGER DEFAULT NULL,
POLICY_ID INTEGER NOT NULL,
FEATURE_ID INTEGER NOT NULL,
PRIMARY KEY (ID),
CONSTRAINT FK_DM_POLICY_DM_POLICY_CORRECTIVE_ACTION
FOREIGN KEY (POLICY_ID)
REFERENCES DM_POLICY (ID)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT FK_DM_POLICY_DM_POLICY_CORRECTIVE_ACTION
FOREIGN KEY (FEATURE_ID)
REFERENCES DM_PROFILE_FEATURES (ID)
ON DELETE NO ACTION
ON UPDATE NO ACTION
);

@ -233,11 +233,17 @@ CREATE TABLE IF NOT EXISTS DM_POLICY_CORRECTIVE_ACTION (
ACTION_TYPE VARCHAR(45) NOT NULL,
CORRECTIVE_POLICY_ID INT(11) DEFAULT NULL,
POLICY_ID INT(11) NOT NULL,
FEATURE_ID INT(11) NOT NULL,
PRIMARY KEY (ID),
CONSTRAINT FK_DM_POLICY_DM_POLICY_CORRECTIVE_ACTION
FOREIGN KEY (POLICY_ID)
REFERENCES DM_POLICY (ID)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT FK_DM_POLICY_DM_POLICY_CORRECTIVE_ACTION
FOREIGN KEY (FEATURE_ID)
REFERENCES DM_PROFILE_FEATURES (ID)
ON DELETE NO ACTION
ON UPDATE NO ACTION
)ENGINE = InnoDB;

@ -340,10 +340,14 @@ CREATE TABLE DM_POLICY_CORRECTIVE_ACTION (
ACTION_TYPE VARCHAR2(45) NOT NULL,
CORRECTIVE_POLICY_ID NUMBER(10) DEFAULT NULL,
POLICY_ID NUMBER(10) NOT NULL,
FEATURE_ID NUMBER(10) NOT NULL,
CONSTRAINT PK_DM_POLICY_CORRECTIVE_ACTION PRIMARY KEY (ID),
CONSTRAINT FK_DM_POLICY_DM_POLICY_CORRECTIVE_ACTION
FOREIGN KEY (POLICY_ID)
REFERENCES DM_POLICY (ID)
REFERENCES DM_POLICY (ID),
CONSTRAINT FK_DM_POLICY_DM_POLICY_CORRECTIVE_ACTION
FOREIGN KEY (FEATURE_ID)
REFERENCES DM_PROFILE_FEATURES (ID)
)
/

@ -237,6 +237,23 @@ CREATE TABLE IF NOT EXISTS DM_POLICY (
CREATE SEQUENCE DM_DEVICE_POLICY_seq;
CREATE TABLE IF NOT EXISTS DM_POLICY_CORRECTIVE_ACTION (
ID BIGSERIAL NOT NULL PRIMARY KEY,
ACTION_TYPE VARCHAR(45) NOT NULL,
CORRECTIVE_POLICY_ID INTEGER DEFAULT NULL,
POLICY_ID INTEGER NOT NULL,
FEATURE_ID INTEGER NOT NULL,
CONSTRAINT FK_DM_POLICY_DM_POLICY_CORRECTIVE_ACTION
FOREIGN KEY (POLICY_ID)
REFERENCES DM_POLICY (ID)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT FK_DM_POLICY_DM_POLICY_CORRECTIVE_ACTION
FOREIGN KEY (FEATURE_ID)
REFERENCES DM_PROFILE_FEATURES (ID)
ON DELETE NO ACTION
ON UPDATE NO ACTION
);
CREATE TABLE IF NOT EXISTS DM_DEVICE_POLICY (
ID INTEGER NOT NULL DEFAULT NEXTVAL ('DM_DEVICE_POLICY_seq') ,

Loading…
Cancel
Save