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";
37 import {DirectivesEnum} from "../../ng2/components/logic/service-dependencies/directive-option";
39 export interface IComponentInstance {
45 componentVersion:string;
49 normalizedName:string;
51 deploymentArtifacts:ArtifactGroupModel;
52 artifacts:ArtifactGroupModel;
53 propertyValueCounter:number;
56 modificationTime:number;
57 capabilities:CapabilitiesGroup;
58 requirements:RequirementsGroup;
59 customizationUUID:string;
60 sourceModelInvariant:string;
61 sourceModelName:string;
62 sourceModelUid:string;
63 sourceModelUuid:string;
67 inputs:Array<InputModel>;
68 properties:Array<PropertyModel>;
69 groupInstances:Array<Module>;
71 originArchived:boolean;
73 export class ComponentInstance implements IComponentInstance{
75 public componentUid:string;
76 public componentName:string;
79 public componentVersion:string;
80 public description:string;
83 public normalizedName:string;
84 public originType:string;
85 public deploymentArtifacts:ArtifactGroupModel;
86 public artifacts:ArtifactGroupModel;
87 public propertyValueCounter:number;
88 public uniqueId:string;
89 public creationTime:number;
90 public modificationTime:number;
91 public capabilities:CapabilitiesGroup;
92 public requirements:RequirementsGroup;
93 public customizationUUID:string;
94 public sourceModelInvariant:string;
95 public sourceModelName:string;
96 public sourceModelUid:string;
97 public sourceModelUuid:string;
99 public certified:boolean;
100 public iconSprite:string;
101 public inputs:Array<InputModel>;
102 public properties:Array<PropertyModel>;
103 public groupInstances:Array<Module>;
104 public invariantName:string;
105 public originArchived:boolean;
106 public directives: string[];
108 constructor(componentInstance?:ComponentInstance) {
110 if (componentInstance) {
111 this.componentUid = componentInstance.componentUid;
112 this.componentName = componentInstance.componentName;
114 this.componentVersion = componentInstance.componentVersion;
115 this.description = componentInstance.description;
116 this.icon = componentInstance.icon;
117 this.name = componentInstance.name;
118 this.normalizedName = componentInstance.normalizedName;
119 this.originType = componentInstance.originType;
120 this.deploymentArtifacts = new ArtifactGroupModel(componentInstance.deploymentArtifacts);
121 this.artifacts = new ArtifactGroupModel(componentInstance.artifacts);
122 this.uniqueId = componentInstance.uniqueId;
123 this.creationTime = componentInstance.creationTime;
124 this.modificationTime = componentInstance.modificationTime;
125 this.propertyValueCounter = componentInstance.propertyValueCounter;
126 this.capabilities = new CapabilitiesGroup(componentInstance.capabilities);
127 this.requirements = new RequirementsGroup(componentInstance.requirements);
128 this.certified = componentInstance.certified;
129 this.customizationUUID = componentInstance.customizationUUID;
130 this.updatePosition(componentInstance.posX, componentInstance.posY);
131 this.groupInstances = componentInstance.groupInstances;
132 this.invariantName = componentInstance.invariantName;
133 this.sourceModelInvariant = componentInstance.sourceModelInvariant;
134 this.sourceModelName = componentInstance.sourceModelName;
135 this.sourceModelUid = componentInstance.sourceModelUid;
136 this.sourceModelUuid = componentInstance.sourceModelUuid;
137 this.originArchived = componentInstance.originArchived;
138 this.directives = componentInstance.directives;
142 public isUcpe = ():boolean => {
143 if (this.originType === 'VF' && this.capabilities && this.capabilities['tosca.capabilities.Container'] && this.name.toLowerCase().indexOf('ucpe') > -1) {
149 public isVl = ():boolean => {
150 return this.originType === 'VL';
153 public isComplex = ():boolean => {
154 return this.originType === ResourceType.VF || this.originType === ResourceType.PNF || this.originType === ResourceType.CVFC || this.originType === ResourceType.CR;
157 public isServiceProxy = ():boolean => {
158 return this.originType === ComponentType.SERVICE_PROXY;
161 public isServiceSubstitution = ():boolean => {
162 return this.originType === ComponentType.SERVICE_SUBSTITUTION;
165 public isVFC = ():boolean => {
166 return this.originType === ResourceType.VFC;
169 public getComponentUid = ():string => {
170 return this.isServiceProxy() || this.isServiceSubstitution() ? this.sourceModelUid : this.componentUid;
173 public setInstanceRC = ():void=> {
174 _.forEach(this.requirements, (requirementValue:Array<any>, requirementKey)=> {
175 _.forEach(requirementValue, (requirement)=> {
176 if (!requirement.ownerName) {
177 requirement['ownerId'] = this.uniqueId;
178 requirement['ownerName'] = this.name;
182 _.forEach(this.capabilities, (capabilityValue:Array<any>, capabilityKey)=> {
183 _.forEach(capabilityValue, (capability)=> {
184 if (!capability.ownerName) {
185 capability['ownerId'] = this.uniqueId;
186 capability['ownerName'] = this.name;
192 public updatePosition(posX:number, posY:number) {
197 public findRequirement(reqType:string, uniqueId:string, ownerId:string, name:string):Requirement|undefined {
198 let requirement:Requirement = undefined;
199 const searchGroup = (reqType) ? [this.requirements[reqType]] : this.requirements;
200 _.some(_.keys(searchGroup), (searchType) => {
201 requirement = _.find<Requirement>(searchGroup[searchType], (req:Requirement) => (
202 req.uniqueId === uniqueId && req.ownerId === ownerId && req.name === name
209 public findCapability(capType:string, uniqueId:string, ownerId:string, name:string):Capability|undefined {
210 let capability:Capability = undefined;
211 const searchGroup = (capType) ? [this.capabilities[capType]] : this.capabilities;
212 _.some(_.keys(searchGroup), (searchType) => {
213 capability = _.find<Capability>(searchGroup[searchType], (cap:Capability) => (
214 cap.uniqueId === uniqueId && cap.ownerId === ownerId && cap.name === name
221 public toJSON = ():any => {
222 let temp = angular.copy(this);
223 temp.certified = undefined;
224 temp.iconSprite = undefined;
225 temp.inputs = undefined;
226 temp.groupInstances = undefined;
227 temp.properties = undefined;
228 temp.requirements = undefined;
229 temp.capabilities = undefined;
233 public get iconClass() {
234 return this.iconSprite + ' ' + this.icon;
236 public isDependent = () : boolean => {
237 return Array.isArray(this.directives) && this.directives.length > 0;
240 public markAsSelect = () : void => {
241 this.directives.push(DirectivesEnum.SELECT);
244 public markAsSubstitute = () : void => {
245 this.directives.push(DirectivesEnum.SUBSTITUTE);
248 public unmarkAsDependent = (actualDirectiveValue: string) : void => {
249 console.info("[START] this.directives: ", this.directives)
250 let index = this.directives.indexOf(actualDirectiveValue);
252 this.directives.splice(index, 1);
254 console.info("[STOP] this.directives: ", this.directives)