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=========================================================
21 import {Requirement} from "../requirement";
22 import {Capability} from "../capability";
23 import {Relationship, RelationshipModel} from "./relationship";
24 import {PropertyModel} from "../properties";
27 requirement:Requirement;
28 capability:Capability;
32 private _relationship:Relationship;
34 constructor(requirement:Requirement, capability:Capability, isFromTo:boolean, fromNode:string, toNode:string) {
35 this.requirement = requirement;
36 this.capability = capability;
37 this.isFromTo = isFromTo;
38 this.fromNode = fromNode;
42 // NOTE: Hold the relationship instance for cases capability / requirement are not available (when fulfilled).
43 // In case relationship instance is not manually saved to here, then build the relationship from the given capability and requirement.
44 public get relationship():Relationship {
45 if (!this._relationship) {
46 this._relationship = this.matchToRelation();
48 return this._relationship;
50 public set relationship(relationship) {
51 this._relationship = relationship;
54 public matchToRelation = ():Relationship => {
55 const relationship:Relationship = new Relationship();
56 relationship.setRelationProperties(this.capability, this.requirement);
60 public getDisplayText = (menuSide:string):string => {
61 if (this.isFromTo && 'left' == menuSide || !this.isFromTo && 'right' == menuSide) {
62 return this.requirement.getFullTitle();
64 return this.capability.getFullTitle();
67 public isOwner = (id:string):boolean => {
68 return this.capability.ownerId === id || this.requirement.ownerId === id;
71 public matchToRelationModel = ():RelationshipModel => {
72 let relationshipModel:RelationshipModel = new RelationshipModel();
73 let relationship:Relationship = this.matchToRelation();
74 relationshipModel.setRelationshipModelParams(this.fromNode, this.toNode, [relationship]);
75 return relationshipModel;