Catalog alignment
[sdc.git] / catalog-ui / src / app / models / properties-inputs / property-be-model.ts
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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=========================================================
19  */
20
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';
25
26 export enum DerivedPropertyType {
27     SIMPLE,
28     LIST,
29     MAP,
30     COMPLEX
31 }
32 export class PropertyPolicyDetail {
33     policyId: string;
34     propertyName: string;
35     constructor(propertyPolicy?: PropertyPolicyDetail) {
36         if(propertyPolicy) {
37             this.policyId = propertyPolicy.policyId;
38             this.propertyName = propertyPolicy.propertyName;
39         }
40     }
41 }
42
43 export class PropertyBEModel {
44
45     constraints: any[];
46     defaultValue: string;
47     definition: boolean;
48     description: string;
49     fromDerived: boolean;
50     getInputValues: PropertyInputDetail[];
51     getPolicyValues: PropertyPolicyDetail[];
52     name: string;
53     origName: string;
54     parentUniqueId: string;
55     password: boolean;
56     required: boolean;
57     schema: SchemaPropertyGroupModel;
58     schemaType: string;
59     type: string;
60     uniqueId: string;
61     value: string;
62     parentPropertyType: string;
63     subPropertyInputPath: string;
64     inputPath: string;
65     toscaPresentation: ToscaPresentationData;
66
67     constructor(property?: PropertyBEModel) {
68         if (property) {
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;
90         }
91
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));
96         }
97     }
98
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;
103         return temp;
104     }
105
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;
113         } else {
114             return DerivedPropertyType.COMPLEX;
115         }
116     }
117 }
118