Fix test failures

4.x.x
Pahansith 5 years ago
parent e486db868e
commit 684ff5df7f

@ -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<Integer> 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<Integer> getCorrectiveActionIds() {
return correctiveActionIds;
}
public void setCorrectiveActionIds(List<Integer> correctiveActionIds) {
this.correctiveActionIds = correctiveActionIds;
}
}

@ -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<CorrectiveAction> 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();
}

@ -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,

@ -195,33 +195,70 @@ public class PolicyManagerUtil {
}
private static void setCorrectiveActions(List<ProfileFeature> features,
PolicyOperation policyOperation, Policy policy) throws PolicyTransformException {
List<ProfileFeature> 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<ProfileOperation> 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<ProfileOperation> 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<ProfileOperation> 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<ProfileOperation> profileOperations = createProfileOperations(correctivePolicy
.getProfile().getProfileFeaturesList());
String payload = new Gson().toJson(profileOperations);
correctiveOperationList.setPayLoad(correctivePayload.concat(payload));
}
public static List<ProfileOperation> createProfileOperations(List<ProfileFeature> effectiveFeatures) {
List<ProfileOperation> 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;

@ -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`

@ -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 ,

@ -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,

@ -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 ,

@ -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
/

Loading…
Cancel
Save