e63b17fa270163aec25ec44ac359908dacb1c447
[ccsdk/cds.git] /
1 import { ResourceDictionary } from './ResourceDictionary.model';
2 import { JsonObject, JsonProperty, JsonConvert } from 'json2typescript';
3
4 // Convert ResourceDictionary object to store Mapping.
5 export class MappingAdapter {
6
7     constructor(
8         private resourceDictionary: ResourceDictionary,
9         private dependancies: Map<string, Array<string>>,
10         private dependanciesSource: Map<string, string>) { }
11
12     ToMapping(): Mapping {
13         // console.log(this.resourceDictionary.definition.property);
14         const mapping = new Mapping();
15         mapping.name = this.resourceDictionary.name;
16         mapping.dictionaryName = this.resourceDictionary.name;
17         mapping.property = Object.assign({}, this.resourceDictionary.definition.property);
18         mapping.inputParam = this.resourceDictionary['input-param'] || false;
19         // tslint:disable-next-line: no-string-literal
20         mapping.property['required'] = this.resourceDictionary['required'] || false;
21         mapping.dictionarySource = this.dependanciesSource.get(mapping.name);
22         if (this.dependancies.get(mapping.name)) {
23             mapping.dependencies = this.dependancies.get(mapping.name);
24         } else {
25             mapping.dependencies = [];
26         }
27         mapping.version = 0;
28         return mapping;
29     }
30 }
31
32 @JsonObject('Mapping')
33 export class Mapping {
34     @JsonProperty('name')
35     name: string;
36     @JsonProperty()
37     property: any;
38     @JsonProperty('input-param', Boolean)
39     inputParam: boolean;
40     @JsonProperty('dictionary-name')
41     dictionaryName: string;
42     @JsonProperty('dictionary-source')
43     dictionarySource: string;
44     @JsonProperty()
45     dependencies: string[];
46     @JsonProperty()
47     version: number;
48 }