Catalog alignment
[sdc.git] / catalog-ui / src / app / models / modules / base-module.ts
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 /**
22  * Created by obarda on 6/30/2016.
23  */
24 /**
25  * Created by obarda on 2/4/2016.
26  */
27 'use strict';
28 import * as _ from "lodash";
29 import {PropertyModel} from "../properties";
30 import {ArtifactModel} from "../artifacts";
31 import {CommonUtils} from "../../utils/common-utils";
32
33 export class Module {
34
35     public name:string;
36     public groupUUID:string;
37     public invariantUUID:string;
38     public propertyValueCounter:number;
39     public type:string;
40     public typeUid:string;
41     public uniqueId:string;
42     public version:string;
43     public artifacts:Array<string> | Array<ArtifactModel>;
44     public artifactsUuid:Array<string>;
45     public properties:Array<PropertyModel>;
46     public members:Map<string, string>;
47     public customizationUUID:string;
48     public groupInstanceUniqueId:string; // This will only have a value if this is a group instance
49
50     constructor(module?:Module) {
51         if (module) {   
52             this.name = module.name;
53             this.groupUUID = module.groupUUID;
54             this.invariantUUID = module.invariantUUID;
55             this.propertyValueCounter = module.propertyValueCounter;
56             this.type = module.type;
57             this.typeUid = module.typeUid;
58             this.uniqueId = module.uniqueId;
59             this.version = module.version;
60             this.artifacts = module.artifacts;
61             this.artifactsUuid = module.artifactsUuid;
62             this.properties = CommonUtils.initProperties(module.properties);
63             this.members = module.members;
64             this.customizationUUID = module.customizationUUID;
65             this.groupInstanceUniqueId = module.groupInstanceUniqueId;
66             this.name = this.name.replace(/:/g, '..');
67
68         }
69     }
70 }
71
72 export class DisplayModule extends Module {
73
74     isBase:string;
75     artifacts:Array<ArtifactModel>;
76
77     //custom properties
78     public vfInstanceName:string;
79     public heatName:string;
80     public moduleName:string;
81     public customizationUUID:string;
82
83
84     constructor(displayModule?:DisplayModule) {
85         super(displayModule);
86
87         this.isBase = displayModule.isBase;
88         this.customizationUUID = displayModule.customizationUUID;
89         this.initArtifactsForDisplay(displayModule.artifacts);
90
91         //splitting module name for display and edit
92         let splitName:Array<string> = this.name.split('..');
93         this.vfInstanceName = splitName[0];
94         this.heatName = splitName[1];
95         this.moduleName = splitName[2];
96     }
97
98     private initArtifactsForDisplay = (artifacts:Array<ArtifactModel>):void => {
99         this.artifacts = new Array<ArtifactModel>();
100         _.forEach(artifacts, (artifact:ArtifactModel) => {
101             this.artifacts.push(new ArtifactModel(artifact));
102         });
103     };
104
105     public updateName = ():void => {
106         this.name = this.vfInstanceName + '..' + this.heatName + '..' + this.moduleName;
107     };
108
109     public toJSON = ():any => {
110         this.vfInstanceName = undefined;
111         this.heatName = undefined;
112         this.moduleName = undefined;
113         this.isBase = undefined;
114         this.artifacts = undefined;
115         return this;
116     };
117 }