diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/api/device-api.jag b/modules/distribution/src/repository/jaggeryapps/iotserver/api/device-api.jag
index 4bf153b9..75cc8b77 100644
--- a/modules/distribution/src/repository/jaggeryapps/iotserver/api/device-api.jag
+++ b/modules/distribution/src/repository/jaggeryapps/iotserver/api/device-api.jag
@@ -124,7 +124,12 @@ if (uriMatcher.match("/{context}/api/device/sketch/download/{downloadId}")) {
var data = {};
//XMLHTTPRequest's GET
- result = get(listAllDevicesEndPoint, data, "json");
+ try {
+ result = get(listAllDevicesEndPoint, data, "json");
+ }catch(err){
+ log.error("Error occured while retrieveing all devices with username: "+user.username);
+ result=[];
+ }
} else if (uriMatcher.match("/{context}/api/devices/types")) {
diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/modules/policy.js b/modules/distribution/src/repository/jaggeryapps/iotserver/modules/policy.js
new file mode 100644
index 00000000..f1f45132
--- /dev/null
+++ b/modules/distribution/src/repository/jaggeryapps/iotserver/modules/policy.js
@@ -0,0 +1,85 @@
+/*
+ * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
+ *
+ * WSO2 Inc. licenses this file to you under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
+ * either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+var policyModule;
+policyModule = function () {
+ var log = new Log("modules/policy.js");
+
+ var constants = require("/modules/constants.js");
+ var utility = require("/modules/utility.js").utility;
+
+ var userManagementService = utility.getUserManagementService();
+
+ var publicMethods = {};
+ var privateMethods = {};
+
+ publicMethods.getPolicies = function () {
+
+ //TODO-This method returns includes dummy policy data
+
+ var policies = [];
+ var policyObj = {
+ "id":1, // Identifier of the policy.
+ "priorityId":1, // Priority of the policies. This will be used only for simple evaluation.
+ "profile":{}, // Profile
+ "policyName":"Turn off light", // Name of the policy.
+ "generic":true, // If true, this should be applied to all related device.
+ "roles":{}, // Roles which this policy should be applied.
+ "ownershipType":{}, // Ownership type (COPE, BYOD, CPE)
+ "devices":{}, // Individual devices this policy should be applied
+ "users":{}, // Individual users this policy should be applied
+ "Compliance":{},
+ "policyCriterias":{},
+ "startTime":283468236, // Start time to apply the policy.
+ "endTime":283468236, // After this time policy will not be applied
+ "startDate":"", // Start date to apply the policy
+ "endDate":"", // After this date policy will not be applied.
+ "tenantId":-1234,
+ "profileId":1
+ };
+
+ policies.push(policyObj);
+
+ policyObj = {
+ "id":2, // Identifier of the policy.
+ "priorityId":1, // Priority of the policies. This will be used only for simple evaluation.
+ "profile":{}, // Profile
+ "policyName":"Turn on Buzzer", // Name of the policy.
+ "generic":false, // If true, this should be applied to all related device.
+ "roles":{}, // Roles which this policy should be applied.
+ "ownershipType":{}, // Ownership type (COPE, BYOD, CPE)
+ "devices":{}, // Individual devices this policy should be applied
+ "users":{}, // Individual users this policy should be applied
+ "Compliance":{},
+ "policyCriterias":{},
+ "startTime":283468236, // Start time to apply the policy.
+ "endTime":283468236, // After this time policy will not be applied
+ "startDate":"", // Start date to apply the policy
+ "endDate":"", // After this date policy will not be applied.
+ "tenantId":-1234,
+ "profileId":2
+ };
+
+ policies.push(policyObj);
+ return policies;
+ };
+
+ return publicMethods;
+}();
+
+
diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/modules/user.js b/modules/distribution/src/repository/jaggeryapps/iotserver/modules/user.js
index 803df504..01c9e1b5 100644
--- a/modules/distribution/src/repository/jaggeryapps/iotserver/modules/user.js
+++ b/modules/distribution/src/repository/jaggeryapps/iotserver/modules/user.js
@@ -310,6 +310,34 @@ userModule = function () {
return permissions;
};
+ /**
+ * Get User Roles from user store.
+ * If "Internal/Everyone" role is required - true param needs to be passed.
+ * @param enableInternalEveryone boolean value true/false to enable Internal/Everyone role
+ */
+ publicMethods.getRoles = function (enableInternalEveryone) {
+ var carbonModule = require("carbon");
+ var carbonServer = application.get("carbonServer");
+ var carbonUser = session.get(constants.USER_SESSION_KEY);
+ if (!carbonUser) {
+ log.error("User object was not found in the session");
+ throw constants.ERRORS.USER_NOT_FOUND;
+ }
+ var userManager = new carbonModule.user.UserManager(carbonServer, carbonUser.tenantId);
+ var allRoles = userManager.allRoles();
+ var filteredRoles = [];
+ var i;
+ for (i = 0; i < allRoles.length; i++) {
+ if (enableInternalEveryone && allRoles[i] == "Internal/everyone") {
+ filteredRoles.push(allRoles[i]);
+ }
+ if (allRoles[i].indexOf("Internal/") != 0) {
+ filteredRoles.push(allRoles[i]);
+ }
+ }
+ return filteredRoles;
+ };
+
publicMethods.logout = function (successCallback) {
session.invalidate();
successCallback();
diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/modules/utility.js b/modules/distribution/src/repository/jaggeryapps/iotserver/modules/utility.js
index 31f68927..7117b6fe 100644
--- a/modules/distribution/src/repository/jaggeryapps/iotserver/modules/utility.js
+++ b/modules/distribution/src/repository/jaggeryapps/iotserver/modules/utility.js
@@ -20,6 +20,7 @@ var utility;
utility = function () {
var JavaClass = Packages.java.lang.Class;
var PrivilegedCarbonContext = Packages.org.wso2.carbon.context.PrivilegedCarbonContext;
+ var userManagement = Packages.org.wso2.carbon.device.mgt.iot.common.UserManagement();
var getOsgiService = function (className) {
return PrivilegedCarbonContext.getThreadLocalCarbonContext().getOSGiService(JavaClass.forName(className));
@@ -32,7 +33,7 @@ utility = function () {
};
publicMethods.getUserManagementService = function () {
- return Packages.org.wso2.carbon.device.mgt.iot.common.UserManagement();
+ return userManagement;
};
publicMethods.getPolicyManagementService = function () {
diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/pages/policies/add-policy.hbs b/modules/distribution/src/repository/jaggeryapps/iotserver/pages/policies/add-policy.hbs
new file mode 100644
index 00000000..f8a1adc7
--- /dev/null
+++ b/modules/distribution/src/repository/jaggeryapps/iotserver/pages/policies/add-policy.hbs
@@ -0,0 +1,9 @@
+{{authorized}}
+{{layout "fluid"}}
+{{#zone "title"}}
+ WSO2 DC | Add New Policy
+{{/zone}}
+{{#zone "body"}}
+ {{unit "appbar" link="policies" title="My Policies"}}
+ {{unit "policy-create"}}
+{{/zone}}
\ No newline at end of file
diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/pages/policies/index.hbs b/modules/distribution/src/repository/jaggeryapps/iotserver/pages/policies/index.hbs
new file mode 100644
index 00000000..cb210ed1
--- /dev/null
+++ b/modules/distribution/src/repository/jaggeryapps/iotserver/pages/policies/index.hbs
@@ -0,0 +1,21 @@
+{{authorized}}
+{{layout "fluid"}}
+{{#zone "title"}}
+ Policies
+{{/zone}}
+{{#zone "body"}}
+ {{unit "appbar" link="policies" title="My Policies"}}
+ {{unit "extended-search-box"}}
+
+
+
+
+
+
+
+ {{unit "policy-listing"}}
+
+
+
+
+{{/zone}}
\ No newline at end of file
diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/units/appbar/appbar.hbs b/modules/distribution/src/repository/jaggeryapps/iotserver/units/appbar/appbar.hbs
index 4067deba..20489738 100644
--- a/modules/distribution/src/repository/jaggeryapps/iotserver/units/appbar/appbar.hbs
+++ b/modules/distribution/src/repository/jaggeryapps/iotserver/units/appbar/appbar.hbs
@@ -45,7 +45,7 @@
{{#if permissions.ADD_USER}}
\ No newline at end of file
diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/units/policy-create/public/templates/hidden-operations-ios.hbs b/modules/distribution/src/repository/jaggeryapps/iotserver/units/policy-create/public/templates/hidden-operations-ios.hbs
new file mode 100644
index 00000000..4cb006ef
--- /dev/null
+++ b/modules/distribution/src/repository/jaggeryapps/iotserver/units/policy-create/public/templates/hidden-operations-ios.hbs
@@ -0,0 +1,366 @@
+
\ No newline at end of file
diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/units/policy-detail/policy-detail.hbs b/modules/distribution/src/repository/jaggeryapps/iotserver/units/policy-detail/policy-detail.hbs
new file mode 100644
index 00000000..bf566146
--- /dev/null
+++ b/modules/distribution/src/repository/jaggeryapps/iotserver/units/policy-detail/policy-detail.hbs
@@ -0,0 +1,201 @@
+{{#zone "main"}}
+