diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/PolicyWrapper.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/PolicyWrapper.java index 92e07aeab1..ca15114bac 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/PolicyWrapper.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/PolicyWrapper.java @@ -49,6 +49,12 @@ import java.util.List; + "Wrappers") public class PolicyWrapper { + @ApiModelProperty( + name = "payloadVersion", + value = "Payload version of the Policy") + @Size(max = 45) + private String payloadVersion; + @ApiModelProperty( name = "policyName", value = "The name of the policy", @@ -126,12 +132,18 @@ public class PolicyWrapper { @NotNull private String policyType; - @ApiModelProperty( - name = "correctiveActions", - value = "List of corrective actions to be applied when the policy is violated" - ) + @ApiModelProperty(name = "correctiveActions", + value = "List of corrective actions to be applied when the policy is violated") private List correctiveActions; + public String getPayloadVersion() { + return payloadVersion; + } + + public void setPayloadVersion(String payloadVersion) { + this.payloadVersion = payloadVersion; + } + public String getPolicyType() { return policyType; } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/ProfileFeature.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/ProfileFeature.java index b32c7613f4..3ced3879a0 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/ProfileFeature.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/ProfileFeature.java @@ -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,9 @@ 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") + private List correctiveActions; public int getId() { return id; @@ -109,4 +114,12 @@ public class ProfileFeature implements Serializable { public void setContent(Object content) { this.content = content; } + + public List getCorrectiveActions() { + return correctiveActions; + } + + public void setCorrectiveActions(List correctiveActions) { + this.correctiveActions = correctiveActions; + } } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/PolicyManagementServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/PolicyManagementServiceImpl.java index d58c4ce870..b92fa01e1d 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/PolicyManagementServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/PolicyManagementServiceImpl.java @@ -141,7 +141,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()); @@ -149,6 +148,8 @@ public class PolicyManagementServiceImpl implements PolicyManagementService { policy.setCompliance(policyWrapper.getCompliance()); policy.setDeviceGroups(policyWrapper.getDeviceGroups()); policy.setPolicyType(policyWrapper.getPolicyType()); + policy.setPolicyPayloadVersion(policyWrapper.getPayloadVersion()); + policy.setCorrectiveActions(policyWrapper.getCorrectiveActions()); //TODO iterates the device identifiers to create the object. need to implement a proper DAO layer here. List devices = new ArrayList(); List deviceIdentifiers = policyWrapper.getDeviceIdentifiers(); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/util/DeviceMgtUtil.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/util/DeviceMgtUtil.java index c11fd758c9..31d1b38104 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/util/DeviceMgtUtil.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/util/DeviceMgtUtil.java @@ -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; } 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..dd0a017952 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,16 @@ public class CorrectiveAction implements Serializable { ) private List operations; + @ApiModelProperty( + name = "isReactive", + value = "Declare the action as a reactive action" + ) + private boolean isReactive; + + private Integer featureId; + + private Integer associatedGeneralPolicyId; + public String getActionType() { return actionType; } @@ -78,4 +88,28 @@ public class CorrectiveAction implements Serializable { public void setOperations(List operations) { this.operations = operations; } + + public Integer getFeatureId() { + return featureId; + } + + public void setFeatureId(Integer featureId) { + this.featureId = featureId; + } + + public Integer getAssociatedGeneralPolicyId() { + return associatedGeneralPolicyId; + } + + public void setAssociatedGeneralPolicyId(Integer associatedGeneralPolicyId) { + this.associatedGeneralPolicyId = associatedGeneralPolicyId; + } + + public boolean isReactive() { + return isReactive; + } + + public void setReactive(boolean reactive) { + isReactive = reactive; + } } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/policy/mgt/Policy.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/policy/mgt/Policy.java index 452521286b..6b7dc48738 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/policy/mgt/Policy.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/policy/mgt/Policy.java @@ -53,6 +53,12 @@ public class Policy implements Comparable, Serializable { private static final long serialVersionUID = 19981017L; + @ApiModelProperty( + name = "payloadVersion", + value = "Payload version of the Policy", + example = "1") + private String policyPayloadVersion; + @ApiModelProperty( name = "id", value = "The policy ID", @@ -201,13 +207,19 @@ public class Policy implements Comparable, 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}]" - ) + @ApiModelProperty(name = "correctiveActions", + value = "List of corrective actions to be applied when the policy is violated") private List correctiveActions; + @XmlElement + public String getPolicyPayloadVersion() { + return policyPayloadVersion; + } + + public void setPolicyPayloadVersion(String policyPayloadVersion) { + this.policyPayloadVersion = policyPayloadVersion; + } + @XmlElement public int getId() { return id; @@ -379,13 +391,11 @@ public class Policy implements Comparable, Serializable { this.policyType = policyType; } - @XmlElement public List getCorrectiveActions() { return correctiveActions; } - public void setCorrectiveActions( - List correctiveActions) { + public void setCorrectiveActions(List correctiveActions) { this.correctiveActions = correctiveActions; } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/policy/mgt/ProfileFeature.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/policy/mgt/ProfileFeature.java index 638814b63d..4d0bde90b6 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/policy/mgt/ProfileFeature.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/policy/mgt/ProfileFeature.java @@ -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 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 getCorrectiveActions() { + return correctiveActions; + } + + public void setCorrectiveActions(List correctiveActions) { + this.correctiveActions = correctiveActions; + } } \ No newline at end of file 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 f984fdfb0c..03efcd8ded 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,13 @@ 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; + + private List reactiveActionIds; public Type getType() { return Type.PROFILE; @@ -30,4 +35,19 @@ public class ProfileOperation extends ConfigOperation implements Serializable { return Control.REPEAT; } + public List getCorrectiveActionIds() { + return correctiveActionIds; + } + + public void setCorrectiveActionIds(List correctiveActionIds) { + this.correctiveActionIds = correctiveActionIds; + } + + public List getReactiveActionIds() { + return reactiveActionIds; + } + + public void setReactiveActionIds(List reactiveActionIds) { + this.reactiveActionIds = reactiveActionIds; + } } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/policy.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/policy.js index 8c881ef3df..95bf9c1d22 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/policy.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/policy.js @@ -63,7 +63,10 @@ policyModule = function () { policyObjectToView["name"] = policyObjectFromRestEndpoint["policyName"]; policyObjectToView["platform"] = policyObjectFromRestEndpoint["profile"]["deviceType"]; policyObjectFromRestEndpoint["policyType"] = policyListFromRestEndpoint["policyType"]; - policyObjectFromRestEndpoint["correctiveActions"] = policyListFromRestEndpoint["correctiveActions"]; + var payloadVersion = policyObjectFromRestEndpoint["policyPayloadVersion"]; + if (!parseFloat(payloadVersion) >= 2.0) { + policyObjectFromRestEndpoint["correctiveActions"] = policyListFromRestEndpoint["correctiveActions"]; + } if (policyObjectToView["platform"] == "ios") { policyObjectToView["deviceTypeIcon"] = "apple"; } else { 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..fab22e06d3 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 @@ -2,14 +2,13 @@ {{#if isAuthorized}}
-
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..8c5bf96dd9 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"], 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}}">