From 2724d8ac0353d5af52e7e4fe2fa21b63e7961466 Mon Sep 17 00:00:00 2001 From: Pahansith Date: Thu, 26 Mar 2020 18:20:24 +0530 Subject: [PATCH] Optimize policy pick strategy for corrective action implementation --- .../common/policy/mgt/CorrectiveAction.java | 10 ++ .../core/operation/mgt/ProfileOperation.java | 2 +- .../units/cdmf.unit.policy.create/create.hbs | 54 +----- .../public/js/policy-create.js | 48 +---- .../app/units/cdmf.unit.policy.edit/edit.hbs | 69 +------- .../app/units/cdmf.unit.policy.edit/edit.js | 13 -- .../public/js/policy-edit.js | 65 +------ .../cdmf.unit.policy.view/public/js/view.js | 24 --- .../app/units/cdmf.unit.policy.view/view.hbs | 36 +--- .../app/units/cdmf.unit.policy.view/view.js | 2 +- .../carbon/policy/mgt/core/dao/PolicyDAO.java | 2 +- .../mgt/core/dao/impl/PolicyDAOImpl.java | 9 +- .../mgt/core/mgt/impl/PolicyManagerImpl.java | 30 +++- .../core/util/PolicyManagementConstants.java | 4 +- .../mgt/core/util/PolicyManagerUtil.java | 167 +++++------------- 15 files changed, 97 insertions(+), 438 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/policy/mgt/CorrectiveAction.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/policy/mgt/CorrectiveAction.java index dece7db618..6ebe74e17c 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/policy/mgt/CorrectiveAction.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/policy/mgt/CorrectiveAction.java @@ -55,6 +55,8 @@ public class CorrectiveAction implements Serializable { ) private List operations; + private int featureId; + public String getActionType() { return actionType; } @@ -78,4 +80,12 @@ public class CorrectiveAction implements Serializable { public void setOperations(List operations) { this.operations = operations; } + + public int getFeatureId() { + return featureId; + } + + public void setFeatureId(int featureId) { + this.featureId = featureId; + } } 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 b89233f967..21d41f3aed 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 @@ -23,7 +23,7 @@ import java.util.ArrayList; import java.util.List; public class ProfileOperation extends ConfigOperation implements Serializable { - private List correctiveActionIds = new ArrayList<>(); + private List correctiveActionIds; public Type getType() { return Type.PROFILE; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.policy.create/create.hbs b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.policy.create/create.hbs index c67f099c5b..54e89548f5 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.policy.create/create.hbs +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.policy.create/create.hbs @@ -9,7 +9,7 @@
- diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.policy.create/public/js/policy-create.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.policy.create/public/js/policy-create.js index e4adef0e38..f3cc76c3c7 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.policy.create/public/js/policy-create.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.policy.create/public/js/policy-create.js @@ -222,28 +222,6 @@ stepForwardFrom["policy-profile"] = function () { policy["profile"] = generatePolicyProfile(); } - // add policy correction action page - var policyCorrectiveActionTemplateSrc = - "/public/cdmf.unit.policy.corrective-action/templates/policy-corrective-action.hbs"; - var policyCorrectiveActionScriptSrc = - "/public/cdmf.unit.policy.corrective-action/js/policy-corrective-action.js"; - var policyCorrectiveActionTemplateCacheKey = "policy-corrective-action"; - - $.template(policyCorrectiveActionTemplateCacheKey, context + policyCorrectiveActionTemplateSrc, - function (template) { - var content = template( - { - "deviceType": policy["platform"], - "correctivePolicies": $("#logged-in-user").data("corrective-policies") - } - ); - $("#select-general-policy-type").html(content); - var script = document.createElement('script'); - script.type = 'text/javascript'; - script.src = context + policyCorrectiveActionScriptSrc; - document.head.append(script); - }); - // updating next-page wizard title with selected platform $("#policy-type-page-wizard-title").text("ADD " + policy["platform"] + " POLICY"); }; @@ -261,28 +239,6 @@ stepBackFrom["policy-profile"] = function () { } }; - -/** - * Forward action of policy type page. - */ -stepForwardFrom["policy-type"] = function () { - policy["type"] = $("input[name=policy-type-radio-btn]:checked").val(); - var correctiveActionList = []; - if (policy.type === "GENERAL") { - var selectedCorrectivePolicyId = $("#corrective-policy-input").val(); - if (selectedCorrectivePolicyId && selectedCorrectivePolicyId !== "none") { - var correctiveAction = { - "actionType": "POLICY", - "policyId": selectedCorrectivePolicyId - }; - correctiveActionList.push(correctiveAction); - } - } - policy["correctiveActionList"] = correctiveActionList; - //updating next-page wizard title with selected platform - $("#policy-criteria-page-wizard-title").text("ADD " + policy["platform"] + " POLICY"); -}; - /** * Forward action of policy criteria page. */ @@ -483,8 +439,7 @@ var savePolicy = function (policy, isActive, serviceURL) { "compliance": policy["selectedNonCompliantAction"], "ownershipType": null, "active": isActive, - "policyType": policy["type"], - "correctiveActions": policy["correctiveActionList"], + "policyType": "GENERAL", "profile": { "profileName": policy["policyName"], "deviceType": policy["platform"], @@ -639,6 +594,7 @@ $(document).ready(function () { } }); + //todo $('input[type=radio][name=policy-type-radio-btn]').change(function() { if ($(this).val() === "CORRECTIVE") { $("#select-general-policy-type").addClass("hidden"); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.policy.edit/edit.hbs b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.policy.edit/edit.hbs index f471497415..672fc524f3 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.policy.edit/edit.hbs +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.policy.edit/edit.hbs @@ -1,38 +1,30 @@ {{#zone "content"}} {{#if isAuthorized }} + data-tenant-id="{{@user.tenantId}}" data-iscloud="{{isCloud}}" data-storeapps="{{storeApps}}">