From 18b1f7830dc1e901f3a2247c83d3d3b24a35fdf9 Mon Sep 17 00:00:00 2001 From: lasantha Date: Wed, 28 Feb 2018 19:44:39 +0530 Subject: [PATCH 1/4] Add debug logs for Device Management Plugin Repository It is important to have debugged logs when finding the root causes for some issues.Hence added those to the Device Management Plugin Repository. --- .../DeviceManagementPluginRepository.java | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagementPluginRepository.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagementPluginRepository.java index 93bee26a82..c0c4fe8535 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagementPluginRepository.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagementPluginRepository.java @@ -23,6 +23,7 @@ import org.apache.commons.logging.LogFactory; import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.device.mgt.common.DeviceManagementException; import org.wso2.carbon.device.mgt.common.DeviceStatusTaskPluginConfig; +import org.wso2.carbon.device.mgt.common.InvalidConfigurationException; import org.wso2.carbon.device.mgt.common.OperationMonitoringTaskConfig; import org.wso2.carbon.device.mgt.common.ProvisioningConfig; import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManager; @@ -71,6 +72,9 @@ public class DeviceManagementPluginRepository implements DeviceManagerStartupLis String deviceType = provider.getType(); ProvisioningConfig provisioningConfig = provider.getProvisioningConfig(); String tenantDomain = provisioningConfig.getProviderTenantDomain(); + if (log.isDebugEnabled()) { + log.debug(deviceType + " device type is added for tenant : " + tenantDomain); + } DeviceManagementConfig deviceManagementConfig = DeviceConfigurationManager.getInstance().getDeviceManagementConfig(); boolean isSharedWithAllTenants = provisioningConfig.isSharedWithAllTenants(); int tenantId = DeviceManagerUtil.getTenantId(tenantDomain); @@ -125,6 +129,9 @@ public class DeviceManagementPluginRepository implements DeviceManagerStartupLis public void removeDeviceManagementProvider(DeviceManagementService provider) throws DeviceManagementException { String deviceTypeName = provider.getType(); + if (log.isDebugEnabled()) { + log.debug(deviceTypeName + " device type is removed."); + } DeviceManagementConfig deviceManagementConfig = DeviceConfigurationManager.getInstance() .getDeviceManagementConfig(); DeviceTypeServiceIdentifier deviceTypeIdentifier; @@ -152,6 +159,15 @@ public class DeviceManagementPluginRepository implements DeviceManagerStartupLis private void unregisterPushNotificationStrategy(DeviceTypeServiceIdentifier deviceTypeIdentifier) { OperationManager operationManager = operationManagerRepository.getOperationManager( deviceTypeIdentifier); + if (log.isDebugEnabled()) { + log.debug(deviceTypeIdentifier.getDeviceType() + " device type management service is " + + "retrieved for tenant id: " + deviceTypeIdentifier.getTenantId()); + + for (Map.Entry entry : providers.entrySet()) { + log.debug("Device Type : " + entry.getKey().getDeviceType() + " Tenant Id : " + + entry.getKey().getTenantId()); + } + } if (operationManager != null) { NotificationStrategy notificationStrategy = operationManager.getNotificationStrategy(); if (notificationStrategy != null) { @@ -165,6 +181,14 @@ public class DeviceManagementPluginRepository implements DeviceManagerStartupLis //Priority need to be given to the tenant before public. DeviceTypeServiceIdentifier deviceTypeIdentifier = new DeviceTypeServiceIdentifier(type, tenantId); DeviceManagementServiceHolder provider = providers.get(deviceTypeIdentifier); + if (log.isDebugEnabled()) { + log.debug(type + " device type management service is retrieved for tenant id: " + tenantId); + + for (Map.Entry entry : providers.entrySet()) { + log.debug("Device Type : " + entry.getKey().getDeviceType() + " Tenant Id : " + + entry.getKey().getTenantId()); + } + } if (provider == null) { deviceTypeIdentifier = new DeviceTypeServiceIdentifier(type); provider = providers.get(deviceTypeIdentifier); @@ -310,6 +334,9 @@ public class DeviceManagementPluginRepository implements DeviceManagerStartupLis DeviceTaskManagerService deviceTaskManagerService = DeviceManagementDataHolder.getInstance(). getDeviceTaskManagerService(); DeviceStatusTaskPluginConfig deviceStatusTaskPluginConfig = deviceManagementService.getDeviceStatusTaskPluginConfig(); + if (log.isDebugEnabled()) { + log.debug(deviceType + " device type status monitoring task is registered."); + } if (deviceStatusTaskPluginConfig != null && deviceStatusTaskPluginConfig.isRequireStatusMonitoring()) { if (deviceTaskManagerService == null) { DeviceManagementDataHolder.getInstance().addDeviceStatusTaskPluginConfig(deviceType, @@ -330,6 +357,9 @@ public class DeviceManagementPluginRepository implements DeviceManagerStartupLis DeviceStatusTaskManagerService deviceStatusTaskManagerService = DeviceManagementDataHolder.getInstance(). getDeviceStatusTaskManagerService(); DeviceStatusTaskPluginConfig deviceStatusTaskPluginConfig = deviceManagementService.getDeviceStatusTaskPluginConfig(); + if (log.isDebugEnabled()) { + log.debug(deviceType + " device type status monitoring task is unregistered."); + } if (deviceStatusTaskPluginConfig != null && deviceStatusTaskPluginConfig.isRequireStatusMonitoring()) { try { DeviceManagementDataHolder.getInstance().removeDeviceStatusTaskPluginConfig(deviceType); @@ -346,6 +376,9 @@ public class DeviceManagementPluginRepository implements DeviceManagerStartupLis public OperationManager getOperationManager(String deviceType, int tenantId) { //Priority need to be given to the tenant before public. DeviceTypeServiceIdentifier deviceTypeIdentifier = new DeviceTypeServiceIdentifier(deviceType, tenantId); + if (log.isDebugEnabled()) { + log.debug(deviceType + " device type operation manager is retrieved for tenant: ." + tenantId); + } if (getDeviceManagementService(deviceType, tenantId) == null) { return null; } From 0ce103e1ad33617f640d5c03b57477f2b5adb4db Mon Sep 17 00:00:00 2001 From: lasantha Date: Wed, 28 Feb 2018 19:53:28 +0530 Subject: [PATCH 2/4] Format the source code In order to equivalent with WSO2 coding standards modified the source code --- .../jaggeryapps/devicemgt/api/device-api.jag | 4 ++-- .../public/js/operation-bar.js | 11 +++++------ 2 files changed, 7 insertions(+), 8 deletions(-) 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 84a9b98bdc..a214f536e9 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 @@ -74,13 +74,13 @@ if (!user) { } else { result = 400; } - }else if (uriMatcher.match("/{context}/api/devices/sketch/generate_link")) { + } else if (uriMatcher.match("/{context}/api/devices/sketch/generate_link")) { if (!request.getContent()){ log.error("Request Payload Is Empty"); // HTTP status code 400 refers to - Bad request. result = 400; - }else{ + } else{ deviceType = request.getContent()["deviceType"]; queryString = "?deviceName=" + request.getContent()["deviceName"] +"&deviceType="+ request.getContent()["deviceType"]+"&sketchType="+request.getContent()["sketchType"]; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.operation-bar/public/js/operation-bar.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.operation-bar/public/js/operation-bar.js index a892a32ff8..8d1a9475be 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.operation-bar/public/js/operation-bar.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.operation-bar/public/js/operation-bar.js @@ -52,22 +52,21 @@ function submitForm(formId) { uriencodedQueryStr += prefix + input.attr("id") + "=" + input.val(); } else if (input.data("param-type") == "form") { var prefix = (uriencodedFormStr == "") ? "" : "&"; - if (input.attr("type") == "checkbox" || input.attr("type") == "radio"){ - - if (isItemSelected == undefined){ + if (input.attr("type") == "checkbox" || input.attr("type") == "radio") { + if (isItemSelected == undefined) { isItemSelected = false; } - if (input.is(':checked')){ + if (input.is(':checked')) { isItemSelected = true; uriencodedFormStr += prefix + input.attr("name") + "=" + input.val(); } - }else{ + } else { uriencodedFormStr += prefix + input.attr("id") + "=" + input.val(); } } }); - if (isItemSelected === false){ + if (isItemSelected === false) { title.html("Please Select One Option"); statusIcon.attr("class", defaultStatusClasses + " fw-error"); $(modalPopupContent).html(content.html()); From 8df53899d66d6e1b79e726cd1d0ec2268105dfb3 Mon Sep 17 00:00:00 2001 From: lasantha Date: Wed, 28 Feb 2018 19:56:18 +0530 Subject: [PATCH 3/4] remove unnecessary imports --- .../carbon/device/mgt/core/DeviceManagementPluginRepository.java | 1 - 1 file changed, 1 deletion(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagementPluginRepository.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagementPluginRepository.java index c0c4fe8535..69559c15b1 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagementPluginRepository.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagementPluginRepository.java @@ -23,7 +23,6 @@ import org.apache.commons.logging.LogFactory; import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.device.mgt.common.DeviceManagementException; import org.wso2.carbon.device.mgt.common.DeviceStatusTaskPluginConfig; -import org.wso2.carbon.device.mgt.common.InvalidConfigurationException; import org.wso2.carbon.device.mgt.common.OperationMonitoringTaskConfig; import org.wso2.carbon.device.mgt.common.ProvisioningConfig; import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManager; From fc982eab674dff389abc3c7ad852158d3abf4ebb Mon Sep 17 00:00:00 2001 From: lasantha Date: Wed, 28 Feb 2018 19:58:40 +0530 Subject: [PATCH 4/4] remove unnecessary empty lines --- .../device/mgt/core/DeviceManagementPluginRepository.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagementPluginRepository.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagementPluginRepository.java index 69559c15b1..63508c3f06 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagementPluginRepository.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagementPluginRepository.java @@ -161,7 +161,6 @@ public class DeviceManagementPluginRepository implements DeviceManagerStartupLis if (log.isDebugEnabled()) { log.debug(deviceTypeIdentifier.getDeviceType() + " device type management service is " + "retrieved for tenant id: " + deviceTypeIdentifier.getTenantId()); - for (Map.Entry entry : providers.entrySet()) { log.debug("Device Type : " + entry.getKey().getDeviceType() + " Tenant Id : " + entry.getKey().getTenantId()); @@ -182,7 +181,6 @@ public class DeviceManagementPluginRepository implements DeviceManagerStartupLis DeviceManagementServiceHolder provider = providers.get(deviceTypeIdentifier); if (log.isDebugEnabled()) { log.debug(type + " device type management service is retrieved for tenant id: " + tenantId); - for (Map.Entry entry : providers.entrySet()) { log.debug("Device Type : " + entry.getKey().getDeviceType() + " Tenant Id : " + entry.getKey().getTenantId());