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=========================================================
22 * Created by obarda on 4/20/2016.
25 import * as _ from "lodash";
26 import {RequirementCapabilityModel} from "./capability";
28 //this is an object contains keys, when each key has matching array.
29 // for example: key = tosca.capabilities.network. and the match array is array of requirements objects
30 export class RequirementsGroup {
31 [key: string]: Array<Requirement>;
32 constructor(requirementGroupObj?:RequirementsGroup) {
33 _.forEach(requirementGroupObj, (requirementsArrayObj:Array<Requirement>, instance) => {
35 _.forEach(requirementsArrayObj, (requirement:Requirement):void => {
36 this[instance].push(new Requirement(requirement));
42 export class Requirement implements RequirementCapabilityModel{
53 leftOccurrences:string;
54 minOccurrences:string;
55 maxOccurrences:string;
59 constructor(requirement?:Requirement) {
62 this.capability = requirement.capability;
63 this.name = requirement.name;
64 this.ownerId = requirement.ownerId;
65 this.ownerName = requirement.ownerName;
66 this.parentName = requirement.parentName;
67 this.node = requirement.node;
68 this.uniqueId = requirement.uniqueId;
69 this.relationship = requirement.relationship;
70 this.leftOccurrences = requirement.leftOccurrences;
71 this.minOccurrences = requirement.minOccurrences;
72 this.maxOccurrences = requirement.maxOccurrences;
73 this.initFilterTerm();
78 public getTitle():string {
79 return this.ownerName + ': ' + this.name;
82 public getFullTitle():string {
83 return this.getTitle() + ': [' + this.minOccurrences + ', ' + this.maxOccurrences + ']';
86 public toJSON = ():any => {
87 this.filterTerm = undefined;
91 private initFilterTerm = ():void => {
92 this.filterTerm = (this.name + " ") +
93 (this.ownerName + " " ) +
94 (this.capability ? (this.capability.substring("tosca.capabilities.".length) + " " ) : "") +
95 (this.node ? (this.node.substring("tosca.nodes.".length) + " ") : "") +
96 (this.relationship ? (this.relationship.substring("tosca.relationships.".length) + " ") : "") +
97 this.minOccurrences + "," + this.maxOccurrences;
100 public isFulfilled() {
101 return parseInt(this.leftOccurrences) === 0;