From bbff93adcc13599b1a406c82392aa355f1f1e5e4 Mon Sep 17 00:00:00 2001 From: dilanua Date: Mon, 1 Aug 2016 18:50:47 +0530 Subject: [PATCH 01/13] Updating token-handler-utils with suppressed warnings for java packg imports --- .../app/modules/oauth/token-handler-utils.js | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/oauth/token-handler-utils.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/oauth/token-handler-utils.js index 1ed0291e37..dc2655233f 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/oauth/token-handler-utils.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/oauth/token-handler-utils.js @@ -19,22 +19,26 @@ var utils = function () { var log = new Log("/app/modules/oauth/token-handler-utils.js"); - var deviceMgtProps = require("/app/conf/reader/main.js")["conf"]; + var deviceMgtProps = require("/app/modules/conf-reader/main.js")["conf"]; var constants = require("/app/modules/constants.js"); var carbon = require("carbon"); + //noinspection JSUnresolvedVariable var Base64 = Packages.org.apache.commons.codec.binary.Base64; + //noinspection JSUnresolvedVariable var String = Packages.java.lang.String; var publicMethods = {}; var privateMethods = {}; publicMethods.encode = function (payload) { - return new String(Base64.encodeBase64(new String(payload).getBytes())); + //noinspection JSUnresolvedFunction + return String(Base64.encodeBase64(String(payload).getBytes())); }; publicMethods.decode = function (payload) { - return new String(Base64.decodeBase64(new String(payload).getBytes())); + //noinspection JSUnresolvedFunction + return String(Base64.decodeBase64(String(payload).getBytes())); }; publicMethods.getDynamicClientAppCredentials = function () { @@ -117,8 +121,8 @@ var utils = function () { } else { var assertionXML = publicMethods.decode(assertion); /* - TODO: make assertion extraction with proper parsing. Since Jaggery XML parser seem - to add formatting which causes signature verification to fail. + TODO: make assertion extraction with proper parsing. + Since Jaggery XML parser seem to add formatting which causes signature verification to fail. */ var assertionStartMarker = " Date: Mon, 1 Aug 2016 19:06:04 +0530 Subject: [PATCH 02/13] Adding conf-reader to UI modules --- .../jaggeryapps/devicemgt/api/data-tables-invoker-api.jag | 2 +- .../resources/jaggeryapps/devicemgt/api/device-api.jag | 2 +- .../resources/jaggeryapps/devicemgt/api/group-api.jag | 2 +- .../resources/jaggeryapps/devicemgt/api/invoker-api.jag | 2 +- .../resources/jaggeryapps/devicemgt/api/operation-api.jag | 2 +- .../main/resources/jaggeryapps/devicemgt/api/user-api.jag | 2 +- .../app/{conf/reader => modules/conf-reader}/main.js | 8 +++++--- .../app/{conf/reader => modules/conf-reader}/pinch.min.js | 0 .../resources/jaggeryapps/devicemgt/app/modules/device.js | 2 +- .../resources/jaggeryapps/devicemgt/app/modules/group.js | 2 +- .../resources/jaggeryapps/devicemgt/app/modules/init.js | 2 +- .../resources/jaggeryapps/devicemgt/app/modules/login.js | 2 +- .../devicemgt/app/modules/oauth/token-handlers.js | 2 +- .../app/modules/oauth/token-protected-service-invokers.js | 2 +- .../jaggeryapps/devicemgt/app/modules/operation.js | 2 +- .../resources/jaggeryapps/devicemgt/app/modules/policy.js | 2 +- .../resources/jaggeryapps/devicemgt/app/modules/user.js | 2 +- .../jaggeryapps/devicemgt/app/modules/utility.js | 2 +- .../devicemgt/app/pages/cdmf.page.dashboard/dashboard.js | 2 +- .../devicemgt/app/pages/cdmf.page.group.create/create.js | 2 +- .../devicemgt/app/pages/cdmf.page.user.create/create.js | 2 +- .../devicemgt/app/pages/cdmf.page.user.edit/edit.js | 2 +- .../devicemgt/app/pages/cdmf.page.users/users.js | 2 +- .../app/units/cdmf.unit.device.type.view/view.js | 2 +- .../devicemgt/app/units/cdmf.unit.role.create/create.js | 2 +- .../devicemgt/app/units/cdmf.unit.role.edit/edit.js | 2 +- .../devicemgt/app/units/cdmf.unit.role.listing/listing.js | 2 +- .../app/units/cdmf.unit.ui.navbar.nav-menu/nav-menu.js | 2 +- 28 files changed, 31 insertions(+), 29 deletions(-) rename components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/{conf/reader => modules/conf-reader}/main.js (84%) rename components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/{conf/reader => modules/conf-reader}/pinch.min.js (100%) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/api/data-tables-invoker-api.jag b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/api/data-tables-invoker-api.jag index 6777383200..ce0dbd1d41 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/api/data-tables-invoker-api.jag +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/api/data-tables-invoker-api.jag @@ -22,7 +22,7 @@ var log = new Log("api/data-tables-invoker-api.jag"); var uri = request.getRequestURI(); var uriMatcher = new URIMatcher(String(uri)); -var devicemgtProps = require("/app/conf/reader/main.js")["conf"]; +var devicemgtProps = require("/app/modules/conf-reader/main.js")["conf"]; var serviceInvokers = require("/app/modules/oauth/token-protected-service-invokers.js")["invokers"]; function appendQueryParam (url, queryParam , value) { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/api/device-api.jag b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/api/device-api.jag index 74ba1290d4..937d396885 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/api/device-api.jag +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/api/device-api.jag @@ -24,7 +24,7 @@ var log = new Log("api/device-api.jag"); var constants = require("/app/modules/constants.js"); var deviceModule = require("/app/modules/device.js").deviceModule; var utility = require("/app/modules/utility.js").utility; -var devicemgtProps = require("/app/conf/reader/main.js")["conf"]; +var devicemgtProps = require("/app/modules/conf-reader/main.js")["conf"]; var userModule = require("/app/modules/user.js").userModule; var serviceInvokers = require("/app/modules/oauth/token-protected-service-invokers.js")["invokers"]; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/api/group-api.jag b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/api/group-api.jag index cfce1f0409..2ba4ebba9e 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/api/group-api.jag +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/api/group-api.jag @@ -23,7 +23,7 @@ var uriMatcher = new URIMatcher(String(uri)); var log = new Log("api/device-api.jag"); var constants = require("/app/modules/constants.js"); var utility = require("/app/modules/utility.js").utility; -var devicemgtProps = require("/app/conf/reader/main.js")["conf"]; +var devicemgtProps = require("/app/modules/conf-reader/main.js")["conf"]; var serviceInvokers = require("/app/modules/oauth/token-protected-service-invokers.js")["invokers"]; var user = session.get(constants.USER_SESSION_KEY); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/api/invoker-api.jag b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/api/invoker-api.jag index 741bf1ed53..3e410ee2c5 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/api/invoker-api.jag +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/api/invoker-api.jag @@ -23,7 +23,7 @@ var uri = request.getRequestURI(); var uriMatcher = new URIMatcher(String(uri)); var constants = require("/app/modules/constants.js"); -var devicemgtProps = require("/app/conf/reader/main.js")["conf"]; +var devicemgtProps = require("/app/modules/conf-reader/main.js")["conf"]; var serviceInvokers = require("/app/modules/oauth/token-protected-service-invokers.js")["invokers"]; if (uriMatcher.match("/{context}/api/invoker/execute/")) { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/api/operation-api.jag b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/api/operation-api.jag index 99fa61a9f9..c6dca89321 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/api/operation-api.jag +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/api/operation-api.jag @@ -23,7 +23,7 @@ var uriMatcher = new URIMatcher(String(uri)); var log = new Log("api/operation-api.jag"); var serviceInvokers = require("/app/modules/oauth/token-protected-service-invokers.js")["invokers"]; -var devicemgtProps = require("/app/conf/reader/main.js")["conf"]; +var devicemgtProps = require("/app/modules/conf-reader/main.js")["conf"]; if (uriMatcher.match("/{context}/api/operation/paginate")) { var deviceType = request.getParameter("deviceType"); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/api/user-api.jag b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/api/user-api.jag index b8f495aa7c..3c11d19fde 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/api/user-api.jag +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/api/user-api.jag @@ -23,7 +23,7 @@ var uriMatcher = new URIMatcher(String(uri)); var log = new Log("api/user-api.jag"); var constants = require("/app/modules/constants.js"); -var devicemgtProps = require("/app/conf/reader/main.js")["conf"]; +var devicemgtProps = require("/app/modules/conf-reader/main.js")["conf"]; var userModule = require("/app/modules/user.js").userModule; var deviceModule = require("/app/modules/device.js").deviceModule; var utility = require("/app/modules/utility.js").utility; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/conf/reader/main.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/conf-reader/main.js similarity index 84% rename from components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/conf/reader/main.js rename to components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/conf-reader/main.js index ec5b6642f2..f81849fe3b 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/conf/reader/main.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/conf-reader/main.js @@ -17,16 +17,18 @@ */ var conf = function () { - var conf = application.get("UI_CONF"); + var conf = application.get("CONF"); if (!conf) { conf = require("/app/conf/config.json"); - var pinch = require("/app/conf/reader/pinch.min.js")["pinch"]; + var pinch = require("/app/modules/conf-reader/pinch.min.js")["pinch"]; var server = require("carbon")["server"]; pinch(conf, /^/, function (path, key, value) { if ((typeof value === "string") && value.indexOf("%https.ip%") > -1) { + //noinspection JSUnresolvedFunction return value.replace("%https.ip%", server.address("https")); } else if ((typeof value === "string") && value.indexOf("%http.ip%") > -1) { + //noinspection JSUnresolvedFunction return value.replace("%http.ip%", server.address("http")); } else if ((typeof value === "string") && value.indexOf("%date-year%") > -1) { var year = new Date().getFullYear(); @@ -35,7 +37,7 @@ var conf = function () { return value; } ); - application.put("UI_CONF", conf); + application.put("CONF", conf); } return conf; }(); \ No newline at end of file diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/conf/reader/pinch.min.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/conf-reader/pinch.min.js similarity index 100% rename from components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/conf/reader/pinch.min.js rename to components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/conf-reader/pinch.min.js diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/device.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/device.js index cb640d4537..071154584d 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/device.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/device.js @@ -22,7 +22,7 @@ deviceModule = function () { var utility = require('/app/modules/utility.js').utility; var constants = require('/app/modules/constants.js'); - var devicemgtProps = require("/app/conf/reader/main.js")["conf"]; + var devicemgtProps = require("/app/modules/conf-reader/main.js")["conf"]; var serviceInvokers = require("/app/modules/oauth/token-protected-service-invokers.js")["invokers"]; // var ArrayList = Packages.java.util.ArrayList; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/group.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/group.js index 549d0d8787..c2567cec29 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/group.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/group.js @@ -22,7 +22,7 @@ var groupModule = {}; var userModule = require("/app/modules/user.js").userModule; var constants = require('/app/modules/constants.js'); - var devicemgtProps = require("/app/conf/reader/main.js")["conf"]; + var devicemgtProps = require("/app/modules/conf-reader/main.js")["conf"]; var utility = require("/app/modules/utility.js").utility; var serviceInvokers = require("/app/modules/oauth/token-protected-service-invokers.js")["invokers"]; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/init.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/init.js index 35c902dbab..8e86f44ab8 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/init.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/init.js @@ -17,7 +17,7 @@ */ var carbonModule = require("carbon"); -var devicemgtProps = require("/app/conf/reader/main.js")["conf"]; +var devicemgtProps = require("/app/modules/conf-reader/main.js")["conf"]; var carbonServer = new carbonModule.server.Server({ tenanted: true, url: devicemgtProps["httpsURL"] + "/admin" diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/login.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/login.js index c383e1e817..87f840d3ce 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/login.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/login.js @@ -30,7 +30,7 @@ var onFail; } else { apiWrapperUtil.setupTokenPairByPasswordGrantType(context.input.username, context.input.password); } - var devicemgtProps = require("/app/conf/reader/main.js")["conf"]; + var devicemgtProps = require("/app/modules/conf-reader/main.js")["conf"]; var carbonServer = require("carbon").server; (new carbonServer.Server({url: devicemgtProps["adminService"]})) .login(context.input.username, context.input.password); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/oauth/token-handlers.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/oauth/token-handlers.js index 64b0c1894a..4943a2d823 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/oauth/token-handlers.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/oauth/token-handlers.js @@ -27,7 +27,7 @@ var handlers = function () { var tokenUtil = require("/app/modules/oauth/token-handler-utils.js")["utils"]; var constants = require("/app/modules/constants.js"); - var devicemgtProps = require("/app/conf/reader/main.js")["conf"]; + var devicemgtProps = require("/app/modules/conf-reader/main.js")["conf"]; var publicMethods = {}; var privateMethods = {}; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/oauth/token-protected-service-invokers.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/oauth/token-protected-service-invokers.js index 2b9a3d09c9..d94ea02f48 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/oauth/token-protected-service-invokers.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/oauth/token-protected-service-invokers.js @@ -35,7 +35,7 @@ var invokers = function () { var TOKEN_EXPIRED = "Access token expired"; var TOKEN_INVALID = "Invalid input. Access token validation failed"; - var devicemgtProps = require("/app/conf/reader/main.js")["conf"]; + var devicemgtProps = require("/app/modules/conf-reader/main.js")["conf"]; var constants = require("/app/modules/constants.js"); var userModule = require("/app/modules/user.js")["userModule"]; var tokenUtil = require("/app/modules/oauth/token-handlers.js")["handlers"]; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/operation.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/operation.js index 98890b9a19..9f75d4eb17 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/operation.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/operation.js @@ -20,7 +20,7 @@ var operationModule = function () { var log = new Log("/app/modules/operation.js"); var utility = require('/app/modules/utility.js').utility; var constants = require('/app/modules/constants.js'); - var devicemgtProps = require("/app/conf/reader/main.js")["conf"]; + var devicemgtProps = require("/app/modules/conf-reader/main.js")["conf"]; var serviceInvokers = require("/app/modules/oauth/token-protected-service-invokers.js")["invokers"]; var publicMethods = {}; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/policy.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/policy.js index 0fbe5a2116..998e6722d1 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/policy.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/policy.js @@ -25,7 +25,7 @@ policyModule = function () { var constants = require('/app/modules/constants.js'); var utility = require("/app/modules/utility.js")["utility"]; - var devicemgtProps = require("/app/conf/reader/main.js")["conf"]; + var devicemgtProps = require("/app/modules/conf-reader/main.js")["conf"]; var serviceInvokers = require("/app/modules/oauth/token-protected-service-invokers.js")["invokers"]; var publicMethods = {}; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/user.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/user.js index 2a28f5fddf..29a7de7365 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/user.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/user.js @@ -24,7 +24,7 @@ var userModule = function () { var constants = require("/app/modules/constants.js"); var utility = require("/app/modules/utility.js")["utility"]; - var devicemgtProps = require("/app/conf/reader/main.js")["conf"]; + var devicemgtProps = require("/app/modules/conf-reader/main.js")["conf"]; var serviceInvokers = require("/app/modules/oauth/token-protected-service-invokers.js")["invokers"]; /* Initializing user manager */ diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/utility.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/utility.js index b63edc3a2a..f5dd896bc4 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/utility.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/utility.js @@ -20,7 +20,7 @@ var utility; utility = function () { var constants = require('/app/modules/constants.js'); - var devicemgtProps = require("/app/conf/reader/main.js")["conf"]; + var devicemgtProps = require("/app/modules/conf-reader/main.js")["conf"]; var log = new Log("/app/modules/utility.js"); var JavaClass = Packages.java.lang.Class; var PrivilegedCarbonContext = Packages.org.wso2.carbon.context.PrivilegedCarbonContext; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.dashboard/dashboard.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.dashboard/dashboard.js index a3b0875812..8681882f2e 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.dashboard/dashboard.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.dashboard/dashboard.js @@ -21,7 +21,7 @@ function onRequest(context) { var user = session.get(constants.USER_SESSION_KEY); var userModule = require("/app/modules/user.js").userModule; var permissions = userModule.getUIPermissions(); - var devicemgtProps = require("/app/conf/reader/main.js")["conf"]; + var devicemgtProps = require("/app/modules/conf-reader/main.js")["conf"]; if (!permissions.VIEW_DASHBOARD) { response.sendRedirect(constants.WEB_APP_CONTEXT + "/devices"); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.group.create/create.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.group.create/create.js index ebfda4568b..350d245d1f 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.group.create/create.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.group.create/create.js @@ -23,7 +23,7 @@ * @returns {*} A context object that returns the dynamic state of this page to be presented */ function onRequest(context) { - var devicemgtProps = require("/app/conf/reader/main.js")["conf"]; + var devicemgtProps = require("/app/modules/conf-reader/main.js")["conf"]; var page = {}; page["groupNameJSRegEx"] = devicemgtProps.groupValidationConfig.groupNameJSRegEx; page["groupNameRegExViolationErrorMsg"] = devicemgtProps.groupValidationConfig.groupNameRegExViolationErrorMsg; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.user.create/create.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.user.create/create.js index 70e9089a5f..cbd0564b15 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.user.create/create.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.user.create/create.js @@ -26,7 +26,7 @@ function onRequest(context) { //var log = new Log("/app/pages/cdmf.page.user.create server-side js"); var userModule = require("/app/modules/user.js")["userModule"]; - var devicemgtProps = require("/app/conf/reader/main.js")["conf"]; + var devicemgtProps = require("/app/modules/conf-reader/main.js")["conf"]; var page = {}; var response = userModule.getRolesByUserStore(); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.user.edit/edit.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.user.edit/edit.js index 8f94c2902b..7037721ad9 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.user.edit/edit.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.user.edit/edit.js @@ -20,7 +20,7 @@ function onRequest(context) { var userModule = require("/app/modules/user.js").userModule; var userName = request.getParameter("username"); var user = userModule.getUser(userName)["content"]; - var devicemgtProps = require("/app/conf/reader/main.js")["conf"]; + var devicemgtProps = require("/app/modules/conf-reader/main.js")["conf"]; if (user) { var title; if (user.firstname || user.lastname) { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.users/users.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.users/users.js index 98ddb20716..df93724633 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.users/users.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.users/users.js @@ -29,7 +29,7 @@ function onRequest(context) { var page = {}; var userModule = require("/app/modules/user.js")["userModule"]; - var deviceMgtProps = require("/app/conf/reader/main.js")["conf"]; + var deviceMgtProps = require("/app/modules/conf-reader/main.js")["conf"]; page["adminUser"] = deviceMgtProps["adminUser"]; page["permissions"] = userModule.getUIPermissions(); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.view/view.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.view/view.js index 9cf038f561..f003d47581 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.view/view.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.view/view.js @@ -30,7 +30,7 @@ function onRequest (context) { var userModule = require("/app/modules/user.js").userModule; var constants = require("/app/modules/constants.js"); var permissions = userModule.getUIPermissions(); - var deviceMgtProps = require("/app/conf/reader/main.js")["conf"]; + var deviceMgtProps = require("/app/modules/conf-reader/main.js")["conf"]; context.permissions = permissions; context["enrollmentURL"] = deviceMgtProps.enrollmentURL; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.role.create/create.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.role.create/create.js index db293c3bf6..9e00dc32aa 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.role.create/create.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.role.create/create.js @@ -24,7 +24,7 @@ */ function onRequest(context) { var userModule = require("/app/modules/user.js")["userModule"]; - var deviceMgtProps = require("/app/conf/reader/main.js")["conf"]; + var deviceMgtProps = require("/app/modules/conf-reader/main.js")["conf"]; var response = userModule.getRoles(); if (response["status"] == "success") { context["roles"] = response["content"]; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.role.edit/edit.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.role.edit/edit.js index 5e24261bd2..01a08da69f 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.role.edit/edit.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.role.edit/edit.js @@ -24,7 +24,7 @@ */ function onRequest(context) { var userModule = require("/app/modules/user.js")["userModule"]; - var deviceMgtProps = require("/app/conf/reader/main.js")["conf"]; + var deviceMgtProps = require("/app/modules/conf-reader/main.js")["conf"]; var uri = request.getRequestURI(); var uriMatcher = new URIMatcher(String(uri)); var isMatched = uriMatcher.match("/{context}/role/edit/{rolename}"); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.role.listing/listing.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.role.listing/listing.js index 681883aae3..c5c67d1029 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.role.listing/listing.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.role.listing/listing.js @@ -30,7 +30,7 @@ function onRequest(context) { if (userModule.isAuthorized("/permission/admin/device-mgt/roles/remove")) { context["removePermitted"] = true; } - var deviceMgtProps = require("/app/conf/reader/main.js")["conf"]; + var deviceMgtProps = require("/app/modules/conf-reader/main.js")["conf"]; context["appContext"] = deviceMgtProps.appContext; context["adminRole"] = deviceMgtProps.adminRole; return context; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.ui.navbar.nav-menu/nav-menu.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.ui.navbar.nav-menu/nav-menu.js index 89213cf587..3f4ede1774 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.ui.navbar.nav-menu/nav-menu.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.ui.navbar.nav-menu/nav-menu.js @@ -28,7 +28,7 @@ function onRequest(context) { } }); var userModule = require("/app/modules/user.js")["userModule"]; - var mdmProps = require('/app/conf/reader/main.js')["conf"]; + var mdmProps = require("/app/modules/conf-reader/main.js")["conf"]; var constants = require("/app/modules/constants.js"); var uiPermissions = userModule.getUIPermissions(); context["permissions"] = uiPermissions; From 89cebcdb9e68139a5d23d33b7b9ec816e5578148 Mon Sep 17 00:00:00 2001 From: dilanua Date: Mon, 1 Aug 2016 19:28:05 +0530 Subject: [PATCH 03/13] Updating UI oauth module with suppressed warnings for verified, but unresolved variables and functions --- .../app/modules/oauth/token-handler-utils.js | 158 +++++++++--------- .../app/modules/oauth/token-handlers.js | 8 +- .../oauth/token-protected-service-invokers.js | 54 ++++-- 3 files changed, 120 insertions(+), 100 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/oauth/token-handler-utils.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/oauth/token-handler-utils.js index dc2655233f..180438518f 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/oauth/token-handler-utils.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/oauth/token-handler-utils.js @@ -31,17 +31,17 @@ var utils = function () { var publicMethods = {}; var privateMethods = {}; - publicMethods.encode = function (payload) { + publicMethods["encode"] = function (payload) { //noinspection JSUnresolvedFunction return String(Base64.encodeBase64(String(payload).getBytes())); }; - publicMethods.decode = function (payload) { + publicMethods["decode"] = function (payload) { //noinspection JSUnresolvedFunction return String(Base64.decodeBase64(String(payload).getBytes())); }; - publicMethods.getDynamicClientAppCredentials = function () { + publicMethods["getDynamicClientAppCredentials"] = function () { // setting up dynamic client application properties var dcAppProperties = { "applicationType": deviceMgtProps["oauthProvider"]["appRegistration"]["appType"], @@ -80,7 +80,79 @@ var utils = function () { return dynamicClientAppCredentials; }; - publicMethods.getTokenPairByPasswordGrantType = function (username, password, encodedClientAppCredentials, scopes) { + publicMethods["getTenantBasedClientAppCredentials"] = function (username, jwtToken) { + if (!username || !jwtToken) { + log.error("{/app/modules/oauth/token-handler-utils.js} Error in retrieving tenant " + + "based client app credentials. No username or jwt token is found " + + "as input - getTenantBasedClientAppCredentials(x, y)"); + return null; + } else { + //noinspection JSUnresolvedFunction, JSUnresolvedVariable + var tenantDomain = carbon.server.tenantDomain({username: username}); + if (!tenantDomain) { + log.error("{/app/modules/oauth/token-handler-utils.js} Error in retrieving tenant " + + "based client application credentials. Unable to obtain a valid tenant domain for provided " + + "username - getTenantBasedClientAppCredentials(x, y)"); + return null; + } else { + var cachedTenantBasedClientAppCredentials = privateMethods. + getCachedTenantBasedClientAppCredentials(tenantDomain); + if (cachedTenantBasedClientAppCredentials) { + return cachedTenantBasedClientAppCredentials; + } else { + // register a tenant based client app at API Manager + var applicationName = "webapp_" + tenantDomain; + var requestURL = deviceMgtProps["oauthProvider"]["appRegistration"] + ["apiManagerClientAppRegistrationServiceURL"] + + "?tenantDomain=" + tenantDomain + "&applicationName=" + applicationName; + + var xhr = new XMLHttpRequest(); + xhr.open("POST", requestURL, false); + xhr.setRequestHeader("Content-Type", "application/json"); + xhr.setRequestHeader("Authorization", "Bearer " + jwtToken); + xhr.send(); + + if (xhr["status"] == 201 && xhr["responseText"]) { + var responsePayload = parse(xhr["responseText"]); + var tenantBasedClientAppCredentials = {}; + tenantBasedClientAppCredentials["clientId"] = responsePayload["client_id"]; + tenantBasedClientAppCredentials["clientSecret"] = responsePayload["client_secret"]; + privateMethods. + setCachedTenantBasedClientAppCredentials(tenantDomain, tenantBasedClientAppCredentials); + return tenantBasedClientAppCredentials; + } else { + log.error("{/app/modules/oauth/token-handler-utils.js} Error in retrieving tenant " + + "based client application credentials from API " + + "Manager - getTenantBasedClientAppCredentials(x, y)"); + return null; + } + } + } + } + }; + + privateMethods["setCachedTenantBasedClientAppCredentials"] = function (tenantDomain, clientAppCredentials) { + var cachedTenantBasedClientAppCredentialsMap = application.get(constants["CACHED_CREDENTIALS"]); + if (!cachedTenantBasedClientAppCredentialsMap) { + cachedTenantBasedClientAppCredentialsMap = {}; + cachedTenantBasedClientAppCredentialsMap[tenantDomain] = clientAppCredentials; + application.put(constants["CACHED_CREDENTIALS"], cachedTenantBasedClientAppCredentialsMap); + } else if (!cachedTenantBasedClientAppCredentialsMap[tenantDomain]) { + cachedTenantBasedClientAppCredentialsMap[tenantDomain] = clientAppCredentials; + } + }; + + privateMethods["getCachedTenantBasedClientAppCredentials"] = function (tenantDomain) { + var cachedTenantBasedClientAppCredentialsMap = application.get(constants["CACHED_CREDENTIALS"]); + if (!cachedTenantBasedClientAppCredentialsMap || + !cachedTenantBasedClientAppCredentialsMap[tenantDomain]) { + return null; + } else { + return cachedTenantBasedClientAppCredentialsMap[tenantDomain]; + } + }; + + publicMethods["getTokenPairByPasswordGrantType"] = function (username, password, encodedClientAppCredentials, scopes) { if (!username || !password || !encodedClientAppCredentials || !scopes) { log.error("{/app/modules/oauth/token-handler-utils.js} Error in retrieving access token by password " + "grant type. No username, password, encoded client app credentials or scopes are " + @@ -112,7 +184,7 @@ var utils = function () { } }; - publicMethods.getTokenPairBySAMLGrantType = function (assertion, encodedClientAppCredentials, scopes) { + publicMethods["getTokenPairBySAMLGrantType"] = function (assertion, encodedClientAppCredentials, scopes) { if (!assertion || !encodedClientAppCredentials || !scopes) { log.error("{/app/modules/oauth/token-handler-utils.js} Error in retrieving access token by saml " + "grant type. No assertion, encoded client app credentials or scopes are " + @@ -165,7 +237,7 @@ var utils = function () { } }; - publicMethods.getNewTokenPairByRefreshToken = function (refreshToken, encodedClientAppCredentials, scopes) { + publicMethods["getNewTokenPairByRefreshToken"] = function (refreshToken, encodedClientAppCredentials, scopes) { if (!refreshToken || !encodedClientAppCredentials) { log.error("{/app/modules/oauth/token-handler-utils.js} Error in retrieving new access token " + "by current refresh token. No refresh token or encoded client app credentials are " + @@ -198,7 +270,7 @@ var utils = function () { } }; - publicMethods.getAccessTokenByJWTGrantType = function (clientAppCredentials) { + publicMethods["getAccessTokenByJWTGrantType"] = function (clientAppCredentials) { if (!clientAppCredentials) { log.error("{/app/modules/oauth/token-handler-utils.js} Error in retrieving new access token " + "by current refresh token. No client app credentials are found " + @@ -217,77 +289,5 @@ var utils = function () { } }; - publicMethods.getTenantBasedClientAppCredentials = function (username, jwtToken) { - if (!username || !jwtToken) { - log.error("{/app/modules/oauth/token-handler-utils.js} Error in retrieving tenant " + - "based client app credentials. No username or jwt token is found " + - "as input - getTenantBasedClientAppCredentials(x, y)"); - return null; - } else { - //noinspection JSUnresolvedFunction, JSUnresolvedVariable - var tenantDomain = carbon.server.tenantDomain({username: username}); - if (!tenantDomain) { - log.error("{/app/modules/oauth/token-handler-utils.js} Error in retrieving tenant " + - "based client application credentials. Unable to obtain a valid tenant domain for provided " + - "username - getTenantBasedClientAppCredentials(x, y)"); - return null; - } else { - var cachedTenantBasedClientAppCredentials = privateMethods. - getCachedTenantBasedClientAppCredentials(tenantDomain); - if (cachedTenantBasedClientAppCredentials) { - return cachedTenantBasedClientAppCredentials; - } else { - // register a tenant based client app at API Manager - var applicationName = "webapp_" + tenantDomain; - var requestURL = deviceMgtProps["oauthProvider"]["appRegistration"] - ["apiManagerClientAppRegistrationServiceURL"] + - "?tenantDomain=" + tenantDomain + "&applicationName=" + applicationName; - - var xhr = new XMLHttpRequest(); - xhr.open("POST", requestURL, false); - xhr.setRequestHeader("Content-Type", "application/json"); - xhr.setRequestHeader("Authorization", "Bearer " + jwtToken); - xhr.send(); - - if (xhr["status"] == 201 && xhr["responseText"]) { - var responsePayload = parse(xhr["responseText"]); - var tenantBasedClientAppCredentials = {}; - tenantBasedClientAppCredentials["clientId"] = responsePayload["client_id"]; - tenantBasedClientAppCredentials["clientSecret"] = responsePayload["client_secret"]; - privateMethods. - setCachedTenantBasedClientAppCredentials(tenantDomain, tenantBasedClientAppCredentials); - return tenantBasedClientAppCredentials; - } else { - log.error("{/app/modules/oauth/token-handler-utils.js} Error in retrieving tenant " + - "based client application credentials from API " + - "Manager - getTenantBasedClientAppCredentials(x, y)"); - return null; - } - } - } - } - }; - - privateMethods.setCachedTenantBasedClientAppCredentials = function (tenantDomain, clientAppCredentials) { - var cachedTenantBasedClientAppCredentialsMap = application.get(constants["CACHED_CREDENTIALS"]); - if (!cachedTenantBasedClientAppCredentialsMap) { - cachedTenantBasedClientAppCredentialsMap = {}; - cachedTenantBasedClientAppCredentialsMap[tenantDomain] = clientAppCredentials; - application.put(constants["CACHED_CREDENTIALS"], cachedTenantBasedClientAppCredentialsMap); - } else if (!cachedTenantBasedClientAppCredentialsMap[tenantDomain]) { - cachedTenantBasedClientAppCredentialsMap[tenantDomain] = clientAppCredentials; - } - }; - - privateMethods.getCachedTenantBasedClientAppCredentials = function (tenantDomain) { - var cachedTenantBasedClientAppCredentialsMap = application.get(constants["CACHED_CREDENTIALS"]); - if (!cachedTenantBasedClientAppCredentialsMap || - !cachedTenantBasedClientAppCredentialsMap[tenantDomain]) { - return null; - } else { - return cachedTenantBasedClientAppCredentialsMap[tenantDomain]; - } - }; - return publicMethods; }(); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/oauth/token-handlers.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/oauth/token-handlers.js index 4943a2d823..af8a7e6674 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/oauth/token-handlers.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/oauth/token-handlers.js @@ -32,7 +32,7 @@ var handlers = function () { var publicMethods = {}; var privateMethods = {}; - publicMethods.setupTokenPairByPasswordGrantType = function (username, password) { + publicMethods["setupTokenPairByPasswordGrantType"] = function (username, password) { if (!username || !password) { throw new Error("{/app/modules/oauth/token-handlers.js} Could not set up access token pair by " + "password grant type. Either username of logged in user, password or both are missing " + @@ -67,7 +67,7 @@ var handlers = function () { } }; - publicMethods.setupTokenPairBySamlGrantType = function (username, samlToken) { + publicMethods["setupTokenPairBySamlGrantType"] = function (username, samlToken) { if (!username || !samlToken) { throw new Error("{/app/modules/oauth/token-handlers.js} Could not set up access token pair by " + "saml grant type. Either username of logged in user, samlToken or both are missing " + @@ -96,7 +96,7 @@ var handlers = function () { } }; - publicMethods.refreshTokenPair = function () { + publicMethods["refreshTokenPair"] = function () { var currentTokenPair = parse(session.get(constants["TOKEN_PAIR"])); // currentTokenPair includes current access token as well as current refresh token var encodedClientAppCredentials = session.get(constants["ENCODED_TENANT_BASED_CLIENT_APP_CREDENTIALS"]); @@ -116,7 +116,7 @@ var handlers = function () { } }; - privateMethods.setUpEncodedTenantBasedClientAppCredentials = function (username) { + privateMethods["setUpEncodedTenantBasedClientAppCredentials"] = function (username) { if (!username) { throw new Error("{/app/modules/oauth/token-handlers.js} Could not set up encoded tenant based " + "client credentials to session context. No username of logged in user is found as " + diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/oauth/token-protected-service-invokers.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/oauth/token-protected-service-invokers.js index d94ea02f48..9c217a52dd 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/oauth/token-protected-service-invokers.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/oauth/token-protected-service-invokers.js @@ -67,7 +67,7 @@ var invokers = function () { * @param responseCallback a function to be called with response retrieved. * @param count a counter which hold the number of recursive execution */ - privateMethods.execute = function (httpMethod, requestPayload, endpoint, responseCallback, count) { + privateMethods["execute"] = function (httpMethod, requestPayload, endpoint, responseCallback, count) { var xmlHttpRequest = new XMLHttpRequest(); xmlHttpRequest.open(httpMethod, endpoint); @@ -81,8 +81,8 @@ var invokers = function () { response.sendRedirect(devicemgtProps["appContext"] + "login"); }); } else { - xmlHttpRequest. - setRequestHeader(constants["AUTHORIZATION_HEADER"], constants["BEARER_PREFIX"] + accessToken); + xmlHttpRequest.setRequestHeader(constants["AUTHORIZATION_HEADER"], + constants["BEARER_PREFIX"] + accessToken); } } @@ -99,7 +99,6 @@ var invokers = function () { log.info("Request payload if any : " + stringify(requestPayload)); log.info("Response status : " + xmlHttpRequest.status); log.info("Response payload if any : " + xmlHttpRequest.responseText); - //log.info("Response headers : " + xmlHttpRequest.getAllResponseHeaders()); if (xmlHttpRequest.status == 401 && (xmlHttpRequest.responseText == TOKEN_EXPIRED || xmlHttpRequest.responseText == TOKEN_INVALID ) && count < 5) { @@ -117,7 +116,7 @@ var invokers = function () { * @param endpoint Backend REST API url. * @param responseCallback a function to be called with response retrieved. */ - privateMethods.initiateXMLHTTPRequest = function (httpMethod, requestPayload, endpoint, responseCallback) { + privateMethods["initiateXMLHTTPRequest"] = function (httpMethod, requestPayload, endpoint, responseCallback) { return privateMethods.execute(httpMethod, requestPayload, endpoint, responseCallback, 0); }; @@ -126,7 +125,7 @@ var invokers = function () { * @param endpoint Backend REST API url. * @param responseCallback a function to be called with response retrieved. */ - publicXMLHTTPInvokers.get = function (endpoint, responseCallback) { + publicXMLHTTPInvokers["get"] = function (endpoint, responseCallback) { var requestPayload = null; return privateMethods.initiateXMLHTTPRequest(constants["HTTP_GET"], requestPayload, endpoint, responseCallback); }; @@ -137,7 +136,7 @@ var invokers = function () { * @param requestPayload payload/data if exists which is needed to be send. * @param responseCallback a function to be called with response retrieved. */ - publicXMLHTTPInvokers.post = function (endpoint, requestPayload, responseCallback) { + publicXMLHTTPInvokers["post"] = function (endpoint, requestPayload, responseCallback) { return privateMethods.initiateXMLHTTPRequest(constants["HTTP_POST"], requestPayload, endpoint, responseCallback); }; @@ -147,7 +146,7 @@ var invokers = function () { * @param requestPayload payload/data if exists which is needed to be send. * @param responseCallback a function to be called with response retrieved. */ - publicXMLHTTPInvokers.put = function (endpoint, requestPayload, responseCallback) { + publicXMLHTTPInvokers["put"] = function (endpoint, requestPayload, responseCallback) { return privateMethods.initiateXMLHTTPRequest(constants["HTTP_PUT"], requestPayload, endpoint, responseCallback); }; @@ -156,7 +155,7 @@ var invokers = function () { * @param endpoint Backend REST API url. * @param responseCallback a function to be called with response retrieved. */ - publicXMLHTTPInvokers.delete = function (endpoint, responseCallback) { + publicXMLHTTPInvokers["delete"] = function (endpoint, responseCallback) { var requestPayload = null; return privateMethods.initiateXMLHTTPRequest(constants["HTTP_DELETE"], requestPayload, endpoint, responseCallback); }; @@ -176,8 +175,10 @@ var invokers = function () { * @param errorCallback a function to be called if en error is reserved. * @param soapVersion soapVersion which need to used. */ - privateMethods.initiateWSRequest = function (action, endpoint, successCallback, errorCallback, soapVersion, payload) { + privateMethods["initiateWSRequest"] = function (action, endpoint, successCallback, + errorCallback, soapVersion, payload) { var ws = require("ws"); + //noinspection JSUnresolvedFunction var wsRequest = new ws.WSRequest(); var options = []; if (devicemgtProps["isOAuthEnabled"]) { @@ -222,8 +223,10 @@ var invokers = function () { * @param errorCallback a function to be called if en error is reserved. * @param soapVersion soapVersion which need to used. */ - publicWSInvokers.soapRequest = function (action, requestPayload, endpoint, successCallback, errorCallback, soapVersion) { - return privateMethods.initiateWSRequest(action, endpoint, successCallback, errorCallback, soapVersion, requestPayload); + publicWSInvokers["soapRequest"] = function (action, requestPayload, endpoint, + successCallback, errorCallback, soapVersion) { + return privateMethods.initiateWSRequest(action, endpoint, successCallback, + errorCallback, soapVersion, requestPayload); }; /** @@ -240,37 +243,46 @@ var invokers = function () { * @param successCallback a function to be called if the respond if successful. * @param errorCallback a function to be called if en error is reserved. */ - privateMethods.initiateHTTPClientRequest = function (method, url, successCallback, errorCallback, payload) { + privateMethods["initiateHTTPClientRequest"] = function (method, url, successCallback, errorCallback, payload) { + //noinspection JSUnresolvedVariable var HttpClient = Packages.org.apache.commons.httpclient.HttpClient; var httpMethodObject; switch (method) { case constants["HTTP_GET"]: + //noinspection JSUnresolvedVariable var GetMethod = Packages.org.apache.commons.httpclient.methods.GetMethod; httpMethodObject = new GetMethod(url); break; case constants["HTTP_POST"]: + //noinspection JSUnresolvedVariable var PostMethod = Packages.org.apache.commons.httpclient.methods.PostMethod; httpMethodObject = new PostMethod(url); break; case constants["HTTP_PUT"]: + //noinspection JSUnresolvedVariable var PutMethod = Packages.org.apache.commons.httpclient.methods.PutMethod; httpMethodObject = new PutMethod(url); break; case constants["HTTP_DELETE"]: + //noinspection JSUnresolvedVariable var DeleteMethod = Packages.org.apache.commons.httpclient.methods.DeleteMethod; httpMethodObject = new DeleteMethod(url); break; default: + //noinspection JSUnresolvedFunction throw new IllegalArgumentException("Invalid HTTP request method: " + method); } + //noinspection JSUnresolvedVariable var Header = Packages.org.apache.commons.httpclient.Header; var header = new Header(); header.setName(constants["CONTENT_TYPE_IDENTIFIER"]); header.setValue(constants["APPLICATION_JSON"]); + //noinspection JSUnresolvedFunction httpMethodObject.addRequestHeader(header); header = new Header(); header.setName(constants["ACCEPT_IDENTIFIER"]); header.setValue(constants["APPLICATION_JSON"]); + //noinspection JSUnresolvedFunction httpMethodObject.addRequestHeader(header); if (devicemgtProps["isOAuthEnabled"]) { @@ -279,25 +291,33 @@ var invokers = function () { header = new Header(); header.setName(constants["AUTHORIZATION_HEADER"]); header.setValue(constants["BEARER_PREFIX"] + accessToken); + //noinspection JSUnresolvedFunction httpMethodObject.addRequestHeader(header); } else { response.sendRedirect(devicemgtProps["appContext"] + "login"); } } + //noinspection JSUnresolvedFunction var stringRequestEntity = new StringRequestEntity(stringify(payload)); + //noinspection JSUnresolvedFunction httpMethodObject.setRequestEntity(stringRequestEntity); var client = new HttpClient(); try { + //noinspection JSUnresolvedFunction client.executeMethod(httpMethodObject); + //noinspection JSUnresolvedFunction var status = httpMethodObject.getStatusCode(); if (status == 200) { + //noinspection JSUnresolvedFunction return successCallback(httpMethodObject.getResponseBody()); } else { + //noinspection JSUnresolvedFunction return errorCallback(httpMethodObject.getResponseBody()); } } catch (e) { return errorCallback(response); } finally { + //noinspection JSUnresolvedFunction method.releaseConnection(); } }; @@ -308,7 +328,7 @@ var invokers = function () { * @param successCallback a function to be called if the respond if successful. * @param errorCallback a function to be called if en error is reserved. */ - publicHTTPClientInvokers.get = function (url, successCallback, errorCallback) { + publicHTTPClientInvokers["get"] = function (url, successCallback, errorCallback) { var requestPayload = null; return privateMethods. initiateHTTPClientRequest(constants["HTTP_GET"], url, successCallback, errorCallback, requestPayload); @@ -321,7 +341,7 @@ var invokers = function () { * @param successCallback a function to be called if the respond if successful. * @param errorCallback a function to be called if en error is reserved. */ - publicHTTPClientInvokers.post = function (url, payload, successCallback, errorCallback) { + publicHTTPClientInvokers["post"] = function (url, payload, successCallback, errorCallback) { return privateMethods. initiateHTTPClientRequest(constants["HTTP_POST"], url, successCallback, errorCallback, payload); }; @@ -333,7 +353,7 @@ var invokers = function () { * @param successCallback a function to be called if the respond if successful. * @param errorCallback a function to be called if en error is reserved. */ - publicHTTPClientInvokers.put = function (url, payload, successCallback, errorCallback) { + publicHTTPClientInvokers["put"] = function (url, payload, successCallback, errorCallback) { return privateMethods. initiateHTTPClientRequest(constants["HTTP_PUT"], url, successCallback, errorCallback, payload); }; @@ -344,7 +364,7 @@ var invokers = function () { * @param successCallback a function to be called if the respond if successful. * @param errorCallback a function to be called if en error is reserved. */ - publicHTTPClientInvokers.delete = function (url, successCallback, errorCallback) { + publicHTTPClientInvokers["delete"] = function (url, successCallback, errorCallback) { var requestPayload = null; return privateMethods. initiateHTTPClientRequest(constants["HTTP_DELETE"], url, successCallback, errorCallback, requestPayload); From ec7f8ccd1fda8312e1c5b94b54b09d69b12b638d Mon Sep 17 00:00:00 2001 From: dilanua Date: Mon, 1 Aug 2016 20:28:39 +0530 Subject: [PATCH 04/13] disabling testing info logs at token-protected-service-invokers.js --- .../app/modules/oauth/token-protected-service-invokers.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/oauth/token-protected-service-invokers.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/oauth/token-protected-service-invokers.js index 9c217a52dd..4994e160bf 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/oauth/token-protected-service-invokers.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/oauth/token-protected-service-invokers.js @@ -95,10 +95,10 @@ var invokers = function () { log.debug("Service Invoker-URL: " + endpoint); log.debug("Service Invoker-Method: " + httpMethod); - log.info("Request : " + httpMethod + " " + endpoint); - log.info("Request payload if any : " + stringify(requestPayload)); - log.info("Response status : " + xmlHttpRequest.status); - log.info("Response payload if any : " + xmlHttpRequest.responseText); +// log.info("Request : " + httpMethod + " " + endpoint); +// log.info("Request payload if any : " + stringify(requestPayload)); +// log.info("Response status : " + xmlHttpRequest.status); +// log.info("Response payload if any : " + xmlHttpRequest.responseText); if (xmlHttpRequest.status == 401 && (xmlHttpRequest.responseText == TOKEN_EXPIRED || xmlHttpRequest.responseText == TOKEN_INVALID ) && count < 5) { From 6cc1bb088cabc2023823078eee7d9a8a56646338 Mon Sep 17 00:00:00 2001 From: harshanl Date: Mon, 1 Aug 2016 20:29:21 +0530 Subject: [PATCH 05/13] Fixed EMM-1447, EMM-1424 --- .../impl/ActivityProviderServiceImpl.java | 2 +- .../impl/DeviceManagementServiceImpl.java | 4 +- .../NotificationManagementServiceImpl.java | 1 + .../impl/PolicyManagementServiceImpl.java | 1 + .../impl/RoleManagementServiceImpl.java | 1 + .../impl/UserManagementServiceImpl.java | 2 + .../DeviceManagementAdminServiceImpl.java | 2 + .../impl/util/RequestValidationUtil.java | 14 ++++ .../core/config/DeviceManagementConfig.java | 11 +++ .../pagination/PaginationConfiguration.java | 71 ++++++++++++++++ .../NotificationManagementServiceImpl.java | 3 + .../DeviceManagementProviderServiceImpl.java | 9 ++ .../mgt/core/util/DeviceManagerUtil.java | 84 ++++++++++++++++++- .../src/main/resources/conf/cdm-config.xml | 14 +++- 14 files changed, 209 insertions(+), 10 deletions(-) create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/pagination/PaginationConfiguration.java diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/ActivityProviderServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/ActivityProviderServiceImpl.java index 444854e1e4..b80889f41b 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/ActivityProviderServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/ActivityProviderServiceImpl.java @@ -81,7 +81,7 @@ public class ActivityProviderServiceImpl implements ActivityInfoProviderService long timestamp = 0; boolean isIfModifiedSinceSet = false; boolean isSinceSet = false; - + RequestValidationUtil.validatePaginationParameters(offset, limit); if (ifModifiedSince != null && !ifModifiedSince.isEmpty()) { Date ifSinceDate; SimpleDateFormat format = new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss Z"); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceManagementServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceManagementServiceImpl.java index 2266f51d4a..2fafc9b129 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceManagementServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceManagementServiceImpl.java @@ -74,7 +74,7 @@ public class DeviceManagementServiceImpl implements DeviceManagementService { @QueryParam("limit") int limit) { try { // RequestValidationUtil.validateSelectionCriteria(type, user, roleName, ownership, status); - + RequestValidationUtil.validatePaginationParameters(offset, limit); DeviceManagementProviderService dms = DeviceMgtAPIUtils.getDeviceManagementService(); PaginationRequest request = new PaginationRequest(offset, limit); PaginationResult result; @@ -154,6 +154,7 @@ public class DeviceManagementServiceImpl implements DeviceManagementService { public Response getDeviceByUser(@QueryParam("offset") int offset, @QueryParam("limit") int limit) { + RequestValidationUtil.validatePaginationParameters(offset, limit); PaginationRequest request = new PaginationRequest(offset, limit); PaginationResult result; DeviceList devices = new DeviceList(); @@ -292,6 +293,7 @@ public class DeviceManagementServiceImpl implements DeviceManagementService { @QueryParam("offset") int offset, @QueryParam("limit") int limit) { OperationList operationsList = new OperationList(); + RequestValidationUtil.validatePaginationParameters(offset, limit); PaginationRequest request = new PaginationRequest(offset, limit); PaginationResult result; DeviceManagementProviderService dms; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/NotificationManagementServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/NotificationManagementServiceImpl.java index c504da33d1..acfe66f043 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/NotificationManagementServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/NotificationManagementServiceImpl.java @@ -50,6 +50,7 @@ public class NotificationManagementServiceImpl implements NotificationManagement @HeaderParam("If-Modified-Since") String ifModifiedSince, @QueryParam("offset") int offset, @QueryParam("limit") int limit) { + RequestValidationUtil.validatePaginationParameters(offset, limit); PaginationRequest request = new PaginationRequest(offset, limit); PaginationResult result; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/PolicyManagementServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/PolicyManagementServiceImpl.java index 487cdc1517..a47e85e5c1 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/PolicyManagementServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/PolicyManagementServiceImpl.java @@ -140,6 +140,7 @@ public class PolicyManagementServiceImpl implements PolicyManagementService { @HeaderParam("If-Modified-Since") String ifModifiedSince, @QueryParam("offset") int offset, @QueryParam("limit") int limit) { + RequestValidationUtil.validatePaginationParameters(offset, limit); PolicyManagerService policyManagementService = DeviceMgtAPIUtils.getPolicyManagementService(); List policies; List filteredPolicies; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/RoleManagementServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/RoleManagementServiceImpl.java index e0a832a77c..dab2affc1a 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/RoleManagementServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/RoleManagementServiceImpl.java @@ -61,6 +61,7 @@ public class RoleManagementServiceImpl implements RoleManagementService { @QueryParam("user-store") String userStore, @HeaderParam("If-Modified-Since") String ifModifiedSince, @QueryParam("offset") int offset, @QueryParam("limit") int limit) { + RequestValidationUtil.validatePaginationParameters(offset, limit); List filteredRoles; RoleList targetRoles = new RoleList(); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/UserManagementServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/UserManagementServiceImpl.java index ffad2e8d81..eda434e2f8 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/UserManagementServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/UserManagementServiceImpl.java @@ -26,6 +26,7 @@ import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService; import org.wso2.carbon.device.mgt.core.service.EmailMetaInfo; import org.wso2.carbon.device.mgt.jaxrs.beans.*; import org.wso2.carbon.device.mgt.jaxrs.service.api.UserManagementService; +import org.wso2.carbon.device.mgt.jaxrs.service.impl.util.RequestValidationUtil; import org.wso2.carbon.device.mgt.jaxrs.util.Constants; import org.wso2.carbon.device.mgt.jaxrs.util.CredentialManagementResponseBuilder; import org.wso2.carbon.device.mgt.jaxrs.util.DeviceMgtAPIUtils; @@ -264,6 +265,7 @@ public class UserManagementServiceImpl implements UserManagementService { log.debug("Getting the list of users with all user-related information"); } List userList, offsetList; + RequestValidationUtil.validatePaginationParameters(offset, limit); String appliedFilter = ((filter == null) || filter.isEmpty() ? "*" : filter); int appliedLimit = (limit <= 0) ? -1 : (limit + offset); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/admin/DeviceManagementAdminServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/admin/DeviceManagementAdminServiceImpl.java index 4956583627..26ac8dd8d2 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/admin/DeviceManagementAdminServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/admin/DeviceManagementAdminServiceImpl.java @@ -28,6 +28,7 @@ import org.wso2.carbon.device.mgt.common.DeviceManagementException; import org.wso2.carbon.device.mgt.jaxrs.beans.DeviceList; import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse; import org.wso2.carbon.device.mgt.jaxrs.service.api.admin.DeviceManagementAdminService; +import org.wso2.carbon.device.mgt.jaxrs.service.impl.util.RequestValidationUtil; import org.wso2.carbon.device.mgt.jaxrs.util.DeviceMgtAPIUtils; import javax.ws.rs.*; @@ -50,6 +51,7 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe @HeaderParam("If-Modified-Since") String ifModifiedSince, @QueryParam("offset") int offset, @QueryParam("limit") int limit) { + RequestValidationUtil.validatePaginationParameters(offset, limit); try { int currentTenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId(); if (MultitenantConstants.SUPER_TENANT_ID != currentTenantId) { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/util/RequestValidationUtil.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/util/RequestValidationUtil.java index 5d0a585ca7..3a4c4b5c63 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/util/RequestValidationUtil.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/util/RequestValidationUtil.java @@ -19,6 +19,7 @@ package org.wso2.carbon.device.mgt.jaxrs.service.impl.util; import org.wso2.carbon.device.mgt.common.DeviceIdentifier; +import org.wso2.carbon.device.mgt.common.PaginationRequest; import org.wso2.carbon.device.mgt.common.configuration.mgt.PlatformConfiguration; import org.wso2.carbon.device.mgt.common.notification.mgt.Notification; import org.wso2.carbon.device.mgt.jaxrs.beans.*; @@ -312,4 +313,17 @@ public class RequestValidationUtil { } } + public static void validatePaginationParameters(int offset, int limit) { + if (offset < 0) { + throw new InputValidationException( + new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage("Request parameter offset is s " + + "negative value.").build()); + } + if (limit < 0) { + throw new InputValidationException( + new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage("Request parameter limit is a " + + "negative value.").build()); + } + } + } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/DeviceManagementConfig.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/DeviceManagementConfig.java index 0891164cb0..20e4eba5c2 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/DeviceManagementConfig.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/DeviceManagementConfig.java @@ -18,6 +18,7 @@ package org.wso2.carbon.device.mgt.core.config; import org.wso2.carbon.device.mgt.core.config.identity.IdentityConfigurations; +import org.wso2.carbon.device.mgt.core.config.pagination.PaginationConfiguration; import org.wso2.carbon.device.mgt.core.config.policy.PolicyConfiguration; import org.wso2.carbon.device.mgt.core.config.task.TaskConfiguration; @@ -37,6 +38,7 @@ public final class DeviceManagementConfig { private TaskConfiguration taskConfiguration; private IdentityConfigurations identityConfigurations; private PolicyConfiguration policyConfiguration; + private PaginationConfiguration paginationConfiguration; private List pushNotificationProviders; @@ -87,5 +89,14 @@ public final class DeviceManagementConfig { this.pushNotificationProviders = pushNotificationProviders; } + @XmlElement(name = "PaginationConfiguration", required = true) + public PaginationConfiguration getPaginationConfiguration() { + return paginationConfiguration; + } + + public void setPaginationConfiguration(PaginationConfiguration paginationConfiguration) { + this.paginationConfiguration = paginationConfiguration; + } + } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/pagination/PaginationConfiguration.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/pagination/PaginationConfiguration.java new file mode 100644 index 0000000000..f60f33d98f --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/pagination/PaginationConfiguration.java @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2016, 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. + */ + +package org.wso2.carbon.device.mgt.core.config.pagination; + +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; + +/** + * This class represents the information related to Pagination configuration. + */ +@XmlRootElement(name = "PaginationConfiguration") +public class PaginationConfiguration { + + private int deviceListPageSize; + private int operationListPageSize; + private int notificationListPageSize; + private int activityListPageSize; + + public int getDeviceListPageSize() { + return deviceListPageSize; + } + + @XmlElement(name = "DeviceListPageSize", required = true) + public void setDeviceListPageSize(int deviceListPageSize) { + this.deviceListPageSize = deviceListPageSize; + } + + public int getOperationListPageSize() { + return operationListPageSize; + } + + @XmlElement(name = "OperationListPageSize", required = true) + public void setOperationListPageSize(int operationListPageSize) { + this.operationListPageSize = operationListPageSize; + } + + public int getNotificationListPageSize() { + return notificationListPageSize; + } + + @XmlElement(name = "NotificationListPageSize", required = true) + public void setNotificationListPageSize(int notificationListPageSize) { + this.notificationListPageSize = notificationListPageSize; + } + + public int getActivityListPageSize() { + return activityListPageSize; + } + + @XmlElement(name = "ActivityListPageSize", required = true) + public void setActivityListPageSize(int activityListPageSize) { + this.activityListPageSize = activityListPageSize; + } + +} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/notification/mgt/NotificationManagementServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/notification/mgt/NotificationManagementServiceImpl.java index 59692da94d..88883a4e26 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/notification/mgt/NotificationManagementServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/notification/mgt/NotificationManagementServiceImpl.java @@ -35,6 +35,7 @@ import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory; import org.wso2.carbon.device.mgt.core.notification.mgt.dao.NotificationDAO; import org.wso2.carbon.device.mgt.core.notification.mgt.dao.NotificationManagementDAOFactory; import org.wso2.carbon.device.mgt.core.notification.mgt.dao.util.NotificationDAOUtil; +import org.wso2.carbon.device.mgt.core.util.DeviceManagerUtil; import java.sql.SQLException; import java.util.ArrayList; @@ -177,6 +178,7 @@ public class NotificationManagementServiceImpl implements NotificationManagement public PaginationResult getAllNotifications(PaginationRequest request) throws NotificationManagementException { PaginationResult paginationResult = new PaginationResult(); List notifications = new ArrayList<>(); + request = DeviceManagerUtil.validateNotificationListPageSize(request); int count =0; try { NotificationManagementDAOFactory.openConnection(); @@ -199,6 +201,7 @@ public class NotificationManagementServiceImpl implements NotificationManagement PaginationRequest request) throws NotificationManagementException{ PaginationResult paginationResult = new PaginationResult(); List notifications = new ArrayList<>(); + request = DeviceManagerUtil.validateNotificationListPageSize(request); int count =0; try { NotificationManagementDAOFactory.openConnection(); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java index 314a26c392..73533f36fd 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java @@ -508,6 +508,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv int count = 0; int tenantId = this.getTenantId(); String deviceType = request.getDeviceType(); + request = DeviceManagerUtil.validateDeviceListPageSize(request); try { DeviceManagementDAOFactory.openConnection(); allDevices = deviceDAO.getDevices(request, tenantId); @@ -569,6 +570,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv List allDevices = new ArrayList<>(); int count = 0; int tenantId = this.getTenantId(); + request = DeviceManagerUtil.validateDeviceListPageSize(request); try { DeviceManagementDAOFactory.openConnection(); allDevices = deviceDAO.getDevices(request, tenantId); @@ -1031,6 +1033,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv @Override public PaginationResult getOperations(DeviceIdentifier deviceId, PaginationRequest request) throws OperationManagementException { + request = DeviceManagerUtil.validateOperationListPageSize(request); return pluginRepository.getOperationManager(deviceId.getType(), this.getTenantId()) .getOperations(deviceId, request); } @@ -1091,6 +1094,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv @Override public List getActivitiesUpdatedAfter(long timestamp, int limit, int offset) throws OperationManagementException { + limit = DeviceManagerUtil.validateActivityListPageSize(limit); return DeviceManagementDataHolder.getInstance().getOperationManager().getActivitiesUpdatedAfter(timestamp, limit, offset); } @@ -1176,6 +1180,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv String username = request.getOwner(); List devices = new ArrayList<>(); List userDevices = new ArrayList<>(); + request = DeviceManagerUtil.validateDeviceListPageSize(request); try { DeviceManagementDAOFactory.openConnection(); userDevices = deviceDAO.getDevicesOfUser(request, tenantId); @@ -1253,6 +1258,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv int deviceCount = 0; int tenantId = this.getTenantId(); String ownerShip = request.getOwnership(); + request = DeviceManagerUtil.validateDeviceListPageSize(request); try { DeviceManagementDAOFactory.openConnection(); allDevices = deviceDAO.getDevicesByOwnership(request, tenantId); @@ -1412,6 +1418,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv public List getDevicesByNameAndType(String deviceName, String type, int offset, int limit) throws DeviceManagementException { List devices = new ArrayList<>(); List allDevices; + limit = DeviceManagerUtil.validateDeviceListPageSize(limit); try { DeviceManagementDAOFactory.openConnection(); allDevices = deviceDAO.getDevicesByNameAndType(deviceName, type, this.getTenantId(), offset, limit); @@ -1474,6 +1481,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv List devices = new ArrayList<>(); List allDevices = new ArrayList<>(); String deviceName = request.getDeviceName(); + request = DeviceManagerUtil.validateDeviceListPageSize(request); try { DeviceManagementDAOFactory.openConnection(); allDevices = deviceDAO.getDevicesByName(request, tenantId); @@ -1636,6 +1644,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv List allDevices = new ArrayList<>(); int tenantId = this.getTenantId(); String status = request.getStatus(); + request = DeviceManagerUtil.validateDeviceListPageSize(request); try { DeviceManagementDAOFactory.openConnection(); allDevices = deviceDAO.getDevicesByStatus(request, tenantId); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/util/DeviceManagerUtil.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/util/DeviceManagerUtil.java index a9d472d498..2e338943b8 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/util/DeviceManagerUtil.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/util/DeviceManagerUtil.java @@ -21,10 +21,11 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.w3c.dom.Document; import org.wso2.carbon.base.MultitenantConstants; -import org.wso2.carbon.device.mgt.common.Device; -import org.wso2.carbon.device.mgt.common.DeviceIdentifier; -import org.wso2.carbon.device.mgt.common.DeviceManagementException; -import org.wso2.carbon.device.mgt.common.TransactionManagementException; +import org.wso2.carbon.device.mgt.common.*; +import org.wso2.carbon.device.mgt.common.notification.mgt.NotificationManagementException; +import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException; +import org.wso2.carbon.device.mgt.core.config.DeviceConfigurationManager; +import org.wso2.carbon.device.mgt.core.config.DeviceManagementConfig; import org.wso2.carbon.device.mgt.core.config.datasource.DataSourceConfig; import org.wso2.carbon.device.mgt.core.config.datasource.JNDILookupDefinition; import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOException; @@ -241,4 +242,79 @@ public final class DeviceManagerUtil { } } + public static int validateActivityListPageSize(int limit) throws OperationManagementException { + if (limit == 0) { + DeviceManagementConfig deviceManagementConfig = DeviceConfigurationManager.getInstance(). + getDeviceManagementConfig(); + if (deviceManagementConfig != null) { + return deviceManagementConfig.getPaginationConfiguration().getActivityListPageSize(); + } else { + throw new OperationManagementException("Device-Mgt configuration has not initialized. Please check the " + + "cdm-config.xml file."); + } + } + return limit; + } + + public static PaginationRequest validateOperationListPageSize(PaginationRequest paginationRequest) throws + OperationManagementException { + if (paginationRequest.getRowCount() == 0) { + DeviceManagementConfig deviceManagementConfig = DeviceConfigurationManager.getInstance(). + getDeviceManagementConfig(); + if (deviceManagementConfig != null) { + paginationRequest.setRowCount(deviceManagementConfig.getPaginationConfiguration(). + getOperationListPageSize()); + } else { + throw new OperationManagementException("Device-Mgt configuration has not initialized. Please check the " + + "cdm-config.xml file."); + } + } + return paginationRequest; + } + + public static PaginationRequest validateNotificationListPageSize(PaginationRequest paginationRequest) throws + NotificationManagementException { + if (paginationRequest.getRowCount() == 0) { + DeviceManagementConfig deviceManagementConfig = DeviceConfigurationManager.getInstance(). + getDeviceManagementConfig(); + if (deviceManagementConfig != null) { + paginationRequest.setRowCount(deviceManagementConfig.getPaginationConfiguration(). + getNotificationListPageSize()); + } else { + throw new NotificationManagementException("Device-Mgt configuration has not initialized. Please check the " + + "cdm-config.xml file."); + } + } + return paginationRequest; + } + + public static PaginationRequest validateDeviceListPageSize(PaginationRequest paginationRequest) throws + DeviceManagementException { + if (paginationRequest.getRowCount() == 0) { + DeviceManagementConfig deviceManagementConfig = DeviceConfigurationManager.getInstance(). + getDeviceManagementConfig(); + if (deviceManagementConfig != null) { + paginationRequest.setRowCount(deviceManagementConfig.getPaginationConfiguration(). + getDeviceListPageSize()); + } else { + throw new DeviceManagementException("Device-Mgt configuration has not initialized. Please check the " + + "cdm-config.xml file."); + } + } + return paginationRequest; + } + + public static int validateDeviceListPageSize(int limit) throws DeviceManagementException { + if (limit == 0) { + DeviceManagementConfig deviceManagementConfig = DeviceConfigurationManager.getInstance(). + getDeviceManagementConfig(); + if (deviceManagementConfig != null) { + return deviceManagementConfig.getPaginationConfiguration().getDeviceListPageSize(); + } else { + throw new DeviceManagementException("Device-Mgt configuration has not initialized. Please check the " + + "cdm-config.xml file."); + } + } + return limit; + } } diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/conf/cdm-config.xml b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/conf/cdm-config.xml index 416495b061..bf6e3787b1 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/conf/cdm-config.xml +++ b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/conf/cdm-config.xml @@ -27,8 +27,8 @@ org.wso2.carbon.device.mgt.extensions.push.notification.provider.gcm.GCMBasedPushNotificationProvider - org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt.MQTTBasedPushNotificationProvider - org.wso2.carbon.device.mgt.extensions.push.notification.provider.xmpp.XMPPBasedPushNotificationProvider + + https://localhost:9443 @@ -37,14 +37,14 @@ org.wso2.carbon.policy.mgt - false + true 60000 5 8 20 - false + true 600000 org.wso2.carbon.device.mgt.core.task.impl.DeviceDetailsRetrieverTask @@ -62,5 +62,11 @@ + + 20 + 20 + 20 + 20 + From e125871de0cb4216da341a16257c643d5415f427 Mon Sep 17 00:00:00 2001 From: dilanua Date: Mon, 1 Aug 2016 22:42:53 +0530 Subject: [PATCH 06/13] Adding business-controllers to UI Modules --- .../resources/jaggeryapps/devicemgt/api/device-api.jag | 4 ++-- .../resources/jaggeryapps/devicemgt/api/policy-api.jag | 2 +- .../main/resources/jaggeryapps/devicemgt/api/user-api.jag | 4 ++-- .../app/modules/{ => business-controllers}/device.js | 4 ++-- .../app/modules/{ => business-controllers}/group.js | 4 ++-- .../app/modules/{ => business-controllers}/operation.js | 2 +- .../app/modules/{ => business-controllers}/policy.js | 2 +- .../app/modules/{ => business-controllers}/user.js | 2 +- .../resources/jaggeryapps/devicemgt/app/modules/init.js | 2 +- .../app/modules/oauth/token-protected-service-invokers.js | 2 +- .../devicemgt/app/pages/cdmf.page.dashboard/dashboard.js | 8 ++++---- .../devicemgt/app/pages/cdmf.page.devices/devices.js | 6 +++--- .../app/pages/cdmf.page.group.analytics/analytics.js | 2 +- .../devicemgt/app/pages/cdmf.page.groups/groups.js | 4 ++-- .../devicemgt/app/pages/cdmf.page.policies/policies.js | 4 ++-- .../devicemgt/app/pages/cdmf.page.user.create/create.js | 2 +- .../devicemgt/app/pages/cdmf.page.user.edit/edit.js | 2 +- .../devicemgt/app/pages/cdmf.page.user.view/view.js | 4 ++-- .../app/units/cdmf.unit.device.type.view/view.js | 2 +- .../app/units/cdmf.unit.device.types.listing/listing.js | 2 +- .../devicemgt/app/units/cdmf.unit.device.view/view.js | 2 +- .../app/units/cdmf.unit.notification.listing/listing.js | 2 +- .../cdmf.unit.platform.configuration/configuration.js | 4 ++-- .../devicemgt/app/units/cdmf.unit.policy.create/create.js | 2 +- .../app/units/cdmf.unit.policy.priority/priority.js | 2 +- .../devicemgt/app/units/cdmf.unit.role.create/create.js | 2 +- .../units/cdmf.unit.role.edit.permission/permission.js | 2 +- .../devicemgt/app/units/cdmf.unit.role.edit/edit.js | 2 +- .../devicemgt/app/units/cdmf.unit.role.listing/listing.js | 2 +- .../app/units/cdmf.unit.ui.navbar.nav-menu/nav-menu.js | 2 +- 30 files changed, 43 insertions(+), 43 deletions(-) rename components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/{ => business-controllers}/device.js (98%) rename components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/{ => business-controllers}/group.js (94%) rename components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/{ => business-controllers}/operation.js (98%) rename components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/{ => business-controllers}/policy.js (99%) rename components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/{ => business-controllers}/user.js (99%) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/api/device-api.jag b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/api/device-api.jag index 937d396885..ecb9806b5d 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/api/device-api.jag +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/api/device-api.jag @@ -22,10 +22,10 @@ var uriMatcher = new URIMatcher(String(uri)); var log = new Log("api/device-api.jag"); var constants = require("/app/modules/constants.js"); -var deviceModule = require("/app/modules/device.js").deviceModule; +var deviceModule = require("/app/modules/business-controllers/device.js")["deviceModule"]; var utility = require("/app/modules/utility.js").utility; var devicemgtProps = require("/app/modules/conf-reader/main.js")["conf"]; -var userModule = require("/app/modules/user.js").userModule; +var userModule = require("/app/modules/business-controllers/user.js")["userModule"]; var serviceInvokers = require("/app/modules/oauth/token-protected-service-invokers.js")["invokers"]; var user = session.get(constants.USER_SESSION_KEY); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/api/policy-api.jag b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/api/policy-api.jag index d2a2630be7..5ae93fdde7 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/api/policy-api.jag +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/api/policy-api.jag @@ -27,7 +27,7 @@ var uriMatcher = new URIMatcher(String(uri)); var log = new Log("api/policy-api.jag"); var constants = require("/modules/constants.js"); -var policyModule = require("/modules/policy.js").policyModule; +var policyModule = require("/app/modules/business-controllers/group.js")["groupModule"]; var result; if (uriMatcher.match("/{context}/api/policies/update")) { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/api/user-api.jag b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/api/user-api.jag index 3c11d19fde..212a087539 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/api/user-api.jag +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/api/user-api.jag @@ -24,8 +24,8 @@ var log = new Log("api/user-api.jag"); var constants = require("/app/modules/constants.js"); var devicemgtProps = require("/app/modules/conf-reader/main.js")["conf"]; -var userModule = require("/app/modules/user.js").userModule; -var deviceModule = require("/app/modules/device.js").deviceModule; +var userModule = require("/app/modules/business-controllers/user.js")["userModule"]; +var deviceModule = require("/app/modules/business-controllers/device.js")["deviceModule"]; var utility = require("/app/modules/utility.js").utility; var apiWrapperUtil = require("/app/modules/oauth/token-handlers.js")["handlers"]; var util = require("/app/modules/oauth/token-handler-utils.js")["utils"]; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/device.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/device.js similarity index 98% rename from components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/device.js rename to components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/device.js index 071154584d..4510106bad 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/device.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/device.js @@ -18,7 +18,7 @@ var deviceModule; deviceModule = function () { - var log = new Log("/app/modules/device.js"); + var log = new Log("/app/modules/business-controllers/device.js"); var utility = require('/app/modules/utility.js').utility; var constants = require('/app/modules/constants.js'); @@ -261,7 +261,7 @@ deviceModule = function () { publicMethods.getDevicesCount = function () { var carbonUser = session.get(constants.USER_SESSION_KEY); if (carbonUser) { - var userModule = require("/app/modules/user.js").userModule; + var userModule = require("/app/modules/business-controllers/user.js")["userModule"]; var uiPermissions = userModule.getUIPermissions(); var url; if (uiPermissions.LIST_DEVICES) { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/group.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/group.js similarity index 94% rename from components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/group.js rename to components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/group.js index c2567cec29..02b2198b48 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/group.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/group.js @@ -18,9 +18,9 @@ var groupModule = {}; (function (groupModule) { - var log = new Log("/app/modules/group.js"); + var log = new Log("/app/modules/business-controllers/group.js"); - var userModule = require("/app/modules/user.js").userModule; + var userModule = require("/app/modules/business-controllers/user.js")["userModule"]; var constants = require('/app/modules/constants.js'); var devicemgtProps = require("/app/modules/conf-reader/main.js")["conf"]; var utility = require("/app/modules/utility.js").utility; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/operation.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/operation.js similarity index 98% rename from components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/operation.js rename to components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/operation.js index 9f75d4eb17..e96ffcdec1 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/operation.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/operation.js @@ -17,7 +17,7 @@ */ var operationModule = function () { - var log = new Log("/app/modules/operation.js"); + var log = new Log("/app/modules/business-controllers/operation.js"); var utility = require('/app/modules/utility.js').utility; var constants = require('/app/modules/constants.js'); var devicemgtProps = require("/app/modules/conf-reader/main.js")["conf"]; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/policy.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/policy.js similarity index 99% rename from components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/policy.js rename to components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/policy.js index 998e6722d1..6cc38a9bfe 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/policy.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/policy.js @@ -21,7 +21,7 @@ */ var policyModule; policyModule = function () { - var log = new Log("/app/modules/policy.js"); + var log = new Log("/app/modules/business-controllers/policy.js"); var constants = require('/app/modules/constants.js'); var utility = require("/app/modules/utility.js")["utility"]; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/user.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/user.js similarity index 99% rename from components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/user.js rename to components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/user.js index 29a7de7365..720cbc4629 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/user.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/user.js @@ -20,7 +20,7 @@ * This module contains user and roles related functionality. */ var userModule = function () { - var log = new Log("/app/modules/user.js"); + var log = new Log("/app/modules/business-controllers/user.js"); var constants = require("/app/modules/constants.js"); var utility = require("/app/modules/utility.js")["utility"]; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/init.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/init.js index 8e86f44ab8..d9f442cdd4 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/init.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/init.js @@ -24,7 +24,7 @@ var carbonServer = new carbonModule.server.Server({ }); application.put("carbonServer", carbonServer); -var userModule = require("/app/modules/user.js")["userModule"]; +var userModule = require("/app/modules/business-controllers/user.js")["userModule"]; var utility = require("/app/modules/utility.js")["utility"]; var permissions = { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/oauth/token-protected-service-invokers.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/oauth/token-protected-service-invokers.js index 4994e160bf..fa71ce1475 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/oauth/token-protected-service-invokers.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/oauth/token-protected-service-invokers.js @@ -37,7 +37,7 @@ var invokers = function () { var devicemgtProps = require("/app/modules/conf-reader/main.js")["conf"]; var constants = require("/app/modules/constants.js"); - var userModule = require("/app/modules/user.js")["userModule"]; + var userModule = require("/app/modules/business-controllers/user.js")["userModule"]; var tokenUtil = require("/app/modules/oauth/token-handlers.js")["handlers"]; /** diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.dashboard/dashboard.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.dashboard/dashboard.js index 8681882f2e..ec98554ce1 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.dashboard/dashboard.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.dashboard/dashboard.js @@ -19,7 +19,7 @@ function onRequest(context) { var constants = require("/app/modules/constants.js"); var user = session.get(constants.USER_SESSION_KEY); - var userModule = require("/app/modules/user.js").userModule; + var userModule = require("/app/modules/business-controllers/user.js")["userModule"]; var permissions = userModule.getUIPermissions(); var devicemgtProps = require("/app/modules/conf-reader/main.js")["conf"]; @@ -31,9 +31,9 @@ function onRequest(context) { var page = {}; page.permissions = permissions; page.enrollmentURL = devicemgtProps.enrollmentURL; - var deviceModule = require("/app/modules/device.js").deviceModule; - var groupModule = require("/app/modules/group.js").groupModule; - var policyModule = require("/app/modules/policy.js").policyModule; + var deviceModule = require("/app/modules/business-controllers/device.js")["deviceModule"]; + var groupModule = require("/app/modules/business-controllers/group.js")["groupModule"]; + var policyModule = require("/app/modules/business-controllers/policy.js")["policyModule"]; page.device_count = deviceModule.getDevicesCount(); page.group_count = groupModule.getGroupCount(); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devices/devices.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devices/devices.js index 085f1f5a69..15c9b131f7 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devices/devices.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devices/devices.js @@ -18,8 +18,8 @@ function onRequest(context) { var constants = require("/app/modules/constants.js"); - var userModule = require("/app/modules/user.js").userModule; - var deviceModule = require("/app/modules/device.js").deviceModule; + var userModule = require("/app/modules/business-controllers/user.js")["userModule"]; + var deviceModule = require("/app/modules/business-controllers/device.js")["deviceModule"]; var groupName = request.getParameter("groupName"); var groupOwner = request.getParameter("groupOwner"); @@ -42,7 +42,7 @@ function onRequest(context) { page.currentUser = currentUser; var deviceCount = 0; if (groupName && groupOwner) { - var groupModule = require("/app/modules/group.js").groupModule; + var groupModule = require("/app/modules/business-controllers/group.js")["groupModule"]; deviceCount = groupModule.getGroupDeviceCount(groupName, groupOwner); } else { deviceCount = deviceModule.getDevicesCount(); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.group.analytics/analytics.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.group.analytics/analytics.js index 563660dadb..fe9a550516 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.group.analytics/analytics.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.group.analytics/analytics.js @@ -18,7 +18,7 @@ function onRequest(context) { var utility = require("/app/modules/utility.js").utility; - var groupModule = require("/app/modules/group.js").groupModule; + var groupModule = require("/app/modules/business-controllers/group.js")["groupModule"]; var groupName = context.uriParams.name; var groupOwner = context.uriParams.owner; var devices = groupModule.getGroupDevices(groupName, groupOwner).data; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.groups/groups.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.groups/groups.js index 188a8fec1a..532ce661c7 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.groups/groups.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.groups/groups.js @@ -17,8 +17,8 @@ */ function onRequest(context) { - var groupModule = require("/app/modules/group.js").groupModule; - var userModule = require("/app/modules/user.js").userModule; + var groupModule = require("/app/modules/business-controllers/group.js")["groupModule"]; + var userModule = require("/app/modules/business-controllers/user.js")["userModule"]; var constants = require("/app/modules/constants.js"); var currentUser = session.get(constants.USER_SESSION_KEY); var page = {}; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.policies/policies.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.policies/policies.js index b21d376f06..3f60618d84 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.policies/policies.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.policies/policies.js @@ -28,8 +28,8 @@ function onRequest(context) { } }); var page = {}; - var policyModule = require("/app/modules/policy.js")["policyModule"]; - var userModule = require("/app/modules/user.js")["userModule"]; + var policyModule = require("/app/modules/business-controllers/group.js")["groupModule"]; + var userModule = require("/app/modules/business-controllers/user.js")["userModule"]; var response = policyModule.getAllPolicies(); if (response["status"] == "success") { var policyListToView = response["content"]; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.user.create/create.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.user.create/create.js index cbd0564b15..4cba6f75c3 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.user.create/create.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.user.create/create.js @@ -25,7 +25,7 @@ function onRequest(context) { //var log = new Log("/app/pages/cdmf.page.user.create server-side js"); - var userModule = require("/app/modules/user.js")["userModule"]; + var userModule = require("/app/modules/business-controllers/user.js")["userModule"]; var devicemgtProps = require("/app/modules/conf-reader/main.js")["conf"]; var page = {}; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.user.edit/edit.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.user.edit/edit.js index 7037721ad9..a8eab03731 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.user.edit/edit.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.user.edit/edit.js @@ -17,7 +17,7 @@ */ function onRequest(context) { - var userModule = require("/app/modules/user.js").userModule; + var userModule = require("/app/modules/business-controllers/user.js")["userModule"]; var userName = request.getParameter("username"); var user = userModule.getUser(userName)["content"]; var devicemgtProps = require("/app/modules/conf-reader/main.js")["conf"]; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.user.view/view.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.user.view/view.js index 8b41bc8a36..ffb86426bb 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.user.view/view.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.user.view/view.js @@ -17,7 +17,7 @@ */ function onRequest(context) { - var userModule = require("/app/modules/user.js").userModule; + var userModule = require("/app/modules/business-controllers/user.js")["userModule"]; var username = request.getParameter("username"); var user = userModule.getUser(username)["content"]; var userModule = require("/app/modules/user.js")["userModule"]; @@ -38,7 +38,7 @@ function onRequest(context) { if (response["status"] == "success") { userRoles = response["content"]; } - var deviceModule = require("/app/modules/device.js").deviceModule; + var deviceModule = require("/app/modules/business-controllers/device.js")["deviceModule"]; devices = deviceModule.getDevices(userName); } return {"user": user, "userRoles": userRoles, "devices": devices}; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.view/view.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.view/view.js index f003d47581..fa599c37a7 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.view/view.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.view/view.js @@ -27,7 +27,7 @@ function onRequest (context) { } //For QR Code - var userModule = require("/app/modules/user.js").userModule; + var userModule = require("/app/modules/business-controllers/user.js")["userModule"]; var constants = require("/app/modules/constants.js"); var permissions = userModule.getUIPermissions(); var deviceMgtProps = require("/app/modules/conf-reader/main.js")["conf"]; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.types.listing/listing.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.types.listing/listing.js index fecc522807..0ae0ed8a48 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.types.listing/listing.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.types.listing/listing.js @@ -23,7 +23,7 @@ function onRequest(context) { var DTYPE_CONF_DEVICE_TYPE_LABEL_KEY = "label"; var viewModel = {}; - var deviceModule = require("/app/modules/device.js").deviceModule; + var deviceModule = require("/app/modules/business-controllers/device.js")["deviceModule"]; var utility = require("/app/modules/utility.js").utility; var deviceTypes = deviceModule.getDeviceTypes(); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.view/view.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.view/view.js index d544e09b58..a3a0037dcb 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.view/view.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.view/view.js @@ -22,7 +22,7 @@ function onRequest(context) { var deviceId = request.getParameter("id"); if (deviceType != null && deviceType != undefined && deviceId != null && deviceId != undefined) { - var deviceModule = require("/app/modules/device.js").deviceModule; + var deviceModule = require("/app/modules/business-controllers/device.js")["deviceModule"]; var device = deviceModule.viewDevice(deviceType, deviceId); if (device) { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.notification.listing/listing.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.notification.listing/listing.js index 50306cbfb3..0086ba8e3e 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.notification.listing/listing.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.notification.listing/listing.js @@ -17,7 +17,7 @@ */ function onRequest(context){ - var userModule = require("/app/modules/user.js").userModule; + var userModule = require("/app/modules/business-controllers/user.js")["userModule"]; var constants = require("/app/modules/constants.js"); var permissions = []; if(userModule.isAuthorized("/permission/admin/device-mgt/emm-admin/notifications/list")){ diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.platform.configuration/configuration.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.platform.configuration/configuration.js index 749ee92c15..e34720df7b 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.platform.configuration/configuration.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.platform.configuration/configuration.js @@ -17,8 +17,8 @@ */ function onRequest(context) { - var utility = require("/app/modules/device.js").utility; - var deviceModule = require("/app/modules/device.js").deviceModule; + var utility = require("/app/modules/utility.js").utility; + var deviceModule = require("/app/modules/business-controllers/device.js")["deviceModule"]; //get all device types var data = deviceModule.getDeviceTypes(); var deviceTypesArray = []; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.policy.create/create.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.policy.create/create.js index 3e09ae185d..cf46e20def 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.policy.create/create.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.policy.create/create.js @@ -21,7 +21,7 @@ function onRequest(context) { var DTYPE_CONF_DEVICE_TYPE_LABEL_KEY = "label"; var utility = require("/app/modules/utility.js").utility; - var userModule = require("/app/modules/user.js")["userModule"]; + var userModule = require("/app/modules/business-controllers/user.js")["userModule"]; var types = {}; types["types"] = []; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.policy.priority/priority.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.policy.priority/priority.js index 7630df258b..2ba2155ac2 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.policy.priority/priority.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.policy.priority/priority.js @@ -27,7 +27,7 @@ function onRequest(context) { return options.fn(this); } }); - var policyModule = require("/app/modules/policy.js")["policyModule"]; + var policyModule = require("/app/modules/business-controllers/group.js")["groupModule"]; var response = policyModule.getAllPolicies(); if (response["status"] == "success") { var policyListToView = response["content"]; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.role.create/create.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.role.create/create.js index 9e00dc32aa..a65fa31e25 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.role.create/create.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.role.create/create.js @@ -23,7 +23,7 @@ * @returns {*} A context object that returns the dynamic state of this page to be presented */ function onRequest(context) { - var userModule = require("/app/modules/user.js")["userModule"]; + var userModule = require("/app/modules/business-controllers/user.js")["userModule"]; var deviceMgtProps = require("/app/modules/conf-reader/main.js")["conf"]; var response = userModule.getRoles(); if (response["status"] == "success") { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.role.edit.permission/permission.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.role.edit.permission/permission.js index a16f9a38bb..6829dc21e3 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.role.edit.permission/permission.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.role.edit.permission/permission.js @@ -23,7 +23,7 @@ * @returns {*} A context object that returns the dynamic state of this page to be presented */ function onRequest(context) { - var userModule = require("/app/modules/user.js")["userModule"]; + var userModule = require("/app/modules/business-controllers/user.js")["userModule"]; var uri = request.getRequestURI(); var uriMatcher = new URIMatcher(String(uri)); var isMatched = uriMatcher.match("/{context}/roles/edit-role-permission/{rolename}"); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.role.edit/edit.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.role.edit/edit.js index 01a08da69f..cf54af034e 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.role.edit/edit.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.role.edit/edit.js @@ -23,7 +23,7 @@ * @returns {*} A context object that returns the dynamic state of this page to be presented */ function onRequest(context) { - var userModule = require("/app/modules/user.js")["userModule"]; + var userModule = require("/app/modules/business-controllers/user.js")["userModule"]; var deviceMgtProps = require("/app/modules/conf-reader/main.js")["conf"]; var uri = request.getRequestURI(); var uriMatcher = new URIMatcher(String(uri)); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.role.listing/listing.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.role.listing/listing.js index c5c67d1029..d908da5d2d 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.role.listing/listing.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.role.listing/listing.js @@ -17,7 +17,7 @@ */ function onRequest(context) { - var userModule = require("/app/modules/user.js")["userModule"]; + var userModule = require("/app/modules/business-controllers/user.js")["userModule"]; var response = userModule.getUsers(); var users = {}; context["permissions"] = userModule.getUIPermissions(); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.ui.navbar.nav-menu/nav-menu.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.ui.navbar.nav-menu/nav-menu.js index 3f4ede1774..363d9688e6 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.ui.navbar.nav-menu/nav-menu.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.ui.navbar.nav-menu/nav-menu.js @@ -27,7 +27,7 @@ function onRequest(context) { return options.fn(this); } }); - var userModule = require("/app/modules/user.js")["userModule"]; + var userModule = require("/app/modules/business-controllers/user.js")["userModule"]; var mdmProps = require("/app/modules/conf-reader/main.js")["conf"]; var constants = require("/app/modules/constants.js"); var uiPermissions = userModule.getUIPermissions(); From c7f4bba8bf5bd22b1dc8eae30895967ca39720bb Mon Sep 17 00:00:00 2001 From: dilanua Date: Mon, 1 Aug 2016 22:45:30 +0530 Subject: [PATCH 07/13] Deprecating operation.js module from UI --- .../modules/business-controllers/operation.js | 234 +++++++++--------- 1 file changed, 119 insertions(+), 115 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/operation.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/operation.js index e96ffcdec1..1e479286a9 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/operation.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/operation.js @@ -16,119 +16,123 @@ * under the License. */ -var operationModule = function () { - var log = new Log("/app/modules/business-controllers/operation.js"); - var utility = require('/app/modules/utility.js').utility; - var constants = require('/app/modules/constants.js'); - var devicemgtProps = require("/app/modules/conf-reader/main.js")["conf"]; - var serviceInvokers = require("/app/modules/oauth/token-protected-service-invokers.js")["invokers"]; - - var publicMethods = {}; - var privateMethods = {}; - - /** - * This method reads the token from the Token client and return the access token. - * If the token pair s not set in the session this will send a redirect to the login page. - */ - function getAccessToken(deviceType, owner, deviceId) { - var TokenClient = Packages.org.wso2.carbon.device.mgt.iot.apimgt.TokenClient; - var accessTokenClient = new TokenClient(deviceType); - var accessTokenInfo = accessTokenClient.getAccessToken(owner, deviceId); - return accessTokenInfo.getAccess_token(); - } - - privateMethods.getOperationsFromFeatures = function (deviceType, operationType) { - var url = devicemgtProps["httpsURL"] + constants.ADMIN_SERVICE_CONTEXT + "/features/" + deviceType; - var featuresList = serviceInvokers.XMLHttp.get(url, function (responsePayload) { - var features = responsePayload; - var featureList = []; - var feature; - for (var i = 0; i < features.length; i++) { - feature = {}; - var analyticStreams = utility.getDeviceTypeConfig(deviceType)["analyticStreams"]; - if (analyticStreams) { - for (var stream in analyticStreams) { - if (analyticStreams[stream].name == features[i].name) { - feature.ui_unit = analyticStreams[stream].ui_unit; - break; - } - } - } - - feature["operation"] = features[i].code; - feature["name"] = features[i].name; - feature["description"] = features[i].description; - feature["deviceType"] = deviceType; - feature["params"] = []; - var metaData = features[i].metadataEntries; - if (metaData) { - for (var j = 0; j < metaData.length; j++) { - feature["params"].push(metaData[j].value); - } - featureList.push(feature); - } - } - return featureList; - }, function (responsePayload) { - var response = {}; - response["status"] = "error"; - return response; - } - ); - return featuresList; - }; - - publicMethods.getControlOperations = function (deviceType) { - var operations = privateMethods.getOperationsFromFeatures(deviceType, "operation"); - for (var op in operations) { - var iconPath = utility.getOperationIcon(deviceType, operations[op].operation); - if (iconPath) { - operations[op]["icon"] = iconPath; - } - } - return operations; - }; - - publicMethods.getMonitorOperations = function (deviceType) { - return privateMethods.getOperationsFromFeatures(deviceType, "monitor"); - }; - - publicMethods.handlePOSTOperation = function (deviceType, operation, deviceId, params) { - var user = session.get(constants.USER_SESSION_KEY); - var endPoint = devicemgtProps["httpsURL"] + '/' + deviceType + "/controller/" + operation; - var header = '{"owner":"' + user.username + '","deviceId":"' + deviceId + - '","protocol":"mqtt", "sessionId":"' + session.getId() + '", "' + - constants.AUTHORIZATION_HEADER + '":"' + constants.BEARER_PREFIX + - getAccessToken(deviceType, user.username, deviceId) + '"}'; - return post(endPoint, params, JSON.parse(header), "json"); - }; - - publicMethods.handleGETOperation = function (deviceType, operation, operationName, deviceId) { - var user = session.get(constants.USER_SESSION_KEY); - var endPoint = devicemgtProps["httpsURL"] + '/' + deviceType + "/controller/" + operation; - var header = '{"owner":"' + user.username + '","deviceId":"' + deviceId + - '","protocol":"mqtt", "' + constants.AUTHORIZATION_HEADER + '":"' + - constants.BEARER_PREFIX + getAccessToken(deviceType, user.username, deviceId) + - '"}'; - var result = get(endPoint, {}, JSON.parse(header), "json"); - if (result.data) { - var values = result.data.sensorValue.split(','); - if (operationName == 'gps') { - result.data.map = { - lat: parseFloat(values[0]), - lng: parseFloat(values[1]) - } - } else { - var sqSum = 0; - for (var v in values) { - sqSum += Math.pow(values[v], 2); - } - result.data[operationName] = Math.sqrt(sqSum); - } - delete result.data['sensorValue']; - } - return result; - }; +/* + @Deprecated New + */ - return publicMethods; -}(); \ No newline at end of file +//var operationModule = function () { +// var log = new Log("/app/modules/business-controllers/operation.js"); +// var utility = require('/app/modules/utility.js').utility; +// var constants = require('/app/modules/constants.js'); +// var devicemgtProps = require("/app/modules/conf-reader/main.js")["conf"]; +// var serviceInvokers = require("/app/modules/oauth/token-protected-service-invokers.js")["invokers"]; +// +// var publicMethods = {}; +// var privateMethods = {}; +// +// /** +// * This method reads the token from the Token client and return the access token. +// * If the token pair s not set in the session this will send a redirect to the login page. +// */ +// function getAccessToken(deviceType, owner, deviceId) { +// var TokenClient = Packages.org.wso2.carbon.device.mgt.iot.apimgt.TokenClient; +// var accessTokenClient = new TokenClient(deviceType); +// var accessTokenInfo = accessTokenClient.getAccessToken(owner, deviceId); +// return accessTokenInfo.getAccess_token(); +// } +// +// privateMethods.getOperationsFromFeatures = function (deviceType, operationType) { +// var url = devicemgtProps["httpsURL"] + constants.ADMIN_SERVICE_CONTEXT + "/features/" + deviceType; +// var featuresList = serviceInvokers.XMLHttp.get(url, function (responsePayload) { +// var features = responsePayload; +// var featureList = []; +// var feature; +// for (var i = 0; i < features.length; i++) { +// feature = {}; +// var analyticStreams = utility.getDeviceTypeConfig(deviceType)["analyticStreams"]; +// if (analyticStreams) { +// for (var stream in analyticStreams) { +// if (analyticStreams[stream].name == features[i].name) { +// feature.ui_unit = analyticStreams[stream].ui_unit; +// break; +// } +// } +// } +// +// feature["operation"] = features[i].code; +// feature["name"] = features[i].name; +// feature["description"] = features[i].description; +// feature["deviceType"] = deviceType; +// feature["params"] = []; +// var metaData = features[i].metadataEntries; +// if (metaData) { +// for (var j = 0; j < metaData.length; j++) { +// feature["params"].push(metaData[j].value); +// } +// featureList.push(feature); +// } +// } +// return featureList; +// }, function (responsePayload) { +// var response = {}; +// response["status"] = "error"; +// return response; +// } +// ); +// return featuresList; +// }; +// +// publicMethods.getControlOperations = function (deviceType) { +// var operations = privateMethods.getOperationsFromFeatures(deviceType, "operation"); +// for (var op in operations) { +// var iconPath = utility.getOperationIcon(deviceType, operations[op].operation); +// if (iconPath) { +// operations[op]["icon"] = iconPath; +// } +// } +// return operations; +// }; +// +// publicMethods.getMonitorOperations = function (deviceType) { +// return privateMethods.getOperationsFromFeatures(deviceType, "monitor"); +// }; +// +// publicMethods.handlePOSTOperation = function (deviceType, operation, deviceId, params) { +// var user = session.get(constants.USER_SESSION_KEY); +// var endPoint = devicemgtProps["httpsURL"] + '/' + deviceType + "/controller/" + operation; +// var header = '{"owner":"' + user.username + '","deviceId":"' + deviceId + +// '","protocol":"mqtt", "sessionId":"' + session.getId() + '", "' + +// constants.AUTHORIZATION_HEADER + '":"' + constants.BEARER_PREFIX + +// getAccessToken(deviceType, user.username, deviceId) + '"}'; +// return post(endPoint, params, JSON.parse(header), "json"); +// }; +// +// publicMethods.handleGETOperation = function (deviceType, operation, operationName, deviceId) { +// var user = session.get(constants.USER_SESSION_KEY); +// var endPoint = devicemgtProps["httpsURL"] + '/' + deviceType + "/controller/" + operation; +// var header = '{"owner":"' + user.username + '","deviceId":"' + deviceId + +// '","protocol":"mqtt", "' + constants.AUTHORIZATION_HEADER + '":"' + +// constants.BEARER_PREFIX + getAccessToken(deviceType, user.username, deviceId) + +// '"}'; +// var result = get(endPoint, {}, JSON.parse(header), "json"); +// if (result.data) { +// var values = result.data.sensorValue.split(','); +// if (operationName == 'gps') { +// result.data.map = { +// lat: parseFloat(values[0]), +// lng: parseFloat(values[1]) +// } +// } else { +// var sqSum = 0; +// for (var v in values) { +// sqSum += Math.pow(values[v], 2); +// } +// result.data[operationName] = Math.sqrt(sqSum); +// } +// delete result.data['sensorValue']; +// } +// return result; +// }; +// +// return publicMethods; +//}(); \ No newline at end of file From 9510554f67e26e88a75cbffc6353def7c78b205d Mon Sep 17 00:00:00 2001 From: kamidu Date: Tue, 2 Aug 2016 00:05:23 +0530 Subject: [PATCH 08/13] Fix the notification view internal server error issue --- .../public/js/notification-listing.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.notification.listing/public/js/notification-listing.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.notification.listing/public/js/notification-listing.js index ba6f47c614..52fd96af33 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.notification.listing/public/js/notification-listing.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.notification.listing/public/js/notification-listing.js @@ -46,7 +46,7 @@ $(document).ready(function () { $("#ast-container").on("click", ".new-notification", function(e){ var notificationId = $(this).data("id"); var redirectUrl = $(this).data("url"); - var getNotificationsAPI = "/devicemgt_admin/notifications/"+notificationId+"/CHECKED"; + var getNotificationsAPI = "/api/device-mgt/v1.0/notifications/"+notificationId+"/CHECKED"; var errorMsgWrapper = "#error-msg"; var errorMsg = "#error-msg span"; invokerUtil.put( @@ -87,7 +87,7 @@ function loadNotifications(){ var deviceListingSrc = deviceListing.attr("src"); var currentUser = deviceListing.data("currentUser"); $.template("notification-listing", deviceListingSrc, function (template) { - var serviceURL = "/devicemgt_admin/notifications"; + var serviceURL = "/api/device-mgt/v1.0/notifications"; var successCallback = function (data) { var viewModel = {}; data = JSON.parse(data); From efcd5272d277a80c0279b8959b7125a408afdfed Mon Sep 17 00:00:00 2001 From: charitha Date: Tue, 2 Aug 2016 14:31:12 +0530 Subject: [PATCH 09/13] Fix issues in sql statements --- .../device/mgt/core/dao/impl/ApplicationMappingDAOImpl.java | 4 ++-- .../carbon/device/mgt/core/dao/impl/EnrollmentDAOImpl.java | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/ApplicationMappingDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/ApplicationMappingDAOImpl.java index 0021c0dc96..45a4b881c4 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/ApplicationMappingDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/ApplicationMappingDAOImpl.java @@ -102,7 +102,7 @@ public class ApplicationMappingDAOImpl implements ApplicationMappingDAO { Connection conn; PreparedStatement stmt = null; try { - String sql = "DELETE DM_DEVICE_APPLICATION_MAPPING WHERE DEVICE_ID = ? AND " + + String sql = "DELETE FROM DM_DEVICE_APPLICATION_MAPPING WHERE DEVICE_ID = ? AND " + "APPLICATION_ID = ? AND TENANT_ID = ?"; conn = this.getConnection(); @@ -114,7 +114,7 @@ public class ApplicationMappingDAOImpl implements ApplicationMappingDAO { stmt.execute(); } } catch (SQLException e) { - throw new DeviceManagementDAOException("Error occurred while adding device application mapping", e); + throw new DeviceManagementDAOException("Error occurred while removing device application mapping", e); } finally { DeviceManagementDAOUtil.cleanupResources(stmt, null); } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/EnrollmentDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/EnrollmentDAOImpl.java index 1998907b9d..abb9b1f87c 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/EnrollmentDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/EnrollmentDAOImpl.java @@ -129,7 +129,7 @@ public class EnrollmentDAOImpl implements EnrollmentDAO { int status = -1; try { conn = this.getConnection(); - String sql = "DELETE DM_ENROLMENT WHERE DEVICE_ID = ? AND OWNER = ? AND TENANT_ID = ?"; + String sql = "DELETE FROM DM_ENROLMENT WHERE DEVICE_ID = ? AND OWNER = ? AND TENANT_ID = ?"; stmt = conn.prepareStatement(sql, new String[] {"id"}); stmt.setInt(1, deviceId); stmt.setString(2, currentOwner); From b8bf855378bd748201f578bb3ca1357f70168196 Mon Sep 17 00:00:00 2001 From: Rasika Perera Date: Tue, 2 Aug 2016 15:43:40 +0530 Subject: [PATCH 10/13] Calculating enrollment url when generalConfig.host config exists --- .../jaggeryapps/devicemgt/app/modules/conf-reader/main.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/conf-reader/main.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/conf-reader/main.js index f81849fe3b..6731dbd23a 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/conf-reader/main.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/conf-reader/main.js @@ -37,6 +37,12 @@ var conf = function () { return value; } ); + if (conf.generalConfig.host) { + //TODO: Move enrollment URL into app-conf.json + var enrollmentHost = conf.generalConfig.host.replace(/https:\/\/localhost(:\d+)?/, conf.httpsURL).replace( + /http:\/\/localhost(:\d+)?/, conf.httpURL); + conf.enrollmentUrl = enrollmentHost + conf.enrollmentDir; + } application.put("CONF", conf); } return conf; From 03835bdeb73d996e47cad56b8cd1c1439ccada7b Mon Sep 17 00:00:00 2001 From: harshanl Date: Tue, 2 Aug 2016 17:40:20 +0530 Subject: [PATCH 11/13] Fixed EMM-1449 issue --- .../src/main/resources/dbscripts/cdm/h2.sql | 8 ++++---- .../src/main/resources/dbscripts/cdm/mssql.sql | 16 ++++++++-------- .../src/main/resources/dbscripts/cdm/mysql.sql | 17 +++++++++-------- .../src/main/resources/dbscripts/cdm/oracle.sql | 16 ++++++++-------- .../main/resources/dbscripts/cdm/postgresql.sql | 16 ++++++++-------- 5 files changed, 37 insertions(+), 36 deletions(-) diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/h2.sql b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/h2.sql index f3f3735e50..82c2eba536 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/h2.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/h2.sql @@ -134,7 +134,7 @@ CREATE TABLE IF NOT EXISTS DM_PROFILE ( ID INT NOT NULL AUTO_INCREMENT , PROFILE_NAME VARCHAR(45) NOT NULL , TENANT_ID INT NOT NULL , - DEVICE_TYPE VARCHAR(20) NOT NULL , + DEVICE_TYPE VARCHAR(300) NOT NULL , CREATED_TIME DATETIME NOT NULL , UPDATED_TIME DATETIME NOT NULL , PRIMARY KEY (ID) , @@ -195,7 +195,7 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_POLICY ( CREATE TABLE IF NOT EXISTS DM_DEVICE_TYPE_POLICY ( ID INT(11) NOT NULL , - DEVICE_TYPE VARCHAR(20) NOT NULL , + DEVICE_TYPE VARCHAR(300) NOT NULL , POLICY_ID INT(11) NOT NULL , PRIMARY KEY (ID) , CONSTRAINT FK_DEVICE_TYPE_POLICY @@ -218,7 +218,7 @@ CREATE TABLE IF NOT EXISTS DM_PROFILE_FEATURES ( ID INT(11) NOT NULL AUTO_INCREMENT, PROFILE_ID INT(11) NOT NULL, FEATURE_CODE VARCHAR(100) NOT NULL, - DEVICE_TYPE VARCHAR(20) NOT NULL, + DEVICE_TYPE VARCHAR(300) NOT NULL, TENANT_ID INT(11) NOT NULL , CONTENT BLOB NULL DEFAULT NULL, PRIMARY KEY (ID), @@ -339,7 +339,7 @@ CREATE TABLE IF NOT EXISTS DM_POLICY_COMPLIANCE_STATUS ( CREATE TABLE IF NOT EXISTS DM_POLICY_CHANGE_MGT ( ID INT NOT NULL AUTO_INCREMENT, POLICY_ID INT NOT NULL, - DEVICE_TYPE VARCHAR(20) NOT NULL, + DEVICE_TYPE VARCHAR(300) NOT NULL , TENANT_ID INT(11) NOT NULL, PRIMARY KEY (ID) ); diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/mssql.sql b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/mssql.sql index 66ce12dc87..385ac2a135 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/mssql.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/mssql.sql @@ -135,13 +135,13 @@ CREATE TABLE DM_PROFILE ( ID INTEGER NOT NULL IDENTITY , PROFILE_NAME VARCHAR(45) NOT NULL , TENANT_ID INTEGER NOT NULL , - DEVICE_TYPE_ID INTEGER NOT NULL , + DEVICE_TYPE VARCHAR(300) NOT NULL , CREATED_TIME DATETIME2(0) NOT NULL , UPDATED_TIME DATETIME2(0) NOT NULL , PRIMARY KEY (ID) , CONSTRAINT DM_PROFILE_DEVICE_TYPE - FOREIGN KEY (DEVICE_TYPE_ID ) - REFERENCES DM_DEVICE_TYPE (ID ) + FOREIGN KEY (DEVICE_TYPE) + REFERENCES DM_DEVICE_TYPE (NAME ) ON DELETE NO ACTION ON UPDATE NO ACTION ); @@ -196,7 +196,7 @@ CREATE TABLE DM_DEVICE_POLICY ( CREATE TABLE DM_DEVICE_TYPE_POLICY ( ID INTEGER NOT NULL , - DEVICE_TYPE_ID INTEGER NOT NULL , + DEVICE_TYPE VARCHAR(300) NOT NULL , POLICY_ID INTEGER NOT NULL , PRIMARY KEY (ID) , CONSTRAINT FK_DEVICE_TYPE_POLICY @@ -205,8 +205,8 @@ CREATE TABLE DM_DEVICE_TYPE_POLICY ( ON DELETE NO ACTION ON UPDATE NO ACTION, CONSTRAINT FK_DEVICE_TYPE_POLICY_DEVICE_TYPE - FOREIGN KEY (DEVICE_TYPE_ID ) - REFERENCES DM_DEVICE_TYPE (ID ) + FOREIGN KEY (DEVICE_TYPE) + REFERENCES DM_DEVICE_TYPE (NAME ) ON DELETE NO ACTION ON UPDATE NO ACTION ); @@ -219,7 +219,7 @@ CREATE TABLE DM_PROFILE_FEATURES ( ID INTEGER NOT NULL IDENTITY, PROFILE_ID INTEGER NOT NULL, FEATURE_CODE VARCHAR(100) NOT NULL, - DEVICE_TYPE_ID INTEGER NOT NULL, + DEVICE_TYPE VARCHAR(300) NOT NULL , TENANT_ID INTEGER NOT NULL , CONTENT VARBINARY(max) NULL DEFAULT NULL, PRIMARY KEY (ID), @@ -340,7 +340,7 @@ CREATE TABLE DM_POLICY_COMPLIANCE_STATUS ( CREATE TABLE DM_POLICY_CHANGE_MGT ( ID INTEGER NOT NULL IDENTITY, POLICY_ID INTEGER NOT NULL, - DEVICE_TYPE_ID INTEGER NOT NULL, + DEVICE_TYPE VARCHAR(300) NOT NULL, TENANT_ID INTEGER NOT NULL, PRIMARY KEY (ID) ); diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/mysql.sql b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/mysql.sql index 1d2013cbc4..098ebc5d98 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/mysql.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/mysql.sql @@ -5,6 +5,7 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_TYPE ( SHARED_WITH_ALL_TENANTS BOOLEAN NOT NULL DEFAULT FALSE, PRIMARY KEY (ID) )ENGINE = InnoDB; +CREATE INDEX device_type_name ON DM_DEVICE_TYPE (NAME); CREATE TABLE IF NOT EXISTS DM_DEVICE ( ID INTEGER AUTO_INCREMENT NOT NULL, @@ -117,13 +118,13 @@ CREATE TABLE IF NOT EXISTS DM_PROFILE ( ID INT NOT NULL AUTO_INCREMENT , PROFILE_NAME VARCHAR(45) NOT NULL , TENANT_ID INT NOT NULL , - DEVICE_TYPE_ID INT NOT NULL , + DEVICE_TYPE VARCHAR(300) NOT NULL , CREATED_TIME DATETIME NOT NULL , UPDATED_TIME DATETIME NOT NULL , PRIMARY KEY (ID) , CONSTRAINT DM_PROFILE_DEVICE_TYPE - FOREIGN KEY (DEVICE_TYPE_ID ) - REFERENCES DM_DEVICE_TYPE (ID ) + FOREIGN KEY (DEVICE_TYPE) + REFERENCES DM_DEVICE_TYPE (NAME) ON DELETE NO ACTION ON UPDATE NO ACTION )ENGINE = InnoDB; @@ -171,7 +172,7 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_POLICY ( CREATE TABLE IF NOT EXISTS DM_DEVICE_TYPE_POLICY ( ID INT(11) NOT NULL , - DEVICE_TYPE_ID INT(11) NOT NULL , + DEVICE_TYPE VARCHAR(300) NOT NULL , POLICY_ID INT(11) NOT NULL , PRIMARY KEY (ID) , CONSTRAINT FK_DEVICE_TYPE_POLICY @@ -180,8 +181,8 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_TYPE_POLICY ( ON DELETE NO ACTION ON UPDATE NO ACTION, CONSTRAINT FK_DEVICE_TYPE_POLICY_DEVICE_TYPE - FOREIGN KEY (DEVICE_TYPE_ID ) - REFERENCES DM_DEVICE_TYPE (ID ) + FOREIGN KEY (DEVICE_TYPE ) + REFERENCES DM_DEVICE_TYPE (NAME ) ON DELETE NO ACTION ON UPDATE NO ACTION )ENGINE = InnoDB; @@ -191,7 +192,7 @@ CREATE TABLE IF NOT EXISTS DM_PROFILE_FEATURES ( ID INT(11) NOT NULL AUTO_INCREMENT, PROFILE_ID INT(11) NOT NULL, FEATURE_CODE VARCHAR(100) NOT NULL, - DEVICE_TYPE_ID INT NOT NULL, + DEVICE_TYPE VARCHAR(300) NOT NULL , TENANT_ID INT(11) NOT NULL , CONTENT BLOB NULL DEFAULT NULL, PRIMARY KEY (ID), @@ -308,7 +309,7 @@ CREATE TABLE IF NOT EXISTS DM_POLICY_COMPLIANCE_STATUS ( CREATE TABLE IF NOT EXISTS DM_POLICY_CHANGE_MGT ( ID INT NOT NULL AUTO_INCREMENT, POLICY_ID INT NOT NULL, - DEVICE_TYPE_ID INT NOT NULL, + DEVICE_TYPE VARCHAR(300) NOT NULL , TENANT_ID INT(11) NOT NULL, PRIMARY KEY (ID) )ENGINE = InnoDB; diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/oracle.sql b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/oracle.sql index 18ed9c2abe..0b1256d5ee 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/oracle.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/oracle.sql @@ -250,13 +250,13 @@ CREATE TABLE DM_PROFILE ( ID NUMBER(10) NOT NULL , PROFILE_NAME VARCHAR2(45) NOT NULL , TENANT_ID NUMBER(10) NOT NULL , - DEVICE_TYPE_ID NUMBER(10) NOT NULL , + DEVICE_TYPE VARCHAR2(300) NOT NULL , CREATED_TIME TIMESTAMP(0) NOT NULL , UPDATED_TIME TIMESTAMP(0) NOT NULL , CONSTRAINT PK_DM_PROFILE PRIMARY KEY (ID) , CONSTRAINT DM_PROFILE_DEVICE_TYPE - FOREIGN KEY (DEVICE_TYPE_ID ) - REFERENCES DM_DEVICE_TYPE (ID ) + FOREIGN KEY (DEVICE_TYPE ) + REFERENCES DM_DEVICE_TYPE (NAME ) ) / -- Generate ID using sequence and trigger @@ -338,15 +338,15 @@ WHEN (NEW.ID IS NULL) CREATE TABLE DM_DEVICE_TYPE_POLICY ( ID NUMBER(10) NOT NULL , - DEVICE_TYPE_ID NUMBER(10) NOT NULL , + DEVICE_TYPE VARCHAR2(300) NOT NULL , POLICY_ID NUMBER(10) NOT NULL , CONSTRAINT PK_DEV_TYPE_POLICY PRIMARY KEY (ID) , CONSTRAINT FK_DEV_TYPE_POLICY FOREIGN KEY (POLICY_ID ) REFERENCES DM_POLICY (ID ), CONSTRAINT FK_DEV_TYPE_POLICY_DEV_TYPE - FOREIGN KEY (DEVICE_TYPE_ID ) - REFERENCES DM_DEVICE_TYPE (ID ) + FOREIGN KEY (DEVICE_TYPE ) + REFERENCES DM_DEVICE_TYPE (NAME ) ) / @@ -355,7 +355,7 @@ CREATE TABLE DM_PROFILE_FEATURES ( ID NUMBER(10) NOT NULL, PROFILE_ID NUMBER(10) NOT NULL, FEATURE_CODE VARCHAR2(100) NOT NULL, - DEVICE_TYPE_ID NUMBER(10) NOT NULL, + DEVICE_TYPE VARCHAR2(300) NOT NULL , TENANT_ID NUMBER(10) NOT NULL , CONTENT BLOB DEFAULT NULL NULL, CONSTRAINT PK_DM_PROF_DM_POLICY_FEATURES PRIMARY KEY (ID), @@ -566,7 +566,7 @@ WHEN (NEW.ID IS NULL) CREATE TABLE DM_POLICY_CHANGE_MGT ( ID NUMBER(10) NOT NULL, POLICY_ID NUMBER(10) NOT NULL, - DEVICE_TYPE_ID NUMBER(10) NOT NULL, + DEVICE_TYPE VARCHAR2(300) NOT NULL, TENANT_ID NUMBER(10) NOT NULL, CONSTRAINT PK_DM_POLICY_CHANGE_MGT PRIMARY KEY (ID) ) diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/postgresql.sql b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/postgresql.sql index 2da059d3a7..dc3c6229f2 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/postgresql.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/postgresql.sql @@ -103,12 +103,12 @@ CREATE TABLE IF NOT EXISTS DM_PROFILE ( ID BIGSERIAL NOT NULL PRIMARY KEY, PROFILE_NAME VARCHAR(45) NOT NULL , TENANT_ID INTEGER NOT NULL , - DEVICE_TYPE_ID INTEGER NOT NULL , + DEVICE_TYPE VARCHAR(300) NOT NULL , CREATED_TIME TIMESTAMP NOT NULL , UPDATED_TIME TIMESTAMP NOT NULL , CONSTRAINT DM_PROFILE_DEVICE_TYPE - FOREIGN KEY (DEVICE_TYPE_ID ) - REFERENCES DM_DEVICE_TYPE (ID ) + FOREIGN KEY (DEVICE_TYPE ) + REFERENCES DM_DEVICE_TYPE (NAME ) ON DELETE NO ACTION ON UPDATE NO ACTION ); @@ -151,7 +151,7 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_POLICY ( CREATE TABLE IF NOT EXISTS DM_DEVICE_TYPE_POLICY ( ID INTEGER NOT NULL, - DEVICE_TYPE_ID INTEGER NOT NULL , + DEVICE_TYPE VARCHAR(300) NOT NULL , POLICY_ID INTEGER NOT NULL , PRIMARY KEY (ID) , CONSTRAINT FK_DEVICE_TYPE_POLICY @@ -160,8 +160,8 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_TYPE_POLICY ( ON DELETE NO ACTION ON UPDATE NO ACTION, CONSTRAINT FK_DEVICE_TYPE_POLICY_DEVICE_TYPE - FOREIGN KEY (DEVICE_TYPE_ID ) - REFERENCES DM_DEVICE_TYPE (ID ) + FOREIGN KEY (DEVICE_TYPE ) + REFERENCES DM_DEVICE_TYPE (NAME ) ON DELETE NO ACTION ON UPDATE NO ACTION ); @@ -170,7 +170,7 @@ CREATE TABLE IF NOT EXISTS DM_PROFILE_FEATURES ( ID BIGSERIAL NOT NULL PRIMARY KEY, PROFILE_ID INTEGER NOT NULL, FEATURE_CODE VARCHAR(100) NOT NULL, - DEVICE_TYPE_ID INT NOT NULL, + DEVICE_TYPE VARCHAR(300) NOT NULL , TENANT_ID INTEGER NOT NULL , CONTENT BYTEA NULL DEFAULT NULL, CONSTRAINT FK_DM_PROFILE_DM_POLICY_FEATURES @@ -272,7 +272,7 @@ CREATE TABLE IF NOT EXISTS DM_POLICY_COMPLIANCE_STATUS ( CREATE TABLE IF NOT EXISTS DM_POLICY_CHANGE_MGT ( ID BIGSERIAL NOT NULL PRIMARY KEY, POLICY_ID INTEGER NOT NULL, - DEVICE_TYPE_ID INTEGER NOT NULL, + DEVICE_TYPE VARCHAR(300) NOT NULL, TENANT_ID INTEGER NOT NULL ); From 2ec9f68135eaaae156219cfdaaf48f827fdf09c6 Mon Sep 17 00:00:00 2001 From: dilanua Date: Tue, 2 Aug 2016 18:47:14 +0530 Subject: [PATCH 12/13] Removing the deprecation of operation.js as it seems to have one dependancy to plugins --- .../modules/business-controllers/operation.js | 234 +++++++++--------- 1 file changed, 115 insertions(+), 119 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/operation.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/operation.js index 1e479286a9..e96ffcdec1 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/operation.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/operation.js @@ -16,123 +16,119 @@ * under the License. */ -/* - @Deprecated New - */ +var operationModule = function () { + var log = new Log("/app/modules/business-controllers/operation.js"); + var utility = require('/app/modules/utility.js').utility; + var constants = require('/app/modules/constants.js'); + var devicemgtProps = require("/app/modules/conf-reader/main.js")["conf"]; + var serviceInvokers = require("/app/modules/oauth/token-protected-service-invokers.js")["invokers"]; + + var publicMethods = {}; + var privateMethods = {}; + + /** + * This method reads the token from the Token client and return the access token. + * If the token pair s not set in the session this will send a redirect to the login page. + */ + function getAccessToken(deviceType, owner, deviceId) { + var TokenClient = Packages.org.wso2.carbon.device.mgt.iot.apimgt.TokenClient; + var accessTokenClient = new TokenClient(deviceType); + var accessTokenInfo = accessTokenClient.getAccessToken(owner, deviceId); + return accessTokenInfo.getAccess_token(); + } + + privateMethods.getOperationsFromFeatures = function (deviceType, operationType) { + var url = devicemgtProps["httpsURL"] + constants.ADMIN_SERVICE_CONTEXT + "/features/" + deviceType; + var featuresList = serviceInvokers.XMLHttp.get(url, function (responsePayload) { + var features = responsePayload; + var featureList = []; + var feature; + for (var i = 0; i < features.length; i++) { + feature = {}; + var analyticStreams = utility.getDeviceTypeConfig(deviceType)["analyticStreams"]; + if (analyticStreams) { + for (var stream in analyticStreams) { + if (analyticStreams[stream].name == features[i].name) { + feature.ui_unit = analyticStreams[stream].ui_unit; + break; + } + } + } + + feature["operation"] = features[i].code; + feature["name"] = features[i].name; + feature["description"] = features[i].description; + feature["deviceType"] = deviceType; + feature["params"] = []; + var metaData = features[i].metadataEntries; + if (metaData) { + for (var j = 0; j < metaData.length; j++) { + feature["params"].push(metaData[j].value); + } + featureList.push(feature); + } + } + return featureList; + }, function (responsePayload) { + var response = {}; + response["status"] = "error"; + return response; + } + ); + return featuresList; + }; + + publicMethods.getControlOperations = function (deviceType) { + var operations = privateMethods.getOperationsFromFeatures(deviceType, "operation"); + for (var op in operations) { + var iconPath = utility.getOperationIcon(deviceType, operations[op].operation); + if (iconPath) { + operations[op]["icon"] = iconPath; + } + } + return operations; + }; + + publicMethods.getMonitorOperations = function (deviceType) { + return privateMethods.getOperationsFromFeatures(deviceType, "monitor"); + }; + + publicMethods.handlePOSTOperation = function (deviceType, operation, deviceId, params) { + var user = session.get(constants.USER_SESSION_KEY); + var endPoint = devicemgtProps["httpsURL"] + '/' + deviceType + "/controller/" + operation; + var header = '{"owner":"' + user.username + '","deviceId":"' + deviceId + + '","protocol":"mqtt", "sessionId":"' + session.getId() + '", "' + + constants.AUTHORIZATION_HEADER + '":"' + constants.BEARER_PREFIX + + getAccessToken(deviceType, user.username, deviceId) + '"}'; + return post(endPoint, params, JSON.parse(header), "json"); + }; + + publicMethods.handleGETOperation = function (deviceType, operation, operationName, deviceId) { + var user = session.get(constants.USER_SESSION_KEY); + var endPoint = devicemgtProps["httpsURL"] + '/' + deviceType + "/controller/" + operation; + var header = '{"owner":"' + user.username + '","deviceId":"' + deviceId + + '","protocol":"mqtt", "' + constants.AUTHORIZATION_HEADER + '":"' + + constants.BEARER_PREFIX + getAccessToken(deviceType, user.username, deviceId) + + '"}'; + var result = get(endPoint, {}, JSON.parse(header), "json"); + if (result.data) { + var values = result.data.sensorValue.split(','); + if (operationName == 'gps') { + result.data.map = { + lat: parseFloat(values[0]), + lng: parseFloat(values[1]) + } + } else { + var sqSum = 0; + for (var v in values) { + sqSum += Math.pow(values[v], 2); + } + result.data[operationName] = Math.sqrt(sqSum); + } + delete result.data['sensorValue']; + } + return result; + }; -//var operationModule = function () { -// var log = new Log("/app/modules/business-controllers/operation.js"); -// var utility = require('/app/modules/utility.js').utility; -// var constants = require('/app/modules/constants.js'); -// var devicemgtProps = require("/app/modules/conf-reader/main.js")["conf"]; -// var serviceInvokers = require("/app/modules/oauth/token-protected-service-invokers.js")["invokers"]; -// -// var publicMethods = {}; -// var privateMethods = {}; -// -// /** -// * This method reads the token from the Token client and return the access token. -// * If the token pair s not set in the session this will send a redirect to the login page. -// */ -// function getAccessToken(deviceType, owner, deviceId) { -// var TokenClient = Packages.org.wso2.carbon.device.mgt.iot.apimgt.TokenClient; -// var accessTokenClient = new TokenClient(deviceType); -// var accessTokenInfo = accessTokenClient.getAccessToken(owner, deviceId); -// return accessTokenInfo.getAccess_token(); -// } -// -// privateMethods.getOperationsFromFeatures = function (deviceType, operationType) { -// var url = devicemgtProps["httpsURL"] + constants.ADMIN_SERVICE_CONTEXT + "/features/" + deviceType; -// var featuresList = serviceInvokers.XMLHttp.get(url, function (responsePayload) { -// var features = responsePayload; -// var featureList = []; -// var feature; -// for (var i = 0; i < features.length; i++) { -// feature = {}; -// var analyticStreams = utility.getDeviceTypeConfig(deviceType)["analyticStreams"]; -// if (analyticStreams) { -// for (var stream in analyticStreams) { -// if (analyticStreams[stream].name == features[i].name) { -// feature.ui_unit = analyticStreams[stream].ui_unit; -// break; -// } -// } -// } -// -// feature["operation"] = features[i].code; -// feature["name"] = features[i].name; -// feature["description"] = features[i].description; -// feature["deviceType"] = deviceType; -// feature["params"] = []; -// var metaData = features[i].metadataEntries; -// if (metaData) { -// for (var j = 0; j < metaData.length; j++) { -// feature["params"].push(metaData[j].value); -// } -// featureList.push(feature); -// } -// } -// return featureList; -// }, function (responsePayload) { -// var response = {}; -// response["status"] = "error"; -// return response; -// } -// ); -// return featuresList; -// }; -// -// publicMethods.getControlOperations = function (deviceType) { -// var operations = privateMethods.getOperationsFromFeatures(deviceType, "operation"); -// for (var op in operations) { -// var iconPath = utility.getOperationIcon(deviceType, operations[op].operation); -// if (iconPath) { -// operations[op]["icon"] = iconPath; -// } -// } -// return operations; -// }; -// -// publicMethods.getMonitorOperations = function (deviceType) { -// return privateMethods.getOperationsFromFeatures(deviceType, "monitor"); -// }; -// -// publicMethods.handlePOSTOperation = function (deviceType, operation, deviceId, params) { -// var user = session.get(constants.USER_SESSION_KEY); -// var endPoint = devicemgtProps["httpsURL"] + '/' + deviceType + "/controller/" + operation; -// var header = '{"owner":"' + user.username + '","deviceId":"' + deviceId + -// '","protocol":"mqtt", "sessionId":"' + session.getId() + '", "' + -// constants.AUTHORIZATION_HEADER + '":"' + constants.BEARER_PREFIX + -// getAccessToken(deviceType, user.username, deviceId) + '"}'; -// return post(endPoint, params, JSON.parse(header), "json"); -// }; -// -// publicMethods.handleGETOperation = function (deviceType, operation, operationName, deviceId) { -// var user = session.get(constants.USER_SESSION_KEY); -// var endPoint = devicemgtProps["httpsURL"] + '/' + deviceType + "/controller/" + operation; -// var header = '{"owner":"' + user.username + '","deviceId":"' + deviceId + -// '","protocol":"mqtt", "' + constants.AUTHORIZATION_HEADER + '":"' + -// constants.BEARER_PREFIX + getAccessToken(deviceType, user.username, deviceId) + -// '"}'; -// var result = get(endPoint, {}, JSON.parse(header), "json"); -// if (result.data) { -// var values = result.data.sensorValue.split(','); -// if (operationName == 'gps') { -// result.data.map = { -// lat: parseFloat(values[0]), -// lng: parseFloat(values[1]) -// } -// } else { -// var sqSum = 0; -// for (var v in values) { -// sqSum += Math.pow(values[v], 2); -// } -// result.data[operationName] = Math.sqrt(sqSum); -// } -// delete result.data['sensorValue']; -// } -// return result; -// }; -// -// return publicMethods; -//}(); \ No newline at end of file + return publicMethods; +}(); \ No newline at end of file From 160d8c2feb795174e67d593a13032dd45b24d410 Mon Sep 17 00:00:00 2001 From: kamidu Date: Tue, 2 Aug 2016 18:51:31 +0530 Subject: [PATCH 13/13] Fix the policy create wizard ui issues --- .../modules/business-controllers/policy.js | 291 +++++------------- .../units/cdmf.unit.policy.create/create.js | 10 +- 2 files changed, 90 insertions(+), 211 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/policy.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/policy.js index 6cc38a9bfe..f569accf61 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/policy.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/policy.js @@ -1,24 +1,21 @@ /* - * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * 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 + * 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 + * "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. */ -/* - @Refactored - */ var policyModule; policyModule = function () { var log = new Log("/app/modules/business-controllers/policy.js"); @@ -31,118 +28,90 @@ policyModule = function () { var publicMethods = {}; var privateMethods = {}; - privateMethods.handleGetAllPoliciesError = function (responsePayload) { + privateMethods.handleGetAllPoliciesResponse = function (backendResponse) { var response = {}; - response.status = "error"; - /* responsePayload == "Scope validation failed" - Here the response.context("Scope validation failed") is used other then response.status(401). - Reason for this is IDP return 401 as the status in 4 different situations such as, - 1. UnAuthorized. - 2. Scope Validation Failed. - 3. Permission Denied. - 4. Access Token Expired. - 5. Access Token Invalid. - In these cases in order to identify the correct situation we have to compare the unique value from status and - context which is context. - */ - if (responsePayload == "Scope validation failed") { - response.content = "Permission Denied"; - } else { - response.content = responsePayload; - } - return response; - }; + if (backendResponse.status == 200 && backendResponse.responseText) { + var isUpdated = false; + var policyListFromRestEndpoint = parse(backendResponse.responseText)["policies"]; + + var policyListToView = []; + var i, policyObjectFromRestEndpoint, policyObjectToView; + for (i = 0; i < policyListFromRestEndpoint.length; i++) { + // get list object + policyObjectFromRestEndpoint = policyListFromRestEndpoint[i]; + // populate list object values to view-object + policyObjectToView = {}; + policyObjectToView["id"] = policyObjectFromRestEndpoint["id"]; + policyObjectToView["priorityId"] = policyObjectFromRestEndpoint["priorityId"]; + policyObjectToView["name"] = policyObjectFromRestEndpoint["policyName"]; + policyObjectToView["platform"] = policyObjectFromRestEndpoint["profile"]["deviceType"]; + policyObjectToView["ownershipType"] = policyObjectFromRestEndpoint["ownershipType"]; + + var assignedRoleCount = policyObjectFromRestEndpoint["roles"].length; + var assignedUserCount = policyObjectFromRestEndpoint["users"].length; + + if (assignedRoleCount == 0) { + policyObjectToView["roles"] = "None"; + } else if (assignedRoleCount == 1) { + policyObjectToView["roles"] = policyObjectFromRestEndpoint["roles"][0]; + } else if (assignedRoleCount > 1) { + policyObjectToView["roles"] = policyObjectFromRestEndpoint["roles"][0] + ", ..."; + } - privateMethods.handleGetAllPoliciesSuccess = function (responsePayload) { - var isUpdated = false; - var policyListFromRestEndpoint = responsePayload["responseContent"]; - var policyListToView = []; - var i, policyObjectFromRestEndpoint, policyObjectToView; - for (i = 0; i < policyListFromRestEndpoint.length; i++) { - // get list object - policyObjectFromRestEndpoint = policyListFromRestEndpoint[i]; - // populate list object values to view-object - policyObjectToView = {}; - policyObjectToView["id"] = policyObjectFromRestEndpoint["id"]; - policyObjectToView["priorityId"] = policyObjectFromRestEndpoint["priorityId"]; - policyObjectToView["name"] = policyObjectFromRestEndpoint["policyName"]; - policyObjectToView["platform"] = policyObjectFromRestEndpoint["profile"]["deviceType"]["name"]; - policyObjectToView["icon"] = utility.getDeviceThumb(policyObjectToView["platform"]); - policyObjectToView["ownershipType"] = policyObjectFromRestEndpoint["ownershipType"]; - policyObjectToView["roles"] = privateMethods. - getElementsInAString(policyObjectFromRestEndpoint["roles"]); - policyObjectToView["users"] = privateMethods. - getElementsInAString(policyObjectFromRestEndpoint["users"]); - policyObjectToView["compliance"] = policyObjectFromRestEndpoint["compliance"]; + if (assignedUserCount == 0) { + policyObjectToView["users"] = "None"; + } else if (assignedUserCount == 1) { + policyObjectToView["users"] = policyObjectFromRestEndpoint["users"][0]; + } else if (assignedUserCount > 1) { + policyObjectToView["users"] = policyObjectFromRestEndpoint["users"][0] + ", ..."; + } - if (policyObjectFromRestEndpoint["active"] == true && policyObjectFromRestEndpoint["updated"] == true) { - policyObjectToView["status"] = "Active/Updated"; - isUpdated = true; - } else if (policyObjectFromRestEndpoint["active"] == true && - policyObjectFromRestEndpoint["updated"] == false) { - policyObjectToView["status"] = "Active"; - } else if (policyObjectFromRestEndpoint["active"] == false && - policyObjectFromRestEndpoint["updated"] == true) { - policyObjectToView["status"] = "Inactive/Updated"; - isUpdated = true; - } else if (policyObjectFromRestEndpoint["active"] == false && - policyObjectFromRestEndpoint["updated"] == false) { - policyObjectToView["status"] = "Inactive"; + policyObjectToView["compliance"] = policyObjectFromRestEndpoint["compliance"]; + + if (policyObjectFromRestEndpoint["active"] == true && + policyObjectFromRestEndpoint["updated"] == true) { + policyObjectToView["status"] = "Active/Updated"; + isUpdated = true; + } else if (policyObjectFromRestEndpoint["active"] == true && + policyObjectFromRestEndpoint["updated"] == false) { + policyObjectToView["status"] = "Active"; + } else if (policyObjectFromRestEndpoint["active"] == false && + policyObjectFromRestEndpoint["updated"] == true) { + policyObjectToView["status"] = "Inactive/Updated"; + isUpdated = true; + } else if (policyObjectFromRestEndpoint["active"] == false && + policyObjectFromRestEndpoint["updated"] == false) { + policyObjectToView["status"] = "Inactive"; + } + // push view-objects to list + policyListToView.push(policyObjectToView); } - // push view-objects to list - policyListToView.push(policyObjectToView); - } - // generate response - var response = {}; - response.updated = isUpdated; - response.status = "success"; - response.content = policyListToView; - return response; - }; + // generate response + response.updated = isUpdated; + response.status = "success"; + response.content = policyListToView; - publicMethods.addPolicy = function (policyName, deviceType, policyDefinition, policyDescription, - deviceId) { - 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"]; - } - if (policyName && deviceType) { - var queName = "WSO2IoTServer/" + carbonUser.username + "/" + deviceType; - var deviceQueName; - if (deviceId) { - deviceQueName = queName + "/" + deviceId; - privateMethods.publish(deviceQueName, policyName, deviceType, policyDefinition); + return response; + } else { + response.status = "error"; + /* backendResponse.responseText == "Scope validation failed" + Here the response.context("Scope validation failed") is used other then response.status(401). + Reason for this is IDP return 401 as the status in 4 different situations such as, + 1. UnAuthorized. + 2. Scope Validation Failed. + 3. Permission Denied. + 4. Access Token Expired. + 5. Access Token Invalid. + In these cases in order to identify the correct situation we have to compare the unique value from status and + context which is context. + */ + if (backendResponse.responseText == "Scope validation failed") { + response.content = "Permission Denied"; } else { - var deviceManagementService = utility.getDeviceManagementService(); - var devices = deviceManagementService.getDevicesOfUser(carbonUser.username); - var device; - for (var i = 0; i < devices.size(); i++) { - device = devices.get(i); - deviceId = device.getDeviceIdentifier(); - deviceQueName = queName + "/" + deviceId; - privateMethods.publish(deviceQueName, policyName, deviceType, policyDefinition); - } + response.content = backendResponse.responseText; } - return true; + return response; } - return false; - }; - - privateMethods.publish = function (queName, policyName, deviceType, policyDefinition) { - var configurationService = utility.getConfigurationService(); - var mqttEndPointDeviceConfig = configurationService.getControlQueue(constants.MQTT_QUEUE_CONFIG_NAME); - var mqttBrokerURL = mqttEndPointDeviceConfig.getServerURL(); - var mqttBrokerPort = mqttEndPointDeviceConfig.getPort(); - var mqttQueueEndpoint = mqttBrokerURL + ":" + mqttBrokerPort; - - var mqttsenderClass = Packages.org.wso2.carbon.device.mgt.iot.mqtt.PolicyPush; - var mqttsender = new mqttsenderClass(); - - var policyPayload = "POLICY:" + policyDefinition; - var result = mqttsender.pushToMQTT(queName, policyPayload, mqttQueueEndpoint, "MQTT_Agent"); - mqttsender = null; - return result; }; /* @@ -155,9 +124,9 @@ policyModule = function () { throw constants["ERRORS"]["USER_NOT_FOUND"]; } try { - var url = devicemgtProps["httpsURL"] + constants.ADMIN_SERVICE_CONTEXT + "/policies"; - return serviceInvokers.XMLHttp. - get(url, privateMethods.handleGetAllPoliciesSuccess, privateMethods.handleGetAllPoliciesError); + var url = devicemgtProps["httpsURL"] + devicemgtProps["backendRestEndpoints"]["deviceMgt"] + + "/policies?offset=0&limit=100"; + return serviceInvokers.XMLHttp.get(url, privateMethods.handleGetAllPoliciesResponse); } catch (e) { throw e; } @@ -178,97 +147,5 @@ policyModule = function () { return elementsInAString; }; - /* - @Deprecated - */ - publicMethods.getProfiles = function () { - var carbonUser = session.get(constants.USER_SESSION_KEY); - var utility = require('/app/modules/utility.js').utility; - if (!carbonUser) { - log.error("User object was not found in the session"); - throw constants.ERRORS.USER_NOT_FOUND; - } - try { - utility.startTenantFlow(carbonUser); - var policyManagementService = utility.getPolicyManagementService(); - var policyAdminPoint = policyManagementService.getPAP(); - var profiles = policyAdminPoint.getProfiles(); - var profileList = []; - var i, profile, profileObject; - for (i = 0; i < profiles.size(); i++) { - profile = profiles.get(i); - profileObject = {}; - profileObject.name = profile.getProfileName(); - profileObject.id = profile.getProfileId(); - profileList.push(profileObject); - } - return profileList; - } catch (e) { - throw e; - } finally { - utility.endTenantFlow(); - } - }; - - /* - @Deprecated - */ - publicMethods.updatePolicyPriorities = function (payload) { - 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; - } - try { - utility.startTenantFlow(carbonUser); - var policyManagementService = utility.getPolicyManagementService(); - var policyAdminPoint = policyManagementService.getPAP(); - var policyCount = payload.length; - var policyList = new java.util.ArrayList(); - var i, policyObject; - for (i = 0; i < policyCount; i++) { - policyObject = new Policy(); - policyObject.setId(payload[i].id); - policyObject.setPriorityId(payload[i].priority); - policyList.add(policyObject); - } - policyAdminPoint.updatePolicyPriorities(policyList); - } catch (e) { - throw e; - } finally { - utility.endTenantFlow(); - } - }; - - /* - @Deprecated - */ - publicMethods.deletePolicy = function (policyId) { - var isDeleted; - var carbonUser = session.get(constants.USER_SESSION_KEY); - var utility = require('/app/modules/utility.js').utility; - if (!carbonUser) { - log.error("User object was not found in the session"); - throw constants.ERRORS.USER_NOT_FOUND; - } - try { - utility.startTenantFlow(carbonUser); - var policyManagementService = utility.getPolicyManagementService(); - var policyAdminPoint = policyManagementService.getPAP(); - isDeleted = policyAdminPoint.deletePolicy(policyId); - if (isDeleted) { - // http status code 200 refers to - success. - return 200; - } else { - // http status code 409 refers to - conflict. - return 409; - } - } catch (e) { - throw e; - } finally { - utility.endTenantFlow(); - } - }; - return publicMethods; -}(); +}(); \ No newline at end of file diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.policy.create/create.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.policy.create/create.js index cf46e20def..28142c13eb 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.policy.create/create.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.policy.create/create.js @@ -28,7 +28,9 @@ function onRequest(context) { var typesListResponse = userModule.getPlatforms(); if (typesListResponse["status"] == "success") { for (var type in typesListResponse["content"]) { - var deviceType = typesListResponse["content"][type]["name"]; + var content = {}; + var deviceType = typesListResponse["content"]["deviceTypes"][type]; + content["name"] = deviceType; var configs = utility.getDeviceTypeConfig(deviceType); var deviceTypeLabel = deviceType; if (configs && configs[DTYPE_CONF_DEVICE_TYPE_KEY][DTYPE_CONF_DEVICE_TYPE_LABEL_KEY]) { @@ -36,9 +38,9 @@ function onRequest(context) { } var policyWizard = new File("/app/units/" + utility.getTenantedDeviceUnitName(deviceType, "policy-wizard")); if(policyWizard.isExists()){ - typesListResponse["content"][type]["icon"] = utility.getDeviceThumb(deviceType); - typesListResponse["content"][type]["label"] = deviceTypeLabel; - types["types"].push(typesListResponse["content"][type]); + content["icon"] = utility.getDeviceThumb(deviceType); + content["label"] = deviceTypeLabel; + types["types"].push(content); } } }