From 52cbe843dc5871ea0d347a14cbe4831927998601 Mon Sep 17 00:00:00 2001 From: Volodymyr Babak Date: Tue, 17 Mar 2020 17:57:48 +0200 Subject: [PATCH] Fixed import/export rule chain functionality --- .../server/dao/entity/BaseEntityService.java | 7 +++++++ ui/src/app/import-export/import-export.service.js | 10 +++++++++- ui/src/app/locale/locale.constant-en_US.json | 3 ++- ui/src/app/rulechain/rulechain.controller.js | 6 +++++- ui/src/app/rulechain/rulechain.routes.js | 7 ++++--- ui/src/app/rulechain/rulechains.controller.js | 10 +++++----- 6 files changed, 32 insertions(+), 11 deletions(-) diff --git a/dao/src/main/java/org/thingsboard/server/dao/entity/BaseEntityService.java b/dao/src/main/java/org/thingsboard/server/dao/entity/BaseEntityService.java index 2fb7196603..594c7a479c 100644 --- a/dao/src/main/java/org/thingsboard/server/dao/entity/BaseEntityService.java +++ b/dao/src/main/java/org/thingsboard/server/dao/entity/BaseEntityService.java @@ -29,6 +29,7 @@ import org.thingsboard.server.dao.asset.AssetService; import org.thingsboard.server.dao.customer.CustomerService; import org.thingsboard.server.dao.dashboard.DashboardService; import org.thingsboard.server.dao.device.DeviceService; +import org.thingsboard.server.dao.edge.EdgeService; import org.thingsboard.server.dao.entityview.EntityViewService; import org.thingsboard.server.dao.rule.RuleChainService; import org.thingsboard.server.dao.tenant.TenantService; @@ -68,6 +69,9 @@ public class BaseEntityService extends AbstractEntityService implements EntitySe @Autowired private RuleChainService ruleChainService; + @Autowired + private EdgeService edgeService; + @Override public void deleteEntityRelations(TenantId tenantId, EntityId entityId) { super.deleteEntityRelations(tenantId, entityId); @@ -106,6 +110,9 @@ public class BaseEntityService extends AbstractEntityService implements EntitySe case RULE_CHAIN: hasName = ruleChainService.findRuleChainByIdAsync(tenantId, new RuleChainId(entityId.getId())); break; + case EDGE: + hasName = edgeService.findEdgeByIdAsync(tenantId, new EdgeId(entityId.getId())); + break; default: throw new IllegalStateException("Not Implemented!"); } diff --git a/ui/src/app/import-export/import-export.service.js b/ui/src/app/import-export/import-export.service.js index 1bef77b6b2..e8f6ce937f 100644 --- a/ui/src/app/import-export/import-export.service.js +++ b/ui/src/app/import-export/import-export.service.js @@ -252,6 +252,8 @@ export default function ImportExport($log, $translate, $q, $mdDialog, $document, } ruleChain.root = false; delete ruleChain.assignedEdgesText; + delete ruleChain.assignedEdges; + delete ruleChain.assignedEdgesIds; return ruleChain; } @@ -273,13 +275,16 @@ export default function ImportExport($log, $translate, $q, $mdDialog, $document, toast.showError($translate.instant('rulechain.export-failed-error', {error: message})); } - function importRuleChain($event) { + function importRuleChain($event, expectedRuleChainType) { var deferred = $q.defer(); openImportDialog($event, 'rulechain.import', 'rulechain.rulechain-file').then( function success(ruleChainImport) { if (!validateImportedRuleChain(ruleChainImport)) { toast.showError($translate.instant('rulechain.invalid-rulechain-file-error')); deferred.reject(); + } else if (ruleChainImport.ruleChain.type !== expectedRuleChainType) { + toast.showError($translate.instant('rulechain.invalid-rulechain-type-error', {expectedRuleChainType: expectedRuleChainType})); + deferred.reject(); } else { deferred.resolve(ruleChainImport); } @@ -301,6 +306,9 @@ export default function ImportExport($log, $translate, $q, $mdDialog, $document, if (angular.isUndefined(ruleChainImport.ruleChain.name)) { return false; } + if (angular.isUndefined(ruleChainImport.ruleChain.type)) { + return false; + } return true; } diff --git a/ui/src/app/locale/locale.constant-en_US.json b/ui/src/app/locale/locale.constant-en_US.json index a65a2030f0..df2fd42576 100644 --- a/ui/src/app/locale/locale.constant-en_US.json +++ b/ui/src/app/locale/locale.constant-en_US.json @@ -1450,7 +1450,8 @@ "assigned-to-edges": "Assigned to edges", "set-default-root-edge": "Make rule chain default root", "set-default-root-edge-rulechain-title": "Are you sure you want to make the rule chain '{{ruleChainName}}' default edge root?", - "set-default-root-edge-rulechain-text": "After the confirmation the rule chain will become default edge root and will handle all incoming transport messages." + "set-default-root-edge-rulechain-text": "After the confirmation the rule chain will become default edge root and will handle all incoming transport messages.", + "invalid-rulechain-type-error": "Unable to import rule chain: Invalid rule chain type. Expected type is {{expectedRuleChainType}}." }, "rulenode": { "details": "Details", diff --git a/ui/src/app/rulechain/rulechain.controller.js b/ui/src/app/rulechain/rulechain.controller.js index 61294180bf..0bc176b397 100644 --- a/ui/src/app/rulechain/rulechain.controller.js +++ b/ui/src/app/rulechain/rulechain.controller.js @@ -1269,7 +1269,11 @@ export function RuleChainController($state, $scope, $compile, $q, $mdUtil, $time vm.isDirty = false; vm.isImport = false; $mdUtil.nextTick(() => { - $state.go('home.ruleChains.ruleChain', {ruleChainId: vm.ruleChain.id.id}); + if (vm.ruleChain.type === vm.types.systemRuleChainType) { + $state.go('home.ruleChains.system.ruleChain', {ruleChainId: vm.ruleChain.id.id}); + } else { + $state.go('home.ruleChains.edge.ruleChain', {ruleChainId: vm.ruleChain.id.id}); + } }); } else { prepareRuleChain(); diff --git a/ui/src/app/rulechain/rulechain.routes.js b/ui/src/app/rulechain/rulechain.routes.js index 754903abcb..e3bcc50159 100644 --- a/ui/src/app/rulechain/rulechain.routes.js +++ b/ui/src/app/rulechain/rulechain.routes.js @@ -56,7 +56,7 @@ export default function RuleChainRoutes($stateProvider, NodeTemplatePathProvider ncyBreadcrumb: { label: '{"icon": "settings_ethernet", "label": "rulechain.system-rulechains"}' } - }).state('home.ruleChains.ruleChain', { + }).state('home.ruleChains.system.ruleChain', { url: '/:ruleChainId', reloadOnSearch: false, module: 'private', @@ -106,7 +106,8 @@ export default function RuleChainRoutes($stateProvider, NodeTemplatePathProvider } }, params: { - ruleChainImport: {} + ruleChainImport: {}, + ruleChainType: {} }, resolve: { ruleChain: @@ -122,7 +123,7 @@ export default function RuleChainRoutes($stateProvider, NodeTemplatePathProvider ruleNodeComponents: /*@ngInject*/ function($stateParams, ruleChainService) { - return ruleChainService.getRuleNodeComponents(types.systemRuleChainType); + return ruleChainService.getRuleNodeComponents($stateParams.ruleChainType); } }, data: { diff --git a/ui/src/app/rulechain/rulechains.controller.js b/ui/src/app/rulechain/rulechains.controller.js index 09e76040a8..93217b1177 100644 --- a/ui/src/app/rulechain/rulechains.controller.js +++ b/ui/src/app/rulechain/rulechains.controller.js @@ -164,9 +164,9 @@ export default function RuleChainsController(ruleChainService, userService, edge }); vm.ruleChainGridConfig.addItemActions.push({ onAction: function ($event) { - importExport.importRuleChain($event).then( + importExport.importRuleChain($event, types.systemRuleChainType).then( function(ruleChainImport) { - $state.go('home.ruleChains.importRuleChain', {ruleChainImport:ruleChainImport}); + $state.go('home.ruleChains.importRuleChain', {ruleChainImport:ruleChainImport, ruleChainType: types.systemRuleChainType}); } ); }, @@ -260,9 +260,9 @@ export default function RuleChainsController(ruleChainService, userService, edge }); vm.ruleChainGridConfig.addItemActions.push({ onAction: function ($event) { - importExport.importRuleChain($event).then( + importExport.importRuleChain($event, types.edgeRuleChainType).then( function(ruleChainImport) { - $state.go('home.ruleChains.importRuleChain', {ruleChainImport:ruleChainImport}); + $state.go('home.ruleChains.importRuleChain', {ruleChainImport:ruleChainImport, ruleChainType: types.edgeRuleChainType}); } ); }, @@ -376,7 +376,7 @@ export default function RuleChainsController(ruleChainService, userService, edge } else if (vm.ruleChainsScope === 'edges') { $state.go('home.ruleChains.edge.ruleChain', {ruleChainId: ruleChain.id.id}); } else { - $state.go('home.ruleChains.ruleChain', {ruleChainId: ruleChain.id.id}); + $state.go('home.ruleChains.system.ruleChain', {ruleChainId: ruleChain.id.id}); } }