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=========================================================
21 import {PROPERTY_DATA, PROPERTY_TYPES} from 'app/utils/constants';
22 import {SchemaProperty, SchemaPropertyGroupModel} from '../schema-property';
23 import {ToscaPresentationData} from '../tosca-presentation';
24 import {PropertyInputDetail} from './property-input-detail';
25 import {Metadata} from '../metadata';
26 import {ToscaFunction} from "../tosca-function";
27 import {ToscaGetFunction} from "../tosca-get-function";
28 import {ToscaGetFunctionTypeConverter} from "../tosca-get-function-type-converter";
29 import {ToscaGetFunctionDto} from "../tosca-get-function-dto";
31 export enum DerivedPropertyType {
37 export class PropertyPolicyDetail {
40 constructor(propertyPolicy?: PropertyPolicyDetail) {
42 this.policyId = propertyPolicy.policyId;
43 this.propertyName = propertyPolicy.propertyName;
48 export class PropertyBEModel {
55 getInputValues: PropertyInputDetail[];
56 getPolicyValues: PropertyPolicyDetail[];
59 parentUniqueId: string;
62 schema: SchemaPropertyGroupModel;
67 parentPropertyType: string;
68 subPropertyInputPath: string;
70 toscaPresentation: ToscaPresentationData;
73 * @deprecated Use toscaFunction instead
75 toscaGetFunction: ToscaGetFunctionDto;
76 toscaFunction: ToscaFunction;
78 constructor(property?: PropertyBEModel) {
80 this.constraints = property.constraints;
81 this.defaultValue = property.defaultValue;
82 this.description = property.description;
83 this.fromDerived = property.fromDerived;
84 this.name = property.name;
85 this.origName = property.origName;
86 this.parentUniqueId = property.parentUniqueId;
87 this.password = property.password;
88 this.required = property.required;
89 this.schema = property.schema;
90 this.schemaType = property.schemaType;
91 this.type = property.type;
92 this.uniqueId = property.uniqueId;
93 this.value = property.value;
94 this.definition = property.definition;
95 this.getInputValues = property.getInputValues;
96 this.parentPropertyType = property.parentPropertyType;
97 this.subPropertyInputPath = property.subPropertyInputPath;
98 this.toscaPresentation = property.toscaPresentation;
99 this.getPolicyValues = property.getPolicyValues;
100 this.inputPath = property.inputPath;
101 this.metadata = property.metadata;
102 if (property.toscaFunction) {
103 this.toscaFunction = property.toscaFunction;
104 } else if (property.toscaGetFunction) {
105 //support for legacy tosca function
106 const toscaGetFunction1 = new ToscaGetFunction();
107 toscaGetFunction1.type = ToscaGetFunctionTypeConverter.convertToToscaFunctionType(property.toscaGetFunction.functionType);
108 toscaGetFunction1.propertyUniqueId = property.toscaGetFunction.propertyUniqueId;
109 toscaGetFunction1.propertyName = property.toscaGetFunction.propertyName;
110 toscaGetFunction1.propertySource = property.toscaGetFunction.propertySource;
111 toscaGetFunction1.sourceUniqueId = property.toscaGetFunction.sourceUniqueId;
112 toscaGetFunction1.sourceName = property.toscaGetFunction.sourceName;
113 toscaGetFunction1.functionType = property.toscaGetFunction.functionType;
114 toscaGetFunction1.propertyPathFromSource = property.toscaGetFunction.propertyPathFromSource;
115 this.toscaFunction = toscaGetFunction1;
119 if (!this.schema || !this.schema.property) {
120 this.schema = new SchemaPropertyGroupModel(new SchemaProperty());
121 } else { // forcing creating new object, so editing different one than the object in the table
122 this.schema = new SchemaPropertyGroupModel(new SchemaProperty(this.schema.property));
126 public toJSON = (): any => {
127 const temp = angular.copy(this);
128 temp.value = temp.value === '{}' || temp.value === '[]' ? undefined : temp.value;
129 temp.defaultValue = temp.defaultValue === '{}' || temp.defaultValue === '[]' ? undefined : temp.defaultValue;
133 public getDerivedPropertyType = (): DerivedPropertyType => {
134 if (PROPERTY_DATA.SIMPLE_TYPES.indexOf(this.type) > -1) {
135 return DerivedPropertyType.SIMPLE;
137 if (this.type === PROPERTY_TYPES.LIST) {
138 return DerivedPropertyType.LIST;
140 if (this.type === PROPERTY_TYPES.MAP) {
141 return DerivedPropertyType.MAP;
143 return DerivedPropertyType.COMPLEX;
147 * Parses default value to JSON.
149 public parseDefaultValueToJson(): any {
150 if (this.defaultValue == undefined) {
154 const propertyType: DerivedPropertyType = this.getDerivedPropertyType();
155 if (propertyType == DerivedPropertyType.SIMPLE) {
156 return this.parseDefaultSimpleValue();
160 return JSON.parse(this.defaultValue);
162 console.error(`Could not parse the property of type '${this.type}' default value to JSON '${this.defaultValue}'`, e);
168 private parseDefaultSimpleValue() {
170 case PROPERTY_TYPES.INTEGER:
172 return parseInt(this.defaultValue);
174 console.error(`Could not parse the property of type '${this.type}' default value to int '${this.defaultValue}'`, e);
177 case PROPERTY_TYPES.FLOAT:
179 return parseFloat(this.defaultValue);
181 console.error(`Could not parse the property of type '${this.type}' default value to float '${this.defaultValue}'`, e);
184 case PROPERTY_TYPES.BOOLEAN:
185 return this.defaultValue === 'true';
187 return this.defaultValue;
192 * Checks whether the property value is a tosca get function (e.g. get_input, get_property, get_attribute)
194 public isToscaGetFunction(): boolean {
195 return this.toscaFunction != null;