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";
23 import {ComponentInstance, InputModel, DataTypesMap, PropertyModel, InputPropertyBase, IAppConfigurtaion, SchemaProperty} from "../models";
24 import {PROPERTY_DATA} from "../utils/constants";
26 export interface IDataTypesService {
28 dataTypes:DataTypesMap; //Data type map
29 selectedPropertiesName:string;
30 selectedInput:PropertyModel;
31 alreadySelectedProperties:Array<InputPropertyBase>;
32 selectedInstance:ComponentInstance;
33 selectedComponentInputs:Array<InputModel>;
36 getAllDataTypes():DataTypesMap;
37 getFirsLevelOfDataTypeProperties(dataTypeName:string):Array<DataTypePropertyModel>;
38 isDataTypeForSchemaType(property:SchemaProperty):boolean;
39 isDataTypeForPropertyType(property:PropertyModel):boolean;
40 isDataTypeForDataTypePropertyType(property:DataTypePropertyModel):boolean;
43 export class DataTypesService implements IDataTypesService {
51 constructor(private sdcConfig:IAppConfigurtaion,
52 private $q:ng.IQService,
53 private $http:ng.IHttpService) {
57 dataTypes:DataTypesMap; //Data type map
58 selectedPropertiesName:string;
59 selectedInput:PropertyModel;
60 alreadySelectedProperties:Array<InputPropertyBase>;
61 selectedInstance:ComponentInstance;
62 selectedComponentInputs:Array<InputModel>;
64 public initDataTypes = ():void => {
66 url: this.sdcConfig.api.root + this.sdcConfig.api.component_api_root + "dataTypes",
68 }).then((response:any) => {
69 this.dataTypes = response.data;
70 delete this.dataTypes['tosca.datatypes.Root'];
74 public getAllDataTypes = ():DataTypesMap => {
75 return this.dataTypes;
78 //if the dt derived from simple- return the first parent type, else- return null
79 private getTypeForDataTypeDerivedFromSimple = (dataTypeName:string):string => {
80 /////////temporary hack for tosca primitives///////////////////////
81 if (!this.dataTypes[dataTypeName]) {
84 ///////////////////////////////////////////////////////////////////
85 if (this.dataTypes[dataTypeName].derivedFromName == "tosca.datatypes.Root" || this.dataTypes[dataTypeName].properties) {
88 if (PROPERTY_DATA.SIMPLE_TYPES.indexOf(this.dataTypes[dataTypeName].derivedFromName) > -1) {
89 return this.dataTypes[dataTypeName].derivedFromName
91 return this.getTypeForDataTypeDerivedFromSimple(this.dataTypes[dataTypeName].derivedFromName);
95 //return list of data type properties and all its parents properties
96 //(not include the properties of its properties, in case this data type has not primitive properties)
97 public getFirsLevelOfDataTypeProperties = (dataTypeName:string):Array<DataTypePropertyModel> => {
98 let properties = this.dataTypes[dataTypeName].properties || [];
99 if (this.dataTypes[dataTypeName].derivedFromName != "tosca.datatypes.Root") {
100 properties = this.getFirsLevelOfDataTypeProperties(this.dataTypes[dataTypeName].derivedFromName).concat(properties);
105 //return false when type= data type (=not simple type) that not derived from simple type
106 public isDataTypeForSchemaType = (property:SchemaProperty):boolean=> {
107 property.simpleType = "";
108 if (property.type && PROPERTY_DATA.TYPES.indexOf(property.type) > -1) {
111 let simpleType = this.getTypeForDataTypeDerivedFromSimple(property.type);
113 property.simpleType = simpleType;
119 public isDataTypeForPropertyType = (property:PropertyModel):boolean=> {
120 property.simpleType = "";
121 if (property.type && PROPERTY_DATA.TYPES.indexOf(property.type) > -1) {
124 let simpleType = this.getTypeForDataTypeDerivedFromSimple(property.type);
126 property.simpleType = simpleType;
133 public isDataTypeForDataTypePropertyType = (property:DataTypePropertyModel):boolean=> {
134 property.simpleType = "";
135 let isScalarForNFoD:boolean = property.type === 'scalar-unit.size';
136 if (property.type && PROPERTY_DATA.TYPES.indexOf(property.type) > -1 || isScalarForNFoD) {
139 let simpleType = this.getTypeForDataTypeDerivedFromSimple(property.type);
141 property.simpleType = simpleType;