[SDC-29] rebase continue work to align source
[sdc.git] / catalog-ui / src / app / models / graph / graph-links / links-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 5/1/2016.
22  */
23 'use strict';
24 import {RelationshipModel, Relationship, CompositionCiLinkBase, CompositionCiNodeBase, LinkUcpeHost, CompositionCiUcpeLink,
25     CompositionCiVlUcpeLink, CompositionCiSimpleLink, ModuleCiLinkBase, ModuleCiVlLink, CompositionCiVLink} from "../../../models";
26
27 export class LinksFactory {
28
29   constructor() {
30   }
31
32   public createGraphLink = (cy:Cy.Instance, relation:RelationshipModel, singleRelation:Relationship):CompositionCiLinkBase => {
33
34     let newRelation:CompositionCiLinkBase;
35
36     // let fromNode:CompositionCiNodeBase = cy.getElementById(relation.fromNode).data();
37     // let toNode:CompositionCiNodeBase = cy.getElementById(relation.toNode).data();
38     //
39     // if ((relation.fromNode && fromNode.isUcpePart) || (relation.toNode && toNode.isUcpePart )) { //Link from or to node inside ucpe
40     //
41     //   if (singleRelation && singleRelation.relationship.type && singleRelation.relationship.type == 'tosca.relationships.HostedOn') {
42     //     newRelation = new LinkUcpeHost(relation, singleRelation);
43     //   } else if (singleRelation.relationship.type && _.includes(singleRelation.relationship.type.toLowerCase(), 'link')) {
44     //     newRelation = new CompositionCiVlUcpeLink(relation, fromNode.isUcpePart, singleRelation);
45     //   } else {
46     //     newRelation = new CompositionCiUcpeLink(relation, fromNode.isUcpePart, singleRelation);
47     //   }
48     // } else
49      if (singleRelation.relationship.type && _.includes(singleRelation.relationship.type.toLowerCase(), 'link')) {
50       newRelation = new CompositionCiVLink(relation, singleRelation);
51     } else {
52       newRelation = new CompositionCiSimpleLink(relation, singleRelation);
53     }
54
55     return newRelation;
56   };
57
58   public createUcpeHostLink = (relation:RelationshipModel):LinkUcpeHost => {
59     return new LinkUcpeHost(relation);
60   };
61
62   public createVLLink = (relation:RelationshipModel):CompositionCiVLink => {
63     return new CompositionCiVLink(relation);
64   }
65
66
67   public createModuleGraphLinks = (relation:RelationshipModel, singleRelation:Relationship):ModuleCiLinkBase => {
68
69     let newRelation:ModuleCiLinkBase;
70
71     if (_.includes(singleRelation.relationship.type.toLowerCase(), 'link')) {
72       newRelation = new ModuleCiVlLink(relation, singleRelation);
73     } else {
74       newRelation = new ModuleCiLinkBase(relation, singleRelation);
75     }
76
77     return newRelation;
78   };
79
80 }