From 03f323d6e284ecc7b126a3a86272b13abd55bc40 Mon Sep 17 00:00:00 2001 From: Dulitha Wijewantha Date: Mon, 18 Jul 2016 12:29:58 +0530 Subject: [PATCH 01/24] Fixed a bug where getBoolean wasn't used --- .../core/operation/mgt/dao/impl/CommandOperationDAOImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/CommandOperationDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/CommandOperationDAOImpl.java index 464597dc05..d21872b103 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/CommandOperationDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/CommandOperationDAOImpl.java @@ -99,7 +99,7 @@ public class CommandOperationDAOImpl extends GenericOperationDAOImpl { if (rs.next()) { commandOperation = new CommandOperation(); - commandOperation.setEnabled(rs.getInt("ENABLED") != 0); + commandOperation.setEnabled(rs.getBoolean("ENABLED")); } } catch (SQLException e) { throw new OperationManagementDAOException("SQL Error occurred while retrieving the command operation " + From b8635db485350ad57e9a288cf7c546a0ddfb400a Mon Sep 17 00:00:00 2001 From: Ace Date: Thu, 21 Jul 2016 07:42:20 +0530 Subject: [PATCH 02/24] Adding changes to common modules to accomodate ui restructuring --- .../app/modules/backend-service-invoker.js | 401 +++++++++--------- .../jaggeryapps/devicemgt/app/modules/util.js | 9 +- .../public/js/invoker-lib.js | 95 ++--- 3 files changed, 250 insertions(+), 255 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/backend-service-invoker.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/backend-service-invoker.js index 30c5edaff8..19e5a7c379 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/backend-service-invoker.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/backend-service-invoker.js @@ -1,43 +1,47 @@ /* - * 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. */ /** - * This backendServiceInvoker contains the wrappers for back end jaggary calls. + * This backendServiceInvoker contains the wrappers for back end jaggery calls. */ var backendServiceInvoker = function () { var log = new Log("/app/modules/backend-service-invoker.js"); + var publicXMLHTTPInvokers = {}; + var publicHTTPClientInvokers = {}; + var privateMethods = {}; var publicWSInvokers = {}; - var publicHTTPClientInvokers = {}; - var IS_OAUTH_ENABLED = true; + var TOKEN_EXPIRED = "Access token expired"; var TOKEN_INVALID = "Invalid input. Access token validation failed"; + + var devicemgtProps = require("/app/conf/devicemgt-props.js").config(); var constants = require("/app/modules/constants.js"); - var tokenUtil = require("/app/modules/api-wrapper-util.js").apiWrapperUtil; - var devicemgtProps = require('/app/conf/devicemgt-props.js').config(); + var userModule = require("/app/modules/user.js")["userModule"]; + var tokenUtil = require("/app/modules/api-wrapper-util.js")["apiWrapperUtil"]; /** - * This methoad reads the token pair from the session and return the access token. + * This method reads the token pair from the session and return the access token. * If the token pair s not set in the session this will send a redirect to the login page. */ privateMethods.getAccessToken = function () { - var tokenPair = session.get(constants.ACCESS_TOKEN_PAIR_IDENTIFIER); + var tokenPair = session.get(constants["ACCESS_TOKEN_PAIR_IDENTIFIER"]); if (tokenPair) { return tokenPair.accessToken; } else { @@ -46,152 +50,119 @@ var backendServiceInvoker = function () { }; /** - * This method add Oauth authentication header to outgoing XMLHTTP Requests if Oauth authentication is enabled. - * @param method HTTP request type. - * @param url target url. - * @param payload payload/data which need to be send. - * @param successCallback a function to be called if the respond if successful. - * @param errorCallback a function to be called if en error is reserved. + * --------------------------------------------------------------------------- + * Start of XML-HTTP-REQUEST based Interceptor implementations + * --------------------------------------------------------------------------- + */ + + /** + * This method add Oauth authentication header to outgoing XML-HTTP Requests if Oauth authentication is enabled. + * @param httpMethod HTTP request type. + * @param requestPayload payload/data if exists which is needed to be send. + * @param endpoint Backend REST API url. + * @param responseCallback a function to be called with response retrieved. * @param count a counter which hold the number of recursive execution */ - privateMethods.execute = function (method, url, successCallback, errorCallback, payload, count, contentType, acceptType) { + privateMethods.execute = function (httpMethod, requestPayload, endpoint, responseCallback, count) { var xmlHttpRequest = new XMLHttpRequest(); - xmlHttpRequest.open(method, url); - if(!contentType){ - contentType = constants.APPLICATION_JSON; - } - if(!acceptType){ - acceptType = constants.APPLICATION_JSON; - } - xmlHttpRequest.setRequestHeader(constants.CONTENT_TYPE_IDENTIFIER, contentType); - xmlHttpRequest.setRequestHeader(constants.ACCEPT_IDENTIFIER, acceptType); - xmlHttpRequest.setRequestHeader(constants.REFERER, String(privateMethods.getClientDomain())); - if (IS_OAUTH_ENABLED) { + + xmlHttpRequest.open(httpMethod, endpoint); + xmlHttpRequest.setRequestHeader(constants["CONTENT_TYPE_IDENTIFIER"], constants["APPLICATION_JSON"]); + xmlHttpRequest.setRequestHeader(constants["ACCEPT_IDENTIFIER"], constants["APPLICATION_JSON"]); + + if (devicemgtProps["isOAuthEnabled"]) { var accessToken = privateMethods.getAccessToken(); if (!accessToken) { - response.sendRedirect(devicemgtProps["httpsURL"] + "/devicemgt/login"); + userModule.logout(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); } } - if (payload) { - xmlHttpRequest.send(payload); + + if (requestPayload) { + xmlHttpRequest.send(requestPayload); } else { xmlHttpRequest.send(); } - if ((xmlHttpRequest.status >= 200 && xmlHttpRequest.status < 300) || xmlHttpRequest.status == 302) { - if (xmlHttpRequest.responseText != null) { - return successCallback(parse(xmlHttpRequest.responseText)); - } else { - return successCallback({"status": xmlHttpRequest.status, "messageFromServer": "Operation Completed"}); - } - } else if (xmlHttpRequest.status == 401 && (xmlHttpRequest.responseText == TOKEN_EXPIRED || - xmlHttpRequest.responseText == TOKEN_INVALID ) && count < 5) { + 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("Response headers : " + xmlHttpRequest.getAllResponseHeaders()); + + if (xmlHttpRequest.status == 401 && (xmlHttpRequest.responseText == TOKEN_EXPIRED || + xmlHttpRequest.responseText == TOKEN_INVALID ) && count < 5) { tokenUtil.refreshToken(); - return privateMethods.execute(method, url, successCallback, errorCallback, payload, (count + 1)); - } else if (xmlHttpRequest.status == 500) { - return errorCallback(xmlHttpRequest); + return privateMethods.execute(httpMethod, requestPayload, endpoint, responseCallback, ++count); } else { - return errorCallback(xmlHttpRequest); + return responseCallback(xmlHttpRequest); } }; /** - * This method add Oauth authentication header to outgoing XMLHTTP Requests if Oauth authentication is enabled. - * @param method HTTP request type. - * @param url target url. - * @param payload payload/data which need to be send. - * @param successCallback a function to be called if the respond if successful. - * @param errorCallback a function to be called if en error is reserved. + * This method add Oauth authentication header to outgoing XML-HTTP Requests if Oauth authentication is enabled. + * @param httpMethod HTTP request type. + * @param requestPayload payload/data if exists which is needed to be send. + * @param endpoint Backend REST API url. + * @param responseCallback a function to be called with response retrieved. */ - privateMethods.initiateXMLHTTPRequest = function (method, url, successCallback, errorCallback, payload, contentType, acceptType) { - if (privateMethods.getAccessToken()) { - return privateMethods.execute(method, url, successCallback, errorCallback, payload, 0, contentType, acceptType); - } + privateMethods.initiateXMLHTTPRequest = function (httpMethod, requestPayload, endpoint, responseCallback) { + return privateMethods.execute(httpMethod, requestPayload, endpoint, responseCallback, 0); }; /** - * This method add Oauth authentication header to outgoing HTTPClient Requests if Oauth authentication is enabled. - * @param method HTTP request type. - * @param url target url. - * @param payload payload/data which need to be send. - * @param successCallback a function to be called if the respond if successful. - * @param errorCallback a function to be called if en error is reserved. + * This method invokes return initiateXMLHttpRequest for get calls + * @param endpoint Backend REST API url. + * @param responseCallback a function to be called with response retrieved. */ - privateMethods.initiateHTTPClientRequest = function (method, url, successCallback, errorCallback, payload, contentType, acceptType) { - var HttpClient = Packages.org.apache.commons.httpclient.HttpClient; - var httpMethodObject; - switch (method) { - case constants.HTTP_POST: - var PostMethod = Packages.org.apache.commons.httpclient.methods.PostMethod; - httpMethodObject = new PostMethod(url); - break; - case constants.HTTP_PUT: - var PutMethod = Packages.org.apache.commons.httpclient.methods.PutMethod; - httpMethodObject = new PutMethod(url); - break; - case constants.HTTP_GET: - var GetMethod = Packages.org.apache.commons.httpclient.methods.GetMethod; - httpMethodObject = new GetMethod(url); - break; - case constants.HTTP_DELETE: - var DeleteMethod = Packages.org.apache.commons.httpclient.methods.DeleteMethod; - httpMethodObject = new DeleteMethod(url); - break; - default: - throw new IllegalArgumentException("Invalid HTTP request type: " + method); - } - var Header = Packages.org.apache.commons.httpclient.Header; - var header = new Header(); - header.setName(constants.CONTENT_TYPE_IDENTIFIER); - header.setValue(contentType); - httpMethodObject.addRequestHeader(header); - header = new Header(); - header.setName(constants.ACCEPT_IDENTIFIER); - header.setValue(acceptType); - httpMethodObject.addRequestHeader(header); - header = new Header(); - header.setName(constants.REFERER); - header.setValue(String(privateMethods.getClientDomain())); - httpMethodObject.addRequestHeader(header); - if (IS_OAUTH_ENABLED) { - var accessToken = privateMethods.getAccessToken(); - if (accessToken) { - header = new Header(); - header.setName(constants.AUTHORIZATION_HEADER); - header.setValue(constants.BEARER_PREFIX + accessToken); - httpMethodObject.addRequestHeader(header); - } else { - response.sendRedirect(devicemgtProps["httpsURL"] + "/devicemgt/login"); - } + publicXMLHTTPInvokers.get = function (endpoint, responseCallback) { + var requestPayload = null; + return privateMethods.initiateXMLHTTPRequest(constants["HTTP_GET"], requestPayload, endpoint, responseCallback); + }; - } - if (payload) { - var stringRequestEntity = new StringRequestEntity(stringify(payload)); - httpMethodObject.setRequestEntity(stringRequestEntity); - } - var client = new HttpClient(); - try { - client.executeMethod(httpMethodObject); - var status = httpMethodObject.getStatusCode(); - if (status == 200) { - var responseContentDispositionHeader = httpMethodObject.getResponseHeader(constants.CONTENT_DISPOSITION_IDENTIFIER); - if (responseContentDispositionHeader) { - return successCallback(httpMethodObject.getResponseBodyAsStream(), httpMethodObject.getResponseHeaders()); - } else { - return successCallback(httpMethodObject.getResponseBody()); - } - } else { - return errorCallback(httpMethodObject.getResponseBody()); - } - } catch (e) { - return errorCallback(response); - } finally { - httpMethodObject.releaseConnection(); - } + /** + * This method invokes return initiateXMLHttpRequest for post calls + * @param endpoint Backend REST API url. + * @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) { + return privateMethods.initiateXMLHTTPRequest(constants["HTTP_POST"], requestPayload, endpoint, responseCallback); + }; + + /** + * This method invokes return initiateXMLHttpRequest for put calls + * @param endpoint Backend REST API url. + * @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) { + return privateMethods.initiateXMLHTTPRequest(constants["HTTP_PUT"], requestPayload, endpoint, responseCallback); }; + /** + * This method invokes return initiateXMLHttpRequest for delete calls + * @param endpoint Backend REST API url. + * @param responseCallback a function to be called with response retrieved. + */ + publicXMLHTTPInvokers.delete = function (endpoint, responseCallback) { + var requestPayload = null; + return privateMethods.initiateXMLHTTPRequest(constants["HTTP_DELETE"], requestPayload, endpoint, responseCallback); + }; + + /** + * --------------------------------------------------------------------------- + * Start of WS-REQUEST based Interceptor implementations + * --------------------------------------------------------------------------- + */ + /** * This method add Oauth authentication header to outgoing WS Requests if Oauth authentication is enabled. * @param action @@ -202,32 +173,26 @@ var backendServiceInvoker = function () { * @param soapVersion soapVersion which need to used. */ privateMethods.initiateWSRequest = function (action, endpoint, successCallback, errorCallback, soapVersion, payload) { - var ws = require('ws'); + var ws = require("ws"); var wsRequest = new ws.WSRequest(); var options = []; - if (IS_OAUTH_ENABLED) { + if (devicemgtProps["isOAuthEnabled"]) { var accessToken = privateMethods.getAccessToken(); if (accessToken) { - var authenticationHeaderName = String(constants.AUTHORIZATION_HEADER); - var authenticationHeaderValue = String(constants.BEARER_PREFIX + accessToken); + var authenticationHeaderName = String(constants["AUTHORIZATION_HEADER"]); + var authenticationHeaderValue = String(constants["BEARER_PREFIX"] + accessToken); var headers = []; var oAuthAuthenticationData = {}; oAuthAuthenticationData.name = authenticationHeaderName; oAuthAuthenticationData.value = authenticationHeaderValue; headers.push(oAuthAuthenticationData); - - var referrerData = {}; - referrerData.name = constants.REFERER; - referrerData.value = String(privateMethods.getClientDomain()); - headers.push(referrerData); - options.HTTPHeaders = headers; } else { - response.sendRedirect(devicemgtProps["httpsURL"] + "/devicemgt/login"); + response.sendRedirect(devicemgtProps["appContext"] + "login"); } } options.useSOAP = soapVersion; - options.useWSA = constants.WEB_SERVICE_ADDRESSING_VERSION; + options.useWSA = constants["WEB_SERVICE_ADDRESSING_VERSION"]; options.action = action; var wsResponse; try { @@ -245,68 +210,104 @@ var backendServiceInvoker = function () { }; /** - * This method invokes return initiateXMLHttpRequest for get calls - * @param url target url. + * This method invokes return initiateWSRequest for soap calls + * @param action describes particular soap action. + * @param requestPayload SOAP request payload which is needed to be send. + * @param endpoint service end point to be triggered. * @param successCallback a function to be called if the respond if successful. * @param errorCallback a function to be called if en error is reserved. + * @param soapVersion soapVersion which need to used. */ - publicXMLHTTPInvokers.get = function (url, successCallback, errorCallback, contentType, acceptType) { - return privateMethods.initiateXMLHTTPRequest(constants.HTTP_GET, url, successCallback, errorCallback, contentType, acceptType); + publicWSInvokers.soapRequest = function (action, requestPayload, endpoint, successCallback, errorCallback, soapVersion) { + return privateMethods.initiateWSRequest(action, endpoint, successCallback, errorCallback, soapVersion, requestPayload); }; /** - * This method invokes return initiateXMLHttpRequest for post calls - * @param url target url. - * @param payload payload/data which need to be send. - * @param successCallback a function to be called if the respond if successful. - * @param errorCallback a function to be called if en error is reserved. + * --------------------------------------------------------------------------- + * Start of HTTP-CLIENT-REQUEST based Interceptor implementations + * --------------------------------------------------------------------------- */ - publicXMLHTTPInvokers.post = function (url, payload, successCallback, errorCallback, contentType, acceptType) { - return privateMethods.initiateXMLHTTPRequest(constants.HTTP_POST, url, successCallback, errorCallback, payload, contentType, acceptType); - }; /** - * This method invokes return initiateXMLHttpRequest for put calls + * This method add Oauth authentication header to outgoing HTTPClient Requests if Oauth authentication is enabled. + * @param method HTTP request type. * @param url target url. * @param payload payload/data which need to be send. * @param successCallback a function to be called if the respond if successful. * @param errorCallback a function to be called if en error is reserved. */ - publicXMLHTTPInvokers.put = function (url, payload, successCallback, errorCallback, contentType, acceptType) { - return privateMethods.initiateXMLHTTPRequest(constants.HTTP_PUT, url, successCallback, errorCallback, payload, contentType, acceptType); - }; - - /** - * This method invokes return initiateXMLHttpRequest for delete calls - * @param url target url. - * @param successCallback a function to be called if the respond if successful. - * @param errorCallback a function to be called if en error is reserved. - */ - publicXMLHTTPInvokers.delete = function (url, successCallback, errorCallback, contentType, acceptType) { - return privateMethods.initiateXMLHTTPRequest(constants.HTTP_DELETE, url, successCallback, errorCallback, contentType, acceptType); - }; + privateMethods.initiateHTTPClientRequest = function (method, url, successCallback, errorCallback, payload) { + var HttpClient = Packages.org.apache.commons.httpclient.HttpClient; + var httpMethodObject; + switch (method) { + case constants["HTTP_GET"]: + var GetMethod = Packages.org.apache.commons.httpclient.methods.GetMethod; + httpMethodObject = new GetMethod(url); + break; + case constants["HTTP_POST"]: + var PostMethod = Packages.org.apache.commons.httpclient.methods.PostMethod; + httpMethodObject = new PostMethod(url); + break; + case constants["HTTP_PUT"]: + var PutMethod = Packages.org.apache.commons.httpclient.methods.PutMethod; + httpMethodObject = new PutMethod(url); + break; + case constants["HTTP_DELETE"]: + var DeleteMethod = Packages.org.apache.commons.httpclient.methods.DeleteMethod; + httpMethodObject = new DeleteMethod(url); + break; + default: + throw new IllegalArgumentException("Invalid HTTP request method: " + method); + } + var Header = Packages.org.apache.commons.httpclient.Header; + var header = new Header(); + header.setName(constants["CONTENT_TYPE_IDENTIFIER"]); + header.setValue(constants["APPLICATION_JSON"]); + httpMethodObject.addRequestHeader(header); + header = new Header(); + header.setName(constants["ACCEPT_IDENTIFIER"]); + header.setValue(constants["APPLICATION_JSON"]); + httpMethodObject.addRequestHeader(header); - /** - * This method invokes return initiateWSRequest for soap calls - * @param endpoint service end point to be triggered. - * @param payload soap payload which need to be send. - * @param successCallback a function to be called if the respond if successful. - * @param errorCallback a function to be called if en error is reserved. - * @param soapVersion soapVersion which need to used. - */ - publicWSInvokers.soapRequest = function (action, endpoint, payload, successCallback, errorCallback, soapVersion) { - return privateMethods.initiateWSRequest(action, endpoint, successCallback, errorCallback, soapVersion, payload); + if (devicemgtProps["isOAuthEnabled"]) { + var accessToken = privateMethods.getAccessToken(); + if (accessToken) { + header = new Header(); + header.setName(constants["AUTHORIZATION_HEADER"]); + header.setValue(constants["BEARER_PREFIX"] + accessToken); + httpMethodObject.addRequestHeader(header); + } else { + response.sendRedirect(devicemgtProps["appContext"] + "login"); + } + } + var stringRequestEntity = new StringRequestEntity(stringify(payload)); + httpMethodObject.setRequestEntity(stringRequestEntity); + var client = new HttpClient(); + try { + client.executeMethod(httpMethodObject); + var status = httpMethodObject.getStatusCode(); + if (status == 200) { + return successCallback(httpMethodObject.getResponseBody()); + } else { + return errorCallback(httpMethodObject.getResponseBody()); + } + } catch (e) { + return errorCallback(response); + } finally { + method.releaseConnection(); + } }; - /** * This method invokes return initiateHTTPClientRequest for get calls * @param url target url. * @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, contentType, acceptType) { - return privateMethods.initiateHTTPClientRequest(constants.HTTP_GET, url, successCallback, errorCallback, null, contentType, acceptType); + publicHTTPClientInvokers.get = function (url, successCallback, errorCallback) { + var requestPayload = null; + return privateMethods. + initiateHTTPClientRequest(constants["HTTP_GET"], url, successCallback, errorCallback, requestPayload); }; /** @@ -316,9 +317,9 @@ var backendServiceInvoker = 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, contentType, acceptType) { + publicHTTPClientInvokers.post = function (url, payload, successCallback, errorCallback) { return privateMethods. - initiateHTTPClientRequest(constants.HTTP_POST, url, successCallback, errorCallback, payload, contentType, acceptType); + initiateHTTPClientRequest(constants["HTTP_POST"], url, successCallback, errorCallback, payload); }; /** @@ -328,8 +329,9 @@ var backendServiceInvoker = 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, contentType, acceptType) { - return privateMethods.initiateHTTPClientRequest(constants.HTTP_PUT, url, successCallback, errorCallback, payload, contentType, acceptType); + publicHTTPClientInvokers.put = function (url, payload, successCallback, errorCallback) { + return privateMethods. + initiateHTTPClientRequest(constants["HTTP_PUT"], url, successCallback, errorCallback, payload); }; /** @@ -338,23 +340,16 @@ var backendServiceInvoker = 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, contentType, acceptType) { - return privateMethods.initiateHTTPClientRequest(constants.HTTP_DELETE, url, successCallback, errorCallback, contentType, acceptType); + publicHTTPClientInvokers.delete = function (url, successCallback, errorCallback) { + var requestPayload = null; + return privateMethods. + initiateHTTPClientRequest(constants["HTTP_DELETE"], url, successCallback, errorCallback, requestPayload); }; - /** - * This method fetch the current logged user from the session and returns - * the tenant domain name of the user - * @returns {tenantDomain} - */ - privateMethods.getClientDomain = function () { - var user = session.get(constants.USER_SESSION_KEY); - return user.domain; - } + var publicMethods = {}; + publicMethods.XMLHttp = publicXMLHTTPInvokers; + publicMethods.WS = publicWSInvokers; + publicMethods.HttpClient = publicHTTPClientInvokers; - var publicInvokers = {}; - publicInvokers.XMLHttp = publicXMLHTTPInvokers; - publicInvokers.WS = publicWSInvokers; - publicInvokers.HttpClient = publicHTTPClientInvokers; - return publicInvokers; -}(); \ No newline at end of file + return publicMethods; +}(); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/util.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/util.js index 1deb5c6093..3334ea6664 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/util.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/util.js @@ -25,11 +25,12 @@ var util = function () { var carbon = require('carbon'); var constants = require("/app/modules/constants.js"); var adminUser = devicemgtProps["adminUser"]; + var clientName = devicemgtProps["clientName"]; module.getDyanmicCredentials = function (owner) { var payload = { "callbackUrl": devicemgtProps.callBackUrl, - "clientName": "devicemgt", + "clientName": clientName, "tokenScope": "admin", "owner": adminUser, "applicationType": "webapp", @@ -79,7 +80,7 @@ var util = function () { */ module.getTokenWithPasswordGrantType = function (username, password, encodedClientKeys, scope) { var xhr = new XMLHttpRequest(); - var tokenEndpoint = devicemgtProps.idPServer + "/token"; + var tokenEndpoint = devicemgtProps.idPServer; xhr.open("POST", tokenEndpoint, false); xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); xhr.setRequestHeader("Authorization", "Basic " + encodedClientKeys); @@ -119,7 +120,7 @@ var util = function () { encodedExtractedAssertion = this.encode(extractedAssertion); var xhr = new XMLHttpRequest(); - var tokenEndpoint = devicemgtProps.idPServer + "/token"; + var tokenEndpoint = devicemgtProps.idPServer; xhr.open("POST", tokenEndpoint, false); xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); xhr.setRequestHeader("Authorization", "Basic " + clientKeys); @@ -140,7 +141,7 @@ var util = function () { module.refreshToken = function (tokenPair, clientData, scope) { var xhr = new XMLHttpRequest(); - var tokenEndpoint = devicemgtProps.idPServer + "/token"; + var tokenEndpoint = devicemgtProps.idPServer; xhr.open("POST", tokenEndpoint, false); xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); xhr.setRequestHeader("Authorization", "Basic " + clientData); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.lib.service-invoker-utility/public/js/invoker-lib.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.lib.service-invoker-utility/public/js/invoker-lib.js index cd9d2e5d29..30f2be1c64 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.lib.service-invoker-utility/public/js/invoker-lib.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.lib.service-invoker-utility/public/js/invoker-lib.js @@ -1,72 +1,71 @@ /* - * 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. */ var invokerUtil = function () { - var module = {}; + var publicMethods = {}; + var privateMethods = {}; - var END_POINT = window.location.origin+"/devicemgt/api/invoker/execute/"; + privateMethods.execute = function (requestMethod, requestURL, requestPayload, successCallback, errorCallback) { + var restAPIRequestDetails = {}; + restAPIRequestDetails["requestMethod"] = requestMethod; + restAPIRequestDetails["requestURL"] = requestURL; + restAPIRequestDetails["requestPayload"] = JSON.stringify(requestPayload); + var appContext = devicemgtProps["appContext"]; - module.get = function (url, successCallback, errorCallback, contentType, acceptType) { - var payload = null; - execute("GET", url, payload, successCallback, errorCallback, contentType, acceptType); + var request = { + url: appContext + "api/invoker/execute/", + type: "POST", + contentType: "application/json", + data: JSON.stringify(restAPIRequestDetails), + accept: "application/json", + success: successCallback, + error: function (jqXHR) { + if (jqXHR.status == 401) { + console.log("Unauthorized access attempt!"); + $(modalPopupContent).html($("#error-msg").html()); + showPopup(); + } else { + errorCallback(jqXHR); + } + } + }; + + $.ajax(request); }; - module.post = function (url, payload, successCallback, errorCallback, contentType, acceptType) { - execute("POST", url, payload, successCallback, errorCallback, contentType, acceptType); + + publicMethods.get = function (requestURL, successCallback, errorCallback) { + var requestPayload = null; + privateMethods.execute("GET", requestURL, requestPayload, successCallback, errorCallback); }; - module.put = function (url, payload, successCallback, errorCallback, contentType, acceptType) { - execute("PUT", url, payload, successCallback, errorCallback, contentType, acceptType); + + publicMethods.post = function (requestURL, requestPayload, successCallback, errorCallback) { + privateMethods.execute("POST", requestURL, requestPayload, successCallback, errorCallback); }; - module.delete = function (url, successCallback, errorCallback, contentType, acceptType) { - var payload = null; - execute("DELETE", url, payload, successCallback, errorCallback, contentType, acceptType); + + publicMethods.put = function (requestURL, requestPayload, successCallback, errorCallback) { + privateMethods.execute("PUT", requestURL, requestPayload, successCallback, errorCallback); }; - function execute (methoad, url, payload, successCallback, errorCallback, contentType, acceptType) { - if(contentType == undefined){ - contentType = "application/json"; - } - if(acceptType == undefined){ - acceptType = "application/json"; - } - var data = { - url: END_POINT, - type: "POST", - contentType: contentType, - accept: acceptType, - success: successCallback - }; - var paramValue = {}; - paramValue.actionMethod = methoad; - paramValue.actionUrl = url; - paramValue.actionPayload = payload; - if(contentType == "application/json"){ - paramValue.actionPayload = JSON.stringify(payload); - } - data.data = JSON.stringify(paramValue); - $.ajax(data).fail(function (jqXHR) { - if (jqXHR.status == "401") { - console.log("Unauthorized access attempt!"); - $(modalPopupContent).html($('#error-msg').html()); - showPopup(); - } else { - errorCallback(jqXHR); - } - }); + + publicMethods.delete = function (requestURL, successCallback, errorCallback) { + var requestPayload = null; + privateMethods.execute("DELETE", requestURL, requestPayload, successCallback, errorCallback); }; - return module; + + return publicMethods; }(); From 31b62e633654be43f0f3d003520387e8fd2ed2a1 Mon Sep 17 00:00:00 2001 From: dilanua Date: Thu, 21 Jul 2016 12:54:39 +0530 Subject: [PATCH 03/24] Adding jaggery.conf url mapping for data-tables-invoker-api --- .../jaggeryapps/devicemgt/api/data-tables-invoker-api.jag | 2 +- .../src/main/resources/jaggeryapps/devicemgt/jaggery.conf | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) 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 160a7ff517..88babb54f0 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/devicemgt-props.js').config(); +var devicemgtProps = require("/app/conf/devicemgt-props.js").config(); var serviceInvokers = require("/app/modules/backend-service-invoker.js")["backendServiceInvoker"]; if (uriMatcher.match("/{context}/api/data-tables/invoker")) { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/jaggery.conf b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/jaggery.conf index 28ddcefb6c..909af4c456 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/jaggery.conf +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/jaggery.conf @@ -1,6 +1,6 @@ { "displayName": "Carbon Device Management App", - "logLevel": "warn", + "logLevel": "info", "initScripts": ["/app/modules/init.js"], "urlMappings": [ { @@ -50,6 +50,10 @@ { "url": "/*", "path": "/lib/pages.jag" + }, + { + "url": "/api/data-tables/invoker", + "path": "/api/data-tables-invoker-api.jag" } ] } \ No newline at end of file From c8b37207fcfd9fa3ea93904534b93c733ef78571 Mon Sep 17 00:00:00 2001 From: Ace Date: Thu, 21 Jul 2016 15:03:17 +0530 Subject: [PATCH 04/24] Fixing context issue in service-invoker --- .../public/js/invoker-lib.js | 3 +-- .../service-invoker-utility.hbs | 14 +++++++++----- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.lib.service-invoker-utility/public/js/invoker-lib.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.lib.service-invoker-utility/public/js/invoker-lib.js index 30f2be1c64..a63dcbd5b0 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.lib.service-invoker-utility/public/js/invoker-lib.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.lib.service-invoker-utility/public/js/invoker-lib.js @@ -26,10 +26,9 @@ var invokerUtil = function () { restAPIRequestDetails["requestMethod"] = requestMethod; restAPIRequestDetails["requestURL"] = requestURL; restAPIRequestDetails["requestPayload"] = JSON.stringify(requestPayload); - var appContext = devicemgtProps["appContext"]; var request = { - url: appContext + "api/invoker/execute/", + url: context + "/api/invoker/execute/", type: "POST", contentType: "application/json", data: JSON.stringify(restAPIRequestDetails), diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.lib.service-invoker-utility/service-invoker-utility.hbs b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.lib.service-invoker-utility/service-invoker-utility.hbs index 1659537657..af0fa53631 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.lib.service-invoker-utility/service-invoker-utility.hbs +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.lib.service-invoker-utility/service-invoker-utility.hbs @@ -15,10 +15,7 @@ specific language governing permissions and limitations under the License. }} -{{#zone "bottomJs"}} - {{js "js/js.cookie.js"}} - {{js "js/invoker-lib.js"}} - +{{#zone "content"}}
@@ -34,4 +31,11 @@
-{{/zone}} \ No newline at end of file +{{/zone}} +{{#zone "bottomJs"}} + + {{js "js/js.cookie.js"}} + {{js "js/invoker-lib.js"}} +{{/zone}} From 177b7cf3dfc81ad063477ae228f852943caddfaa Mon Sep 17 00:00:00 2001 From: dilanua Date: Thu, 21 Jul 2016 17:58:59 +0530 Subject: [PATCH 05/24] Refactoring data-tables-extended-unit --- .../data-tables-extended.hbs | 3 +- .../dataTables.extended.serversidepaging.js | 281 ++++++++++++++++++ 2 files changed, 283 insertions(+), 1 deletion(-) create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.data-tables-extended/public/js/dataTables.extended.serversidepaging.js diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.data-tables-extended/data-tables-extended.hbs b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.data-tables-extended/data-tables-extended.hbs index ebe533ca13..0bb33aa8cb 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.data-tables-extended/data-tables-extended.hbs +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.data-tables-extended/data-tables-extended.hbs @@ -19,9 +19,10 @@ {{~css "css/dataTables.bootstrap.css"}} {{~css "css/dataTables.responsive.css"}} {{/zone}} -{{~#zone "bottomJs"}} +{{#zone "bottomJs"}} {{~js "js/jquery.dataTables.min.js"}} {{~js "js/dataTables.bootstrap.js"}} {{~js "js/dataTables.responsive.min.js"}} {{~js "js/dataTables.extended.js"}} + {{~js "js/dataTables.extended.serversidepaging.js"}} {{/zone}} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.data-tables-extended/public/js/dataTables.extended.serversidepaging.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.data-tables-extended/public/js/dataTables.extended.serversidepaging.js new file mode 100644 index 0000000000..1ac4db312d --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.data-tables-extended/public/js/dataTables.extended.serversidepaging.js @@ -0,0 +1,281 @@ +/* + * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/* + * ========================================================= + * data-tables extended function (Server-side Pagination) + * ========================================================= + */ + +/** + * @namespace $ + * The $ is just a function. + * It is actually an alias for the function called jQuery. + * For ex: $(this) means jQuery(this) and S.fn.x means jQuery.fn.x + */ + + $.fn.datatables_extended_serverside_paging = function (settings , url, dataFilter, + columns, fnCreatedRow, fnDrawCallback) { + var elem = $(this); + + // EMM related function + if (initiateViewOption) { + $(".viewEnabledIcon").bind("click", initiateViewOption); + } + //--- End of EMM related codes + + $(elem).DataTable( + $.extend({},{ + serverSide: true, + bSortCellsTop: true, + ajax : { + url: "/emm/api/data-tables/invoker", + data : function (params) { + var filter = ""; + var i; + for (i = 0; i < params.columns.length; i++) { + // console.log(i); + filter += "&" + params.columns[i].data + "=" + params.columns[i].search.value; + } + // console.log(filter); + params.offset = params.start; + params.limit = params.length; + params.filter = filter; + params.url = url; + }, + dataFilter: dataFilter + }, + columns: columns, + responsive: false, + autoWidth: false, + dom:'<"dataTablesTop"' + + 'f' + + '<"dataTables_toolbar">' + + '>' + + 'rt' + + '<"dataTablesBottom"' + + 'lip' + + '>', + language: { + searchPlaceholder: 'Search by Role name', + search: '' + }, + fnCreatedRow: fnCreatedRow, + "fnDrawCallback": fnDrawCallback, + initComplete: function () { + this.api().columns().every(function () { + + var column = this; + var filterColumn = $('.filter-row th', elem); + + /** + * Create & add select/text filters to each column + */ + if (filterColumn.eq(column.index()).hasClass('select-filter')) { + var select = $('') + .appendTo(filterColumn.eq(column.index()).empty()) + .on('change', function () { + var val = $.fn.dataTable.util.escapeRegex( + $(this).val() + ); + + column + //.search(val ? '^' + val + '$' : '', true, false) + .search(val ? val : '', true, false) + .draw(); + + if (filterColumn.eq(column.index()).hasClass('data-platform')) { + if (val == null || val == undefined || val == "") { + $("#operation-bar").hide(); + $("#operation-guide").show(); + } else { + $("#operation-guide").hide(); + $("#operation-bar").show(); + loadOperationBar(val); + } + } + }); + + $(column).each(function () { + if ($(column.nodes()).attr('data-search')) { + var titles = []; + column.nodes().unique().sort().each(function (d, j) { + var title = $(d).attr('data-display'); + if ($.inArray(title, titles) < 0) { + titles.push(title); + if (title !== undefined) { + select.append('') + } + } + }); + } else { + column.data().unique().sort().each(function (d, j) { + select.append('') + }); + } + }); + } else if (filterColumn.eq(column.index()).hasClass('text-filter')) { + var title = filterColumn.eq(column.index()).attr('data-for'); + $(filterColumn.eq(column.index()).empty()).html(''); + + filterColumn.eq(column.index()).find('input').on('keyup change', function () { + column.search($(this).val()).draw(); + if ($('.dataTables_empty').length > 0) { + $('.bulk-action-row').addClass("hidden"); + } else { + $('.bulk-action-row').removeClass("hidden"); + } + }); + } + + }); + + /** + * search input default styles override + */ + var search_input = $(this).closest('.dataTables_wrapper').find('div[id$=_filter] input'); + search_input.before('').removeClass('input-sm'); + + /** + * create sorting dropdown menu for list table advance operations + */ + var dropdownmenu = $(''); + $('.sort-row th', elem).each(function () { + if (!$(this).hasClass('no-sort')) { + dropdownmenu.append('
  • ' + $(this).html() + '
  • '); + } + }); + + /** + * append advance operations to list table toolbar + */ + $('.dataTable.list-table').closest('.dataTables_wrapper').find('.dataTablesTop .dataTables_toolbar').html('' + + '' + ); + + /** + * sorting dropdown menu select function + */ + $('.dataTables_wrapper .sort-list li a').click(function () { + $(this).closest('li').siblings('li').find('a').removeClass('sorting_asc').removeClass('sorting_desc'); + + var thisTable = $(this).closest('.dataTables_wrapper').find('.dataTable').dataTable(); + + if (!($(this).hasClass('sorting_asc')) && !($(this).hasClass('sorting_desc'))) { + $(this).addClass('sorting_asc'); + thisTable.fnSort([[$(this).attr('data-column'), 'asc']]); + } + else if ($(this).hasClass('sorting_asc')) { + $(this).switchClass('sorting_asc', 'sorting_desc'); + thisTable.fnSort([[$(this).attr('data-column'), 'desc']]); + } + else if ($(this).hasClass('sorting_desc')) { + $(this).switchClass('sorting_desc', 'sorting_asc'); + thisTable.fnSort([[$(this).attr('data-column'), 'asc']]); + } + }); + + var rowSelectedClass = 'DTTT_selected selected'; + + /** + * Enable/Disable selection on rows + */ + $('.dataTables_wrapper [data-click-event=toggle-selectable]').click(function () { + var button = this, + thisTable = $(this).closest('.dataTables_wrapper').find('.dataTable').dataTable(); + if ($(button).html() == 'Select') { + thisTable.addClass("table-selectable"); + $(button).addClass("active").html('Cancel'); + $(button).parent().next().children("button").removeClass("disabled"); + // EMM related code + $(".viewEnabledIcon").unbind("click"); + //--- End of EMM related codes + } else if ($(button).html() == 'Cancel') { + thisTable.removeClass("table-selectable"); + $(button).addClass("active").html('Select'); + $(button).parent().next().children().addClass("disabled"); + // EMM related function + $(".viewEnabledIcon").bind("click", initiateViewOption); + //--- End of EMM related codes + } + }); + /** + * select/deselect all rows function + */ + $('.dataTables_wrapper [data-click-event=toggle-selected]').click(function () { + var button = this, + thisTable = $(this).closest('.dataTables_wrapper').find('.dataTable').dataTable(); + if (!$(button).hasClass('disabled')) { + if ($(button).html() == 'Select All') { + thisTable.api().rows().every(function () { + $(this.node()).addClass(rowSelectedClass); + $(button).html('Deselect All'); + }); + } + else if ($(button).html() == 'Deselect All') { + thisTable.api().rows().every(function () { + $(this.node()).removeClass(rowSelectedClass); + $(button).html('Select All'); + }); + } + } + }); + + /** + * on row click select/deselect row function + */ + $('body').on('click', '[data-type=selectable]', function () { + var rowSelectedClass = 'DTTT_selected selected'; + $(this).toggleClass(rowSelectedClass); + var button = this, + thisTable = $(this).closest('.dataTables_wrapper').find('.dataTable').dataTable(); + + thisTable.api().rows().every(function () { + if (!$(this.node()).hasClass(rowSelectedClass)) { + $(button).closest('.dataTables_wrapper').find('[data-click-event=toggle-selected]').html('Select All'); + } + }); + }); + + /** + * list table list/grid view toggle function + */ + var toggleButton = $('[data-click-event=toggle-list-view]'); + toggleButton.click(function () { + if ($(this).attr('data-view') == 'grid') { + $(this).closest('.dataTables_wrapper').find('.dataTable').addClass('grid-view'); + //$(this).closest('li').hide(); + //$(this).closest('li').siblings().show(); + } + else { + $(this).closest('.dataTables_wrapper').find('.dataTable').removeClass('grid-view'); + //$(this).closest('li').hide(); + //$(this).closest('li').siblings().show(); + } + }) + } + },settings) + ); + +}; From da6ff6e7fa0c2f8f9cf2372083f0c4aaaee18991 Mon Sep 17 00:00:00 2001 From: dilanua Date: Thu, 21 Jul 2016 18:04:51 +0530 Subject: [PATCH 06/24] Refactoring user-listing page --- .../cdmf.page.users/public/js/listing.js | 274 ++++++++++-------- .../public/templates/listing.hbs | 5 + .../app/pages/cdmf.page.users/users.hbs | 7 +- .../app/pages/cdmf.page.users/users.js | 7 +- 4 files changed, 171 insertions(+), 122 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.users/public/js/listing.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.users/public/js/listing.js index 6c29b73a40..2ef13959c3 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.users/public/js/listing.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.users/public/js/listing.js @@ -1,21 +1,23 @@ /* - * 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. */ +var deviceMgtAPIsBasePath = "/api/device-mgt/v1.0"; + /** * Checks if provided input is valid against RegEx input. * @@ -35,10 +37,10 @@ function inputIsValid(regExp, inputString) { $(function () { var sortableElem = '.wr-sortable'; $(sortableElem).sortable({ - beforeStop: function () { - var sortedIDs = $(this).sortable('toArray'); - } - }); + beforeStop: function () { + $(this).sortable('toArray'); + } + }); $(sortableElem).disableSelection(); }); @@ -46,11 +48,9 @@ var modalPopup = ".wr-modalpopup"; var modalPopupContainer = modalPopup + " .modalpopup-container"; var modalPopupContent = modalPopup + " .modalpopup-content"; var body = "body"; -var isInit = true; +//var isInit = true; $(".icon .text").res_text(0.2); -var resetPasswordServiceURL = "/devicemgt_admin/users/reset-password"; - /* * set popup maximum height function. */ @@ -80,11 +80,9 @@ function hidePopup() { */ function getSelectedUsernames() { var usernameList = []; - var userList = $("#user-grid").find('> tbody > tr'); + var userList = $("#user-grid").find('tr.DTTT_selected'); userList.each(function () { - if ($(this).hasClass('DTTT_selected')) { - usernameList.push($(this).attr('data-username')); - } + usernameList.push($(this).data('username')); }); return usernameList; } @@ -96,7 +94,7 @@ function getSelectedUsernames() { */ $("a.invite-user-link").click(function () { var usernameList = getSelectedUsernames(); - var inviteUserAPI = "/devicemgt_admin/users/email-invitation"; + var inviteUserAPI = deviceMgtAPIsBasePath + "/users/send-invitation"; if (usernameList.length == 0) { $(modalPopupContent).html($("#errorUsers").html()); @@ -108,20 +106,25 @@ $("a.invite-user-link").click(function () { $("a#invite-user-yes-link").click(function () { invokerUtil.post( - inviteUserAPI, - usernameList, - function () { + inviteUserAPI, + usernameList, + // The success callback + function (data, textStatus, jqXHR) { + if (jqXHR.status == 200) { $(modalPopupContent).html($('#invite-user-success-content').html()); $("a#invite-user-success-link").click(function () { hidePopup(); }); - }, - function () { - $(modalPopupContent).html($('#invite-user-error-content').html()); - $("a#invite-user-error-link").click(function () { - hidePopup(); - }); } + }, + // The error callback + function (jqXHR) { + console.log("error in invite-user API, status code: " + jqXHR.status); + $(modalPopupContent).html($('#invite-user-error-content').html()); + $("a#invite-user-error-link").click(function () { + hidePopup(); + }); + } ); }); @@ -137,16 +140,17 @@ $("a.invite-user-link").click(function () { */ function removeUser(uname, uid) { var username = uname; - var userid = uid; - var removeUserAPI = "/devicemgt_admin/users?username=" + username; + var userId = uid; + var removeUserAPI = deviceMgtAPIsBasePath + "/users/" + username; $(modalPopupContent).html($('#remove-user-modal-content').html()); showPopup(); $("a#remove-user-yes-link").click(function () { invokerUtil.delete( - removeUserAPI, - function () { - $("#" + userid).remove(); + removeUserAPI, + function (data, textStatus, jqXHR) { + if (jqXHR.status == 200) { + $("#" + userId).remove(); // get new user-list-count var newUserListCount = $(".user-list > span").length; // update user-listing-status-msg with new user-count @@ -156,13 +160,16 @@ function removeUser(uname, uid) { $("a#remove-user-success-link").click(function () { hidePopup(); }); - }, - function () { - $(modalPopupContent).html($('#remove-user-error-content').html()); - $("a#remove-user-error-link").click(function () { - hidePopup(); - }); } + }, + // The error callback + function (jqXHR) { + console.log("error in remove-user API, status code: " + jqXHR.status); + $(modalPopupContent).html($('#remove-user-error-content').html()); + $("a#remove-user-error-link").click(function () { + hidePopup(); + }); + } ); }); @@ -202,29 +209,30 @@ function resetPassword(uname) { $(errorMsgWrapper).removeClass("hidden"); } else { var resetPasswordFormData = {}; - resetPasswordFormData.username = user; - resetPasswordFormData.newPassword = window.btoa(unescape(encodeURIComponent(confirmedPassword))); + //resetPasswordFormData.username = user; + resetPasswordFormData.newPassword = unescape(confirmedPassword); + + var resetPasswordServiceURL = deviceMgtAPIsBasePath + "/admin/users/"+ user +"/credentials"; invokerUtil.post( - resetPasswordServiceURL, - resetPasswordFormData, - function (data) { // The success callback - data = JSON.parse(data); - if (data.statusCode == 201) { - $(modalPopupContent).html($('#reset-password-success-content').html()); - $("a#reset-password-success-link").click(function () { - hidePopup(); - }); - } - }, function (data) { // The error callback - if (data.statusCode == 400) { - $(errorMsg).text("Old password does not match with the provided value."); - $(errorMsgWrapper).removeClass("hidden"); - } else { - $(errorMsg).text("An unexpected error occurred. Please try again later."); - $(errorMsgWrapper).removeClass("hidden"); - } + resetPasswordServiceURL, + resetPasswordFormData, + // The success callback + function (data, textStatus, jqXHR) { + if (jqXHR.status == 200) { + $(modalPopupContent).html($('#reset-password-success-content').html()); + $("a#reset-password-success-link").click(function () { + hidePopup(); + }); } + }, + // The error callback + function (jqXHR) { + console.log("error in reset-password API, status code: " + jqXHR.status); + var payload = JSON.parse(jqXHR.responseText); + $(errorMsg).text(payload.message); + $(errorMsgWrapper).removeClass("hidden"); + } ); } }); @@ -250,7 +258,7 @@ $("#search-btn").click(function () { * when a user clicks on the list item * initial mode and with out select mode. */ -function InitiateViewOption() { +function initiateViewOption() { if ($("#can-view").val()) { $(location).attr('href', $(this).data("url")); } else { @@ -259,74 +267,112 @@ function InitiateViewOption() { } } -function loadUsers(searchParam) { - $("#loading-content").show(); - var userListing = $("#user-listing"); - var userListingSrc = userListing.attr("src"); - $.template("user-listing", userListingSrc, function (template) { - var serviceURL = "/devicemgt_admin/users"; - if (searchParam) { - serviceURL = serviceURL + "/view-users?username=" + searchParam; - } - var successCallback = function (data) { - if (!data) { - $('#ast-container').addClass('hidden'); - $('#user-listing-status-msg').text('No users are available to be displayed.'); - return; +function loadUsers() { + var loadingContentIcon = "#loading-content"; + $(loadingContentIcon).show(); + + var dataFilter = function (data) { + data = JSON.parse(data); + + var objects = []; + + $(data.users).each(function (index) { + objects.push({ + username: data.users[index].username, + firstname: data.users[index].firstname ? data.users[index].firstname: '' , + lastname: data.users[index].lastname ? data.users[index].lastname : '', + emailAddress : data.users[index].emailAddress ? data.users[index].emailAddress: '', + DT_RowId : "role-" + data.users[index].username}) + }); + + var json = { + "recordsTotal": data.count, + "recordsFiltered": data.count, + "data": objects + }; + + return JSON.stringify(json); + }; + + var fnCreatedRow = function(nRow, aData, iDataIndex) { + console.log(JSON.stringify(aData)); + $(nRow).attr('data-type', 'selectable'); + $(nRow).attr('data-username', aData["username"]); + }; + + var columns = [ + { + class: "remove-padding icon-only content-fill", + data: null, + defaultContent: + '
    ' + + '' + + '
    ' + }, + { + class: "fade-edge", + data: null, + render: function (data, type, row, meta) { + return '

    ' + data.firstname + ' ' + data.lastname + '

    '; } - var canRemove = $("#can-remove").val(); - var canEdit = $("#can-edit").val(); - var canResetPassword = $("#can-reset-password").val(); - data = JSON.parse(data); - data = data.responseContent; - var viewModel = {}; - viewModel.users = data; - for (var i = 0; i < viewModel.users.length; i++) { - viewModel.users[i].userid = viewModel.users[i].username.replace(/[^\w\s]/gi, ''); - if (canRemove) { - viewModel.users[i].canRemove = true; - } - if (canEdit) { - viewModel.users[i].canEdit = true; - } - if (canResetPassword) { - viewModel.users[i].canResetPassword = true; - } - viewModel.users[i].adminUser = $("#user-table").data("user"); + }, + { + class: "fade-edge remove-padding-top", + data: null, + render: function (data, type, row, meta) { + return ' ' + data.username; } - if (data.length > 0) { - $('#ast-container').removeClass('hidden'); - $('#user-listing-status-msg').text(""); - var content = template(viewModel); - $("#ast-container").html(content); - } else { - $('#ast-container').addClass('hidden'); - $('#user-listing-status-msg').text('No users are available to be displayed.'); + }, + { + class: "fade-edge remove-padding-top", + data: null, + render: function (data, type, row, meta) { + return ' ' + + data.emailAddress + ' '; } - $("#loading-content").hide(); - if (isInit) { - $('#user-grid').datatables_extended(); - isInit = false; + }, + { + class: "text-right content-fill text-left-on-grid-view no-wrap", + data: null, + render: function (data, type, row, meta) { + return ' ' + + '' + + '' + + ' ' + + + '' + + ' ' + + ' ' + + + ' ' + + '' + + ' ' + + '<' + + '/i> ' + + ' ' } - $(".icon .text").res_text(0.2); - }; - invokerUtil.get(serviceURL, - successCallback, - function (message) { - $('#ast-container').addClass('hidden'); - $('#user-listing-status-msg').text('Invalid search query. Try again with a valid search query'); - } - ); - }); + } + + ]; + + $('#user-grid').datatables_extended_serverside_paging(null, '/api/device-mgt/v1.0/users', dataFilter, columns, fnCreatedRow, null); + + $("#loading-content").hide(); } $(document).ready(function () { loadUsers(); $(".viewEnabledIcon").click(function () { - InitiateViewOption(); + initiateViewOption(); }); + if (!$("#can-invite").val()) { $("#invite-user-button").remove(); } -}); \ No newline at end of file +}); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.users/public/templates/listing.hbs b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.users/public/templates/listing.hbs index 6414e6de93..db67d76973 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.users/public/templates/listing.hbs +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.users/public/templates/listing.hbs @@ -52,6 +52,11 @@ + + + + + diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.users/users.hbs b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.users/users.hbs index 493f395a70..d54c3a1d55 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.users/users.hbs +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.users/users.hbs @@ -298,15 +298,13 @@ Enter new password

    - +

    Retype new password

    - +

    @@ -338,6 +336,7 @@ + {{/zone}} {{#zone "common-navigation"}} 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 74f3d583fc..d0085bd39d 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 @@ -26,13 +26,13 @@ function onRequest(context) { return options.fn(this); } }); + var page = {}; var userModule = require("/app/modules/user.js")["userModule"]; var deviceMgtProps = require("/app/conf/devicemgt-props.js").config(); + + page["adminUser"] = deviceMgtProps["adminUser"]; page["permissions"] = userModule.getUIPermissions(); - if (userModule.isAuthorized("/permission/admin/device-mgt/users/delete")) { - page["removePermitted"] = true; - } if (userModule.isAuthorized("/permission/admin/device-mgt/users/remove")) { page["removePermitted"] = true; @@ -51,6 +51,5 @@ function onRequest(context) { page["resetPasswordPermitted"] = true; } - page["adminUser"] = deviceMgtProps.adminUser; return page; } \ No newline at end of file From d79de070f17a3aaee91819a973a86629859b9b25 Mon Sep 17 00:00:00 2001 From: madhawap Date: Fri, 22 Jul 2016 10:58:50 +0530 Subject: [PATCH 07/24] fix to iOS device enrolment --- .../framework/authenticator/CertificateAuthenticator.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/authenticator/CertificateAuthenticator.java b/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/authenticator/CertificateAuthenticator.java index 067405622d..a402f18e7c 100644 --- a/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/authenticator/CertificateAuthenticator.java +++ b/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/authenticator/CertificateAuthenticator.java @@ -29,7 +29,7 @@ public class CertificateAuthenticator implements WebappAuthenticator { private static final String CERTIFICATE_AUTHENTICATOR = "CertificateAuth"; private static final String MUTUAL_AUTH_HEADER = "mutual-auth-header"; private static final String PROXY_MUTUAL_AUTH_HEADER = "proxy-mutual-auth-header"; - private static final String CERTIFICATE_VERIFICATION_HEADER = "certificate-verification-header"; + private static final String CERTIFICATE_VERIFICATION_HEADER = "Mdm-Signature"; private static final String CLIENT_CERTIFICATE_ATTRIBUTE = "javax.servlet.request.X509Certificate"; @Override @@ -55,7 +55,6 @@ public class CertificateAuthenticator implements WebappAuthenticator { authenticationInfo.setStatus(Status.CONTINUE); } - String certVerificationHeader = request.getContext().findParameter(CERTIFICATE_VERIFICATION_HEADER); try { // When there is a load balancer terminating mutual SSL, it should pass this header along and // as the value of this header, the client certificate subject dn should be passed. @@ -78,7 +77,7 @@ public class CertificateAuthenticator implements WebappAuthenticator { } } else if (request.getHeader(CERTIFICATE_VERIFICATION_HEADER) != null) { - String certHeader = request.getHeader(certVerificationHeader); + String certHeader = request.getHeader(CERTIFICATE_VERIFICATION_HEADER); if (certHeader != null && AuthenticatorFrameworkDataHolder.getInstance().getCertificateManagementService(). verifySignature(certHeader)) { From 74658d1e8519d9bf7837fd1f606b0be14d4f42a2 Mon Sep 17 00:00:00 2001 From: hasuniea Date: Fri, 22 Jul 2016 11:42:55 +0530 Subject: [PATCH 08/24] adding certificate scripts --- .../src/main/resources/dbscripts/cdm/certs/h2.sql | 8 ++++++++ .../src/main/resources/dbscripts/cdm/certs/mssql.sql | 8 ++++++++ .../src/main/resources/dbscripts/cdm/certs/mysql.sql | 8 ++++++++ .../src/main/resources/dbscripts/cdm/certs/oracle.sql | 8 ++++++++ .../main/resources/dbscripts/cdm/certs/postgresql.sql | 7 +++++++ .../src/main/resources/p2.inf | 3 ++- .../src/main/resources/dbscripts/cdm/h2.sql | 9 --------- .../src/main/resources/dbscripts/cdm/mssql.sql | 9 --------- .../src/main/resources/dbscripts/cdm/mysql.sql | 9 --------- .../src/main/resources/dbscripts/cdm/oracle.sql | 10 ---------- .../src/main/resources/dbscripts/cdm/postgresql.sql | 8 -------- 11 files changed, 41 insertions(+), 46 deletions(-) create mode 100644 features/certificate-mgt/org.wso2.carbon.certificate.mgt.server.feature/src/main/resources/dbscripts/cdm/certs/h2.sql create mode 100644 features/certificate-mgt/org.wso2.carbon.certificate.mgt.server.feature/src/main/resources/dbscripts/cdm/certs/mssql.sql create mode 100644 features/certificate-mgt/org.wso2.carbon.certificate.mgt.server.feature/src/main/resources/dbscripts/cdm/certs/mysql.sql create mode 100644 features/certificate-mgt/org.wso2.carbon.certificate.mgt.server.feature/src/main/resources/dbscripts/cdm/certs/oracle.sql create mode 100644 features/certificate-mgt/org.wso2.carbon.certificate.mgt.server.feature/src/main/resources/dbscripts/cdm/certs/postgresql.sql diff --git a/features/certificate-mgt/org.wso2.carbon.certificate.mgt.server.feature/src/main/resources/dbscripts/cdm/certs/h2.sql b/features/certificate-mgt/org.wso2.carbon.certificate.mgt.server.feature/src/main/resources/dbscripts/cdm/certs/h2.sql new file mode 100644 index 0000000000..6705b595f0 --- /dev/null +++ b/features/certificate-mgt/org.wso2.carbon.certificate.mgt.server.feature/src/main/resources/dbscripts/cdm/certs/h2.sql @@ -0,0 +1,8 @@ +CREATE TABLE IF NOT EXISTS DM_DEVICE_CERTIFICATE ( + ID INTEGER auto_increment NOT NULL, + SERIAL_NUMBER VARCHAR(500) DEFAULT NULL, + CERTIFICATE BLOB DEFAULT NULL, + TENANT_ID INTEGER DEFAULT 0, + USERNAME VARCHAR(500) DEFAULT NULL, + PRIMARY KEY (ID) +); \ No newline at end of file diff --git a/features/certificate-mgt/org.wso2.carbon.certificate.mgt.server.feature/src/main/resources/dbscripts/cdm/certs/mssql.sql b/features/certificate-mgt/org.wso2.carbon.certificate.mgt.server.feature/src/main/resources/dbscripts/cdm/certs/mssql.sql new file mode 100644 index 0000000000..888ee030c8 --- /dev/null +++ b/features/certificate-mgt/org.wso2.carbon.certificate.mgt.server.feature/src/main/resources/dbscripts/cdm/certs/mssql.sql @@ -0,0 +1,8 @@ +CREATE TABLE DM_DEVICE_CERTIFICATE ( + ID INTEGER IDENTITY NOT NULL, + SERIAL_NUMBER VARCHAR(500) DEFAULT NULL, + CERTIFICATE VARBINARY(max) DEFAULT NULL, + TENANT_ID INTEGER DEFAULT 0, + USERNAME VARCHAR(500) DEFAULT NULL, + PRIMARY KEY (ID) +); diff --git a/features/certificate-mgt/org.wso2.carbon.certificate.mgt.server.feature/src/main/resources/dbscripts/cdm/certs/mysql.sql b/features/certificate-mgt/org.wso2.carbon.certificate.mgt.server.feature/src/main/resources/dbscripts/cdm/certs/mysql.sql new file mode 100644 index 0000000000..3bdf0a5a17 --- /dev/null +++ b/features/certificate-mgt/org.wso2.carbon.certificate.mgt.server.feature/src/main/resources/dbscripts/cdm/certs/mysql.sql @@ -0,0 +1,8 @@ +CREATE TABLE IF NOT EXISTS DM_DEVICE_CERTIFICATE ( + ID INTEGER auto_increment NOT NULL, + SERIAL_NUMBER VARCHAR(500) DEFAULT NULL, + CERTIFICATE BLOB DEFAULT NULL, + TENANT_ID INTEGER DEFAULT 0, + USERNAME VARCHAR(500) DEFAULT NULL, + PRIMARY KEY (ID) +)ENGINE = InnoDB; \ No newline at end of file diff --git a/features/certificate-mgt/org.wso2.carbon.certificate.mgt.server.feature/src/main/resources/dbscripts/cdm/certs/oracle.sql b/features/certificate-mgt/org.wso2.carbon.certificate.mgt.server.feature/src/main/resources/dbscripts/cdm/certs/oracle.sql new file mode 100644 index 0000000000..75732199f6 --- /dev/null +++ b/features/certificate-mgt/org.wso2.carbon.certificate.mgt.server.feature/src/main/resources/dbscripts/cdm/certs/oracle.sql @@ -0,0 +1,8 @@ +CREATE TABLE DM_DEVICE_CERTIFICATE ( + ID NUMBER(10) NOT NULL, + SERIAL_NUMBER VARCHAR2(500) DEFAULT NULL, + CERTIFICATE BLOB DEFAULT NULL, + TENANT_ID NUMBER(10) DEFAULT 0, + USERNAME VARCHAR2(500) DEFAULT NULL, + PRIMARY KEY (ID) +) \ No newline at end of file diff --git a/features/certificate-mgt/org.wso2.carbon.certificate.mgt.server.feature/src/main/resources/dbscripts/cdm/certs/postgresql.sql b/features/certificate-mgt/org.wso2.carbon.certificate.mgt.server.feature/src/main/resources/dbscripts/cdm/certs/postgresql.sql new file mode 100644 index 0000000000..c23791abf0 --- /dev/null +++ b/features/certificate-mgt/org.wso2.carbon.certificate.mgt.server.feature/src/main/resources/dbscripts/cdm/certs/postgresql.sql @@ -0,0 +1,7 @@ +CREATE TABLE IF NOT EXISTS DM_DEVICE_CERTIFICATE ( + ID BIGSERIAL NOT NULL PRIMARY KEY, + SERIAL_NUMBER VARCHAR(500) DEFAULT NULL, + CERTIFICATE BYTEA DEFAULT NULL, + TENANT_ID INTEGER DEFAULT 0, + USERNAME VARCHAR(500) DEFAULT NULL +); \ No newline at end of file diff --git a/features/certificate-mgt/org.wso2.carbon.certificate.mgt.server.feature/src/main/resources/p2.inf b/features/certificate-mgt/org.wso2.carbon.certificate.mgt.server.feature/src/main/resources/p2.inf index 7bae1dd04a..44e5960b63 100644 --- a/features/certificate-mgt/org.wso2.carbon.certificate.mgt.server.feature/src/main/resources/p2.inf +++ b/features/certificate-mgt/org.wso2.carbon.certificate.mgt.server.feature/src/main/resources/p2.inf @@ -1,3 +1,4 @@ instructions.configure = \ org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.certificate.mgt.server_${feature.version}/conf/wso2certs.jks,target:${installFolder}/../../resources/security/wso2certs.jks,overwrite:true);\ -org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.certificate.mgt.server_${feature.version}/conf/certificate-config.xml,target:${installFolder}/../../conf/certificate-config.xml,overwrite:true);\ \ No newline at end of file +org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.certificate.mgt.server_${feature.version}/conf/certificate-config.xml,target:${installFolder}/../../conf/certificate-config.xml,overwrite:true);\ +org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.certificate.mgt.server_${feature.version}/dbscripts/cdm/,target:${installFolder}/../../../dbscripts/cdm,overwrite:true);\ \ No newline at end of file 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 3e40d109bd..e9894b7997 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 @@ -17,15 +17,6 @@ CREATE TABLE IF NOT EXISTS DM_GROUP ( PRIMARY KEY (ID) ); -CREATE TABLE IF NOT EXISTS DM_DEVICE_CERTIFICATE ( - ID INTEGER auto_increment NOT NULL, - SERIAL_NUMBER VARCHAR(500) DEFAULT NULL, - CERTIFICATE BLOB DEFAULT NULL, - TENANT_ID INTEGER DEFAULT 0, - USERNAME VARCHAR(500) DEFAULT NULL, - PRIMARY KEY (ID) -); - CREATE TABLE IF NOT EXISTS DM_DEVICE ( ID INTEGER auto_increment NOT NULL, DESCRIPTION TEXT DEFAULT NULL, 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 a67d67f9e0..66ce12dc87 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 @@ -17,15 +17,6 @@ CREATE TABLE DM_GROUP ( PRIMARY KEY (ID) ); -CREATE TABLE DM_DEVICE_CERTIFICATE ( - ID INTEGER IDENTITY NOT NULL, - SERIAL_NUMBER VARCHAR(500) DEFAULT NULL, - CERTIFICATE VARBINARY(max) DEFAULT NULL, - TENANT_ID INTEGER DEFAULT 0, - USERNAME VARCHAR(500) DEFAULT NULL, - PRIMARY KEY (ID) -); - CREATE TABLE DM_DEVICE ( ID INTEGER identity NOT NULL, DESCRIPTION VARCHAR(max) DEFAULT NULL, 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 40535450ac..1d2013cbc4 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 @@ -6,15 +6,6 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_TYPE ( PRIMARY KEY (ID) )ENGINE = InnoDB; -CREATE TABLE IF NOT EXISTS DM_DEVICE_CERTIFICATE ( - ID INTEGER auto_increment NOT NULL, - SERIAL_NUMBER VARCHAR(500) DEFAULT NULL, - CERTIFICATE BLOB DEFAULT NULL, - TENANT_ID INTEGER DEFAULT 0, - USERNAME VARCHAR(500) DEFAULT NULL, - PRIMARY KEY (ID) -)ENGINE = InnoDB; - CREATE TABLE IF NOT EXISTS DM_DEVICE ( ID INTEGER AUTO_INCREMENT NOT NULL, DESCRIPTION TEXT DEFAULT NULL, 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 41f539cee0..18ed9c2abe 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 @@ -44,16 +44,6 @@ WHEN (NEW.ID IS NULL) SELECT DM_GROUP_seq.NEXTVAL INTO :NEW.ID FROM DUAL; END; / - -CREATE TABLE DM_DEVICE_CERTIFICATE ( - ID NUMBER(10) NOT NULL, - SERIAL_NUMBER VARCHAR2(500) DEFAULT NULL, - CERTIFICATE BLOB DEFAULT NULL, - TENANT_ID NUMBER(10) DEFAULT 0, - USERNAME VARCHAR2(500) DEFAULT NULL, - PRIMARY KEY (ID) -) -/ -- Generate ID using sequence and trigger CREATE SEQUENCE DM_DEVICE_CERTIFICATE_seq START WITH 1 INCREMENT BY 1 NOCACHE / 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 c29d18e021..2da059d3a7 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 @@ -5,14 +5,6 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_TYPE ( SHARED_WITH_ALL_TENANTS BOOLEAN NOT NULL DEFAULT FALSE ); -CREATE TABLE IF NOT EXISTS DM_DEVICE_CERTIFICATE ( - ID BIGSERIAL NOT NULL PRIMARY KEY, - SERIAL_NUMBER VARCHAR(500) DEFAULT NULL, - CERTIFICATE BYTEA DEFAULT NULL, - TENANT_ID INTEGER DEFAULT 0, - USERNAME VARCHAR(500) DEFAULT NULL -); - CREATE TABLE IF NOT EXISTS DM_DEVICE ( ID BIGSERIAL NOT NULL PRIMARY KEY, DESCRIPTION TEXT DEFAULT NULL, From b636738be30c767471d4ee76c6f9985923164c04 Mon Sep 17 00:00:00 2001 From: dilanua Date: Fri, 22 Jul 2016 11:54:35 +0530 Subject: [PATCH 09/24] Fixing issue: user-list not getting updated upon user-removal --- .../jaggeryapps/devicemgt/app/modules/user.js | 4 ++-- .../pages/cdmf.page.users/public/js/listing.js | 17 ++++++----------- 2 files changed, 8 insertions(+), 13 deletions(-) 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 b0eb98c554..2a1eccdbed 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 @@ -17,14 +17,14 @@ */ /* - * This module contains user and roles related functionality + * This module contains user and roles related functionality. */ var userModule = function () { var log = new Log("/app/modules/user.js"); var constants = require("/app/modules/constants.js"); var utility = require("/app/modules/utility.js")["utility"]; - var devicemgtProps = require('/app/conf/devicemgt-props.js').config(); + var devicemgtProps = require("/app/conf/devicemgt-props.js").config(); var serviceInvokers = require("/app/modules/backend-service-invoker.js").backendServiceInvoker; /* Initializing user manager */ diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.users/public/js/listing.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.users/public/js/listing.js index 2ef13959c3..dfc9d6acd9 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.users/public/js/listing.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.users/public/js/listing.js @@ -138,9 +138,7 @@ $("a.invite-user-link").click(function () { * when a user clicks on "Remove" link * on User Listing page in WSO2 Devicemgt Console. */ -function removeUser(uname, uid) { - var username = uname; - var userId = uid; +function removeUser(username) { var removeUserAPI = deviceMgtAPIsBasePath + "/users/" + username; $(modalPopupContent).html($('#remove-user-modal-content').html()); showPopup(); @@ -148,21 +146,18 @@ function removeUser(uname, uid) { $("a#remove-user-yes-link").click(function () { invokerUtil.delete( removeUserAPI, + // success callback function (data, textStatus, jqXHR) { if (jqXHR.status == 200) { - $("#" + userId).remove(); - // get new user-list-count - var newUserListCount = $(".user-list > span").length; - // update user-listing-status-msg with new user-count - $("#user-listing-status-msg").text("Total number of Users found : " + newUserListCount); // update modal-content with success message $(modalPopupContent).html($('#remove-user-success-content').html()); $("a#remove-user-success-link").click(function () { hidePopup(); + location.reload(); }); } }, - // The error callback + // error callback function (jqXHR) { console.log("error in remove-user API, status code: " + jqXHR.status); $(modalPopupContent).html($('#remove-user-error-content').html()); @@ -282,7 +277,7 @@ function loadUsers() { firstname: data.users[index].firstname ? data.users[index].firstname: '' , lastname: data.users[index].lastname ? data.users[index].lastname : '', emailAddress : data.users[index].emailAddress ? data.users[index].emailAddress: '', - DT_RowId : "role-" + data.users[index].username}) + DT_RowId : "user-" + data.users[index].username}) }); var json = { @@ -360,7 +355,7 @@ function loadUsers() { ]; - $('#user-grid').datatables_extended_serverside_paging(null, '/api/device-mgt/v1.0/users', dataFilter, columns, fnCreatedRow, null); + $("#user-grid").datatables_extended_serverside_paging(null, '/api/device-mgt/v1.0/users', dataFilter, columns, fnCreatedRow, null); $("#loading-content").hide(); } From 24d846a328ba221da1bbec633c8fff464b0d8b84 Mon Sep 17 00:00:00 2001 From: dilanua Date: Fri, 22 Jul 2016 15:25:33 +0530 Subject: [PATCH 10/24] Refactoring user-create page and related modules --- .../jaggeryapps/devicemgt/app/modules/user.js | 502 +++++++++--------- .../pages/cdmf.page.user.create/create.hbs | 16 +- .../app/pages/cdmf.page.user.create/create.js | 24 +- .../pages/cdmf.page.user.create/create.json | 2 +- .../public/js/bottomJs.js | 127 +++-- 5 files changed, 340 insertions(+), 331 deletions(-) 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 2a1eccdbed..0a3d157390 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 @@ -1,17 +1,17 @@ /* - * 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. */ @@ -25,32 +25,30 @@ var userModule = function () { var constants = require("/app/modules/constants.js"); var utility = require("/app/modules/utility.js")["utility"]; var devicemgtProps = require("/app/conf/devicemgt-props.js").config(); - var serviceInvokers = require("/app/modules/backend-service-invoker.js").backendServiceInvoker; + var serviceInvokers = require("/app/modules/backend-service-invoker.js")["backendServiceInvoker"]; /* Initializing user manager */ - var carbon = require('carbon'); - var tenantId = carbon.server.tenantId(); - var url = carbon.server.address('https') + "/admin/services"; + var carbon = require("carbon"); + var url = carbon.server.address("https") + "/admin/services"; var server = new carbon.server.Server(url); - var userManager = new carbon.user.UserManager(server, tenantId); - var deviceManagementService = utility.getDeviceManagementService(); - var EmailMessageProperties = Packages.org.wso2.carbon.device.mgt.common.EmailMessageProperties; + //var deviceManagementService = utility.getDeviceManagementService(); + //var EmailMessageProperties = Packages.org.wso2.carbon.device.mgt.common.EmailMessageProperties; var publicMethods = {}; var privateMethods = {}; /** - * Get the carbon user object from the session. If not found - it will throw a user not found error. - * @returns {carbon user object} + * Get the carbon user object from the session. If not found - it will throw a user not found error. + * @returns {object} carbon user object */ privateMethods.getCarbonUser = function () { - var carbon = require('carbon'); - var carbonUser = session.get(constants.USER_SESSION_KEY); - var utility = require('/app/modules/utility.js').utility; + var carbon = require("carbon"); + var carbonUser = session.get(constants["USER_SESSION_KEY"]); + var utility = require("/modules/utility.js")["utility"]; if (!carbonUser) { log.error("User object was not found in the session"); - throw constants.ERRORS.USER_NOT_FOUND; + throw constants["ERRORS"]["USER_NOT_FOUND"]; } return carbonUser; }; @@ -59,31 +57,25 @@ var userModule = function () { * Only GET method is implemented for now since there are no other type of methods used this method. * @param url - URL to call the backend without the host * @param method - HTTP Method (GET, POST) - * @returns { - * 'status': 'success'|'error', - * 'content': {} - * } + * @returns An object with 'status': 'success'|'error', 'content': {} */ privateMethods.callBackend = function (url, method) { - if (constants.HTTP_GET == method) { - var response = serviceInvokers.XMLHttp.get(url, function (responsePayload) { - var response = {}; - response.content = responsePayload["responseContent"]; - if (responsePayload["responseContent"] == null && responsePayload != null) { - response.content = responsePayload; + if (constants["HTTP_GET"] == method) { + return serviceInvokers.XMLHttp.get(url, + function (backendResponse) { + var response = {}; + response.content = backendResponse.responseText; + if (backendResponse.status == 200) { + response.status = "success"; + } else if (backendResponse.status == 400 || backendResponse.status == 401 || + backendResponse.status == 404 || backendResponse.status == 500) { + response.status = "error"; + } + return response; } - response.status = "success"; - return response; - }, - function (responsePayload) { - var response = {}; - response.content = responsePayload; - response.status = "error"; - return response; - }); - return response; + ); } else { - log.error("Programming error : This method only support HTTP GET requests."); + log.error("Runtime error : This method only support HTTP GET requests."); } }; @@ -101,43 +93,43 @@ var userModule = function () { * * @returns {number} HTTP Status code 201 if succeeded, 409 if user already exists */ - publicMethods.addUser = function (username, firstname, lastname, emailAddress, userRoles) { - var statusCode, carbon = require('carbon'); - 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 tenantId = carbon.server.tenantId(); - var userManager = new carbon.user.UserManager(server, tenantId); - if (userManager.userExists(username)) { - if (log.isDebugEnabled()) { - log.debug("A user with name '" + username + "' already exists."); - } - // http status code 409 refers to - conflict. - statusCode = 409; - } else { - var initialUserPassword = privateMethods.generateInitialUserPassword(); - var defaultUserClaims = privateMethods.buildDefaultUserClaims(firstname, lastname, emailAddress); - - userManager.addUser(username, initialUserPassword, userRoles, defaultUserClaims, "default"); - privateMethods.inviteUserToEnroll(username, initialUserPassword); - if (log.isDebugEnabled()) { - log.debug("A new user with name '" + username + "' was created."); - } - // http status code 201 refers to - created. - statusCode = 201; - } - return statusCode; - } catch (e) { - throw e; - } finally { - utility.endTenantFlow(); - } - }; +// publicMethods.addUser = function (username, firstname, lastname, emailAddress, userRoles) { +// var statusCode, carbon = require("carbon"); +// 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 tenantId = carbon.server.tenantId(); +// var userManager = new carbon.user.UserManager(server, tenantId); +// if (userManager.userExists(username)) { +// if (log.isDebugEnabled()) { +// log.debug("A user with name '" + username + "' already exists."); +// } +// // http status code 409 refers to - conflict. +// statusCode = 409; +// } else { +// var initialUserPassword = privateMethods.generateInitialUserPassword(); +// var defaultUserClaims = privateMethods.buildDefaultUserClaims(firstname, lastname, emailAddress); +// +// userManager.addUser(username, initialUserPassword, userRoles, defaultUserClaims, "default"); +// privateMethods.inviteUserToEnroll(username, initialUserPassword); +// if (log.isDebugEnabled()) { +// log.debug("A new user with name '" + username + "' was created."); +// } +// // http status code 201 refers to - created. +// statusCode = 201; +// } +// return statusCode; +// } catch (e) { +// throw e; +// } finally { +// utility.endTenantFlow(); +// } +// }; /** * Register user to dc-user-store. @@ -188,39 +180,39 @@ var userModule = function () { * @param username Username of the user * @returns {number} HTTP Status code 200 if succeeded, 409 if the user does not exist */ - publicMethods.removeUser = function (username) { - var statusCode, carbon = require('carbon'); - 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 tenantId = carbon.server.tenantId(); - var userManager = new carbon.user.UserManager(server, tenantId); - if (userManager.userExists(username)) { - userManager.removeUser(username); - if (log.isDebugEnabled()) { - log.debug("An existing user with name '" + username + "' was removed."); - } - // http status code 200 refers to - success. - statusCode = 200; - } else { - if (log.isDebugEnabled()) { - log.debug("A user with name '" + username + "' does not exist to remove."); - } - // http status code 409 refers to - conflict. - statusCode = 409; - } - return statusCode; - } catch (e) { - throw e; - } finally { - utility.endTenantFlow(); - } - }; +// publicMethods.removeUser = function (username) { +// var statusCode, carbon = require('carbon'); +// 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 tenantId = carbon.server.tenantId(); +// var userManager = new carbon.user.UserManager(server, tenantId); +// if (userManager.userExists(username)) { +// userManager.removeUser(username); +// if (log.isDebugEnabled()) { +// log.debug("An existing user with name '" + username + "' was removed."); +// } +// // http status code 200 refers to - success. +// statusCode = 200; +// } else { +// if (log.isDebugEnabled()) { +// log.debug("A user with name '" + username + "' does not exist to remove."); +// } +// // http status code 409 refers to - conflict. +// statusCode = 409; +// } +// return statusCode; +// } catch (e) { +// throw e; +// } finally { +// utility.endTenantFlow(); +// } +// }; /* @Deprecated @@ -232,25 +224,25 @@ var userModule = function () { * * @returns {string} Initial User Password */ - privateMethods.generateInitialUserPassword = function () { - var passwordLength = 6; - //defining the pool of characters to be used for initial password generation - var lowerCaseCharset = "abcdefghijklmnopqrstuvwxyz"; - var upperCaseCharset = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; - var numericCharset = "0123456789"; - - var totalCharset = lowerCaseCharset + upperCaseCharset + numericCharset; - var totalCharsetLength = totalCharset.length; - - var initialUserPassword = ""; - for (var i = 0; i < passwordLength; ++i) { - initialUserPassword += totalCharset.charAt(Math.floor(Math.random() * totalCharsetLength)); - } - if (log.isDebugEnabled()) { - log.debug("Initial password created for new user : " + initialUserPassword); - } - return String(initialUserPassword); - }; +// privateMethods.generateInitialUserPassword = function () { +// var passwordLength = 6; +// //defining the pool of characters to be used for initial password generation +// var lowerCaseCharset = "abcdefghijklmnopqrstuvwxyz"; +// var upperCaseCharset = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; +// var numericCharset = "0123456789"; +// +// var totalCharset = lowerCaseCharset + upperCaseCharset + numericCharset; +// var totalCharsetLength = totalCharset.length; +// +// var initialUserPassword = ""; +// for (var i = 0; i < passwordLength; ++i) { +// initialUserPassword += totalCharset.charAt(Math.floor(Math.random() * totalCharsetLength)); +// } +// if (log.isDebugEnabled()) { +// log.debug("Initial password created for new user : " + initialUserPassword); +// } +// return String(initialUserPassword); +// }; /* @Deprecated @@ -264,17 +256,17 @@ var userModule = function () { * * @returns {Object} Default user claims to be provided */ - privateMethods.buildDefaultUserClaims = function (firstname, lastname, emailAddress) { - var defaultUserClaims = { - "http://wso2.org/claims/givenname": firstname, - "http://wso2.org/claims/lastname": lastname, - "http://wso2.org/claims/emailaddress": emailAddress - }; - if (log.isDebugEnabled()) { - log.debug("ClaimMap created for new user : " + stringify(defaultUserClaims)); - } - return defaultUserClaims; - }; +// privateMethods.buildDefaultUserClaims = function (firstname, lastname, emailAddress) { +// var defaultUserClaims = { +// "http://wso2.org/claims/givenname": firstname, +// "http://wso2.org/claims/lastname": lastname, +// "http://wso2.org/claims/emailaddress": emailAddress +// }; +// if (log.isDebugEnabled()) { +// log.debug("ClaimMap created for new user : " + stringify(defaultUserClaims)); +// } +// return defaultUserClaims; +// }; /* @Deprecated @@ -286,89 +278,89 @@ var userModule = function () { * @param username Username of the user * @param password Password of the user */ - privateMethods.inviteUserToEnroll = function (username, password) { - var carbon = require('carbon'); - var enrollmentURL = devicemgtProps.generalConfig.host + devicemgtProps.webAgentContext + "download-agent"; - 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; - } - //var user = userManagementService.getUser(username, carbonUser.tenantId); - try { - utility.startTenantFlow(carbonUser); - var tenantId = carbon.server.tenantId(); - var userManager = new carbon.user.UserManager(server, tenantId); - var emailTo = []; - var user = userManager.getUser(username); - emailTo[0] = privateMethods.getEmail(username, userManager); - var emailMessageProperties = new EmailMessageProperties(); - emailMessageProperties.setMailTo(emailTo); - emailMessageProperties.setFirstName(privateMethods.getFirstName(username, userManager)); - emailMessageProperties.setUserName(username); - emailMessageProperties.setPassword(password); - emailMessageProperties.setEnrolmentUrl(enrollmentURL); - deviceManagementService.sendRegistrationEmail(emailMessageProperties); - } catch (e) { - throw e; - } finally { - utility.endTenantFlow(); - } - }; +// privateMethods.inviteUserToEnroll = function (username, password) { +// var carbon = require('carbon'); +// var enrollmentURL = devicemgtProps.generalConfig.host + devicemgtProps.webAgentContext + "download-agent"; +// 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; +// } +// //var user = userManagementService.getUser(username, carbonUser.tenantId); +// try { +// utility.startTenantFlow(carbonUser); +// var tenantId = carbon.server.tenantId(); +// var userManager = new carbon.user.UserManager(server, tenantId); +// var emailTo = []; +// var user = userManager.getUser(username); +// emailTo[0] = privateMethods.getEmail(username, userManager); +// var emailMessageProperties = new EmailMessageProperties(); +// emailMessageProperties.setMailTo(emailTo); +// emailMessageProperties.setFirstName(privateMethods.getFirstName(username, userManager)); +// emailMessageProperties.setUserName(username); +// emailMessageProperties.setPassword(password); +// emailMessageProperties.setEnrolmentUrl(enrollmentURL); +// deviceManagementService.sendRegistrationEmail(emailMessageProperties); +// } catch (e) { +// throw e; +// } finally { +// utility.endTenantFlow(); +// } +// }; /* @Deprecated */ - privateMethods.getEmail = function (username, userManager) { - return userManager.getClaim(username, "http://wso2.org/claims/emailaddress", null) - }; +// privateMethods.getEmail = function (username, userManager) { +// return userManager.getClaim(username, "http://wso2.org/claims/emailaddress", null) +// }; /* @Deprecated */ - privateMethods.getFirstName = function (username, userManager) { - return userManager.getClaim(username, "http://wso2.org/claims/givenname", null) - }; +// privateMethods.getFirstName = function (username, userManager) { +// return userManager.getClaim(username, "http://wso2.org/claims/givenname", null) +// }; /* @Deprecated */ - privateMethods.getLastName = function (username, userManager) { - return userManager.getClaim(username, "http://wso2.org/claims/lastname", null) - }; +// privateMethods.getLastName = function (username, userManager) { +// return userManager.getClaim(username, "http://wso2.org/claims/lastname", null) +// }; /* @Deprecated */ - publicMethods.inviteUser = function (username) { - 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; - } - var enrollmentURL = devicemgtProps.generalConfig.host + devicemgtProps.webAgentContext + "download-agent"; - - try { - utility.startTenantFlow(carbonUser); - var tenantId = carbon.server.tenantId(); - var userManager = new carbon.user.UserManager(server, tenantId); - var user = userManager.getUser(username); - var emailProperties = new EmailMessageProperties(); - var emailTo = []; - emailTo[0] = privateMethods.getEmail(username, userManager); - emailProperties.setMailTo(emailTo); - //emailProperties.setFirstName(user.getFirstName()); - emailProperties.setFirstName(privateMethods.getFirstName(username, userManager)); - emailProperties.setEnrolmentUrl(enrollmentURL); - deviceManagementService.sendEnrolmentInvitation(emailProperties); - } catch (e) { - throw e; - } finally { - utility.endTenantFlow(); - } - }; +// publicMethods.inviteUser = function (username) { +// 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; +// } +// var enrollmentURL = devicemgtProps.generalConfig.host + devicemgtProps.webAgentContext + "download-agent"; +// +// try { +// utility.startTenantFlow(carbonUser); +// var tenantId = carbon.server.tenantId(); +// var userManager = new carbon.user.UserManager(server, tenantId); +// var user = userManager.getUser(username); +// var emailProperties = new EmailMessageProperties(); +// var emailTo = []; +// emailTo[0] = privateMethods.getEmail(username, userManager); +// emailProperties.setMailTo(emailTo); +// //emailProperties.setFirstName(user.getFirstName()); +// emailProperties.setFirstName(privateMethods.getFirstName(username, userManager)); +// emailProperties.setEnrolmentUrl(enrollmentURL); +// deviceManagementService.sendEnrolmentInvitation(emailProperties); +// } catch (e) { +// throw e; +// } finally { +// utility.endTenantFlow(); +// } +// }; /* @Updated @@ -382,9 +374,12 @@ var userModule = function () { } try { utility.startTenantFlow(carbonUser); - var url = devicemgtProps["httpsURL"] + constants.ADMIN_SERVICE_CONTEXT + "/users"; - return privateMethods.callBackend(url, constants.HTTP_GET); - + var url = devicemgtProps["httpsURL"] + devicemgtProps["backendRestEndpoints"]["deviceMgt"] + "/users?offset=0&limit=100"; + var response = privateMethods.callBackend(url, constants["HTTP_GET"]); + if (response.status == "success") { + response.content = parse(response.content).users; + } + return response; } catch (e) { throw e; } finally { @@ -395,22 +390,16 @@ var userModule = function () { /** * Return a User object from the backend by calling the JAX-RS * @param username - * @returns { - * 'status': 'success'|'error', - * 'content': { - "username": "abc", - "firstname": "abc", - "lastname": "efj", - "emailAddress": "abc@abc.com" - } - * } + * @returns {object} a response object with status and content on success. */ publicMethods.getUser = function (username) { var carbonUser = privateMethods.getCarbonUser(); try { utility.startTenantFlow(carbonUser); - var url = devicemgtProps["httpsURL"] + constants.ADMIN_SERVICE_CONTEXT + "/users/view?username=" + username; - var response = privateMethods.callBackend(url, constants.HTTP_GET); + var url = devicemgtProps["httpsURL"] + devicemgtProps["backendRestEndpoints"]["deviceMgt"] + "/users/" + + encodeURIComponent(username); + var response = privateMethods.callBackend(url, constants["HTTP_GET"]); + response["content"] = parse(response.content); response["userDomain"] = carbonUser.domain; return response; } catch (e) { @@ -419,18 +408,19 @@ var userModule = function () { utility.endTenantFlow(); } }; + /** - * TODO: comment + * Returns a set of roles assigned to a particular user * @param username - * @returns {*} + * @returns {object} a response object with status and content on success. */ publicMethods.getRolesByUsername = function (username) { var carbonUser = privateMethods.getCarbonUser(); try { utility.startTenantFlow(carbonUser); - var url = devicemgtProps["httpsURL"] + constants.ADMIN_SERVICE_CONTEXT + "/users/roles?username=" + username; - var response = privateMethods.callBackend(url, constants.HTTP_GET); - return response; + var url = devicemgtProps["httpsURL"] + devicemgtProps["backendRestEndpoints"]["deviceMgt"] + "/users/" + + encodeURIComponent(username) + "/roles"; + return privateMethods.callBackend(url, constants["HTTP_GET"]); } catch (e) { throw e; } finally { @@ -450,8 +440,8 @@ var userModule = function () { } try { utility.startTenantFlow(carbonUser); - var url = devicemgtProps["httpsURL"] + constants.ADMIN_SERVICE_CONTEXT + "/users/users-by-username"; - return privateMethods.callBackend(url, constants.HTTP_GET) + var url = devicemgtProps["httpsURL"] + "/mdm-admin/users/users-by-username"; + return privateMethods.callBackend(url, constants["HTTP_GET"]); } catch (e) { throw e; } finally { @@ -467,15 +457,19 @@ var userModule = function () { */ publicMethods.getRoles = function () { var carbonUser = session.get(constants["USER_SESSION_KEY"]); - var utility = require('/app/modules/utility.js')["utility"]; + 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 url = devicemgtProps["httpsURL"] + constants.ADMIN_SERVICE_CONTEXT + "/roles"; - return privateMethods.callBackend(url, constants.HTTP_GET); + var url = devicemgtProps["httpsURL"] + devicemgtProps["backendRestEndpoints"]["deviceMgt"] + "/roles"; + var response = privateMethods.callBackend(url, constants["HTTP_GET"]); + if (response.status == "success") { + response.content = parse(response.content).roles; + } + return response; } catch (e) { throw e; } finally { @@ -488,18 +482,24 @@ var userModule = function () { */ /** * Get User Roles from user store (Internal roles not included). + * @returns {object} a response object with status and content on success. */ - publicMethods.getRolesByUserStore = function (userStore) { + publicMethods.getRolesByUserStore = function () { + var ROLE_LIMIT = devicemgtProps["pageSize"]; var carbonUser = session.get(constants["USER_SESSION_KEY"]); - var utility = require('/app/modules/utility.js')["utility"]; + 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 url = devicemgtProps["httpsURL"] + constants.ADMIN_SERVICE_CONTEXT + "/roles/" + encodeURIComponent(userStore); - return privateMethods.callBackend(url, constants.HTTP_GET); + var url = devicemgtProps["httpsURL"] + devicemgtProps["backendRestEndpoints"]["deviceMgt"] + "/roles?limit=" + ROLE_LIMIT; + var response = privateMethods.callBackend(url, constants["HTTP_GET"]); + if (response.status == "success") { + response.content = parse(response.content).roles; + } + return response; } catch (e) { throw e; } finally { @@ -510,17 +510,22 @@ var userModule = function () { /** * Get Platforms. */ + //TODO Move this piece of logic out of user.js to somewhere else appropriate. publicMethods.getPlatforms = function () { var carbonUser = session.get(constants["USER_SESSION_KEY"]); - var utility = require('/app/modules/utility.js')["utility"]; + 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 url = devicemgtProps["httpsURL"] + constants.ADMIN_SERVICE_CONTEXT + "/devices/types"; - return privateMethods.callBackend(url, constants.HTTP_GET); + var url = devicemgtProps["httpsURL"] + devicemgtProps["backendRestEndpoints"]["deviceMgt"] + "/admin/device-types"; + var response = privateMethods.callBackend(url, constants["HTTP_GET"]); + if (response.status == "success") { + response.content = parse(response.content); + } + return response; } catch (e) { throw e; } finally { @@ -535,15 +540,17 @@ var userModule = function () { */ publicMethods.getRole = function (roleName) { var carbonUser = session.get(constants["USER_SESSION_KEY"]); - var utility = require('/app/modules/utility.js')["utility"]; + 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 url = devicemgtProps["httpsURL"] + constants.ADMIN_SERVICE_CONTEXT + "/roles/role?rolename=" + encodeURIComponent(roleName); - var response = privateMethods.callBackend(url, constants.HTTP_GET); + var url = devicemgtProps["httpsURL"] + devicemgtProps["backendRestEndpoints"]["deviceMgt"] + + "/roles/" + encodeURIComponent(roleName); + var response = privateMethods.callBackend(url, constants["HTTP_GET"]); + response.content = parse(response.content); return response; } catch (e) { throw e; @@ -776,24 +783,29 @@ var userModule = function () { * retrieve secondary user stores. * This needs Authentication since the method access admin services. * - * @returns {string array} Array of secondary user stores. + * @returns Array of secondary user stores. */ publicMethods.getSecondaryUserStores = function () { var returnVal = []; - var endpoint = devicemgtProps.adminService + constants.USER_STORE_CONFIG_ADMIN_SERVICE_END_POINT; + var endpoint = devicemgtProps["adminService"] + constants["USER_STORE_CONFIG_ADMIN_SERVICE_END_POINT"]; var wsPayload = ""; serviceInvokers.WS.soapRequest( - "urn:getSecondaryRealmConfigurations", endpoint, wsPayload, function (wsResponse) { + "urn:getSecondaryRealmConfigurations", + wsPayload, + endpoint, + function (wsResponse) { var domainIDs = stringify(wsResponse.*::['return']. *::domainId.text()); if (domainIDs != "\"\"") { - var regExpForSearch = new RegExp(constants.USER_STORES_NOISY_CHAR, "g"); + var regExpForSearch = new RegExp(constants["USER_STORES_NOISY_CHAR"], "g"); domainIDs = domainIDs.replace(regExpForSearch, ""); - returnVal = domainIDs.split(constants.USER_STORES_SPLITTING_CHAR); + returnVal = domainIDs.split(constants["USER_STORES_SPLITTING_CHAR"]); } }, function (e) { log.error("Error retrieving secondary user stores", e); - }, constants.SOAP_VERSION); + }, + constants["SOAP_VERSION"]); return returnVal; }; + return publicMethods; }(); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.user.create/create.hbs b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.user.create/create.hbs index e8902e77d2..d9f24cd04f 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.user.create/create.hbs +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.user.create/create.hbs @@ -15,7 +15,7 @@ specific language governing permissions and limitations under the License. }} -{{unit "cdmf.unit.ui.title" pageTitle="User Management"}} +{{unit "cdmf.unit.ui.title" pageTitle="User Management | Add User"}} {{#zone "breadcrumbs"}}
  • @@ -50,8 +50,8 @@ -
  • - Users + USERS
  • {{/zone}} {{#zone "navbarActions"}}
  • - + 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.hbs 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.hbs index 2a3054d3af..181056757f 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.hbs +++ 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.hbs @@ -16,38 +16,58 @@ under the License. }} {{#zone "navMenu-icon"}} - + + + {{/zone}} -{{~#zone "navMenu-items"}} +{{#zone "navMenu-items"}} {{#if permissions.VIEW_DASHBOARD}}
  • - Admin Dashboard + + + Admin Dashboard +
  • {{/if}} {{#if permissions.LIST_OWN_DEVICES}}
  • - Device Management + + + Device Management +
  • {{/if}} {{#if permissions.LIST_GROUPS}}
  • - Group Management + + + Group Management +
  • {{/if}} {{#if permissions.ADD_USER}}
  • - User Management + + + User Management +
  • {{/if}} {{#if permissions.ADD_ROLE}}
  • - Role Management + + + Role Management +
  • {{/if}} {{#if permissions.ADD_POLICY}}
  • - Policy Management + + + Policy Management +
  • {{/if}} {{#if permissions.TENANT_CONFIGURATION}} From 1916c4df5fb87c231b86d39152bc3716ed27d9cd Mon Sep 17 00:00:00 2001 From: dilanua Date: Sun, 24 Jul 2016 20:35:52 +0530 Subject: [PATCH 17/24] Refactoring cdmf product page layout --- .../app/layouts/cdmf.layout.default.hbs | 120 ++++++++++-------- 1 file changed, 66 insertions(+), 54 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/layouts/cdmf.layout.default.hbs b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/layouts/cdmf.layout.default.hbs index 4cb1625d3c..e4e75b3bd0 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/layouts/cdmf.layout.default.hbs +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/layouts/cdmf.layout.default.hbs @@ -1,64 +1,76 @@ - - - - - - +{{!-- 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 - {{#defineZone "title"}}WSO2 Template{{/defineZone}} - {{defineZone "favicon"}} - {{defineZone "topCss"}} - {{defineZone "topJs"}} - - +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. --}} - -
    -
    -
    - - - - - GO BACK + + + + + + + {{defineZone "favicon"}} + + {{defineZone "title"}} + + {{defineZone "topLibCss"}} + {{defineZone "topCss"}} + {{defineZone "topJs"}} + + + +
    +
    +
    + + + + + GO BACK +
    +
    + +
    +
    +
    -
    -
    -
    -
    - + - -{{defineZone "header"}} - + {{defineZone "header"}} - - - + - -{{defineZone "sidePanes"}} - + {{defineZone "sidePanes"}} - -
    - {{defineZone "contentTitle"}} -
    - {{defineZone "content"}} -
    -
    - + +
    + {{defineZone "contentTitle"}} +
    + {{defineZone "content"}} +
    +
    + - -
    -
    - {{defineZone "footer"}} -
    -
    - +
    +
    + {{defineZone "footer"}} +
    +
    -{{defineZone "bottomJs"}} - + {{defineZone "bottomLibJs"}} + {{defineZone "bottomJs"}} + \ No newline at end of file From c12630e65c076d5e734176625eff589e8b67a462 Mon Sep 17 00:00:00 2001 From: dilanua Date: Sun, 24 Jul 2016 21:20:51 +0530 Subject: [PATCH 18/24] Refactoring base ui app config reader --- .../jaggeryapps/devicemgt/api/data-tables-invoker-api.jag | 2 +- .../main/resources/jaggeryapps/devicemgt/api/device-api.jag | 2 +- .../main/resources/jaggeryapps/devicemgt/api/group-api.jag | 2 +- .../main/resources/jaggeryapps/devicemgt/api/invoker-api.jag | 2 +- .../resources/jaggeryapps/devicemgt/api/operation-api.jag | 2 +- .../src/main/resources/jaggeryapps/devicemgt/api/user-api.jag | 2 +- .../devicemgt/app/conf/{devicemgt-props.js => reader/main.js} | 4 ++-- .../devicemgt/app/{modules => conf/reader}/pinch.min.js | 0 .../jaggeryapps/devicemgt/app/modules/api-wrapper-util.js | 2 +- .../devicemgt/app/modules/backend-service-invoker.js | 2 +- .../resources/jaggeryapps/devicemgt/app/modules/device.js | 2 +- .../main/resources/jaggeryapps/devicemgt/app/modules/group.js | 2 +- .../main/resources/jaggeryapps/devicemgt/app/modules/init.js | 2 +- .../main/resources/jaggeryapps/devicemgt/app/modules/login.js | 2 +- .../resources/jaggeryapps/devicemgt/app/modules/operation.js | 2 +- .../resources/jaggeryapps/devicemgt/app/modules/policy.js | 2 +- .../main/resources/jaggeryapps/devicemgt/app/modules/user.js | 2 +- .../main/resources/jaggeryapps/devicemgt/app/modules/util.js | 2 +- .../resources/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 +- .../jaggeryapps/devicemgt/app/pages/cdmf.page.users/users.js | 2 +- .../devicemgt/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 +- 28 files changed, 28 insertions(+), 28 deletions(-) rename components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/conf/{devicemgt-props.js => reader/main.js} (95%) rename components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/{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 f118862bf1..9e75c45d18 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/devicemgt-props.js").config(); +var devicemgtProps = require("/app/conf/reader/main.js").config(); var serviceInvokers = require("/app/modules/backend-service-invoker.js")["backendServiceInvoker"]; 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 d609d950e8..0a95efff1e 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/devicemgt-props.js').config(); +var devicemgtProps = require("/app/conf/reader/main.js").config(); var userModule = require("/app/modules/user.js").userModule; var serviceInvokers = require("/app/modules/backend-service-invoker.js").backendServiceInvoker; 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 4d5bd9973f..6edc578656 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/devicemgt-props.js').config(); +var devicemgtProps = require("/app/conf/reader/main.js").config(); var serviceInvokers = require("/app/modules/backend-service-invoker.js").backendServiceInvoker; 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 1fd232e3c7..d808aa612b 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/devicemgt-props.js').config(); +var devicemgtProps = require("/app/conf/reader/main.js").config(); var serviceInvokers = require("/app/modules/backend-service-invoker.js")["backendServiceInvoker"]; 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 797eac1bd1..e23288eeec 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/backend-service-invoker.js")["backendServiceInvoker"]; -var devicemgtProps = require('/app/conf/devicemgt-props.js').config(); +var devicemgtProps = require("/app/conf/reader/main.js").config(); 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 05364453b5..1f5dd33501 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/devicemgt-props.js').config(); +var devicemgtProps = require("/app/conf/reader/main.js").config(); 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/devicemgt-props.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/conf/reader/main.js similarity index 95% rename from components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/conf/devicemgt-props.js rename to components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/conf/reader/main.js index 39a7c2eb51..219c6de62d 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/conf/devicemgt-props.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/conf/reader/main.js @@ -19,9 +19,9 @@ var config = function () { var conf = application.get("UI_CONFIG"); if (!conf) { - var pinch = require("/app/modules/pinch.min.js")["pinch"]; - var server = require("carbon")["server"]; + var pinch = require("/app/conf/reader/pinch.min.js")["pinch"]; var config = require("/app/conf/config.json"); + var server = require("carbon")["server"]; pinch(config, /^/, function (path, key, value) { if ((typeof value === "string") && value.indexOf("%https.ip%") > -1) { return value.replace("%https.ip%", server.address("https")); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/pinch.min.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/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/modules/pinch.min.js rename to components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/conf/reader/pinch.min.js diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/api-wrapper-util.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/api-wrapper-util.js index becd0c13c8..14fe692824 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/api-wrapper-util.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/api-wrapper-util.js @@ -20,7 +20,7 @@ var apiWrapperUtil = function () { var module = {}; var tokenUtil = require("/app/modules/util.js").util; var constants = require("/app/modules/constants.js"); - var devicemgtProps = require('/app/conf/devicemgt-props.js').config(); + var devicemgtProps = require("/app/conf/reader/main.js").config(); var log = new Log("/app/modules/api-wrapper-util.js"); module.refreshToken = function () { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/backend-service-invoker.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/backend-service-invoker.js index 19e5a7c379..632e72cf40 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/backend-service-invoker.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/backend-service-invoker.js @@ -31,7 +31,7 @@ var backendServiceInvoker = function () { var TOKEN_EXPIRED = "Access token expired"; var TOKEN_INVALID = "Invalid input. Access token validation failed"; - var devicemgtProps = require("/app/conf/devicemgt-props.js").config(); + var devicemgtProps = require("/app/conf/reader/main.js").config(); var constants = require("/app/modules/constants.js"); var userModule = require("/app/modules/user.js")["userModule"]; var tokenUtil = require("/app/modules/api-wrapper-util.js")["apiWrapperUtil"]; 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 367db085bc..bcee18781a 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/devicemgt-props.js').config(); + var devicemgtProps = require("/app/conf/reader/main.js").config(); var serviceInvokers = require("/app/modules/backend-service-invoker.js").backendServiceInvoker; 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 d4cd86a29c..feebae5946 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/devicemgt-props.js').config(); + var devicemgtProps = require("/app/conf/reader/main.js").config(); var utility = require("/app/modules/utility.js").utility; var serviceInvokers = require("/app/modules/backend-service-invoker.js").backendServiceInvoker; 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 8d2b0c197f..0c0f7e0925 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/devicemgt-props.js").config(); +var devicemgtProps = require("/app/conf/reader/main.js").config(); 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 4597c2d737..a720c724be 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 @@ -33,7 +33,7 @@ var onFail; properties = {username: context.input.username, password: context.input.password}; apiWrapperUtil.setupAccessTokenPair(constants.GRANT_TYPE_PASSWORD, properties); } - var devicemgtProps = require('/app/conf/devicemgt-props.js').config(); + var devicemgtProps = require("/app/conf/reader/main.js").config(); 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/operation.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/operation.js index 1655adf1ed..e49c37cecd 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/devicemgt-props.js').config(); + var devicemgtProps = require("/app/conf/reader/main.js").config(); var serviceInvokers = require("/app/modules/backend-service-invoker.js").backendServiceInvoker; 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 a4ee8c1256..d623683249 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/devicemgt-props.js').config(); + var devicemgtProps = require("/app/conf/reader/main.js").config(); var serviceInvokers = require("/app/modules/backend-service-invoker.js").backendServiceInvoker; 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 b0e05fdd8a..608ba421c7 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/devicemgt-props.js").config(); + var devicemgtProps = require("/app/conf/reader/main.js").config(); var serviceInvokers = require("/app/modules/backend-service-invoker.js")["backendServiceInvoker"]; /* Initializing user manager */ diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/util.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/util.js index 3334ea6664..01cbb616fe 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/util.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/util.js @@ -21,7 +21,7 @@ var util = function () { var module = {}; var Base64 = Packages.org.apache.commons.codec.binary.Base64; var String = Packages.java.lang.String; - var devicemgtProps = require('/app/conf/devicemgt-props.js').config(); + var devicemgtProps = require("/app/conf/reader/main.js").config(); var carbon = require('carbon'); var constants = require("/app/modules/constants.js"); var adminUser = devicemgtProps["adminUser"]; 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 c92fea29cd..da8b95feab 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/devicemgt-props.js').config(); + var devicemgtProps = require("/app/conf/reader/main.js").config(); 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 82aa1101a6..9220fc5bb8 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/devicemgt-props.js').config(); + var devicemgtProps = require("/app/conf/reader/main.js").config(); 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 5c646f33f9..57e24f4551 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/devicemgt-props.js').config(); + var devicemgtProps = require("/app/conf/reader/main.js").config(); 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 2119d5d600..641a0b1c64 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/devicemgt-props.js").config(); + var devicemgtProps = require("/app/conf/reader/main.js").config(); 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 982661fcd4..1d19063197 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/devicemgt-props.js').config(); + var devicemgtProps = require("/app/conf/reader/main.js").config(); 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 d0085bd39d..e48afde551 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/devicemgt-props.js").config(); + require("/app/conf/reader/main.js").config(); 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 770ee3ca8c..593ebad5da 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 mdmProps = require('/app/conf/devicemgt-props.js').config(); + var mdmProps = require("/app/conf/reader/main.js").config(); context.permissions = permissions; context["enrollmentURL"] = mdmProps.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 b98e0e2310..0cf5326700 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/devicemgt-props.js').config(); + var deviceMgtProps = require("/app/conf/reader/main.js").config(); 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 90970d8e42..c2633447db 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/devicemgt-props.js").config(); + var deviceMgtProps = require("/app/conf/reader/main.js").config(); 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 2cd3d91080..af1cff839d 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/devicemgt-props.js").config(); + var deviceMgtProps = require("/app/conf/reader/main.js").config(); context["appContext"] = deviceMgtProps.appContext; context["adminRole"] = deviceMgtProps.adminRole; return context; From d04cb54ae8412e4bf20ab4cde7277617f82256e3 Mon Sep 17 00:00:00 2001 From: dilanua Date: Sun, 24 Jul 2016 21:34:22 +0530 Subject: [PATCH 19/24] Refactoring base ui app config reader --- .../devicemgt/app/conf/reader/main.js | 29 ++++++++++--------- 1 file changed, 15 insertions(+), 14 deletions(-) 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/conf/reader/main.js index 219c6de62d..3e8797e2d3 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/conf/reader/main.js @@ -17,24 +17,25 @@ */ var config = function () { - var conf = application.get("UI_CONFIG"); + var conf = application.get("UI_CONF"); if (!conf) { + conf = require("/app/conf/config.json"); var pinch = require("/app/conf/reader/pinch.min.js")["pinch"]; - var config = require("/app/conf/config.json"); var server = require("carbon")["server"]; - pinch(config, /^/, function (path, key, value) { - if ((typeof value === "string") && value.indexOf("%https.ip%") > -1) { - return value.replace("%https.ip%", server.address("https")); - } else if ((typeof value === "string") && value.indexOf("%http.ip%") > -1) { - return value.replace("%http.ip%", server.address("http")); - } else if ((typeof value === "string") && value.indexOf("%date-year%") > -1) { - var year = new Date().getFullYear(); - return value.replace("%date-year%", year); + pinch(conf, /^/, + function (path, key, value) { + if ((typeof value === "string") && value.indexOf("%https.ip%") > -1) { + return value.replace("%https.ip%", server.address("https")); + } else if ((typeof value === "string") && value.indexOf("%http.ip%") > -1) { + return value.replace("%http.ip%", server.address("http")); + } else if ((typeof value === "string") && value.indexOf("%date-year%") > -1) { + var year = new Date().getFullYear(); + return value.replace("%date-year%", year); + } + return value; } - return value; - }); - application.put("UI_CONFIG", config); - conf = config; + ); + application.put("UI_CONF", conf); } return conf; }; \ No newline at end of file From 00f98f5ccea4c9fd7f9551c4fb5d6202d2aa32b1 Mon Sep 17 00:00:00 2001 From: dilanua Date: Mon, 25 Jul 2016 05:50:49 +0530 Subject: [PATCH 20/24] Updating base ui app config reader --- .../jaggeryapps/devicemgt/api/data-tables-invoker-api.jag | 2 +- .../main/resources/jaggeryapps/devicemgt/api/device-api.jag | 2 +- .../main/resources/jaggeryapps/devicemgt/api/group-api.jag | 2 +- .../main/resources/jaggeryapps/devicemgt/api/invoker-api.jag | 2 +- .../resources/jaggeryapps/devicemgt/api/operation-api.jag | 2 +- .../src/main/resources/jaggeryapps/devicemgt/api/user-api.jag | 2 +- .../resources/jaggeryapps/devicemgt/app/conf/reader/main.js | 4 ++-- .../jaggeryapps/devicemgt/app/modules/api-wrapper-util.js | 2 +- .../devicemgt/app/modules/backend-service-invoker.js | 2 +- .../resources/jaggeryapps/devicemgt/app/modules/device.js | 2 +- .../main/resources/jaggeryapps/devicemgt/app/modules/group.js | 2 +- .../main/resources/jaggeryapps/devicemgt/app/modules/init.js | 2 +- .../main/resources/jaggeryapps/devicemgt/app/modules/login.js | 2 +- .../resources/jaggeryapps/devicemgt/app/modules/operation.js | 2 +- .../resources/jaggeryapps/devicemgt/app/modules/policy.js | 2 +- .../main/resources/jaggeryapps/devicemgt/app/modules/user.js | 2 +- .../main/resources/jaggeryapps/devicemgt/app/modules/util.js | 2 +- .../resources/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 +- .../jaggeryapps/devicemgt/app/pages/cdmf.page.users/users.js | 2 +- .../devicemgt/app/units/cdmf.unit.device.type.view/view.js | 4 ++-- .../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 +- 27 files changed, 29 insertions(+), 29 deletions(-) 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 9e75c45d18..16aa1a7ed9 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").config(); +var devicemgtProps = require("/app/conf/reader/main.js")["conf"]; var serviceInvokers = require("/app/modules/backend-service-invoker.js")["backendServiceInvoker"]; 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 0a95efff1e..8b1d42b393 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").config(); +var devicemgtProps = require("/app/conf/reader/main.js")["conf"]; var userModule = require("/app/modules/user.js").userModule; var serviceInvokers = require("/app/modules/backend-service-invoker.js").backendServiceInvoker; 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 6edc578656..d36efad7e5 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").config(); +var devicemgtProps = require("/app/conf/reader/main.js")["conf"]; var serviceInvokers = require("/app/modules/backend-service-invoker.js").backendServiceInvoker; 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 d808aa612b..fbbaad8d90 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").config(); +var devicemgtProps = require("/app/conf/reader/main.js")["conf"]; var serviceInvokers = require("/app/modules/backend-service-invoker.js")["backendServiceInvoker"]; 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 e23288eeec..b961df21a6 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/backend-service-invoker.js")["backendServiceInvoker"]; -var devicemgtProps = require("/app/conf/reader/main.js").config(); +var devicemgtProps = require("/app/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 1f5dd33501..d472fad051 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").config(); +var devicemgtProps = require("/app/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/conf/reader/main.js index 3e8797e2d3..ec5b6642f2 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/conf/reader/main.js @@ -16,7 +16,7 @@ * under the License. */ -var config = function () { +var conf = function () { var conf = application.get("UI_CONF"); if (!conf) { conf = require("/app/conf/config.json"); @@ -38,4 +38,4 @@ var config = function () { application.put("UI_CONF", conf); } return conf; -}; \ No newline at end of file +}(); \ No newline at end of file diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/api-wrapper-util.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/api-wrapper-util.js index 14fe692824..55d80f5497 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/api-wrapper-util.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/api-wrapper-util.js @@ -20,7 +20,7 @@ var apiWrapperUtil = function () { var module = {}; var tokenUtil = require("/app/modules/util.js").util; var constants = require("/app/modules/constants.js"); - var devicemgtProps = require("/app/conf/reader/main.js").config(); + var devicemgtProps = require("/app/conf/reader/main.js")["conf"]; var log = new Log("/app/modules/api-wrapper-util.js"); module.refreshToken = function () { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/backend-service-invoker.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/backend-service-invoker.js index 632e72cf40..1e374b434d 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/backend-service-invoker.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/backend-service-invoker.js @@ -31,7 +31,7 @@ var backendServiceInvoker = function () { var TOKEN_EXPIRED = "Access token expired"; var TOKEN_INVALID = "Invalid input. Access token validation failed"; - var devicemgtProps = require("/app/conf/reader/main.js").config(); + var devicemgtProps = require("/app/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/api-wrapper-util.js")["apiWrapperUtil"]; 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 bcee18781a..1cd0c5e445 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").config(); + var devicemgtProps = require("/app/conf/reader/main.js")["conf"]; var serviceInvokers = require("/app/modules/backend-service-invoker.js").backendServiceInvoker; 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 feebae5946..da664859b5 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").config(); + var devicemgtProps = require("/app/conf/reader/main.js")["conf"]; var utility = require("/app/modules/utility.js").utility; var serviceInvokers = require("/app/modules/backend-service-invoker.js").backendServiceInvoker; 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 0c0f7e0925..897a4f0c4f 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").config(); +var devicemgtProps = require("/app/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 a720c724be..038082c50c 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 @@ -33,7 +33,7 @@ var onFail; properties = {username: context.input.username, password: context.input.password}; apiWrapperUtil.setupAccessTokenPair(constants.GRANT_TYPE_PASSWORD, properties); } - var devicemgtProps = require("/app/conf/reader/main.js").config(); + var devicemgtProps = require("/app/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/operation.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/operation.js index e49c37cecd..447c386812 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").config(); + var devicemgtProps = require("/app/conf/reader/main.js")["conf"]; var serviceInvokers = require("/app/modules/backend-service-invoker.js").backendServiceInvoker; 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 d623683249..e4b143dee3 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").config(); + var devicemgtProps = require("/app/conf/reader/main.js")["conf"]; var serviceInvokers = require("/app/modules/backend-service-invoker.js").backendServiceInvoker; 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 608ba421c7..cea0e38c40 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").config(); + var devicemgtProps = require("/app/conf/reader/main.js")["conf"]; var serviceInvokers = require("/app/modules/backend-service-invoker.js")["backendServiceInvoker"]; /* Initializing user manager */ diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/util.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/util.js index 01cbb616fe..921850ca64 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/util.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/util.js @@ -21,7 +21,7 @@ var util = function () { var module = {}; var Base64 = Packages.org.apache.commons.codec.binary.Base64; var String = Packages.java.lang.String; - var devicemgtProps = require("/app/conf/reader/main.js").config(); + var devicemgtProps = require("/app/conf/reader/main.js")["conf"]; var carbon = require('carbon'); var constants = require("/app/modules/constants.js"); var adminUser = devicemgtProps["adminUser"]; 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 da8b95feab..b63edc3a2a 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").config(); + var devicemgtProps = require("/app/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 9220fc5bb8..a3b0875812 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").config(); + var devicemgtProps = require("/app/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 57e24f4551..ebfda4568b 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").config(); + var devicemgtProps = require("/app/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 641a0b1c64..70e9089a5f 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").config(); + var devicemgtProps = require("/app/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 1d19063197..8f94c2902b 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").config(); + var devicemgtProps = require("/app/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 e48afde551..98ddb20716 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"]; - require("/app/conf/reader/main.js").config(); + var deviceMgtProps = require("/app/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 593ebad5da..9cf038f561 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,9 +30,9 @@ function onRequest (context) { var userModule = require("/app/modules/user.js").userModule; var constants = require("/app/modules/constants.js"); var permissions = userModule.getUIPermissions(); - var mdmProps = require("/app/conf/reader/main.js").config(); + var deviceMgtProps = require("/app/conf/reader/main.js")["conf"]; context.permissions = permissions; - context["enrollmentURL"] = mdmProps.enrollmentURL; + context["enrollmentURL"] = deviceMgtProps.enrollmentURL; return configs; } \ 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.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 0cf5326700..db293c3bf6 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").config(); + var deviceMgtProps = require("/app/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 c2633447db..5e24261bd2 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").config(); + var deviceMgtProps = require("/app/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 af1cff839d..681883aae3 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").config(); + var deviceMgtProps = require("/app/conf/reader/main.js")["conf"]; context["appContext"] = deviceMgtProps.appContext; context["adminRole"] = deviceMgtProps.adminRole; return context; From c57c75945c94cf31c4a576e0bbdbb9607fc920af Mon Sep 17 00:00:00 2001 From: dilanua Date: Mon, 25 Jul 2016 10:11:39 +0530 Subject: [PATCH 21/24] Deprecating invoker-request-wrapper (unused) --- .../app/modules/invoker-request-wrapper.js | 150 +++++++++--------- 1 file changed, 77 insertions(+), 73 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/invoker-request-wrapper.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/invoker-request-wrapper.js index a8fe2b0fc1..b4ccc62dc1 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/invoker-request-wrapper.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/invoker-request-wrapper.js @@ -16,79 +16,83 @@ * under the License. */ +/* + @Deprecated + */ + /** * This invokerRequestWrapper contains the wrappers for invoker util requests. */ -var invokerRequestWrapper = function () { - - var constants = require("/modules/constants.js"); - var serviceInvokers = require("/modules/backend-service-invoker.js").backendServiceInvoker; - - var publicWrappers = []; - - publicWrappers.initiate = function (method, url, payload) { - switch (method) { - case constants.HTTP_GET: - var response = serviceInvokers.XMLHttp.get(url, function (responsePayload) { - var response = {}; - response.content = responsePayload["responseContent"]; - response.status = "success"; - return response; - }, - function (responsePayload) { - var response = {}; - response.content = responsePayload; - response.status = "error"; - return response; - }); - return response; - break; - case constants.HTTP_POST: - var response = serviceInvokers.XMLHttp.post(url, payload, function (responsePayload) { - var response = {}; - response.content = responsePayload["responseContent"]; - response.status = "success"; - return response; - }, - function (responsePayload) { - var response = {}; - response.content = responsePayload; - response.status = "error"; - return response; - }); - return response; - break; - case constants.HTTP_PUT: - var response = serviceInvokers.XMLHttp.put(url, payload, function (responsePayload) { - var response = {}; - response.content = responsePayload["responseContent"]; - response.status = "success"; - return response; - }, - function (responsePayload) { - var response = {}; - response.content = responsePayload; - response.status = "error"; - return response; - }); - return response; - break; - case constants.HTTP_DELETE: - var response = serviceInvokers.XMLHttp.delete(url, function (responsePayload) { - var response = {}; - response.content = responsePayload["responseContent"]; - response.status = "success"; - return response; - }, - function (responsePayload) { - var response = {}; - response.content = responsePayload; - response.status = "error"; - return response; - }); - return response; - break; - } - } - -}(); +//var invokerRequestWrapper = function () { +// +// var constants = require("/modules/constants.js"); +// var serviceInvokers = require("/modules/backend-service-invoker.js").backendServiceInvoker; +// +// var publicWrappers = []; +// +// publicWrappers.initiate = function (method, url, payload) { +// switch (method) { +// case constants.HTTP_GET: +// var response = serviceInvokers.XMLHttp.get(url, function (responsePayload) { +// var response = {}; +// response.content = responsePayload["responseContent"]; +// response.status = "success"; +// return response; +// }, +// function (responsePayload) { +// var response = {}; +// response.content = responsePayload; +// response.status = "error"; +// return response; +// }); +// return response; +// break; +// case constants.HTTP_POST: +// var response = serviceInvokers.XMLHttp.post(url, payload, function (responsePayload) { +// var response = {}; +// response.content = responsePayload["responseContent"]; +// response.status = "success"; +// return response; +// }, +// function (responsePayload) { +// var response = {}; +// response.content = responsePayload; +// response.status = "error"; +// return response; +// }); +// return response; +// break; +// case constants.HTTP_PUT: +// var response = serviceInvokers.XMLHttp.put(url, payload, function (responsePayload) { +// var response = {}; +// response.content = responsePayload["responseContent"]; +// response.status = "success"; +// return response; +// }, +// function (responsePayload) { +// var response = {}; +// response.content = responsePayload; +// response.status = "error"; +// return response; +// }); +// return response; +// break; +// case constants.HTTP_DELETE: +// var response = serviceInvokers.XMLHttp.delete(url, function (responsePayload) { +// var response = {}; +// response.content = responsePayload["responseContent"]; +// response.status = "success"; +// return response; +// }, +// function (responsePayload) { +// var response = {}; +// response.content = responsePayload; +// response.status = "error"; +// return response; +// }); +// return response; +// break; +// } +// } +// +//}(); From 19275634a1e4518b9f651bf87f75e34e6d1d9a16 Mon Sep 17 00:00:00 2001 From: mharindu Date: Mon, 25 Jul 2016 12:04:30 +0530 Subject: [PATCH 22/24] Fixed webapp name resolving issue --- .../lifecycle/util/AnnotationProcessor.java | 36 ++++++-- .../lifecycle/util/ExtendedAnnotationDB.java | 92 +++++++++++++++++++ .../ExtendedFileProtocolIteratorFactory.java | 34 +++++++ .../util/ExtendedIteratorFactory.java | 54 +++++++++++ 4 files changed, 210 insertions(+), 6 deletions(-) create mode 100644 components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/lifecycle/util/ExtendedAnnotationDB.java create mode 100644 components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/lifecycle/util/ExtendedFileProtocolIteratorFactory.java create mode 100644 components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/lifecycle/util/ExtendedIteratorFactory.java diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/lifecycle/util/AnnotationProcessor.java b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/lifecycle/util/AnnotationProcessor.java index a88fe00e9f..3db6a31551 100644 --- a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/lifecycle/util/AnnotationProcessor.java +++ b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/lifecycle/util/AnnotationProcessor.java @@ -36,11 +36,14 @@ import org.wso2.carbon.apimgt.webapp.publisher.config.PermissionManagementExcept import javax.servlet.ServletContext; import javax.ws.rs.*; +import java.io.File; import java.io.IOException; import java.lang.annotation.Annotation; import java.lang.reflect.InvocationHandler; import java.lang.reflect.Method; import java.lang.reflect.Proxy; +import java.net.MalformedURLException; +import java.net.URI; import java.net.URL; import java.security.AccessController; import java.security.PrivilegedAction; @@ -85,16 +88,13 @@ public class AnnotationProcessor { * @throws IOException */ public Set scanStandardContext(String className) throws IOException { - AnnotationDB db = new AnnotationDB(); + ExtendedAnnotationDB db = new ExtendedAnnotationDB(); db.addIgnoredPackages(PACKAGE_ORG_APACHE); db.addIgnoredPackages(PACKAGE_ORG_CODEHAUS); db.addIgnoredPackages(PACKAGE_ORG_SPRINGFRAMEWORK); - URL[] libPath = WarUrlFinder.findWebInfLibClasspaths(servletContext); - URL classPath = WarUrlFinder.findWebInfClassesPath(servletContext); - URL[] urls = (URL[]) ArrayUtils.add(libPath, libPath.length, classPath); - - db.scanArchives(urls); + URL classPath = findWebInfClassesPath(servletContext); + db.scanArchives(classPath); //Returns a list of classes with given Annotation return db.getAnnotationIndex().get(className); @@ -387,4 +387,28 @@ public class AnnotationProcessor { } } + /** + * Find the URL pointing to "/WEB-INF/classes" This method may not work in conjunction with IteratorFactory + * if your servlet container does not extract the /WEB-INF/classes into a real file-based directory + * + * @param servletContext + * @return null if cannot determin /WEB-INF/classes + */ + public static URL findWebInfClassesPath(ServletContext servletContext) + { + String path = servletContext.getRealPath("/WEB-INF/classes"); + if (path == null) return null; + File fp = new File(path); + if (fp.exists() == false) return null; + try + { + URI uri = fp.toURI(); + return uri.toURL(); + } + catch (MalformedURLException e) + { + throw new RuntimeException(e); + } + } + } diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/lifecycle/util/ExtendedAnnotationDB.java b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/lifecycle/util/ExtendedAnnotationDB.java new file mode 100644 index 0000000000..24fdd738b8 --- /dev/null +++ b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/lifecycle/util/ExtendedAnnotationDB.java @@ -0,0 +1,92 @@ +/* +* Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. +* +* Licensed 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.apimgt.webapp.publisher.lifecycle.util; + +import org.scannotation.AnnotationDB; +import org.scannotation.archiveiterator.Filter; +import org.scannotation.archiveiterator.StreamIterator; + +import java.io.IOException; +import java.io.InputStream; +import java.net.URL; + +public class ExtendedAnnotationDB extends AnnotationDB { + + public ExtendedAnnotationDB() { + super(); + } + + public void scanArchives(URL... urls) throws IOException { + URL[] arr$ = urls; + int len$ = urls.length; + + for(int i$ = 0; i$ < len$; ++i$) { + URL url = arr$[i$]; + Filter filter = new Filter() { + public boolean accepts(String filename) { + if(filename.endsWith(".class")) { + if(filename.startsWith("/") || filename.startsWith("\\")) { + filename = filename.substring(1); + } + + if(!ExtendedAnnotationDB.this.ignoreScan(filename.replace('/', '.'))) { + return true; + } + } + return false; + } + }; + StreamIterator it = ExtendedIteratorFactory.create(url, filter); + + InputStream stream; + while((stream = it.next()) != null) { + this.scanClass(stream); + } + } + + } + + private boolean ignoreScan(String intf) { + String[] arr$; + int len$; + int i$; + String ignored; + if(this.scanPackages != null) { + arr$ = this.scanPackages; + len$ = arr$.length; + + for(i$ = 0; i$ < len$; ++i$) { + ignored = arr$[i$]; + if(intf.startsWith(ignored + ".")) { + return false; + } + } + + return true; + } else { + arr$ = this.ignoredPackages; + len$ = arr$.length; + + for(i$ = 0; i$ < len$; ++i$) { + ignored = arr$[i$]; + if(intf.startsWith(ignored + ".")) { + return true; + } + } + return false; + } + } +} diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/lifecycle/util/ExtendedFileProtocolIteratorFactory.java b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/lifecycle/util/ExtendedFileProtocolIteratorFactory.java new file mode 100644 index 0000000000..34936f61c8 --- /dev/null +++ b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/lifecycle/util/ExtendedFileProtocolIteratorFactory.java @@ -0,0 +1,34 @@ +/* +* Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. +* +* Licensed 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.apimgt.webapp.publisher.lifecycle.util; + +import org.scannotation.archiveiterator.*; + +import java.io.File; +import java.io.IOException; +import java.net.URL; + +public class ExtendedFileProtocolIteratorFactory implements DirectoryIteratorFactory { + + private static final String ENCODING_SCHEME = "UTF-8"; + + @Override + public StreamIterator create(URL url, Filter filter) throws IOException { + File f = new File(java.net.URLDecoder.decode(url.getPath(), ENCODING_SCHEME)); + return f.isDirectory()?new FileIterator(f, filter):new JarIterator(url.openStream(), filter); + } + +} diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/lifecycle/util/ExtendedIteratorFactory.java b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/lifecycle/util/ExtendedIteratorFactory.java new file mode 100644 index 0000000000..a62a58f733 --- /dev/null +++ b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/lifecycle/util/ExtendedIteratorFactory.java @@ -0,0 +1,54 @@ +/* +* Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. +* +* Licensed 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.apimgt.webapp.publisher.lifecycle.util; + +import org.scannotation.archiveiterator.DirectoryIteratorFactory; +import org.scannotation.archiveiterator.Filter; +import org.scannotation.archiveiterator.JarIterator; +import org.scannotation.archiveiterator.StreamIterator; + +import java.io.IOException; +import java.net.URL; +import java.util.concurrent.ConcurrentHashMap; + +public class ExtendedIteratorFactory { + + private static final ConcurrentHashMap registry = new ConcurrentHashMap(); + + public static StreamIterator create(URL url, Filter filter) throws IOException { + String urlString = url.toString(); + if(urlString.endsWith("!/")) { + urlString = urlString.substring(4); + urlString = urlString.substring(0, urlString.length() - 2); + url = new URL(urlString); + } + + if(!urlString.endsWith("/")) { + return new JarIterator(url.openStream(), filter); + } else { + DirectoryIteratorFactory factory = registry.get(url.getProtocol()); + if(factory == null) { + throw new IOException("Unable to scan directory of protocol: " + url.getProtocol()); + } else { + return factory.create(url, filter); + } + } + } + + static { + registry.put("file", new ExtendedFileProtocolIteratorFactory()); + } +} From 7facff4b58210a269b9fc884be7605ca7c8461a7 Mon Sep 17 00:00:00 2001 From: dilanua Date: Mon, 25 Jul 2016 15:28:41 +0530 Subject: [PATCH 23/24] Updating ui init logic --- .../main/resources/jaggeryapps/devicemgt/app/modules/init.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 897a4f0c4f..35c902dbab 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 @@ -31,4 +31,4 @@ var permissions = { '/permission/admin/device-mgt/user': ['ui.execute'], '/permission/admin/manage/api/subscribe': ['ui.execute'] }; -userModule.addRole("internal/devicemgt-user", ["admin"], permissions); +//userModule.addRole("internal/devicemgt-user", ["admin"], permissions); From 87dbb5f9e14dd8b753614d55494ff3232b2b9362 Mon Sep 17 00:00:00 2001 From: dilanua Date: Mon, 25 Jul 2016 15:32:39 +0530 Subject: [PATCH 24/24] Refactoring ui token handling functions --- .../devicemgt/app/modules/api-wrapper-util.js | 73 ++++++++++--------- .../app/modules/invoker-request-wrapper.js | 2 +- 2 files changed, 41 insertions(+), 34 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/api-wrapper-util.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/api-wrapper-util.js index 55d80f5497..1a2f7be25f 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/api-wrapper-util.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/api-wrapper-util.js @@ -1,55 +1,62 @@ /* - * 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. */ var apiWrapperUtil = function () { - var module = {}; - var tokenUtil = require("/app/modules/util.js").util; + // var log = new Log("/app/modules/api-wrapper-util.js"); + + var tokenUtil = require("/app/modules/util.js")["util"]; var constants = require("/app/modules/constants.js"); var devicemgtProps = require("/app/conf/reader/main.js")["conf"]; - var log = new Log("/app/modules/api-wrapper-util.js"); - module.refreshToken = function () { - var tokenPair = session.get(constants.ACCESS_TOKEN_PAIR_IDENTIFIER); - var clientData = session.get(constants.ENCODED_CLIENT_KEYS_IDENTIFIER); - tokenPair = tokenUtil.refreshToken(tokenPair, clientData); - session.put(constants.ACCESS_TOKEN_PAIR_IDENTIFIER, tokenPair); + var publicMethods = {}; + + publicMethods.refreshToken = function () { + var accessTokenPair = session.get(constants["ACCESS_TOKEN_PAIR_IDENTIFIER"]); + // accessTokenPair includes current access token as well as current refresh token + var encodedClientCredentials = session.get(constants["ENCODED_CLIENT_KEYS_IDENTIFIER"]); + accessTokenPair = tokenUtil.refreshToken(accessTokenPair, encodedClientCredentials); + session.put(constants["ACCESS_TOKEN_PAIR_IDENTIFIER"], accessTokenPair); }; - module.setupAccessTokenPair = function (type, properties) { - var tokenPair; - var clientData = tokenUtil.getDyanmicCredentials(properties); - var jwtToken = tokenUtil.getTokenWithJWTGrantType(clientData); - clientData = tokenUtil.getTenantBasedAppCredentials(properties.username, jwtToken); - var encodedClientKeys = tokenUtil.encode(clientData.clientId + ":" + clientData.clientSecret); - session.put(constants.ENCODED_CLIENT_KEYS_IDENTIFIER, encodedClientKeys); - if (type == constants.GRANT_TYPE_PASSWORD) { - var scopes = devicemgtProps.scopes; - var scope = ""; - scopes.forEach(function(entry) { - scope += entry + " "; - }); - tokenPair = - tokenUtil.getTokenWithPasswordGrantType(properties.username, encodeURIComponent(properties.password), - encodedClientKeys, scope); - } else if (type == constants.GRANT_TYPE_SAML) { - tokenPair = tokenUtil. - getTokenWithSAMLGrantType(properties.samlToken, encodedClientKeys, "PRODUCTION"); + + publicMethods.setupAccessTokenPair = function (type, properties) { + var dynamicClientCredentials = tokenUtil.getDyanmicCredentials(properties); + var jwtToken = tokenUtil.getTokenWithJWTGrantType(dynamicClientCredentials); + var tenantBasedClientCredentials = tokenUtil.getTenantBasedAppCredentials(properties["username"], jwtToken); + var encodedTenantBasedClientCredentials = tokenUtil. + encode(tenantBasedClientCredentials["clientId"] + ":" + tenantBasedClientCredentials["clientSecret"]); + + session.put(constants["ENCODED_CLIENT_KEYS_IDENTIFIER"], encodedTenantBasedClientCredentials); + + var accessTokenPair; + // accessTokenPair will include current access token as well as current refresh token + if (type == constants["GRANT_TYPE_PASSWORD"]) { + var arrayOfScopes = devicemgtProps["scopes"]; + var stringOfScopes = ""; + arrayOfScopes.forEach(function (entry) { stringOfScopes += entry + " "; }); + accessTokenPair = tokenUtil.getTokenWithPasswordGrantType(properties["username"], + encodeURIComponent(properties["password"]), encodedTenantBasedClientCredentials, stringOfScopes); + } else if (type == constants["GRANT_TYPE_SAML"]) { + accessTokenPair = tokenUtil.getTokenWithSAMLGrantType(properties["samlToken"], + encodedTenantBasedClientCredentials, "PRODUCTION"); } - session.put(constants.ACCESS_TOKEN_PAIR_IDENTIFIER, tokenPair); + + session.put(constants["ACCESS_TOKEN_PAIR_IDENTIFIER"], accessTokenPair); }; - return module; + + 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/modules/invoker-request-wrapper.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/invoker-request-wrapper.js index b4ccc62dc1..d191b1868d 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/invoker-request-wrapper.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/invoker-request-wrapper.js @@ -17,7 +17,7 @@ */ /* - @Deprecated + @Deprecated - new */ /**