Refactor SaveEntityEvent to make it more generic in EdgeEventSourcingListener
This commit is contained in:
parent
28e9aae2e5
commit
67fe8067b7
@ -80,24 +80,16 @@ public class EdgeEventSourcingListener {
|
||||
}
|
||||
log.trace("[{}] SaveEntityEvent called: {}", event.getTenantId(), event);
|
||||
boolean isAdded = Boolean.TRUE.equals(event.getAdded());
|
||||
EdgeEventActionType action = isAdded ? EdgeEventActionType.ADDED : EdgeEventActionType.UPDATED;
|
||||
if (event.getEntity() instanceof AlarmComment) {
|
||||
processAlarmCommentEvent(event, isAdded);
|
||||
return;
|
||||
}
|
||||
String body = getBodyMsgForEntityEvent(event.getEntity());
|
||||
EdgeEventType type = getEdgeEventTypeForEntityEvent(event.getEntity());
|
||||
EdgeEventActionType action = getActionForEntityEvent(event.getEntity(), isAdded);
|
||||
tbClusterService.sendNotificationMsgToEdge(event.getTenantId(), null, event.getEntityId(),
|
||||
null, null, action, edgeSynchronizationManager.getEdgeId().get());
|
||||
body, type, action, edgeSynchronizationManager.getEdgeId().get());
|
||||
} catch (Exception e) {
|
||||
log.error("[{}] failed to process SaveEntityEvent: {}", event.getTenantId(), event, e);
|
||||
}
|
||||
}
|
||||
|
||||
private void processAlarmCommentEvent(SaveEntityEvent<?> event, boolean added) {
|
||||
EdgeEventActionType action = added ? EdgeEventActionType.ADDED_COMMENT : EdgeEventActionType.UPDATED_COMMENT;
|
||||
tbClusterService.sendNotificationMsgToEdge(event.getTenantId(), null, event.getEntityId(),
|
||||
JacksonUtil.toString(event.getEntity()), EdgeEventType.ALARM_COMMENT, action, edgeSynchronizationManager.getEdgeId().get());
|
||||
}
|
||||
|
||||
@TransactionalEventListener(fallbackExecution = true)
|
||||
public void handleEvent(DeleteEntityEvent<?> event) {
|
||||
try {
|
||||
@ -207,4 +199,11 @@ public class EdgeEventSourcingListener {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private EdgeEventActionType getActionForEntityEvent(Object entity, boolean isAdded) {
|
||||
if (entity instanceof AlarmComment) {
|
||||
return isAdded ? EdgeEventActionType.ADDED_COMMENT : EdgeEventActionType.UPDATED_COMMENT;
|
||||
}
|
||||
return isAdded ? EdgeEventActionType.ADDED : EdgeEventActionType.UPDATED;
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user