From c8fe5b45b7af2b4e24d3926663f5dea6306cb960 Mon Sep 17 00:00:00 2001 From: charitha Date: Sun, 29 Mar 2020 21:46:22 +0530 Subject: [PATCH] Performance improvements --- ...eviceTypeOperationAdapterSubscription.java | 9 ++++++-- .../DeviceManagementProviderServiceMock.java | 3 +-- .../NotificationManagementServiceMock.java | 6 ++++++ .../mocks/PolicyManagerServiceMock.java | 21 +++++++++++++++++++ 4 files changed, 35 insertions(+), 4 deletions(-) diff --git a/components/extensions/pull-notification-listeners/org.wso2.carbon.device.mgt.mqtt.notification.listener/src/main/java/org/wso2/carbon/device/mgt/mqtt/notification/listener/DeviceTypeOperationAdapterSubscription.java b/components/extensions/pull-notification-listeners/org.wso2.carbon.device.mgt.mqtt.notification.listener/src/main/java/org/wso2/carbon/device/mgt/mqtt/notification/listener/DeviceTypeOperationAdapterSubscription.java index f59d96415e..0b23371c42 100644 --- a/components/extensions/pull-notification-listeners/org.wso2.carbon.device.mgt.mqtt.notification.listener/src/main/java/org/wso2/carbon/device/mgt/mqtt/notification/listener/DeviceTypeOperationAdapterSubscription.java +++ b/components/extensions/pull-notification-listeners/org.wso2.carbon.device.mgt.mqtt.notification.listener/src/main/java/org/wso2/carbon/device/mgt/mqtt/notification/listener/DeviceTypeOperationAdapterSubscription.java @@ -21,6 +21,8 @@ package org.wso2.carbon.device.mgt.mqtt.notification.listener; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.wso2.carbon.context.PrivilegedCarbonContext; +import org.wso2.carbon.device.mgt.common.Device; +import org.wso2.carbon.device.mgt.common.exceptions.DeviceManagementException; import org.wso2.carbon.device.mgt.common.pull.notification.PullNotificationExecutionFailedException; import org.wso2.carbon.device.mgt.mqtt.notification.listener.internal.MqttNotificationDataHolder; import org.wso2.carbon.event.input.adapter.core.InputEventAdapterSubscription; @@ -48,11 +50,14 @@ public class DeviceTypeOperationAdapterSubscription implements InputEventAdapter PrivilegedCarbonContext.getThreadLocalCarbonContext().setUsername(PrivilegedCarbonContext. getThreadLocalCarbonContext().getUserRealm().getRealmConfiguration().getAdminUserName()); deviceType = notificationMessage.getDeviceIdentifier().getType(); + Device device = MqttNotificationDataHolder.getInstance().getDeviceManagementProviderService() + .getDevice(notificationMessage.getDeviceIdentifier(), false); MqttNotificationDataHolder.getInstance().getDeviceManagementProviderService(). - notifyPullNotificationSubscriber(notificationMessage.getDeviceIdentifier(), - notificationMessage.getOperation()); + notifyPullNotificationSubscriber(device, notificationMessage.getOperation()); } catch (UserStoreException e) { log.error("Failed to retrieve tenant username", e); + } catch (DeviceManagementException e) { + log.error("Failed to retrieve device " + notificationMessage.getDeviceIdentifier(), e); } catch (PullNotificationExecutionFailedException e) { log.error("Failed to execute device type pull notification subscriber execution for device type" + deviceType, e); diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/test/java/org/wso2/carbon/mdm/services/android/mocks/DeviceManagementProviderServiceMock.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/test/java/org/wso2/carbon/mdm/services/android/mocks/DeviceManagementProviderServiceMock.java index 85daa33c20..e7d5901231 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/test/java/org/wso2/carbon/mdm/services/android/mocks/DeviceManagementProviderServiceMock.java +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/test/java/org/wso2/carbon/mdm/services/android/mocks/DeviceManagementProviderServiceMock.java @@ -625,9 +625,8 @@ public class DeviceManagementProviderServiceMock implements DeviceManagementProv } @Override - public void notifyPullNotificationSubscriber(DeviceIdentifier deviceIdentifier, Operation operation) + public void notifyPullNotificationSubscriber(Device device, Operation operation) throws PullNotificationExecutionFailedException { - } @Override diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/test/java/org/wso2/carbon/mdm/services/android/mocks/NotificationManagementServiceMock.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/test/java/org/wso2/carbon/mdm/services/android/mocks/NotificationManagementServiceMock.java index 4fd989de6d..bb5418b21d 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/test/java/org/wso2/carbon/mdm/services/android/mocks/NotificationManagementServiceMock.java +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/test/java/org/wso2/carbon/mdm/services/android/mocks/NotificationManagementServiceMock.java @@ -18,6 +18,7 @@ package org.wso2.carbon.mdm.services.android.mocks; +import org.wso2.carbon.device.mgt.common.Device; import org.wso2.carbon.device.mgt.common.DeviceIdentifier; import org.wso2.carbon.device.mgt.common.PaginationRequest; import org.wso2.carbon.device.mgt.common.PaginationResult; @@ -34,6 +35,11 @@ public class NotificationManagementServiceMock implements NotificationManagement return false; } + @Override + public boolean addNotification(Device device, Notification notification) throws NotificationManagementException { + return false; + } + @Override public boolean updateNotification(Notification notification) throws NotificationManagementException { return false; diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/test/java/org/wso2/carbon/mdm/services/android/mocks/PolicyManagerServiceMock.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/test/java/org/wso2/carbon/mdm/services/android/mocks/PolicyManagerServiceMock.java index 537b2e8743..b15f50a02c 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/test/java/org/wso2/carbon/mdm/services/android/mocks/PolicyManagerServiceMock.java +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/test/java/org/wso2/carbon/mdm/services/android/mocks/PolicyManagerServiceMock.java @@ -17,6 +17,7 @@ */ package org.wso2.carbon.mdm.services.android.mocks; +import org.wso2.carbon.device.mgt.common.Device; import org.wso2.carbon.device.mgt.common.DeviceIdentifier; import org.wso2.carbon.device.mgt.common.Feature; import org.wso2.carbon.device.mgt.common.PaginationRequest; @@ -121,22 +122,42 @@ public class PolicyManagerServiceMock implements PolicyManagerService { return null; } + @Override + public Policy getAppliedPolicyToDevice(Device device) throws PolicyManagementException { + return null; + } + @Override public List checkPolicyCompliance(DeviceIdentifier deviceIdentifier, Object o) throws PolicyComplianceException { return null; } + @Override + public List checkPolicyCompliance(Device device, Object o) throws PolicyComplianceException { + return null; + } + @Override public boolean checkCompliance(DeviceIdentifier deviceIdentifier, Object o) throws PolicyComplianceException { return false; } + @Override + public boolean checkCompliance(Device device, Object o) throws PolicyComplianceException { + return false; + } + @Override public NonComplianceData getDeviceCompliance(DeviceIdentifier deviceIdentifier) throws PolicyComplianceException { return null; } + @Override + public NonComplianceData getDeviceCompliance(Device device) throws PolicyComplianceException { + return null; + } + @Override public boolean isCompliant(DeviceIdentifier deviceIdentifier) throws PolicyComplianceException { return false;