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 * as _ from "lodash";
22 import {Capability} from "../capability";
23 import {Requirement} from "../requirement";
25 export class RelationshipModel {
28 relationships:Array<Relationship>;
30 constructor(relationshipModel?:RelationshipModel, singleRelationship?:Relationship) {
31 if (relationshipModel) {
32 this.fromNode = relationshipModel.fromNode;
33 this.toNode = relationshipModel.toNode;
34 this.relationships = [];
35 if (relationshipModel.relationships && !singleRelationship) {
36 _.forEach(relationshipModel.relationships, (relation:Relationship):void => {
37 this.relationships.push(new Relationship(relation));
39 } else if (singleRelationship) {
40 this.relationships.push(singleRelationship);
45 public setRelationshipModelParams(fromNode:string, toNode:string, relationships:Array<Relationship>) {
46 this.fromNode = fromNode;
48 this.relationships = relationships;
52 export class RelationType {
55 constructor(type?:string) {
62 export class RelationshipType {
65 capabilityOwnerId:string;
67 relationship:RelationType;
69 requirementOwnerId:string;
70 requirementUid:string;
72 constructor(relationship?:RelationshipType) {
74 this.id = relationship.id;
75 this.capability = relationship.capability;
76 this.capabilityOwnerId = relationship.capabilityOwnerId;
77 this.capabilityUid = relationship.capabilityUid;
78 this.relationship = new RelationType(relationship.relationship.type);
79 this.requirement = relationship.requirement;
80 this.requirementOwnerId = relationship.requirementOwnerId;
81 this.requirementUid = relationship.requirementUid;
83 this.relationship = new RelationType();
87 public setRelationProperties = (capability?:Capability, requirement?:Requirement)=> {
89 this.capability = capability.name;
90 this.capabilityOwnerId = capability.ownerId;
91 this.capabilityUid = capability.uniqueId;
92 this.relationship = new RelationType(capability.type);
95 this.requirement = requirement.name;
96 this.requirementOwnerId = requirement.ownerId;
97 this.requirementUid = requirement.uniqueId;
102 export class Relationship {
103 relation: RelationshipType;
104 capability?: Capability;
105 requirement?: Requirement;
107 constructor(fullRelationship?:Relationship) {
108 if (fullRelationship) {
109 this.relation = new RelationshipType(fullRelationship.relation);
110 this.capability = fullRelationship.capability && new Capability(fullRelationship.capability);
111 this.requirement = fullRelationship.requirement && new Requirement(fullRelationship.requirement);
113 this.relation = new RelationshipType();
117 public setRelationProperties(capability?:Capability, requirement?:Requirement) {
118 this.relation.setRelationProperties(capability, requirement);
119 this.capability = capability;
120 this.requirement = requirement;