blob: e62c809ec9d5f19c1f793c5c41d129878bbafaeb [file] [log] [blame]
Michael Landoed64b5e2017-06-09 03:19:04 +03001/**
2 * Created by obarda on 4/20/2016.
3 */
4'use strict';
5//this is an object contains keys, when each key has matching array.
6// for example: key = tosca.capabilities.network. and the match array is array of requirements objects
7export class RequirementsGroup {
8 [key: string]: Array<Requirement>;
9 constructor(requirementGroupObj?:RequirementsGroup) {
10 _.forEach(requirementGroupObj, (requirementsArrayObj:Array<Requirement>, instance) => {
11 this[instance] = [];
12 _.forEach(requirementsArrayObj, (requirement:Requirement):void => {
13 this[instance].push(new Requirement(requirement));
14 });
15 });
16 }
17}
18
19export class Requirement {
20
21 //server data
22 capability:string;
23 name:string;
24 ownerId:string;
25 ownerName:string;
26 node:string;
27 uniqueId:string;
28 relationship:string;
29 minOccurrences:string;
30 maxOccurrences:string;
31 //custom
32 filterTerm:string;
33
34 constructor(requirement?:Requirement) {
35
36 if (requirement) {
37 this.capability = requirement.capability;
38 this.name = requirement.name;
39 this.ownerId = requirement.ownerId;
40 this.ownerName = requirement.ownerName;
41 this.node = requirement.node;
42 this.uniqueId = requirement.uniqueId;
43 this.relationship = requirement.relationship;
44 this.minOccurrences = requirement.minOccurrences;
45 this.maxOccurrences = requirement.maxOccurrences;
46 this.initFilterTerm();
47
48 }
49 }
50
51 public getFullTitle():string {
52 return this.ownerName + ': ' + this.name +
53 ': [' + this.minOccurrences + ', ' + this.maxOccurrences + ']';
54 }
55
56 public toJSON = ():any => {
57 this.filterTerm = undefined;
58 return this;
59 };
60
61 private initFilterTerm = ():void => {
62 this.filterTerm = (this.name + " ") +
63 (this.ownerName + " " ) +
64 (this.capability ? (this.capability.substring("tosca.capabilities.".length) + " " ) : "") +
65 (this.node ? (this.node.substring("tosca.nodes.".length) + " ") : "") +
66 (this.relationship ? (this.relationship.substring("tosca.relationships.".length) + " ") : "") +
67 this.minOccurrences + "," + this.maxOccurrences;
68 }
69}
70
71