changed entity name to device name when alarm

This commit is contained in:
IrynaMatveieva 2024-08-21 16:48:33 +03:00
parent ef20700b88
commit 45f298fb0d
3 changed files with 18 additions and 17 deletions

View File

@ -82,7 +82,7 @@ public class DefaultTbAlarmService extends AbstractTbEntityService implements Tb
resultAlarm = unassign(alarm, alarm.getAssignTs(), user); resultAlarm = unassign(alarm, alarm.getAssignTs(), user);
} }
if (result.isModified()) { if (result.isModified()) {
logEntityActionService.logEntityAction(tenantId, resultAlarm.getId(), resultAlarm, logEntityActionService.logEntityAction(tenantId, alarm.getOriginator(), resultAlarm,
resultAlarm.getCustomerId(), actionType, user); resultAlarm.getCustomerId(), actionType, user);
} }
return new Alarm(resultAlarm); return new Alarm(resultAlarm);
@ -107,7 +107,7 @@ public class DefaultTbAlarmService extends AbstractTbEntityService implements Tb
if (result.isModified()) { if (result.isModified()) {
String systemComment = String.format("Alarm was acknowledged by user %s", user.getTitle()); String systemComment = String.format("Alarm was acknowledged by user %s", user.getTitle());
addSystemAlarmComment(alarmInfo, user, "ACK", systemComment); addSystemAlarmComment(alarmInfo, user, "ACK", systemComment);
logEntityActionService.logEntityAction(alarm.getTenantId(), alarm.getId(), alarmInfo, logEntityActionService.logEntityAction(alarm.getTenantId(), alarm.getOriginator(), alarmInfo,
alarmInfo.getCustomerId(), ActionType.ALARM_ACK, user); alarmInfo.getCustomerId(), ActionType.ALARM_ACK, user);
} else { } else {
throw new ThingsboardException("Alarm was already acknowledged!", ThingsboardErrorCode.BAD_REQUEST_PARAMS); throw new ThingsboardException("Alarm was already acknowledged!", ThingsboardErrorCode.BAD_REQUEST_PARAMS);
@ -130,7 +130,7 @@ public class DefaultTbAlarmService extends AbstractTbEntityService implements Tb
if (result.isCleared()) { if (result.isCleared()) {
String systemComment = String.format("Alarm was cleared by user %s", user.getTitle()); String systemComment = String.format("Alarm was cleared by user %s", user.getTitle());
addSystemAlarmComment(alarmInfo, user, "CLEAR", systemComment); addSystemAlarmComment(alarmInfo, user, "CLEAR", systemComment);
logEntityActionService.logEntityAction(alarm.getTenantId(), alarm.getId(), alarmInfo, logEntityActionService.logEntityAction(alarm.getTenantId(), alarm.getOriginator(), alarmInfo,
alarmInfo.getCustomerId(), ActionType.ALARM_CLEAR, user); alarmInfo.getCustomerId(), ActionType.ALARM_CLEAR, user);
} else { } else {
throw new ThingsboardException("Alarm was already cleared!", ThingsboardErrorCode.BAD_REQUEST_PARAMS); throw new ThingsboardException("Alarm was already cleared!", ThingsboardErrorCode.BAD_REQUEST_PARAMS);
@ -149,7 +149,7 @@ public class DefaultTbAlarmService extends AbstractTbEntityService implements Tb
AlarmAssignee assignee = alarmInfo.getAssignee(); AlarmAssignee assignee = alarmInfo.getAssignee();
String systemComment = String.format("Alarm was assigned by user %s to user %s", user.getTitle(), assignee.getTitle()); String systemComment = String.format("Alarm was assigned by user %s to user %s", user.getTitle(), assignee.getTitle());
addSystemAlarmComment(alarmInfo, user, "ASSIGN", systemComment, assignee.getId()); addSystemAlarmComment(alarmInfo, user, "ASSIGN", systemComment, assignee.getId());
logEntityActionService.logEntityAction(alarm.getTenantId(), alarm.getId(), alarmInfo, logEntityActionService.logEntityAction(alarm.getTenantId(), alarm.getOriginator(), alarmInfo,
alarmInfo.getCustomerId(), ActionType.ALARM_ASSIGNED, user); alarmInfo.getCustomerId(), ActionType.ALARM_ASSIGNED, user);
} else { } else {
throw new ThingsboardException("Alarm was already assigned to this user!", ThingsboardErrorCode.BAD_REQUEST_PARAMS); throw new ThingsboardException("Alarm was already assigned to this user!", ThingsboardErrorCode.BAD_REQUEST_PARAMS);
@ -167,7 +167,7 @@ public class DefaultTbAlarmService extends AbstractTbEntityService implements Tb
if (result.isModified()) { if (result.isModified()) {
String systemComment = String.format("Alarm was unassigned by user %s", user.getTitle()); String systemComment = String.format("Alarm was unassigned by user %s", user.getTitle());
addSystemAlarmComment(alarmInfo, user, "ASSIGN", systemComment); addSystemAlarmComment(alarmInfo, user, "ASSIGN", systemComment);
logEntityActionService.logEntityAction(alarm.getTenantId(), alarm.getId(), alarmInfo, logEntityActionService.logEntityAction(alarm.getTenantId(), alarm.getOriginator(), alarmInfo,
alarmInfo.getCustomerId(), ActionType.ALARM_UNASSIGNED, user); alarmInfo.getCustomerId(), ActionType.ALARM_UNASSIGNED, user);
} else { } else {
throw new ThingsboardException("Alarm was already unassigned!", ThingsboardErrorCode.BAD_REQUEST_PARAMS); throw new ThingsboardException("Alarm was already unassigned!", ThingsboardErrorCode.BAD_REQUEST_PARAMS);
@ -195,8 +195,8 @@ public class DefaultTbAlarmService extends AbstractTbEntityService implements Tb
@Override @Override
public Boolean delete(Alarm alarm, User user) { public Boolean delete(Alarm alarm, User user) {
TenantId tenantId = alarm.getTenantId(); TenantId tenantId = alarm.getTenantId();
logEntityActionService.logEntityAction(tenantId, alarm.getId(), alarm, alarm.getCustomerId(), logEntityActionService.logEntityAction(tenantId, alarm.getOriginator(), alarm, alarm.getCustomerId(),
ActionType.ALARM_DELETE, user, alarm.getOriginator()); ActionType.ALARM_DELETE, user, alarm.getId());
return alarmSubscriptionService.deleteAlarm(tenantId, alarm.getId()); return alarmSubscriptionService.deleteAlarm(tenantId, alarm.getId());
} }
@ -215,7 +215,7 @@ public class DefaultTbAlarmService extends AbstractTbEntityService implements Tb
if (result.isModified()) { if (result.isModified()) {
String comment = String.format("Alarm was unassigned because user %s - was deleted", userTitle); String comment = String.format("Alarm was unassigned because user %s - was deleted", userTitle);
addSystemAlarmComment(result.getAlarm(), null, "ASSIGN", comment); addSystemAlarmComment(result.getAlarm(), null, "ASSIGN", comment);
logEntityActionService.logEntityAction(result.getAlarm().getTenantId(), result.getAlarm().getId(), result.getAlarm(), result.getAlarm().getCustomerId(), ActionType.ALARM_UNASSIGNED, null); logEntityActionService.logEntityAction(result.getAlarm().getTenantId(), result.getAlarm().getOriginator(), result.getAlarm(), result.getAlarm().getCustomerId(), ActionType.ALARM_UNASSIGNED, null);
} }
} }
} }

View File

@ -29,6 +29,7 @@ import org.thingsboard.server.common.data.AttributeScope;
import org.thingsboard.server.common.data.EntityType; import org.thingsboard.server.common.data.EntityType;
import org.thingsboard.server.common.data.HasName; import org.thingsboard.server.common.data.HasName;
import org.thingsboard.server.common.data.StringUtils; import org.thingsboard.server.common.data.StringUtils;
import org.thingsboard.server.common.data.alarm.Alarm;
import org.thingsboard.server.common.data.alarm.AlarmComment; import org.thingsboard.server.common.data.alarm.AlarmComment;
import org.thingsboard.server.common.data.audit.ActionStatus; import org.thingsboard.server.common.data.audit.ActionStatus;
import org.thingsboard.server.common.data.audit.ActionType; import org.thingsboard.server.common.data.audit.ActionType;
@ -123,7 +124,7 @@ public class AuditLogServiceImpl implements AuditLogService {
ActionStatus actionStatus = ActionStatus.SUCCESS; ActionStatus actionStatus = ActionStatus.SUCCESS;
String failureDetails = ""; String failureDetails = "";
String entityName = "N/A"; String entityName = "N/A";
if (entity != null) { if (entity != null && !(entity instanceof Alarm)) {
entityName = entity.getName(); entityName = entity.getName();
} else { } else {
try { try {
@ -192,9 +193,9 @@ public class AuditLogServiceImpl implements AuditLogService {
actionData.set("comment", comment.getComment()); actionData.set("comment", comment.getComment());
break; break;
case ALARM_DELETE: case ALARM_DELETE:
actionData.put("entityId", entityId.toString()); EntityId alarmId = extractParameter(EntityId.class, additionalInfo);
EntityId originatorId = extractParameter(EntityId.class, additionalInfo); actionData.put("alarmId", alarmId != null ? alarmId.toString() : null);
actionData.put("originatorId", originatorId != null ? originatorId.toString() : null); actionData.put("originatorId", entityId.toString());
break; break;
case DELETED: case DELETED:
case ACTIVATED: case ACTIVATED:

View File

@ -934,11 +934,11 @@
"type-relation-add-or-update": "Relation updated", "type-relation-add-or-update": "Relation updated",
"type-relation-delete": "Relation deleted", "type-relation-delete": "Relation deleted",
"type-relations-delete": "All relation deleted", "type-relations-delete": "All relation deleted",
"type-alarm-ack": "Acknowledged", "type-alarm-ack": "Alarm acknowledged",
"type-alarm-clear": "Cleared", "type-alarm-clear": "Alarm cleared",
"type-alarm-delete": "Deleted", "type-alarm-delete": "Alarm deleted",
"type-alarm-assign": "Assigned", "type-alarm-assign": "Alarm assigned",
"type-alarm-unassign": "Unassigned", "type-alarm-unassign": "Alarm unassigned",
"type-added-comment": "Added comment", "type-added-comment": "Added comment",
"type-updated-comment": "Updated comment", "type-updated-comment": "Updated comment",
"type-deleted-comment": "Deleted comment", "type-deleted-comment": "Deleted comment",