1 import { Injectable } from "@angular/core";
2 import { TopologyTemplateService } from "../../../services/component-services/topology-template.service";
3 import { Store } from "@ngxs/store";
4 import { SdcUiServices } from "onap-ui-angular";
5 import { CapabilityTypeModel } from "../../../../models/capability-types";
6 import { RelationshipTypeModel } from "../../../../models/relationship-types";
7 import { NodeTypeModel } from "../../../../models/node-types";
8 import { WorkspaceService } from "../workspace.service";
9 import { ToscaTypesServiceNg2 } from "../../../services/tosca-types.service";
14 export class ReqAndCapabilitiesService {
16 private capabilityTypesList: CapabilityTypeModel[];
17 private relationshipTypesList: RelationshipTypeModel[];
18 private nodeTypesList: NodeTypeModel[];
20 readonly INPUTS_FOR_REQUIREMENTS: string = 'INPUTS_FOR_REQUIREMENTS';
21 readonly INPUTS_FOR_CAPABILITIES: string = 'INPUTS_FOR_CAPABILITIES';
24 private workspaceService: WorkspaceService,
25 private modalService: SdcUiServices.ModalService,
26 private loaderService: SdcUiServices.LoaderService,
27 private topologyTemplateService: TopologyTemplateService,
29 private toscaTypesServiceNg2: ToscaTypesServiceNg2){}
31 public isViewOnly = (): boolean => {
32 return this.store.selectSnapshot((state) => state.workspace.isViewOnly);
35 public isDesigner = (): boolean => {
36 return this.store.selectSnapshot((state) => state.workspace.isDesigner);
39 public async initInputs(initInputsFor: string) {
41 // -- COMMON for both --
42 this.capabilityTypesList = [];
43 let capabilityTypesResult = await this.toscaTypesServiceNg2.fetchCapabilityTypes(this.workspaceService.metadata.model);
44 Object.keys(capabilityTypesResult).forEach(key => {this.capabilityTypesList.push(capabilityTypesResult[key])});
45 this.capabilityTypesList.sort((capabilityType1, capabilityType2) => capabilityType1.toscaPresentation.type.localeCompare(capabilityType2.toscaPresentation.type));
47 if (initInputsFor === 'INPUTS_FOR_REQUIREMENTS') {
48 this.relationshipTypesList = [];
49 let relationshipTypesResult = await this.toscaTypesServiceNg2.fetchRelationshipTypes(this.workspaceService.metadata.model);
50 Object.keys(relationshipTypesResult).forEach(key => {this.relationshipTypesList.push(relationshipTypesResult[key])});
51 this.relationshipTypesList.sort((relationship1,relationship2) => relationship1.toscaPresentation.type.localeCompare(relationship2.toscaPresentation.type));
53 this.nodeTypesList = [];
54 let nodeTypesResult = await this.toscaTypesServiceNg2.fetchNodeTypes(this.workspaceService.metadata.model);
55 Object.keys(nodeTypesResult).forEach(key => {this.nodeTypesList.push(nodeTypesResult[key])});
56 this.nodeTypesList.sort((node1,node2) => node1.componentMetadataDefinition.componentMetadataDataDefinition.toscaResourceName.localeCompare(node2.componentMetadataDefinition.componentMetadataDataDefinition.toscaResourceName));
60 getCapabilityTypesList() {
61 return this.capabilityTypesList;
64 getRelationsShipeTypeList() {
65 return this.relationshipTypesList;
69 return this.nodeTypesList;