301b3a4c9be14a7aeea2da25a2da244b6d17cde8
[sdc.git] / catalog-ui / src / app / ng2 / services / responses / component-generic-response.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 /**
22  * Created by ob0695 on 4/18/2017.
23  */
24
25 import { ArtifactGroupModel, PropertyModel, PropertiesGroup, AttributeModel, AttributesGroup, ComponentInstance, OperationModel,
26     InputBEModel, Module, ComponentMetadata, RelationshipModel, RequirementsGroup, CapabilitiesGroup} from "app/models";
27 import {CommonUtils} from "app/utils";
28 import {Serializable} from "../utils/serializable";
29 import {PropertyBEModel} from "../../../models/properties-inputs/property-be-model";
30 import { PolicyInstance } from "app/models/graph/zones/policy-instance";
31 import { GroupInstance } from "../../../models/graph/zones/group-instance";
32 import { InputsGroup } from "../../../models/inputs";
33 import { InterfaceModel } from "../../../models/operation";
34
35 export class ComponentGenericResponse  implements Serializable<ComponentGenericResponse> {
36
37     public metadata: ComponentMetadata;
38     public deploymentArtifacts:ArtifactGroupModel;
39     public artifacts:ArtifactGroupModel;
40     public toscaArtifacts:ArtifactGroupModel;
41     public componentInstancesProperties:PropertiesGroup;
42     public componentInstancesInputs:InputsGroup;
43     public componentInstancesAttributes:AttributesGroup;
44     public componentInstancesRelations:Array<RelationshipModel>;
45     public componentInstances:Array<ComponentInstance>;
46     public componentInstancesInterfaces: Map<string, Array<InterfaceModel>>;
47     public inputs:Array<InputBEModel>;
48     public capabilities:CapabilitiesGroup;
49     public requirements:RequirementsGroup;
50     public properties:Array<PropertyModel>;
51     public attributes:Array<AttributeModel>;
52     public policies:Array<PolicyInstance>;
53     public groupInstances: Array<GroupInstance>;
54     public modules:Array<Module>;
55     public interfaces:any;
56     public interfaceOperations:Array<OperationModel>;
57     public additionalInformation:any;
58     public derivedList:Array<any>;
59     public nodeFilterData: Array<any>;
60
61     deserialize (response): ComponentGenericResponse {
62
63         if(response.componentInstancesProperties) {
64             this.componentInstancesProperties = new PropertiesGroup(response.componentInstancesProperties);
65         }
66         if(response.componentInstancesInputs) {
67             this.componentInstancesInputs = response.componentInstancesInputs;
68         }
69         if(response.componentInstancesAttributes) {
70             this.componentInstancesAttributes = new AttributesGroup(response.componentInstancesAttributes);
71         }
72         if(response.componentInstances) {
73             this.componentInstances = CommonUtils.initComponentInstances(response.componentInstances);
74         }
75         if(response.componentInstancesRelations) {
76             this.componentInstancesRelations = CommonUtils.initComponentInstanceRelations(response.componentInstancesRelations);
77         }
78         if(response.deploymentArtifacts) {
79             this.deploymentArtifacts = new ArtifactGroupModel(response.deploymentArtifacts);
80         }
81         if(response.inputs) {
82             this.inputs = CommonUtils.initInputs(response.inputs);
83         }
84         if(response.attributes) {
85             this.attributes = CommonUtils.initAttributes(response.attributes);
86         }
87         if(response.artifacts) {
88             this.artifacts = new ArtifactGroupModel(response.artifacts);
89         }
90         if(response.properties) {
91             this.properties = CommonUtils.initProperties(response.properties);
92         }
93         if(response.capabilities) {
94             this.capabilities = new CapabilitiesGroup(response.capabilities);
95         }
96         if(response.requirements) {
97             this.requirements = new RequirementsGroup(response.requirements);
98         }
99         if(response.toscaArtifacts) {
100             this.toscaArtifacts = new ArtifactGroupModel(response.toscaArtifacts);
101         }
102         if(response.interfaces) {
103             this.interfaces = CommonUtils.initInterfaces(response.interfaces);
104             this.interfaceOperations = CommonUtils.initInterfaceOperations(response.interfaces);
105         }
106         if (response.componentInstancesInterfaces) {
107             this.componentInstancesInterfaces = new Map();
108             for (let resourceId in response.componentInstancesInterfaces) {
109                 this.componentInstancesInterfaces[resourceId] = CommonUtils.initInterfaces(response.componentInstancesInterfaces[resourceId]);
110             }
111         }
112         if(response.metadata) {
113             this.metadata = new ComponentMetadata().deserialize(response.metadata);
114         }
115         if(response.groups) {
116             this.modules = CommonUtils.initModules(response.groups);
117             this.groupInstances = CommonUtils.initGroups(response.groups)
118         }
119         if(response.policies) {
120             this.policies = CommonUtils.initPolicies(response.policies);
121         }
122         if(response.nodeFilterData) {
123             this.nodeFilterData = response.nodeFilterData;
124         }
125         return this;
126     }
127 }