Commit ab14bcb963bf2b0b339e06bdd4884fe86fe97eb3

Authored by VoBa
Committed by GitHub
2 parents 27971801 44468165

Merge pull request #35 from BohdanSmetanyuk/feature/fetch_admin_settings

Feature/fetch admin settings
@@ -39,6 +39,7 @@ import org.thingsboard.server.queue.discovery.PartitionService; @@ -39,6 +39,7 @@ import org.thingsboard.server.queue.discovery.PartitionService;
39 import org.thingsboard.server.queue.provider.TbQueueProducerProvider; 39 import org.thingsboard.server.queue.provider.TbQueueProducerProvider;
40 import org.thingsboard.server.queue.util.TbCoreComponent; 40 import org.thingsboard.server.queue.util.TbCoreComponent;
41 import org.thingsboard.server.service.edge.rpc.EdgeEventStorageSettings; 41 import org.thingsboard.server.service.edge.rpc.EdgeEventStorageSettings;
  42 +import org.thingsboard.server.service.edge.rpc.constructor.AdminSettingsUpdateMsgConstructor;
42 import org.thingsboard.server.service.edge.rpc.constructor.AlarmUpdateMsgConstructor; 43 import org.thingsboard.server.service.edge.rpc.constructor.AlarmUpdateMsgConstructor;
43 import org.thingsboard.server.service.edge.rpc.constructor.AssetUpdateMsgConstructor; 44 import org.thingsboard.server.service.edge.rpc.constructor.AssetUpdateMsgConstructor;
44 import org.thingsboard.server.service.edge.rpc.constructor.CustomerUpdateMsgConstructor; 45 import org.thingsboard.server.service.edge.rpc.constructor.CustomerUpdateMsgConstructor;
@@ -190,6 +191,10 @@ public class EdgeContextComponent { @@ -190,6 +191,10 @@ public class EdgeContextComponent {
190 191
191 @Lazy 192 @Lazy
192 @Autowired 193 @Autowired
  194 + private AdminSettingsUpdateMsgConstructor adminSettingsUpdateMsgConstructor;
  195 +
  196 + @Lazy
  197 + @Autowired
193 private EntityDataMsgConstructor entityDataMsgConstructor; 198 private EntityDataMsgConstructor entityDataMsgConstructor;
194 199
195 @Lazy 200 @Lazy
@@ -32,6 +32,7 @@ import lombok.Data; @@ -32,6 +32,7 @@ import lombok.Data;
32 import lombok.extern.slf4j.Slf4j; 32 import lombok.extern.slf4j.Slf4j;
33 import org.apache.commons.lang.RandomStringUtils; 33 import org.apache.commons.lang.RandomStringUtils;
34 import org.checkerframework.checker.nullness.qual.Nullable; 34 import org.checkerframework.checker.nullness.qual.Nullable;
  35 +import org.thingsboard.server.common.data.AdminSettings;
35 import org.thingsboard.server.common.data.Customer; 36 import org.thingsboard.server.common.data.Customer;
36 import org.thingsboard.server.common.data.Dashboard; 37 import org.thingsboard.server.common.data.Dashboard;
37 import org.thingsboard.server.common.data.DataConstants; 38 import org.thingsboard.server.common.data.DataConstants;
@@ -377,6 +378,9 @@ public final class EdgeGrpcSession implements Closeable { @@ -377,6 +378,9 @@ public final class EdgeGrpcSession implements Closeable {
377 case WIDGET_TYPE: 378 case WIDGET_TYPE:
378 processWidgetType(edgeEvent, msgType, edgeEventAction); 379 processWidgetType(edgeEvent, msgType, edgeEventAction);
379 break; 380 break;
  381 + case ADMIN_SETTINGS:
  382 + processAdminSettings(edgeEvent);
  383 + break;
380 } 384 }
381 } 385 }
382 386
@@ -732,6 +736,16 @@ public final class EdgeGrpcSession implements Closeable { @@ -732,6 +736,16 @@ public final class EdgeGrpcSession implements Closeable {
732 } 736 }
733 } 737 }
734 738
  739 + private void processAdminSettings(EdgeEvent edgeEvent) {
  740 + AdminSettings adminSettings = mapper.convertValue(edgeEvent.getEntityBody(), AdminSettings.class);
  741 + EntityUpdateMsg entityUpdateMsg = EntityUpdateMsg.newBuilder()
  742 + .setAdminSettingsUpdateMsg(ctx.getAdminSettingsUpdateMsgConstructor().constructAdminSettingsUpdateMsg(adminSettings))
  743 + .build();
  744 + outputStream.onNext(ResponseMsg.newBuilder()
  745 + .setEntityUpdateMsg(entityUpdateMsg)
  746 + .build());
  747 + }
  748 +
735 private UpdateMsgType getResponseMsgType(ActionType actionType) { 749 private UpdateMsgType getResponseMsgType(ActionType actionType) {
736 switch (actionType) { 750 switch (actionType) {
737 case UPDATED: 751 case UPDATED:
  1 +/**
  2 + * Copyright © 2016-2020 The Thingsboard Authors
  3 + *
  4 + * Licensed under the Apache License, Version 2.0 (the "License");
  5 + * you may not use this file except in compliance with the License.
  6 + * You may obtain a copy of the License at
  7 + *
  8 + * http://www.apache.org/licenses/LICENSE-2.0
  9 + *
  10 + * Unless required by applicable law or agreed to in writing, software
  11 + * distributed under the License is distributed on an "AS IS" BASIS,
  12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13 + * See the License for the specific language governing permissions and
  14 + * limitations under the License.
  15 + */
  16 +package org.thingsboard.server.service.edge.rpc.constructor;
  17 +
  18 +import lombok.extern.slf4j.Slf4j;
  19 +import org.springframework.stereotype.Component;
  20 +import org.thingsboard.server.common.data.AdminSettings;
  21 +import org.thingsboard.server.common.data.id.AdminSettingsId;
  22 +import org.thingsboard.server.dao.util.mapping.JacksonUtil;
  23 +import org.thingsboard.server.gen.edge.AdminSettingsUpdateMsg;
  24 +
  25 +@Slf4j
  26 +@Component
  27 +public class AdminSettingsUpdateMsgConstructor {
  28 +
  29 + public AdminSettingsUpdateMsg constructAdminSettingsUpdateMsg(AdminSettings adminSettings) {
  30 + AdminSettingsUpdateMsg.Builder builder = AdminSettingsUpdateMsg.newBuilder()
  31 + .setKey(adminSettings.getKey())
  32 + .setJsonValue(JacksonUtil.toString(adminSettings.getJsonValue()));
  33 + AdminSettingsId adminSettingsId = adminSettings.getId();
  34 + if (adminSettingsId != null) {
  35 + builder.setIdMSB(adminSettingsId.getId().getMostSignificantBits());
  36 + builder.setIdLSB(adminSettingsId.getId().getLeastSignificantBits());
  37 + }
  38 + return builder.build();
  39 + }
  40 +
  41 +}
@@ -25,6 +25,7 @@ import lombok.extern.slf4j.Slf4j; @@ -25,6 +25,7 @@ import lombok.extern.slf4j.Slf4j;
25 import org.checkerframework.checker.nullness.qual.Nullable; 25 import org.checkerframework.checker.nullness.qual.Nullable;
26 import org.springframework.beans.factory.annotation.Autowired; 26 import org.springframework.beans.factory.annotation.Autowired;
27 import org.springframework.stereotype.Service; 27 import org.springframework.stereotype.Service;
  28 +import org.thingsboard.server.common.data.AdminSettings;
28 import org.thingsboard.server.common.data.DashboardInfo; 29 import org.thingsboard.server.common.data.DashboardInfo;
29 import org.thingsboard.server.common.data.DataConstants; 30 import org.thingsboard.server.common.data.DataConstants;
30 import org.thingsboard.server.common.data.Device; 31 import org.thingsboard.server.common.data.Device;
@@ -64,6 +65,7 @@ import org.thingsboard.server.dao.edge.EdgeEventService; @@ -64,6 +65,7 @@ import org.thingsboard.server.dao.edge.EdgeEventService;
64 import org.thingsboard.server.dao.entityview.EntityViewService; 65 import org.thingsboard.server.dao.entityview.EntityViewService;
65 import org.thingsboard.server.dao.relation.RelationService; 66 import org.thingsboard.server.dao.relation.RelationService;
66 import org.thingsboard.server.dao.rule.RuleChainService; 67 import org.thingsboard.server.dao.rule.RuleChainService;
  68 +import org.thingsboard.server.dao.settings.AdminSettingsService;
67 import org.thingsboard.server.dao.user.UserService; 69 import org.thingsboard.server.dao.user.UserService;
68 import org.thingsboard.server.dao.widget.WidgetTypeService; 70 import org.thingsboard.server.dao.widget.WidgetTypeService;
69 import org.thingsboard.server.dao.widget.WidgetsBundleService; 71 import org.thingsboard.server.dao.widget.WidgetsBundleService;
@@ -120,6 +122,9 @@ public class DefaultSyncEdgeService implements SyncEdgeService { @@ -120,6 +122,9 @@ public class DefaultSyncEdgeService implements SyncEdgeService {
120 private WidgetTypeService widgetTypeService; 122 private WidgetTypeService widgetTypeService;
121 123
122 @Autowired 124 @Autowired
  125 + private AdminSettingsService adminSettingsService;
  126 +
  127 + @Autowired
123 private DbCallbackExecutorService dbCallbackExecutorService; 128 private DbCallbackExecutorService dbCallbackExecutorService;
124 129
125 @Override 130 @Override
@@ -132,6 +137,7 @@ public class DefaultSyncEdgeService implements SyncEdgeService { @@ -132,6 +137,7 @@ public class DefaultSyncEdgeService implements SyncEdgeService {
132 syncEntityViews(edge); 137 syncEntityViews(edge);
133 syncDashboards(edge); 138 syncDashboards(edge);
134 syncWidgetsBundleAndWidgetTypes(edge); 139 syncWidgetsBundleAndWidgetTypes(edge);
  140 + syncAdminSettings(edge);
135 } catch (Exception e) { 141 } catch (Exception e) {
136 log.error("Exception during sync process", e); 142 log.error("Exception during sync process", e);
137 } 143 }
@@ -291,6 +297,15 @@ public class DefaultSyncEdgeService implements SyncEdgeService { @@ -291,6 +297,15 @@ public class DefaultSyncEdgeService implements SyncEdgeService {
291 } 297 }
292 } 298 }
293 299
  300 + private void syncAdminSettings(Edge edge) {
  301 + try {
  302 + AdminSettings mailSettings = adminSettingsService.findAdminSettingsByKey(TenantId.SYS_TENANT_ID, "mail");
  303 + saveEdgeEvent(edge.getTenantId(), edge.getId(), EdgeEventType.ADMIN_SETTINGS, ActionType.UPDATED, null, mapper.valueToTree(mailSettings));
  304 + } catch (Exception e) {
  305 + log.error("Can't load admin settings", e);
  306 + }
  307 + }
  308 +
294 private void pushUsersToEdge(TextPageData<User> pageData, Edge edge) { 309 private void pushUsersToEdge(TextPageData<User> pageData, Edge edge) {
295 if (pageData != null && pageData.getData() != null && !pageData.getData().isEmpty()) { 310 if (pageData != null && pageData.getData() != null && !pageData.getData().isEmpty()) {
296 log.trace("[{}] [{}] user(s) are going to be pushed to edge.", edge.getId(), pageData.getData().size()); 311 log.trace("[{}] [{}] user(s) are going to be pushed to edge.", edge.getId(), pageData.getData().size());
@@ -29,5 +29,6 @@ public enum EdgeEventType { @@ -29,5 +29,6 @@ public enum EdgeEventType {
29 RELATION, 29 RELATION,
30 TENANT, 30 TENANT,
31 WIDGETS_BUNDLE, 31 WIDGETS_BUNDLE,
32 - WIDGET_TYPE 32 + WIDGET_TYPE,
  33 + ADMIN_SETTINGS
33 } 34 }
@@ -61,6 +61,7 @@ message EntityUpdateMsg { @@ -61,6 +61,7 @@ message EntityUpdateMsg {
61 RelationUpdateMsg relationUpdateMsg = 12; 61 RelationUpdateMsg relationUpdateMsg = 12;
62 WidgetsBundleUpdateMsg widgetsBundleUpdateMsg = 13; 62 WidgetsBundleUpdateMsg widgetsBundleUpdateMsg = 13;
63 WidgetTypeUpdateMsg widgetTypeUpdateMsg = 14; 63 WidgetTypeUpdateMsg widgetTypeUpdateMsg = 14;
  64 + AdminSettingsUpdateMsg adminSettingsUpdateMsg = 15;
64 } 65 }
65 66
66 enum RequestMsgType { 67 enum RequestMsgType {
@@ -291,6 +292,13 @@ message WidgetTypeUpdateMsg { @@ -291,6 +292,13 @@ message WidgetTypeUpdateMsg {
291 bool isSystem = 8; 292 bool isSystem = 8;
292 } 293 }
293 294
  295 +message AdminSettingsUpdateMsg {
  296 + int64 idMSB = 1;
  297 + int64 idLSB = 2;
  298 + string key = 3;
  299 + string jsonValue = 4;
  300 +}
  301 +
294 message UserCredentialsUpdateMsg { 302 message UserCredentialsUpdateMsg {
295 int64 userIdMSB = 1; 303 int64 userIdMSB = 1;
296 int64 userIdLSB = 2; 304 int64 userIdLSB = 2;