2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 * Created by obarda on 3/7/2016.
24 import {ComponentInstance, ServiceInstance, ResourceInstance, Component} from "../models";
25 import {LeftPaletteComponent} from "../models/components/displayComponent";
27 export class ComponentInstanceFactory {
29 static createComponentInstance(componentInstance:ComponentInstance):ComponentInstance {
30 let newComponentInstance:ComponentInstance;
31 switch (componentInstance.originType) {
33 newComponentInstance = new ServiceInstance(componentInstance);
37 newComponentInstance = new ResourceInstance(componentInstance);
40 return newComponentInstance;
43 public createEmptyComponentInstance = (componentInstanceType?:string):ComponentInstance => {
44 let newComponentInstance:ComponentInstance;
45 switch (componentInstanceType) {
47 newComponentInstance = new ServiceInstance();
51 newComponentInstance = new ResourceInstance();
54 return newComponentInstance;
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;