Remove device list and store device identifiers on custom logs

rm-10583
Lasantha Dharmakeerthi 10 months ago
commit d62e671a5c

@ -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<Device> devices = DeviceMgtAPIUtils.getGroupManagementProviderService().getAllDevicesOfGroup(deviceGroup.getName(), false);
List<String> 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<Device> 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<String> 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)

@ -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;
}

@ -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());

Loading…
Cancel
Save