Skip to content

Commit

Permalink
Merge branch 'main'
Browse files Browse the repository at this point in the history
  • Loading branch information
ck-c8y committed Nov 2, 2023
2 parents 2f10a54 + 7037734 commit 90f67cc
Show file tree
Hide file tree
Showing 12 changed files with 107 additions and 29 deletions.
2 changes: 1 addition & 1 deletion mqtt-mapping-ui/mqtt-mapping/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "mqtt-mapping",
"version": "3.3.3",
"description": "Cumulocity plugin to map custom JSON payloads to C8Y payloads.The lugin support both directions: inbound/outbound.",
"description": "Cumulocity plugin to map custom JSON payloads to C8Y payloads.The plugin support both directions: inbound/outbound.",
"repository": {
"type": "git",
"url": "[email protected]:SoftwareAG/cumulocity-dynamic-mqtt-mapper.git"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ export class C8YAgent {
private alert: AlertService
) {}


public initializeCache(): void {
this.inventory.initializeCache();
this.identity.initializeCache();
}

async createMEAO(context: ProcessingContext) {
let result: any;
let error: string = "";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import {
IExternalIdentity,
IIdentified,
IResult,
IResultList,
} from "@c8y/client";
import * as _ from "lodash";
import { ProcessingContext } from "../processor/prosessor.model";
Expand All @@ -39,6 +38,10 @@ export class FacadeIdentityService {
private identity: IdentityService
) {}

public initializeCache(): void {
this.mockIdentity.initializeCache();
}

public async resolveGlobalId2ExternalId(
managedObjectId: string,
externalIdType: string,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ export class FacadeInventoryService {
private inventory: InventoryService
) {}

public initializeCache(): void {
this.mockInventory.initializeCache();
}

public update(
managedObject: Partial<IManagedObject>,
context: ProcessingContext
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,12 @@ export class MappingService {
return this.reload$;
}

initializeCache(dir: Direction): void{
if (dir == Direction.INBOUND) {
this.jsonProcessorInbound.initializeCache();
}
}

async updateSubscriptions(sub: C8YAPISubscription): Promise<any> {
let response = this.client.fetch(
`${BASE_URL}/${PATH_SUBSCRIPTION_ENDPOINT}`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ export abstract class PayloadProcessorInbound {

public abstract extractFromSource(context: ProcessingContext): void;

public initializeCache(): void {
this.c8yClient.initializeCache();
}

protected JSONATA = require("jsonata");

public async substituteInTargetAndSend(context: ProcessingContext) {
Expand Down Expand Up @@ -114,7 +118,10 @@ export abstract class PayloadProcessorInbound {
}

if (mapping.targetAPI != API.INVENTORY.name) {
if (pathTarget == findDeviceIdentifier(mapping).pathTarget && mapping.mapDeviceIdentifier) {
if (
pathTarget == findDeviceIdentifier(mapping).pathTarget &&
mapping.mapDeviceIdentifier
) {
let sourceId: string;
const identity = {
externalId: substituteValue.value.toString(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -387,8 +387,8 @@

<cdk-step state="final" stepLabel="step3" label="Test mapping">
<mapping-testing
[editorTestingRequestTemplateEmitter]="
editorTestingRequestTemplateEmitter
[editorTestingPayloadTemplateEmitter]="
editorTestingPayloadTemplateEmitter
"
[mapping]="getCurrentMapping(true)"
(testResult)="updateTestResult($event)"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export class MappingStepperComponent implements OnInit {
templateFormly: FormGroup = new FormGroup({});
templateForm: FormGroup;
templateFormlyFields: FormlyFieldConfig[];
editorTestingRequestTemplateEmitter = new EventEmitter<any>();
editorTestingPayloadTemplateEmitter = new EventEmitter<any>();
schemaUpdateSource: EventEmitter<string> = new EventEmitter<any>();
schemaUpdateTarget: EventEmitter<string> = new EventEmitter<any>();

Expand Down Expand Up @@ -705,7 +705,7 @@ export class MappingStepperComponent implements OnInit {
const testSourceTemplate = this.editorSource
? this.editorSource.get()
: {};
this.editorTestingRequestTemplateEmitter.emit(testSourceTemplate);
this.editorTestingPayloadTemplateEmitter.emit(testSourceTemplate);
this.onSelectSubstitution(0);
event.stepper.next();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,32 @@ <h4 class="text-center text-medium">Test mapping</h4>
<div class="card-block p-b-0">
<div class="container">
<div class="row">
<div class="col-lg-10 col-lg-offset-1">
<div class="col-lg-5 col-lg-offset-1 column-right-border">
<div class="form-group">
<div style="display: flex">
<label for="testResult" translate
>Testing - {{ targetSystem }} Request&nbsp;</label
>{{ sourceSystem }} Payload&nbsp;</label
>
</div>
<mapping-json-editor2
[options]="editorOptionsTesting"
[data]="testingModel.payload"
#editorTestingPayload
id="editorTestingPayload"
>
</mapping-json-editor2>
<c8y-messages>
<c8y-message *ngIf="testingModel.errorMsg" translate
><span class="text-warning">{{ testingModel.errorMsg }}</span>
</c8y-message>
</c8y-messages>
</div>
</div>
<div class="col-lg-5 column-left-border">
<div class="form-group">
<div style="display: flex">
<label for="testResult" translate
>{{ targetSystem }} Request&nbsp;</label
>
<h6>
<span class="badge badge-success">{{
Expand All @@ -59,13 +80,19 @@ <h6>
</div>
</div>
</div>
<div class="row" [hidden]="mapping.direction == Direction.OUTBOUND">
<div class="col-lg-10 col-lg-offset-1">
<div class="legend form-block col-lg-10 col-lg-offset-1"></div>
<div
class="row"
[hidden]="mapping.direction == Direction.OUTBOUND"
>
<!-- <div class="legend form-block col-lg-10 col-lg-offset-1">
Substitutions
</div> -->
<div class="col-lg-5 col-lg-offset-1 column-right-border"></div>
<div class="col-lg-5 column-left-border">
<div class="form-group">
<div style="display: flex">
<label for="testResult" translate
>Testing - {{ targetSystem }} Response&nbsp;</label
>
<label>{{ targetSystem }} Response&nbsp;</label>
<h6>
<span class="badge badge-success">{{
selectedResult$ | async
Expand All @@ -86,7 +113,7 @@ <h6>
</div>
</div>
</div>
<div class="col-lg-6 col-lg-offset-3 text-center">
<div class="col-lg-8 col-lg-offset-2 text-center p-b-24 p-t-24">
<button
type="button"
class="btn btn-default"
Expand All @@ -108,6 +135,14 @@ <h6>
{{ testingModel.results.length }}</span
>
</button>
<button
type="button"
class="btn btn-default"
(click)="onResetTransformation()"
[attr.disabled]="isDisabled(!stepperConfiguration.allowTestTransformation)"
>
Reset Transform
</button>
<button
type="button"
class="btn btn-default"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,13 @@ export class MappingStepTestingComponent implements OnInit {
@Input() mapping: Mapping;
@Output() testResult: EventEmitter<boolean> = new EventEmitter<boolean>();
@Input() stepperConfiguration: StepperConfiguration;
@Input() editorTestingRequestTemplateEmitter: EventEmitter<any>;
@Input() editorTestingPayloadTemplateEmitter: EventEmitter<any>;

Direction = Direction;
isDisabled = isDisabled;

testingModel: {
payload?: any;
results: C8YRequest[];
errorMsg?: string;
request?: any;
Expand All @@ -68,9 +69,11 @@ export class MappingStepTestingComponent implements OnInit {
selectedResult$: BehaviorSubject<number> = new BehaviorSubject<number>(0);
sourceSystem: string;
targetSystem: string;

currentSourceTemplate: any;
editorOptionsTesting: any = {};

@ViewChild("editorTestingPayload", { static: false })
editorTestingPayload: JsonEditor2Component;
@ViewChild("editorTestingRequest", { static: false })
editorTestingRequest: JsonEditor2Component;
@ViewChild("editorTestingResponse", { static: false })
Expand Down Expand Up @@ -108,25 +111,24 @@ export class MappingStepTestingComponent implements OnInit {
readOnly: true,
};

this.editorTestingRequestTemplateEmitter.subscribe((template) => {
const editorTestingResponseRef =
this.elementRef.nativeElement.querySelector("#editorTestingResponse");
if (editorTestingResponseRef != null) {
//set schema for editors
this.editorTestingResponse.set({} as JSON);
editorTestingResponseRef.setAttribute("initialized", "true");
}

this.editorTestingPayloadTemplateEmitter.subscribe((template) => {
this.currentSourceTemplate = template;
const editorTestingRequestRef =
this.elementRef.nativeElement.querySelector("#editorTestingRequest");
if (editorTestingRequestRef != null) {
//set schema for editors
this.editorTestingRequest.setSchema(
getSchema(this.mapping.targetAPI, this.mapping.direction, true)
);
this.testingModel.request = template;
this.testingModel = {
payload: this.currentSourceTemplate,
results: [],
selectedResult: -1,
request: {},
response: {},
};
}
console.log("New test template:", template);
console.log("New test template:", this.currentSourceTemplate);
});
}

Expand Down Expand Up @@ -181,6 +183,17 @@ export class MappingStepTestingComponent implements OnInit {
this.onNextTestResult();
}

onResetTransformation() {
this.testingModel = {
payload: this.currentSourceTemplate,
results: [],
request: {},
response: {},
selectedResult: -1,
};
this.mappingService.initializeCache(this.mapping.direction);
}

public onNextTestResult() {
if (
this.testingModel.selectedResult >=
Expand All @@ -189,7 +202,7 @@ export class MappingStepTestingComponent implements OnInit {
this.testingModel.selectedResult = -1;
}
this.testingModel.selectedResult++;
this.selectedResult$.next(this.testingModel.selectedResult);
this.selectedResult$.next(this.testingModel.selectedResult + 1);
if (
this.testingModel.selectedResult >= 0 &&
this.testingModel.selectedResult < this.testingModel.results.length
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,7 @@ svg {
--jse-font-size: var(--c8y-font-size-small);
--jse-font-size-mono: var(--c8y-font-size-small);
}

.jse-main {
max-height: 300px;
}
Binary file modified resources/image/Generic_MQTT_TestTransformation.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 90f67cc

Please sign in to comment.