Skip to content

Commit

Permalink
change step-testing
Browse files Browse the repository at this point in the history
  • Loading branch information
ck-c8y committed Dec 20, 2024
1 parent 2b9e731 commit e2f6d12
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 66 deletions.
2 changes: 1 addition & 1 deletion dynamic-mapping-ui/src/mapping/core/c8y-agent.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ export class C8YAgent {
// );
}

const currentRequest = context.requests[context.requests.length-1];
const currentRequest = context.requests?.slice(-1)[0] ?? null;
const device: Partial<IManagedObject> = {
c8y_IsDevice: {},
[MAPPING_TEST_DEVICE_FRAGMENT]: {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,35 @@ export abstract class PayloadProcessorInbound {
), repairStrategy: RepairStrategy.DEFAULT, type: SubstituteValueType.TEXTUAL
};
} catch (e) {
// console.log(
// `External id ${identity.externalId} doesn't exist! Just return original id ${identity.externalId} `
// );
// here we create a mock device to tesing locally

Check warning on line 152 in dynamic-mapping-ui/src/mapping/core/processor/payload-processor-inbound.service.ts

View workflow job for this annotation

GitHub Actions / Spell Check with Typos

"tesing" should be "testing".
try {
const request = {
c8y_IsDevice: {},
name: `device_${mapping.externalIdType}_${substitute.value}`,
d11r_device_generatedType: {},
[MAPPING_TEST_DEVICE_FRAGMENT]: {},
type: MAPPING_TEST_DEVICE_TYPE
};
const newPredecessor = context.requests.push({
predecessor: predecessor,
method: 'POST',
source: device.value,
externalIdType: mapping.externalIdType,
request,
targetAPI: API.INVENTORY.name
});
const response = await this.c8yClient.upsertDevice(
{
externalId: substitute.value.toString(),
type: mapping.externalIdType
},
context
);
context.requests[newPredecessor - 1].response = response;
substitute.value = response.id as any;
} catch (e) {
console.log ("Error", e);
}
}
if (!sourceId.value && mapping.createNonExistingDevice) {
const request = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,11 @@ export class MappingStepTestingComponent implements OnInit, OnDestroy {
results: [],
selectedResult: -1
};
testMapping: Mapping;

selectedResult$: BehaviorSubject<number> = new BehaviorSubject<number>(0);
sourceSystem: string;
targetSystem: string;
currentContext: any;
editorOptionsTesting: any = {
mode: 'tree',
removeModes: ['text', 'table'],
Expand Down Expand Up @@ -112,17 +112,13 @@ export class MappingStepTestingComponent implements OnInit, OnDestroy {
// this.stepperConfiguration
// );

this.editorTestingPayloadTemplateEmitter.subscribe((current) => {
// prepare local data
this.currentContext = current;
this.currentContext.mapping.sourceTemplate = JSON.stringify(current.sourceTemplate);
this.currentContext.mapping.targetTemplate = JSON.stringify(current.targetTemplate);
this.editorTestingPayloadTemplateEmitter.subscribe((testMapping) => {
this.testMapping = testMapping;
// prepare local data add c8y data for testing: source.id
this.sourceTemplate = JSON.parse(testMapping.sourceTemplate);
if (testMapping.direction == Direction.OUTBOUND) patchC8YTemplateForTesting(this.sourceTemplate, this.testMapping);

// add c8y data for testing: source.id
this.sourceTemplate = _.clone(current.sourceTemplate);
if (this.currentContext.mapping.direction == Direction.OUTBOUND) patchC8YTemplateForTesting(this.sourceTemplate, this.currentContext.mapping);

this.testContext = this.mappingService.initializeContext(this.currentContext.mapping);
this.testContext = this.mappingService.initializeContext(testMapping);
const editorTestingRequestRef =
this.elementRef.nativeElement.querySelector('#editorTestingRequest');
if (editorTestingRequestRef != null) {
Expand Down Expand Up @@ -194,7 +190,7 @@ export class MappingStepTestingComponent implements OnInit, OnDestroy {
}

onResetTransformation() {
patchC8YTemplateForTesting(this.sourceTemplate, this.currentContext.mapping);
patchC8YTemplateForTesting(this.sourceTemplate, this.testMapping);
this.testingModel = {
payload: this.sourceTemplate,
results: [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -643,7 +643,10 @@ export class MappingStepperComponent implements OnInit, OnDestroy {
this.editorTargetStepSubstitution.set(this.targetTemplate);
this.updateSubstitutionValid();
this.onSelectSubstitution(0);
this.editorTestingPayloadTemplateEmitter.emit({ mapping: this.mapping, sourceTemplate: this.sourceTemplate, targetTemplate: this.targetTemplate });
const testMapping = _.clone(this.mapping);
testMapping.sourceTemplate = JSON.stringify(this.sourceTemplate);
testMapping.targetTemplate = JSON.stringify(this.targetTemplate);
this.editorTestingPayloadTemplateEmitter.emit(testMapping);
// this.step == 'Select templates'
} else if (index == STEP_TEST_MAPPING) {
// console.log("Step 4: onStepChange targetTemplate ", this.mapping.targetTemplate);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,26 +74,6 @@
</button>
</div>
</c8y-form-group>

<!-- <c8y-form-group *ngIf="mapping.direction === Direction.OUTBOUND">
<label class="c8y-switch d-inline" title="Resolve to externalId" style="padding-top: 6px">
<input type="checkbox" formControlName="resolve2ExternalId" />
<span></span>
<span>
{{ 'Resolve to externalId' | translate }}
</span>
</label>
<div class="d-inline">
<ng-template #popTemplateResolve>
Resolve system Cumulocity Id to externalId using externalIdType.
This can only be used for OUTBOUND mappings.
</ng-template>
<button class="btn-clean text-primary" [popover]="popTemplateResolve" popoverTitle="Resolve to externalId"
placement="right" triggers="focus" type="button">
<i c8yIcon="question-circle-o"></i>
</button>
</div>
</c8y-form-group> -->
<c8y-form-group>
<label><span>Repair strategy</span>
<span> &nbsp;</span>
Expand All @@ -108,7 +88,7 @@
<div class="c8y-select-wrapper">
<select class="form-control" formControlName="repairStrategy" name="repairStrategy">
<option [value]="t.value" *ngFor="let t of repairStrategyOptions">
{{ t.label }}
{{ t.label | formatStringAsWords}}
</option>
</select>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
{{ sub.expandArray ? 'on' : 'off' }}
</td>
<td>
{{ sub.repairStrategy }}
{{ sub.repairStrategy | formatStringAsWords }}
</td>
<td width="8%">
<button
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,33 +66,6 @@
</c8y-form-group>
</div>
</c8y-action-bar-item>
<!-- <div class="d-flex d-col bg-inherit content-fullpage bg-gray-white">
<div class="card-header large-padding separator sticky-top">
<span class="card-title" translate>
Mapping service events
</span>
</div>
<div class="page-sticky-header hidden-xs c8y-list__item c8y-list--timeline">
<div class="d-flex">
<div class="c8y-list--timeline__item__date">
<p class="m-0 text-medium text-truncate" title="Date">
Date
</p>
</div>
<div class="c8y-list__item__block flex-grow">
<div class="c8y-list__item__body">
<div class="d-flex">
<div class="col-md-2">Event type</div>
<div class="col-md-2">Connector</div>
<div class="col-md-8">Message</div>
</div>
</div>
</div>
</div>
</div>
</div> -->

<div class="card-header large-padding separator sticky-top">
<span class="card-title" translate>
Expand Down

0 comments on commit e2f6d12

Please sign in to comment.