2 * Created by ob0695 on 6/26/2018.
5 * ============LICENSE_START=======================================================
7 * ================================================================================
8 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
9 * ================================================================================
10 * Licensed under the Apache License, Version 2.0 (the "License");
11 * you may not use this file except in compliance with the License.
12 * You may obtain a copy of the License at
14 * http://www.apache.org/licenses/LICENSE-2.0
16 * Unless required by applicable law or agreed to in writing, software
17 * distributed under the License is distributed on an "AS IS" BASIS,
18 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 * See the License for the specific language governing permissions and
20 * limitations under the License.
21 * ============LICENSE_END=========================================================
24 import * as _ from "lodash";
25 import {Inject, Injectable} from '@angular/core';
26 import {Observable} from 'rxjs/Observable';
27 import 'rxjs/add/operator/map';
28 import 'rxjs/add/operator/toPromise';
34 FilterPropertiesAssignmentData,
37 InstancePropertiesAPIMap,
42 import {API_QUERY_PARAMS, ArtifactGroupType, COMPONENT_FIELDS} from "app/utils";
43 import {ComponentGenericResponse} from "../responses/component-generic-response";
44 import {InstanceBePropertiesMap} from "../../../models/properties-inputs/property-fe-map";
45 import {ComponentType, ServerTypeUrl, SERVICE_FIELDS} from "../../../utils/constants";
46 import {ISdcConfig, SdcConfigToken} from "../../config/sdc-config.config";
47 import {IDependenciesServerResponse} from "../responses/dependencies-server-response";
48 import {AutomatedUpgradeGenericResponse} from "../responses/automated-upgrade-response";
49 import {IAutomatedUpgradeRequestObj} from "../../pages/automated-upgrade/automated-upgrade.service";
50 import {ComponentInstance} from "../../../models/componentsInstances/componentInstance";
51 import {CommonUtils} from "../../../utils/common-utils";
52 import {RelationshipModel} from "../../../models/graph/relationship";
53 import {ServiceGenericResponse} from "../responses/service-generic-response";
54 import {HttpClient, HttpHeaders, HttpParams} from "@angular/common/http";
55 import {HttpHelperService} from "../http-hepler.service";
56 import {ConsumptionInput} from "../../components/logic/service-consumption/service-consumption.component";
57 import {ConstraintObject} from "../../components/logic/service-dependencies/service-dependencies.component";
58 import {PolicyInstance} from "../../../models/graph/zones/policy-instance";
59 import {PropertyBEModel} from "../../../models/properties-inputs/property-be-model";
60 import {map} from "rxjs/operators";
61 import {CapabilitiesConstraintObject} from "../../components/logic/capabilities-constraint/capabilities-constraint.component";
62 import {BEInterfaceOperationModel, InterfaceOperationModel} from "../../../models/interfaceOperation";
63 import {AttributeBEModel} from "../../../models/attributes-outputs/attribute-be-model";
64 import {InstanceAttributesAPIMap} from "../../../models/attributes-outputs/attribute-fe-map";
66 /* we need to use this service from now, we will remove component.service when we finish remove the angular1.
67 The service is duplicated since we can not use downgrades service with NGXS*/
70 export class TopologyTemplateService {
74 constructor(protected http: HttpClient, @Inject(SdcConfigToken) sdcConfig: ISdcConfig) {
75 this.baseUrl = sdcConfig.api.root + sdcConfig.api.component_api_root;
78 getFullComponent(componentType: string, uniqueId: string): Observable<Component> {
79 return this.http.get<Component>(this.baseUrl + this.getServerTypeUrl(componentType) + uniqueId);
82 getComponentMetadata(uniqueId: string, type: string): Observable<ComponentGenericResponse> {
83 return this.getComponentDataByFieldsName(type, uniqueId, [COMPONENT_FIELDS.COMPONENT_METADATA]);
86 getComponentInstanceAttributesAndProperties(uniqueId: string, type: string): Observable<ComponentGenericResponse> {
87 return this.getComponentDataByFieldsName(type, uniqueId, [COMPONENT_FIELDS.COMPONENT_INSTANCES_PROPERTIES, COMPONENT_FIELDS.COMPONENT_INSTANCES_ATTRIBUTES]);
90 getComponentInstanceAttributesAndPropertiesAndInputs(uniqueId: string, type: string): Observable<ComponentGenericResponse> {
91 return this.getComponentDataByFieldsName(type, uniqueId, [COMPONENT_FIELDS.COMPONENT_INSTANCES_PROPERTIES, COMPONENT_FIELDS.COMPONENT_INSTANCES_ATTRIBUTES, COMPONENT_FIELDS.COMPONENT_INPUTS]);
94 async getComponentAttributes(componentType: string, componentId: string): Promise<ComponentGenericResponse> {
95 return this.getComponentDataByFieldsName(componentType, componentId, [COMPONENT_FIELDS.COMPONENT_ATTRIBUTES]).toPromise();
98 getComponentCompositionData(componentUniqueId: string, componentType: string): Observable<ComponentGenericResponse> {
99 const params: string[] = [COMPONENT_FIELDS.COMPONENT_INSTANCES_RELATION, COMPONENT_FIELDS.COMPONENT_INSTANCES,
100 COMPONENT_FIELDS.COMPONENT_NON_EXCLUDED_POLICIES, COMPONENT_FIELDS.COMPONENT_NON_EXCLUDED_GROUPS];
101 if (componentType === ComponentType.SERVICE) {
102 params.push(COMPONENT_FIELDS.FORWARDING_PATHS);
104 return this.getComponentDataByFieldsName(componentType, componentUniqueId, params);
107 getComponentResourcePropertiesData(component: Component): Observable<ComponentGenericResponse> {
108 return this.getComponentDataByFieldsName(component.componentType, component.uniqueId,
109 [COMPONENT_FIELDS.COMPONENT_INSTANCES, COMPONENT_FIELDS.COMPONENT_POLICIES, COMPONENT_FIELDS.COMPONENT_NON_EXCLUDED_GROUPS]);
112 getComponentInstances(componentType: string, componentId: string): Observable<ComponentGenericResponse> {
113 return this.getComponentDataByFieldsName(componentType, componentId, [COMPONENT_FIELDS.COMPONENT_INSTANCES]);
116 getComponentInputs(component: Component): Observable<ComponentGenericResponse> {
117 return this.getComponentDataByFieldsName(component.componentType, component.uniqueId, [COMPONENT_FIELDS.COMPONENT_INPUTS]);
120 getComponentInputsValues(componentType: string, componentId: string): Observable<ComponentGenericResponse> {
121 return this.getComponentDataByFieldsName(componentType, componentId, [COMPONENT_FIELDS.COMPONENT_INPUTS]);
124 getComponentInputsWithProperties(componentType: string, componentId: string): Observable<ComponentGenericResponse> {
125 return this.getComponentDataByFieldsName(componentType, componentId,
126 [COMPONENT_FIELDS.COMPONENT_INPUTS, COMPONENT_FIELDS.COMPONENT_INSTANCES, COMPONENT_FIELDS.COMPONENT_INSTANCES_PROPERTIES, COMPONENT_FIELDS.COMPONENT_PROPERTIES]);
129 getComponentOutputsWithAttributes(componentType: string, componentId: string): Observable<ComponentGenericResponse> {
130 return this.getComponentDataByFieldsName(componentType, componentId,
131 [COMPONENT_FIELDS.COMPONENT_OUTPUTS, COMPONENT_FIELDS.COMPONENT_INSTANCES, COMPONENT_FIELDS.COMPONENT_INSTANCES_ATTRIBUTES, COMPONENT_FIELDS.COMPONENT_ATTRIBUTES,COMPONENT_FIELDS.COMPONENT_INSTANCES_OUTPUTS]);
134 getComponentDeploymentArtifacts(component: Component): Observable<ComponentGenericResponse> {
135 return this.getComponentDataByFieldsName(component.componentType, component.uniqueId, [COMPONENT_FIELDS.COMPONENT_DEPLOYMENT_ARTIFACTS]);
138 getComponentInformationalArtifacts(component: Component): Observable<ComponentGenericResponse> {
139 return this.getComponentDataByFieldsName(component.componentType, component.uniqueId, [COMPONENT_FIELDS.COMPONENT_INFORMATIONAL_ARTIFACTS]);
142 getComponentInterfaceOperations(componentType: string, componentId: string): Observable<ComponentGenericResponse> {
143 return this.getComponentDataByFieldsName(componentType, componentId, [COMPONENT_FIELDS.COMPONENT_INTERFACE_OPERATIONS]);
146 getComponentInformationalArtifactsAndInstances(component: Component): Observable<ComponentGenericResponse> {
147 return this.getComponentDataByFieldsName(component.componentType, component.uniqueId, [COMPONENT_FIELDS.COMPONENT_INFORMATIONAL_ARTIFACTS, COMPONENT_FIELDS.COMPONENT_INSTANCES]);
150 getComponentToscaArtifacts(componentType: string, componentId: string): Observable<ComponentGenericResponse> {
151 return this.getComponentDataByFieldsName(componentType, componentId, [COMPONENT_FIELDS.COMPONENT_TOSCA_ARTIFACTS]);
154 getComponentProperties(component: Component): Observable<ComponentGenericResponse> {
155 return this.findAllComponentProperties(component.componentType, component.uniqueId);
158 findAllComponentProperties(componentType: string, componentUniqueId: string): Observable<ComponentGenericResponse> {
159 return this.getComponentDataByFieldsName(componentType, componentUniqueId, [COMPONENT_FIELDS.COMPONENT_PROPERTIES]);
162 findAllComponentAttributes(componentType: string, componentUniqueId: string): Observable<ComponentGenericResponse> {
163 return this.getComponentDataByFieldsName(componentType, componentUniqueId, [COMPONENT_FIELDS.COMPONENT_ATTRIBUTES]);
166 getCapabilitiesAndRequirements(componentType: string, componentId: string): Observable<ComponentGenericResponse> {
167 return this.getComponentDataByFieldsName(componentType, componentId, [COMPONENT_FIELDS.COMPONENT_REQUIREMENTS, COMPONENT_FIELDS.COMPONENT_CAPABILITIES]);
170 getRequirementsAndCapabilitiesWithProperties(componentType: string, componentId: string): Observable<ComponentGenericResponse> {
171 return this.getComponentDataByFieldsName(componentType, componentId,
172 [COMPONENT_FIELDS.COMPONENT_REQUIREMENTS, COMPONENT_FIELDS.COMPONENT_CAPABILITIES, COMPONENT_FIELDS.COMPONENT_CAPABILITIES_PROPERTIES]);
175 getDeploymentGraphData(componentType: string, componentId: string): Observable<ComponentGenericResponse> {
176 return this.getComponentDataByFieldsName(componentType, componentId, [COMPONENT_FIELDS.COMPONENT_INSTANCES_RELATION, COMPONENT_FIELDS.COMPONENT_INSTANCES, COMPONENT_FIELDS.COMPONENT_GROUPS]);
179 createInput(component: Component, inputsToCreate: InstancePropertiesAPIMap, isSelf: boolean): Observable<any> {
180 const inputs = isSelf ? { serviceProperties: inputsToCreate.componentInstanceProperties } : inputsToCreate;
181 return this.http.post(this.baseUrl + component.getTypeUrl() + component.uniqueId + '/create/inputs', inputs);
184 createOutput(component: Component, outputsToCreate: InstanceAttributesAPIMap, isSelf: boolean): Observable<any> {
185 const outputs = isSelf ? { serviceProperties: outputsToCreate.componentInstanceAttributes } : outputsToCreate;
186 return this.http.post(this.baseUrl + component.getTypeUrl() + component.uniqueId + '/create/outputs', outputs);
189 restoreComponent(componentType: string, componentId: string) {
190 return this.http.post(this.baseUrl + this.getServerTypeUrl(componentType) + componentId + '/restore', {});
193 archiveComponent(componentType: string, componentId: string) {
194 return this.http.post(this.baseUrl + this.getServerTypeUrl(componentType) + componentId + '/archive', {});
197 deleteInput(component: Component, input: InputBEModel): Observable<InputBEModel> {
198 return this.http.delete<InputBEModel>(this.baseUrl + component.getTypeUrl() + component.uniqueId + '/delete/' + input.uniqueId + '/input')
200 return new InputBEModel(res);
204 updateComponentInputs(component: Component, inputs: InputBEModel[]): Observable<InputBEModel[]> {
205 return this.http.post<InputBEModel[]>(this.baseUrl + component.getTypeUrl() + component.uniqueId + '/update/inputs', inputs)
207 return res.map((input) => new InputBEModel(input));
211 filterComponentInstanceProperties(component: Component, filterData: FilterPropertiesAssignmentData): Observable<InstanceBePropertiesMap> {// instance-property-be-map
212 let params: HttpParams = new HttpParams();
213 _.forEach(filterData.selectedTypes, (type: string) => {
214 params = params.append('resourceType', type);
217 // tslint:disable-next-line:object-literal-shorthand
218 return this.http.get<InstanceBePropertiesMap>(this.baseUrl + component.getTypeUrl() + component.uniqueId + '/filteredproperties/' + filterData.propertyName, {params: params});
221 createServiceProperty(componentId: string, propertyModel: PropertyBEModel): Observable<PropertyBEModel> {
222 const serverObject = {};
223 serverObject[propertyModel.name] = propertyModel;
224 return this.http.post<PropertyBEModel>(this.baseUrl + 'services/' + componentId + '/properties', serverObject)
226 const property: PropertyBEModel = new PropertyBEModel(res);
231 createServiceAttribute(componentId: string, attributeModel: AttributeBEModel): Observable<AttributeBEModel> {
232 const serverObject = {};
233 serverObject[attributeModel.name] = attributeModel;
234 return this.http.post<AttributeBEModel>(this.baseUrl + 'services/' + componentId + '/attributes', serverObject)
236 const attribute: AttributeBEModel = new AttributeBEModel(res);
241 getServiceProperties(componentId: string): Observable<PropertyBEModel[]> {
242 return this.http.get<any>(this.baseUrl + 'services/' + componentId + '/properties')
245 return new Array<PropertyBEModel>();
247 return CommonUtils.initBeProperties(res);
251 getServiceAttributes(componentId: string): Observable<AttributeBEModel[]> {
252 return this.http.get<any>(this.baseUrl + 'services/' + componentId + '/attributes')
255 return new Array<AttributeBEModel>();
257 return CommonUtils.initAttributes(res);
261 updateServiceProperties(componentId: string, properties: PropertyBEModel[]) {
262 return this.http.put<any>( this.baseUrl + 'services/' + componentId + '/properties', properties)
265 return _.map(resJson,
266 (resValue: PropertyBEModel) => new PropertyBEModel(resValue));
270 updateServiceAttributes(componentId: string, attributes: AttributeBEModel[]) {
271 return this.http.put<any>( this.baseUrl + 'services/' + componentId + '/attributes', attributes)
274 return _.map(resJson,
275 (resValue: AttributeBEModel) => new AttributeBEModel(resValue));
279 deleteServiceProperty(componentId: string, property: PropertyBEModel): Observable<string> {
280 return this.http.delete(this.baseUrl + 'services/' + componentId + '/properties/' + property.uniqueId )
281 .map((res: Response) => {
282 return property.uniqueId;
286 createServiceInput(componentId: string, inputModel: InputBEModel): Observable<InputBEModel> {
287 const serverObject = {};
288 serverObject[inputModel.name] = inputModel;
289 return this.http.post<InputBEModel>(this.baseUrl + 'services/' + componentId + '/create/input', serverObject)
291 const input: InputBEModel = new InputBEModel(res);
296 deleteServiceAttribute(componentId: string, attribute: AttributeBEModel): Observable<string> {
297 return this.http.delete(this.baseUrl + 'services/' + componentId + '/attributes/' + attribute.uniqueId )
298 .map((res: Response) => {
299 return attribute.uniqueId;
303 getDependencies(componentType: string, componentId: string): Observable<IDependenciesServerResponse[]> {
304 return this.http.get<IDependenciesServerResponse[]>(this.baseUrl + this.getServerTypeUrl(componentType) + componentId + '/dependencies');
307 automatedUpgrade(componentType: string, componentId: string, componentsIdsToUpgrade: IAutomatedUpgradeRequestObj[]): Observable<AutomatedUpgradeGenericResponse> {
308 return this.http.post<AutomatedUpgradeGenericResponse>(this.baseUrl + this.getServerTypeUrl(componentType) + componentId + '/automatedupgrade', componentsIdsToUpgrade);
311 updateComponentInstance(componentMetaDataId: string, componentType: string, componentInstance:ComponentInstance): Observable<ComponentInstance> {
312 return this.http.post<ComponentInstance>(this.baseUrl + this.getServerTypeUrl(componentType) + componentMetaDataId + '/resourceInstance/' + componentInstance.uniqueId, componentInstance);
315 updateMultipleComponentInstances(componentId: string, componentType: string, instances: ComponentInstance[]): Observable<ComponentInstance[]> {
316 return this.http.post<ComponentInstance[]>(this.baseUrl + this.getServerTypeUrl(componentType) + componentId + '/resourceInstance/multipleComponentInstance', instances)
318 return CommonUtils.initComponentInstances(res);
322 createRelation(componentId: string, componentType: string, link: RelationshipModel): Observable<RelationshipModel> {
323 return this.http.post<RelationshipModel>(this.baseUrl + this.getServerTypeUrl(componentType) + componentId + '/resourceInstance/associate', link)
325 return new RelationshipModel(res);
329 deleteRelation(componentId: string, componentType: string, link: RelationshipModel): Observable<RelationshipModel> {
330 return this.http.put<RelationshipModel>(this.baseUrl + this.getServerTypeUrl(componentType) + componentId + '/resourceInstance/dissociate', link)
332 return new RelationshipModel(res);
336 createComponentInstance(componentType: string, componentId: string, componentInstance: ComponentInstance): Observable<ComponentInstance> {
337 return this.http.post<ComponentInstance>(this.baseUrl + this.getServerTypeUrl(componentType) + componentId + '/resourceInstance', componentInstance)
339 return new ComponentInstance(res);
343 deleteComponentInstance(componentType: string, componentId: string, componentInstanceId: string): Observable<ComponentInstance> {
344 return this.http.delete<ComponentInstance>(this.baseUrl + this.getServerTypeUrl(componentType) + componentId + '/resourceInstance/' + componentInstanceId)
346 return new ComponentInstance(res);
350 fetchRelation(componentType: string, componentId: string, linkId: string): Observable<RelationshipModel> {
351 return this.http.get<RelationshipModel>(this.baseUrl + this.getServerTypeUrl(componentType) + componentId + '/relationId/' + linkId)
353 return new RelationshipModel(res);
357 addOrUpdateArtifact = (componentType: string, componentId: string, artifact: ArtifactModel): Observable<ArtifactModel> => {
358 let headerObj: HttpHeaders = new HttpHeaders();
359 if (artifact.payloadData) {
360 headerObj = headerObj.append('Content-MD5', HttpHelperService.getHeaderMd5(artifact));
363 let artifactID: string = '';
364 if (artifact.uniqueId) {
365 artifactID = '/' + artifact.uniqueId;
367 return this.http.post<ArtifactModel>(this.baseUrl + this.getServerTypeUrl(componentType) + componentId + '/artifacts' + artifactID, JSON.stringify(artifact), {headers: headerObj}).map(
368 (res) => new ArtifactModel(res)
372 deleteArtifact = (componentId: string, componentType: string, artifactId: string, artifactLabel: string): Observable<ArtifactModel> => {
373 return this.http.delete<ArtifactModel>(this.baseUrl + this.getServerTypeUrl(componentType) + componentId + '/artifacts/' + artifactId + '?operation=' + artifactLabel)
374 .map((res) => new ArtifactModel(res));
377 downloadArtifact = (componentType: string, componentId: string, artifactId: string): Observable<IFileDownload> => {
378 return this.http.get<IFileDownload>(this.baseUrl + this.getServerTypeUrl(componentType) + componentId + '/artifacts/' + artifactId);
381 // ------------------------------------------------ Properties API --------------------------------------------------//
382 addProperty = (componentType: string, componentId: string, property: PropertyModel):Observable<PropertyModel> => {
383 return this.http.post<PropertyModel>(this.baseUrl + this.getServerTypeUrl(componentType) + componentId + '/properties', property.convertToServerObject())
385 return new PropertyModel(response);
389 updateProperty = (componentType: string, componentId: string, property: PropertyModel): Observable<PropertyModel> => {
390 const propertiesList: PropertyBEModel[] = [property];
391 return this.http.put<PropertyModel>(this.baseUrl + this.getServerTypeUrl(componentType) + componentId + '/properties', propertiesList)
393 return new PropertyModel(response[Object.keys(response)[0]]);
397 deleteProperty = (componentType: string, componentId: string, propertyId: string): Observable<PropertyModel> => {
398 return this.http.delete<PropertyModel>(this.baseUrl + this.getServerTypeUrl(componentType) + componentId + '/properties/' + propertyId);
401 // ------------------------------------------------ Attributes API --------------------------------------------------//
402 addAttribute = (componentType: string, componentId: string, attribute: AttributeModel): Observable<AttributeModel> => {
403 return this.http.post<AttributeModel>(this.baseUrl + this.getServerTypeUrl(componentType) + componentId + '/attributes', attribute.convertToServerObject())
405 return new AttributeModel(response);
409 updateAttribute = (componentType: string, componentId: string, attribute: AttributeModel): Observable<AttributeModel> => {
410 const payload = attribute.convertToServerObject();
412 return this.http.put<AttributeModel>(this.baseUrl + this.getServerTypeUrl(componentType) + componentId + '/attributes/' + attribute.uniqueId, payload)
414 return new AttributeModel(response);
419 addAttributeAsync = async (componentType: string, componentId: string, attribute: AttributeModel): Promise<AttributeModel> => {
420 return this.addAttribute(componentType, componentId, attribute).toPromise();
423 updateAttributeAsync = async (componentType: string, componentId: string, attribute: AttributeModel): Promise<AttributeModel> => {
424 return this.updateAttribute(componentType, componentId, attribute).toPromise();
427 deleteAttributeAsync = async (componentType: string, componentId: string, attribute: AttributeModel): Promise<any> => {
428 return this.http.delete<any>(this.baseUrl + this.getServerTypeUrl(componentType) + componentId + '/attributes/' + attribute.uniqueId, {}).toPromise();
431 getArtifactsByType(componentType: string, componentId: string, artifactsType: ArtifactGroupType) {
432 return this.getComponentDataByFieldsName(componentType, componentId, [this.convertArtifactTypeToUrl(artifactsType)]);
435 getServiceConsumptionData(componentType: string, componentId: string): Observable<ComponentGenericResponse> {
436 return this.getComponentDataByFieldsName(componentType, componentId, [
437 // COMPONENT_FIELDS.COMPONENT_INSTANCES_INTERFACES,
438 COMPONENT_FIELDS.COMPONENT_INSTANCES_PROPERTIES,
439 // COMPONENT_FIELDS.COMPONENT_INSTANCES_INPUTS,
440 COMPONENT_FIELDS.COMPONENT_INPUTS,
441 COMPONENT_FIELDS.COMPONENT_INSTANCES,
442 COMPONENT_FIELDS.COMPONENT_CAPABILITIES
446 getServiceConsumptionInputs(componentMetaDataId: string, serviceInstanceId: string, interfaceId: string, operation: OperationModel): Observable<ConsumptionInput[]> {
447 return this.http.get<ConsumptionInput[]>
448 (this.baseUrl + 'services/' + componentMetaDataId + '/consumption/' + serviceInstanceId + '/interfaces/' + interfaceId + '/operations/' + operation.uniqueId + '/inputs');
451 createOrUpdateServiceConsumptionInputs(componentMetaDataId: string, serviceInstanceId: string, consumptionInputsList: Array<{[id: string]: ConsumptionInput[]}>): Observable<any> {
452 return this.http.post(this.baseUrl + 'services/' + componentMetaDataId + '/consumption/' + serviceInstanceId, consumptionInputsList);
455 getServiceFilterConstraints(componentType: string, componentId: string): Observable<ComponentGenericResponse> {
456 return this.getComponentDataByFieldsName(componentType, componentId, [SERVICE_FIELDS.NODE_FILTER]);
459 getSubstitutionFilterConstraints(componentType: string, componentId: string): Observable<ComponentGenericResponse> {
460 return this.getComponentDataByFieldsName(componentType, componentId, [SERVICE_FIELDS.SUBSTITUTION_FILTER]);
463 getComponentInstanceProperties(componentType: string, componentId: string): Observable<ComponentGenericResponse> {
464 return this.getComponentDataByFieldsName(componentType, componentId, [COMPONENT_FIELDS.COMPONENT_INSTANCES_PROPERTIES]);
467 findAllComponentInstanceAttributes(componentType: string, componentId: string): Observable<ComponentGenericResponse> {
468 return this.getComponentDataByFieldsName(componentType, componentId, [COMPONENT_FIELDS.COMPONENT_INSTANCES_ATTRIBUTES]);
471 getComponentInstanceCapabilityProperties(componentType: string, componentId: string): Observable<ComponentGenericResponse> {
472 return this.getComponentDataByFieldsName(componentType, componentId,
473 [COMPONENT_FIELDS.COMPONENT_CAPABILITIES, COMPONENT_FIELDS.COMPONENT_CAPABILITIES_PROPERTIES]);
476 createServiceFilterConstraints(componentMetaDataId: string, componentInstanceId: string, constraint: ConstraintObject, componentType: string, constraintType: string): Observable<any> {
477 return this.http.post<any>(this.baseUrl + this.getServerTypeUrl(componentType) + componentMetaDataId + '/componentInstance/' + componentInstanceId + '/' + constraintType + '/nodeFilter', constraint);
480 createServiceFilterCapabilitiesConstraints(componentMetaDataId: string, componentInstanceId: string, constraint: CapabilitiesConstraintObject, componentType: string, constraintType: string): Observable<any> {
481 return this.http.post<any>(this.baseUrl + this.getServerTypeUrl(componentType) + componentMetaDataId + '/componentInstance/' + componentInstanceId + '/' + constraintType + '/nodeFilter', constraint);
484 updateServiceFilterConstraints(componentMetaDataId: string, componentInstanceId: string, constraints: ConstraintObject, componentType: string, constraintType: string, constraintIndex: number):Observable<any>{
485 return this.http.put<any>(this.baseUrl + this.getServerTypeUrl(componentType) + componentMetaDataId + '/componentInstance/' + componentInstanceId + '/' + constraintType + '/' + constraintIndex + '/nodeFilter', constraints)
488 updateServiceFilterCapabilitiesConstraint(componentMetaDataId: string, componentInstanceId: string, constraints: CapabilitiesConstraintObject, componentType: string, constraintType: string, constraintIndex: number):Observable<any>{
489 return this.http.put<any>(this.baseUrl + this.getServerTypeUrl(componentType) + componentMetaDataId + '/componentInstance/' + componentInstanceId + '/' + constraintType + '/' + constraintIndex + '/nodeFilter', constraints)
492 deleteServiceFilterConstraints(componentMetaDataId: string, componentInstanceId: string, constraintIndex: number, componentType: string, constraintType: string): Observable<any>{
493 return this.http.delete<any>(this.baseUrl + this.getServerTypeUrl(componentType) + componentMetaDataId + '/componentInstance/' + componentInstanceId + '/' + constraintType + '/' + constraintIndex + '/nodeFilter')
496 getComponentPropertiesAndInputsForSubstitutionFilter(componentType: string, componentId: string): Observable<ComponentGenericResponse> {
497 return this.getComponentDataByFieldsName(componentType, componentId, [COMPONENT_FIELDS.COMPONENT_PROPERTIES, COMPONENT_FIELDS.COMPONENT_INPUTS]);
500 createSubstitutionFilterConstraints(componentMetaDataId: string, constraint: ConstraintObject, componentType: string, constraintType: string): Observable<any> {
501 return this.http.post<any>(this.baseUrl + this.getServerTypeUrl(componentType) + componentMetaDataId + '/substitutionFilter/' + constraintType, constraint);
504 updateSubstitutionFilterConstraints(componentMetaDataId: string, constraint: ConstraintObject[], componentType: string, constraintType: string): Observable<any>{
505 return this.http.put<any>(this.baseUrl + this.getServerTypeUrl(componentType) + componentMetaDataId + '/substitutionFilter/' + constraintType, constraint);
508 deleteSubstitutionFilterConstraints(componentMetaDataId: string, constraintIndex: number, componentType: string, constraintType: string): Observable<any>{
509 return this.http.delete<any>(this.baseUrl + this.getServerTypeUrl(componentType) + componentMetaDataId + '/substitutionFilter/' + constraintType + "/" + constraintIndex)
512 deletePolicy(component: Component, policy: PolicyInstance): Observable<PolicyInstance> {
513 return this.http.put<PolicyInstance>(this.baseUrl + component.getTypeUrl() + component.uniqueId + '/policies/' + policy.uniqueId + '/undeclare', policy)
516 createListInput(component: Component, input: any, isSelf: boolean): Observable<any> {
519 // change componentInstanceProperties -> serviceProperties
521 componentInstInputsMap: {
522 serviceProperties: input.componentInstInputsMap.componentInstanceProperties
524 listInput: input.listInput
529 return this.http.post<any>(this.baseUrl + component.getTypeUrl() + component.uniqueId + '/create/listInput', inputs);
532 createPolicy(component: Component, policiesToCreate: InstancePropertiesAPIMap, isSelf: boolean): Observable<any> {
535 // tslint:disable-next-line:object-literal-key-quotes
536 {'componentPropertiesToPolicies': {
537 ...policiesToCreate.componentInstanceProperties
540 // tslint:disable-next-line:object-literal-key-quotes
541 {'componentInstancePropertiesToPolicies': {
542 ...policiesToCreate.componentInstanceProperties
545 return this.http.post(this.baseUrl + component.getTypeUrl() + component.uniqueId + '/create/policies', policiesList);
548 protected getComponentDataByFieldsName(componentType: string, componentId: string, fields: string[]): Observable<ComponentGenericResponse> {
549 let params: HttpParams = new HttpParams();
550 _.forEach(fields, (field: string): void => {
551 params = params.append(API_QUERY_PARAMS.INCLUDE, field);
553 // tslint:disable-next-line:object-literal-shorthand
554 return this.http.get<ComponentGenericResponse>(this.baseUrl + this.getServerTypeUrl(componentType) + componentId + '/filteredDataByParams', {params: params})
556 return componentType === ComponentType.SERVICE ? new ServiceGenericResponse().deserialize(res) :
557 new ComponentGenericResponse().deserialize(res);
561 private getServerTypeUrl = (componentType: string): string => {
562 switch (componentType) {
563 case ComponentType.SERVICE:
564 case ComponentType.SERVICE_PROXY:
565 case ComponentType.SERVICE_SUBSTITUTION:
566 return ServerTypeUrl.SERVICES;
568 return ServerTypeUrl.RESOURCES;
572 private convertArtifactTypeToUrl = (artifactType: ArtifactGroupType): string => {
573 switch (artifactType) {
574 case ArtifactGroupType.TOSCA:
575 return COMPONENT_FIELDS.COMPONENT_TOSCA_ARTIFACTS;
576 case ArtifactGroupType.INFORMATION:
577 return COMPONENT_FIELDS.COMPONENT_INFORMATIONAL_ARTIFACTS;
578 case ArtifactGroupType.DEPLOYMENT:
579 return COMPONENT_FIELDS.COMPONENT_DEPLOYMENT_ARTIFACTS;
580 case ArtifactGroupType.SERVICE_API:
581 return COMPONENT_FIELDS.SERVICE_API_ARTIFACT;
585 // createCapability(component: Component, capabilityData: Capability): Observable<Capability[]> {
586 createCapability(type: string, uniqueId: string, capabilityData: Capability): Observable<Capability[]> {
589 [capabilityData.type]: [capabilityData]
592 return this.http.post<any>(this.baseUrl + type + uniqueId + '/capabilities', capBEObj);
595 updateCapability(type: string, uniqueId: string, capabilityData: Capability): Observable<Capability[]> {
598 [capabilityData.type]: [capabilityData]
601 return this.http.put<any>(this.baseUrl + type + uniqueId + '/capabilities', capBEObj);
604 deleteCapability(component: Component, capId: string): Observable<Capability> {
605 return this.http.delete<Capability>(this.baseUrl + component.getTypeUrl() + component.uniqueId + '/capabilities/' + capId);
608 createRequirement(type: string, uniqueId: string, requirementData: Requirement): Observable<any> {
611 [requirementData.capability]: [requirementData]
614 return this.http.post(this.baseUrl + type + uniqueId + '/requirements', reqBEObj);
617 updateRequirement(type: string, uniqueId: string, requirementData: Requirement): Observable<any> {
620 [requirementData.capability]: [requirementData]
623 return this.http.put(this.baseUrl + type + uniqueId + '/requirements', reqBEObj);
626 deleteRequirement(component: Component, reqId: string): Observable<Requirement> {
627 return this.http.delete<Requirement>(this.baseUrl + component.getTypeUrl() + component.uniqueId + '/requirements/' + reqId);
630 getDirectiveList(): Observable<string[]> {
631 return this.http.get<ListDirectiveResponse>(this.baseUrl + "directives")
632 .pipe(map(response => response.directives));
635 updateComponentInstanceInterfaceOperation(componentMetaDataId: string,
636 componentMetaDataType: string,
637 componentInstanceId: string,
638 operation: InterfaceOperationModel): Observable<ComponentInstance> {
639 const operationList = {
641 [operation.interfaceType]: {
642 type: operation.interfaceType,
644 [operation.name]: new BEInterfaceOperationModel(operation)
649 return this.http.put<ComponentInstance>(this.baseUrl + this
650 .getServerTypeUrl(componentMetaDataType) + componentMetaDataId + '/componentInstance/' + componentInstanceId + '/interfaceOperation', operationList);