Catalog alignment
[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 * as _ from "lodash";
25 import {
26     RelationshipModel, Relationship, CompositionCiLinkBase, CompositionCiNodeBase, LinkUcpeHost, CompositionCiUcpeLink,
27     CompositionCiVlUcpeLink, CompositionCiSimpleLink, ModuleCiLinkBase, ModuleCiVlLink, CompositionCiVLink
28 } from "app/models";
29 import {Injectable} from "@angular/core";
30
31 @Injectable()
32 export class LinksFactory {
33
34     constructor() {
35     }
36
37     public createGraphLink = (cy:Cy.Instance, relation:RelationshipModel, singleRelation:Relationship):CompositionCiLinkBase => {
38
39         let newRelation:CompositionCiLinkBase;
40         if (singleRelation.relation.relationship.type && _.includes(singleRelation.relation.relationship.type.toLowerCase(), 'link')) {
41             newRelation = new CompositionCiVLink(relation, singleRelation);
42         } else {
43             newRelation = new CompositionCiSimpleLink(relation, singleRelation);
44         }
45
46         return newRelation;
47     };
48
49     public createUcpeHostLink = (relation:RelationshipModel):LinkUcpeHost => {
50         return new LinkUcpeHost(relation);
51     };
52
53     public createVLLink = (relation:RelationshipModel):CompositionCiVLink => {
54         return new CompositionCiVLink(relation);
55     }
56
57     public createModuleGraphLinks = (relation:RelationshipModel, singleRelation:Relationship):ModuleCiLinkBase => {
58
59         let newRelation:ModuleCiLinkBase;
60
61         if (_.includes(singleRelation.relation.relationship.type.toLowerCase(), 'link')) {
62             newRelation = new ModuleCiVlLink(relation, singleRelation);
63         } else {
64             newRelation = new ModuleCiLinkBase(relation, singleRelation);
65         }
66
67         return newRelation;
68     };
69
70 }