Browse Source

feat(solutions): add dashboard assignment to edge provisioning, minor style fix

pull/15508/head
Igor Kulikov 6 months ago
parent
commit
53d118dcf3
  1. 58
      application/src/main/java/org/thingsboard/server/service/solutions/DefaultSolutionService.java
  2. 1
      application/src/main/java/org/thingsboard/server/service/solutions/data/definition/EdgeDefinition.java
  3. 1
      ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-update-dialog.component.scss

58
application/src/main/java/org/thingsboard/server/service/solutions/DefaultSolutionService.java

@ -91,6 +91,7 @@ import org.thingsboard.server.service.entitiy.asset.TbAssetService;
import org.thingsboard.server.service.entitiy.cf.TbCalculatedFieldService; import org.thingsboard.server.service.entitiy.cf.TbCalculatedFieldService;
import org.thingsboard.server.service.entitiy.device.TbDeviceService; import org.thingsboard.server.service.entitiy.device.TbDeviceService;
import org.thingsboard.server.service.entitiy.edge.TbEdgeService; import org.thingsboard.server.service.entitiy.edge.TbEdgeService;
import org.thingsboard.server.service.entitiy.entity.relation.TbEntityRelationService;
import org.thingsboard.server.service.rule.TbRuleChainService; import org.thingsboard.server.service.rule.TbRuleChainService;
import org.thingsboard.server.service.security.model.SecurityUser; import org.thingsboard.server.service.security.model.SecurityUser;
import org.thingsboard.server.service.security.system.SystemSecurityService; import org.thingsboard.server.service.security.system.SystemSecurityService;
@ -177,7 +178,7 @@ public class DefaultSolutionService implements SolutionService {
private final DashboardService dashboardService; private final DashboardService dashboardService;
private final EdgeService edgeService; private final EdgeService edgeService;
private final TbEdgeService tbEdgeService; private final TbEdgeService tbEdgeService;
private final RelationService relationService; private final TbEntityRelationService relationService;
private final AlarmService alarmService; private final AlarmService alarmService;
private final CalculatedFieldService calculatedFieldService; private final CalculatedFieldService calculatedFieldService;
private final TbCalculatedFieldService tbCalculatedFieldService; private final TbCalculatedFieldService tbCalculatedFieldService;
@ -680,6 +681,7 @@ public class DefaultSolutionService implements SolutionService {
assignRuleChainsToEdge(ctx, entityDef.getRuleChainIds(), entity); assignRuleChainsToEdge(ctx, entityDef.getRuleChainIds(), entity);
assignAssetsToEdge(ctx, entityDef.getAssetIds(), entity); assignAssetsToEdge(ctx, entityDef.getAssetIds(), entity);
assignDevicesToEdge(ctx, entityDef.getDeviceIds(), entity); assignDevicesToEdge(ctx, entityDef.getDeviceIds(), entity);
assignDashboardsToEdge(ctx, entityDef.getDashboardIds(), entity);
log.info("[{}] Saved edge: {}", entity.getId(), entity); log.info("[{}] Saved edge: {}", entity.getId(), entity);
EdgeId entityId = entity.getId(); EdgeId entityId = entity.getId();
ctx.putIdToMap(entityDef, entityId); ctx.putIdToMap(entityDef, entityId);
@ -737,6 +739,22 @@ public class DefaultSolutionService implements SolutionService {
} }
} }
private void assignDashboardsToEdge(SolutionInstallContext ctx, List<String> dashboardIds, Edge entity) {
if (dashboardIds == null || dashboardIds.isEmpty()) {
return;
}
for (String strDashboardId : dashboardIds) {
String newId = ctx.getRealIds().get(strDashboardId);
if (newId != null) {
DashboardId dashboardId = new DashboardId(UUID.fromString(newId));
dashboardService.assignDashboardToEdge(ctx.getTenantId(), dashboardId, entity.getId());
} else {
log.error("[{}] Edge: {} references non existing dashboard.", ctx.getTenantId(), entity.getName());
throw new RuntimeException("Edge: " + entity.getName() + " references non existing dashboard.");
}
}
}
private void provisionAlarmRules(SolutionInstallContext ctx) { private void provisionAlarmRules(SolutionInstallContext ctx) {
List<CalculatedField> cfs = loadListOfEntitiesIfFileExists(ctx.getTempDir(), "alarm_rules.json", new TypeReference<>() {}); List<CalculatedField> cfs = loadListOfEntitiesIfFileExists(ctx.getTempDir(), "alarm_rules.json", new TypeReference<>() {});
cfs.addAll(loadListOfEntitiesFromDirectory(ctx.getTempDir(), "alarm_rules", CalculatedField.class)); cfs.addAll(loadListOfEntitiesFromDirectory(ctx.getTempDir(), "alarm_rules", CalculatedField.class));
@ -933,30 +951,30 @@ public class DefaultSolutionService implements SolutionService {
} }
private void provisionRelations(SolutionInstallContext ctx) { private void provisionRelations(SolutionInstallContext ctx) {
for (var entry : ctx.getRelationDefinitions().entrySet()) { ctx.getRelationDefinitions().forEach((id, relations) -> {
EntityId entityId = entry.getKey(); for (RelationDefinition relationDef : relations) {
for (RelationDefinition relationDef : entry.getValue()) { log.info("[{}] Saving relation: {}", id, relationDef);
EntityId targetId = resolveRelatedEntityId(ctx, relationDef); EntityRelation entityRelation = new EntityRelation();
if (targetId == null) { EntityId otherId = resolveRelatedEntityId(relationDef, ctx);
log.warn("[{}] Relation target not found: {} '{}'", ctx.getTenantId(), relationDef.getEntityType(), relationDef.getEntityName()); if (EntitySearchDirection.FROM.equals(relationDef.getDirection())) {
continue; entityRelation.setFrom(otherId);
} entityRelation.setTo(id);
EntityRelation relation = new EntityRelation();
if (relationDef.getDirection() == EntitySearchDirection.FROM) {
relation.setFrom(entityId);
relation.setTo(targetId);
} else { } else {
relation.setFrom(targetId); entityRelation.setFrom(id);
relation.setTo(entityId); entityRelation.setTo(otherId);
}
entityRelation.setTypeGroup(RelationTypeGroup.COMMON);
entityRelation.setType(relationDef.getType());
try {
relationService.save(ctx.getTenantId(), null, entityRelation, null);
} catch (Exception e) {
log.info("[{}] Failed to save relation: {}, cause: {}", id, relationDef, e.getMessage());
} }
relation.setType(relationDef.getType());
relation.setTypeGroup(RelationTypeGroup.COMMON);
relationService.saveRelation(ctx.getTenantId(), relation);
} }
} });
} }
private EntityId resolveRelatedEntityId(SolutionInstallContext ctx, RelationDefinition relationDef) { private EntityId resolveRelatedEntityId(RelationDefinition relationDef, SolutionInstallContext ctx) {
if (relationDef.getEntityType() == EntityType.TENANT) { if (relationDef.getEntityType() == EntityType.TENANT) {
return ctx.getTenantId(); return ctx.getTenantId();
} }

1
application/src/main/java/org/thingsboard/server/service/solutions/data/definition/EdgeDefinition.java

@ -36,6 +36,7 @@ public class EdgeDefinition extends CustomerEntityDefinition {
private List<String> ruleChainIds = Collections.emptyList(); private List<String> ruleChainIds = Collections.emptyList();
private List<String> deviceIds = Collections.emptyList(); private List<String> deviceIds = Collections.emptyList();
private List<String> assetIds = Collections.emptyList(); private List<String> assetIds = Collections.emptyList();
private List<String> dashboardIds = Collections.emptyList();
@Override @Override
public EntityType getEntityType() { public EntityType getEntityType() {

1
ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-update-dialog.component.scss

@ -41,6 +41,7 @@
.tb-iot-hub-inline-spinner { .tb-iot-hub-inline-spinner {
display: inline-block; display: inline-block;
margin-right: 8px; margin-right: 8px;
vertical-align: middle;
} }
.tb-iot-hub-error-details { .tb-iot-hub-error-details {

Loading…
Cancel
Save