diff options
Diffstat (limited to 'catalog-ui/src/app/models')
-rw-r--r-- | catalog-ui/src/app/models/data-types-map.ts | 10 | ||||
-rw-r--r-- | catalog-ui/src/app/models/data-types.ts | 35 | ||||
-rw-r--r-- | catalog-ui/src/app/models/interfaceOperation.ts | 28 | ||||
-rw-r--r-- | catalog-ui/src/app/models/properties-inputs/property-be-model.ts | 56 |
4 files changed, 115 insertions, 14 deletions
diff --git a/catalog-ui/src/app/models/data-types-map.ts b/catalog-ui/src/app/models/data-types-map.ts index 3591bc2705..e7b1c6922a 100644 --- a/catalog-ui/src/app/models/data-types-map.ts +++ b/catalog-ui/src/app/models/data-types-map.ts @@ -25,13 +25,13 @@ import {DataTypeModel} from "./data-types"; export class DataTypesMapData { - [dataTypeId:string]:Array<DataTypeModel>; + [dataTypeId: string]: Array<DataTypeModel>; } export class DataTypesMap { - dataTypesMap:DataTypesMapData; + dataTypesMap: DataTypesMapData; - constructor(dataTypesMap:DataTypesMapData) { - this.dataTypesMap = dataTypesMap; - } + constructor(dataTypesMap: DataTypesMapData) { + this.dataTypesMap = dataTypesMap; + } } diff --git a/catalog-ui/src/app/models/data-types.ts b/catalog-ui/src/app/models/data-types.ts index 7004b43cbc..7fc788bf93 100644 --- a/catalog-ui/src/app/models/data-types.ts +++ b/catalog-ui/src/app/models/data-types.ts @@ -25,6 +25,7 @@ import {PropertyBEModel} from "./properties-inputs/property-be-model"; import {AttributeBEModel} from "./attributes-outputs/attribute-be-model"; import {Model} from "./model"; +import {PROPERTY_DATA} from "../utils/constants"; export class DataTypeModel { @@ -39,16 +40,24 @@ export class DataTypeModel { attributes: Array<AttributeBEModel>; model: Model; - constructor(dataType:DataTypeModel) { + constructor(dataType: DataTypeModel) { if (dataType) { this.uniqueId = dataType.uniqueId; this.name = dataType.name; this.derivedFromName = dataType.derivedFromName; + if (dataType.derivedFrom) { + this.derivedFrom = new DataTypeModel(dataType.derivedFrom); + } this.creationTime = dataType.creationTime; this.modificationTime = dataType.modificationTime; - this.properties = dataType.properties; + if (dataType.properties) { + this.properties = []; + dataType.properties.forEach(property => { + this.properties.push(new PropertyBEModel(property)); + }); + } this.attributes = dataType.attributes; - this.model = this.model; + this.model = dataType.model; } } @@ -56,5 +65,25 @@ export class DataTypeModel { return this; }; + + /** + * Parses the default value to JSON. + */ + public parseDefaultValueToJson(): any { + if (PROPERTY_DATA.TYPES.indexOf(this.name) > -1) { + return undefined; + } + const defaultValue = {}; + if (this.properties) { + this.properties.forEach(property => { + const propertyDefaultValue = property.parseDefaultValueToJson(); + if (propertyDefaultValue != undefined) { + defaultValue[property.name] = propertyDefaultValue; + } + }); + } + + return defaultValue === {} ? undefined : defaultValue; + } } diff --git a/catalog-ui/src/app/models/interfaceOperation.ts b/catalog-ui/src/app/models/interfaceOperation.ts index 109babb068..9d8ab366a2 100644 --- a/catalog-ui/src/app/models/interfaceOperation.ts +++ b/catalog-ui/src/app/models/interfaceOperation.ts @@ -20,21 +20,47 @@ 'use strict'; import {ArtifactModel} from "./artifacts"; +import {SchemaPropertyGroupModel} from "./schema-property"; +import {PROPERTY_DATA, PROPERTY_TYPES} from "../utils/constants"; export class InputOperationParameter { name: string; type: string; + schema: SchemaPropertyGroupModel; inputId: string; toscaDefaultValue?: string; + value?: any; constructor(param?: any) { if (param) { this.name = param.name; this.type = param.type; + this.schema = param.schema; this.inputId = param.inputId; this.toscaDefaultValue = param.toscaDefaultValue; + this.value = param.value; + } + } + + public getDefaultValue(): any { + if (this.isTypeNotSimple()) { + if (this.toscaDefaultValue) { + this.toscaDefaultValue = JSON.parse(this.toscaDefaultValue); + return JSON.parse(this.toscaDefaultValue); + } + switch (this.type) { + case PROPERTY_TYPES.LIST: + return []; + default: + return {}; + } } - console.info("InputOperationParameter Constructor: ", param) + + return this.toscaDefaultValue; + } + + private isTypeNotSimple() { + return PROPERTY_DATA.SIMPLE_TYPES.indexOf(this.type) == -1; } } diff --git a/catalog-ui/src/app/models/properties-inputs/property-be-model.ts b/catalog-ui/src/app/models/properties-inputs/property-be-model.ts index bd65c3a70a..267a2adc71 100644 --- a/catalog-ui/src/app/models/properties-inputs/property-be-model.ts +++ b/catalog-ui/src/app/models/properties-inputs/property-be-model.ts @@ -109,15 +109,61 @@ export class PropertyBEModel { return temp; } - public getDerivedPropertyType = () => { + public getDerivedPropertyType = (): DerivedPropertyType => { if (PROPERTY_DATA.SIMPLE_TYPES.indexOf(this.type) > -1) { return DerivedPropertyType.SIMPLE; - } else if (this.type === PROPERTY_TYPES.LIST) { + } + if (this.type === PROPERTY_TYPES.LIST) { return DerivedPropertyType.LIST; - } else if (this.type === PROPERTY_TYPES.MAP) { + } + if (this.type === PROPERTY_TYPES.MAP) { return DerivedPropertyType.MAP; - } else { - return DerivedPropertyType.COMPLEX; + } + return DerivedPropertyType.COMPLEX; + } + + /** + * Parses default value to JSON. + */ + public parseDefaultValueToJson(): any { + if (this.defaultValue == undefined) { + return undefined; + } + + const propertyType: DerivedPropertyType = this.getDerivedPropertyType(); + if (propertyType == DerivedPropertyType.SIMPLE) { + return this.parseDefaultSimpleValue(); + } + + try { + return JSON.parse(this.defaultValue); + } catch (e) { + console.error(`Could not parse the property of type '${this.type}' default value to JSON '${this.defaultValue}'`, e); + } + + return undefined; + } + + private parseDefaultSimpleValue() { + switch (this.type) { + case PROPERTY_TYPES.INTEGER: + try { + return parseInt(this.defaultValue); + } catch (e) { + console.error(`Could not parse the property of type '${this.type}' default value to int '${this.defaultValue}'`, e); + } + return undefined; + case PROPERTY_TYPES.FLOAT: + try { + return parseFloat(this.defaultValue); + } catch (e) { + console.error(`Could not parse the property of type '${this.type}' default value to float '${this.defaultValue}'`, e); + } + return undefined; + case PROPERTY_TYPES.BOOLEAN: + return this.defaultValue === 'true'; + default: + return this.defaultValue; } } |