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 {ToscaGetFunctionType} from "../tosca-get-function-type";
27 import {ToscaGetFunctionDto} from '../tosca-get-function-dto';
28 import {PropertySource} from '../property-source';
30 export enum DerivedPropertyType {
36 export class PropertyPolicyDetail {
39 constructor(propertyPolicy?: PropertyPolicyDetail) {
41 this.policyId = propertyPolicy.policyId;
42 this.propertyName = propertyPolicy.propertyName;
47 export class PropertyBEModel {
54 getInputValues: PropertyInputDetail[];
55 getPolicyValues: PropertyPolicyDetail[];
58 parentUniqueId: string;
61 schema: SchemaPropertyGroupModel;
66 parentPropertyType: string;
67 subPropertyInputPath: string;
69 toscaPresentation: ToscaPresentationData;
72 toscaGetFunctionType: ToscaGetFunctionType;
73 toscaGetFunction: ToscaGetFunctionDto;
75 constructor(property?: PropertyBEModel) {
77 this.constraints = property.constraints;
78 this.defaultValue = property.defaultValue;
79 this.description = property.description;
80 this.fromDerived = property.fromDerived;
81 this.name = property.name;
82 this.origName = property.origName;
83 this.parentUniqueId = property.parentUniqueId;
84 this.password = property.password;
85 this.required = property.required;
86 this.schema = property.schema;
87 this.schemaType = property.schemaType;
88 this.type = property.type;
89 this.uniqueId = property.uniqueId;
90 this.value = property.value;
91 this.definition = property.definition;
92 this.getInputValues = property.getInputValues;
93 this.parentPropertyType = property.parentPropertyType;
94 this.subPropertyInputPath = property.subPropertyInputPath;
95 this.toscaPresentation = property.toscaPresentation;
96 this.getPolicyValues = property.getPolicyValues;
97 this.inputPath = property.inputPath;
98 this.metadata = property.metadata;
99 if (property.toscaGetFunction) {
100 this.toscaGetFunction = property.toscaGetFunction;
101 } else if (property.toscaGetFunctionType) {
102 this.toscaGetFunction = new ToscaGetFunctionDto();
103 this.toscaGetFunction.functionType = property.toscaGetFunctionType;
104 this.toscaGetFunction.propertySource = PropertySource.SELF;
108 if (!this.schema || !this.schema.property) {
109 this.schema = new SchemaPropertyGroupModel(new SchemaProperty());
110 } else { // forcing creating new object, so editing different one than the object in the table
111 this.schema = new SchemaPropertyGroupModel(new SchemaProperty(this.schema.property));
115 public toJSON = (): any => {
116 const temp = angular.copy(this);
117 temp.value = temp.value === '{}' || temp.value === '[]' ? undefined : temp.value;
118 temp.defaultValue = temp.defaultValue === '{}' || temp.defaultValue === '[]' ? undefined : temp.defaultValue;
122 public getDerivedPropertyType = (): DerivedPropertyType => {
123 if (PROPERTY_DATA.SIMPLE_TYPES.indexOf(this.type) > -1) {
124 return DerivedPropertyType.SIMPLE;
126 if (this.type === PROPERTY_TYPES.LIST) {
127 return DerivedPropertyType.LIST;
129 if (this.type === PROPERTY_TYPES.MAP) {
130 return DerivedPropertyType.MAP;
132 return DerivedPropertyType.COMPLEX;
136 * Parses default value to JSON.
138 public parseDefaultValueToJson(): any {
139 if (this.defaultValue == undefined) {
143 const propertyType: DerivedPropertyType = this.getDerivedPropertyType();
144 if (propertyType == DerivedPropertyType.SIMPLE) {
145 return this.parseDefaultSimpleValue();
149 return JSON.parse(this.defaultValue);
151 console.error(`Could not parse the property of type '${this.type}' default value to JSON '${this.defaultValue}'`, e);
157 private parseDefaultSimpleValue() {
159 case PROPERTY_TYPES.INTEGER:
161 return parseInt(this.defaultValue);
163 console.error(`Could not parse the property of type '${this.type}' default value to int '${this.defaultValue}'`, e);
166 case PROPERTY_TYPES.FLOAT:
168 return parseFloat(this.defaultValue);
170 console.error(`Could not parse the property of type '${this.type}' default value to float '${this.defaultValue}'`, e);
173 case PROPERTY_TYPES.BOOLEAN:
174 return this.defaultValue === 'true';
176 return this.defaultValue;
181 * Checks whether the property value is a tosca get function (e.g. get_input, get_property, get_attribute)
183 public isToscaGetFunction(): boolean {
184 return this.toscaGetFunction != null;