[SDC-29] Amdocs OnBoard 1707 initial commit.
[sdc.git] / catalog-ui / app / scripts / models / graph / match-relation.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 /// <reference path="../../references"/>
21 module Sdc.Models {
22     'use strict';
23
24     export class MatchBase {
25         requirement:Models.Requirement;
26         isFromTo:boolean;
27         fromNode:string;
28         toNode:string;
29
30         constructor(requirement:Models.Requirement, isFromTo:boolean, fromNode:string, toNode:string) {
31             this.requirement = requirement;
32             this.isFromTo = isFromTo;
33             this.fromNode = fromNode;
34             this.toNode = toNode;
35         }
36
37         public getDisplayText = (menuSide:string):string => {return '';};
38
39         public isOwner = (id:string):boolean => { return false; }
40
41     }
42
43     export class MatchReqToReq extends MatchBase {
44
45         secondRequirement:Models.Requirement;
46
47         constructor(requirement:Models.Requirement, secondRequirement:Models.Requirement, isFromTo:boolean, fromNode:string, toNode:string) {
48             super(requirement, isFromTo, fromNode, toNode);
49             this.secondRequirement = secondRequirement;
50         }
51
52         public getDisplayText = (menuSide:string):string => {
53             if ('left' == menuSide) {
54                 return this.requirement.getFullTitle();
55             }
56             return this.secondRequirement.getFullTitle();
57         };
58
59         public isOwner = (id:string):boolean => {
60             return this.secondRequirement.ownerId === id || this.requirement.ownerId === id;
61         }
62     }
63
64     export class MatchReqToCapability extends MatchBase {
65
66         capability:Models.Capability;
67
68         constructor(requirement:Models.Requirement, capability:Models.Capability, isFromTo:boolean, fromNode:string, toNode:string) {
69             super(requirement, isFromTo, fromNode, toNode);
70             this.capability = capability;
71         }
72
73         public matchToRelation = ():Models.Relationship => {
74             let relationship:Models.Relationship = new Models.Relationship();
75             relationship.capability = this.capability.name;
76             relationship.capabilityOwnerId = this.capability.ownerId;
77             relationship.capabilityUid = this.capability.uniqueId;
78             relationship.relationship = new Models.RelationType(this.capability.type);
79             relationship.requirement = this.requirement.name;
80             relationship.requirementOwnerId = this.requirement.ownerId;
81             relationship.requirementUid = this.requirement.uniqueId;
82             return relationship;
83         };
84
85
86         public getDisplayText = (menuSide:string):string => {
87             if (this.isFromTo && 'left' == menuSide || !this.isFromTo && 'right' == menuSide) {
88                 return this.requirement.getFullTitle();
89             }
90             return this.capability.getFullTitle();
91
92         };
93
94         public isOwner = (id:string):boolean => {
95             return this.capability.ownerId === id || this.requirement.ownerId === id;
96         };
97
98
99         public matchToRelationModel = ():Models.RelationshipModel => {
100             let relationshipModel:Models.RelationshipModel = new Models.RelationshipModel();
101             let relationship:Models.Relationship = this.matchToRelation();
102             relationshipModel.setRelationshipModelParams(this.fromNode, this.toNode, [relationship]);
103             return relationshipModel;
104         };
105     }
106
107 }
108
109