adding policies

merge-requests/1/head
Rasika Perera 9 years ago
parent 987c35fecc
commit c7b3161231

@ -40,6 +40,37 @@ if (uriMatcher.match("/{context}/api/policies/update")) {
// http status code 500 refers to - Internal Server Error.
result = 500;
}
}else if (uriMatcher.match("/{context}/api/policies/update")) {
payload = request.getContent();
policyModule.updatePolicyPriorities(payload);
} else if (uriMatcher.match("/{context}/api/policies/add")) {
var content = request.getContent();
var id = content.policyName;
var policyDefinition = content.profile.policyDefinition;
var deviceType = content.profile.deviceType.id;
log.info("@@@@@ Policy Declaration : "+stringify(content));
try {
result = policyModule.addPolicy(id,deviceType,policyDefinition);
} catch (e) {
log.error("Exception occurred while trying to add new policy under name:" + id, e);
// http status code 500 refers to - Internal Server Error.
result = 500;
}
} else if (uriMatcher.match("/{context}/api/policies/get")) {
var id = request.getParameter("policyName");
var deviceType = request.getParameter("deviceTypeId");
log.info("@@@@@ Policy Declaration : "+stringify(content));
try {
result = policyModule.getPolicy(id,deviceType);
} catch (e) {
log.error("Exception occurred while trying to add new policy under name:" + id, e);
// http status code 500 refers to - Internal Server Error.
result = 500;
}
}
// returning the result.

@ -27,10 +27,45 @@ policyModule = function () {
var privateMethods = {};
publicMethods.addPolicy = function (name, deviceType, policyDefinition) {
var carbonModule = require("carbon");
var carbonServer = application.get("carbonServer");
var options = {system: true};
var carbonUser = session.get(constants.USER_SESSION_KEY);
resource = {
name : name,
mediaType: 'text/plain',
content : policyDefinition
};
if (carbonUser) {
options.tenantId = carbonUser.tenantId;
var registry = new carbonModule.registry.Registry(carbonServer, options);
log.info("########### Policy name : "+name);
log.info("########### Policy type : "+deviceType);
log.info("########### Policy Declarationsss : "+policyDefinition);
registry.put("/_system/governance/policy_declarations/" + deviceType + "/" + name, resource);
}
var mqttsenderClass = Packages.org.wso2.device.mgt.mqtt.policy.push.MqttPush;
var mqttsender = new mqttsenderClass();
var result = mqttsender.pushToMQTT("/iot/policymgt/govern",policyDefinition,"tcp://10.100.0.104:1883","Raspberry-Policy-sender");
mqttsender = null;
};
publicMethods.getPolicies = function () {
var carbonModule = require("carbon");
var carbonServer = application.get("carbonServer");
var options = {system: true};
var carbonUser = session.get(constants.USER_SESSION_KEY);
if (carbonUser) {
options.tenantId = carbonUser.tenantId;
var registry = new carbonModule.registry.Registry(carbonServer, options);
log.info(registry.get("/_system/governance/policy_declarations/firealarm/"));
}
//TODO-This method returns includes dummy policy data

@ -63,14 +63,12 @@ function savePolicy(){
}
};
console.log(payload);
invokerUtil.post("/iotserver/api/policies/add", payload, function(){
$(".policy-message").removeClass("hidden");
$(".add-policy").addClass("hidden");
}, function(){
//invokerUtil.post("/iotserver/policy-api/policy/add", payload, function(){
// $(".policy-message").removeClass("hidden");
// $(".add-policy").addClass("hidden");
//}, function(){
//
//});
});
}
$(document).ready(function(){
@ -105,7 +103,8 @@ $(document).ready(function(){
};
stepperRegistry['policy-profile'] = function (actionButton){
var deviceType = policy.devicetype;
policy.policyDefinition = $("#policy-definition-input").val();
console.log(window.queryEditor.getValue());
policy.policyDefinition = window.queryEditor.getValue();
};
stepperRegistry['policy-devicetype'] = function (actionButton){
policy.devicetype = $(actionButton).data("devicetype");

Loading…
Cancel
Save