Browse Source

Fixed import/export rule chain functionality

pull/2818/head
Volodymyr Babak 7 years ago
parent
commit
52cbe843dc
  1. 7
      dao/src/main/java/org/thingsboard/server/dao/entity/BaseEntityService.java
  2. 10
      ui/src/app/import-export/import-export.service.js
  3. 3
      ui/src/app/locale/locale.constant-en_US.json
  4. 6
      ui/src/app/rulechain/rulechain.controller.js
  5. 7
      ui/src/app/rulechain/rulechain.routes.js
  6. 10
      ui/src/app/rulechain/rulechains.controller.js

7
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!");
}

10
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;
}

3
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",

6
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();

7
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: {

10
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});
}
}

Loading…
Cancel
Save