blob: d880456b06cbf0ed4c66b79e5108c9a02edbef86 [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';
Tal Gitelman51d50f02017-12-10 18:55:03 +020025import {RequirementCapabilityModel} from "./capability";
Michael Landoed64b5e2017-06-09 03:19:04 +030026//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
28export 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 Gitelman51d50f02017-12-10 18:55:03 +020040export class Requirement implements RequirementCapabilityModel{
Michael Landoed64b5e2017-06-09 03:19:04 +030041
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 Gitelman51d50f02017-12-10 18:55:03 +020050 leftOccurrences:string;
Michael Landoed64b5e2017-06-09 03:19:04 +030051 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 Gitelman51d50f02017-12-10 18:55:03 +020066 this.leftOccurrences = requirement.leftOccurrences;
Michael Landoed64b5e2017-06-09 03:19:04 +030067 this.minOccurrences = requirement.minOccurrences;
68 this.maxOccurrences = requirement.maxOccurrences;
69 this.initFilterTerm();
70
71 }
72 }
73
Tal Gitelman51d50f02017-12-10 18:55:03 +020074 public getTitle():string {
75 return this.ownerName + ': ' + this.name;
76 }
77
Michael Landoed64b5e2017-06-09 03:19:04 +030078 public getFullTitle():string {
Tal Gitelman51d50f02017-12-10 18:55:03 +020079 return this.getTitle() + ': [' + this.minOccurrences + ', ' + this.maxOccurrences + ']';
Michael Landoed64b5e2017-06-09 03:19:04 +030080 }
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 Gitelman51d50f02017-12-10 18:55:03 +020095
96 public isFulfilled() {
97 return parseInt(this.leftOccurrences) === 0;
98 }
Michael Landoed64b5e2017-06-09 03:19:04 +030099}
100
101