Fix bugs in attribute outputs page
[sdc.git] / catalog-ui / src / app / models / component-metadata.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 { CapabilitiesGroup, RequirementsGroup } from 'app/models';
22 import {ComponentState, ComponentType, ResourceType} from 'app/utils';
23 import { IMainCategory } from './category';
24 import { Metadata } from "app/models/metadata";
25 /**
26  * Created by obarda on 4/18/2017.
27  */
28 export interface IComponentMetadata {
29
30     abstract: string;
31     uniqueId: string;
32     uuid: string;
33     invariantUUID: string;
34     name: string;
35     version: string;
36     creationDate: number;
37     lastUpdateDate: number;
38     description: string;
39     lifecycleState: string;
40     tags: string[];
41     icon: string;
42     contactId: string;
43     allVersions: any;
44     creatorUserId: string;
45     creatorFullName: string;
46     lastUpdaterUserId: string;
47     lastUpdaterFullName: string;
48     componentType: string;
49     categories: IMainCategory[];
50     highestVersion: boolean;
51     normalizedName: string;
52     systemName: string;
53     isArchived: boolean;
54     vspArchived: boolean;
55     selectedCategory: string;
56     filterTerm: string;
57     categorySpecificMetadata: Metadata;
58
59     // Resource only
60     resourceType: string;
61     csarUUID: string;
62     csarVersion: string;
63     csarVersionId: string;
64     derivedList: string[];
65     vendorName: string;
66     vendorRelease: string;
67     derivedFrom: string[];
68     resourceVendorModelNumber: string;
69     csarPackageType: string;
70     packageId: string;
71     iconSprite: string;
72
73     // Service only
74     serviceFunction: string;
75     distributionStatus: string;
76     ecompGeneratedNaming: boolean;
77     namingPolicy: string;
78     serviceType: string;
79     serviceRole: string;
80     environmentContext: string;
81     instantiationType: string;
82
83     // backend lifecycleState
84     state: string;
85
86     capabilities: CapabilitiesGroup;
87     requirements: RequirementsGroup;
88
89     // Model
90     model: string;
91
92 }
93
94 export class ComponentMetadata implements IComponentMetadata {
95
96     public abstract: string;
97     public uniqueId: string;
98     public uuid: string;
99     public invariantUUID: string;
100     public name: string;
101     public version: string;
102     public creationDate: number;
103     public lastUpdateDate: number;
104     public description: string;
105     public lifecycleState: string;
106     public tags: string[];
107     public icon: string;
108     public contactId: string;
109     public allVersions: any;
110     public creatorUserId: string;
111     public creatorFullName: string;
112     public lastUpdaterUserId: string;
113     public lastUpdaterFullName: string;
114     public componentType: string;
115     public categories: IMainCategory[];
116     public highestVersion: boolean;
117     public normalizedName: string;
118     public systemName: string;
119     public isArchived: boolean;
120     public vspArchived: boolean;
121     public toscaResourceName: string;
122     public selectedCategory: string;
123     public filterTerm: string;
124     public categorySpecificMetadata: Metadata = new Metadata();
125
126     // Resource only
127     public resourceType: string;
128     public csarUUID: string;
129     public csarVersion: string;
130     public csarVersionId: string;
131     public derivedList: string[];
132     public vendorName: string;
133     public vendorRelease: string;
134     public derivedFrom: string[];
135     public resourceVendorModelNumber: string;
136     public csarPackageType: string;
137     public packageId: string;
138     public iconSprite: string;
139     public models: string[];
140
141     // Service only
142     public serviceFunction: string;
143     public distributionStatus: string;
144     public ecompGeneratedNaming: boolean;
145     public namingPolicy: string;
146     public serviceType: string;
147     public serviceRole: string;
148     public environmentContext: string;
149     public instantiationType: string;
150     public model: string;
151
152     // backend lifecycleState
153     public state: string;
154
155     // requirements
156     public capabilities;
157     public requirements;
158
159     deserialize(response): ComponentMetadata {
160         this.abstract = response.abstract;
161         this.uniqueId = response.uniqueId;
162         this.uuid = response.uuid;
163         this.invariantUUID = response.invariantUUID;
164         this.contactId = response.contactId;
165         this.categories = response.categories;
166         this.creatorUserId = response.creatorUserId;
167         this.creationDate = response.creationDate;
168         this.creatorFullName = response.creatorFullName;
169         this.description = response.description;
170         this.icon = response.icon;
171         this.lastUpdateDate = response.lastUpdateDate;
172         this.lastUpdaterUserId = response.lastUpdaterUserId;
173         this.lastUpdaterFullName = response.lastUpdaterFullName;
174         this.lifecycleState = response.lifecycleState;
175         this.name = response.name;
176         this.version = response.version;
177         this.tags = angular.copy(response.tags, this.tags);
178         this.allVersions = response.allVersions;
179         this.componentType = response.componentType;
180         this.distributionStatus = response.distributionStatus;
181         this.highestVersion = response.highestVersion;
182         this.vendorName = response.vendorName;
183         this.vendorRelease = response.vendorRelease;
184         this.derivedList = response.derivedList;
185         this.normalizedName = response.normalizedName;
186         this.systemName = response.systemName;
187         this.serviceFunction = response.serviceFunction;
188         this.resourceType = response.resourceType;
189         this.csarUUID = response.csarUUID;
190         this.csarVersion = response.csarVersion;
191         this.csarVersionId = response.csarVersionId;
192         this.state = response.state;
193         this.ecompGeneratedNaming = response.ecompGeneratedNaming;
194         this.namingPolicy = response.namingPolicy;
195         this.derivedFrom = response.derivedFrom;
196         this.resourceVendorModelNumber = response.resourceVendorModelNumber;
197         this.serviceType = response.serviceType;
198         this.serviceRole = response.serviceRole;
199         this.environmentContext = response.environmentContext;
200         this.isArchived = response.isArchived;
201         this.instantiationType = response.instantiationType;
202         this.vspArchived = response.vspArchived;
203         this.toscaResourceName = response.toscaResourceName;
204         this.capabilities = response.capabilities;
205         this.requirements = response.requirements;
206         this.categorySpecificMetadata = response.categorySpecificMetadata;
207         this.model = response.model;
208         return this;
209     }
210
211     public isService = (): boolean => {
212         return this.componentType === ComponentType.SERVICE;
213     }
214
215     public isVfc(): boolean {
216         return this.resourceType === ResourceType.VFC;
217     }
218
219     public getTypeUrl(): string {
220         return this.componentType === ComponentType.RESOURCE ? 'resources/' : 'services/';
221     }
222
223     public isComponentDataEditable(): boolean {
224         return this.lifecycleState !== ComponentState.NOT_CERTIFIED_CHECKOUT;
225     }
226 }