From 864ee109a5ef05e861c8e1ecf50ea056b71bb92c Mon Sep 17 00:00:00 2001 From: Rasika Perera Date: Fri, 7 Aug 2015 11:17:25 +0530 Subject: [PATCH] adding policy owner parameter --- .../jaggeryapps/iotserver/modules/policy.js | 13 ++++++++++--- .../units/policy-listing/policy-listing.hbs | 2 -- .../units/policy-listing/policy-listing.js | 2 +- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/modules/policy.js b/modules/distribution/src/repository/jaggeryapps/iotserver/modules/policy.js index c1b8e822..a9137582 100755 --- a/modules/distribution/src/repository/jaggeryapps/iotserver/modules/policy.js +++ b/modules/distribution/src/repository/jaggeryapps/iotserver/modules/policy.js @@ -38,7 +38,8 @@ policyModule = function () { name: policyName, mediaType: 'text/plain', content: policyDefinition, - description: policyDescription + description: policyDescription, + properties:{owner: carbonUser.username} }; if (carbonUser) { @@ -54,7 +55,7 @@ policyModule = function () { var mqttsenderClass = Packages.org.wso2.device.mgt.mqtt.policy.push.MqttPush; var mqttsender = new mqttsenderClass(); - var result = mqttsender.pushToMQTT("/iot/policymgt/govern", policyDefinition, "tcp://localhost:1883", "Raspberry-Policy-sender"); + var result = mqttsender.pushToMQTT("/iot/policymgt/govern/" + deviceType + "/" + carbonUser.username, policyDefinition, "tcp://localhost:1883", "Raspberry-Policy-sender"); mqttsender = null; @@ -88,6 +89,12 @@ policyModule = function () { //loop through policies for (var j = 0; j < deviceTypePolicies.content.length; j++) { var deviceTypePolicy = registry.get(deviceTypePolicies.content[j]); + + if(stringify(registry.properties(deviceTypePolicies.content[j]).owner) != '["'+carbonUser.username+'"]'){ + //not owned by current user, skip it + continue; + } + var policyObj = { "id": deviceTypePolicy.uuid, // Identifier of the policy. //"priorityId": 1, // Priority of the policies. This will be used only for simple evaluation. @@ -136,7 +143,7 @@ policyModule = function () { registry.remove(constants.POLICY_REGISTRY_PATH + deviceType + "/" + name); bool = true; } catch (err) { - log.error("Error while trying to remove policy :" + name); + log.error("Error while trying to remove policy :" + name, err); } } diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/units/policy-listing/policy-listing.hbs b/modules/distribution/src/repository/jaggeryapps/iotserver/units/policy-listing/policy-listing.hbs index 3484060b..77701f63 100644 --- a/modules/distribution/src/repository/jaggeryapps/iotserver/units/policy-listing/policy-listing.hbs +++ b/modules/distribution/src/repository/jaggeryapps/iotserver/units/policy-listing/policy-listing.hbs @@ -3,8 +3,6 @@
-

Policies

-

{{listPolicyStatus}}

diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/units/policy-listing/policy-listing.js b/modules/distribution/src/repository/jaggeryapps/iotserver/units/policy-listing/policy-listing.js index 5da8aee7..d7f2da5c 100644 --- a/modules/distribution/src/repository/jaggeryapps/iotserver/units/policy-listing/policy-listing.js +++ b/modules/distribution/src/repository/jaggeryapps/iotserver/units/policy-listing/policy-listing.js @@ -5,7 +5,7 @@ function onRequest(context) { //log.info((allPolicies)); if (!allPolicies || allPolicies.length == 0) { context.policies = []; - context.listPolicyStatus = "Oops, Sorry, No other Policies found."; + context.listPolicyStatus = ""; } else { var i, filteredPoliciesList = []; for (i = 0; i < allPolicies.length; i++) {