From 684ff5df7fe97b4bb81b8cac7554e52536edccc2 Mon Sep 17 00:00:00 2001 From: Pahansith Date: Tue, 24 Mar 2020 11:42:50 +0530 Subject: [PATCH] Fix test failures --- .../core/operation/mgt/ProfileOperation.java | 10 ++ .../mgt/core/mgt/impl/PolicyManagerImpl.java | 20 +++- .../core/util/PolicyManagementConstants.java | 1 + .../mgt/core/util/PolicyManagerUtil.java | 92 ++++++++++++++++--- .../test/resources/sql/CreateMySqlTestDB.sql | 45 +++++---- .../src/main/resources/dbscripts/cdm/h2.sql | 38 ++++---- .../main/resources/dbscripts/cdm/mssql.sql | 40 ++++---- .../main/resources/dbscripts/cdm/mysql.sql | 37 ++++---- .../main/resources/dbscripts/cdm/oracle.sql | 32 +++---- 9 files changed, 200 insertions(+), 115 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/ProfileOperation.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/ProfileOperation.java index f984fdfb0c1..b89233f9671 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/ProfileOperation.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/ProfileOperation.java @@ -19,8 +19,11 @@ package org.wso2.carbon.device.mgt.core.operation.mgt; import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; public class ProfileOperation extends ConfigOperation implements Serializable { + private List correctiveActionIds = new ArrayList<>(); public Type getType() { return Type.PROFILE; @@ -30,4 +33,11 @@ public class ProfileOperation extends ConfigOperation implements Serializable { return Control.REPEAT; } + public List getCorrectiveActionIds() { + return correctiveActionIds; + } + + public void setCorrectiveActionIds(List correctiveActionIds) { + this.correctiveActionIds = correctiveActionIds; + } } diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/mgt/impl/PolicyManagerImpl.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/mgt/impl/PolicyManagerImpl.java index b1261daa110..79bf61696a8 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/mgt/impl/PolicyManagerImpl.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/mgt/impl/PolicyManagerImpl.java @@ -211,9 +211,13 @@ public class PolicyManagerImpl implements PolicyManager { // Checks for the existing features for (ProfileFeature feature : updatedFeatureList) { - updatedCorrectiveActionsMap.put(feature.getId(), feature.getCorrectiveActions()); + if (feature.getCorrectiveActions() != null) { + updatedCorrectiveActionsMap.put(feature.getId(), feature.getCorrectiveActions()); + } for (ProfileFeature fe : existingProfileFeaturesList) { - existingCorrectiveActionsMap.put(fe.getId(), fe.getCorrectiveActions()); + if (fe.getCorrectiveActions() != null) { + existingCorrectiveActionsMap.put(fe.getId(), fe.getCorrectiveActions()); + } if (feature.getFeatureCode().equalsIgnoreCase(fe.getFeatureCode())) { existingFeaturesList.add(feature); temp.add(feature.getFeatureCode()); @@ -722,12 +726,16 @@ public class PolicyManagerImpl implements PolicyManager { policy.setDevices(deviceList); try { - // PolicyManagementDAOFactory.openConnection(); Profile profile = profileManager.getProfile(policy.getProfileId()); policy.setProfile(profile); + PolicyManagementDAOFactory.openConnection(); for (ProfileFeature profileFeature : policy.getProfile().getProfileFeaturesList()) { - profileFeature.setCorrectiveActions(policyDAO.getCorrectiveActionsOfPolicy(policyId, profileFeature.getId())); + List correctiveActionsOfPolicy = policyDAO + .getCorrectiveActionsOfPolicy(policyId, profileFeature.getId()); + if (correctiveActionsOfPolicy != null) { + profileFeature.setCorrectiveActions(correctiveActionsOfPolicy); + } } } catch (ProfileManagementException e) { throw new PolicyManagementException("Error occurred while getting the profile related to policy ID (" + @@ -739,6 +747,10 @@ public class PolicyManagerImpl implements PolicyManager { } catch (PolicyManagerDAOException e) { throw new PolicyManagementException("Error occurred while getting the corrective " + "actions related to policy ID (" + policyId + ")", e); + } catch (SQLException e) { + e.printStackTrace(); + } finally { + PolicyManagementDAOFactory.closeConnection(); } diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/util/PolicyManagementConstants.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/util/PolicyManagementConstants.java index e945f98127a..3ea0efa51d8 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/util/PolicyManagementConstants.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/util/PolicyManagementConstants.java @@ -66,6 +66,7 @@ public final class PolicyManagementConstants { public static final String CORRECTIVE_POLICY_TYPE = "CORRECTIVE"; public static final String POLICY_CORRECTIVE_ACTION_TYPE = "POLICY"; public static final String CORRECTIVE_POLICY_FEATURE_CODE = "CORRECTIVE_POLICY"; + public static final String CORRECTIVE_POLICY_LIST = "CORRECTIVE_ACTIONS"; /** Caller would reference the constants using PolicyManagementConstants.DEVICE_CONFIG_XML_NAME, diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/util/PolicyManagerUtil.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/util/PolicyManagerUtil.java index 4c089596e90..55e39354d54 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/util/PolicyManagerUtil.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/util/PolicyManagerUtil.java @@ -195,33 +195,70 @@ public class PolicyManagerUtil { } private static void setCorrectiveActions(List features, - PolicyOperation policyOperation, Policy policy) throws PolicyTransformException { - List effectiveFeatures = new ArrayList<>(features); + PolicyOperation policyOperation, Policy policy) + throws PolicyTransformException { + ProfileOperation correctiveOperations = new ProfileOperation(); + correctiveOperations.setCode(PolicyManagementConstants.CORRECTIVE_POLICY_LIST); 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(); + 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 correctiveProfileOperations = createProfileOperations( - correctivePolicy.getProfile().getProfileFeaturesList()); + createCorrectiveProfileOperations(correctivePolicy, correctiveOperations); + policyOperation.getProfileOperations().add(correctiveOperations); + } + } 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); + } + } + } + + + + /*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 correctiveProfileOperations = + createProfileOperations();*//* + createCorrectiveProfileOperations(correctivePolicy.getProfile() + .getProfileFeaturesList()); + + ProfileFeature correctivePolicyFeature = new ProfileFeature(); correctivePolicyFeature.setProfileId(correctivePolicy.getProfileId()); - correctivePolicyFeature.setContent(new Gson().toJson(correctiveProfileOperations)); - correctivePolicyFeature.setDeviceType(correctivePolicy.getProfile().getDeviceType()); + correctivePolicyFeature.setContent(new Gson() + .toJson(correctiveProfileOperations)); + correctivePolicyFeature.setDeviceType(correctivePolicy + .getProfile().getDeviceType()); correctivePolicyFeature.setFeatureCode( PolicyManagementConstants.CORRECTIVE_POLICY_FEATURE_CODE); correctivePolicyFeature.setId(correctivePolicy.getId()); - List profileOperations = policyOperation.getProfileOperations(); effectiveFeatures.add(correctivePolicyFeature); } } catch (PolicyManagementException e) { @@ -230,15 +267,39 @@ public class PolicyManagerUtil { 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 + // 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; } - } + }*/ + + + + + } } } + private static void createCorrectiveProfileOperations(Policy correctivePolicy, + ProfileOperation correctiveOperationList) { + ProfileOperation profileOperation = new ProfileOperation(); + profileOperation.setId(correctivePolicy.getId()); + profileOperation.setCode(PolicyManagementConstants.CORRECTIVE_POLICY_FEATURE_CODE); + profileOperation.setEnabled(true); + profileOperation.setStatus(org.wso2.carbon.device.mgt.common.operation.mgt.Operation.Status.PENDING); + profileOperation.setType(org.wso2.carbon.device.mgt.common.operation.mgt.Operation.Type.PROFILE); + String correctivePayload =(String) correctiveOperationList.getPayLoad(); + if (correctivePayload == null) { + correctivePayload = ""; + } + List profileOperations = createProfileOperations(correctivePolicy + .getProfile().getProfileFeaturesList()); + String payload = new Gson().toJson(profileOperations); + correctiveOperationList.setPayLoad(correctivePayload.concat(payload)); + } + public static List createProfileOperations(List effectiveFeatures) { List profileOperations = new ArrayList<>(); @@ -249,6 +310,9 @@ public class PolicyManagerUtil { profileOperation.setStatus(org.wso2.carbon.device.mgt.common.operation.mgt.Operation.Status.PENDING); profileOperation.setType(org.wso2.carbon.device.mgt.common.operation.mgt.Operation.Type.PROFILE); profileOperation.setPayLoad(feature.getContent()); + for (CorrectiveAction correctiveAction : feature.getCorrectiveActions()) { + profileOperation.getCorrectiveActionIds().add(correctiveAction.getPolicyId()); + } profileOperations.add(profileOperation); } return profileOperations; diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/resources/sql/CreateMySqlTestDB.sql b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/resources/sql/CreateMySqlTestDB.sql index 51b4a428f5c..3d659d099f2 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/resources/sql/CreateMySqlTestDB.sql +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/resources/sql/CreateMySqlTestDB.sql @@ -77,29 +77,6 @@ CREATE TABLE IF NOT EXISTS `WSO2CDM`.`DM_POLICY` ( ENGINE = InnoDB DEFAULT CHARACTER SET = latin1; --- ----------------------------------------------------- --- Table `WSO2CDM`.`DM_POLICY_CORRECTIVE_ACTION` --- ----------------------------------------------------- -CREATE TABLE IF NOT EXISTS `WSO2CDM`.`DM_POLICY_CORRECTIVE_ACTION` ( - `ID` INT(11) NOT NULL AUTO_INCREMENT, - `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; - -- ----------------------------------------------------- -- Table `WSO2CDM`.`DM_DATE` @@ -227,6 +204,28 @@ CREATE TABLE IF NOT EXISTS `WSO2CDM`.`DM_PROFILE_FEATURES` ( ENGINE = InnoDB DEFAULT CHARACTER SET = latin1; +-- ----------------------------------------------------- +-- Table `WSO2CDM`.`DM_POLICY_CORRECTIVE_ACTION` +-- ----------------------------------------------------- +CREATE TABLE IF NOT EXISTS `WSO2CDM`.`DM_POLICY_CORRECTIVE_ACTION` ( + `ID` INT(11) NOT NULL AUTO_INCREMENT, + `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_FEATURE + FOREIGN KEY (FEATURE_ID) + REFERENCES DM_PROFILE_FEATURES (ID) + ON DELETE NO ACTION + ON UPDATE NO ACTION +)ENGINE = InnoDB +DEFAULT CHARACTER SET = latin1; -- ----------------------------------------------------- -- Table `WSO2CDM`.`DM_ROLE_POLICY` diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/h2.sql b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/h2.sql index 370200ca96e..0a8f646fdff 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/h2.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/h2.sql @@ -194,25 +194,6 @@ CREATE TABLE IF NOT EXISTS DM_POLICY ( ON UPDATE NO ACTION ); -CREATE TABLE IF NOT EXISTS DM_POLICY_CORRECTIVE_ACTION ( - ID INT(11) NOT NULL AUTO_INCREMENT, - 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 -); - CREATE TABLE IF NOT EXISTS DM_DEVICE_POLICY ( ID INT(11) NOT NULL AUTO_INCREMENT , DEVICE_ID INT(11) NOT NULL , @@ -259,6 +240,25 @@ CREATE TABLE IF NOT EXISTS DM_PROFILE_FEATURES ( ON UPDATE NO ACTION ); +CREATE TABLE IF NOT EXISTS DM_POLICY_CORRECTIVE_ACTION ( + ID INT(11) NOT NULL AUTO_INCREMENT, + 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_FEATURE + FOREIGN KEY (FEATURE_ID) + REFERENCES DM_PROFILE_FEATURES (ID) + ON DELETE NO ACTION + ON UPDATE NO ACTION +); + CREATE TABLE IF NOT EXISTS DM_ROLE_POLICY ( ID INT(11) NOT NULL AUTO_INCREMENT , ROLE_NAME VARCHAR(45) NOT NULL , diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/mssql.sql b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/mssql.sql index 1d41602fdd1..3b4f65e50ea 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/mssql.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/mssql.sql @@ -243,26 +243,6 @@ CREATE TABLE DM_POLICY ( ON DELETE NO ACTION ON UPDATE NO ACTION ); -IF NOT EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[DM_POLICY_CORRECTIVE_ACTION]') AND TYPE IN (N'U')) -CREATE TABLE DM_POLICY_CORRECTIVE_ACTION ( - ID INTEGER IDENTITY(1,1) NOT NULL, - 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 -); - IF NOT EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[DM_DEVICE_POLICY]') AND TYPE IN (N'U')) CREATE TABLE DM_DEVICE_POLICY ( ID INTEGER IDENTITY(1,1) NOT NULL, @@ -300,6 +280,26 @@ CREATE TABLE DM_PROFILE_FEATURES ( ON DELETE NO ACTION ON UPDATE NO ACTION ); +IF NOT EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[DM_POLICY_CORRECTIVE_ACTION]') AND TYPE IN (N'U')) +CREATE TABLE DM_POLICY_CORRECTIVE_ACTION ( + ID INTEGER IDENTITY(1,1) NOT NULL, + 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_FEATURE + FOREIGN KEY (FEATURE_ID) + REFERENCES DM_PROFILE_FEATURES (ID) + ON DELETE NO ACTION + ON UPDATE NO ACTION +); + IF NOT EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[DM_ROLE_POLICY]') AND TYPE IN (N'U')) CREATE TABLE DM_ROLE_POLICY ( ID INTEGER IDENTITY(1,1) NOT NULL, diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/mysql.sql b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/mysql.sql index 13bb74c5d8e..0ce1b6353bb 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/mysql.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/mysql.sql @@ -228,25 +228,6 @@ CREATE TABLE IF NOT EXISTS DM_POLICY ( ON UPDATE NO ACTION )ENGINE = InnoDB; -CREATE TABLE IF NOT EXISTS DM_POLICY_CORRECTIVE_ACTION ( - ID INT(11) NOT NULL AUTO_INCREMENT, - 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; - CREATE TABLE IF NOT EXISTS DM_DEVICE_POLICY ( ID INT(11) NOT NULL AUTO_INCREMENT , @@ -296,6 +277,24 @@ CREATE TABLE IF NOT EXISTS DM_PROFILE_FEATURES ( ON UPDATE NO ACTION )ENGINE = InnoDB; +CREATE TABLE IF NOT EXISTS DM_POLICY_CORRECTIVE_ACTION ( + ID INT(11) NOT NULL AUTO_INCREMENT, + 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_FEATURE + FOREIGN KEY (FEATURE_ID) + REFERENCES DM_PROFILE_FEATURES (ID) + ON DELETE NO ACTION + ON UPDATE NO ACTION +)ENGINE = InnoDB; CREATE TABLE IF NOT EXISTS DM_ROLE_POLICY ( ID INT(11) NOT NULL AUTO_INCREMENT , diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/oracle.sql b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/oracle.sql index ffb4892758a..04fd2337138 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/oracle.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/oracle.sql @@ -335,22 +335,6 @@ CREATE TABLE DM_POLICY ( ) / -CREATE TABLE DM_POLICY_CORRECTIVE_ACTION ( - ID NUMBER(10) NOT NULL, - 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), - CONSTRAINT FK_DM_POLICY_DM_POLICY_CORRECTIVE_ACTION - FOREIGN KEY (FEATURE_ID) - REFERENCES DM_PROFILE_FEATURES (ID) -) -/ - -- Generate ID using sequence and trigger CREATE SEQUENCE DM_POLICY_seq START WITH 1 INCREMENT BY 1 NOCACHE / @@ -422,6 +406,22 @@ CREATE TABLE DM_PROFILE_FEATURES ( ) / +CREATE TABLE DM_POLICY_CORRECTIVE_ACTION ( + ID NUMBER(10) NOT NULL, + 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), + CONSTRAINT FK_DM_POLICY_DM_POLICY_CORRECTIVE_ACTION_FEATURE + FOREIGN KEY (FEATURE_ID) + REFERENCES DM_PROFILE_FEATURES (ID) +) +/ + -- Generate ID using sequence and trigger CREATE SEQUENCE DM_PROFILE_FEATURES_seq START WITH 1 INCREMENT BY 1 NOCACHE /