Commit 4c2effd9bef1653b9861fd244a17b3a07c6e888e

Authored by deaflynx
1 parent a52b8880

Fix import with rule chain type

... ... @@ -14,8 +14,8 @@
14 14 * limitations under the License.
15 15 */
16 16
17   -const forwardUrl = "http://localhost:8080";
18   -const wsForwardUrl = "ws://localhost:8080";
  17 +const forwardUrl = "http://localhost:8081";
  18 +const wsForwardUrl = "ws://localhost:8081";
19 19 const ruleNodeUiforwardUrl = forwardUrl;
20 20
21 21 const PROXY_CONFIG = {
... ...
... ... @@ -324,9 +324,8 @@ export class RuleChainService {
324 324 return this.http.get<Array<RuleChain>>(`/api/ruleChain/defaultEdgeRuleChains`, defaultHttpOptionsFromConfig(config));
325 325 }
326 326
327   - public setEdgeRootRuleChain(edgeId: string, ruleChainId: string, config?: RequestConfig): Observable<Edge> { //TODO deaflynx EdgeInfo vs. Edge check usage
328   - return this.http.post<Edge>(`/api/edge/${edgeId}/${ruleChainId}/root`,
329   - defaultHttpOptionsFromConfig(config));
  327 + public setEdgeRootRuleChain(edgeId: string, ruleChainId: string, config?: RequestConfig): Observable<Edge> {
  328 + return this.http.post<Edge>(`/api/edge/${edgeId}/${ruleChainId}/root`, defaultHttpOptionsFromConfig(config));
330 329 }
331 330
332 331 }
... ...
... ... @@ -52,7 +52,13 @@ import { NULL_UUID } from '@shared/models/id/has-uuid';
52 52 import { WidgetsBundle } from '@shared/models/widgets-bundle.model';
53 53 import { ImportEntitiesResultInfo, ImportEntityData } from '@shared/models/entity.models';
54 54 import { RequestConfig } from '@core/http/http-utils';
55   -import { RuleChain, RuleChainImport, RuleChainMetaData } from '@shared/models/rule-chain.models';
  55 +import {
  56 + RuleChain,
  57 + RuleChainImport,
  58 + RuleChainMetaData,
  59 + RuleChainType,
  60 + ruleChainType
  61 +} from '@shared/models/rule-chain.models';
56 62 import { RuleChainService } from '@core/http/rule-chain.service';
57 63 import * as JSZip from 'jszip';
58 64 import { FiltersInfo } from '@shared/models/query/query.models';
... ... @@ -397,7 +403,7 @@ export class ImportExportService {
397 403 );
398 404 }
399 405
400   - public importRuleChain(): Observable<RuleChainImport> {
  406 + public importRuleChain(expectedRuleChainType: RuleChainType): Observable<RuleChainImport> {
401 407 return this.openImportDialog('rulechain.import', 'rulechain.rulechain-file').pipe(
402 408 mergeMap((ruleChainImport: RuleChainImport) => {
403 409 if (!this.validateImportedRuleChain(ruleChainImport)) {
... ... @@ -405,6 +411,11 @@ export class ImportExportService {
405 411 {message: this.translate.instant('rulechain.invalid-rulechain-file-error'),
406 412 type: 'error'}));
407 413 throw new Error('Invalid rule chain file');
  414 + } else if (ruleChainImport.ruleChain.type !== expectedRuleChainType) {
  415 + this.store.dispatch(new ActionNotificationShow(
  416 + {message: this.translate.instant('rulechain.invalid-rulechain-type-error', { expectedRuleChainType: expectedRuleChainType }),
  417 + type: 'error'}));
  418 + throw new Error('Invalid rule chain file');
408 419 } else {
409 420 return this.ruleChainService.resolveRuleChainMetadata(ruleChainImport.metadata).pipe(
410 421 map((resolvedMetadata) => {
... ... @@ -458,6 +469,9 @@ export class ImportExportService {
458 469 || isUndefined(ruleChainImport.ruleChain.name)) {
459 470 return false;
460 471 }
  472 + if (isUndefined(ruleChainImport.ruleChain.type)) {
  473 + ruleChainImport.ruleChain.type = ruleChainType.core;
  474 + }
461 475 return true;
462 476 }
463 477
... ...
... ... @@ -14,39 +14,40 @@
14 14 /// limitations under the License.
15 15 ///
16 16
17   -import { Injectable } from '@angular/core';
  17 +import {Injectable} from '@angular/core';
18 18
19   -import {ActivatedRouteSnapshot, Resolve, Route, Router} from '@angular/router';
  19 +import {ActivatedRouteSnapshot, Resolve, Router} from '@angular/router';
20 20 import {
21 21 CellActionDescriptor,
22 22 checkBoxCell,
23   - DateEntityTableColumn, EntityColumn,
  23 + DateEntityTableColumn,
  24 + EntityColumn,
24 25 EntityTableColumn,
25 26 EntityTableConfig,
26   - GroupActionDescriptor, HeaderActionDescriptor
  27 + GroupActionDescriptor,
  28 + HeaderActionDescriptor
27 29 } from '@home/models/entity/entities-table-config.models';
28   -import { TranslateService } from '@ngx-translate/core';
29   -import { DatePipe } from '@angular/common';
30   -import { EntityType, entityTypeResources, entityTypeTranslations } from '@shared/models/entity-type.models';
31   -import { EntityAction } from '@home/models/entity/entity-component.models';
32   -import { RuleChain, ruleChainType } from '@shared/models/rule-chain.models';
33   -import { RuleChainService } from '@core/http/rule-chain.service';
34   -import { RuleChainComponent } from '@modules/home/pages/rulechain/rulechain.component';
35   -import { DialogService } from '@core/services/dialog.service';
36   -import { RuleChainTabsComponent } from '@home/pages/rulechain/rulechain-tabs.component';
37   -import { ImportExportService } from '@home/components/import-export/import-export.service';
38   -import { ItemBufferService } from '@core/services/item-buffer.service';
39   -import { EdgeService } from "@core/http/edge.service";
40   -import {map, mergeMap} from "rxjs/operators";
41   -import { forkJoin, Observable } from "rxjs";
  30 +import {TranslateService} from '@ngx-translate/core';
  31 +import {DatePipe} from '@angular/common';
  32 +import {EntityType, entityTypeResources, entityTypeTranslations} from '@shared/models/entity-type.models';
  33 +import {EntityAction} from '@home/models/entity/entity-component.models';
  34 +import {RuleChain, ruleChainType} from '@shared/models/rule-chain.models';
  35 +import {RuleChainService} from '@core/http/rule-chain.service';
  36 +import {RuleChainComponent} from '@modules/home/pages/rulechain/rulechain.component';
  37 +import {DialogService} from '@core/services/dialog.service';
  38 +import {RuleChainTabsComponent} from '@home/pages/rulechain/rulechain-tabs.component';
  39 +import {ImportExportService} from '@home/components/import-export/import-export.service';
  40 +import {ItemBufferService} from '@core/services/item-buffer.service';
  41 +import {EdgeService} from "@core/http/edge.service";
  42 +import {forkJoin, Observable} from "rxjs";
42 43 import {
43 44 AddEntitiesToEdgeDialogComponent,
44 45 AddEntitiesToEdgeDialogData
45 46 } from "@home/dialogs/add-entities-to-edge-dialog.component";
46   -import { MatDialog } from "@angular/material/dialog";
47   -import { isDefined, isUndefined } from "@core/utils";
48   -import { PageLink } from "@shared/models/page/page-link";
49   -import { Edge } from "@shared/models/edge.models";
  47 +import {MatDialog} from "@angular/material/dialog";
  48 +import {isDefined, isUndefined} from "@core/utils";
  49 +import {PageLink} from "@shared/models/page/page-link";
  50 +import {Edge} from "@shared/models/edge.models";
50 51
51 52 @Injectable()
52 53 export class RuleChainsTableConfigResolver implements Resolve<EntityTableConfig<RuleChain>> {
... ... @@ -267,7 +268,8 @@ export class RuleChainsTableConfigResolver implements Resolve<EntityTableConfig<
267 268 if ($event) {
268 269 $event.stopPropagation();
269 270 }
270   - this.importExport.importRuleChain().subscribe((ruleChainImport) => {
  271 + const expectedRuleChainType = this.config.componentsData.ruleChainScope === 'tenant' ? ruleChainType.core : ruleChainType.edge;
  272 + this.importExport.importRuleChain(expectedRuleChainType).subscribe((ruleChainImport) => {
271 273 if (ruleChainImport) {
272 274 this.itembuffer.storeRuleChainImport(ruleChainImport);
273 275 this.router.navigateByUrl(`${this.router.routerState.snapshot.url}/ruleChain/import`);
... ...