Support for Nested/Hierarchical Services
[sdc.git] / catalog-ui / src / app / models / graph / nodes / nodes-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 'use strict';
21
22 import {
23     CompositionCiNodeUcpeCp,
24     Module,
25     ModuleNodeBase,
26     CompositionCiNodeVf,
27     CompositionCiNodeVl,
28     CompositionCiNodeCp,
29     CompositionCiNodeConfiguration,
30     NodeUcpe,
31     CompositionCiNodeService,
32     CompositionCiNodeServiceProxy,
33     CompositionCiNodeServiceSubstitution,
34     CompositionCiNodeBase,
35     ComponentInstance,
36     CompositionCiNodeVfc
37 } from "./../../../models";
38 import {ComponentType, ResourceType} from "../../../utils/constants";
39 import {ImageCreatorService} from "app/ng2/pages/composition/graph/common/image-creator.service";
40 import {Injectable} from "@angular/core";
41
42 @Injectable()
43 export class NodesFactory {
44
45     constructor(private imageCreator: ImageCreatorService) {
46     }
47
48     public createNode = (instance: ComponentInstance): CompositionCiNodeBase => {
49
50         if (instance.isUcpe()) {
51             return new NodeUcpe(instance, this.imageCreator);
52         }
53         if (instance.originType === ComponentType.SERVICE) {
54             return new CompositionCiNodeService(instance, this.imageCreator);
55         }
56         if (instance.originType === ComponentType.SERVICE_PROXY) {
57             return new CompositionCiNodeServiceProxy(instance, this.imageCreator);
58         }
59         if (instance.originType === ComponentType.SERVICE_SUBSTITUTION) {
60             return new CompositionCiNodeServiceSubstitution(instance, this.imageCreator);
61         }
62         if (instance.originType == ResourceType.VFC) {
63             return new CompositionCiNodeVfc(instance, this.imageCreator);
64         }
65         if (instance.originType === ResourceType.CP) {
66             return new CompositionCiNodeCp(instance, this.imageCreator);
67         }
68         if (instance.originType === ResourceType.VL) {
69             return new CompositionCiNodeVl(instance, this.imageCreator);
70         }
71         if (instance.originType === ResourceType.CONFIGURATION) {
72             return new CompositionCiNodeConfiguration(instance, this.imageCreator);
73         }
74
75         return new CompositionCiNodeVf(instance, this.imageCreator);
76     };
77
78     public createModuleNode = (module: Module): ModuleNodeBase => {
79         return new ModuleNodeBase(module);
80     };
81
82     public createUcpeCpNode = (instance: ComponentInstance): CompositionCiNodeCp => {
83
84         return new CompositionCiNodeUcpeCp(instance, this.imageCreator);
85     }
86 }
87