2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2021 Nordix Foundation. 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 {ToscaPresentationData} from '../tosca-presentation';
23 import {AttributeOutputDetail} from "app/models/attributes-outputs/attribute-output-detail";
24 import {SchemaAttribute, SchemaAttributeGroupModel} from "../schema-attribute";
26 export enum DerivedAttributeType {
33 export class AttributeBEModel {
39 getOutputValues: AttributeOutputDetail[];
42 parentUniqueId: string;
45 schema: SchemaAttributeGroupModel;
50 parentAttributeType: string;
51 subAttributeOutputPath: string;
53 toscaPresentation: ToscaPresentationData;
55 constructor(attribute?: AttributeBEModel) {
57 this.constraints = attribute.constraints;
58 this.defaultValue = attribute.defaultValue;
59 this.description = attribute.description;
60 this.fromDerived = attribute.fromDerived;
61 this.name = attribute.name;
62 this.origName = attribute.origName;
63 this.parentUniqueId = attribute.parentUniqueId;
64 this.password = attribute.password;
65 this.required = attribute.required;
66 this.schema = attribute.schema;
68 if (attribute.schemaType) {
69 this.schemaType = attribute.schemaType;
72 this.type = attribute.type;
73 this.uniqueId = attribute.uniqueId;
74 this.value = attribute.value;
75 this.getOutputValues = attribute.getOutputValues;
76 this.parentAttributeType = attribute.parentAttributeType;
77 this.subAttributeOutputPath = attribute.subAttributeOutputPath;
78 this.toscaPresentation = attribute.toscaPresentation;
79 this.outputPath = attribute.outputPath;
82 if (!this.schema || !this.schema.property) {
83 this.schema = new SchemaAttributeGroupModel(new SchemaAttribute());
84 } else { // forcing creating new object, so editing different one than the object in the table
85 this.schema = new SchemaAttributeGroupModel(new SchemaAttribute(this.schema.property));
89 public toJSON = (): any => {
90 const temp = angular.copy(this);
91 temp.value = temp.value === '{}' || temp.value === '[]' ? undefined : temp.value;
92 temp.defaultValue = temp.defaultValue === '{}' || temp.defaultValue === '[]' ? undefined : temp.defaultValue;
96 public getDerivedAttributeType = () => {
97 if (PROPERTY_DATA.SIMPLE_TYPES.indexOf(this.type) > -1) {
98 return DerivedAttributeType.SIMPLE;
99 } else if (this.type === PROPERTY_TYPES.LIST) {
100 return DerivedAttributeType.LIST;
101 } else if (this.type === PROPERTY_TYPES.MAP) {
102 return DerivedAttributeType.MAP;
104 return DerivedAttributeType.COMPLEX;