Support for Nested/Hierarchical Services
[sdc.git] / catalog-ui / src / app / models / components / displayComponent.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  * Created by obarda on 7/5/2016.
22  */
23
24 'use strict';
25 import { ComponentType, SdcElementType } from '../../utils/constants';
26 import { ComponentMetadata } from '../component-metadata';
27 import { PolicyMetadata } from '../policy-metadata';
28 import { GroupMetadata } from '../group-metadata';
29 import { RequirementsGroup } from '../requirement';
30 import { CapabilitiesGroup } from '../capability';
31 import { IMainCategory } from '../category';
32
33 export enum LeftPaletteMetadataTypes {
34     Component = 'COMPONENT',
35     Group = 'GROUP',
36     Policy = 'POLICY'
37 }
38
39 export class LeftPaletteComponent {
40
41     uniqueId: string;
42     type: string;
43     version: string;
44     mainCategory: string;
45     subCategory: string;
46     componentSubType: string;
47     searchFilterTerms: string;
48     certifiedIconClass: string;
49     isDraggable: boolean;
50     uuid: string;
51     name: string;
52     lifecycleState: string;
53     allVersions: any;
54     componentType: string;
55     systemName: string;
56     invariantUUID: string;
57     capabilities: CapabilitiesGroup;
58     requirements: RequirementsGroup;
59     categoryType: LeftPaletteMetadataTypes;
60     resourceType: string;
61     icon: string;
62
63     constructor(metadataType: LeftPaletteMetadataTypes, item: ComponentMetadata | PolicyMetadata | GroupMetadata) {
64         if (metadataType === LeftPaletteMetadataTypes.Policy) {
65             this.initPolicy(item as PolicyMetadata);
66             return;
67         }
68
69         if (metadataType === LeftPaletteMetadataTypes.Group) {
70             this.initGroup(item as GroupMetadata);
71             return;
72         }
73
74         if (metadataType === LeftPaletteMetadataTypes.Component) {
75             this.initComponent(item as ComponentMetadata);
76             return;
77         }
78     }
79
80     private initComponent(component: ComponentMetadata): void {
81         this.version = component.version;
82         this.uniqueId = component.uniqueId;
83         this.uuid = component.uuid;
84         this.name = component.name;
85         this.allVersions = component.allVersions;
86         this.componentType = component.componentType;
87         this.systemName = component.systemName;
88         this.invariantUUID = component.invariantUUID;
89         this.isDraggable = true;
90         if (component.categories && component.categories[0] && component.categories[0].subcategories && component.categories[0].subcategories[0]) {
91             this.mainCategory = component.categories[0].name;
92             this.subCategory = component.categories[0].subcategories[0].name;
93         } else {
94             this.mainCategory = 'Generic';
95             this.subCategory = 'Generic';
96         }
97         // this.categoryType = LeftPaletteMetadataTypes.Component;
98         // this.componentSubType = component. ? component.resourceType: ComponentType.SERVICE_PROXY;
99         this.searchFilterTerms = (this.name + ' ' + component.description + ' ' + component.tags.join(' ')).toLowerCase() + ' ' + component.version;
100         this.icon = component.icon;
101         this.certifiedIconClass = component.lifecycleState != 'CERTIFIED' ? 'non-certified' : ''; // need to fix after onap fix
102
103     }
104
105     private initGroup(group: GroupMetadata): void {
106         this.categoryType = LeftPaletteMetadataTypes.Group;
107         this.uniqueId = group.uniqueId;
108         this.name = group.name;
109         this.mainCategory = 'Groups';
110         this.subCategory = 'Groups';
111         this.version = group.version;
112         this.type = group.type;
113         this.componentSubType = SdcElementType.GROUP;
114         this.icon = SdcElementType.GROUP;
115         this.searchFilterTerms = this.type + ' ' + group.name + ' ' + group.version;
116         this.isDraggable = false;
117     }
118
119     private initPolicy(policy: PolicyMetadata): void {
120         this.categoryType = LeftPaletteMetadataTypes.Policy;
121         this.uniqueId = policy.uniqueId;
122         this.name = policy.name;
123         this.mainCategory = 'Policies';
124         this.subCategory = 'Policies';
125         this.version = policy.version;
126         this.type = policy.type;
127         this.componentSubType = SdcElementType.POLICY;
128         this.icon = SdcElementType.POLICY;
129         this.searchFilterTerms = this.type + ' ' + policy.name + ' ' + policy.version;
130         this.isDraggable = false;
131     }
132
133     public getComponentSubType = (): string => {
134         return this.componentSubType;
135     };
136 }