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 {PropertyModel} from "./properties";
27 //this is an object contains keys, when each key has matching array.
28 // for example: key = tosca.capabilities.network.Linkable and the match array is array of capabilities objects
29 export class CapabilitiesGroup {
30 constructor(capabilityGroupObj?:CapabilitiesGroup) {
31 _.forEach(capabilityGroupObj, (capabilitiesArrayObj:Array<Capability>, instance) => {
33 _.forEach(capabilitiesArrayObj, (capability:Capability):void => {
34 this[instance].push(new Capability(capability));
39 public findValueByKey(keySubstring:string):Array<Capability> {
40 let key:string = _.find(Object.keys(this), (key)=> {
41 return _.includes(key.toLowerCase(), keySubstring);
47 export class Capability {
55 capabilitySources:Array<String>;
56 minOccurrences:string;
57 maxOccurrences:string;
58 properties:Array<PropertyModel>;
60 validSourceTypes:Array<string>;
65 constructor(capability?:Capability) {
69 this.name = capability.name;
70 this.ownerId = capability.ownerId;
71 this.ownerName = capability.ownerName;
72 this.type = capability.type;
73 this.uniqueId = capability.uniqueId;
74 this.capabilitySources = capability.capabilitySources;
75 this.minOccurrences = capability.minOccurrences;
76 this.maxOccurrences = capability.maxOccurrences;
77 this.properties = capability.properties;
78 this.description = capability.description;
79 this.validSourceTypes = capability.validSourceTypes;
80 this.selected = capability.selected;
81 this.initFilterTerm();
86 public getFullTitle():string {
87 let maxOccurrences:string = this.maxOccurrences === 'UNBOUNDED' ? '∞' : this.maxOccurrences;
88 return this.ownerName + ': ' + this.name + ': [' + this.minOccurrences + ', ' + maxOccurrences + ']';
91 public toJSON = ():any => {
92 this.selected = undefined;
93 this.filterTerm = undefined;
97 private initFilterTerm = ():void => {
98 this.filterTerm = this.name + " " +
99 (this.type ? (this.type.replace("tosca.capabilities.", "") + " " ) : "") +
100 (this.description || "") + " " +
101 (this.ownerName || "") + " " +
102 (this.validSourceTypes ? (this.validSourceTypes.join(',') + " ") : "") +
103 this.minOccurrences + "," + this.maxOccurrences;
104 if (this.properties && this.properties.length) {
105 _.forEach(this.properties, (prop:PropertyModel)=> {
106 this.filterTerm += " " + prop.name +
107 " " + (prop.description || "") +
109 (prop.schema && prop.schema.property ? (" " + prop.schema.property.type) : "");