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.enum";
28 export enum DerivedPropertyType {
34 export class PropertyPolicyDetail {
37 constructor(propertyPolicy?: PropertyPolicyDetail) {
39 this.policyId = propertyPolicy.policyId;
40 this.propertyName = propertyPolicy.propertyName;
45 export class PropertyBEModel {
52 getInputValues: PropertyInputDetail[];
53 getPolicyValues: PropertyPolicyDetail[];
56 parentUniqueId: string;
59 schema: SchemaPropertyGroupModel;
64 parentPropertyType: string;
65 subPropertyInputPath: string;
67 toscaPresentation: ToscaPresentationData;
69 toscaGetFunctionType: ToscaGetFunctionType;
71 constructor(property?: PropertyBEModel) {
73 this.constraints = property.constraints;
74 this.defaultValue = property.defaultValue;
75 this.description = property.description;
76 this.fromDerived = property.fromDerived;
77 this.name = property.name;
78 this.origName = property.origName;
79 this.parentUniqueId = property.parentUniqueId;
80 this.password = property.password;
81 this.required = property.required;
82 this.schema = property.schema;
83 this.schemaType = property.schemaType;
84 this.type = property.type;
85 this.uniqueId = property.uniqueId;
86 this.value = property.value;
87 this.definition = property.definition;
88 this.getInputValues = property.getInputValues;
89 this.parentPropertyType = property.parentPropertyType;
90 this.subPropertyInputPath = property.subPropertyInputPath;
91 this.toscaPresentation = property.toscaPresentation;
92 this.getPolicyValues = property.getPolicyValues;
93 this.inputPath = property.inputPath;
94 this.metadata = property.metadata;
95 this.toscaGetFunctionType = property.toscaGetFunctionType;
98 if (!this.schema || !this.schema.property) {
99 this.schema = new SchemaPropertyGroupModel(new SchemaProperty());
100 } else { // forcing creating new object, so editing different one than the object in the table
101 this.schema = new SchemaPropertyGroupModel(new SchemaProperty(this.schema.property));
105 public toJSON = (): any => {
106 const temp = angular.copy(this);
107 temp.value = temp.value === '{}' || temp.value === '[]' ? undefined : temp.value;
108 temp.defaultValue = temp.defaultValue === '{}' || temp.defaultValue === '[]' ? undefined : temp.defaultValue;
112 public getDerivedPropertyType = () => {
113 if (PROPERTY_DATA.SIMPLE_TYPES.indexOf(this.type) > -1) {
114 return DerivedPropertyType.SIMPLE;
115 } else if (this.type === PROPERTY_TYPES.LIST) {
116 return DerivedPropertyType.LIST;
117 } else if (this.type === PROPERTY_TYPES.MAP) {
118 return DerivedPropertyType.MAP;
120 return DerivedPropertyType.COMPLEX;
125 * Checks whether the property value is a tosca get function (e.g. get_input, get_property, get_attribute)
127 public isToscaGetFunction(): boolean {
128 return this.toscaGetFunctionType != null;