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 import { DataTypePropertyModel } from "../models/data-type-properties";
32 import {PROPERTY_DATA} from "../utils/constants";
34 export interface IDataTypesService {
36 dataTypes:DataTypesMap; //Data type map
37 selectedPropertiesName:string;
38 selectedInput:PropertyModel;
39 alreadySelectedProperties:Array<InputPropertyBase>;
40 selectedInstance:ComponentInstance;
41 selectedComponentInputs:Array<InputModel>;
43 fetchDataTypesByModel(modelName:string):void;
44 getAllDataTypes():DataTypesMap;
45 getFirsLevelOfDataTypeProperties(dataTypeName:string):Array<DataTypePropertyModel>;
46 isDataTypeForSchemaType(property:SchemaProperty):boolean;
47 isDataTypeForPropertyType(property:PropertyModel):boolean;
48 isDataTypeForDataTypePropertyType(property:DataTypePropertyModel):boolean;
51 export class DataTypesService implements IDataTypesService {
59 constructor(private sdcConfig:IAppConfigurtaion,
60 private $q:ng.IQService,
61 private $http:ng.IHttpService) {
64 private baseUrl = this.sdcConfig.api.root + this.sdcConfig.api.component_api_root;
66 dataTypes:DataTypesMap; //Data type map
67 selectedPropertiesName:string;
68 selectedInput:PropertyModel;
69 alreadySelectedProperties:Array<InputPropertyBase>;
70 selectedInstance:ComponentInstance;
71 selectedComponentInputs:Array<InputModel>;
73 public fetchDataTypesByModel = (modelName: string):void => {
76 model = {'model': modelName}
78 this.$http.get(this.baseUrl+"dataTypes", {params: model})
79 .then((response:any) => {
80 this.dataTypes = response.data;
81 delete this.dataTypes['tosca.datatypes.Root'];
85 public getAllDataTypesFromModel = (modelName: string): DataTypesMap => {
86 this.fetchDataTypesByModel(modelName);
87 return this.dataTypes;
90 public getAllDataTypes = ():DataTypesMap => {
91 return this.dataTypes;
94 //if the dt derived from simple- return the first parent type, else- return null
95 private getTypeForDataTypeDerivedFromSimple = (dataTypeName:string):string => {
96 /////////temporary hack for tosca primitives///////////////////////
97 if (!this.dataTypes[dataTypeName]) {
100 ///////////////////////////////////////////////////////////////////
101 if (this.dataTypes[dataTypeName].derivedFromName == "tosca.datatypes.Root" || this.dataTypes[dataTypeName].properties) {
104 if (PROPERTY_DATA.SIMPLE_TYPES.indexOf(this.dataTypes[dataTypeName].derivedFromName) > -1) {
105 return this.dataTypes[dataTypeName].derivedFromName
107 return this.getTypeForDataTypeDerivedFromSimple(this.dataTypes[dataTypeName].derivedFromName);
111 //return list of data type properties and all its parents properties
112 //(not include the properties of its properties, in case this data type has not primitive properties)
113 public getFirsLevelOfDataTypeProperties = (dataTypeName:string):Array<DataTypePropertyModel> => {
114 let properties = this.dataTypes[dataTypeName].properties || [];
115 if (this.dataTypes[dataTypeName].derivedFromName != "tosca.datatypes.Root") {
116 properties = this.getFirsLevelOfDataTypeProperties(this.dataTypes[dataTypeName].derivedFromName).concat(properties);
121 //return false when type= data type (=not simple type) that not derived from simple type
122 public isDataTypeForSchemaType = (property:SchemaProperty):boolean=> {
123 property.simpleType = "";
124 if (property.type && PROPERTY_DATA.TYPES.indexOf(property.type) > -1) {
127 let simpleType = this.getTypeForDataTypeDerivedFromSimple(property.type);
129 property.simpleType = simpleType;
135 public isDataTypeForPropertyType = (property:PropertyModel):boolean=> {
136 property.simpleType = "";
137 if (property.type && PROPERTY_DATA.TYPES.indexOf(property.type) > -1) {
140 let simpleType = this.getTypeForDataTypeDerivedFromSimple(property.type);
142 property.simpleType = simpleType;
149 public isDataTypeForDataTypePropertyType = (property:DataTypePropertyModel):boolean=> {
150 property.simpleType = "";
151 let isScalarForNFoD:boolean = property.type === 'scalar-unit.size';
152 if (property.type && PROPERTY_DATA.TYPES.indexOf(property.type) > -1 || isScalarForNFoD) {
155 let simpleType = this.getTypeForDataTypeDerivedFromSimple(property.type);
157 property.simpleType = simpleType;