From ddb8f4e9b3662e79206a4e895976a2c96ab38cdb Mon Sep 17 00:00:00 2001 From: sinthuja Date: Thu, 31 Aug 2017 16:53:57 +0530 Subject: [PATCH 1/3] Fixing https://github.com/wso2/product-iots/issues/353. --- .../mgt/jaxrs/service/impl/RoleManagementServiceImpl.java | 4 ++++ .../mgt/jaxrs/service/impl/UserManagementServiceImpl.java | 4 +++- .../java/org/wso2/carbon/device/mgt/jaxrs/util/Constants.java | 1 + 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/RoleManagementServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/RoleManagementServiceImpl.java index d396237df4..978b449885 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/RoleManagementServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/RoleManagementServiceImpl.java @@ -30,6 +30,7 @@ import org.wso2.carbon.device.mgt.jaxrs.beans.RoleList; import org.wso2.carbon.device.mgt.jaxrs.service.api.RoleManagementService; import org.wso2.carbon.device.mgt.jaxrs.service.impl.util.FilteringUtil; import org.wso2.carbon.device.mgt.jaxrs.service.impl.util.RequestValidationUtil; +import org.wso2.carbon.device.mgt.jaxrs.util.Constants; import org.wso2.carbon.device.mgt.jaxrs.util.DeviceMgtAPIUtils; import org.wso2.carbon.device.mgt.jaxrs.util.SetReferenceTransformer; import org.wso2.carbon.registry.api.Registry; @@ -68,6 +69,9 @@ public class RoleManagementServiceImpl implements RoleManagementService { @HeaderParam("If-Modified-Since") String ifModifiedSince, @QueryParam("offset") int offset, @QueryParam("limit") int limit) { RequestValidationUtil.validatePaginationParameters(offset, limit); + if (limit == 0){ + limit = Constants.DEFAULT_PAGE_LIMIT; + } List filteredRoles; RoleList targetRoles = new RoleList(); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/UserManagementServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/UserManagementServiceImpl.java index e8272f6f88..75e3857725 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/UserManagementServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/UserManagementServiceImpl.java @@ -363,7 +363,9 @@ public class UserManagementServiceImpl implements UserManagementService { } RequestValidationUtil.validatePaginationParameters(offset, limit); - + if (limit == 0){ + limit = Constants.DEFAULT_PAGE_LIMIT; + } List userList, offsetList; String appliedFilter = ((filter == null) || filter.isEmpty() ? "*" : filter + "*"); // to get whole set of users, appliedLimit is set to -1 diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/util/Constants.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/util/Constants.java index 55dd398e18..5afbf58626 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/util/Constants.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/util/Constants.java @@ -30,6 +30,7 @@ public class Constants { public static final String DEFAULT_STREAM_VERSION = "1.0.0"; public static final String SCOPE = "scope"; public static final String JDBC_USERSTOREMANAGER = "org.wso2.carbon.user.core.jdbc.JDBCUserStoreManager"; + public static final int DEFAULT_PAGE_LIMIT = 10; public final class ErrorMessages { From 5996e6841b84e4d43ed442591fb5055e6344bdc2 Mon Sep 17 00:00:00 2001 From: Harshan Liyanage Date: Thu, 31 Aug 2017 16:56:53 +0530 Subject: [PATCH 2/3] Added null check to resolve wso2/product-iots#1367 --- .../device/mgt/core/DeviceManagementPluginRepository.java | 4 +++- 1 file changed, 3 insertions(+), 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 7a3b487121..4c06d507ca 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 @@ -350,7 +350,9 @@ public class DeviceManagementPluginRepository implements DeviceManagerStartupLis if (deviceStatusTaskPluginConfig != null && deviceStatusTaskPluginConfig.isRequireStatusMonitoring()) { try { DeviceManagementDataHolder.getInstance().removeDeviceStatusTaskPluginConfig(deviceType); - deviceStatusTaskManagerService.stopTask(deviceType, deviceStatusTaskPluginConfig); + if (deviceStatusTaskManagerService != null) { + deviceStatusTaskManagerService.stopTask(deviceType, deviceStatusTaskPluginConfig); + } } catch (DeviceStatusTaskException e) { throw new DeviceManagementException("Error occurred while stopping Device Status task service for '" + deviceManagementService.getType() + "'", e); From b87d3898f699a923254a61c701709f5258faf8e9 Mon Sep 17 00:00:00 2001 From: Harshan Liyanage Date: Thu, 31 Aug 2017 16:59:43 +0530 Subject: [PATCH 3/3] Fixes for wso2/product-iots#1285 --- .../service/DeviceManagementProviderServiceImpl.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java index a4afef2f48..d5f8707d4e 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java @@ -2333,8 +2333,14 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv DeviceManagementDAOFactory.openConnection(); info = deviceInfoDAO.getDeviceInformation(device.getId()); DeviceLocation location = deviceInfoDAO.getDeviceLocation(device.getId()); - if (info != null) { - info.setLocation(location); + if (location != null) { + //There are some cases where the device-info is not updated properly. Hence returning a null value. + if (info != null) { + info.setLocation(location); + } else { + info = new DeviceInfo(); + info.setLocation(location); + } } } catch (DeviceDetailsMgtDAOException e) { String msg = "Error occurred while retrieving advance info of '" + device.getType() +