blob: 091bfc139e3218d05cd347f413903ef3e86902a4 [file] [log] [blame]
Michael Lando451a3402017-02-19 10:28:42 +02001/*-
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 /*
21 * Created by obarda on 4/20/2016.
22 */
23/// <reference path="../references"/>
24module Sdc.Models {
25 'use strict';
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 constructor(requirementGroupObj?:Models.RequirementsGroup){
30 _.forEach(requirementGroupObj, (requirementsArrayObj:Array<Models.Requirement>, instance) => {
31 this[instance] = [];
32 _.forEach(requirementsArrayObj, (requirement:Models.Requirement):void => {
33 this[instance].push(new Models.Requirement(requirement));
34 });
35 });
36 }
37 }
38
39 export 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 constructor(requirement?:Requirement) {
54
55 if(requirement) {
56 this.capability = requirement.capability;
57 this.name = requirement.name;
58 this.ownerId = requirement.ownerId;
59 this.ownerName = requirement.ownerName;
60 this.node = requirement.node;
61 this.uniqueId = requirement.uniqueId;
62 this.relationship = requirement.relationship;
63 this.minOccurrences = requirement.minOccurrences;
64 this.maxOccurrences = requirement.maxOccurrences;
65 this.initFilterTerm();
66
67 }
68 }
69
70 public getFullTitle():string {
71 return this.ownerName + ': ' + this.name +
72 ': [' + this.minOccurrences + ', ' + this.maxOccurrences + ']';
73 }
74
75 public toJSON = ():any => {
76 this.filterTerm = undefined;
77 return this;
78 };
79
80 private initFilterTerm = ():void =>{
81 this.filterTerm = (this.name + " ") +
82 (this.ownerName + " " ) +
83 (this.capability ? (this.capability.substring("tosca.capabilities.".length) + " " ) : "") +
84 (this.node? (this.node.substring("tosca.nodes.".length) +" ") : "") +
85 (this.relationship? (this.relationship.substring("tosca.relationships.".length) +" ") : "") +
86 this.minOccurrences+","+this.maxOccurrences;
87 }
88 }
89}
90
91