From 83d56fae4cdbd64767de95810e59bf4f7bcddd49 Mon Sep 17 00:00:00 2001 From: Volodymyr Babak Date: Mon, 14 Dec 2020 11:21:42 +0200 Subject: [PATCH 1/7] Translate --- ui/src/app/locale/locale.constant-en_US.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ui/src/app/locale/locale.constant-en_US.json b/ui/src/app/locale/locale.constant-en_US.json index 5ec07cf6cf..1bb5af2024 100644 --- a/ui/src/app/locale/locale.constant-en_US.json +++ b/ui/src/app/locale/locale.constant-en_US.json @@ -847,7 +847,8 @@ "status": "Received by edge", "deployed": "Deployed", "pending": "Pending", - "unassign-edges-action-title": "Unassign { count, plural, 1 {1 edge} other {# edges} } from customer" + "unassign-edges-action-title": "Unassign { count, plural, 1 {1 edge} other {# edges} } from customer", + "enter-edge-type": "Enter edge type" }, "error": { "unable-to-connect": "Unable to connect to the server! Please check your internet connection.", From 85036d053780bc8ad8a51238e142ed41aa1f0938 Mon Sep 17 00:00:00 2001 From: Volodymyr Babak Date: Mon, 14 Dec 2020 11:32:35 +0200 Subject: [PATCH 2/7] Refactored in sync with ce-3 --- .../queue/DefaultTbClusterService.java | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/application/src/main/java/org/thingsboard/server/service/queue/DefaultTbClusterService.java b/application/src/main/java/org/thingsboard/server/service/queue/DefaultTbClusterService.java index 66e93ef76c..28ad5e3486 100644 --- a/application/src/main/java/org/thingsboard/server/service/queue/DefaultTbClusterService.java +++ b/application/src/main/java/org/thingsboard/server/service/queue/DefaultTbClusterService.java @@ -184,12 +184,9 @@ public class DefaultTbClusterService implements TbClusterService { byte[] msgBytes = encodingService.encode(msg); TbQueueProducer> toRuleEngineProducer = producerProvider.getRuleEngineNotificationsMsgProducer(); Set tbRuleEngineServices = new HashSet<>(partitionService.getAllServiceIds(ServiceType.TB_RULE_ENGINE)); - boolean toCore = msg.getEntityId().getEntityType().equals(EntityType.TENANT) || - msg.getEntityId().getEntityType().equals(EntityType.EDGE); - boolean toRuleEngine = !msg.getEntityId().getEntityType().equals(EntityType.EDGE); - - if (toCore) { + if (msg.getEntityId().getEntityType().equals(EntityType.TENANT) || + msg.getEntityId().getEntityType().equals(EntityType.EDGE)) { TbQueueProducer> toCoreNfProducer = producerProvider.getTbCoreNotificationsMsgProducer(); Set tbCoreServices = partitionService.getAllServiceIds(ServiceType.TB_CORE); for (String serviceId : tbCoreServices) { @@ -201,13 +198,11 @@ public class DefaultTbClusterService implements TbClusterService { // No need to push notifications twice tbRuleEngineServices.removeAll(tbCoreServices); } - if (toRuleEngine) { - for (String serviceId : tbRuleEngineServices) { - TopicPartitionInfo tpi = partitionService.getNotificationsTopic(ServiceType.TB_RULE_ENGINE, serviceId); - ToRuleEngineNotificationMsg toRuleEngineMsg = ToRuleEngineNotificationMsg.newBuilder().setComponentLifecycleMsg(ByteString.copyFrom(msgBytes)).build(); - toRuleEngineProducer.send(tpi, new TbProtoQueueMsg<>(msg.getEntityId().getId(), toRuleEngineMsg), null); - toRuleEngineNfs.incrementAndGet(); - } + for (String serviceId : tbRuleEngineServices) { + TopicPartitionInfo tpi = partitionService.getNotificationsTopic(ServiceType.TB_RULE_ENGINE, serviceId); + ToRuleEngineNotificationMsg toRuleEngineMsg = ToRuleEngineNotificationMsg.newBuilder().setComponentLifecycleMsg(ByteString.copyFrom(msgBytes)).build(); + toRuleEngineProducer.send(tpi, new TbProtoQueueMsg<>(msg.getEntityId().getId(), toRuleEngineMsg), null); + toRuleEngineNfs.incrementAndGet(); } } From 230a303156c42df78430a64f54b920eb3894a3d3 Mon Sep 17 00:00:00 2001 From: Volodymyr Babak Date: Mon, 14 Dec 2020 12:37:21 +0200 Subject: [PATCH 3/7] Fixes incorrect customer user sync --- .../edge/rpc/init/DefaultSyncEdgeService.java | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/application/src/main/java/org/thingsboard/server/service/edge/rpc/init/DefaultSyncEdgeService.java b/application/src/main/java/org/thingsboard/server/service/edge/rpc/init/DefaultSyncEdgeService.java index 0d62beaa1b..c67a8062a0 100644 --- a/application/src/main/java/org/thingsboard/server/service/edge/rpc/init/DefaultSyncEdgeService.java +++ b/application/src/main/java/org/thingsboard/server/service/edge/rpc/init/DefaultSyncEdgeService.java @@ -311,11 +311,11 @@ public class DefaultSyncEdgeService implements SyncEdgeService { do { pageData = userService.findTenantAdmins(edge.getTenantId(), pageLink); pushUsersToEdge(pageData, edge); - syncCustomerUsers(edge); if (pageData != null && pageData.hasNext()) { pageLink = pageData.getNextPageLink(); } } while (pageData != null && pageData.hasNext()); + syncCustomerUsers(edge); } catch (Exception e) { log.error("Exception during loading edge user(s) on sync!", e); } @@ -336,6 +336,15 @@ public class DefaultSyncEdgeService implements SyncEdgeService { } } + private void pushUsersToEdge(TextPageData pageData, Edge edge) { + if (pageData != null && pageData.getData() != null && !pageData.getData().isEmpty()) { + log.trace("[{}] [{}] user(s) are going to be pushed to edge.", edge.getId(), pageData.getData().size()); + for (User user : pageData.getData()) { + saveEdgeEvent(edge.getTenantId(), edge.getId(), EdgeEventType.USER, EdgeEventActionType.ADDED, user.getId(), null); + } + } + } + private void syncWidgetsBundleAndWidgetTypes(Edge edge) { log.trace("[{}] syncWidgetsBundleAndWidgetTypes [{}]", edge.getTenantId(), edge.getName()); List widgetsBundlesToPush = new ArrayList<>(); @@ -423,15 +432,6 @@ public class DefaultSyncEdgeService implements SyncEdgeService { return tenantMailSettings; } - private void pushUsersToEdge(TextPageData pageData, Edge edge) { - if (pageData != null && pageData.getData() != null && !pageData.getData().isEmpty()) { - log.trace("[{}] [{}] user(s) are going to be pushed to edge.", edge.getId(), pageData.getData().size()); - for (User user : pageData.getData()) { - saveEdgeEvent(edge.getTenantId(), edge.getId(), EdgeEventType.USER, EdgeEventActionType.ADDED, user.getId(), null); - } - } - } - @Override public ListenableFuture processRuleChainMetadataRequestMsg(Edge edge, RuleChainMetadataRequestMsg ruleChainMetadataRequestMsg) { log.trace("[{}] processRuleChainMetadataRequestMsg [{}][{}]", edge.getTenantId(), edge.getName(), ruleChainMetadataRequestMsg); From b52d2aae17c21f6018ef316998297d149b90ddd6 Mon Sep 17 00:00:00 2001 From: Volodymyr Babak Date: Mon, 14 Dec 2020 15:31:58 +0200 Subject: [PATCH 4/7] Get rid of configuration field --- application/src/main/data/upgrade/2.6.0/schema_update.cql | 1 - application/src/main/data/upgrade/2.6.0/schema_update.sql | 1 - .../server/service/edge/rpc/EdgeGrpcSession.java | 2 +- .../java/org/thingsboard/server/common/data/edge/Edge.java | 2 -- common/edge-api/src/main/proto/edge.proto | 2 +- .../org/thingsboard/server/dao/model/ModelConstants.java | 1 - .../org/thingsboard/server/dao/model/nosql/EdgeEntity.java | 6 ------ .../org/thingsboard/server/dao/model/sql/EdgeEntity.java | 6 ------ dao/src/main/resources/cassandra/schema-entities.cql | 1 - dao/src/main/resources/sql/schema-entities-hsql.sql | 1 - dao/src/main/resources/sql/schema-entities.sql | 1 - 11 files changed, 2 insertions(+), 22 deletions(-) diff --git a/application/src/main/data/upgrade/2.6.0/schema_update.cql b/application/src/main/data/upgrade/2.6.0/schema_update.cql index cad6d658a6..8a95c62969 100644 --- a/application/src/main/data/upgrade/2.6.0/schema_update.cql +++ b/application/src/main/data/upgrade/2.6.0/schema_update.cql @@ -59,7 +59,6 @@ CREATE TABLE IF NOT EXISTS thingsboard.edge ( secret text, edge_license_key text, cloud_endpoint text, - configuration text, additional_info text, PRIMARY KEY (id, tenant_id, customer_id, type) ); diff --git a/application/src/main/data/upgrade/2.6.0/schema_update.sql b/application/src/main/data/upgrade/2.6.0/schema_update.sql index b3bfd07620..c08a854a66 100644 --- a/application/src/main/data/upgrade/2.6.0/schema_update.sql +++ b/application/src/main/data/upgrade/2.6.0/schema_update.sql @@ -19,7 +19,6 @@ CREATE TABLE IF NOT EXISTS edge ( additional_info varchar, customer_id varchar(31), root_rule_chain_id varchar(31), - configuration varchar(10000000), type varchar(255), name varchar(255), label varchar(255), diff --git a/application/src/main/java/org/thingsboard/server/service/edge/rpc/EdgeGrpcSession.java b/application/src/main/java/org/thingsboard/server/service/edge/rpc/EdgeGrpcSession.java index 83fbc637cb..f4d2a6a3b2 100644 --- a/application/src/main/java/org/thingsboard/server/service/edge/rpc/EdgeGrpcSession.java +++ b/application/src/main/java/org/thingsboard/server/service/edge/rpc/EdgeGrpcSession.java @@ -969,7 +969,7 @@ public final class EdgeGrpcSession implements Closeable { .setSecret(edge.getSecret()) .setEdgeLicenseKey(edge.getEdgeLicenseKey()) .setCloudEndpoint(edge.getCloudEndpoint()) - .setConfiguration(JacksonUtil.toString(edge.getConfiguration())) + .setAdditionalInfo(JacksonUtil.toString(edge.getAdditionalInfo())) .setCloudType("CE"); if (edge.getCustomerId() != null) { builder.setCustomerIdMSB(edge.getCustomerId().getId().getMostSignificantBits()) diff --git a/common/data/src/main/java/org/thingsboard/server/common/data/edge/Edge.java b/common/data/src/main/java/org/thingsboard/server/common/data/edge/Edge.java index 699fdf954a..67319740ca 100644 --- a/common/data/src/main/java/org/thingsboard/server/common/data/edge/Edge.java +++ b/common/data/src/main/java/org/thingsboard/server/common/data/edge/Edge.java @@ -47,7 +47,6 @@ public class Edge extends SearchTextBasedWithAdditionalInfo implements H private String secret; private String edgeLicenseKey; private String cloudEndpoint; - private transient JsonNode configuration; public Edge() { super(); @@ -68,7 +67,6 @@ public class Edge extends SearchTextBasedWithAdditionalInfo implements H this.secret = edge.getSecret(); this.edgeLicenseKey = edge.getEdgeLicenseKey(); this.cloudEndpoint = edge.getCloudEndpoint(); - this.configuration = edge.getConfiguration(); } @Override diff --git a/common/edge-api/src/main/proto/edge.proto b/common/edge-api/src/main/proto/edge.proto index 1ea5839a2b..d14215d848 100644 --- a/common/edge-api/src/main/proto/edge.proto +++ b/common/edge-api/src/main/proto/edge.proto @@ -87,7 +87,7 @@ message EdgeConfiguration { string secret = 10; string edgeLicenseKey = 11; string cloudEndpoint = 12; - string configuration = 13; + string additionalInfo = 13; string cloudType = 14; } diff --git a/dao/src/main/java/org/thingsboard/server/dao/model/ModelConstants.java b/dao/src/main/java/org/thingsboard/server/dao/model/ModelConstants.java index 688a22675d..6ad975901d 100644 --- a/dao/src/main/java/org/thingsboard/server/dao/model/ModelConstants.java +++ b/dao/src/main/java/org/thingsboard/server/dao/model/ModelConstants.java @@ -366,7 +366,6 @@ public class ModelConstants { public static final String EDGE_NAME_PROPERTY = "name"; public static final String EDGE_LABEL_PROPERTY = "label"; public static final String EDGE_TYPE_PROPERTY = "type"; - public static final String EDGE_CONFIGURATION_PROPERTY = "configuration"; public static final String EDGE_ADDITIONAL_INFO_PROPERTY = ADDITIONAL_INFO_PROPERTY; public static final String EDGE_BY_TENANT_AND_SEARCH_TEXT_COLUMN_FAMILY_NAME = "edge_by_tenant_and_search_text"; public static final String EDGE_BY_TENANT_BY_TYPE_AND_SEARCH_TEXT_COLUMN_FAMILY_NAME = "edge_by_tenant_by_type_and_search_text"; diff --git a/dao/src/main/java/org/thingsboard/server/dao/model/nosql/EdgeEntity.java b/dao/src/main/java/org/thingsboard/server/dao/model/nosql/EdgeEntity.java index 5480a9109f..79d06a4615 100644 --- a/dao/src/main/java/org/thingsboard/server/dao/model/nosql/EdgeEntity.java +++ b/dao/src/main/java/org/thingsboard/server/dao/model/nosql/EdgeEntity.java @@ -34,7 +34,6 @@ import java.util.UUID; import static org.thingsboard.server.dao.model.ModelConstants.EDGE_ADDITIONAL_INFO_PROPERTY; import static org.thingsboard.server.dao.model.ModelConstants.EDGE_CLOUD_ENDPOINT_KEY_PROPERTY; import static org.thingsboard.server.dao.model.ModelConstants.EDGE_COLUMN_FAMILY_NAME; -import static org.thingsboard.server.dao.model.ModelConstants.EDGE_CONFIGURATION_PROPERTY; import static org.thingsboard.server.dao.model.ModelConstants.EDGE_CUSTOMER_ID_PROPERTY; import static org.thingsboard.server.dao.model.ModelConstants.EDGE_LABEL_PROPERTY; import static org.thingsboard.server.dao.model.ModelConstants.EDGE_LICENSE_KEY_PROPERTY; @@ -91,9 +90,6 @@ public class EdgeEntity implements SearchTextEntity { @Column(name = EDGE_SECRET_PROPERTY) private String secret; - @Column(name = EDGE_CONFIGURATION_PROPERTY, codec = JsonCodec.class) - private JsonNode configuration; - @Column(name = EDGE_ADDITIONAL_INFO_PROPERTY, codec = JsonCodec.class) private JsonNode additionalInfo; @@ -131,7 +127,6 @@ public class EdgeEntity implements SearchTextEntity { this.secret = edge.getSecret(); this.edgeLicenseKey = edge.getEdgeLicenseKey(); this.cloudEndpoint = edge.getCloudEndpoint(); - this.configuration = edge.getConfiguration(); this.additionalInfo = edge.getAdditionalInfo(); } @@ -160,7 +155,6 @@ public class EdgeEntity implements SearchTextEntity { edge.setSecret(secret); edge.setEdgeLicenseKey(edgeLicenseKey); edge.setCloudEndpoint(cloudEndpoint); - edge.setConfiguration(configuration); edge.setAdditionalInfo(additionalInfo); return edge; } diff --git a/dao/src/main/java/org/thingsboard/server/dao/model/sql/EdgeEntity.java b/dao/src/main/java/org/thingsboard/server/dao/model/sql/EdgeEntity.java index 76bd4f2961..1896e57e66 100644 --- a/dao/src/main/java/org/thingsboard/server/dao/model/sql/EdgeEntity.java +++ b/dao/src/main/java/org/thingsboard/server/dao/model/sql/EdgeEntity.java @@ -89,10 +89,6 @@ public class EdgeEntity extends BaseSqlEntity implements SearchTextEntity< @Column(name = EDGE_CLOUD_ENDPOINT_KEY_PROPERTY) private String cloudEndpoint; - @Type(type = "json") - @Column(name = ModelConstants.EDGE_CONFIGURATION_PROPERTY) - private JsonNode configuration; - @Type(type = "json") @Column(name = ModelConstants.EDGE_ADDITIONAL_INFO_PROPERTY) private JsonNode additionalInfo; @@ -121,7 +117,6 @@ public class EdgeEntity extends BaseSqlEntity implements SearchTextEntity< this.secret = edge.getSecret(); this.edgeLicenseKey = edge.getEdgeLicenseKey(); this.cloudEndpoint = edge.getCloudEndpoint(); - this.configuration = edge.getConfiguration(); this.additionalInfo = edge.getAdditionalInfo(); } @@ -159,7 +154,6 @@ public class EdgeEntity extends BaseSqlEntity implements SearchTextEntity< edge.setSecret(secret); edge.setEdgeLicenseKey(edgeLicenseKey); edge.setCloudEndpoint(cloudEndpoint); - edge.setConfiguration(configuration); edge.setAdditionalInfo(additionalInfo); return edge; } diff --git a/dao/src/main/resources/cassandra/schema-entities.cql b/dao/src/main/resources/cassandra/schema-entities.cql index 0c3265b6ed..6e65783747 100644 --- a/dao/src/main/resources/cassandra/schema-entities.cql +++ b/dao/src/main/resources/cassandra/schema-entities.cql @@ -739,7 +739,6 @@ CREATE TABLE IF NOT EXISTS thingsboard.edge ( secret text, edge_license_key text, cloud_endpoint text, - configuration text, additional_info text, PRIMARY KEY (id, tenant_id, customer_id, type) ); diff --git a/dao/src/main/resources/sql/schema-entities-hsql.sql b/dao/src/main/resources/sql/schema-entities-hsql.sql index 8aea89a2b4..98e6798ea4 100644 --- a/dao/src/main/resources/sql/schema-entities-hsql.sql +++ b/dao/src/main/resources/sql/schema-entities-hsql.sql @@ -259,7 +259,6 @@ CREATE TABLE IF NOT EXISTS edge ( additional_info varchar, customer_id varchar(31), root_rule_chain_id varchar(31), - configuration varchar(10000000), type varchar(255), name varchar(255), label varchar(255), diff --git a/dao/src/main/resources/sql/schema-entities.sql b/dao/src/main/resources/sql/schema-entities.sql index 4ec76cc845..a30a5b81eb 100644 --- a/dao/src/main/resources/sql/schema-entities.sql +++ b/dao/src/main/resources/sql/schema-entities.sql @@ -259,7 +259,6 @@ CREATE TABLE IF NOT EXISTS edge ( additional_info varchar, customer_id varchar(31), root_rule_chain_id varchar(31), - configuration varchar(10000000), type varchar(255), name varchar(255), label varchar(255), From 59c55fb2c59c4005c0a6152aba3dba3b9d4e9854 Mon Sep 17 00:00:00 2001 From: Volodymyr Babak Date: Tue, 15 Dec 2020 18:32:35 +0200 Subject: [PATCH 5/7] For devices from edge new id generated every time --- .../service/edge/rpc/EdgeGrpcSession.java | 16 ++- .../rpc/constructor/DeviceMsgConstructor.java | 5 +- .../edge/rpc/processor/BaseProcessor.java | 4 + .../edge/rpc/processor/DeviceProcessor.java | 99 +++++++++++-------- .../thingsboard/server/edge/BaseEdgeTest.java | 56 ++++++++++- .../common/data/edge/EdgeEventActionType.java | 2 +- common/edge-api/src/main/proto/edge.proto | 3 +- .../thingsboard/rest/client/RestClient.java | 19 +++- 8 files changed, 150 insertions(+), 54 deletions(-) diff --git a/application/src/main/java/org/thingsboard/server/service/edge/rpc/EdgeGrpcSession.java b/application/src/main/java/org/thingsboard/server/service/edge/rpc/EdgeGrpcSession.java index f4d2a6a3b2..fe44d51d2f 100644 --- a/application/src/main/java/org/thingsboard/server/service/edge/rpc/EdgeGrpcSession.java +++ b/application/src/main/java/org/thingsboard/server/service/edge/rpc/EdgeGrpcSession.java @@ -17,6 +17,7 @@ package org.thingsboard.server.service.edge.rpc; import com.datastax.driver.core.utils.UUIDs; import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.node.ObjectNode; import com.google.common.util.concurrent.FutureCallback; import com.google.common.util.concurrent.Futures; import com.google.common.util.concurrent.ListenableFuture; @@ -335,8 +336,8 @@ public final class EdgeGrpcSession implements Closeable { case CREDENTIALS_REQUEST: downlinkMsg = processCredentialsRequestMessage(edgeEvent); break; - case ENTITY_EXISTS_REQUEST: - downlinkMsg = processEntityExistsRequestMessage(edgeEvent); + case ENTITY_MERGE_REQUEST: + downlinkMsg = processEntityMergeRequestMessage(edgeEvent); break; case RPC_CALL: downlinkMsg = processRpcCallMsg(edgeEvent); @@ -352,13 +353,18 @@ public final class EdgeGrpcSession implements Closeable { return result; } - private DownlinkMsg processEntityExistsRequestMessage(EdgeEvent edgeEvent) { + private DownlinkMsg processEntityMergeRequestMessage(EdgeEvent edgeEvent) { DownlinkMsg downlinkMsg = null; if (EdgeEventType.DEVICE.equals(edgeEvent.getType())) { DeviceId deviceId = new DeviceId(edgeEvent.getEntityId()); Device device = ctx.getDeviceService().findDeviceById(edge.getTenantId(), deviceId); CustomerId customerId = getCustomerIdIfEdgeAssignedToCustomer(device); - DeviceUpdateMsg d = ctx.getDeviceMsgConstructor().constructDeviceUpdatedMsg(UpdateMsgType.DEVICE_CONFLICT_RPC_MESSAGE, device, customerId); + String conflictName = null; + if(edgeEvent.getBody() != null) { + conflictName = edgeEvent.getBody().get("conflictName").asText(); + } + DeviceUpdateMsg d = ctx.getDeviceMsgConstructor() + .constructDeviceUpdatedMsg(UpdateMsgType.ENTITY_MERGE_RPC_MESSAGE, device, customerId, conflictName); downlinkMsg = DownlinkMsg.newBuilder() .addAllDeviceUpdateMsg(Collections.singletonList(d)) .build(); @@ -497,7 +503,7 @@ public final class EdgeGrpcSession implements Closeable { if (device != null) { CustomerId customerId = getCustomerIdIfEdgeAssignedToCustomer(device); DeviceUpdateMsg deviceUpdateMsg = - ctx.getDeviceMsgConstructor().constructDeviceUpdatedMsg(msgType, device, customerId); + ctx.getDeviceMsgConstructor().constructDeviceUpdatedMsg(msgType, device, customerId, null); downlinkMsg = DownlinkMsg.newBuilder() .addAllDeviceUpdateMsg(Collections.singletonList(deviceUpdateMsg)) .build(); diff --git a/application/src/main/java/org/thingsboard/server/service/edge/rpc/constructor/DeviceMsgConstructor.java b/application/src/main/java/org/thingsboard/server/service/edge/rpc/constructor/DeviceMsgConstructor.java index 1f5b360d5b..ad52779a4b 100644 --- a/application/src/main/java/org/thingsboard/server/service/edge/rpc/constructor/DeviceMsgConstructor.java +++ b/application/src/main/java/org/thingsboard/server/service/edge/rpc/constructor/DeviceMsgConstructor.java @@ -38,7 +38,7 @@ public class DeviceMsgConstructor { protected static final ObjectMapper mapper = new ObjectMapper(); - public DeviceUpdateMsg constructDeviceUpdatedMsg(UpdateMsgType msgType, Device device, CustomerId customerId) { + public DeviceUpdateMsg constructDeviceUpdatedMsg(UpdateMsgType msgType, Device device, CustomerId customerId, String conflictName) { DeviceUpdateMsg.Builder builder = DeviceUpdateMsg.newBuilder() .setMsgType(msgType) .setIdMSB(device.getId().getId().getMostSignificantBits()) @@ -55,6 +55,9 @@ public class DeviceMsgConstructor { if (device.getAdditionalInfo() != null) { builder.setAdditionalInfo(JacksonUtil.toString(device.getAdditionalInfo())); } + if (conflictName != null) { + builder.setConflictName(conflictName); + } return builder.build(); } diff --git a/application/src/main/java/org/thingsboard/server/service/edge/rpc/processor/BaseProcessor.java b/application/src/main/java/org/thingsboard/server/service/edge/rpc/processor/BaseProcessor.java index 2bdcd136ce..d1236f610d 100644 --- a/application/src/main/java/org/thingsboard/server/service/edge/rpc/processor/BaseProcessor.java +++ b/application/src/main/java/org/thingsboard/server/service/edge/rpc/processor/BaseProcessor.java @@ -37,6 +37,7 @@ import org.thingsboard.server.dao.dashboard.DashboardService; import org.thingsboard.server.dao.device.DeviceCredentialsService; import org.thingsboard.server.dao.device.DeviceService; import org.thingsboard.server.dao.edge.EdgeEventService; +import org.thingsboard.server.dao.edge.EdgeService; import org.thingsboard.server.dao.entityview.EntityViewService; import org.thingsboard.server.dao.relation.RelationService; import org.thingsboard.server.dao.user.UserService; @@ -64,6 +65,9 @@ public abstract class BaseProcessor { @Autowired protected EntityViewService entityViewService; + @Autowired + protected EdgeService edgeService; + @Autowired protected CustomerService customerService; diff --git a/application/src/main/java/org/thingsboard/server/service/edge/rpc/processor/DeviceProcessor.java b/application/src/main/java/org/thingsboard/server/service/edge/rpc/processor/DeviceProcessor.java index e503bed6b8..9aab6ec124 100644 --- a/application/src/main/java/org/thingsboard/server/service/edge/rpc/processor/DeviceProcessor.java +++ b/application/src/main/java/org/thingsboard/server/service/edge/rpc/processor/DeviceProcessor.java @@ -17,12 +17,15 @@ package org.thingsboard.server.service.edge.rpc.processor; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.node.ObjectNode; +import com.google.common.util.concurrent.FutureCallback; import com.google.common.util.concurrent.Futures; import com.google.common.util.concurrent.ListenableFuture; import com.google.common.util.concurrent.SettableFuture; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang.RandomStringUtils; import org.apache.commons.lang.StringUtils; +import org.checkerframework.checker.nullness.qual.Nullable; +import org.springframework.security.core.parameters.P; import org.springframework.stereotype.Component; import org.thingsboard.rule.engine.api.RpcError; import org.thingsboard.server.common.data.DataConstants; @@ -52,6 +55,7 @@ import org.thingsboard.server.queue.util.TbCoreComponent; import org.thingsboard.server.service.rpc.FromDeviceRpcResponse; import org.thingsboard.server.service.rpc.FromDeviceRpcResponseActorMsg; +import java.util.List; import java.util.UUID; import java.util.concurrent.locks.ReentrantLock; @@ -64,36 +68,62 @@ public class DeviceProcessor extends BaseProcessor { public ListenableFuture onDeviceUpdate(TenantId tenantId, Edge edge, DeviceUpdateMsg deviceUpdateMsg) { log.trace("[{}] onDeviceUpdate [{}] from edge [{}]", tenantId, deviceUpdateMsg, edge.getName()); - DeviceId edgeDeviceId = new DeviceId(new UUID(deviceUpdateMsg.getIdMSB(), deviceUpdateMsg.getIdLSB())); switch (deviceUpdateMsg.getMsgType()) { case ENTITY_CREATED_RPC_MESSAGE: String deviceName = deviceUpdateMsg.getName(); Device device = deviceService.findDeviceByTenantIdAndName(tenantId, deviceName); if (device != null) { - log.info("[{}] Device with name '{}' already exists on the cloud. Updating id of device entity on the edge", tenantId, deviceName); - if (!device.getId().equals(edgeDeviceId)) { - saveEdgeEvent(tenantId, edge.getId(), EdgeEventType.DEVICE, EdgeEventActionType.ENTITY_EXISTS_REQUEST, device.getId(), null); - } + ListenableFuture> future = edgeService.findRelatedEdgeIdsByEntityId(tenantId, device.getId()); + SettableFuture futureToSet = SettableFuture.create(); + Futures.addCallback(future, new FutureCallback>() { + @Override + public void onSuccess(@Nullable List edgeIds) { + boolean update = false; + if (edgeIds != null && !edgeIds.isEmpty()) { + if (edgeIds.contains(edge.getId())) { + update = true; + } + } + Device device; + if (update) { + log.info("[{}] Device with name '{}' already exists on the cloud, and related to this edge [{}]. " + + "deviceUpdateMsg [{}], Updating device", tenantId, deviceName, edge.getId(), deviceUpdateMsg); + updateDevice(tenantId, edge, deviceUpdateMsg); + } else { + log.info("[{}] Device with name '{}' already exists on the cloud, but not related to this edge [{}]. deviceUpdateMsg [{}]." + + "Creating a new device with random prefix and relate to this edge", tenantId, deviceName, edge.getId(), deviceUpdateMsg); + String newDeviceName = deviceUpdateMsg.getName() + "_" + RandomStringUtils.randomAlphabetic(15); + device = createDevice(tenantId, edge, deviceUpdateMsg, newDeviceName); + ObjectNode body = mapper.createObjectNode(); + body.put("conflictName", deviceName); + saveEdgeEvent(tenantId, edge.getId(), EdgeEventType.DEVICE, EdgeEventActionType.ENTITY_MERGE_REQUEST, device.getId(), body); + deviceService.assignDeviceToEdge(edge.getTenantId(), device.getId(), edge.getId()); + } + futureToSet.set(null); + } + + @Override + public void onFailure(Throwable t) { + log.error("[{}] Failed to get related edge ids by device id [{}], edge [{}]", tenantId, deviceUpdateMsg, edge.getId(), t); + futureToSet.setException(t); + } + }, dbCallbackExecutorService); + return futureToSet; } else { - Device deviceById = deviceService.findDeviceById(edge.getTenantId(), edgeDeviceId); - if (deviceById != null) { - log.info("[{}] Device ID [{}] already used by other device on the cloud. Creating new device and replacing device entity on the edge", tenantId, edgeDeviceId.getId()); - device = createDevice(tenantId, edge, deviceUpdateMsg); - saveEdgeEvent(tenantId, edge.getId(), EdgeEventType.DEVICE, EdgeEventActionType.ENTITY_EXISTS_REQUEST, device.getId(), null); - } else { - device = createDevice(tenantId, edge, deviceUpdateMsg); - } + log.info("[{}] Creating new device and replacing device entity on the edge [{}]", tenantId, deviceUpdateMsg); + device = createDevice(tenantId, edge, deviceUpdateMsg, deviceUpdateMsg.getName()); + saveEdgeEvent(tenantId, edge.getId(), EdgeEventType.DEVICE, EdgeEventActionType.ENTITY_MERGE_REQUEST, device.getId(), null); + deviceService.assignDeviceToEdge(edge.getTenantId(), device.getId(), edge.getId()); } - // TODO: voba - assign device only in case device is not assigned yet. Missing functionality to check this relation prior assignment - deviceService.assignDeviceToEdge(edge.getTenantId(), device.getId(), edge.getId()); break; case ENTITY_UPDATED_RPC_MESSAGE: updateDevice(tenantId, edge, deviceUpdateMsg); break; case ENTITY_DELETED_RPC_MESSAGE: - Device deviceToDelete = deviceService.findDeviceById(tenantId, edgeDeviceId); + DeviceId deviceId = new DeviceId(new UUID(deviceUpdateMsg.getIdMSB(), deviceUpdateMsg.getIdLSB())); + Device deviceToDelete = deviceService.findDeviceById(tenantId, deviceId); if (deviceToDelete != null) { - deviceService.unassignDeviceFromEdge(tenantId, edgeDeviceId, edge.getId()); + deviceService.unassignDeviceFromEdge(tenantId, deviceId, edge.getId()); } break; case UNRECOGNIZED: @@ -103,7 +133,6 @@ public class DeviceProcessor extends BaseProcessor { return Futures.immediateFuture(null); } - public ListenableFuture onDeviceCredentialsUpdate(TenantId tenantId, DeviceCredentialsUpdateMsg deviceCredentialsUpdateMsg) { log.debug("Executing onDeviceCredentialsUpdate, deviceCredentialsUpdateMsg [{}]", deviceCredentialsUpdateMsg); DeviceId deviceId = new DeviceId(new UUID(deviceCredentialsUpdateMsg.getDeviceIdMSB(), deviceCredentialsUpdateMsg.getDeviceIdLSB())); @@ -131,36 +160,34 @@ public class DeviceProcessor extends BaseProcessor { private void updateDevice(TenantId tenantId, Edge edge, DeviceUpdateMsg deviceUpdateMsg) { DeviceId deviceId = new DeviceId(new UUID(deviceUpdateMsg.getIdMSB(), deviceUpdateMsg.getIdLSB())); Device device = deviceService.findDeviceById(tenantId, deviceId); - device.setName(deviceUpdateMsg.getName()); - device.setType(deviceUpdateMsg.getType()); - device.setLabel(deviceUpdateMsg.getLabel()); - device.setAdditionalInfo(JacksonUtil.toJsonNode(deviceUpdateMsg.getAdditionalInfo())); - deviceService.saveDevice(device); - - saveEdgeEvent(tenantId, edge.getId(), EdgeEventType.DEVICE, EdgeEventActionType.CREDENTIALS_REQUEST, deviceId, null); + if (device != null) { + device.setName(deviceUpdateMsg.getName()); + device.setType(deviceUpdateMsg.getType()); + device.setLabel(deviceUpdateMsg.getLabel()); + device.setAdditionalInfo(JacksonUtil.toJsonNode(deviceUpdateMsg.getAdditionalInfo())); + deviceService.saveDevice(device); + saveEdgeEvent(tenantId, edge.getId(), EdgeEventType.DEVICE, EdgeEventActionType.CREDENTIALS_REQUEST, deviceId, null); + } else { + log.warn("[{}] can't find device [{}], edge [{}]", tenantId, deviceUpdateMsg, edge.getId()); + } } - private Device createDevice(TenantId tenantId, Edge edge, DeviceUpdateMsg deviceUpdateMsg) { + private Device createDevice(TenantId tenantId, Edge edge, DeviceUpdateMsg deviceUpdateMsg, String deviceName) { Device device; try { deviceCreationLock.lock(); log.debug("[{}] Creating device entity [{}] from edge [{}]", tenantId, deviceUpdateMsg, edge.getName()); - DeviceId deviceId = new DeviceId(new UUID(deviceUpdateMsg.getIdMSB(), deviceUpdateMsg.getIdLSB())); device = new Device(); device.setTenantId(edge.getTenantId()); device.setCustomerId(edge.getCustomerId()); - device.setId(deviceId); - device.setName(deviceUpdateMsg.getName()); + device.setName(deviceName); device.setType(deviceUpdateMsg.getType()); device.setLabel(deviceUpdateMsg.getLabel()); device.setAdditionalInfo(JacksonUtil.toJsonNode(deviceUpdateMsg.getAdditionalInfo())); device = deviceService.saveDevice(device); - createDeviceCredentials(device); createRelationFromEdge(tenantId, edge.getId(), device.getId()); deviceStateService.onDeviceAdded(device); pushDeviceCreatedEventToRuleEngine(tenantId, edge, device); - - saveEdgeEvent(tenantId, edge.getId(), EdgeEventType.DEVICE, EdgeEventActionType.CREDENTIALS_REQUEST, deviceId, null); } finally { deviceCreationLock.unlock(); } @@ -176,14 +203,6 @@ public class DeviceProcessor extends BaseProcessor { relationService.saveRelation(tenantId, relation); } - private void createDeviceCredentials(Device device) { - DeviceCredentials deviceCredentials = new DeviceCredentials(); - deviceCredentials.setDeviceId(device.getId()); - deviceCredentials.setCredentialsType(DeviceCredentialsType.ACCESS_TOKEN); - deviceCredentials.setCredentialsId(RandomStringUtils.randomAlphanumeric(20)); - deviceCredentialsService.createDeviceCredentials(device.getTenantId(), deviceCredentials); - } - private void pushDeviceCreatedEventToRuleEngine(TenantId tenantId, Edge edge, Device device) { try { DeviceId deviceId = device.getId(); diff --git a/application/src/test/java/org/thingsboard/server/edge/BaseEdgeTest.java b/application/src/test/java/org/thingsboard/server/edge/BaseEdgeTest.java index 776493a176..380d9bafaa 100644 --- a/application/src/test/java/org/thingsboard/server/edge/BaseEdgeTest.java +++ b/application/src/test/java/org/thingsboard/server/edge/BaseEdgeTest.java @@ -26,6 +26,7 @@ import com.google.protobuf.AbstractMessage; import com.google.protobuf.InvalidProtocolBufferException; import com.google.protobuf.MessageLite; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang.RandomStringUtils; import org.junit.After; import org.junit.Assert; import org.junit.Before; @@ -48,6 +49,7 @@ import org.thingsboard.server.common.data.edge.Edge; import org.thingsboard.server.common.data.edge.EdgeEvent; import org.thingsboard.server.common.data.edge.EdgeEventActionType; import org.thingsboard.server.common.data.edge.EdgeEventType; +import org.thingsboard.server.common.data.id.DeviceId; import org.thingsboard.server.common.data.id.EdgeId; import org.thingsboard.server.common.data.id.EntityId; import org.thingsboard.server.common.data.id.EntityIdFactory; @@ -964,6 +966,7 @@ abstract public class BaseEdgeTest extends AbstractControllerTest { private void testSendMessagesToCloud() throws Exception { log.info("Sending messages to cloud"); sendDevice(); + sendDeviceWithNameThatAlreadyExistsOnCloud(); sendRelationRequest(); sendAlarm(); sendTelemetry(); @@ -992,17 +995,66 @@ abstract public class BaseEdgeTest extends AbstractControllerTest { uplinkMsgBuilder.addDeviceUpdateMsg(deviceUpdateMsgBuilder.build()); edgeImitator.expectResponsesAmount(1); - + edgeImitator.expectMessageAmount(1); testAutoGeneratedCodeByProtobuf(uplinkMsgBuilder); edgeImitator.sendUplinkMsg(uplinkMsgBuilder.build()); + edgeImitator.waitForResponses(); + edgeImitator.waitForMessages(); + + AbstractMessage latestMessage = edgeImitator.getLatestMessage(); + Assert.assertTrue(latestMessage instanceof DeviceUpdateMsg); + DeviceUpdateMsg latestDeviceUpdateMsg = (DeviceUpdateMsg) latestMessage; + Assert.assertEquals("Edge Device 2", latestDeviceUpdateMsg.getName()); + + UUID newDeviceId = new UUID(latestDeviceUpdateMsg.getIdMSB(), latestDeviceUpdateMsg.getIdLSB()); - Device device = doGet("/api/device/" + uuid.toString(), Device.class); + Device device = doGet("/api/device/" + newDeviceId, Device.class); Assert.assertNotNull(device); Assert.assertEquals("Edge Device 2", device.getName()); } + private void sendDeviceWithNameThatAlreadyExistsOnCloud() throws Exception { + String deviceOnCloudName = RandomStringUtils.randomAlphanumeric(15); + Device deviceOnCloud = saveDevice(deviceOnCloudName); + + UUID uuid = UUIDs.timeBased(); + + UplinkMsg.Builder uplinkMsgBuilder = UplinkMsg.newBuilder(); + DeviceUpdateMsg.Builder deviceUpdateMsgBuilder = DeviceUpdateMsg.newBuilder(); + deviceUpdateMsgBuilder.setIdMSB(uuid.getMostSignificantBits()); + deviceUpdateMsgBuilder.setIdLSB(uuid.getLeastSignificantBits()); + deviceUpdateMsgBuilder.setName(deviceOnCloudName); + deviceUpdateMsgBuilder.setType("test"); + deviceUpdateMsgBuilder.setMsgType(UpdateMsgType.ENTITY_CREATED_RPC_MESSAGE); + testAutoGeneratedCodeByProtobuf(deviceUpdateMsgBuilder); + uplinkMsgBuilder.addDeviceUpdateMsg(deviceUpdateMsgBuilder.build()); + + edgeImitator.expectResponsesAmount(1); + edgeImitator.expectMessageAmount(1); + testAutoGeneratedCodeByProtobuf(uplinkMsgBuilder); + + edgeImitator.sendUplinkMsg(uplinkMsgBuilder.build()); + + edgeImitator.waitForResponses(); + edgeImitator.waitForMessages(); + + AbstractMessage latestMessage = edgeImitator.getLatestMessage(); + Assert.assertTrue(latestMessage instanceof DeviceUpdateMsg); + DeviceUpdateMsg latestDeviceUpdateMsg = (DeviceUpdateMsg) latestMessage; + Assert.assertNotEquals(deviceOnCloudName, latestDeviceUpdateMsg.getName()); + Assert.assertEquals(deviceOnCloudName, latestDeviceUpdateMsg.getConflictName()); + + UUID newDeviceId = new UUID(latestDeviceUpdateMsg.getIdMSB(), latestDeviceUpdateMsg.getIdLSB()); + + Assert.assertNotEquals(deviceOnCloud.getId().getId(), newDeviceId); + + Device device = doGet("/api/device/" + newDeviceId, Device.class); + Assert.assertNotNull(device); + Assert.assertNotEquals(deviceOnCloudName, device.getName()); + } + private void sendRelationRequest() throws Exception { Device device = findDeviceByName("Edge Device 1"); Asset asset = findAssetByName("Edge Asset 1"); diff --git a/common/data/src/main/java/org/thingsboard/server/common/data/edge/EdgeEventActionType.java b/common/data/src/main/java/org/thingsboard/server/common/data/edge/EdgeEventActionType.java index b8b386ac1a..427ef8a46b 100644 --- a/common/data/src/main/java/org/thingsboard/server/common/data/edge/EdgeEventActionType.java +++ b/common/data/src/main/java/org/thingsboard/server/common/data/edge/EdgeEventActionType.java @@ -34,5 +34,5 @@ public enum EdgeEventActionType { ASSIGNED_TO_EDGE, UNASSIGNED_FROM_EDGE, CREDENTIALS_REQUEST, - ENTITY_EXISTS_REQUEST + ENTITY_MERGE_REQUEST } \ No newline at end of file diff --git a/common/edge-api/src/main/proto/edge.proto b/common/edge-api/src/main/proto/edge.proto index d14215d848..bd23f4868d 100644 --- a/common/edge-api/src/main/proto/edge.proto +++ b/common/edge-api/src/main/proto/edge.proto @@ -97,7 +97,7 @@ enum UpdateMsgType { ENTITY_DELETED_RPC_MESSAGE = 2; ALARM_ACK_RPC_MESSAGE = 3; ALARM_CLEAR_RPC_MESSAGE = 4; - DEVICE_CONFLICT_RPC_MESSAGE = 5; + ENTITY_MERGE_RPC_MESSAGE = 5; } message EntityDataProto { @@ -182,6 +182,7 @@ message DeviceUpdateMsg { string type = 7; string label = 8; string additionalInfo = 9; + string conflictName = 10; } message DeviceCredentialsUpdateMsg { diff --git a/rest-client/src/main/java/org/thingsboard/rest/client/RestClient.java b/rest-client/src/main/java/org/thingsboard/rest/client/RestClient.java index ee62c0808e..9529a67052 100644 --- a/rest-client/src/main/java/org/thingsboard/rest/client/RestClient.java +++ b/rest-client/src/main/java/org/thingsboard/rest/client/RestClient.java @@ -87,6 +87,7 @@ import org.thingsboard.server.common.data.relation.EntityRelationsQuery; import org.thingsboard.server.common.data.relation.RelationTypeGroup; import org.thingsboard.server.common.data.rule.RuleChain; import org.thingsboard.server.common.data.rule.RuleChainMetaData; +import org.thingsboard.server.common.data.rule.RuleChainType; import org.thingsboard.server.common.data.security.DeviceCredentials; import org.thingsboard.server.common.data.security.DeviceCredentialsType; import org.thingsboard.server.common.data.security.model.SecuritySettings; @@ -97,6 +98,7 @@ import org.thingsboard.server.common.data.widget.WidgetsBundle; import java.io.Closeable; import java.io.IOException; import java.net.URI; +import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.List; @@ -626,22 +628,31 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable { } public List getComponentDescriptorsByType(ComponentType componentType) { + return getComponentDescriptorsByType(componentType, RuleChainType.CORE); + } + + public List getComponentDescriptorsByType(ComponentType componentType, RuleChainType ruleChainType) { return restTemplate.exchange( - baseURL + "/api/components?componentType={componentType}", + baseURL + "/api/components/" + componentType.name() + "/?ruleChainType={ruleChainType}", HttpMethod.GET, HttpEntity.EMPTY, new ParameterizedTypeReference>() { }, - componentType).getBody(); + ruleChainType).getBody(); } public List getComponentDescriptorsByTypes(List componentTypes) { + return getComponentDescriptorsByTypes(componentTypes, RuleChainType.CORE); + } + + public List getComponentDescriptorsByTypes(List componentTypes, RuleChainType ruleChainType) { return restTemplate.exchange( - baseURL + "/api/components?componentTypes={componentTypes}", + baseURL + "/api/components?componentTypes={componentTypes}&ruleChainType={ruleChainType}", HttpMethod.GET, HttpEntity.EMPTY, new ParameterizedTypeReference>() { }, - listEnumToString(componentTypes)) + listEnumToString(componentTypes), + ruleChainType) .getBody(); } From 36b8bc452ac52f3045cdf966c694f40e588de982 Mon Sep 17 00:00:00 2001 From: Volodymyr Babak Date: Wed, 16 Dec 2020 17:05:10 +0200 Subject: [PATCH 6/7] Fixed issue if entity created --- .../thingsboard/server/controller/AlarmController.java | 8 ++++---- .../thingsboard/server/controller/AssetController.java | 8 ++++---- .../thingsboard/server/controller/AuthController.java | 5 +++-- .../thingsboard/server/controller/BaseController.java | 8 ++++---- .../server/controller/CustomerController.java | 4 ++-- .../server/controller/DashboardController.java | 8 ++++---- .../server/controller/DeviceController.java | 10 +++++----- .../server/controller/EntityViewController.java | 8 ++++---- .../server/controller/RuleChainController.java | 10 +++++----- .../thingsboard/server/controller/UserController.java | 4 ++-- .../server/controller/WidgetTypeController.java | 5 +++-- .../server/controller/WidgetsBundleController.java | 5 +++-- 12 files changed, 43 insertions(+), 40 deletions(-) diff --git a/application/src/main/java/org/thingsboard/server/controller/AlarmController.java b/application/src/main/java/org/thingsboard/server/controller/AlarmController.java index 01beb1371e..74a73cc064 100644 --- a/application/src/main/java/org/thingsboard/server/controller/AlarmController.java +++ b/application/src/main/java/org/thingsboard/server/controller/AlarmController.java @@ -93,7 +93,7 @@ public class AlarmController extends BaseController { getCurrentUser().getCustomerId(), alarm.getId() == null ? ActionType.ADDED : ActionType.UPDATED, null); - sendNotificationMsgToEdgeService(getTenantId(), savedAlarm.getId(), + sendNotificationMsgToEdgeService(getTenantId(), savedAlarm.getId(), EntityType.ALARM, alarm.getId() == null ? EdgeEventActionType.ADDED : EdgeEventActionType.UPDATED); return savedAlarm; @@ -113,7 +113,7 @@ public class AlarmController extends BaseController { AlarmId alarmId = new AlarmId(toUUID(strAlarmId)); checkAlarmId(alarmId, Operation.WRITE); - sendNotificationMsgToEdgeService(getTenantId(), alarmId, EdgeEventActionType.DELETED); + sendNotificationMsgToEdgeService(getTenantId(), alarmId, EntityType.ALARM, EdgeEventActionType.DELETED); return alarmService.deleteAlarm(getTenantId(), alarmId); } catch (Exception e) { @@ -135,7 +135,7 @@ public class AlarmController extends BaseController { alarm.setStatus(alarm.getStatus().isCleared() ? AlarmStatus.CLEARED_ACK : AlarmStatus.ACTIVE_ACK); logEntityAction(alarmId, alarm, getCurrentUser().getCustomerId(), ActionType.ALARM_ACK, null); - sendNotificationMsgToEdgeService(getTenantId(), alarmId, EdgeEventActionType.ALARM_ACK); + sendNotificationMsgToEdgeService(getTenantId(), alarmId, EntityType.ALARM, EdgeEventActionType.ALARM_ACK); } catch (Exception e) { throw handleException(e); } @@ -155,7 +155,7 @@ public class AlarmController extends BaseController { alarm.setStatus(alarm.getStatus().isAck() ? AlarmStatus.CLEARED_ACK : AlarmStatus.CLEARED_UNACK); logEntityAction(alarmId, alarm, getCurrentUser().getCustomerId(), ActionType.ALARM_CLEAR, null); - sendNotificationMsgToEdgeService(getTenantId(), alarmId, EdgeEventActionType.ALARM_CLEAR); + sendNotificationMsgToEdgeService(getTenantId(), alarmId, EntityType.ALARM, EdgeEventActionType.ALARM_CLEAR); } catch (Exception e) { throw handleException(e); } diff --git a/application/src/main/java/org/thingsboard/server/controller/AssetController.java b/application/src/main/java/org/thingsboard/server/controller/AssetController.java index 9a4ebb1f92..5ad6430a7f 100644 --- a/application/src/main/java/org/thingsboard/server/controller/AssetController.java +++ b/application/src/main/java/org/thingsboard/server/controller/AssetController.java @@ -92,7 +92,7 @@ public class AssetController extends BaseController { asset.getId() == null ? ActionType.ADDED : ActionType.UPDATED, null); if (asset.getId() != null) { - sendNotificationMsgToEdgeService(savedAsset.getTenantId(), savedAsset.getId(), EdgeEventActionType.UPDATED); + sendNotificationMsgToEdgeService(savedAsset.getTenantId(), savedAsset.getId(), EntityType.ASSET, EdgeEventActionType.UPDATED); } return savedAsset; @@ -117,7 +117,7 @@ public class AssetController extends BaseController { asset.getCustomerId(), ActionType.DELETED, null, strAssetId); - sendNotificationMsgToEdgeService(getTenantId(), assetId, EdgeEventActionType.DELETED); + sendNotificationMsgToEdgeService(getTenantId(), assetId, EntityType.ASSET, EdgeEventActionType.DELETED); } catch (Exception e) { logEntityAction(emptyId(EntityType.ASSET), null, @@ -366,7 +366,7 @@ public class AssetController extends BaseController { savedAsset.getCustomerId(), ActionType.ASSIGNED_TO_EDGE, null, strAssetId, strEdgeId, edge.getName()); - sendNotificationMsgToEdgeService(getTenantId(), edgeId, savedAsset.getId(), EdgeEventActionType.ASSIGNED_TO_EDGE); + sendNotificationMsgToEdgeService(getTenantId(), edgeId, savedAsset.getId(), EntityType.ASSET, EdgeEventActionType.ASSIGNED_TO_EDGE); return savedAsset; } catch (Exception e) { @@ -399,7 +399,7 @@ public class AssetController extends BaseController { asset.getCustomerId(), ActionType.UNASSIGNED_FROM_EDGE, null, strAssetId, strEdgeId, edge.getName()); - sendNotificationMsgToEdgeService(getTenantId(), edgeId, savedAsset.getId(), EdgeEventActionType.UNASSIGNED_FROM_EDGE); + sendNotificationMsgToEdgeService(getTenantId(), edgeId, savedAsset.getId(), EntityType.ASSET, EdgeEventActionType.UNASSIGNED_FROM_EDGE); return savedAsset; } catch (Exception e) { diff --git a/application/src/main/java/org/thingsboard/server/controller/AuthController.java b/application/src/main/java/org/thingsboard/server/controller/AuthController.java index eb65a14b4a..f3cfe99129 100644 --- a/application/src/main/java/org/thingsboard/server/controller/AuthController.java +++ b/application/src/main/java/org/thingsboard/server/controller/AuthController.java @@ -33,6 +33,7 @@ import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.ResponseStatus; import org.springframework.web.bind.annotation.RestController; import org.thingsboard.rule.engine.api.MailService; +import org.thingsboard.server.common.data.EntityType; import org.thingsboard.server.common.data.User; import org.thingsboard.server.common.data.audit.ActionType; import org.thingsboard.server.common.data.edge.EdgeEventActionType; @@ -127,7 +128,7 @@ public class AuthController extends BaseController { userCredentials.setPassword(passwordEncoder.encode(newPassword)); userService.replaceUserCredentials(securityUser.getTenantId(), userCredentials); - sendNotificationMsgToEdgeService(getTenantId(), userCredentials.getUserId(), EdgeEventActionType.CREDENTIALS_UPDATED); + sendNotificationMsgToEdgeService(getTenantId(), userCredentials.getUserId(), EntityType.USER, EdgeEventActionType.CREDENTIALS_UPDATED); } catch (Exception e) { throw handleException(e); @@ -237,7 +238,7 @@ public class AuthController extends BaseController { } } - sendNotificationMsgToEdgeService(user.getTenantId(), user.getId(), EdgeEventActionType.CREDENTIALS_UPDATED); + sendNotificationMsgToEdgeService(user.getTenantId(), user.getId(), EntityType.USER, EdgeEventActionType.CREDENTIALS_UPDATED); JwtToken accessToken = tokenFactory.createAccessJwtToken(securityUser); JwtToken refreshToken = refreshTokenRepository.requestRefreshToken(securityUser); diff --git a/application/src/main/java/org/thingsboard/server/controller/BaseController.java b/application/src/main/java/org/thingsboard/server/controller/BaseController.java index 3d7d4e2393..3d0f015678 100644 --- a/application/src/main/java/org/thingsboard/server/controller/BaseController.java +++ b/application/src/main/java/org/thingsboard/server/controller/BaseController.java @@ -799,15 +799,15 @@ public abstract class BaseController { } } - protected void sendNotificationMsgToEdgeService(TenantId tenantId, EntityId entityId, EdgeEventActionType action) { - sendNotificationMsgToEdgeService(tenantId, null, entityId, action); + protected void sendNotificationMsgToEdgeService(TenantId tenantId, EntityId entityId, EntityType entityType, EdgeEventActionType action) { + sendNotificationMsgToEdgeService(tenantId, null, entityId, entityType, action); } - protected void sendNotificationMsgToEdgeService(TenantId tenantId, EdgeId edgeId, EntityId entityId, EdgeEventActionType action) { + protected void sendNotificationMsgToEdgeService(TenantId tenantId, EdgeId edgeId, EntityId entityId, EntityType entityType, EdgeEventActionType action) { if (!edgesRpcEnabled) { return; } - EdgeEventType type = EdgeUtils.getEdgeEventTypeByEntityType(entityId.getEntityType()); + EdgeEventType type = EdgeUtils.getEdgeEventTypeByEntityType(entityType); if (type != null) { sendNotificationMsgToEdgeService(tenantId, edgeId, entityId, null, type, action); } diff --git a/application/src/main/java/org/thingsboard/server/controller/CustomerController.java b/application/src/main/java/org/thingsboard/server/controller/CustomerController.java index 39ae1b8ec1..8de16b8ede 100644 --- a/application/src/main/java/org/thingsboard/server/controller/CustomerController.java +++ b/application/src/main/java/org/thingsboard/server/controller/CustomerController.java @@ -110,7 +110,7 @@ public class CustomerController extends BaseController { customer.getId() == null ? ActionType.ADDED : ActionType.UPDATED, null); if (customer.getId() != null) { - sendNotificationMsgToEdgeService(savedCustomer.getTenantId(), savedCustomer.getId(), EdgeEventActionType.UPDATED); + sendNotificationMsgToEdgeService(savedCustomer.getTenantId(), savedCustomer.getId(), EntityType.CUSTOMER, EdgeEventActionType.UPDATED); } return savedCustomer; @@ -137,7 +137,7 @@ public class CustomerController extends BaseController { customer.getId(), ActionType.DELETED, null, strCustomerId); - sendNotificationMsgToEdgeService(getTenantId(), customerId, EdgeEventActionType.DELETED); + sendNotificationMsgToEdgeService(getTenantId(), customerId, EntityType.CUSTOMER, EdgeEventActionType.DELETED); } catch (Exception e) { logEntityAction(emptyId(EntityType.CUSTOMER), diff --git a/application/src/main/java/org/thingsboard/server/controller/DashboardController.java b/application/src/main/java/org/thingsboard/server/controller/DashboardController.java index bee8a46f65..adfcedea82 100644 --- a/application/src/main/java/org/thingsboard/server/controller/DashboardController.java +++ b/application/src/main/java/org/thingsboard/server/controller/DashboardController.java @@ -117,7 +117,7 @@ public class DashboardController extends BaseController { dashboard.getId() == null ? ActionType.ADDED : ActionType.UPDATED, null); if (dashboard.getId() != null) { - sendNotificationMsgToEdgeService(savedDashboard.getTenantId(), savedDashboard.getId(), EdgeEventActionType.UPDATED); + sendNotificationMsgToEdgeService(savedDashboard.getTenantId(), savedDashboard.getId(), EntityType.DASHBOARD, EdgeEventActionType.UPDATED); } return savedDashboard; @@ -143,7 +143,7 @@ public class DashboardController extends BaseController { null, ActionType.DELETED, null, strDashboardId); - sendNotificationMsgToEdgeService(getTenantId(), dashboardId, EdgeEventActionType.DELETED); + sendNotificationMsgToEdgeService(getTenantId(), dashboardId, EntityType.DASHBOARD, EdgeEventActionType.DELETED); } catch (Exception e) { logEntityAction(emptyId(EntityType.DASHBOARD), @@ -505,7 +505,7 @@ public class DashboardController extends BaseController { null, ActionType.ASSIGNED_TO_EDGE, null, strDashboardId, strEdgeId, edge.getName()); - sendNotificationMsgToEdgeService(getTenantId(), edgeId, savedDashboard.getId(), EdgeEventActionType.ASSIGNED_TO_EDGE); + sendNotificationMsgToEdgeService(getTenantId(), edgeId, savedDashboard.getId(), EntityType.DASHBOARD, EdgeEventActionType.ASSIGNED_TO_EDGE); return savedDashboard; } catch (Exception e) { @@ -537,7 +537,7 @@ public class DashboardController extends BaseController { null, ActionType.UNASSIGNED_FROM_EDGE, null, strDashboardId, strEdgeId, edge.getName()); - sendNotificationMsgToEdgeService(getTenantId(), edgeId, savedDashboard.getId(), EdgeEventActionType.UNASSIGNED_FROM_EDGE); + sendNotificationMsgToEdgeService(getTenantId(), edgeId, savedDashboard.getId(), EntityType.DASHBOARD, EdgeEventActionType.UNASSIGNED_FROM_EDGE); return savedDashboard; } catch (Exception e) { diff --git a/application/src/main/java/org/thingsboard/server/controller/DeviceController.java b/application/src/main/java/org/thingsboard/server/controller/DeviceController.java index e64b3d37d5..653b9cd64b 100644 --- a/application/src/main/java/org/thingsboard/server/controller/DeviceController.java +++ b/application/src/main/java/org/thingsboard/server/controller/DeviceController.java @@ -114,7 +114,7 @@ public class DeviceController extends BaseController { savedDevice.getId(), savedDevice.getName(), savedDevice.getType()), null); if (device.getId() != null) { - sendNotificationMsgToEdgeService(savedDevice.getTenantId(), savedDevice.getId(), EdgeEventActionType.UPDATED); + sendNotificationMsgToEdgeService(savedDevice.getTenantId(), savedDevice.getId(), EntityType.DEVICE, EdgeEventActionType.UPDATED); } logEntityAction(savedDevice.getId(), savedDevice, @@ -148,7 +148,7 @@ public class DeviceController extends BaseController { device.getCustomerId(), ActionType.DELETED, null, strDeviceId); - sendNotificationMsgToEdgeService(getTenantId(), deviceId, EdgeEventActionType.DELETED); + sendNotificationMsgToEdgeService(getTenantId(), deviceId, EntityType.DEVICE, EdgeEventActionType.DELETED); deviceStateService.onDeviceDeleted(device); } catch (Exception e) { @@ -279,7 +279,7 @@ public class DeviceController extends BaseController { tbClusterService.pushMsgToCore(new DeviceCredentialsUpdateNotificationMsg(getCurrentUser().getTenantId(), deviceCredentials.getDeviceId()), null); - sendNotificationMsgToEdgeService(getTenantId(), device.getId(), EdgeEventActionType.CREDENTIALS_UPDATED); + sendNotificationMsgToEdgeService(getTenantId(), device.getId(), EntityType.DEVICE, EdgeEventActionType.CREDENTIALS_UPDATED); logEntityAction(device.getId(), device, device.getCustomerId(), @@ -583,7 +583,7 @@ public class DeviceController extends BaseController { savedDevice.getCustomerId(), ActionType.ASSIGNED_TO_EDGE, null, strDeviceId, strEdgeId, edge.getName()); - sendNotificationMsgToEdgeService(getTenantId(), edgeId, savedDevice.getId(), EdgeEventActionType.ASSIGNED_TO_EDGE); + sendNotificationMsgToEdgeService(getTenantId(), edgeId, savedDevice.getId(), EntityType.DEVICE, EdgeEventActionType.ASSIGNED_TO_EDGE); return savedDevice; } catch (Exception e) { @@ -617,7 +617,7 @@ public class DeviceController extends BaseController { device.getCustomerId(), ActionType.UNASSIGNED_FROM_EDGE, null, strDeviceId, strEdgeId, edge.getName()); - sendNotificationMsgToEdgeService(getTenantId(), edgeId, savedDevice.getId(), EdgeEventActionType.UNASSIGNED_FROM_EDGE); + sendNotificationMsgToEdgeService(getTenantId(), edgeId, savedDevice.getId(), EntityType.DEVICE, EdgeEventActionType.UNASSIGNED_FROM_EDGE); return savedDevice; } catch (Exception e) { diff --git a/application/src/main/java/org/thingsboard/server/controller/EntityViewController.java b/application/src/main/java/org/thingsboard/server/controller/EntityViewController.java index cb514eda1d..da4022684d 100644 --- a/application/src/main/java/org/thingsboard/server/controller/EntityViewController.java +++ b/application/src/main/java/org/thingsboard/server/controller/EntityViewController.java @@ -119,7 +119,7 @@ public class EntityViewController extends BaseController { entityView.getId() == null ? ActionType.ADDED : ActionType.UPDATED, null); if (entityView.getId() != null) { - sendNotificationMsgToEdgeService(savedEntityView.getTenantId(), savedEntityView.getId(), EdgeEventActionType.UPDATED); + sendNotificationMsgToEdgeService(savedEntityView.getTenantId(), savedEntityView.getId(), EntityType.ENTITY_VIEW, EdgeEventActionType.UPDATED); } return savedEntityView; @@ -192,7 +192,7 @@ public class EntityViewController extends BaseController { logEntityAction(entityViewId, entityView, entityView.getCustomerId(), ActionType.DELETED, null, strEntityViewId); - sendNotificationMsgToEdgeService(getTenantId(), entityViewId, EdgeEventActionType.DELETED); + sendNotificationMsgToEdgeService(getTenantId(), entityViewId, EntityType.ENTITY_VIEW, EdgeEventActionType.DELETED); } catch (Exception e) { logEntityAction(emptyId(EntityType.ENTITY_VIEW), null, @@ -405,7 +405,7 @@ public class EntityViewController extends BaseController { savedEntityView.getCustomerId(), ActionType.ASSIGNED_TO_EDGE, null, strEntityViewId, strEdgeId, edge.getName()); - sendNotificationMsgToEdgeService(getTenantId(), edgeId, savedEntityView.getId(), EdgeEventActionType.ASSIGNED_TO_EDGE); + sendNotificationMsgToEdgeService(getTenantId(), edgeId, savedEntityView.getId(), EntityType.ENTITY_VIEW, EdgeEventActionType.ASSIGNED_TO_EDGE); return savedEntityView; } catch (Exception e) { @@ -435,7 +435,7 @@ public class EntityViewController extends BaseController { entityView.getCustomerId(), ActionType.UNASSIGNED_FROM_EDGE, null, strEntityViewId, strEdgeId, edge.getName()); - sendNotificationMsgToEdgeService(getTenantId(), edgeId, savedEntityView.getId(), EdgeEventActionType.UNASSIGNED_FROM_EDGE); + sendNotificationMsgToEdgeService(getTenantId(), edgeId, savedEntityView.getId(), EntityType.ENTITY_VIEW, EdgeEventActionType.UNASSIGNED_FROM_EDGE); return savedEntityView; } catch (Exception e) { diff --git a/application/src/main/java/org/thingsboard/server/controller/RuleChainController.java b/application/src/main/java/org/thingsboard/server/controller/RuleChainController.java index bce274dc3b..43f4143182 100644 --- a/application/src/main/java/org/thingsboard/server/controller/RuleChainController.java +++ b/application/src/main/java/org/thingsboard/server/controller/RuleChainController.java @@ -146,7 +146,7 @@ public class RuleChainController extends BaseController { if (RuleChainType.EDGE.equals(savedRuleChain.getType())) { if (!created) { - sendNotificationMsgToEdgeService(savedRuleChain.getTenantId(), savedRuleChain.getId(), EdgeEventActionType.UPDATED); + sendNotificationMsgToEdgeService(savedRuleChain.getTenantId(), savedRuleChain.getId(), EntityType.RULE_CHAIN, EdgeEventActionType.UPDATED); } } @@ -226,7 +226,7 @@ public class RuleChainController extends BaseController { if (RuleChainType.EDGE.equals(ruleChain.getType())) { sendNotificationMsgToEdgeService(ruleChain.getTenantId(), - ruleChain.getId(), EdgeEventActionType.UPDATED); + ruleChain.getId(), EntityType.RULE_CHAIN, EdgeEventActionType.UPDATED); } return savedRuleChainMetaData; @@ -290,7 +290,7 @@ public class RuleChainController extends BaseController { ActionType.DELETED, null, strRuleChainId); if (RuleChainType.EDGE.equals(ruleChain.getType())) { - sendNotificationMsgToEdgeService(ruleChain.getTenantId(), ruleChain.getId(), EdgeEventActionType.DELETED); + sendNotificationMsgToEdgeService(ruleChain.getTenantId(), ruleChain.getId(), EntityType.RULE_CHAIN, EdgeEventActionType.DELETED); } } catch (Exception e) { @@ -422,7 +422,7 @@ public class RuleChainController extends BaseController { null, ActionType.ASSIGNED_TO_EDGE, null, strRuleChainId, strEdgeId, edge.getName()); - sendNotificationMsgToEdgeService(getTenantId(), edgeId, savedRuleChain.getId(), EdgeEventActionType.ASSIGNED_TO_EDGE); + sendNotificationMsgToEdgeService(getTenantId(), edgeId, savedRuleChain.getId(), EntityType.RULE_CHAIN, EdgeEventActionType.ASSIGNED_TO_EDGE); return savedRuleChain; } catch (Exception e) { @@ -454,7 +454,7 @@ public class RuleChainController extends BaseController { null, ActionType.UNASSIGNED_FROM_EDGE, null, strRuleChainId, strEdgeId, edge.getName()); - sendNotificationMsgToEdgeService(getTenantId(), edgeId, savedRuleChain.getId(), EdgeEventActionType.UNASSIGNED_FROM_EDGE); + sendNotificationMsgToEdgeService(getTenantId(), edgeId, savedRuleChain.getId(), EntityType.RULE_CHAIN, EdgeEventActionType.UNASSIGNED_FROM_EDGE); return savedRuleChain; } catch (Exception e) { diff --git a/application/src/main/java/org/thingsboard/server/controller/UserController.java b/application/src/main/java/org/thingsboard/server/controller/UserController.java index 5f141a241b..1ba54091df 100644 --- a/application/src/main/java/org/thingsboard/server/controller/UserController.java +++ b/application/src/main/java/org/thingsboard/server/controller/UserController.java @@ -166,7 +166,7 @@ public class UserController extends BaseController { savedUser.getCustomerId(), user.getId() == null ? ActionType.ADDED : ActionType.UPDATED, null); - sendNotificationMsgToEdgeService(getTenantId(), savedUser.getId(), + sendNotificationMsgToEdgeService(getTenantId(), savedUser.getId(), EntityType.USER, user.getId() == null ? EdgeEventActionType.ADDED : EdgeEventActionType.UPDATED); return savedUser; @@ -244,7 +244,7 @@ public class UserController extends BaseController { user.getCustomerId(), ActionType.DELETED, null, strUserId); - sendNotificationMsgToEdgeService(getTenantId(), user.getId(), EdgeEventActionType.DELETED); + sendNotificationMsgToEdgeService(getTenantId(), user.getId(), EntityType.USER, EdgeEventActionType.DELETED); } catch (Exception e) { logEntityAction(emptyId(EntityType.USER), diff --git a/application/src/main/java/org/thingsboard/server/controller/WidgetTypeController.java b/application/src/main/java/org/thingsboard/server/controller/WidgetTypeController.java index b061f3170f..fb203ff9ca 100644 --- a/application/src/main/java/org/thingsboard/server/controller/WidgetTypeController.java +++ b/application/src/main/java/org/thingsboard/server/controller/WidgetTypeController.java @@ -26,6 +26,7 @@ import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.ResponseStatus; import org.springframework.web.bind.annotation.RestController; +import org.thingsboard.server.common.data.EntityType; import org.thingsboard.server.common.data.audit.ActionType; import org.thingsboard.server.common.data.edge.EdgeEventActionType; import org.thingsboard.server.common.data.exception.ThingsboardException; @@ -73,7 +74,7 @@ public class WidgetTypeController extends BaseController { checkEntity(widgetType.getId(), widgetType, Resource.WIDGET_TYPE); WidgetType savedWidgetType = widgetTypeService.saveWidgetType(widgetType); - sendNotificationMsgToEdgeService(getTenantId(), savedWidgetType.getId(), + sendNotificationMsgToEdgeService(getTenantId(), savedWidgetType.getId(), EntityType.WIDGET_TYPE, widgetType.getId() == null ? EdgeEventActionType.ADDED : EdgeEventActionType.UPDATED); return checkNotNull(savedWidgetType); @@ -92,7 +93,7 @@ public class WidgetTypeController extends BaseController { checkWidgetTypeId(widgetTypeId, Operation.DELETE); widgetTypeService.deleteWidgetType(getCurrentUser().getTenantId(), widgetTypeId); - sendNotificationMsgToEdgeService(getTenantId(), widgetTypeId, EdgeEventActionType.DELETED); + sendNotificationMsgToEdgeService(getTenantId(), widgetTypeId, EntityType.WIDGET_TYPE, EdgeEventActionType.DELETED); } catch (Exception e) { throw handleException(e); diff --git a/application/src/main/java/org/thingsboard/server/controller/WidgetsBundleController.java b/application/src/main/java/org/thingsboard/server/controller/WidgetsBundleController.java index 08d9cfe4b7..72fccaf41a 100644 --- a/application/src/main/java/org/thingsboard/server/controller/WidgetsBundleController.java +++ b/application/src/main/java/org/thingsboard/server/controller/WidgetsBundleController.java @@ -25,6 +25,7 @@ import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.ResponseStatus; import org.springframework.web.bind.annotation.RestController; +import org.thingsboard.server.common.data.EntityType; import org.thingsboard.server.common.data.audit.ActionType; import org.thingsboard.server.common.data.edge.EdgeEventActionType; import org.thingsboard.server.common.data.exception.ThingsboardException; @@ -72,7 +73,7 @@ public class WidgetsBundleController extends BaseController { checkEntity(widgetsBundle.getId(), widgetsBundle, Resource.WIDGETS_BUNDLE); WidgetsBundle savedWidgetsBundle = widgetsBundleService.saveWidgetsBundle(widgetsBundle); - sendNotificationMsgToEdgeService(getTenantId(), savedWidgetsBundle.getId(), + sendNotificationMsgToEdgeService(getTenantId(), savedWidgetsBundle.getId(), EntityType.WIDGETS_BUNDLE, widgetsBundle.getId() == null ? EdgeEventActionType.ADDED : EdgeEventActionType.UPDATED); return checkNotNull(savedWidgetsBundle); @@ -91,7 +92,7 @@ public class WidgetsBundleController extends BaseController { checkWidgetsBundleId(widgetsBundleId, Operation.DELETE); widgetsBundleService.deleteWidgetsBundle(getTenantId(), widgetsBundleId); - sendNotificationMsgToEdgeService(getTenantId(), widgetsBundleId, EdgeEventActionType.DELETED); + sendNotificationMsgToEdgeService(getTenantId(), widgetsBundleId, EntityType.WIDGETS_BUNDLE, EdgeEventActionType.DELETED); } catch (Exception e) { throw handleException(e); From e23d2c7465cb139b33649c3a7c0b3d57f4fdf708 Mon Sep 17 00:00:00 2001 From: Artem Babak Date: Thu, 17 Dec 2020 05:40:42 +0200 Subject: [PATCH 7/7] Edge import finished --- ui/src/app/api/entity.service.js | 12 ++++++++---- .../table-columns-assignment.directive.js | 14 +++++++++----- ui/src/app/locale/locale.constant-en_US.json | 6 +++--- 3 files changed, 20 insertions(+), 12 deletions(-) diff --git a/ui/src/app/api/entity.service.js b/ui/src/app/api/entity.service.js index 7c94c4b574..df684c334e 100644 --- a/ui/src/app/api/entity.service.js +++ b/ui/src/app/api/entity.service.js @@ -1278,10 +1278,14 @@ function EntityService($http, $q, $filter, $translate, $log, userService, device } if (entityType === types.entityType.edge) { - newEntity.edgeLicenseKey = entityParameters.edgeLicenseKey; - newEntity.cloudEndpoint = entityParameters.cloudEndpoint; - newEntity.routingKey = entityParameters.routingKey; - newEntity.secret = entityParameters.secret; + Object.assign(newEntity, + { + edgeLicenseKey: entityParameters.edgeLicenseKey, + cloudEndpoint: entityParameters.cloudEndpoint, + routingKey: entityParameters.routingKey, + secret: entityParameters.secret + } + ); } let saveEntityPromise = getEntitySavePromise(entityType, newEntity, config); diff --git a/ui/src/app/import-export/table-columns-assignment.directive.js b/ui/src/app/import-export/table-columns-assignment.directive.js index ebfa0c8af6..012f7afad5 100644 --- a/ui/src/app/import-export/table-columns-assignment.directive.js +++ b/ui/src/app/import-export/table-columns-assignment.directive.js @@ -133,15 +133,19 @@ function TableColumnsAssignmentController($scope, types, $timeout) { vm.columnTypes.name.disable = isSelectName; vm.columnTypes.type.disable = isSelectType; vm.columnTypes.label.disable = isSelectLabel; - vm.columnTypes.gateway.disable = isSelectGateway; + if (angular.isDefined(vm.columnTypes.gateway)) { + vm.columnTypes.gateway.disable = isSelectGateway; + } vm.columnTypes.description.disable = isSelectDescription; if (angular.isDefined(vm.columnTypes.accessToken)) { vm.columnTypes.accessToken.disable = isSelectCredentials; } - vm.columnTypes.edgeLicenseKey.disable = isSelectEdgeLicenseKey; - vm.columnTypes.cloudEndpoint.disable = isSelectCloudEndpoint; - vm.columnTypes.routingKey.disable = isSelectRoutingKey; - vm.columnTypes.secret.disable = isSelectSecret; + if (vm.entityType === types.entityType.edge) { + vm.columnTypes.edgeLicenseKey.disable = isSelectEdgeLicenseKey; + vm.columnTypes.cloudEndpoint.disable = isSelectCloudEndpoint; + vm.columnTypes.routingKey.disable = isSelectRoutingKey; + vm.columnTypes.secret.disable = isSelectSecret; + } }); } }, true); diff --git a/ui/src/app/locale/locale.constant-en_US.json b/ui/src/app/locale/locale.constant-en_US.json index cf553f23c2..fe63f6e96b 100644 --- a/ui/src/app/locale/locale.constant-en_US.json +++ b/ui/src/app/locale/locale.constant-en_US.json @@ -1405,9 +1405,9 @@ "access-token": "Access token", "isgateway": "Is Gateway", "description": "Description", - "edgeLicenseKey": "Edge license key", - "cloudEndpoint": "Cloud endpoint", - "routingKey": "Edge routing key", + "edgeLicenseKey": "License Key", + "cloudEndpoint": "Cloud Endpoint", + "routingKey": "Edge key", "secret": "Edge secret" }, "stepper-text":{