6d980190eefa231fa56547a32c2a5205b05a221a
[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 = false;
19         mapping.dictionarySource = this.dependanciesSource.get(mapping.name);
20         if (this.dependancies.get(mapping.name)) {
21             mapping.dependencies = this.dependancies.get(mapping.name);
22         } else {
23             mapping.dependencies = [];
24         }
25         mapping.version = 0;
26         return mapping;
27     }
28 }
29
30 @JsonObject('Mapping')
31 export class Mapping {
32     @JsonProperty('name')
33     name: string;
34     @JsonProperty()
35     property: any;
36     @JsonProperty('input-param', Boolean)
37     inputParam: boolean;
38     @JsonProperty('dictionary-name')
39     dictionaryName: string;
40     @JsonProperty('dictionary-source')
41     dictionarySource: string;
42     @JsonProperty()
43     dependencies: string[];
44     @JsonProperty()
45     version: number;
46 }