Merge pull request 'Add attached roles to logs when creating groups' (#321) from prathabanKavin/device-mgt-core:grouplogsfix into master

Reviewed-on: community/device-mgt-core#321
remotes/1712966534876109980/master
Navod Zoysa 10 months ago
commit 7e1ea40d9b

@ -558,12 +558,17 @@ 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());
String stringRoles = "";
if(groups.getUserRoles() != null){
stringRoles = new Gson().toJson(groups.getUserRoles());
}
log.info( log.info(
"Group " + group.getName() + " created", "Group " + group.getName() + " created",
groupMgtContextBuilder groupMgtContextBuilder
.setActionTag("ADD_GROUP") .setActionTag("ADD_GROUP")
.setGroupId(String.valueOf(group.getGroupId())) .setGroupId(String.valueOf(group.getGroupId()))
.setName(group.getName()) .setName(group.getName())
.setRoles(stringRoles)
.setOwner(group.getOwner()) .setOwner(group.getOwner())
.setTenantID(tenantId) .setTenantID(tenantId)
.setTenantDomain(tenantDomain) .setTenantDomain(tenantDomain)

@ -25,6 +25,7 @@ public class GroupMgtLogContext extends LogContext {
private final String name; private final String name;
private final String owner; private final String owner;
private final String actionTag; private final String actionTag;
private final String roles;
private final String deviceCount; private final String deviceCount;
private final String deviceIdentifiers; private final String deviceIdentifiers;
private final String userName; private final String userName;
@ -36,6 +37,7 @@ public class GroupMgtLogContext extends LogContext {
this.name = builder.name; this.name = builder.name;
this.owner = builder.owner; this.owner = builder.owner;
this.actionTag = builder.actionTag; this.actionTag = builder.actionTag;
this.roles = builder.roles;
this.deviceCount = builder.deviceCount; this.deviceCount = builder.deviceCount;
this.deviceIdentifiers = builder.deviceIdentifiers; this.deviceIdentifiers = builder.deviceIdentifiers;
this.userName = builder.userName; this.userName = builder.userName;
@ -59,6 +61,10 @@ public class GroupMgtLogContext extends LogContext {
return actionTag; return actionTag;
} }
public String getRoles() {
return roles;
}
public String getDeviceCount() { public String getDeviceCount() {
return deviceCount; return deviceCount;
} }
@ -84,6 +90,7 @@ public class GroupMgtLogContext extends LogContext {
private String name; private String name;
private String owner; private String owner;
private String actionTag; private String actionTag;
private String roles;
private String deviceCount; private String deviceCount;
private String deviceIdentifiers; private String deviceIdentifiers;
private String userName; private String userName;
@ -129,6 +136,15 @@ public class GroupMgtLogContext extends LogContext {
return this; return this;
} }
public String getRoles() {
return roles;
}
public Builder setRoles(String roles) {
this.roles = roles;
return this;
}
public String getDeviceCount() { public String getDeviceCount() {
return deviceCount; return deviceCount;
} }

@ -228,6 +228,9 @@ public final class MDCContextUtil {
if (mdcContext.getActionTag() != null) { if (mdcContext.getActionTag() != null) {
MDC.put("ActionTag", mdcContext.getActionTag()); MDC.put("ActionTag", mdcContext.getActionTag());
} }
if (mdcContext.getRoles() != null) {
MDC.put("Roles", mdcContext.getRoles());
}
if (mdcContext.getDeviceCount() != null) { if (mdcContext.getDeviceCount() != null) {
MDC.put("DeviceCount", mdcContext.getDeviceCount()); MDC.put("DeviceCount", mdcContext.getDeviceCount());
} }

Loading…
Cancel
Save