Initial OpenECOMP SDC commit
[sdc.git] / catalog-ui / app / scripts / utils / component-instance-factory.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  * Created by obarda on 3/7/2016.
22  */
23 /**
24  * Created by obarda on 2/8/2016.
25  */
26 /// <reference path="../references"/>
27 module Sdc.Utils {
28     'use strict';
29
30     export class ComponentInstanceFactory {
31
32         static createComponentInstance(componentInstance:Models.ComponentsInstances.ComponentInstance):Models.ComponentsInstances.ComponentInstance {
33             let newComponentInstance:Models.ComponentsInstances.ComponentInstance;
34             switch (componentInstance.originType) {
35                 case 'SERVICE':
36                     newComponentInstance = new Models.ComponentsInstances.ServiceInstance(componentInstance);
37                     break;
38
39                 case 'PRODUCT':
40                     newComponentInstance = new Models.ComponentsInstances.ProductInstance(componentInstance);
41                     break;
42
43                 default :
44                     newComponentInstance = new Models.ComponentsInstances.ResourceInstance(componentInstance);
45                     break;
46             }
47             return newComponentInstance;
48         };
49
50         public createEmptyComponentInstance = (componentInstanceType?: string):Models.ComponentsInstances.ComponentInstance => {
51             let newComponentInstance:Models.ComponentsInstances.ComponentInstance;
52             switch (componentInstanceType) {
53                 case 'SERVICE':
54                     newComponentInstance = new Models.ComponentsInstances.ServiceInstance();
55                     break;
56
57                 case 'PRODUCT':
58                     newComponentInstance = new Models.ComponentsInstances.ProductInstance();
59                     break;
60
61                 default :
62                     newComponentInstance = new Models.ComponentsInstances.ResourceInstance();
63                     break;
64             }
65             return newComponentInstance;
66         };
67
68         public createComponentInstanceFromComponent = (component: Models.Components.Component):Models.ComponentsInstances.ComponentInstance => {
69             let newComponentInstance:Models.ComponentsInstances.ComponentInstance = this.createEmptyComponentInstance(component.componentType);
70             newComponentInstance.uniqueId = component.uniqueId + (new Date()).getTime();
71             newComponentInstance.posX = 0;
72             newComponentInstance.posY = 0;
73             newComponentInstance.name = component.name;
74             newComponentInstance.componentVersion = component.version;
75             newComponentInstance.originType = component.getComponentSubType();
76             //new component instance -> req. & cap. are added on successful instance creation
77             newComponentInstance.requirements = component.requirements;
78             newComponentInstance.capabilities = component.capabilities;
79             newComponentInstance.icon = component.icon;
80             newComponentInstance.componentUid = component.uniqueId;
81             return newComponentInstance;
82         };
83
84     }
85 }