Skip to content

Commit

Permalink
use different schema for inventory depending for the testing editor
Browse files Browse the repository at this point in the history
  • Loading branch information
ck-c8y committed Nov 28, 2024
1 parent 39142ee commit 1bc81b3
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,6 @@ <h6>
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">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import {
import { MappingService } from '../core/mapping.service';
import { C8YRequest } from '../processor/processor.model';
import { StepperConfiguration } from 'src/shared/model/shared.model';
import { expandC8YTemplate, expandExternalTemplate, isDisabled } from '../shared/util';
import { isDisabled } from '../shared/util';

@Component({
selector: 'd11r-mapping-testing',
Expand Down Expand Up @@ -120,7 +120,7 @@ export class MappingStepTestingComponent implements OnInit, OnDestroy {
if (editorTestingRequestRef != null) {
// set schema for editors
this.editorTestingRequest.setSchema(
getSchema(this.mapping.targetAPI, this.mapping.direction, true)
getSchema(this.mapping.targetAPI, this.mapping.direction, true, true)
);
this.testingModel = {
payload: this.source,
Expand Down Expand Up @@ -219,7 +219,7 @@ export class MappingStepTestingComponent implements OnInit, OnDestroy {
getSchema(
this.testingModel.results[this.testingModel.selectedResult].targetAPI,
this.mapping.direction,
true
true, true
)
);
this.testingModel.errorMsg =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -378,13 +378,13 @@ export class MappingStepperComponent implements OnInit, OnDestroy {

onEditorSourceInitialized() {
this.schemaUpdateSource.emit(
getSchema(this.mapping.targetAPI, this.mapping.direction, false)
getSchema(this.mapping.targetAPI, this.mapping.direction, false, false)
);
}

onEditorTargetInitialized() {
this.schemaUpdateTarget.emit(
getSchema(this.mapping.targetAPI, this.mapping.direction, true)
getSchema(this.mapping.targetAPI, this.mapping.direction, true, false)
);
}

Expand Down Expand Up @@ -734,13 +734,13 @@ export class MappingStepperComponent implements OnInit, OnDestroy {
this.mapping.target = SAMPLE_TEMPLATES_C8Y[changedTargetAPI];
this.mapping.source = getExternalTemplate(this.mapping);
this.schemaUpdateTarget.emit(
getSchema(this.mapping.targetAPI, this.mapping.direction, true)
getSchema(this.mapping.targetAPI, this.mapping.direction, true, false)
);
} else {
this.mapping.source = SAMPLE_TEMPLATES_C8Y[changedTargetAPI];
this.mapping.target = getExternalTemplate(this.mapping);
this.schemaUpdateSource.emit(
getSchema(this.mapping.targetAPI, this.mapping.direction, false)
getSchema(this.mapping.targetAPI, this.mapping.direction, false, false)
);
}
}
Expand Down
42 changes: 38 additions & 4 deletions dynamic-mapping-ui/src/shared/model/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,38 @@ export const SCHEMA_INVENTORY = {
}
};

export const SCHEMA_C8Y_INVENTORY = {
definitions: {},
$schema: 'http://json-schema.org/draft-07/schema#',
$id: 'http://example.com/root.json',
type: 'object',
title: 'INVENTORY',
required: ['c8y_IsDevice', 'type', 'name'],
properties: {
c8y_IsDevice: {
$id: '#/properties/c8y_IsDevice',
type: 'object',
title: 'Mark as device.',
properties: {}
},
type: {
$id: '#/properties/type',
type: 'string',
title: 'Type of the device.'
},
name: {
$id: '#/properties/name',
type: 'string',
title: 'Name of the device.'
},
id: {
$id: '#/properties/id',
type: 'string',
title: 'Cumulocity id of the device.',
}
}
};

export const SCHEMA_OPERATION = {
definitions: {},
$schema: 'http://json-schema.org/draft-07/schema#',
Expand Down Expand Up @@ -328,11 +360,12 @@ export function getExternalTemplate(mapping: Mapping): any {
export function getSchema(
targetAPI: string,
direction: Direction,
target: boolean
isTarget: boolean,
isTesting: boolean
): any {
if (
(target && (!direction || direction == Direction.INBOUND)) ||
(!target && direction == Direction.OUTBOUND)
(isTarget && direction == Direction.INBOUND) ||
(!isTarget && direction == Direction.OUTBOUND)
) {
if (targetAPI == API.ALARM.name) {
return SCHEMA_ALARM;
Expand All @@ -341,7 +374,8 @@ export function getSchema(
} else if (targetAPI == API.MEASUREMENT.name) {
return SCHEMA_MEASUREMENT;
} else if (targetAPI == API.INVENTORY.name) {
return SCHEMA_INVENTORY;
if (isTarget) return SCHEMA_C8Y_INVENTORY;
else return SCHEMA_INVENTORY
} else {
return SCHEMA_OPERATION;
}
Expand Down

0 comments on commit 1bc81b3

Please sign in to comment.