2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
20 /// <reference path="../../references"/>
24 export class MatchBase {
25 requirement:Models.Requirement;
30 constructor(requirement:Models.Requirement, isFromTo:boolean, fromNode:string, toNode:string) {
31 this.requirement = requirement;
32 this.isFromTo = isFromTo;
33 this.fromNode = fromNode;
37 public getDisplayText = (menuSide:string):string => {return '';};
39 public isOwner = (id:string):boolean => { return false; }
43 export class MatchReqToReq extends MatchBase {
45 secondRequirement:Models.Requirement;
47 constructor(requirement:Models.Requirement, secondRequirement:Models.Requirement, isFromTo:boolean, fromNode:string, toNode:string) {
48 super(requirement, isFromTo, fromNode, toNode);
49 this.secondRequirement = secondRequirement;
52 public getDisplayText = (menuSide:string):string => {
53 if ('left' == menuSide) {
54 return this.requirement.getFullTitle();
56 return this.secondRequirement.getFullTitle();
59 public isOwner = (id:string):boolean => {
60 return this.secondRequirement.ownerId === id || this.requirement.ownerId === id;
64 export class MatchReqToCapability extends MatchBase {
66 capability:Models.Capability;
68 constructor(requirement:Models.Requirement, capability:Models.Capability, isFromTo:boolean, fromNode:string, toNode:string) {
69 super(requirement, isFromTo, fromNode, toNode);
70 this.capability = capability;
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;
86 public getDisplayText = (menuSide:string):string => {
87 if (this.isFromTo && 'left' == menuSide || !this.isFromTo && 'right' == menuSide) {
88 return this.requirement.getFullTitle();
90 return this.capability.getFullTitle();
94 public isOwner = (id:string):boolean => {
95 return this.capability.ownerId === id || this.requirement.ownerId === id;
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;