Skip to content

Commit

Permalink
Merge pull request #10205 from YevhenBondarenko/fix/delete-alarm
Browse files Browse the repository at this point in the history
fixed delete alarm events (device profile node)
  • Loading branch information
ashvayka authored Feb 16, 2024
2 parents d5da538 + 5c26757 commit b934610
Show file tree
Hide file tree
Showing 10 changed files with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ public void handleEvent(DeleteEntityEvent<?> event) {
private EdgeEventActionType getEdgeEventActionTypeForEntityEvent(Object entity) {
if (entity instanceof AlarmComment) {
return EdgeEventActionType.DELETED_COMMENT;
} else if (entity instanceof Alarm) {
return EdgeEventActionType.ALARM_DELETE;
}
return EdgeEventActionType.DELETED;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,7 @@ private List<DownlinkMsg> convertToDownlinkMsgsPack(List<EdgeEvent> edgeEvents)
case UNASSIGNED_FROM_EDGE:
case ALARM_ACK:
case ALARM_CLEAR:
case ALARM_DELETE:
case CREDENTIALS_UPDATED:
case RELATION_ADD_OR_UPDATE:
case RELATION_DELETED:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,7 @@ protected UpdateMsgType getUpdateMsgType(EdgeEventActionType actionType) {
case UNASSIGNED_FROM_EDGE:
case RELATION_DELETED:
case DELETED_COMMENT:
case ALARM_DELETE:
return UpdateMsgType.ENTITY_DELETED_RPC_MESSAGE;
case ALARM_ACK:
return UpdateMsgType.ALARM_ACK_RPC_MESSAGE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public ListenableFuture<Void> processAlarmNotification(TenantId tenantId, Transp
EdgeEventActionType actionType = EdgeEventActionType.valueOf(edgeNotificationMsg.getAction());
AlarmId alarmId = new AlarmId(new UUID(edgeNotificationMsg.getEntityIdMSB(), edgeNotificationMsg.getEntityIdLSB()));
EdgeId originatorEdgeId = safeGetEdgeId(edgeNotificationMsg.getOriginatorEdgeIdMSB(), edgeNotificationMsg.getOriginatorEdgeIdLSB());
if (EdgeEventActionType.DELETED.equals(actionType)) {
if (EdgeEventActionType.DELETED.equals(actionType) || EdgeEventActionType.ALARM_DELETE.equals(actionType)) {
Alarm deletedAlarm = JacksonUtil.fromString(edgeNotificationMsg.getBody(), Alarm.class);
if (deletedAlarm == null) {
return Futures.immediateFuture(null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ protected AlarmUpdateMsg convertAlarmEventToAlarmMsg(TenantId tenantId, UUID ent
.constructAlarmUpdatedMsg(msgType, alarm, findOriginatorEntityName(tenantId, alarm));
}
break;
case ALARM_DELETE:
case DELETED:
Alarm deletedAlarm = JacksonUtil.convertValue(body, Alarm.class);
if (deletedAlarm != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ public List<AlarmId> unassignDeletedUserAlarms(TenantId tenantId, User user, lon
public Boolean delete(Alarm alarm, User user) {
TenantId tenantId = alarm.getTenantId();
notificationEntityService.logEntityAction(tenantId, alarm.getOriginator(), alarm, alarm.getCustomerId(),
ActionType.DELETED, user);
ActionType.ALARM_DELETE, user);
return alarmSubscriptionService.deleteAlarm(tenantId, alarm.getId());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ public void testDeleteAlarmViaCustomer() throws Exception {
doDelete("/api/alarm/" + alarm.getId()).andExpect(status().isOk());

testNotifyEntityAllOneTime(new Alarm(alarm), alarm.getId(), alarm.getOriginator(),
tenantId, customerId, customerUserId, CUSTOMER_USER_EMAIL, ActionType.DELETED);
tenantId, customerId, customerUserId, CUSTOMER_USER_EMAIL, ActionType.ALARM_DELETE);
}

@Test
Expand All @@ -274,7 +274,7 @@ public void testDeleteAlarmViaTenant() throws Exception {
doDelete("/api/alarm/" + alarm.getId()).andExpect(status().isOk());

testNotifyEntityAllOneTime(new Alarm(alarm), alarm.getId(), alarm.getOriginator(),
tenantId, customerId, tenantAdminUserId, TENANT_ADMIN_EMAIL, ActionType.DELETED);
tenantId, customerId, tenantAdminUserId, TENANT_ADMIN_EMAIL, ActionType.ALARM_DELETE);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public void testClear() throws ThingsboardException {
public void testDelete() {
service.delete(new Alarm(), new User());

verify(notificationEntityService, times(1)).logEntityAction(any(), any(), any(), any(), eq(ActionType.DELETED), any());
verify(notificationEntityService, times(1)).logEntityAction(any(), any(), any(), any(), eq(ActionType.ALARM_DELETE), any());
verify(alarmSubscriptionService, times(1)).deleteAlarm(any(), any());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public enum EdgeEventActionType {
RPC_CALL(ActionType.RPC_CALL),
ALARM_ACK(ActionType.ALARM_ACK),
ALARM_CLEAR(ActionType.ALARM_CLEAR),
ALARM_DELETE(ActionType.ALARM_DELETE),
ALARM_ASSIGNED(ActionType.ALARM_ASSIGNED),
ALARM_UNASSIGNED(ActionType.ALARM_UNASSIGNED),
ADDED_COMMENT(ActionType.ADDED_COMMENT),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ private <E extends HasName, I extends EntityId> JsonNode constructActionData(I e
AlarmComment comment = extractParameter(AlarmComment.class, additionalInfo);
actionData.set("comment", comment.getComment());
break;
case ALARM_DELETE:
case DELETED:
case ACTIVATED:
case SUSPENDED:
Expand Down

0 comments on commit b934610

Please sign in to comment.