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 '../aschema-property';
23 import { ToscaPresentationData } from '../tosca-presentation';
24 import { PropertyInputDetail } from './property-input-detail';
26 export enum DerivedPropertyType {
32 export class PropertyPolicyDetail {
35 constructor(propertyPolicy?: PropertyPolicyDetail) {
37 this.policyId = propertyPolicy.policyId;
38 this.propertyName = propertyPolicy.propertyName;
43 export class PropertyBEModel {
50 getInputValues: PropertyInputDetail[];
51 getPolicyValues: PropertyPolicyDetail[];
54 parentUniqueId: string;
57 schema: SchemaPropertyGroupModel;
62 parentPropertyType: string;
63 subPropertyInputPath: string;
65 toscaPresentation: ToscaPresentationData;
67 constructor(property?: PropertyBEModel) {
69 this.constraints = property.constraints;
70 this.defaultValue = property.defaultValue;
71 this.description = property.description;
72 this.fromDerived = property.fromDerived;
73 this.name = property.name;
74 this.origName = property.origName;
75 this.parentUniqueId = property.parentUniqueId;
76 this.password = property.password;
77 this.required = property.required;
78 this.schema = property.schema;
79 this.schemaType = property.schemaType;
80 this.type = property.type;
81 this.uniqueId = property.uniqueId;
82 this.value = property.value;
83 this.definition = property.definition;
84 this.getInputValues = property.getInputValues;
85 this.parentPropertyType = property.parentPropertyType;
86 this.subPropertyInputPath = property.subPropertyInputPath;
87 this.toscaPresentation = property.toscaPresentation;
88 this.getPolicyValues = property.getPolicyValues;
89 this.inputPath = property.inputPath;
92 if (!this.schema || !this.schema.property) {
93 this.schema = new SchemaPropertyGroupModel(new SchemaProperty());
94 } else { // forcing creating new object, so editing different one than the object in the table
95 this.schema = new SchemaPropertyGroupModel(new SchemaProperty(this.schema.property));
99 public toJSON = (): any => {
100 const temp = angular.copy(this);
101 temp.value = temp.value === '{}' || temp.value === '[]' ? undefined : temp.value;
102 temp.defaultValue = temp.defaultValue === '{}' || temp.defaultValue === '[]' ? undefined : temp.defaultValue;
106 public getDerivedPropertyType = () => {
107 if (PROPERTY_DATA.SIMPLE_TYPES.indexOf(this.type) > -1) {
108 return DerivedPropertyType.SIMPLE;
109 } else if (this.type === PROPERTY_TYPES.LIST) {
110 return DerivedPropertyType.LIST;
111 } else if (this.type === PROPERTY_TYPES.MAP) {
112 return DerivedPropertyType.MAP;
114 return DerivedPropertyType.COMPLEX;