b608312384588b7759431289107fb70637b64a76
[ccsdk/cds.git] /
1 /*
2 ============LICENSE_START==========================================
3 ===================================================================
4 Copyright (C) 2019 Orange. All rights reserved.
5 ===================================================================
6
7 Unless otherwise specified, all software contained herein is licensed
8 under the Apache License, Version 2.0 (the License);
9 you may not use this software except in compliance with the License.
10 You may obtain a copy of the License at
11
12     http://www.apache.org/licenses/LICENSE-2.0
13
14 Unless required by applicable law or agreed to in writing, software
15 distributed under the License is distributed on an "AS IS" BASIS,
16 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 See the License for the specific language governing permissions and
18 limitations under the License.
19 ============LICENSE_END============================================
20 */
21
22 import {Injectable} from '@angular/core';
23
24 import {Store} from '../../../../common/core/stores/Store';
25
26 import {CBAPackage, DslDefinition} from './mapping-models/CBAPacakge.model';
27 import {PackageCreationService} from './package-creation.service';
28 import {MetaDataTabModel} from './mapping-models/metadata/MetaDataTab.model';
29 import {Observable} from 'rxjs';
30 import {ResourceDictionary} from './mapping-models/ResourceDictionary.model';
31 import {BluePrintDetailModel} from '../model/BluePrint.detail.model';
32 import {TemplateTopology} from './mapping-models/definitions/VlbDefinition';
33
34
35 @Injectable({
36     providedIn: 'root'
37 })
38 export class PackageCreationStore extends Store<CBAPackage> {
39
40
41     constructor(private packageCreationService: PackageCreationService) {
42         super(new CBAPackage());
43     }
44
45     changeMetaData(metaDataObject: MetaDataTabModel) {
46
47         this.setState({
48             ...this.state,
49             metaData: metaDataObject
50         });
51     }
52
53     setCustomKeys(mapOfCustomKey: Map<string, string>) {
54         this.setState({
55             ...this.state,
56             metaData: this.state.metaData.setCustomKey(mapOfCustomKey)
57         });
58     }
59
60     istemplateExist(): boolean {
61         return this.state.templates.files.size > 0 && this.state.mapping.files.size > 0;
62     }
63
64     changeDslDefinition(dslDefinition: DslDefinition) {
65
66         this.setState({
67             ...this.state,
68             definitions: this.state.definitions.setDslDefinition(dslDefinition)
69         });
70     }
71
72
73     addDefinition(name: string, content: string) {
74
75         this.setState({
76             ...this.state,
77             definitions: this.state.definitions.setImports(name, content)
78         });
79     }
80
81     addScripts(name: string, content: string) {
82         this.setState({
83             ...this.state,
84             scripts: this.state.scripts.setScripts(name, content)
85         });
86
87     }
88
89     removeFileFromState(name: string) {
90         this.state.scripts.files.delete(name);
91     }
92
93     fileExist(key: string) {
94         return this.state.templates.files.has(key);
95     }
96
97     removeFileFromDefinition(filename) {
98         this.state.definitions.imports.delete(filename);
99     }
100
101     saveBluePrint(blob): Observable<BluePrintDetailModel> {
102         return this.packageCreationService.savePackage(blob);
103     }
104
105     enrichBluePrint(blob): Observable<any> {
106         return this.packageCreationService.enrichPackage(blob);
107     }
108
109     deployBluePrint(blob): Observable<BluePrintDetailModel> {
110         return this.packageCreationService.deploy(blob);
111     }
112
113     addTemplate(filePath: string, fileContent: string) {
114         this.setState({
115             ...this.state,
116             templates: this.state.templates.setTemplates(filePath, fileContent)
117         });
118     }
119
120     addMapping(filePath: string, fileContent: string) {
121         this.setState({
122             ...this.state,
123             mapping: this.state.mapping.setContent(filePath, fileContent)
124         });
125     }
126
127     getTemplateAndMapping(variables: string[]): Observable<ResourceDictionary[]> {
128         return this.packageCreationService.getTemplateAndMapping(variables);
129     }
130
131     clear() {
132         this.setState(new CBAPackage());
133     }
134
135     setEntryDefinition(data: string) {
136         console.log('setting manual enrichment ');
137     }
138
139     addTopologyTemplate(templateTopology: TemplateTopology) {
140         this.setState({
141             ...this.state,
142             templateTopology
143         });
144     }
145 }