[SDC] rebase 1710 code
[sdc.git] / catalog-ui / src / app / 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 'use strict';
24 import {ComponentInstance, ServiceInstance, ResourceInstance, Component} from "../models";
25 import {LeftPaletteComponent} from "../models/components/displayComponent";
26
27 export class ComponentInstanceFactory {
28
29     static createComponentInstance(componentInstance:ComponentInstance):ComponentInstance {
30         let newComponentInstance:ComponentInstance;
31         switch (componentInstance.originType) {
32             case 'SERVICE':
33                 newComponentInstance = new ServiceInstance(componentInstance);
34                 break;
35
36             default :
37                 newComponentInstance = new ResourceInstance(componentInstance);
38                 break;
39         }
40         return newComponentInstance;
41     };
42
43     public createEmptyComponentInstance = (componentInstanceType?:string):ComponentInstance => {
44         let newComponentInstance:ComponentInstance;
45         switch (componentInstanceType) {
46             case 'SERVICE':
47                 newComponentInstance = new ServiceInstance();
48                 break;
49
50             default :
51                 newComponentInstance = new ResourceInstance();
52                 break;
53         }
54         return newComponentInstance;
55     };
56
57     public createComponentInstanceFromComponent = (component:LeftPaletteComponent):ComponentInstance => {
58         let newComponentInstance:ComponentInstance = this.createEmptyComponentInstance(component.componentType);
59         newComponentInstance.uniqueId = component.uniqueId + (new Date()).getTime();
60         newComponentInstance.posX = 0;
61         newComponentInstance.posY = 0;
62         newComponentInstance.name = component.name;
63         newComponentInstance.componentVersion = component.version;
64         newComponentInstance.originType = component.getComponentSubType();
65         //new component instance -> req. & cap. are added on successful instance creation
66         newComponentInstance.requirements = component.requirements;
67         newComponentInstance.capabilities = component.capabilities;
68         newComponentInstance.icon = component.icon;
69         newComponentInstance.componentUid = component.uniqueId;
70         return newComponentInstance;
71     };
72
73 }