[sdc] rebase update
[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,
23     NodeUcpe, CompositionCiNodeService, CompositionCiNodeBase, ComponentInstance} from "./../../../models";
24 import {ComponentType, ResourceType} from "../../../utils/constants";
25 import {ImageCreatorService} from "../../../directives/graphs-v2/image-creator/image-creator.service";
26
27 export class NodesFactory {
28
29     constructor(private imageCreator:ImageCreatorService) {
30     }
31
32     public createNode = (instance:ComponentInstance):CompositionCiNodeBase => {
33
34         if (instance.isUcpe()) {
35             return new NodeUcpe(instance, this.imageCreator);
36         }
37         if (instance.originType === ComponentType.SERVICE) {
38             return new CompositionCiNodeService(instance, this.imageCreator);
39         }
40         if (instance.originType === ResourceType.CP) {
41             return new CompositionCiNodeCp(instance, this.imageCreator);
42         }
43         if (instance.originType === ResourceType.VL) {
44             return new CompositionCiNodeVl(instance, this.imageCreator);
45         }
46
47         return new CompositionCiNodeVf(instance, this.imageCreator);
48     };
49
50     public createModuleNode = (module:Module):ModuleNodeBase => {
51
52         return new ModuleNodeBase(module);
53     };
54
55     public createUcpeCpNode = (instance:ComponentInstance):CompositionCiNodeCp => {
56
57         return new CompositionCiNodeUcpeCp(instance, this.imageCreator);
58     }
59 }
60
61 NodesFactory.$inject = [
62     'ImageCreatorService'
63 ];