mirror of
https://repository.entgra.net/community/device-mgt-core.git
synced 2025-10-06 02:01:45 +00:00
Merge branch 'corrective-action' into 'corrective-policy'
Update corrective action See merge request entgra/carbon-device-mgt!634
This commit is contained in:
commit
49a83a2995
@ -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<CorrectiveAction> correctiveActions;
|
||||
|
||||
public String getPayloadVersion() {
|
||||
return payloadVersion;
|
||||
}
|
||||
|
||||
public void setPayloadVersion(String payloadVersion) {
|
||||
this.payloadVersion = payloadVersion;
|
||||
}
|
||||
|
||||
public String getPolicyType() {
|
||||
return policyType;
|
||||
}
|
||||
|
||||
@ -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<CorrectiveAction> 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<CorrectiveAction> getCorrectiveActions() {
|
||||
return correctiveActions;
|
||||
}
|
||||
|
||||
public void setCorrectiveActions(List<CorrectiveAction> correctiveActions) {
|
||||
this.correctiveActions = correctiveActions;
|
||||
}
|
||||
}
|
||||
|
||||
@ -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<Device> devices = new ArrayList<Device>();
|
||||
List<DeviceIdentifier> deviceIdentifiers = policyWrapper.getDeviceIdentifiers();
|
||||
|
||||
@ -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;
|
||||
|
||||
}
|
||||
|
||||
@ -55,6 +55,16 @@ public class CorrectiveAction implements Serializable {
|
||||
)
|
||||
private List<ProfileFeature> 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<ProfileFeature> 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;
|
||||
}
|
||||
}
|
||||
|
||||
@ -53,6 +53,12 @@ public class Policy implements Comparable<Policy>, 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<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}]"
|
||||
)
|
||||
@ApiModelProperty(name = "correctiveActions",
|
||||
value = "List of corrective actions to be applied when the policy is violated")
|
||||
private List<CorrectiveAction> 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<Policy>, Serializable {
|
||||
this.policyType = policyType;
|
||||
}
|
||||
|
||||
@XmlElement
|
||||
public List<CorrectiveAction> getCorrectiveActions() {
|
||||
return correctiveActions;
|
||||
}
|
||||
|
||||
public void setCorrectiveActions(
|
||||
List<CorrectiveAction> correctiveActions) {
|
||||
public void setCorrectiveActions(List<CorrectiveAction> correctiveActions) {
|
||||
this.correctiveActions = correctiveActions;
|
||||
}
|
||||
|
||||
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
@ -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<Integer> correctiveActionIds;
|
||||
|
||||
private List<Integer> reactiveActionIds;
|
||||
|
||||
public Type getType() {
|
||||
return Type.PROFILE;
|
||||
@ -30,4 +35,19 @@ 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;
|
||||
}
|
||||
|
||||
public List<Integer> getReactiveActionIds() {
|
||||
return reactiveActionIds;
|
||||
}
|
||||
|
||||
public void setReactiveActionIds(List<Integer> reactiveActionIds) {
|
||||
this.reactiveActionIds = reactiveActionIds;
|
||||
}
|
||||
}
|
||||
|
||||
@ -63,7 +63,10 @@ policyModule = function () {
|
||||
policyObjectToView["name"] = policyObjectFromRestEndpoint["policyName"];
|
||||
policyObjectToView["platform"] = policyObjectFromRestEndpoint["profile"]["deviceType"];
|
||||
policyObjectFromRestEndpoint["policyType"] = policyListFromRestEndpoint["policyType"];
|
||||
var payloadVersion = policyObjectFromRestEndpoint["policyPayloadVersion"];
|
||||
if (!parseFloat(payloadVersion) >= 2.0) {
|
||||
policyObjectFromRestEndpoint["correctiveActions"] = policyListFromRestEndpoint["correctiveActions"];
|
||||
}
|
||||
if (policyObjectToView["platform"] == "ios") {
|
||||
policyObjectToView["deviceTypeIcon"] = "apple";
|
||||
} else {
|
||||
|
||||
@ -2,14 +2,13 @@
|
||||
{{#if isAuthorized}}
|
||||
<span id="logged-in-user" class="hidden" data-username="{{@user.username}}" data-domain="{{@user.domain}}"
|
||||
data-tenant-id="{{@user.tenantId}}" data-iscloud="{{isCloud}}"
|
||||
data-isDeviceOwnerEnabled="{{isDeviceOwnerEnabled}}" data-storeapps="{{storeApps}}"
|
||||
data-corrective-policies="{{correctivePolicies}}">
|
||||
data-isDeviceOwnerEnabled="{{isDeviceOwnerEnabled}}" data-storeapps="{{storeApps}}">
|
||||
</span>
|
||||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
|
||||
<div class="wr-steps hidden">
|
||||
<div class="col-md-2 col-xs-2 col-md-offset-1">
|
||||
<div class="col-md-2 col-xs-2 col-md-offset-2">
|
||||
<div class="itm-wiz itm-wiz-current" data-step="policy-platform">
|
||||
<div class="wiz-no">1</div>
|
||||
<div class="wiz-lbl hidden-xs"><span>Select a platform</span></div>
|
||||
@ -23,16 +22,9 @@
|
||||
</div>
|
||||
<br class="c-both"/>
|
||||
</div>
|
||||
<div class="col-md-2 col-xs-2">
|
||||
<div class="itm-wiz" data-step="policy-type">
|
||||
<div class="wiz-no">3</div>
|
||||
<div class="wiz-lbl hidden-xs"><span>Select policy type</span></div>
|
||||
</div>
|
||||
<br class="c-both"/>
|
||||
</div>
|
||||
<div class="col-md-2 col-xs-2">
|
||||
<div class="itm-wiz" data-step="policy-criteria">
|
||||
<div class="wiz-no">4</div>
|
||||
<div class="wiz-no">3</div>
|
||||
<div class="wiz-lbl hidden-xs"><span>Assign to groups</span></div>
|
||||
</div>
|
||||
<br class="c-both"/>
|
||||
@ -209,7 +201,7 @@
|
||||
</div>
|
||||
<div class="wr-input-control wr-btn-grp">
|
||||
<a href="javascript:void(0)" class="wr-btn wizard-stepper" data-is-back-btn="true"
|
||||
data-current="policy-criteria" data-next="policy-type">Back</a>
|
||||
data-current="policy-criteria" data-next="policy-profile">Back</a>
|
||||
<a href="javascript:void(0)" class="wr-btn wizard-stepper"
|
||||
data-current="policy-criteria" data-next="policy-naming" data-validate="true">Continue</a>
|
||||
</div>
|
||||
@ -217,45 +209,6 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-centered wr-content policy-type hidden">
|
||||
<div class="wr-form">
|
||||
<h1 id="policy-type-page-wizard-title" class="page-sub-title">ADD POLICY</h1>
|
||||
<hr>
|
||||
<div id="policy-type-wizard-steps" class="row wr-wizard"></div>
|
||||
<hr>
|
||||
<div class="row">
|
||||
<div class="col-lg-12">
|
||||
<h4 class="hidden-xs"> Step 3: Select policy type</h4>
|
||||
<br>
|
||||
<div id="policy-type-main-error-msg" class="alert alert-danger hidden" role="alert">
|
||||
<i class="icon fw fw-error"></i><span></span>
|
||||
</div>
|
||||
<div>
|
||||
<div class="wr-input-control">
|
||||
<label class="wr-input-control radio light">
|
||||
<input type="radio" id="policy-type-general" name="policy-type-radio-btn"
|
||||
value="GENERAL" checked/>
|
||||
<span class="helper">General Policy</span>
|
||||
</label>
|
||||
<label class="wr-input-control radio light">
|
||||
<input type="radio" id="policy-type-corrective" name="policy-type-radio-btn"
|
||||
value="CORRECTIVE"/>
|
||||
<span class="helper">Corrective Policy</span>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
<div id="select-general-policy-type"></div>
|
||||
<div class="wr-input-control wr-btn-grp">
|
||||
<a href="javascript:void(0)" class="wr-btn wizard-stepper" data-is-back-btn="true"
|
||||
data-current="policy-type" data-next="policy-profile">Back</a>
|
||||
<a href="javascript:void(0)" class="wr-btn wizard-stepper"
|
||||
data-current="policy-type"
|
||||
data-next="policy-criteria" data-validate="false">Continue</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-centered wr-content policy-profile hidden">
|
||||
<div class="wr-form">
|
||||
<h1 id="policy-profile-page-wizard-title" class="page-sub-title">ADD POLICY</h1>
|
||||
@ -288,7 +241,7 @@
|
||||
data-current="policy-profile" data-next="policy-platform">Back</a>
|
||||
<a href="javascript:void(0)" class="wr-btn wizard-stepper"
|
||||
data-current="policy-profile"
|
||||
data-next="policy-type" data-validate="true">Continue</a>
|
||||
data-next="policy-criteria" data-validate="true">Continue</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@ -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"],
|
||||
|
||||
@ -1,38 +1,30 @@
|
||||
{{#zone "content"}}
|
||||
{{#if isAuthorized }}
|
||||
<span id="logged-in-user" class="hidden" data-username="{{@user.username}}" data-domain="{{@user.domain}}"
|
||||
data-tenant-id="{{@user.tenantId}}" data-iscloud="{{isCloud}}" data-storeapps="{{storeApps}}"
|
||||
data-corrective-policies="{{correctivePolicies}}"></span>
|
||||
data-tenant-id="{{@user.tenantId}}" data-iscloud="{{isCloud}}" data-storeapps="{{storeApps}}"></span>
|
||||
<span id="policy-operations" class="hidden" data-template="{{policyOperations.template}}"
|
||||
data-script="{{policyOperations.script}}" data-style="{{policyOperations.style}}"></span>
|
||||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
|
||||
<div class="wr-steps hidden">
|
||||
<div class="col-md-3 col-xs-3">
|
||||
<div class="col-md-3 col-xs-3 col-md-offset-2">
|
||||
<div class="itm-wiz itm-wiz-current" data-step="policy-profile">
|
||||
<div class="wiz-no">1</div>
|
||||
<div class="wiz-lbl hidden-xs"><span>Edit current profile</span></div>
|
||||
</div>
|
||||
<br class="c-both"/>
|
||||
</div>
|
||||
<div class="col-md-3 col-xs-3">
|
||||
<div class="itm-wiz itm-wiz" data-step="policy-type">
|
||||
<div class="wiz-no">2</div>
|
||||
<div class="wiz-lbl hidden-xs"><span>Edit policy type</span></div>
|
||||
</div>
|
||||
<br class="c-both"/>
|
||||
</div>
|
||||
<div class="col-md-3 col-xs-3">
|
||||
<div class="itm-wiz" data-step="policy-criteria">
|
||||
<div class="wiz-no">3</div>
|
||||
<div class="wiz-no">2</div>
|
||||
<div class="wiz-lbl hidden-xs"><span>Edit assignment groups</span></div>
|
||||
</div>
|
||||
<br class="c-both"/>
|
||||
</div>
|
||||
<div class="col-md-3 col-xs-3">
|
||||
<div class="itm-wiz" data-step="policy-naming">
|
||||
<div class="wiz-no">4</div>
|
||||
<div class="wiz-no">3</div>
|
||||
<div class="wiz-lbl hidden-xs"><span>Republish to devices</span></div>
|
||||
</div>
|
||||
<br class="c-both"/>
|
||||
@ -56,7 +48,7 @@
|
||||
<hr>
|
||||
<div class="row">
|
||||
<div class="col-lg-12">
|
||||
<h4 class="visible-xs">Step 4: Republish to devices</h4>
|
||||
<h4 class="visible-xs">Step 3: Republish to devices</h4>
|
||||
<br>
|
||||
<div id="policy-naming-main-error-msg" class="alert alert-danger hidden" role="alert">
|
||||
<i class="icon fw fw-error"></i><span></span>
|
||||
@ -204,7 +196,7 @@
|
||||
</div>
|
||||
<div class="wr-input-control wr-btn-grp">
|
||||
<a href="#" class="wr-btn wizard-stepper" data-is-back-btn="true"
|
||||
data-current="policy-criteria" data-next="policy-type">
|
||||
data-current="policy-criteria" data-next="policy-profile">
|
||||
Back
|
||||
</a>
|
||||
<a href="#" class="wr-btn wizard-stepper" data-current="policy-criteria"
|
||||
@ -217,53 +209,6 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="col-centered wr-content policy-type hidden">
|
||||
<div class="wr-form">
|
||||
<h1 id="policy-type-page-wizard-title" class="page-sub-title">EDIT POLICY</h1>
|
||||
<hr>
|
||||
<div id="policy-type-wizard-steps" class="row wr-wizard"></div>
|
||||
<hr>
|
||||
<div class="row">
|
||||
<div class="col-lg-12">
|
||||
<h4 class="visible-xs"> Step 2: Select policy type</h4>
|
||||
<br>
|
||||
<div id="policy-type-main-error-msg" class="alert alert-danger hidden" role="alert">
|
||||
<i class="icon fw fw-error"></i><span></span>
|
||||
</div>
|
||||
<div>
|
||||
<div class="wr-input-control">
|
||||
<label class="wr-input-control radio light">
|
||||
<input type="radio" id="policy-type-general" name="policy-type-radio-btn"
|
||||
value="GENERAL"/>
|
||||
<span class="helper">General Policy</span>
|
||||
</label>
|
||||
<label class="wr-input-control radio light">
|
||||
<input type="radio" id="policy-type-corrective" name="policy-type-radio-btn"
|
||||
value="CORRECTIVE"/>
|
||||
<span class="helper">Corrective Policy</span>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
<div class='policy-type-loading-corrective-actions'>
|
||||
<br/>
|
||||
<i class='fw fw-settings fw-spin fw-2x'></i>
|
||||
Loading corrective actions . . .
|
||||
<br/>
|
||||
<br/>
|
||||
</div>
|
||||
<div id="select-general-policy-type"></div>
|
||||
<div class="wr-input-control wr-btn-grp">
|
||||
<a href="#" class="wr-btn wizard-stepper" data-is-back-btn="true"
|
||||
data-current="policy-type" data-next="policy-profile">Back</a>
|
||||
<a href="#" class="wr-btn wizard-stepper"
|
||||
data-current="policy-type"
|
||||
data-next="policy-criteria" data-validate="false">Continue</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="col-centered wr-content policy-profile">
|
||||
<div class="wr-form">
|
||||
<h1 id="policy-profile-page-wizard-title" class="page-sub-title">EDIT POLICY</h1>
|
||||
@ -293,7 +238,7 @@
|
||||
</div>
|
||||
<div class="wr-input-control wr-btn-grp">
|
||||
<a href="#" class="wr-btn wizard-stepper" data-current="policy-profile"
|
||||
data-next="policy-type" data-validate="true">
|
||||
data-next="policy-criteria" data-validate="true">
|
||||
Continue
|
||||
</a>
|
||||
</div>
|
||||
|
||||
@ -85,18 +85,5 @@ function onRequest(context) {
|
||||
var enrollmentApps = policyModule.getStoreAppsForPolicy();
|
||||
context["storeApps"] = JSON.stringify(enrollmentApps["content"]);
|
||||
|
||||
var correctivePolicies = policyModule.getAllPoliciesByType("CORRECTIVE")["content"];
|
||||
if (correctivePolicies) {
|
||||
var i;
|
||||
for (i = 0; i < correctivePolicies.length; i++) {
|
||||
if (correctivePolicies[i].id.toString() === policyId) {
|
||||
correctivePolicies.splice(i, 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
context["correctivePolicies"] = JSON.stringify(correctivePolicies);
|
||||
|
||||
return context;
|
||||
}
|
||||
@ -161,7 +161,6 @@ skipStep["policy-platform"] = function (policyPayloadObj) {
|
||||
currentlyEffected["users"] = policyPayloadObj.users;
|
||||
currentlyEffected["groups"] = [];
|
||||
currentlyEffected["policyType"] = policyPayloadObj.policyType;
|
||||
currentlyEffected["correctiveActions"] = policyPayloadObj.correctiveActions;
|
||||
|
||||
if (policyPayloadObj.deviceGroups) {
|
||||
var deviceGroups = policyPayloadObj.deviceGroups;
|
||||
@ -280,72 +279,10 @@ stepForwardFrom["policy-profile"] = function () {
|
||||
policy["profile"] = generatePolicyProfile();
|
||||
}
|
||||
|
||||
var policyType = currentlyEffected.policyType;
|
||||
$("input[name=policy-type-radio-btn][value=" + policyType + "]").prop("checked", true).trigger('change');
|
||||
|
||||
// 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);
|
||||
if ("GENERAL" === policyType && currentlyEffected.correctiveActions &&
|
||||
currentlyEffected.correctiveActions.length > 0) {
|
||||
currentlyEffected.correctiveActions.forEach(function (correctiveAction) {
|
||||
if ("POLICY" === correctiveAction.actionType) {
|
||||
if ($("#corrective-policy-input option[value=" + correctiveAction.policyId + "]").length > 0) {
|
||||
$("#corrective-policy-input").val(correctiveAction.policyId);
|
||||
} else {
|
||||
$("#corrective-action-policy-id-missing-msg").removeClass("hidden");
|
||||
}
|
||||
// returned from for each since currently only supported corrective action type is
|
||||
// POLICY.
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}
|
||||
var script = document.createElement('script');
|
||||
script.type = 'text/javascript';
|
||||
script.src = context + policyCorrectiveActionScriptSrc;
|
||||
document.head.prepend(script);
|
||||
});
|
||||
|
||||
$(".policy-type-loading-corrective-actions").addClass("hidden");
|
||||
|
||||
// updating next-page wizard title with selected platform
|
||||
$("#policy-type-page-wizard-title").text("EDIT " + policy["platform"] + " POLICY - " + policy["name"]);
|
||||
};
|
||||
|
||||
/**
|
||||
* 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("EDIT " + policy["platform"] + " POLICY - " + policy["name"]);
|
||||
};
|
||||
|
||||
/**
|
||||
* Forward action of policy criteria page.
|
||||
@ -556,8 +493,7 @@ var updatePolicy = function (policy, state) {
|
||||
"description": policy["description"],
|
||||
"compliance": policy["selectedNonCompliantAction"],
|
||||
"ownershipType": null,
|
||||
"policyType": policy["type"],
|
||||
"correctiveActions": policy["correctiveActionList"],
|
||||
"policyType": "GENERAL",
|
||||
"profile": {
|
||||
"profileName": policy["policyName"],
|
||||
"deviceType": policy["platform"],
|
||||
|
||||
@ -69,30 +69,6 @@ var displayPolicy = function (policyPayloadObj) {
|
||||
$("#policy-roles").text(policyPayloadObj.roles.toString().split(",").join(", "));
|
||||
}
|
||||
|
||||
if ("GENERAL" === policyPayloadObj.policyType &&
|
||||
policyPayloadObj.correctiveActions && policyPayloadObj.correctiveActions.length > 0) {
|
||||
policyPayloadObj.correctiveActions.forEach(function (correctiveAction) {
|
||||
if ("POLICY" === correctiveAction.actionType) {
|
||||
$("#corrective-action-type-policy-id").html(correctiveAction.policyId);
|
||||
var correctivePolicies = $("#logged-in-user").data("corrective-policies");
|
||||
if (correctivePolicies) {
|
||||
var i;
|
||||
for (i = 0; i < correctivePolicies.length; i++) {
|
||||
if (correctiveAction.policyId === correctivePolicies[i].id) {
|
||||
$("#corrective-action-policy-id-missing-msg").addClass("hidden");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
});
|
||||
$("#policy-corrective-actions-list").removeClass("hidden");
|
||||
} else {
|
||||
$("#policy-corrective-actions-list").addClass("hidden");
|
||||
}
|
||||
|
||||
|
||||
var policyId = policyPayloadObj["id"];
|
||||
var deviceType = policy["platform"];
|
||||
var policyOperations = $("#policy-operations");
|
||||
|
||||
@ -1,8 +1,7 @@
|
||||
{{#zone "content"}}
|
||||
{{#if isAuthorized}}
|
||||
<span id="logged-in-user" class="hidden" data-username="{{@user.username}}" data-domain="{{@user.domain}}"
|
||||
data-tenant-id="{{@user.tenantId}}" data-iscloud="{{isCloud}}"
|
||||
data-corrective-policies="{{correctivePolicies}}"></span>
|
||||
data-tenant-id="{{@user.tenantId}}" data-iscloud="{{isCloud}}"></span>
|
||||
{{#defineZone "policy-profile-top"}}
|
||||
<div class="row wr-device-board">
|
||||
<div class="col-lg-12 wr-secondary-bar">
|
||||
@ -47,42 +46,9 @@
|
||||
<td class="sorting_1" style="padding:10px 15px;">Assigned Roles</td>
|
||||
<td id="policy-roles" style="padding:10px 15px;"></td>
|
||||
</tr>
|
||||
<tr role="row" id="roles-row" class="even">
|
||||
<td class="sorting_1" style="padding:10px 15px;">Policy Type</td>
|
||||
<td id="policy-type" style="padding:10px 15px;"></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
{{/defineZone}}
|
||||
<div id="policy-corrective-actions-list" class="hidden">
|
||||
<div style="background: #008cc4; color: #fff; padding: 10px; margin-bottom: 5px">
|
||||
Corrective Actions
|
||||
</div>
|
||||
<div class="add-margin-top-4x">
|
||||
<div id="policy-corrective-actions">
|
||||
<table class="table table-responsive table-striped">
|
||||
<tbody>
|
||||
<tr role="row">
|
||||
<td class="sorting_1" style="padding:10px 15px; width: 14%;">Action Type</td>
|
||||
<td style="padding:10px 15px;">POLICY</td>
|
||||
<td class="sorting_1" style="padding:10px 15px; width: 14%;">Policy ID</td>
|
||||
<td id="corrective-action-type-policy-id" style="padding:10px 15px;"></td>
|
||||
</tr>
|
||||
<tr id="corrective-action-policy-id-missing-msg">
|
||||
<td class="alert alert-danger" colspan="4" style="padding:10px 15px;">
|
||||
<strong>
|
||||
<i class="icon fw fw-error"></i>
|
||||
Corrective policy having the above Policy ID has been updated to
|
||||
a GENERAL policy or it has been deleted. Hence this policy will
|
||||
not be applied till modified correctly.
|
||||
</strong>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div style="background: #008cc4; color: #fff; padding: 10px; margin-bottom: 5px">Description
|
||||
</div>
|
||||
<div class="add-margin-top-4x">
|
||||
|
||||
@ -45,7 +45,5 @@ function onRequest(context) {
|
||||
var devicemgtProps = require("/app/modules/conf-reader/main.js")["conf"];
|
||||
page["isCloud"] = devicemgtProps.isCloud;
|
||||
|
||||
page["correctivePolicies"] = JSON.stringify(policyModule.getAllPoliciesByType("CORRECTIVE")["content"]);
|
||||
|
||||
return page;
|
||||
}
|
||||
@ -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;
|
||||
|
||||
/**
|
||||
@ -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,9 +105,16 @@ 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;
|
||||
|
||||
/**
|
||||
* This method is used get all corrective actions from DB
|
||||
* @throws PolicyManagerDAOException is thrown when there is an error in deleting corrective actions to database
|
||||
*/
|
||||
List<CorrectiveAction> getAllCorrectiveActions() throws PolicyManagerDAOException;
|
||||
|
||||
Policy updateUserOfPolicy(List<String> usersToAdd, Policy policy) throws PolicyManagerDAOException;
|
||||
|
||||
Policy addPolicyToDevice(List<Device> devices, Policy policy) throws PolicyManagerDAOException;
|
||||
|
||||
@ -40,10 +40,10 @@ import org.apache.commons.logging.LogFactory;
|
||||
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
||||
import org.wso2.carbon.device.mgt.common.Device;
|
||||
import org.wso2.carbon.device.mgt.common.policy.mgt.CorrectiveAction;
|
||||
import org.wso2.carbon.policy.mgt.common.Criterion;
|
||||
import org.wso2.carbon.device.mgt.common.policy.mgt.DeviceGroupWrapper;
|
||||
import org.wso2.carbon.device.mgt.common.policy.mgt.Policy;
|
||||
import org.wso2.carbon.device.mgt.common.policy.mgt.PolicyCriterion;
|
||||
import org.wso2.carbon.policy.mgt.common.Criterion;
|
||||
import org.wso2.carbon.policy.mgt.core.dao.PolicyDAO;
|
||||
import org.wso2.carbon.policy.mgt.core.dao.PolicyManagementDAOFactory;
|
||||
import org.wso2.carbon.policy.mgt.core.dao.PolicyManagerDAOException;
|
||||
@ -54,8 +54,17 @@ import org.wso2.carbon.policy.mgt.core.util.SetReferenceTransformer;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.sql.*;
|
||||
import java.util.*;
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Timestamp;
|
||||
import java.sql.Types;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
|
||||
public class PolicyDAOImpl implements PolicyDAO {
|
||||
|
||||
@ -263,19 +272,26 @@ 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, IS_REACTIVE) 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);
|
||||
if (featureId == -1) {
|
||||
insertStmt.setNull(4, Types.INTEGER);
|
||||
} else {
|
||||
insertStmt.setInt(4, featureId);
|
||||
}
|
||||
insertStmt.setBoolean(5, correctiveAction.isReactive());
|
||||
insertStmt.addBatch();
|
||||
}
|
||||
insertStmt.executeBatch();
|
||||
@ -291,24 +307,12 @@ public class PolicyDAOImpl implements PolicyDAO {
|
||||
public List<CorrectiveAction> getCorrectiveActionsOfPolicy(int policyId) throws PolicyManagerDAOException {
|
||||
try {
|
||||
Connection conn = this.getConnection();
|
||||
String query = "SELECT " +
|
||||
"ACTION_TYPE, " +
|
||||
"CORRECTIVE_POLICY_ID " +
|
||||
String query = "SELECT ACTION_TYPE, CORRECTIVE_POLICY_ID, FEATURE_ID, POLICY_ID, IS_REACTIVE " +
|
||||
"FROM DM_POLICY_CORRECTIVE_ACTION " +
|
||||
"WHERE POLICY_ID = ?";
|
||||
try (PreparedStatement selectStmt = conn.prepareStatement(query)) {
|
||||
List<CorrectiveAction> correctiveActions = new ArrayList<>();
|
||||
selectStmt.setInt(1, policyId);
|
||||
try (ResultSet rs = selectStmt.executeQuery()) {
|
||||
CorrectiveAction correctiveAction;
|
||||
while (rs.next()) {
|
||||
correctiveAction = new CorrectiveAction();
|
||||
correctiveAction.setActionType(rs.getString("ACTION_TYPE"));
|
||||
correctiveAction.setPolicyId(rs.getInt("CORRECTIVE_POLICY_ID"));
|
||||
correctiveActions.add(correctiveAction);
|
||||
}
|
||||
}
|
||||
return correctiveActions;
|
||||
return extractCorrectivePolicies(selectStmt);
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error occurred while retrieving corrective actions of policy ID " + policyId;
|
||||
@ -318,7 +322,48 @@ public class PolicyDAOImpl implements PolicyDAO {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateCorrectiveActionsOfPolicy(List<CorrectiveAction> correctiveActions, int policyId)
|
||||
public List<CorrectiveAction> getAllCorrectiveActions() throws PolicyManagerDAOException {
|
||||
try {
|
||||
Connection conn = this.getConnection();
|
||||
String query = "SELECT ACTION_TYPE, CORRECTIVE_POLICY_ID, FEATURE_ID, POLICY_ID, IS_REACTIVE " +
|
||||
"FROM DM_POLICY_CORRECTIVE_ACTION ";
|
||||
try (PreparedStatement stmt = conn.prepareStatement(query)) {
|
||||
List<CorrectiveAction> correctiveActions = new ArrayList<>();
|
||||
return extractCorrectivePolicies(stmt);
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error occurred while retrieving all corrective actions";
|
||||
log.error(msg, e);
|
||||
throw new PolicyManagerDAOException(msg, e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract corrective policies from DB query result
|
||||
* @param stmt DB Query statement
|
||||
* @return List of corrective actions queries
|
||||
* @throws SQLException when a DB related issue occurs
|
||||
*/
|
||||
private List<CorrectiveAction> extractCorrectivePolicies(PreparedStatement stmt) throws SQLException {
|
||||
List<CorrectiveAction> correctiveActions = new ArrayList<>();
|
||||
try (ResultSet rs = stmt.executeQuery()) {
|
||||
CorrectiveAction correctiveAction;
|
||||
while (rs.next()) {
|
||||
correctiveAction = new CorrectiveAction();
|
||||
correctiveAction.setActionType(rs.getString("ACTION_TYPE"));
|
||||
correctiveAction.setPolicyId(rs.getInt("CORRECTIVE_POLICY_ID"));
|
||||
correctiveAction.setFeatureId(rs.getInt("FEATURE_ID"));
|
||||
correctiveAction.setAssociatedGeneralPolicyId(rs.getInt("POLICY_ID"));
|
||||
correctiveAction.setReactive(rs.getBoolean("IS_REACTIVE"));
|
||||
correctiveActions.add(correctiveAction);
|
||||
}
|
||||
}
|
||||
return correctiveActions;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateCorrectiveActionsOfPolicy(List<CorrectiveAction> correctiveActions,
|
||||
int policyId, int featureId)
|
||||
throws PolicyManagerDAOException {
|
||||
try {
|
||||
Connection conn = this.getConnection();
|
||||
@ -326,11 +371,17 @@ public class PolicyDAOImpl implements PolicyDAO {
|
||||
"SET CORRECTIVE_POLICY_ID = ? " +
|
||||
"WHERE ACTION_TYPE = ? " +
|
||||
"AND POLICY_ID = ? ";
|
||||
if (featureId != -1) {
|
||||
query = query.concat("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);
|
||||
if (featureId != -1) {
|
||||
updateStmt.setInt(4, featureId);
|
||||
}
|
||||
updateStmt.addBatch();
|
||||
}
|
||||
updateStmt.executeBatch();
|
||||
@ -343,17 +394,24 @@ 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 = ? ";
|
||||
if (featureId != -1) {
|
||||
query = query.concat("AND FEATURE_ID = ?");
|
||||
}
|
||||
try (PreparedStatement deleteStmt = conn.prepareStatement(query)) {
|
||||
for (CorrectiveAction correctiveAction : correctiveActions) {
|
||||
deleteStmt.setString(1, correctiveAction.getActionType());
|
||||
deleteStmt.setInt(2, policyId);
|
||||
if (featureId != -1) {
|
||||
deleteStmt.setInt(3, featureId);
|
||||
}
|
||||
deleteStmt.addBatch();
|
||||
}
|
||||
deleteStmt.executeBatch();
|
||||
@ -921,7 +979,8 @@ public class PolicyDAOImpl implements PolicyDAO {
|
||||
try {
|
||||
conn = this.getConnection();
|
||||
String query = "UPDATE DM_POLICY SET NAME = ?, PROFILE_ID = ?, PRIORITY = ?, COMPLIANCE = ?," +
|
||||
" UPDATED = ?, DESCRIPTION = ?, OWNERSHIP_TYPE = ?, POLICY_TYPE = ? WHERE ID = ? AND TENANT_ID = ?";
|
||||
" UPDATED = ?, DESCRIPTION = ?, OWNERSHIP_TYPE = ?, POLICY_TYPE = ?, " +
|
||||
"PAYLOAD_VERSION = ? WHERE ID = ? AND TENANT_ID = ?";
|
||||
stmt = conn.prepareStatement(query);
|
||||
stmt.setString(1, policy.getPolicyName());
|
||||
stmt.setInt(2, policy.getProfile().getProfileId());
|
||||
@ -931,8 +990,9 @@ public class PolicyDAOImpl implements PolicyDAO {
|
||||
stmt.setString(6, policy.getDescription());
|
||||
stmt.setString(7, policy.getOwnershipType());
|
||||
stmt.setString(8, policy.getPolicyType());
|
||||
stmt.setInt(9, policy.getId());
|
||||
stmt.setInt(10, tenantId);
|
||||
stmt.setString(9, policy.getPolicyPayloadVersion());
|
||||
stmt.setInt(10, policy.getId());
|
||||
stmt.setInt(11, tenantId);
|
||||
stmt.executeUpdate();
|
||||
|
||||
} catch (SQLException e) {
|
||||
@ -1041,6 +1101,7 @@ public class PolicyDAOImpl implements PolicyDAO {
|
||||
policy.setPolicyType(resultSet.getString("POLICY_TYPE"));
|
||||
policy.setUpdated(PolicyManagerUtil.convertIntToBoolean(resultSet.getInt("UPDATED")));
|
||||
policy.setActive(PolicyManagerUtil.convertIntToBoolean(resultSet.getInt("ACTIVE")));
|
||||
policy.setPolicyPayloadVersion(resultSet.getString("PAYLOAD_VERSION"));
|
||||
}
|
||||
return policy;
|
||||
|
||||
@ -1552,8 +1613,10 @@ public class PolicyDAOImpl implements PolicyDAO {
|
||||
|
||||
try {
|
||||
conn = this.getConnection();
|
||||
String query = "INSERT INTO DM_POLICY (NAME, PROFILE_ID, TENANT_ID, PRIORITY, COMPLIANCE, OWNERSHIP_TYPE," +
|
||||
"UPDATED, ACTIVE, DESCRIPTION, POLICY_TYPE) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
|
||||
String query = "INSERT INTO DM_POLICY (NAME, PROFILE_ID, TENANT_ID, " +
|
||||
"PRIORITY, COMPLIANCE, OWNERSHIP_TYPE, " +
|
||||
"UPDATED, ACTIVE, DESCRIPTION, POLICY_TYPE, PAYLOAD_VERSION) " +
|
||||
"VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
|
||||
stmt = conn.prepareStatement(query, new String[]{"id"});
|
||||
|
||||
stmt.setString(1, policy.getPolicyName());
|
||||
@ -1566,6 +1629,7 @@ public class PolicyDAOImpl implements PolicyDAO {
|
||||
stmt.setInt(8, 0);
|
||||
stmt.setString(9, policy.getDescription());
|
||||
stmt.setString(10, policy.getPolicyType());
|
||||
stmt.setString(11, policy.getPolicyPayloadVersion());
|
||||
|
||||
int affectedRows = stmt.executeUpdate();
|
||||
|
||||
@ -1870,6 +1934,7 @@ public class PolicyDAOImpl implements PolicyDAO {
|
||||
policy.setActive(PolicyManagerUtil.convertIntToBoolean(resultSet.getInt("ACTIVE")));
|
||||
policy.setDescription(resultSet.getString("DESCRIPTION"));
|
||||
policy.setPolicyType(resultSet.getString("POLICY_TYPE"));
|
||||
policy.setPolicyPayloadVersion(resultSet.getString("PAYLOAD_VERSION"));
|
||||
policies.add(policy);
|
||||
}
|
||||
return policies;
|
||||
|
||||
@ -35,6 +35,7 @@
|
||||
|
||||
package org.wso2.carbon.policy.mgt.core.mgt.impl;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.wso2.carbon.device.mgt.common.Device;
|
||||
@ -57,18 +58,32 @@ import org.wso2.carbon.device.mgt.core.operation.mgt.CommandOperation;
|
||||
import org.wso2.carbon.device.mgt.core.operation.mgt.OperationMgtConstants;
|
||||
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
|
||||
import org.wso2.carbon.device.mgt.core.service.GroupManagementProviderService;
|
||||
import org.wso2.carbon.policy.mgt.common.*;
|
||||
import org.wso2.carbon.policy.mgt.common.Criterion;
|
||||
import org.wso2.carbon.policy.mgt.common.PolicyManagementException;
|
||||
import org.wso2.carbon.policy.mgt.common.ProfileManagementException;
|
||||
import org.wso2.carbon.policy.mgt.core.cache.impl.PolicyCacheManagerImpl;
|
||||
import org.wso2.carbon.policy.mgt.core.dao.*;
|
||||
import org.wso2.carbon.policy.mgt.core.dao.FeatureDAO;
|
||||
import org.wso2.carbon.policy.mgt.core.dao.FeatureManagerDAOException;
|
||||
import org.wso2.carbon.policy.mgt.core.dao.PolicyDAO;
|
||||
import org.wso2.carbon.policy.mgt.core.dao.PolicyManagementDAOFactory;
|
||||
import org.wso2.carbon.policy.mgt.core.dao.PolicyManagerDAOException;
|
||||
import org.wso2.carbon.policy.mgt.core.dao.ProfileDAO;
|
||||
import org.wso2.carbon.policy.mgt.core.dao.ProfileManagerDAOException;
|
||||
import org.wso2.carbon.policy.mgt.core.internal.PolicyManagementDataHolder;
|
||||
import org.wso2.carbon.policy.mgt.core.mgt.PolicyManager;
|
||||
import org.wso2.carbon.policy.mgt.core.mgt.ProfileManager;
|
||||
import org.wso2.carbon.policy.mgt.core.mgt.bean.UpdatedPolicyDeviceListBean;
|
||||
import org.wso2.carbon.policy.mgt.core.util.PolicyManagementConstants;
|
||||
import org.wso2.carbon.policy.mgt.core.util.PolicyManagerUtil;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Timestamp;
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class PolicyManagerImpl implements PolicyManager {
|
||||
|
||||
@ -101,7 +116,23 @@ public class PolicyManagerImpl implements PolicyManager {
|
||||
profileDAO.addProfile(profile);
|
||||
featureDAO.addProfileFeatures(profile.getProfileFeaturesList(), profile.getProfileId());
|
||||
}
|
||||
policy.setPolicyPayloadVersion("2.0");
|
||||
policy = policyDAO.addPolicy(policy);
|
||||
if (policy.getProfile() != null) {
|
||||
Profile profile = policy.getProfile();
|
||||
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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (policy.getUsers() != null) {
|
||||
policyDAO.addPolicyToUser(policy.getUsers(), policy);
|
||||
@ -134,13 +165,7 @@ public class PolicyManagerImpl implements PolicyManager {
|
||||
policyDAO.addPolicyCriteria(policy);
|
||||
policyDAO.addPolicyCriteriaProperties(policy.getPolicyCriterias());
|
||||
}
|
||||
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());
|
||||
}
|
||||
@ -178,6 +203,9 @@ 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();
|
||||
List<ProfileFeature> existingProfileFeaturesList = previousPolicy.getProfile().getProfileFeaturesList();
|
||||
|
||||
@ -212,7 +240,8 @@ public class PolicyManagerImpl implements PolicyManager {
|
||||
Timestamp currentTimestamp = new Timestamp(Calendar.getInstance().getTime().getTime());
|
||||
policy.getProfile().setUpdatedDate(currentTimestamp);
|
||||
policy.setPriorityId(previousPolicy.getPriorityId());
|
||||
policyDAO.updatePolicy(policy);
|
||||
policy.setPolicyPayloadVersion(previousPolicy.getPolicyPayloadVersion());
|
||||
Policy updatedPolicy = policyDAO.updatePolicy(policy);
|
||||
profileDAO.updateProfile(policy.getProfile());
|
||||
|
||||
featureDAO.updateProfileFeatures(existingFeaturesList, profileId);
|
||||
@ -251,51 +280,39 @@ public class PolicyManagerImpl implements PolicyManager {
|
||||
policyDAO.addPolicyCriteria(policy);
|
||||
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) {
|
||||
for (CorrectiveAction existingCorrectiveAction : existingCorrectiveActions) {
|
||||
if (updatedCorrectiveAction.getActionType().equals(existingCorrectiveAction.getActionType())) {
|
||||
correctiveActionsToUpdate.add(updatedCorrectiveAction);
|
||||
existingCorrectiveActionTypes.add(updatedCorrectiveAction.getActionType());
|
||||
}
|
||||
}
|
||||
correctiveActionTypesToUpdate.add(updatedCorrectiveAction.getActionType());
|
||||
String policyPayloadVersion = previousPolicy.getPolicyPayloadVersion();
|
||||
float payloadVersion = 0f;
|
||||
if (policyPayloadVersion != null && !StringUtils.isEmpty(policyPayloadVersion)) {
|
||||
payloadVersion = Float.parseFloat(policyPayloadVersion);
|
||||
}
|
||||
|
||||
for (CorrectiveAction updatedCorrectiveAction : updatedCorrectiveActions) {
|
||||
if (!existingCorrectiveActionTypes.contains(updatedCorrectiveAction.getActionType())) {
|
||||
correctiveActionsToAdd.add(updatedCorrectiveAction);
|
||||
}
|
||||
List<ProfileFeature> updatedFeatures = policy.getProfile().getProfileFeaturesList();
|
||||
List<ProfileFeature> features = featureDAO.getFeaturesForProfile(profileId);
|
||||
for (ProfileFeature updatedFeature : updatedFeatures) {
|
||||
for (ProfileFeature feature : features) {
|
||||
if (updatedFeature.getFeatureCode().equals(feature.getFeatureCode())) {
|
||||
updatedFeature.setId(feature.getId());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
for (CorrectiveAction existingCorrectiveAction : existingCorrectiveActions) {
|
||||
if (!correctiveActionTypesToUpdate.contains(existingCorrectiveAction.getActionType())) {
|
||||
correctiveActionsToDelete.add(existingCorrectiveAction);
|
||||
if (updatedFeature.getCorrectiveActions() != null) {
|
||||
updatedCorrectiveActionsMap.put(updatedFeature.getId(),
|
||||
updatedFeature.getCorrectiveActions());
|
||||
}
|
||||
}
|
||||
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Updating corrective actions for policy " + policy.getPolicyName() +
|
||||
" having policy id " + policy.getId());
|
||||
for (ProfileFeature fe : existingProfileFeaturesList) {
|
||||
if (fe.getCorrectiveActions() != null && !fe.getCorrectiveActions().isEmpty()) {
|
||||
existingCorrectiveActionsMap.put(fe.getId(), fe.getCorrectiveActions());
|
||||
}
|
||||
if (!correctiveActionsToUpdate.isEmpty()) {
|
||||
policyDAO.updateCorrectiveActionsOfPolicy(correctiveActionsToUpdate, previousPolicy.getId());
|
||||
}
|
||||
if (!correctiveActionsToAdd.isEmpty()) {
|
||||
policyDAO.addCorrectiveActionsOfPolicy(correctiveActionsToAdd, previousPolicy.getId());
|
||||
}
|
||||
if (!correctiveActionsToDelete.isEmpty()) {
|
||||
policyDAO.deleteCorrectiveActionsOfPolicy(correctiveActionsToDelete, previousPolicy.getId());
|
||||
|
||||
if (payloadVersion >= 2.0f) {
|
||||
updateMultipleCorrectiveActions(updatedCorrectiveActionsMap,
|
||||
existingCorrectiveActionsMap, policy, previousPolicy);
|
||||
} else {
|
||||
updateSingleCorrectiveActionList(policy, previousPolicy);
|
||||
}
|
||||
PolicyManagementDAOFactory.commitTransaction();
|
||||
} catch (PolicyManagerDAOException e) {
|
||||
@ -317,6 +334,190 @@ public class PolicyManagerImpl implements PolicyManager {
|
||||
return policy;
|
||||
}
|
||||
|
||||
/**
|
||||
* Using for update old type of corrective policies which has single corrective policy
|
||||
* per single general policy
|
||||
* @param policy updating new corrective policy
|
||||
* @param previousPolicy previous corrective policy
|
||||
* @throws PolicyManagerDAOException for errors occur while updating corrective actions
|
||||
*/
|
||||
private void updateSingleCorrectiveActionList(Policy policy, Policy previousPolicy)
|
||||
throws PolicyManagerDAOException {
|
||||
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) {
|
||||
for (CorrectiveAction existingCorrectiveAction : existingCorrectiveActions) {
|
||||
if (updatedCorrectiveAction.getActionType()
|
||||
.equals(existingCorrectiveAction.getActionType())) {
|
||||
correctiveActionsToUpdate.add(updatedCorrectiveAction);
|
||||
existingCorrectiveActionTypes.add(updatedCorrectiveAction.getActionType());
|
||||
}
|
||||
}
|
||||
correctiveActionTypesToUpdate.add(updatedCorrectiveAction.getActionType());
|
||||
}
|
||||
|
||||
for (CorrectiveAction updatedCorrectiveAction : updatedCorrectiveActions) {
|
||||
if (!existingCorrectiveActionTypes.contains(updatedCorrectiveAction
|
||||
.getActionType())) {
|
||||
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 (!correctiveActionsToUpdate.isEmpty()) {
|
||||
policyDAO.updateCorrectiveActionsOfPolicy(correctiveActionsToUpdate,
|
||||
previousPolicy.getId(), -1);
|
||||
}
|
||||
|
||||
if (!correctiveActionsToAdd.isEmpty()) {
|
||||
policyDAO.addCorrectiveActionsOfPolicy(correctiveActionsToAdd,
|
||||
previousPolicy.getId(), -1);
|
||||
}
|
||||
|
||||
if (!correctiveActionsToDelete.isEmpty()) {
|
||||
policyDAO.deleteCorrectiveActionsOfPolicy(correctiveActionsToDelete,
|
||||
previousPolicy.getId(), -1);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Using for update new type of corrective policies which has multiple corrective policies
|
||||
* per single general policy
|
||||
* @param updatedCorrectiveActionsMap updated corrective actions <FeatureId, CorrectiveActionList>
|
||||
* @param existingCorrectiveActionsMap existing corrective actions <FeatureId, CorrectiveActionList>
|
||||
* @param policy updating policy
|
||||
* @param previousPolicy for errors occur while updating corrective actions
|
||||
* @throws PolicyManagerDAOException
|
||||
*/
|
||||
private void updateMultipleCorrectiveActions(
|
||||
Map<Integer, List<CorrectiveAction>> updatedCorrectiveActionsMap,
|
||||
Map<Integer, List<CorrectiveAction>> existingCorrectiveActionsMap,
|
||||
Policy policy, Policy previousPolicy) throws PolicyManagerDAOException {
|
||||
|
||||
Map<Integer, List<CorrectiveAction>> correctiveActionsToUpdate = new HashMap<>();
|
||||
Map<Integer, List<String>> existingCorrectiveActionTypes = new HashMap<>();
|
||||
Map<Integer, List<String>> correctiveActionTypesToUpdate = new HashMap<>();
|
||||
Map<Integer, List<CorrectiveAction>> correctiveActionsToAdd = new HashMap<>();
|
||||
Map<Integer, List<CorrectiveAction>> correctiveActionsToDelete = new HashMap<>();
|
||||
|
||||
for (Integer featureId : updatedCorrectiveActionsMap.keySet()) {
|
||||
List<CorrectiveAction> correctiveActionListToUpdate = new ArrayList<>();
|
||||
List<CorrectiveAction> updatedCorrectiveActions = updatedCorrectiveActionsMap
|
||||
.get(featureId);
|
||||
for (CorrectiveAction updatedCorrectiveAction : updatedCorrectiveActions) {
|
||||
List<CorrectiveAction> existingCorrectiveActions = existingCorrectiveActionsMap
|
||||
.get(featureId);
|
||||
if (existingCorrectiveActions != null) {
|
||||
for (CorrectiveAction existingCorrectiveAction : existingCorrectiveActions) {
|
||||
if (existingCorrectiveAction.getActionType().equals(updatedCorrectiveAction
|
||||
.getActionType())) {
|
||||
correctiveActionListToUpdate.add(updatedCorrectiveAction);
|
||||
List<String> existingTypes = existingCorrectiveActionTypes
|
||||
.get(featureId);
|
||||
if (existingTypes == null) {
|
||||
existingTypes = new ArrayList<>();
|
||||
}
|
||||
existingTypes.add(updatedCorrectiveAction.getActionType());
|
||||
existingCorrectiveActionTypes.put(featureId, existingTypes);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
List<String> toUpdateTypes = correctiveActionTypesToUpdate.get(featureId);
|
||||
if (toUpdateTypes == null) {
|
||||
toUpdateTypes = new ArrayList<>();
|
||||
}
|
||||
toUpdateTypes.add(updatedCorrectiveAction.getActionType());
|
||||
correctiveActionTypesToUpdate.put(featureId, toUpdateTypes);
|
||||
}
|
||||
if (!correctiveActionListToUpdate.isEmpty()) {
|
||||
correctiveActionsToUpdate.put(featureId, correctiveActionListToUpdate);
|
||||
}
|
||||
|
||||
List<String> existingTypes = existingCorrectiveActionTypes.get(featureId);
|
||||
for (CorrectiveAction updatedCorrectiveAction : updatedCorrectiveActions) {
|
||||
if (existingTypes == null || !existingTypes.contains(updatedCorrectiveAction
|
||||
.getActionType())) {
|
||||
List<CorrectiveAction> correctiveActions = correctiveActionsToAdd
|
||||
.get(featureId);
|
||||
if (correctiveActions == null) {
|
||||
correctiveActions = new ArrayList<>();
|
||||
}
|
||||
correctiveActions.add(updatedCorrectiveAction);
|
||||
correctiveActionsToAdd.put(featureId, correctiveActions);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (Integer featureId : existingCorrectiveActionsMap.keySet()) {
|
||||
List<CorrectiveAction> existingCorrectiveActions = existingCorrectiveActionsMap
|
||||
.get(featureId);
|
||||
List<String> actionTypesToUpdate = correctiveActionTypesToUpdate.get(featureId);
|
||||
for (CorrectiveAction existingCorrectiveAction : existingCorrectiveActions) {
|
||||
if (actionTypesToUpdate == null ||
|
||||
!actionTypesToUpdate.contains(existingCorrectiveAction.getActionType())) {
|
||||
List<CorrectiveAction> correctiveActionListToDelete = correctiveActionsToDelete
|
||||
.get(featureId);
|
||||
if (correctiveActionListToDelete == null) {
|
||||
correctiveActionListToDelete = new ArrayList<>();
|
||||
}
|
||||
correctiveActionListToDelete.add(existingCorrectiveAction);
|
||||
correctiveActionsToDelete.put(featureId, correctiveActionListToDelete);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Updating corrective actions for policy " + policy.getPolicyName() +
|
||||
" having policy id " + policy.getId());
|
||||
}
|
||||
|
||||
if (!correctiveActionsToUpdate.isEmpty()) {
|
||||
for (Integer featureId : correctiveActionsToUpdate.keySet()) {
|
||||
List<CorrectiveAction> correctiveActions = correctiveActionsToUpdate
|
||||
.get(featureId);
|
||||
policyDAO.updateCorrectiveActionsOfPolicy(correctiveActions,
|
||||
previousPolicy.getId(), featureId);
|
||||
}
|
||||
}
|
||||
|
||||
if (!correctiveActionsToAdd.isEmpty()) {
|
||||
for (Integer featureId : correctiveActionsToAdd.keySet()) {
|
||||
List<CorrectiveAction> correctiveActions = correctiveActionsToAdd
|
||||
.get(featureId);
|
||||
policyDAO.addCorrectiveActionsOfPolicy(correctiveActions,
|
||||
previousPolicy.getId(), featureId);
|
||||
}
|
||||
}
|
||||
|
||||
if (!correctiveActionsToDelete.isEmpty()) {
|
||||
for (Integer featureId : correctiveActionsToDelete.keySet()) {
|
||||
List<CorrectiveAction> correctiveActions = correctiveActionsToDelete
|
||||
.get(featureId);
|
||||
policyDAO.deleteCorrectiveActionsOfPolicy(correctiveActions,
|
||||
previousPolicy.getId(), featureId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean updatePolicyPriorities(List<Policy> policies) throws PolicyManagementException {
|
||||
boolean bool;
|
||||
@ -616,7 +817,7 @@ 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 (" +
|
||||
policyId + ")", e);
|
||||
@ -637,6 +838,34 @@ public class PolicyManagerImpl implements PolicyManager {
|
||||
throw new PolicyManagementException("Error occurred while getting the profile related to policy ID (" +
|
||||
policyId + ")", e);
|
||||
}
|
||||
|
||||
try {
|
||||
PolicyManagementDAOFactory.openConnection();
|
||||
List<CorrectiveAction> correctiveActionsOfPolicy = policyDAO
|
||||
.getCorrectiveActionsOfPolicy(policyId);
|
||||
String policyPayloadVersion = policy.getPolicyPayloadVersion();
|
||||
float payloadVersion = 0f;
|
||||
if (policyPayloadVersion != null && !StringUtils.isEmpty(policyPayloadVersion)) {
|
||||
payloadVersion = Float.parseFloat(policyPayloadVersion);
|
||||
}
|
||||
if (payloadVersion >= 2.0f) {
|
||||
setMultipleCorrectiveActions(correctiveActionsOfPolicy, policy.getProfile());
|
||||
} else {
|
||||
policy.setCorrectiveActions(getSingleCorrectiveAction
|
||||
(correctiveActionsOfPolicy, policyId));
|
||||
}
|
||||
} catch (PolicyManagerDAOException e) {
|
||||
String msg = "Error occurred while getting the corrective actions related to policy " +
|
||||
"ID (" + policyId + ")";
|
||||
log.error(msg, e);
|
||||
throw new PolicyManagementException(msg, e);
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error occurred while opening DB connection";
|
||||
log.error(msg, e);
|
||||
throw new PolicyManagementException(msg, e);
|
||||
} finally {
|
||||
PolicyManagementDAOFactory.closeConnection();
|
||||
}
|
||||
return policy;
|
||||
}
|
||||
|
||||
@ -1174,17 +1403,41 @@ public class PolicyManagerImpl implements PolicyManager {
|
||||
return policyList;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the list of policies which are included new and old types of corrective actions
|
||||
* @param policyList queried policy list
|
||||
* @param profileList queried profile list
|
||||
* @throws PolicyManagerDAOException when failed to read policies from DB
|
||||
* @throws GroupManagementException when failed to read policy groups from DB
|
||||
*/
|
||||
private void buildPolicyList(List<Policy> policyList, List<Profile> profileList)
|
||||
throws PolicyManagerDAOException, GroupManagementException {
|
||||
List<CorrectiveAction> allCorrectiveActions = policyDAO.getAllCorrectiveActions();
|
||||
for (Policy policy : policyList) {
|
||||
String policyPayloadVersion = policy.getPolicyPayloadVersion();
|
||||
float payloadVersion = 0f;
|
||||
if (policyPayloadVersion != null &&
|
||||
!StringUtils.isEmpty(policyPayloadVersion)) {
|
||||
payloadVersion = Float.parseFloat(policyPayloadVersion);
|
||||
}
|
||||
for (Profile profile : profileList) {
|
||||
if (policy.getProfileId() == profile.getProfileId()) {
|
||||
policy.setProfile(profile);
|
||||
if (payloadVersion >= 2.0f && PolicyManagementConstants.GENERAL_POLICY_TYPE
|
||||
.equals(policy.getPolicyType())) {
|
||||
setMultipleCorrectiveActions(allCorrectiveActions, profile);
|
||||
}
|
||||
}
|
||||
}
|
||||
policy.setRoles(policyDAO.getPolicyAppliedRoles(policy.getId()));
|
||||
policy.setUsers(policyDAO.getPolicyAppliedUsers(policy.getId()));
|
||||
policy.setPolicyCriterias(policyDAO.getPolicyCriteria(policy.getId()));
|
||||
if (payloadVersion < 2.0f && PolicyManagementConstants.GENERAL_POLICY_TYPE
|
||||
.equals(policy.getPolicyType())) {
|
||||
policy.setCorrectiveActions
|
||||
(getSingleCorrectiveAction(allCorrectiveActions, policy.getId()));
|
||||
}
|
||||
|
||||
List<DeviceGroupWrapper> deviceGroupWrappers = policyDAO.getDeviceGroupsOfPolicy(policy.getId());
|
||||
if (!deviceGroupWrappers.isEmpty()) {
|
||||
deviceGroupWrappers = this.getDeviceGroupNames(deviceGroupWrappers);
|
||||
@ -1194,8 +1447,44 @@ 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);
|
||||
}
|
||||
|
||||
private List<CorrectiveAction> getSingleCorrectiveAction
|
||||
(List<CorrectiveAction> allCorrectiveActions, int policyId) {
|
||||
List<CorrectiveAction> correctiveActionsOfPolicy = new ArrayList<>();
|
||||
for (CorrectiveAction correctiveAction : allCorrectiveActions) {
|
||||
if (correctiveAction.getAssociatedGeneralPolicyId() != null &&
|
||||
correctiveAction.getAssociatedGeneralPolicyId() == policyId) {
|
||||
clearMetaDataValues(correctiveAction);
|
||||
correctiveActionsOfPolicy.add(correctiveAction);
|
||||
}
|
||||
}
|
||||
return correctiveActionsOfPolicy;
|
||||
}
|
||||
|
||||
private void setMultipleCorrectiveActions(List<CorrectiveAction> allCorrectiveActions,
|
||||
Profile profile) {
|
||||
for (ProfileFeature profileFeature : profile.getProfileFeaturesList()) {
|
||||
List<CorrectiveAction> correctiveActionList = new ArrayList<>();
|
||||
for (CorrectiveAction correctiveAction : allCorrectiveActions) {
|
||||
if (correctiveAction.getFeatureId() != null &&
|
||||
profileFeature.getId() == correctiveAction.getFeatureId()) {
|
||||
clearMetaDataValues(correctiveAction);
|
||||
correctiveActionList.add(correctiveAction);
|
||||
}
|
||||
}
|
||||
profileFeature.setCorrectiveActions(correctiveActionList);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear corrective action metadata values to avoid sending in payload
|
||||
* @param correctiveAction list of corrective actions
|
||||
*/
|
||||
private void clearMetaDataValues(CorrectiveAction correctiveAction) {
|
||||
correctiveAction.setAssociatedGeneralPolicyId(null); //avoiding send in payload
|
||||
correctiveAction.setFeatureId(null); //avoiding send in payload
|
||||
}
|
||||
}
|
||||
|
||||
@ -65,6 +65,8 @@ public final class PolicyManagementConstants {
|
||||
public static final String GENERAL_POLICY_TYPE = "GENERAL";
|
||||
public static final String CORRECTIVE_POLICY_TYPE = "CORRECTIVE";
|
||||
public static final String POLICY_CORRECTIVE_ACTION_TYPE = "POLICY";
|
||||
public static final String POLICY_FEATURE_CODE = "POLICY_ACTION";
|
||||
public static final String POLICY_ACTIONS = "POLICY_ACTIONS";
|
||||
public static final String CORRECTIVE_POLICY_FEATURE_CODE = "CORRECTIVE_POLICY";
|
||||
|
||||
/**
|
||||
|
||||
@ -36,6 +36,7 @@
|
||||
package org.wso2.carbon.policy.mgt.core.util;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.w3c.dom.Document;
|
||||
@ -140,66 +141,182 @@ public class PolicyManagerUtil {
|
||||
|
||||
public static Operation transformPolicy(Policy policy) throws PolicyTransformException {
|
||||
List<ProfileFeature> effectiveFeatures = policy.getProfile().getProfileFeaturesList();
|
||||
|
||||
PolicyOperation policyOperation = new PolicyOperation();
|
||||
policyOperation.setEnabled(true);
|
||||
policyOperation.setType(org.wso2.carbon.device.mgt.common.operation.mgt.Operation.Type.POLICY);
|
||||
policyOperation.setCode(PolicyOperation.POLICY_OPERATION_CODE);
|
||||
|
||||
policyOperation.setProfileOperations(createProfileOperations(effectiveFeatures));
|
||||
if (policy.getPolicyType() != null &&
|
||||
PolicyManagementConstants.GENERAL_POLICY_TYPE.equals(policy.getPolicyType()) &&
|
||||
policy.getCorrectiveActions() != null) {
|
||||
PolicyManagementConstants.GENERAL_POLICY_TYPE.equals(policy.getPolicyType())) {
|
||||
String policyPayloadVersion = policy.getPolicyPayloadVersion();
|
||||
float payloadVersion = 0f;
|
||||
if (!StringUtils.isEmpty(policyPayloadVersion)) {
|
||||
payloadVersion = Float.parseFloat(policyPayloadVersion);
|
||||
}
|
||||
if (payloadVersion >= 2.0f) {
|
||||
setMultipleCorrectiveActions(effectiveFeatures, policyOperation, policy);
|
||||
} else {
|
||||
setSingleCorrectiveAction(policy, effectiveFeatures);
|
||||
}
|
||||
}
|
||||
policyOperation.setPayLoad(policyOperation.getProfileOperations());
|
||||
return policyOperation;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is used for generate single corrective action set for a single policy which is
|
||||
* bind to the policy payload
|
||||
* @param policy regarding policy object
|
||||
* @param effectiveFeatures effective feature list
|
||||
* @throws PolicyTransformException when transforming of the policy have issues
|
||||
*/
|
||||
private static void setSingleCorrectiveAction(Policy policy, List<ProfileFeature>
|
||||
effectiveFeatures) throws PolicyTransformException {
|
||||
if (policy.getCorrectiveActions() != null) {
|
||||
for (CorrectiveAction correctiveAction : policy.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());
|
||||
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.setContent(new Gson()
|
||||
.toJson(correctiveProfileOperations));
|
||||
correctivePolicyFeature.setDeviceType(correctivePolicy
|
||||
.getProfile().getDeviceType());
|
||||
correctivePolicyFeature.setFeatureCode(
|
||||
PolicyManagementConstants.CORRECTIVE_POLICY_FEATURE_CODE);
|
||||
correctivePolicyFeature.setId(correctivePolicy.getId());
|
||||
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);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is use for generate multiple corrective actions per policy which is attached
|
||||
* to the feature of the policy
|
||||
* @param features regarding feature list of the policy
|
||||
* @param policyOperation operation list which to be sent to the device
|
||||
* @param policy regarding policy
|
||||
* @throws PolicyTransformException
|
||||
*/
|
||||
private static void setMultipleCorrectiveActions(List<ProfileFeature> features,
|
||||
PolicyOperation policyOperation, Policy policy)
|
||||
throws PolicyTransformException {
|
||||
ProfileOperation correctiveProfileOperation = new ProfileOperation();
|
||||
correctiveProfileOperation.setCode(PolicyManagementConstants.POLICY_ACTIONS);
|
||||
Set<Integer> correctivePolicyIdSet = new HashSet<>();
|
||||
try {
|
||||
List<CorrectiveAction> correctiveActions;
|
||||
for (ProfileFeature feature : features) {
|
||||
correctiveActions = feature.getCorrectiveActions();
|
||||
for (CorrectiveAction correctiveAction : correctiveActions) {
|
||||
if (PolicyManagementConstants.POLICY_CORRECTIVE_ACTION_TYPE
|
||||
.equals(correctiveAction.getActionType())) {
|
||||
correctivePolicyIdSet.add(correctiveAction.getPolicyId());
|
||||
}
|
||||
//Add check for another action type in future implementation
|
||||
}
|
||||
}
|
||||
PolicyAdministratorPoint pap = new PolicyAdministratorPointImpl();
|
||||
List<Policy> allCorrectivePolicies = pap
|
||||
.getPolicies(PolicyManagementConstants.CORRECTIVE_POLICY_TYPE);
|
||||
for (Integer policyId : correctivePolicyIdSet) {
|
||||
for (Policy correctivePolicy : allCorrectivePolicies) {
|
||||
if (policyId == correctivePolicy.getId()) {
|
||||
createCorrectiveProfileOperations(correctivePolicy, correctiveProfileOperation);
|
||||
policyOperation.getProfileOperations().add(correctiveProfileOperation);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
} 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
policyOperation.setProfileOperations(createProfileOperations(effectiveFeatures));
|
||||
policyOperation.setPayLoad(policyOperation.getProfileOperations());
|
||||
return policyOperation;
|
||||
/**
|
||||
* This method is using for generate profile operations list which to be sent to the device.
|
||||
* this method is only using multiple corrective actions
|
||||
* @param correctivePolicy regarding corrective policy
|
||||
* @param correctiveOperationList regarding operations list of the corrective policy
|
||||
*/
|
||||
private static void createCorrectiveProfileOperations(Policy correctivePolicy,
|
||||
ProfileOperation correctiveOperationList) {
|
||||
ProfileOperation profileOperation = new ProfileOperation();
|
||||
profileOperation.setId(correctivePolicy.getId());
|
||||
profileOperation.setCode(PolicyManagementConstants.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);
|
||||
List<ProfileOperation> profileOperations = createProfileOperations(correctivePolicy
|
||||
.getProfile().getProfileFeaturesList());
|
||||
profileOperation.setPayLoad(profileOperations);
|
||||
List<ProfileOperation> payLoad;
|
||||
if (correctiveOperationList.getPayLoad() != null) {
|
||||
payLoad = (List<ProfileOperation>) correctiveOperationList.getPayLoad();
|
||||
} else {
|
||||
payLoad = new ArrayList<>();
|
||||
}
|
||||
payLoad.add(profileOperation);
|
||||
correctiveOperationList.setPayLoad(payLoad);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create list of profile operations
|
||||
* @param effectiveFeatures effective features of the policy
|
||||
* @return List of ProfileOperation
|
||||
*/
|
||||
public static List<ProfileOperation> createProfileOperations(List<ProfileFeature> effectiveFeatures) {
|
||||
List<ProfileOperation> profileOperations = new ArrayList<>();
|
||||
for (ProfileFeature feature : effectiveFeatures) {
|
||||
ProfileOperation profileOperation = new ProfileOperation();
|
||||
profileOperation.setCode(feature.getFeatureCode());
|
||||
profileOperation.setEnabled(true);
|
||||
profileOperation.setId(feature.getId());
|
||||
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());
|
||||
if (feature.getCorrectiveActions() != null) {
|
||||
for (CorrectiveAction correctiveAction : feature.getCorrectiveActions()) {
|
||||
if (correctiveAction.isReactive()) {
|
||||
if (profileOperation.getReactiveActionIds() == null) {
|
||||
profileOperation.setReactiveActionIds(new ArrayList<>());
|
||||
}
|
||||
profileOperation.getReactiveActionIds().add(correctiveAction.getPolicyId());
|
||||
} else {
|
||||
if (profileOperation.getCorrectiveActionIds() == null) {
|
||||
profileOperation.setCorrectiveActionIds(new ArrayList<>());
|
||||
}
|
||||
profileOperation.getCorrectiveActionIds().add(correctiveAction.getPolicyId());
|
||||
}
|
||||
}
|
||||
}
|
||||
profileOperations.add(profileOperation);
|
||||
}
|
||||
return profileOperations;
|
||||
|
||||
@ -182,6 +182,7 @@ DROP TABLE IF EXISTS DM_POLICY;
|
||||
CREATE TABLE IF NOT EXISTS DM_POLICY (
|
||||
ID INT(11) NOT NULL AUTO_INCREMENT ,
|
||||
NAME VARCHAR(45) DEFAULT NULL ,
|
||||
PAYLOAD_VERSION VARCHAR (45) DEFAULT NULL,
|
||||
DESCRIPTION VARCHAR(1000) NULL,
|
||||
TENANT_ID INT(11) NOT NULL ,
|
||||
PROFILE_ID INT(11) NOT NULL ,
|
||||
@ -205,6 +206,8 @@ 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) DEFAULT NULL,
|
||||
IS_REACTIVE BOOLEAN NOT NULL DEFAULT FALSE,
|
||||
PRIMARY KEY (ID),
|
||||
CONSTRAINT FK_DM_POLICY_DM_POLICY_CORRECTIVE_ACTION
|
||||
FOREIGN KEY (POLICY_ID)
|
||||
@ -213,6 +216,7 @@ CREATE TABLE IF NOT EXISTS DM_POLICY_CORRECTIVE_ACTION (
|
||||
ON UPDATE NO ACTION
|
||||
);
|
||||
|
||||
|
||||
DROP TABLE IF EXISTS DM_DEVICE_POLICY;
|
||||
CREATE TABLE IF NOT EXISTS DM_DEVICE_POLICY (
|
||||
ID INT(11) NOT NULL AUTO_INCREMENT ,
|
||||
|
||||
@ -63,6 +63,7 @@ DROP TABLE IF EXISTS `WSO2CDM`.`DM_POLICY` ;
|
||||
CREATE TABLE IF NOT EXISTS `WSO2CDM`.`DM_POLICY` (
|
||||
`ID` INT(11) NOT NULL AUTO_INCREMENT,
|
||||
`NAME` VARCHAR(45) NULL DEFAULT NULL,
|
||||
`PAYLOAD_VERSION` VARCHAR(45) NULL DEFAULT NULL,
|
||||
`TENANT_ID` INT(11) NOT NULL,
|
||||
`PROFILE_ID` INT(11) NOT NULL,
|
||||
`COMPLIANCE` VARCHAR(100) NULL,
|
||||
@ -77,23 +78,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,
|
||||
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
|
||||
)ENGINE = InnoDB
|
||||
DEFAULT CHARACTER SET = latin1;
|
||||
|
||||
|
||||
-- -----------------------------------------------------
|
||||
-- Table `WSO2CDM`.`DM_DATE`
|
||||
@ -221,6 +205,24 @@ 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) DEFAULT NULL,
|
||||
`IS_REACTIVE` BOOLEAN NOT NULL DEFAULT FALSE,
|
||||
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
|
||||
)ENGINE = InnoDB
|
||||
DEFAULT CHARACTER SET = latin1;
|
||||
|
||||
-- -----------------------------------------------------
|
||||
-- Table `WSO2CDM`.`DM_ROLE_POLICY`
|
||||
|
||||
@ -178,6 +178,7 @@ CREATE TABLE IF NOT EXISTS DM_POLICY (
|
||||
ID INT(11) NOT NULL AUTO_INCREMENT ,
|
||||
NAME VARCHAR(45) DEFAULT NULL ,
|
||||
DESCRIPTION VARCHAR(1000) NULL,
|
||||
PAYLOAD_VERSION VARCHAR (45) NULL,
|
||||
TENANT_ID INT(11) NOT NULL ,
|
||||
PROFILE_ID INT(11) NOT NULL ,
|
||||
OWNERSHIP_TYPE VARCHAR(45) NULL,
|
||||
@ -194,19 +195,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,
|
||||
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
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS DM_DEVICE_POLICY (
|
||||
ID INT(11) NOT NULL AUTO_INCREMENT ,
|
||||
DEVICE_ID INT(11) NOT NULL ,
|
||||
@ -253,6 +241,21 @@ 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) DEFAULT NULL,
|
||||
IS_REACTIVE BOOLEAN NOT NULL DEFAULT FALSE,
|
||||
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
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS DM_ROLE_POLICY (
|
||||
ID INT(11) NOT NULL AUTO_INCREMENT ,
|
||||
ROLE_NAME VARCHAR(45) NOT NULL ,
|
||||
|
||||
@ -229,6 +229,7 @@ IF NOT EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[D
|
||||
CREATE TABLE DM_POLICY (
|
||||
ID INTEGER IDENTITY(1,1) NOT NULL,
|
||||
NAME VARCHAR(45) DEFAULT NULL ,
|
||||
PAYLOAD_VERSION VARCHAR (45) DEFAULT NULL,
|
||||
DESCRIPTION VARCHAR(1000) NULL,
|
||||
TENANT_ID INTEGER NOT NULL ,
|
||||
PROFILE_ID INTEGER NOT NULL ,
|
||||
@ -243,20 +244,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,
|
||||
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
|
||||
);
|
||||
|
||||
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,
|
||||
@ -294,6 +281,21 @@ 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 DEFAULT 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
|
||||
);
|
||||
|
||||
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,
|
||||
|
||||
@ -212,6 +212,7 @@ CREATE TABLE IF NOT EXISTS DM_POLICY (
|
||||
ID INT(11) NOT NULL AUTO_INCREMENT ,
|
||||
NAME VARCHAR(45) DEFAULT NULL ,
|
||||
DESCRIPTION VARCHAR(1000) NULL,
|
||||
PAYLOAD_VERSION VARCHAR (45) DEFAULT NULL,
|
||||
TENANT_ID INT(11) NOT NULL ,
|
||||
PROFILE_ID INT(11) NOT NULL ,
|
||||
OWNERSHIP_TYPE VARCHAR(45) NULL,
|
||||
@ -228,19 +229,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,
|
||||
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
|
||||
)ENGINE = InnoDB;
|
||||
|
||||
|
||||
CREATE TABLE IF NOT EXISTS DM_DEVICE_POLICY (
|
||||
ID INT(11) NOT NULL AUTO_INCREMENT ,
|
||||
@ -290,6 +278,20 @@ 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) DEFAULT NULL,
|
||||
IS_REACTIVE BOOLEAN NOT NULL DEFAULT FALSE,
|
||||
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
|
||||
)ENGINE = InnoDB;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS DM_ROLE_POLICY (
|
||||
ID INT(11) NOT NULL AUTO_INCREMENT ,
|
||||
|
||||
@ -320,6 +320,7 @@ CREATE TABLE DM_POLICY (
|
||||
ID NUMBER(10) NOT NULL ,
|
||||
NAME VARCHAR2(45) DEFAULT NULL ,
|
||||
DESCRIPTION VARCHAR2(1000) NULL,
|
||||
PAYLOAD_VERSION VARCHAR(45) DEFAULT NULL,
|
||||
TENANT_ID NUMBER(10) NOT NULL ,
|
||||
PROFILE_ID NUMBER(10) NOT NULL ,
|
||||
OWNERSHIP_TYPE VARCHAR2(45) NULL,
|
||||
@ -335,18 +336,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,
|
||||
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)
|
||||
)
|
||||
/
|
||||
|
||||
-- Generate ID using sequence and trigger
|
||||
CREATE SEQUENCE DM_POLICY_seq START WITH 1 INCREMENT BY 1 NOCACHE
|
||||
/
|
||||
@ -418,6 +407,19 @@ 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) DEFAULT 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)
|
||||
)
|
||||
/
|
||||
|
||||
-- Generate ID using sequence and trigger
|
||||
CREATE SEQUENCE DM_PROFILE_FEATURES_seq START WITH 1 INCREMENT BY 1 NOCACHE
|
||||
/
|
||||
|
||||
@ -219,6 +219,7 @@ CREATE SEQUENCE DM_POLICY_seq;
|
||||
CREATE TABLE IF NOT EXISTS DM_POLICY (
|
||||
ID INTEGER NOT NULL DEFAULT NEXTVAL ('DM_POLICY_seq') ,
|
||||
NAME VARCHAR(45) DEFAULT NULL ,
|
||||
PAYLOAD_VERSION VARCHAR(45) DEFAULT NULL,
|
||||
DESCRIPTION VARCHAR(1000) NULL,
|
||||
TENANT_ID INTEGER NOT NULL ,
|
||||
PROFILE_ID INTEGER NOT NULL ,
|
||||
@ -237,6 +238,19 @@ 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 DEFAULT 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
|
||||
);
|
||||
|
||||
|
||||
CREATE TABLE IF NOT EXISTS DM_DEVICE_POLICY (
|
||||
ID INTEGER NOT NULL DEFAULT NEXTVAL ('DM_DEVICE_POLICY_seq') ,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user