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=========================================================
22 * Created by rcohen on 9/25/2016.
25 import {PropertyBEModel} from "./properties-inputs/property-be-model";
26 import {AttributeBEModel} from "./attributes-outputs/attribute-be-model";
27 import {Model} from "./model";
28 import {PROPERTY_DATA} from "../utils/constants";
30 export class DataTypeModel {
34 derivedFromName: string;
35 derivedFrom: DataTypeModel;
38 modificationTime: string;
39 properties: Array<PropertyBEModel>;
40 attributes: Array<AttributeBEModel>;
43 constructor(dataType?: DataTypeModel) {
48 this.uniqueId = dataType.uniqueId;
49 this.name = dataType.name;
50 this.description = dataType.description;
51 this.derivedFromName = dataType.derivedFromName;
52 if (dataType.derivedFrom) {
53 this.derivedFrom = new DataTypeModel(dataType.derivedFrom);
55 this.creationTime = dataType.creationTime;
56 this.modificationTime = dataType.modificationTime;
57 if (dataType.properties) {
59 dataType.properties.forEach(property => {
60 this.properties.push(new PropertyBEModel(property));
63 this.attributes = dataType.attributes;
64 this.model = dataType.model;
67 public toJSON = ():any => {
73 * Parses the default value to JSON.
75 public parseDefaultValueToJson(): any {
76 if (PROPERTY_DATA.TYPES.indexOf(this.name) > -1) {
79 const defaultValue = {};
80 if (this.properties) {
81 this.properties.forEach(property => {
82 const propertyDefaultValue = property.parseDefaultValueToJson();
83 if (propertyDefaultValue != undefined) {
84 defaultValue[property.name] = propertyDefaultValue;
89 return defaultValue === {} ? undefined : defaultValue;