Michael Lando | dd60339 | 2017-07-12 00:54:52 +0300 | [diff] [blame] | 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 | |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 21 | /** |
| 22 | * Created by obarda on 4/20/2016. |
| 23 | */ |
| 24 | 'use strict'; |
Tal Gitelman | 51d50f0 | 2017-12-10 18:55:03 +0200 | [diff] [blame] | 25 | import {RequirementCapabilityModel} from "./capability"; |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 26 | //this is an object contains keys, when each key has matching array. |
| 27 | // for example: key = tosca.capabilities.network. and the match array is array of requirements objects |
| 28 | export class RequirementsGroup { |
| 29 | [key: string]: Array<Requirement>; |
| 30 | constructor(requirementGroupObj?:RequirementsGroup) { |
| 31 | _.forEach(requirementGroupObj, (requirementsArrayObj:Array<Requirement>, instance) => { |
| 32 | this[instance] = []; |
| 33 | _.forEach(requirementsArrayObj, (requirement:Requirement):void => { |
| 34 | this[instance].push(new Requirement(requirement)); |
| 35 | }); |
| 36 | }); |
| 37 | } |
| 38 | } |
| 39 | |
Tal Gitelman | 51d50f0 | 2017-12-10 18:55:03 +0200 | [diff] [blame] | 40 | export class Requirement implements RequirementCapabilityModel{ |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 41 | |
| 42 | //server data |
| 43 | capability:string; |
| 44 | name:string; |
| 45 | ownerId:string; |
| 46 | ownerName:string; |
| 47 | node:string; |
| 48 | uniqueId:string; |
| 49 | relationship:string; |
Tal Gitelman | 51d50f0 | 2017-12-10 18:55:03 +0200 | [diff] [blame] | 50 | leftOccurrences:string; |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 51 | minOccurrences:string; |
| 52 | maxOccurrences:string; |
| 53 | //custom |
| 54 | filterTerm:string; |
| 55 | |
| 56 | constructor(requirement?:Requirement) { |
| 57 | |
| 58 | if (requirement) { |
| 59 | this.capability = requirement.capability; |
| 60 | this.name = requirement.name; |
| 61 | this.ownerId = requirement.ownerId; |
| 62 | this.ownerName = requirement.ownerName; |
| 63 | this.node = requirement.node; |
| 64 | this.uniqueId = requirement.uniqueId; |
| 65 | this.relationship = requirement.relationship; |
Tal Gitelman | 51d50f0 | 2017-12-10 18:55:03 +0200 | [diff] [blame] | 66 | this.leftOccurrences = requirement.leftOccurrences; |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 67 | this.minOccurrences = requirement.minOccurrences; |
| 68 | this.maxOccurrences = requirement.maxOccurrences; |
| 69 | this.initFilterTerm(); |
| 70 | |
| 71 | } |
| 72 | } |
| 73 | |
Tal Gitelman | 51d50f0 | 2017-12-10 18:55:03 +0200 | [diff] [blame] | 74 | public getTitle():string { |
| 75 | return this.ownerName + ': ' + this.name; |
| 76 | } |
| 77 | |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 78 | public getFullTitle():string { |
Tal Gitelman | 51d50f0 | 2017-12-10 18:55:03 +0200 | [diff] [blame] | 79 | return this.getTitle() + ': [' + this.minOccurrences + ', ' + this.maxOccurrences + ']'; |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | public toJSON = ():any => { |
| 83 | this.filterTerm = undefined; |
| 84 | return this; |
| 85 | }; |
| 86 | |
| 87 | private initFilterTerm = ():void => { |
| 88 | this.filterTerm = (this.name + " ") + |
| 89 | (this.ownerName + " " ) + |
| 90 | (this.capability ? (this.capability.substring("tosca.capabilities.".length) + " " ) : "") + |
| 91 | (this.node ? (this.node.substring("tosca.nodes.".length) + " ") : "") + |
| 92 | (this.relationship ? (this.relationship.substring("tosca.relationships.".length) + " ") : "") + |
| 93 | this.minOccurrences + "," + this.maxOccurrences; |
| 94 | } |
Tal Gitelman | 51d50f0 | 2017-12-10 18:55:03 +0200 | [diff] [blame] | 95 | |
| 96 | public isFulfilled() { |
| 97 | return parseInt(this.leftOccurrences) === 0; |
| 98 | } |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 99 | } |
| 100 | |
| 101 | |