From 37b4db02133824e793c847c830160e55d5d584be Mon Sep 17 00:00:00 2001 From: Volodymyr Babak Date: Wed, 20 Jan 2021 18:58:59 +0200 Subject: [PATCH] Moved duplicate code to a separate method --- .../edge/DefaultEdgeNotificationService.java | 30 +++++++++++-------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/application/src/main/java/org/thingsboard/server/service/edge/DefaultEdgeNotificationService.java b/application/src/main/java/org/thingsboard/server/service/edge/DefaultEdgeNotificationService.java index 2e8676650d..94dead8fa8 100644 --- a/application/src/main/java/org/thingsboard/server/service/edge/DefaultEdgeNotificationService.java +++ b/application/src/main/java/org/thingsboard/server/service/edge/DefaultEdgeNotificationService.java @@ -263,19 +263,7 @@ public class DefaultEdgeNotificationService implements EdgeNotificationService { case ADDED: case UPDATED: case DELETED: - TextPageLink pageLink = new TextPageLink(DEFAULT_LIMIT); - TextPageData pageData; - do { - pageData = edgeService.findEdgesByTenantId(tenantId, pageLink); - if (pageData != null && pageData.getData() != null && !pageData.getData().isEmpty()) { - for (Edge edge : pageData.getData()) { - saveEdgeEvent(tenantId, edge.getId(), type, actionType, entityId, null); - } - if (pageData.hasNext()) { - pageLink = pageData.getNextPageLink(); - } - } - } while (pageData != null && pageData.hasNext()); + processActionForAllEdges(tenantId, type, actionType, entityId); break; } } @@ -501,6 +489,22 @@ public class DefaultEdgeNotificationService implements EdgeNotificationService { }, dbCallbackExecutorService); } } + + private void processActionForAllEdges(TenantId tenantId, EdgeEventType type, EdgeEventActionType actionType, EntityId entityId) { + TextPageLink pageLink = new TextPageLink(DEFAULT_LIMIT); + TextPageData pageData; + do { + pageData = edgeService.findEdgesByTenantId(tenantId, pageLink); + if (pageData != null && pageData.getData() != null && !pageData.getData().isEmpty()) { + for (Edge edge : pageData.getData()) { + saveEdgeEvent(tenantId, edge.getId(), type, actionType, entityId, null); + } + if (pageData.hasNext()) { + pageLink = pageData.getNextPageLink(); + } + } + } while (pageData != null && pageData.hasNext()); + } }