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