diff --git a/dynamic-mapping-ui/src/mapping/processor/payload-processor-inbound.service.ts b/dynamic-mapping-ui/src/mapping/processor/payload-processor-inbound.service.ts index e58d7a1bb..6e6ab503d 100644 --- a/dynamic-mapping-ui/src/mapping/processor/payload-processor-inbound.service.ts +++ b/dynamic-mapping-ui/src/mapping/processor/payload-processor-inbound.service.ts @@ -126,11 +126,11 @@ export abstract class PayloadProcessorInbound { mapping.mapDeviceIdentifier ) { let sourceId: string; - const identity = { - externalId: substituteValue.value.toString(), - type: mapping.externalIdType - }; try { + const identity = { + externalId: substituteValue.value.toString(), + type: mapping.externalIdType + }; sourceId = await this.c8yClient.resolveExternalId2GlobalId( identity, context diff --git a/dynamic-mapping-ui/src/mapping/step-testing/mapping-testing.component.ts b/dynamic-mapping-ui/src/mapping/step-testing/mapping-testing.component.ts index cca9242c6..5a73a9d34 100644 --- a/dynamic-mapping-ui/src/mapping/step-testing/mapping-testing.component.ts +++ b/dynamic-mapping-ui/src/mapping/step-testing/mapping-testing.component.ts @@ -73,7 +73,7 @@ export class MappingStepTestingComponent implements OnInit, OnDestroy { selectedResult$: BehaviorSubject = new BehaviorSubject(0); sourceSystem: string; targetSystem: string; - currentSourceTemplate: any; + currentMapping: any; editorOptionsTesting: any = {}; @ViewChild('editorTestingPayload', { static: false }) @@ -111,8 +111,8 @@ export class MappingStepTestingComponent implements OnInit, OnDestroy { readOnly: true }; - this.editorTestingPayloadTemplateEmitter.subscribe((template) => { - this.currentSourceTemplate = template; + this.editorTestingPayloadTemplateEmitter.subscribe((current) => { + this.currentMapping = current; const editorTestingRequestRef = this.elementRef.nativeElement.querySelector('#editorTestingRequest'); if (editorTestingRequestRef != null) { @@ -121,7 +121,7 @@ export class MappingStepTestingComponent implements OnInit, OnDestroy { getSchema(this.mapping.targetAPI, this.mapping.direction, true) ); this.testingModel = { - payload: this.currentSourceTemplate, + payload: JSON.parse(this.currentMapping.source), results: [], selectedResult: -1, request: {}, @@ -134,7 +134,7 @@ export class MappingStepTestingComponent implements OnInit, OnDestroy { async onTestTransformation() { const testProcessingContext = await this.mappingService.testResult( - this.mapping, + this.currentMapping, false ); this.testingModel.results = testProcessingContext.requests; @@ -185,7 +185,7 @@ export class MappingStepTestingComponent implements OnInit, OnDestroy { onResetTransformation() { this.testingModel = { - payload: this.currentSourceTemplate, + payload: this.currentMapping, results: [], request: {}, response: {}, diff --git a/dynamic-mapping-ui/src/mapping/stepper-mapping/mapping-stepper.component.html b/dynamic-mapping-ui/src/mapping/stepper-mapping/mapping-stepper.component.html index 63aa983b2..bb6f4017e 100644 --- a/dynamic-mapping-ui/src/mapping/stepper-mapping/mapping-stepper.component.html +++ b/dynamic-mapping-ui/src/mapping/stepper-mapping/mapping-stepper.component.html @@ -681,7 +681,7 @@

[editorTestingPayloadTemplateEmitter]=" editorTestingPayloadTemplateEmitter " - [mapping]="getCurrentMapping(true)" + [mapping]="mapping" (testResult)="updateTestResult($event)" [stepperConfiguration]="stepperConfiguration" > diff --git a/dynamic-mapping-ui/src/mapping/stepper-mapping/mapping-stepper.component.ts b/dynamic-mapping-ui/src/mapping/stepper-mapping/mapping-stepper.component.ts index e741854f0..d46f4c04d 100644 --- a/dynamic-mapping-ui/src/mapping/stepper-mapping/mapping-stepper.component.ts +++ b/dynamic-mapping-ui/src/mapping/stepper-mapping/mapping-stepper.component.ts @@ -516,24 +516,10 @@ export class MappingStepperComponent implements OnInit, OnDestroy { // eslint-disable-next-line @typescript-eslint/no-unused-vars onTemplateSourceChanged(content: Content) { - // if (_.has(content, 'text') && content['text']) { - // this.templateSource = JSON.parse(content['text']); - // // this.mapping.source = content['text'];‚ - // } else { - // this.templateSource = content['json']; - // // this.mapping.source = JSON.stringify(content['json']); - // } } // eslint-disable-next-line @typescript-eslint/no-unused-vars onTemplateTargetChanged(content: Content) { - // if (_.has(content, 'text') && content['text']) { - // this.templateTarget = JSON.parse(content['text']); - // // this.mapping.target = content['text']; - // } else { - // this.templateTarget = content['json']; - // // this.mapping.target = JSON.stringify(content['json']); - // } } async updateTargetExpressionResult() { @@ -584,7 +570,7 @@ export class MappingStepperComponent implements OnInit, OnDestroy { } getCurrentMapping(patched: boolean): Mapping { - return { + const current = { ...this.mapping, source: reduceSourceTemplate( this.editorSourceStep4 ? this.editorSourceStep4?.get() : {}, @@ -593,10 +579,11 @@ export class MappingStepperComponent implements OnInit, OnDestroy { target: reduceTargetTemplate(this.editorTargetStep4?.get(), patched), // remove patched attributes, since it should not be stored lastUpdate: Date.now() }; + return current; } async onCommitButton() { - this.commit.emit(this.getCurrentMapping(false)); + // this.commit.emit(this.getCurrentMapping(false)); } async onSampleTargetTemplatesButton() { @@ -676,17 +663,7 @@ export class MappingStepperComponent implements OnInit, OnDestroy { } } else if (this.step == 'General settings') { this.templateModel.mapping = this.mapping; - // console.log( - // 'Populate jsonPath if wildcard:', - // isWildcardTopic(this.mapping.direction == Direction.INBOUND? this.mapping.subscriptionTopic :this.mapping.publishTopic ), - // this.mapping.substitutions.length - // ); - // console.log( - // 'Templates from mapping:', - // this.mapping.target, - // this.mapping.source, - // this.mapping - // ); + this.expandTemplates(); this.extensions = (await this.extensionService.getProcessorExtensions()) as any; @@ -704,13 +681,8 @@ export class MappingStepperComponent implements OnInit, OnDestroy { } event.stepper.next(); } else if (this.step == 'Define substitutions') { - this.expandTemplates(); this.getTemplateForm(); - // const testSourceTemplate = this.editorSourceStep4 - // ? this.editorSourceStep4.get() - // : {}; - // this.editorTestingPayloadTemplateEmitter.emit(testSourceTemplate); - this.editorTestingPayloadTemplateEmitter.emit(this.templateSource); + this.editorTestingPayloadTemplateEmitter.emit(this.getCurrentMapping(true)); this.onSelectSubstitution(0); event.stepper.next(); } else if (this.step == 'Select templates') { @@ -721,7 +693,7 @@ export class MappingStepperComponent implements OnInit, OnDestroy { event.step.label, this.mapping, this.editorSourceStep3?.get(), - this.getCurrentMapping(true), + //this.getCurrentMapping(true), this.templateSource, this.templateTarget ); @@ -735,15 +707,7 @@ export class MappingStepperComponent implements OnInit, OnDestroy { stepper: C8yStepper; step: CdkStep; }): Promise { - // console.log( - // 'onBackStep before', - // event.step.label, - // this.mapping, - // this.getCurrentMapping(false), - // this.getCurrentMapping(true), - // this.templateSource, - // this.templateTarget - // ); + this.step = event.step.label; if (this.step == 'Test mapping') { const editorTestingRequestRef = @@ -751,25 +715,8 @@ export class MappingStepperComponent implements OnInit, OnDestroy { if (editorTestingRequestRef != null) { editorTestingRequestRef.setAttribute('schema', undefined); } - } else if (this.step == 'Select templates') { - // this.mapping = this.getCurrentMapping(true); - // this.expandTemplates(); - } else if (this.step == 'Define substitutions') { - // this.mapping = this.getCurrentMapping(true); - // this.expandTemplates(); - } - this.mapping = this.getCurrentMapping(true); - this.expandTemplates(); - // console.log( - // 'onBackStep after', - // event.step.label, - // this.mapping, - // this.getCurrentMapping(false), - // this.getCurrentMapping(true), - // this.templateSource, - // this.templateTarget - // ); + } event.stepper.previous(); }