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 2/4/2016.
25 import * as _ from "lodash";
33 } from "../../models";
34 import {ResourceType, ComponentType} from "../../utils/constants";
35 import {Capability} from "../capability";
36 import {Requirement} from "../requirement";
38 export interface IComponentInstance {
44 componentVersion:string;
48 normalizedName:string;
50 deploymentArtifacts:ArtifactGroupModel;
51 artifacts:ArtifactGroupModel;
52 propertyValueCounter:number;
55 modificationTime:number;
56 capabilities:CapabilitiesGroup;
57 requirements:RequirementsGroup;
58 customizationUUID:string;
59 sourceModelInvariant:string;
60 sourceModelName:string;
61 sourceModelUid:string;
62 sourceModelUuid:string;
66 inputs:Array<InputModel>;
67 properties:Array<PropertyModel>;
68 groupInstances:Array<Module>;
70 originArchived:boolean;
72 export class ComponentInstance implements IComponentInstance{
74 public componentUid:string;
75 public componentName:string;
78 public componentVersion:string;
79 public description:string;
82 public normalizedName:string;
83 public originType:string;
84 public deploymentArtifacts:ArtifactGroupModel;
85 public artifacts:ArtifactGroupModel;
86 public propertyValueCounter:number;
87 public uniqueId:string;
88 public creationTime:number;
89 public modificationTime:number;
90 public capabilities:CapabilitiesGroup;
91 public requirements:RequirementsGroup;
92 public customizationUUID:string;
93 public sourceModelInvariant:string;
94 public sourceModelName:string;
95 public sourceModelUid:string;
96 public sourceModelUuid:string;
97 public minOccurrences: string;
98 public maxOccurrences: string;
100 public certified:boolean;
101 public iconSprite:string;
102 public inputs:Array<InputModel>;
103 public properties:Array<PropertyModel>;
104 public groupInstances:Array<Module>;
105 public invariantName:string;
106 public originArchived:boolean;
107 public directives: string[];
108 public interfaces:any;
110 constructor(componentInstance?:ComponentInstance) {
112 if (componentInstance) {
113 this.componentUid = componentInstance.componentUid;
114 this.componentName = componentInstance.componentName;
116 this.componentVersion = componentInstance.componentVersion;
117 this.description = componentInstance.description;
118 this.icon = componentInstance.icon;
119 this.name = componentInstance.name;
120 this.normalizedName = componentInstance.normalizedName;
121 this.originType = componentInstance.originType;
122 this.deploymentArtifacts = new ArtifactGroupModel(componentInstance.deploymentArtifacts);
123 this.artifacts = new ArtifactGroupModel(componentInstance.artifacts);
124 this.uniqueId = componentInstance.uniqueId;
125 this.creationTime = componentInstance.creationTime;
126 this.modificationTime = componentInstance.modificationTime;
127 this.propertyValueCounter = componentInstance.propertyValueCounter;
128 this.capabilities = new CapabilitiesGroup(componentInstance.capabilities);
129 this.requirements = new RequirementsGroup(componentInstance.requirements);
130 this.certified = componentInstance.certified;
131 this.customizationUUID = componentInstance.customizationUUID;
132 this.updatePosition(componentInstance.posX, componentInstance.posY);
133 this.groupInstances = componentInstance.groupInstances;
134 this.invariantName = componentInstance.invariantName;
135 this.sourceModelInvariant = componentInstance.sourceModelInvariant;
136 this.sourceModelName = componentInstance.sourceModelName;
137 this.sourceModelUid = componentInstance.sourceModelUid;
138 this.sourceModelUuid = componentInstance.sourceModelUuid;
139 this.originArchived = componentInstance.originArchived;
140 this.directives = componentInstance.directives;
141 this.interfaces = componentInstance.interfaces;
142 this.minOccurrences = componentInstance.minOccurrences;
143 this.maxOccurrences = componentInstance.maxOccurrences;
147 public isUcpe = ():boolean => {
148 if (this.originType === 'VF' && this.capabilities && this.capabilities['tosca.capabilities.Container'] && this.name.toLowerCase().indexOf('ucpe') > -1) {
154 public isVl = ():boolean => {
155 return this.originType === 'VL';
158 public isComplex = ():boolean => {
159 return this.originType === ResourceType.VF || this.originType === ResourceType.PNF || this.originType === ResourceType.CVFC || this.originType === ResourceType.CR;
162 public isServiceProxy = ():boolean => {
163 return this.originType === ComponentType.SERVICE_PROXY;
166 public isServiceSubstitution = ():boolean => {
167 return this.originType === ComponentType.SERVICE_SUBSTITUTION;
170 public isVFC = ():boolean => {
171 return this.originType === ResourceType.VFC;
174 public getComponentUid = ():string => {
175 return this.isServiceProxy() || this.isServiceSubstitution() ? this.sourceModelUid : this.componentUid;
178 public setInstanceRC = ():void=> {
179 _.forEach(this.requirements, (requirementValue:Array<any>, requirementKey)=> {
180 _.forEach(requirementValue, (requirement)=> {
181 if (!requirement.ownerName) {
182 requirement['ownerId'] = this.uniqueId;
183 requirement['ownerName'] = this.name;
187 _.forEach(this.capabilities, (capabilityValue:Array<any>, capabilityKey)=> {
188 _.forEach(capabilityValue, (capability)=> {
189 if (!capability.ownerName) {
190 capability['ownerId'] = this.uniqueId;
191 capability['ownerName'] = this.name;
197 public updatePosition(posX:number, posY:number) {
202 public findRequirement(reqType:string, uniqueId:string, ownerId:string, name:string):Requirement|undefined {
203 let requirement:Requirement = undefined;
204 const searchGroup = (reqType) ? [this.requirements[reqType]] : this.requirements;
205 _.some(_.keys(searchGroup), (searchType) => {
206 requirement = _.find<Requirement>(searchGroup[searchType], (req:Requirement) => (
207 req.uniqueId === uniqueId && req.ownerId === ownerId && req.name === name
214 public findCapability(capType:string, uniqueId:string, ownerId:string, name:string):Capability|undefined {
215 let capability:Capability = undefined;
216 const searchGroup = (capType) ? [this.capabilities[capType]] : this.capabilities;
217 _.some(_.keys(searchGroup), (searchType) => {
218 capability = _.find<Capability>(searchGroup[searchType], (cap:Capability) => (
219 cap.uniqueId === uniqueId && cap.ownerId === ownerId && cap.name === name
226 public toJSON = ():any => {
227 let temp = angular.copy(this);
228 temp.certified = undefined;
229 temp.iconSprite = undefined;
230 temp.inputs = undefined;
231 temp.groupInstances = undefined;
232 temp.properties = undefined;
233 temp.requirements = undefined;
234 temp.capabilities = undefined;
238 public get iconClass() {
239 return this.iconSprite + ' ' + this.icon;
241 public isDependent = () : boolean => {
242 return Array.isArray(this.directives) && this.directives.length > 0;
245 public setDirectiveValue = (selectedDirectives: string[]) : void => {
246 this.directives = selectedDirectives;
249 public unmarkAsDependent = (directiveValues: string[]) : void => {
250 console.info("[START] this.directives: ", this.directives)
251 directiveValues.forEach(directive => {
252 let index = this.directives.indexOf(directive);
254 this.directives.splice(index, directiveValues.length);
257 console.info("[STOP] this.directives: ", this.directives)