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); group.setStatus(DeviceGroupConstants.GroupStatus.ACTIVE);
try { try {
DeviceMgtAPIUtils.getGroupManagementProviderService().createGroup(group, DEFAULT_ADMIN_ROLE, DEFAULT_ADMIN_PERMISSIONS); 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( log.info(
"Group " + group.getName() + " created", "Group " + group.getName() + " created",
groupMgtContextBuilder groupMgtContextBuilder
@ -190,8 +188,6 @@ public class GroupManagementServiceImpl implements GroupManagementService {
.setGroupId(String.valueOf(group.getGroupId())) .setGroupId(String.valueOf(group.getGroupId()))
.setName(group.getName()) .setName(group.getName())
.setOwner(group.getOwner()) .setOwner(group.getOwner())
.setDeviceCount(String.valueOf(deviceCount))
.setDevices(stringDevices)
.setTenantID(tenantId) .setTenantID(tenantId)
.setTenantDomain(tenantDomain) .setTenantDomain(tenantDomain)
.setUserName(owner) .setUserName(owner)
@ -255,7 +251,12 @@ public class GroupManagementServiceImpl implements GroupManagementService {
try { try {
DeviceMgtAPIUtils.getGroupManagementProviderService().updateGroup(deviceGroup, groupId); DeviceMgtAPIUtils.getGroupManagementProviderService().updateGroup(deviceGroup, groupId);
int deviceCount = DeviceMgtAPIUtils.getGroupManagementProviderService().getDeviceCount(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( log.info(
"Group " + deviceGroup.getName() + " updated", "Group " + deviceGroup.getName() + " updated",
groupMgtContextBuilder groupMgtContextBuilder
@ -264,7 +265,7 @@ public class GroupManagementServiceImpl implements GroupManagementService {
.setName(deviceGroup.getName()) .setName(deviceGroup.getName())
.setOwner(deviceGroup.getOwner()) .setOwner(deviceGroup.getOwner())
.setDeviceCount(String.valueOf(deviceCount)) .setDeviceCount(String.valueOf(deviceCount))
.setDevices(stringDevices) .setDeviceIdentifiers(stringDeviceIdentifiers)
.setTenantID(tenantId) .setTenantID(tenantId)
.setTenantDomain(tenantDomain) .setTenantDomain(tenantDomain)
.setUserName(username) .setUserName(username)
@ -293,11 +294,13 @@ public class GroupManagementServiceImpl implements GroupManagementService {
String tenantDomain = String.valueOf(CarbonContext.getThreadLocalCarbonContext().getTenantDomain()); String tenantDomain = String.valueOf(CarbonContext.getThreadLocalCarbonContext().getTenantDomain());
String username = CarbonContext.getThreadLocalCarbonContext().getUsername(); String username = CarbonContext.getThreadLocalCarbonContext().getUsername();
if (DeviceMgtAPIUtils.getGroupManagementProviderService().deleteGroup(groupId, isDeleteChildren)) { if (DeviceMgtAPIUtils.getGroupManagementProviderService().deleteGroup(groupId, isDeleteChildren)) {
int deviceCount = DeviceMgtAPIUtils.getGroupManagementProviderService().getDeviceCount(groupId);
log.info( log.info(
"Group with group id " + groupId + " deleted", "Group with group id " + groupId + " deleted",
groupMgtContextBuilder groupMgtContextBuilder
.setActionTag("DELETE_GROUP") .setActionTag("DELETE_GROUP")
.setGroupId(String.valueOf(groupId)) .setGroupId(String.valueOf(groupId))
.setDeviceCount(String.valueOf(deviceCount))
.setTenantID(tenantId) .setTenantID(tenantId)
.setTenantDomain(tenantDomain) .setTenantDomain(tenantDomain)
.setUserName(username) .setUserName(username)
@ -394,10 +397,8 @@ public class GroupManagementServiceImpl implements GroupManagementService {
DeviceMgtAPIUtils.getGroupManagementProviderService().addDevices(groupId, deviceIdentifiers); DeviceMgtAPIUtils.getGroupManagementProviderService().addDevices(groupId, deviceIdentifiers);
PolicyAdministratorPoint pap = DeviceMgtAPIUtils.getPolicyManagementService().getPAP(); PolicyAdministratorPoint pap = DeviceMgtAPIUtils.getPolicyManagementService().getPAP();
DeviceManagementProviderService dms = DeviceMgtAPIUtils.getDeviceManagementService(); DeviceManagementProviderService dms = DeviceMgtAPIUtils.getDeviceManagementService();
List<Device> devices = new ArrayList<>();
for(DeviceIdentifier deviceIdentifier : deviceIdentifiers) { for(DeviceIdentifier deviceIdentifier : deviceIdentifiers) {
Device device = dms.getDevice(deviceIdentifier, false); Device device = dms.getDevice(deviceIdentifier, false);
devices.add(device);
if(!device.getEnrolmentInfo().getStatus().equals(EnrolmentInfo.Status.REMOVED)) { if(!device.getEnrolmentInfo().getStatus().equals(EnrolmentInfo.Status.REMOVED)) {
pap.removePolicyUsed(deviceIdentifier); pap.removePolicyUsed(deviceIdentifier);
DeviceMgtAPIUtils.getPolicyManagementService().getEffectivePolicy(deviceIdentifier); DeviceMgtAPIUtils.getPolicyManagementService().getEffectivePolicy(deviceIdentifier);
@ -405,14 +406,18 @@ public class GroupManagementServiceImpl implements GroupManagementService {
} }
pap.publishChanges(); pap.publishChanges();
int deviceCount = DeviceMgtAPIUtils.getGroupManagementProviderService().getDeviceCount(groupId); 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( log.info(
"Devices added for group id " + groupId, "Devices added for group id " + groupId,
groupMgtContextBuilder groupMgtContextBuilder
.setActionTag("ADD_DEVICES") .setActionTag("ADD_DEVICES")
.setGroupId(String.valueOf(groupId)) .setGroupId(String.valueOf(groupId))
.setDeviceCount(String.valueOf(deviceCount)) .setDeviceCount(String.valueOf(deviceCount))
.setDevices(stringDevices) .setDeviceIdentifiers(stringDeviceIdentifiers)
.setTenantID(tenantId) .setTenantID(tenantId)
.setTenantDomain(tenantDomain) .setTenantDomain(tenantDomain)
.setUserName(username) .setUserName(username)
@ -553,8 +558,6 @@ public class GroupManagementServiceImpl implements GroupManagementService {
PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername().isEmpty()); PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername().isEmpty());
if (group != null) { if (group != null) {
DeviceMgtAPIUtils.getGroupManagementProviderService().manageGroupSharing(group.getGroupId(), groups.getUserRoles()); 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( log.info(
"Group " + group.getName() + " created", "Group " + group.getName() + " created",
groupMgtContextBuilder groupMgtContextBuilder
@ -562,8 +565,6 @@ public class GroupManagementServiceImpl implements GroupManagementService {
.setGroupId(String.valueOf(group.getGroupId())) .setGroupId(String.valueOf(group.getGroupId()))
.setName(group.getName()) .setName(group.getName())
.setOwner(group.getOwner()) .setOwner(group.getOwner())
.setDeviceCount(String.valueOf(deviceCount))
.setDevices(stringDevices)
.setTenantID(tenantId) .setTenantID(tenantId)
.setTenantDomain(tenantDomain) .setTenantDomain(tenantDomain)
.setUserName(username) .setUserName(username)

@ -26,7 +26,7 @@ public class GroupMgtLogContext extends LogContext {
private final String owner; private final String owner;
private final String actionTag; private final String actionTag;
private final String deviceCount; private final String deviceCount;
private final String devices; private final String deviceIdentifiers;
private final String userName; private final String userName;
private final String tenantID; private final String tenantID;
private final String tenantDomain; private final String tenantDomain;
@ -37,7 +37,7 @@ public class GroupMgtLogContext extends LogContext {
this.owner = builder.owner; this.owner = builder.owner;
this.actionTag = builder.actionTag; this.actionTag = builder.actionTag;
this.deviceCount = builder.deviceCount; this.deviceCount = builder.deviceCount;
this.devices = builder.devices; this.deviceIdentifiers = builder.deviceIdentifiers;
this.userName = builder.userName; this.userName = builder.userName;
this.tenantID = builder.tenantID; this.tenantID = builder.tenantID;
this.tenantDomain = builder.tenantDomain; this.tenantDomain = builder.tenantDomain;
@ -63,8 +63,8 @@ public class GroupMgtLogContext extends LogContext {
return deviceCount; return deviceCount;
} }
public String getDevices() { public String getDeviceIdentifiers() {
return devices; return deviceIdentifiers;
} }
public String getUserName() { public String getUserName() {
@ -85,7 +85,7 @@ public class GroupMgtLogContext extends LogContext {
private String owner; private String owner;
private String actionTag; private String actionTag;
private String deviceCount; private String deviceCount;
private String devices; private String deviceIdentifiers;
private String userName; private String userName;
private String tenantID; private String tenantID;
private String tenantDomain; private String tenantDomain;
@ -138,12 +138,12 @@ public class GroupMgtLogContext extends LogContext {
return this; return this;
} }
public String getDevices() { public String getDeviceIdentifiers() {
return devices; return deviceIdentifiers;
} }
public Builder setDevices(String devices) { public Builder setDeviceIdentifiers(String deviceIdentifiers) {
this.devices = devices; this.deviceIdentifiers = deviceIdentifiers;
return this; return this;
} }

@ -231,8 +231,8 @@ public final class MDCContextUtil {
if (mdcContext.getDeviceCount() != null) { if (mdcContext.getDeviceCount() != null) {
MDC.put("DeviceCount", mdcContext.getDeviceCount()); MDC.put("DeviceCount", mdcContext.getDeviceCount());
} }
if (mdcContext.getDevices() != null) { if (mdcContext.getDeviceIdentifiers() != null) {
MDC.put("Devices", mdcContext.getDevices()); MDC.put("DeviceIdentifiers", mdcContext.getDeviceIdentifiers());
} }
if (mdcContext.getUserName() != null) { if (mdcContext.getUserName() != null) {
MDC.put("UserName", mdcContext.getUserName()); MDC.put("UserName", mdcContext.getUserName());

Loading…
Cancel
Save