From 8bb0b4c8551a418a16bd69ce453f76bf72a3fb54 Mon Sep 17 00:00:00 2001 From: prathabanKavin Date: Thu, 18 Jan 2024 20:57:11 +0530 Subject: [PATCH] Remove device list and store device identifiers on custom logs --- .../impl/GroupManagementServiceImpl.java | 29 ++++++++++--------- .../logger/GroupMgtLogContext.java | 18 ++++++------ .../logger/util/MDCContextUtil.java | 4 +-- 3 files changed, 26 insertions(+), 25 deletions(-) diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/service/impl/GroupManagementServiceImpl.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/service/impl/GroupManagementServiceImpl.java index 6a7350a977..ff770ed778 100644 --- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/service/impl/GroupManagementServiceImpl.java +++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/service/impl/GroupManagementServiceImpl.java @@ -181,8 +181,6 @@ public class GroupManagementServiceImpl implements GroupManagementService { group.setStatus(DeviceGroupConstants.GroupStatus.ACTIVE); try { DeviceMgtAPIUtils.getGroupManagementProviderService().createGroup(group, DEFAULT_ADMIN_ROLE, DEFAULT_ADMIN_PERMISSIONS); - int deviceCount = DeviceMgtAPIUtils.getGroupManagementProviderService().getDeviceCount(group.getGroupId()); - String stringDevices = new Gson().toJson(DeviceMgtAPIUtils.getGroupManagementProviderService().getAllDevicesOfGroup(group.getName(), false)); log.info( "Group " + group.getName() + " created", groupMgtContextBuilder @@ -190,8 +188,6 @@ public class GroupManagementServiceImpl implements GroupManagementService { .setGroupId(String.valueOf(group.getGroupId())) .setName(group.getName()) .setOwner(group.getOwner()) - .setDeviceCount(String.valueOf(deviceCount)) - .setDevices(stringDevices) .setTenantID(tenantId) .setTenantDomain(tenantDomain) .setUserName(owner) @@ -255,7 +251,12 @@ public class GroupManagementServiceImpl implements GroupManagementService { try { DeviceMgtAPIUtils.getGroupManagementProviderService().updateGroup(deviceGroup, groupId); int deviceCount = DeviceMgtAPIUtils.getGroupManagementProviderService().getDeviceCount(groupId); - String stringDevices = new Gson().toJson(DeviceMgtAPIUtils.getGroupManagementProviderService().getAllDevicesOfGroup(deviceGroup.getName(), false)); + List devices = DeviceMgtAPIUtils.getGroupManagementProviderService().getAllDevicesOfGroup(deviceGroup.getName(), false); + List deviceIdentifiers = new ArrayList<>(); + for(Device device : devices) { + deviceIdentifiers.add(device.getDeviceIdentifier()); + } + String stringDeviceIdentifiers = new Gson().toJson(deviceIdentifiers); log.info( "Group " + deviceGroup.getName() + " updated", groupMgtContextBuilder @@ -264,7 +265,7 @@ public class GroupManagementServiceImpl implements GroupManagementService { .setName(deviceGroup.getName()) .setOwner(deviceGroup.getOwner()) .setDeviceCount(String.valueOf(deviceCount)) - .setDevices(stringDevices) + .setDeviceIdentifiers(stringDeviceIdentifiers) .setTenantID(tenantId) .setTenantDomain(tenantDomain) .setUserName(username) @@ -293,11 +294,13 @@ public class GroupManagementServiceImpl implements GroupManagementService { String tenantDomain = String.valueOf(CarbonContext.getThreadLocalCarbonContext().getTenantDomain()); String username = CarbonContext.getThreadLocalCarbonContext().getUsername(); if (DeviceMgtAPIUtils.getGroupManagementProviderService().deleteGroup(groupId, isDeleteChildren)) { + int deviceCount = DeviceMgtAPIUtils.getGroupManagementProviderService().getDeviceCount(groupId); log.info( "Group with group id " + groupId + " deleted", groupMgtContextBuilder .setActionTag("DELETE_GROUP") .setGroupId(String.valueOf(groupId)) + .setDeviceCount(String.valueOf(deviceCount)) .setTenantID(tenantId) .setTenantDomain(tenantDomain) .setUserName(username) @@ -394,10 +397,8 @@ public class GroupManagementServiceImpl implements GroupManagementService { DeviceMgtAPIUtils.getGroupManagementProviderService().addDevices(groupId, deviceIdentifiers); PolicyAdministratorPoint pap = DeviceMgtAPIUtils.getPolicyManagementService().getPAP(); DeviceManagementProviderService dms = DeviceMgtAPIUtils.getDeviceManagementService(); - List devices = new ArrayList<>(); for(DeviceIdentifier deviceIdentifier : deviceIdentifiers) { Device device = dms.getDevice(deviceIdentifier, false); - devices.add(device); if(!device.getEnrolmentInfo().getStatus().equals(EnrolmentInfo.Status.REMOVED)) { pap.removePolicyUsed(deviceIdentifier); DeviceMgtAPIUtils.getPolicyManagementService().getEffectivePolicy(deviceIdentifier); @@ -405,14 +406,18 @@ public class GroupManagementServiceImpl implements GroupManagementService { } pap.publishChanges(); int deviceCount = DeviceMgtAPIUtils.getGroupManagementProviderService().getDeviceCount(groupId); - String stringDevices = new Gson().toJson(devices); + List deviceIdentifiersList = new ArrayList<>(); + for(DeviceIdentifier deviceIdentifier : deviceIdentifiers) { + deviceIdentifiersList.add(deviceIdentifier.getId()); + } + String stringDeviceIdentifiers = new Gson().toJson(deviceIdentifiersList); log.info( "Devices added for group id " + groupId, groupMgtContextBuilder .setActionTag("ADD_DEVICES") .setGroupId(String.valueOf(groupId)) .setDeviceCount(String.valueOf(deviceCount)) - .setDevices(stringDevices) + .setDeviceIdentifiers(stringDeviceIdentifiers) .setTenantID(tenantId) .setTenantDomain(tenantDomain) .setUserName(username) @@ -553,8 +558,6 @@ public class GroupManagementServiceImpl implements GroupManagementService { PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername().isEmpty()); if (group != null) { DeviceMgtAPIUtils.getGroupManagementProviderService().manageGroupSharing(group.getGroupId(), groups.getUserRoles()); - int deviceCount = DeviceMgtAPIUtils.getGroupManagementProviderService().getDeviceCount(group.getGroupId()); - String stringDevices = new Gson().toJson(DeviceMgtAPIUtils.getGroupManagementProviderService().getAllDevicesOfGroup(group.getName(), false)); log.info( "Group " + group.getName() + " created", groupMgtContextBuilder @@ -562,8 +565,6 @@ public class GroupManagementServiceImpl implements GroupManagementService { .setGroupId(String.valueOf(group.getGroupId())) .setName(group.getName()) .setOwner(group.getOwner()) - .setDeviceCount(String.valueOf(deviceCount)) - .setDevices(stringDevices) .setTenantID(tenantId) .setTenantDomain(tenantDomain) .setUserName(username) diff --git a/components/logger/io.entgra.device.mgt.core.notification.logger/src/main/java/io/entgra/device/mgt/core/notification/logger/GroupMgtLogContext.java b/components/logger/io.entgra.device.mgt.core.notification.logger/src/main/java/io/entgra/device/mgt/core/notification/logger/GroupMgtLogContext.java index 3eeb4f66bc..113f22fb2c 100644 --- a/components/logger/io.entgra.device.mgt.core.notification.logger/src/main/java/io/entgra/device/mgt/core/notification/logger/GroupMgtLogContext.java +++ b/components/logger/io.entgra.device.mgt.core.notification.logger/src/main/java/io/entgra/device/mgt/core/notification/logger/GroupMgtLogContext.java @@ -26,7 +26,7 @@ public class GroupMgtLogContext extends LogContext { private final String owner; private final String actionTag; private final String deviceCount; - private final String devices; + private final String deviceIdentifiers; private final String userName; private final String tenantID; private final String tenantDomain; @@ -37,7 +37,7 @@ public class GroupMgtLogContext extends LogContext { this.owner = builder.owner; this.actionTag = builder.actionTag; this.deviceCount = builder.deviceCount; - this.devices = builder.devices; + this.deviceIdentifiers = builder.deviceIdentifiers; this.userName = builder.userName; this.tenantID = builder.tenantID; this.tenantDomain = builder.tenantDomain; @@ -63,8 +63,8 @@ public class GroupMgtLogContext extends LogContext { return deviceCount; } - public String getDevices() { - return devices; + public String getDeviceIdentifiers() { + return deviceIdentifiers; } public String getUserName() { @@ -85,7 +85,7 @@ public class GroupMgtLogContext extends LogContext { private String owner; private String actionTag; private String deviceCount; - private String devices; + private String deviceIdentifiers; private String userName; private String tenantID; private String tenantDomain; @@ -138,12 +138,12 @@ public class GroupMgtLogContext extends LogContext { return this; } - public String getDevices() { - return devices; + public String getDeviceIdentifiers() { + return deviceIdentifiers; } - public Builder setDevices(String devices) { - this.devices = devices; + public Builder setDeviceIdentifiers(String deviceIdentifiers) { + this.deviceIdentifiers = deviceIdentifiers; return this; } diff --git a/components/logger/io.entgra.device.mgt.core.notification.logger/src/main/java/io/entgra/device/mgt/core/notification/logger/util/MDCContextUtil.java b/components/logger/io.entgra.device.mgt.core.notification.logger/src/main/java/io/entgra/device/mgt/core/notification/logger/util/MDCContextUtil.java index 1c9afa6948..713ac3cc2f 100644 --- a/components/logger/io.entgra.device.mgt.core.notification.logger/src/main/java/io/entgra/device/mgt/core/notification/logger/util/MDCContextUtil.java +++ b/components/logger/io.entgra.device.mgt.core.notification.logger/src/main/java/io/entgra/device/mgt/core/notification/logger/util/MDCContextUtil.java @@ -231,8 +231,8 @@ public final class MDCContextUtil { if (mdcContext.getDeviceCount() != null) { MDC.put("DeviceCount", mdcContext.getDeviceCount()); } - if (mdcContext.getDevices() != null) { - MDC.put("Devices", mdcContext.getDevices()); + if (mdcContext.getDeviceIdentifiers() != null) { + MDC.put("DeviceIdentifiers", mdcContext.getDeviceIdentifiers()); } if (mdcContext.getUserName() != null) { MDC.put("UserName", mdcContext.getUserName()); -- 2.36.3