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";
26 import {ArtifactGroupModel, CapabilitiesGroup,RequirementsGroup, PropertyModel, InputModel, Module} from "../../models";
27 import {ResourceType,ComponentType} from "../../utils/constants";
28 import {Capability} from "../capability";
29 import {Requirement} from "../requirement";
31 export class ComponentInstance {
33 public componentUid:string;
34 public componentName:string;
37 public componentVersion:string;
38 public description:string;
41 public normalizedName:string;
42 public originType:string;
43 public deploymentArtifacts:ArtifactGroupModel;
44 public artifacts:ArtifactGroupModel;
45 public propertyValueCounter:number;
46 public uniqueId:string;
47 public creationTime:number;
48 public modificationTime:number;
49 public capabilities:CapabilitiesGroup;
50 public requirements:RequirementsGroup;
51 public customizationUUID:string;
52 public sourceModelInvariant:string;
53 public sourceModelName:string;
54 public sourceModelUid:string;
55 public sourceModelUuid:string;
57 public certified:boolean;
58 public iconSprite:string;
59 public inputs:Array<InputModel>;
60 public properties:Array<PropertyModel>;
61 public groupInstances:Array<Module>;
62 public invariantName:string;
64 constructor(componentInstance?:ComponentInstance) {
66 if (componentInstance) {
67 this.componentUid = componentInstance.componentUid;
68 this.componentName = componentInstance.componentName;
70 this.componentVersion = componentInstance.componentVersion;
71 this.description = componentInstance.description;
72 this.icon = componentInstance.icon;
73 this.name = componentInstance.name;
74 this.normalizedName = componentInstance.normalizedName;
75 this.originType = componentInstance.originType;
76 this.deploymentArtifacts = new ArtifactGroupModel(componentInstance.deploymentArtifacts);
77 this.artifacts = new ArtifactGroupModel(componentInstance.artifacts);
78 this.uniqueId = componentInstance.uniqueId;
79 this.creationTime = componentInstance.creationTime;
80 this.modificationTime = componentInstance.modificationTime;
81 this.propertyValueCounter = componentInstance.propertyValueCounter;
82 this.capabilities = new CapabilitiesGroup(componentInstance.capabilities);
83 this.requirements = new RequirementsGroup(componentInstance.requirements);
84 this.certified = componentInstance.certified;
85 this.customizationUUID = componentInstance.customizationUUID;
86 this.updatePosition(componentInstance.posX, componentInstance.posY);
87 this.groupInstances = componentInstance.groupInstances;
88 this.invariantName = componentInstance.invariantName;
89 this.sourceModelInvariant = componentInstance.sourceModelInvariant;
90 this.sourceModelName = componentInstance.sourceModelName;
91 this.sourceModelUid = componentInstance.sourceModelUid;
92 this.sourceModelUuid = componentInstance.sourceModelUuid;
96 public isUcpe = ():boolean => {
97 if (this.originType === 'VF' && this.capabilities && this.capabilities['tosca.capabilities.Container'] && this.name.toLowerCase().indexOf('ucpe') > -1) {
103 public isVl = ():boolean => {
104 return this.originType === 'VL';
107 public isComplex = () : boolean => {
108 return this.originType === ResourceType.VF || this.originType === ResourceType.PNF || this.originType === ResourceType.CVFC || this.originType === ResourceType.CR ;
111 public isServiceProxy = () :boolean => {
112 return this.originType === ComponentType.SERVICE_PROXY;
115 public setInstanceRC = ():void=> {
116 _.forEach(this.requirements, (requirementValue:Array<any>, requirementKey)=> {
117 _.forEach(requirementValue, (requirement)=> {
118 if (!requirement.ownerName) {
119 requirement['ownerId'] = this.uniqueId;
120 requirement['ownerName'] = this.name;
124 _.forEach(this.capabilities, (capabilityValue:Array<any>, capabilityKey)=> {
125 _.forEach(capabilityValue, (capability)=> {
126 if (!capability.ownerName) {
127 capability['ownerId'] = this.uniqueId;
128 capability['ownerName'] = this.name;
134 public updatePosition(posX:number, posY:number) {
139 public findRequirement(reqType:string, uniqueId:string, ownerId:string, name:string):Requirement|undefined {
140 let requirement:Requirement = undefined;
141 const searchGroup = (reqType) ? [this.requirements[reqType]] : this.requirements;
142 _.some(_.keys(searchGroup), (searchType) => {
143 requirement = _.find<Requirement>(searchGroup[searchType], (req:Requirement) => (
144 req.uniqueId === uniqueId && req.ownerId === ownerId && req.name === name
151 public findCapability(capType:string, uniqueId:string, ownerId:string, name:string):Capability|undefined {
152 let capability:Capability = undefined;
153 const searchGroup = (capType) ? [this.capabilities[capType]] : this.capabilities;
154 _.some(_.keys(searchGroup), (searchType) => {
155 capability = _.find<Capability>(searchGroup[searchType], (cap:Capability) => (
156 cap.uniqueId === uniqueId && cap.ownerId === ownerId && cap.name === name
163 public toJSON = ():any => {
164 let temp = angular.copy(this);
165 temp.certified = undefined;
166 temp.iconSprite = undefined;
167 temp.inputs = undefined;
168 temp.groupInstances = undefined;
169 temp.properties = undefined;
170 temp.requirements = undefined;
171 temp.capabilities = undefined;