adding import package basic functionalities
[ccsdk/cds.git] / cds-ui / designer-client / src / app / modules / feature-modules / packages / package-creation / package-creation.store.ts
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 {MetaDataTabModel} from './mapping-models/metadata/MetaDataTab.model';
28 import {TemplateTopology} from './mapping-models/definitions/VlbDefinition';
29
30
31 @Injectable({
32     providedIn: 'root'
33 })
34 export class PackageCreationStore extends Store<CBAPackage> {
35
36
37     constructor() {
38         super(new CBAPackage());
39     }
40
41     changeMetaData(metaDataObject: MetaDataTabModel) {
42
43         this.setState({
44             ...this.state,
45             metaData: metaDataObject
46         });
47     }
48
49     setCustomKeys(mapOfCustomKey: Map<string, string>) {
50         this.setState({
51             ...this.state,
52             metaData: this.state.metaData.setCustomKey(mapOfCustomKey)
53         });
54     }
55
56     istemplateExist(): boolean {
57         return this.state.templates.files.size > 0 && this.state.mapping.files.size > 0;
58     }
59
60     changeDslDefinition(dslDefinition: DslDefinition) {
61
62         this.setState({
63             ...this.state,
64             definitions: this.state.definitions.setDslDefinition(dslDefinition)
65         });
66     }
67
68
69     addDefinition(name: string, content: string) {
70
71         this.setState({
72             ...this.state,
73             definitions: this.state.definitions.setImports(name, content)
74         });
75     }
76
77     addScripts(name: string, content: string) {
78         this.setState({
79             ...this.state,
80             scripts: this.state.scripts.setScripts(name, content)
81         });
82
83     }
84
85     removeFileFromState(name: string) {
86         this.state.scripts.files.delete(name);
87     }
88
89     fileExist(key: string) {
90         return this.state.templates.files.has(key);
91     }
92
93     removeFileFromDefinition(filename) {
94         this.state.definitions.imports.delete(filename);
95     }
96
97
98     addTemplate(filePath: string, fileContent: string) {
99         this.setState({
100             ...this.state,
101             templates: this.state.templates.setTemplates(filePath, fileContent)
102         });
103     }
104
105     addMapping(filePath: string, fileContent: string) {
106         this.setState({
107             ...this.state,
108             mapping: this.state.mapping.setContent(filePath, fileContent)
109         });
110     }
111
112     clear() {
113         this.setState(new CBAPackage());
114     }
115
116     setEntryDefinition(data: string) {
117         console.log('setting manual enrichment ');
118     }
119
120     addTopologyTemplate(templateTopology: TemplateTopology) {
121         this.setState({
122             ...this.state,
123             templateTopology
124         });
125     }
126
127     getMetaData() {
128         return this.state.metaData;
129     }
130 }