Browse Source

Fix import with rule chain type

pull/3811/head
deaflynx 6 years ago
parent
commit
4c2effd9be
  1. 4
      ui-ngx/proxy.conf.js
  2. 5
      ui-ngx/src/app/core/http/rule-chain.service.ts
  3. 18
      ui-ngx/src/app/modules/home/components/import-export/import-export.service.ts
  4. 48
      ui-ngx/src/app/modules/home/pages/rulechain/rulechains-table-config.resolver.ts

4
ui-ngx/proxy.conf.js

@ -14,8 +14,8 @@
* limitations under the License.
*/
const forwardUrl = "http://localhost:8080";
const wsForwardUrl = "ws://localhost:8080";
const forwardUrl = "http://localhost:8081";
const wsForwardUrl = "ws://localhost:8081";
const ruleNodeUiforwardUrl = forwardUrl;
const PROXY_CONFIG = {

5
ui-ngx/src/app/core/http/rule-chain.service.ts

@ -324,9 +324,8 @@ export class RuleChainService {
return this.http.get<Array<RuleChain>>(`/api/ruleChain/defaultEdgeRuleChains`, defaultHttpOptionsFromConfig(config));
}
public setEdgeRootRuleChain(edgeId: string, ruleChainId: string, config?: RequestConfig): Observable<Edge> { //TODO deaflynx EdgeInfo vs. Edge check usage
return this.http.post<Edge>(`/api/edge/${edgeId}/${ruleChainId}/root`,
defaultHttpOptionsFromConfig(config));
public setEdgeRootRuleChain(edgeId: string, ruleChainId: string, config?: RequestConfig): Observable<Edge> {
return this.http.post<Edge>(`/api/edge/${edgeId}/${ruleChainId}/root`, defaultHttpOptionsFromConfig(config));
}
}

18
ui-ngx/src/app/modules/home/components/import-export/import-export.service.ts

@ -52,7 +52,13 @@ import { NULL_UUID } from '@shared/models/id/has-uuid';
import { WidgetsBundle } from '@shared/models/widgets-bundle.model';
import { ImportEntitiesResultInfo, ImportEntityData } from '@shared/models/entity.models';
import { RequestConfig } from '@core/http/http-utils';
import { RuleChain, RuleChainImport, RuleChainMetaData } from '@shared/models/rule-chain.models';
import {
RuleChain,
RuleChainImport,
RuleChainMetaData,
RuleChainType,
ruleChainType
} from '@shared/models/rule-chain.models';
import { RuleChainService } from '@core/http/rule-chain.service';
import * as JSZip from 'jszip';
import { FiltersInfo } from '@shared/models/query/query.models';
@ -397,7 +403,7 @@ export class ImportExportService {
);
}
public importRuleChain(): Observable<RuleChainImport> {
public importRuleChain(expectedRuleChainType: RuleChainType): Observable<RuleChainImport> {
return this.openImportDialog('rulechain.import', 'rulechain.rulechain-file').pipe(
mergeMap((ruleChainImport: RuleChainImport) => {
if (!this.validateImportedRuleChain(ruleChainImport)) {
@ -405,6 +411,11 @@ export class ImportExportService {
{message: this.translate.instant('rulechain.invalid-rulechain-file-error'),
type: 'error'}));
throw new Error('Invalid rule chain file');
} else if (ruleChainImport.ruleChain.type !== expectedRuleChainType) {
this.store.dispatch(new ActionNotificationShow(
{message: this.translate.instant('rulechain.invalid-rulechain-type-error', { expectedRuleChainType: expectedRuleChainType }),
type: 'error'}));
throw new Error('Invalid rule chain file');
} else {
return this.ruleChainService.resolveRuleChainMetadata(ruleChainImport.metadata).pipe(
map((resolvedMetadata) => {
@ -458,6 +469,9 @@ export class ImportExportService {
|| isUndefined(ruleChainImport.ruleChain.name)) {
return false;
}
if (isUndefined(ruleChainImport.ruleChain.type)) {
ruleChainImport.ruleChain.type = ruleChainType.core;
}
return true;
}

48
ui-ngx/src/app/modules/home/pages/rulechain/rulechains-table-config.resolver.ts

@ -14,39 +14,40 @@
/// limitations under the License.
///
import { Injectable } from '@angular/core';
import {Injectable} from '@angular/core';
import {ActivatedRouteSnapshot, Resolve, Route, Router} from '@angular/router';
import {ActivatedRouteSnapshot, Resolve, Router} from '@angular/router';
import {
CellActionDescriptor,
checkBoxCell,
DateEntityTableColumn, EntityColumn,
DateEntityTableColumn,
EntityColumn,
EntityTableColumn,
EntityTableConfig,
GroupActionDescriptor, HeaderActionDescriptor
GroupActionDescriptor,
HeaderActionDescriptor
} from '@home/models/entity/entities-table-config.models';
import { TranslateService } from '@ngx-translate/core';
import { DatePipe } from '@angular/common';
import { EntityType, entityTypeResources, entityTypeTranslations } from '@shared/models/entity-type.models';
import { EntityAction } from '@home/models/entity/entity-component.models';
import { RuleChain, ruleChainType } from '@shared/models/rule-chain.models';
import { RuleChainService } from '@core/http/rule-chain.service';
import { RuleChainComponent } from '@modules/home/pages/rulechain/rulechain.component';
import { DialogService } from '@core/services/dialog.service';
import { RuleChainTabsComponent } from '@home/pages/rulechain/rulechain-tabs.component';
import { ImportExportService } from '@home/components/import-export/import-export.service';
import { ItemBufferService } from '@core/services/item-buffer.service';
import { EdgeService } from "@core/http/edge.service";
import {map, mergeMap} from "rxjs/operators";
import { forkJoin, Observable } from "rxjs";
import {TranslateService} from '@ngx-translate/core';
import {DatePipe} from '@angular/common';
import {EntityType, entityTypeResources, entityTypeTranslations} from '@shared/models/entity-type.models';
import {EntityAction} from '@home/models/entity/entity-component.models';
import {RuleChain, ruleChainType} from '@shared/models/rule-chain.models';
import {RuleChainService} from '@core/http/rule-chain.service';
import {RuleChainComponent} from '@modules/home/pages/rulechain/rulechain.component';
import {DialogService} from '@core/services/dialog.service';
import {RuleChainTabsComponent} from '@home/pages/rulechain/rulechain-tabs.component';
import {ImportExportService} from '@home/components/import-export/import-export.service';
import {ItemBufferService} from '@core/services/item-buffer.service';
import {EdgeService} from "@core/http/edge.service";
import {forkJoin, Observable} from "rxjs";
import {
AddEntitiesToEdgeDialogComponent,
AddEntitiesToEdgeDialogData
} from "@home/dialogs/add-entities-to-edge-dialog.component";
import { MatDialog } from "@angular/material/dialog";
import { isDefined, isUndefined } from "@core/utils";
import { PageLink } from "@shared/models/page/page-link";
import { Edge } from "@shared/models/edge.models";
import {MatDialog} from "@angular/material/dialog";
import {isDefined, isUndefined} from "@core/utils";
import {PageLink} from "@shared/models/page/page-link";
import {Edge} from "@shared/models/edge.models";
@Injectable()
export class RuleChainsTableConfigResolver implements Resolve<EntityTableConfig<RuleChain>> {
@ -267,7 +268,8 @@ export class RuleChainsTableConfigResolver implements Resolve<EntityTableConfig<
if ($event) {
$event.stopPropagation();
}
this.importExport.importRuleChain().subscribe((ruleChainImport) => {
const expectedRuleChainType = this.config.componentsData.ruleChainScope === 'tenant' ? ruleChainType.core : ruleChainType.edge;
this.importExport.importRuleChain(expectedRuleChainType).subscribe((ruleChainImport) => {
if (ruleChainImport) {
this.itembuffer.storeRuleChainImport(ruleChainImport);
this.router.navigateByUrl(`${this.router.routerState.snapshot.url}/ruleChain/import`);

Loading…
Cancel
Save