Catalog alignment
[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 {CompositionCiNodeUcpeCp, Module, ModuleNodeBase, CompositionCiNodeVf, CompositionCiNodeVl, CompositionCiNodeCp, CompositionCiNodeConfiguration,
23     NodeUcpe, CompositionCiNodeService,CompositionCiNodeServiceProxy, CompositionCiNodeBase, ComponentInstance} from "./../../../models";
24 import {ComponentType, ResourceType} from "../../../utils/constants";
25 import {ImageCreatorService} from "app/ng2/pages/composition/graph/common/image-creator.service";
26 import {Injectable} from "@angular/core";
27
28 @Injectable()
29 export class NodesFactory {
30
31     constructor(private imageCreator:ImageCreatorService) {
32     }
33
34     public createNode = (instance:ComponentInstance):CompositionCiNodeBase => {
35
36         if (instance.isUcpe()) {
37             return new NodeUcpe(instance, this.imageCreator);
38         }
39         if (instance.originType === ComponentType.SERVICE) {
40             return new CompositionCiNodeService(instance, this.imageCreator);
41         }
42         if (instance.originType === ComponentType.SERVICE_PROXY) {
43             return new CompositionCiNodeServiceProxy(instance, this.imageCreator);
44         }
45         if (instance.originType === ResourceType.CP) {
46             return new CompositionCiNodeCp(instance, this.imageCreator);
47         }
48         if (instance.originType === ResourceType.VL) {
49             return new CompositionCiNodeVl(instance, this.imageCreator);
50         }
51         if (instance.originType === ResourceType.CONFIGURATION) {
52             return new CompositionCiNodeConfiguration(instance, this.imageCreator);
53         }
54
55         return new CompositionCiNodeVf(instance, this.imageCreator);
56     };
57
58     public createModuleNode = (module:Module):ModuleNodeBase => {
59         return new ModuleNodeBase(module);
60     };
61
62     public createUcpeCpNode = (instance:ComponentInstance):CompositionCiNodeCp => {
63
64         return new CompositionCiNodeUcpeCp(instance, this.imageCreator);
65     }
66 }
67