fixing policy errors

application-manager-new
Rasika Perera 10 years ago
parent 43a756d851
commit d6abb3fdd7

@ -26,14 +26,18 @@ policyModule = function () {
var publicMethods = {}; var publicMethods = {};
var privateMethods = {}; var privateMethods = {};
publicMethods.addPolicy = function (name, deviceType, policyDefinition, policyDescription) { publicMethods.addPolicy = function (policyName, deviceType, policyDefinition, policyDescription) {
if(policyName && deviceType){
return false;
}
var carbonModule = require("carbon"); var carbonModule = require("carbon");
var carbonServer = application.get("carbonServer"); var carbonServer = application.get("carbonServer");
var options = {system: true}; var options = {system: true};
var carbonUser = session.get(constants.USER_SESSION_KEY); var carbonUser = session.get(constants.USER_SESSION_KEY);
resource = { var resource = {
name: name, name: policyName,
mediaType: 'text/plain', mediaType: 'text/plain',
content: policyDefinition, content: policyDefinition,
description: policyDescription description: policyDescription
@ -42,11 +46,11 @@ policyModule = function () {
if (carbonUser) { if (carbonUser) {
options.tenantId = carbonUser.tenantId; options.tenantId = carbonUser.tenantId;
var registry = new carbonModule.registry.Registry(carbonServer, options); var registry = new carbonModule.registry.Registry(carbonServer, options);
log.info("########### Policy name : " + name); log.info("########### Policy name : " + policyName);
log.info("########### Policy type : " + deviceType); log.info("########### Policy type : " + deviceType);
log.info("########### Policy Declaration : " + policyDefinition); log.info("########### Policy Declaration : " + policyDefinition);
log.info("########### Policy policyDescription: " + policyDescription); log.info("########### Policy policyDescription: " + policyDescription);
registry.put(constants.POLICY_REGISTRY_PATH + deviceType + "/" + name, resource); registry.put(constants.POLICY_REGISTRY_PATH + deviceType + "/" + policyName, resource);
} }
var mqttsenderClass = Packages.org.wso2.device.mgt.mqtt.policy.push.MqttPush; var mqttsenderClass = Packages.org.wso2.device.mgt.mqtt.policy.push.MqttPush;
@ -55,6 +59,7 @@ 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;
}; };
publicMethods.getPolicies = function () { publicMethods.getPolicies = function () {

@ -173,7 +173,6 @@
<!--Later add the navigation menu from here--> <!--Later add the navigation menu from here-->
{{/zone}} {{/zone}}
{{#zone "action-bar"}} {{#zone "action-bar"}}
{{#if permissions.ADD_POLICY}}
<a href="/iotserver/policies/add-policy" class="cu-btn"> <a href="/iotserver/policies/add-policy" class="cu-btn">
<span class="fw-stack"> <span class="fw-stack">
<i class="fw fw-ring fw-stack-2x"></i> <i class="fw fw-ring fw-stack-2x"></i>
@ -181,7 +180,6 @@
</span> </span>
Add Policy Add Policy
</a> </a>
{{/if}}
{{/zone}} {{/zone}}
{{#zone "bottomJs"}} {{#zone "bottomJs"}}
<script src="{{self.publicURL}}/js/policy-listing.js"></script> <script src="{{self.publicURL}}/js/policy-listing.js"></script>

Loading…
Cancel
Save