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;
98 public certified:boolean;
99 public iconSprite:string;
100 public inputs:Array<InputModel>;
101 public properties:Array<PropertyModel>;
102 public groupInstances:Array<Module>;
103 public invariantName:string;
104 public originArchived:boolean;
105 public directives: string[];
108 SELECTABLE: 'selectable'
111 constructor(componentInstance?:ComponentInstance) {
113 if (componentInstance) {
114 this.componentUid = componentInstance.componentUid;
115 this.componentName = componentInstance.componentName;
117 this.componentVersion = componentInstance.componentVersion;
118 this.description = componentInstance.description;
119 this.icon = componentInstance.icon;
120 this.name = componentInstance.name;
121 this.normalizedName = componentInstance.normalizedName;
122 this.originType = componentInstance.originType;
123 this.deploymentArtifacts = new ArtifactGroupModel(componentInstance.deploymentArtifacts);
124 this.artifacts = new ArtifactGroupModel(componentInstance.artifacts);
125 this.uniqueId = componentInstance.uniqueId;
126 this.creationTime = componentInstance.creationTime;
127 this.modificationTime = componentInstance.modificationTime;
128 this.propertyValueCounter = componentInstance.propertyValueCounter;
129 this.capabilities = new CapabilitiesGroup(componentInstance.capabilities);
130 this.requirements = new RequirementsGroup(componentInstance.requirements);
131 this.certified = componentInstance.certified;
132 this.customizationUUID = componentInstance.customizationUUID;
133 this.updatePosition(componentInstance.posX, componentInstance.posY);
134 this.groupInstances = componentInstance.groupInstances;
135 this.invariantName = componentInstance.invariantName;
136 this.sourceModelInvariant = componentInstance.sourceModelInvariant;
137 this.sourceModelName = componentInstance.sourceModelName;
138 this.sourceModelUid = componentInstance.sourceModelUid;
139 this.sourceModelUuid = componentInstance.sourceModelUuid;
140 this.originArchived = componentInstance.originArchived;
141 this.directives = componentInstance.directives;
145 public isUcpe = ():boolean => {
146 if (this.originType === 'VF' && this.capabilities && this.capabilities['tosca.capabilities.Container'] && this.name.toLowerCase().indexOf('ucpe') > -1) {
152 public isVl = ():boolean => {
153 return this.originType === 'VL';
156 public isComplex = ():boolean => {
157 return this.originType === ResourceType.VF || this.originType === ResourceType.PNF || this.originType === ResourceType.CVFC || this.originType === ResourceType.CR;
160 public isServiceProxy = ():boolean => {
161 return this.originType === ComponentType.SERVICE_PROXY;
164 public getComponentUid = ():string => {
165 return this.isServiceProxy()? this.sourceModelUid : this.componentUid;
168 public setInstanceRC = ():void=> {
169 _.forEach(this.requirements, (requirementValue:Array<any>, requirementKey)=> {
170 _.forEach(requirementValue, (requirement)=> {
171 if (!requirement.ownerName) {
172 requirement['ownerId'] = this.uniqueId;
173 requirement['ownerName'] = this.name;
177 _.forEach(this.capabilities, (capabilityValue:Array<any>, capabilityKey)=> {
178 _.forEach(capabilityValue, (capability)=> {
179 if (!capability.ownerName) {
180 capability['ownerId'] = this.uniqueId;
181 capability['ownerName'] = this.name;
187 public updatePosition(posX:number, posY:number) {
192 public findRequirement(reqType:string, uniqueId:string, ownerId:string, name:string):Requirement|undefined {
193 let requirement:Requirement = undefined;
194 const searchGroup = (reqType) ? [this.requirements[reqType]] : this.requirements;
195 _.some(_.keys(searchGroup), (searchType) => {
196 requirement = _.find<Requirement>(searchGroup[searchType], (req:Requirement) => (
197 req.uniqueId === uniqueId && req.ownerId === ownerId && req.name === name
204 public findCapability(capType:string, uniqueId:string, ownerId:string, name:string):Capability|undefined {
205 let capability:Capability = undefined;
206 const searchGroup = (capType) ? [this.capabilities[capType]] : this.capabilities;
207 _.some(_.keys(searchGroup), (searchType) => {
208 capability = _.find<Capability>(searchGroup[searchType], (cap:Capability) => (
209 cap.uniqueId === uniqueId && cap.ownerId === ownerId && cap.name === name
216 public toJSON = ():any => {
217 let temp = angular.copy(this);
218 temp.certified = undefined;
219 temp.iconSprite = undefined;
220 temp.inputs = undefined;
221 temp.groupInstances = undefined;
222 temp.properties = undefined;
223 temp.requirements = undefined;
224 temp.capabilities = undefined;
228 public get iconClass() {
229 return this.iconSprite + ' ' + this.icon;
231 public isDependent = () : boolean => {
232 return this.directives && this.directives.indexOf(this.DIRECTIVES_TYPES.SELECTABLE) !== -1;
235 public markAsDependent = () : void => {
236 this.directives.push(this.DIRECTIVES_TYPES.SELECTABLE);
239 public unmarkAsDependent = () : void => {
240 let index = this.directives.indexOf(this.DIRECTIVES_TYPES.SELECTABLE);
242 this.directives.splice(index, 1);