fixing adding new policy not shown error

application-manager-new
Rasika Perera 10 years ago
parent dadf913a83
commit 6ea6551ada

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

@ -27,9 +27,7 @@ policyModule = function () {
var privateMethods = {}; var privateMethods = {};
publicMethods.addPolicy = function (policyName, deviceType, policyDefinition, policyDescription) { publicMethods.addPolicy = function (policyName, deviceType, policyDefinition, policyDescription) {
if(policyName && deviceType){ if (policyName && deviceType) {
return false;
}
var carbonModule = require("carbon"); var carbonModule = require("carbon");
var carbonServer = application.get("carbonServer"); var carbonServer = application.get("carbonServer");
@ -59,7 +57,12 @@ policyModule = function () {
var result = mqttsender.pushToMQTT("/iot/policymgt/govern", policyDefinition, "tcp://10.100.0.104:1883", "Raspberry-Policy-sender"); var result = mqttsender.pushToMQTT("/iot/policymgt/govern", policyDefinition, "tcp://10.100.0.104:1883", "Raspberry-Policy-sender");
mqttsender = null; mqttsender = null;
return true; return true;
} else {
return false;
}
}; };
publicMethods.getPolicies = function () { publicMethods.getPolicies = function () {
@ -82,7 +85,7 @@ policyModule = function () {
log.info("Policies for device types: " + allPolicies.content); log.info("Policies for device types: " + allPolicies.content);
log.info(""); log.info("");
var deviceType = allPolicies.content[i].replace(constants.POLICY_REGISTRY_PATH, ""); var deviceType = allPolicies.content[i].replace(constants.POLICY_REGISTRY_PATH, "");
log.info("##### deviceType:"+deviceType); log.info("##### deviceType:" + deviceType);
var deviceTypePolicies = registry.get(allPolicies.content[i]); var deviceTypePolicies = registry.get(allPolicies.content[i]);
//loop through policies //loop through policies
@ -96,7 +99,7 @@ policyModule = function () {
//"profile": {}, // Profile //"profile": {}, // Profile
"policyName": deviceTypePolicy.name, // Name of the policy. "policyName": deviceTypePolicy.name, // Name of the policy.
"updated": deviceTypePolicy.updated.time, "updated": deviceTypePolicy.updated.time,
"deviceType":deviceType "deviceType": deviceType
//"generic": true, // If true, this should be applied to all related device. //"generic": true, // If true, this should be applied to all related device.
//"roles": {}, // Roles which this policy should be applied. //"roles": {}, // Roles which this policy should be applied.
//"ownershipType": {}, // Ownership type (COPE, BYOD, CPE) //"ownershipType": {}, // Ownership type (COPE, BYOD, CPE)
@ -139,7 +142,7 @@ policyModule = function () {
try { try {
registry.remove(constants.POLICY_REGISTRY_PATH + deviceType + "/" + name); registry.remove(constants.POLICY_REGISTRY_PATH + deviceType + "/" + name);
bool = true; bool = true;
}catch(err){ } catch (err) {
log.error("Error while trying to remove policy :" + name); log.error("Error while trying to remove policy :" + name);
} }
} }

Loading…
Cancel
Save