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=========================================================
21 * Created by obarda on 7/5/2016.
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';
33 export enum LeftPaletteMetadataTypes {
34 Component = 'COMPONENT',
39 export class LeftPaletteComponent {
46 componentSubType: string;
47 searchFilterTerms: string;
48 certifiedIconClass: string;
52 lifecycleState: string;
54 componentType: string;
56 invariantUUID: string;
57 capabilities: CapabilitiesGroup;
58 requirements: RequirementsGroup;
59 categoryType: LeftPaletteMetadataTypes;
63 constructor(metadataType: LeftPaletteMetadataTypes, item: ComponentMetadata | PolicyMetadata | GroupMetadata) {
64 if (metadataType === LeftPaletteMetadataTypes.Policy) {
65 this.initPolicy(item as PolicyMetadata);
69 if (metadataType === LeftPaletteMetadataTypes.Group) {
70 this.initGroup(item as GroupMetadata);
74 if (metadataType === LeftPaletteMetadataTypes.Component) {
75 this.initComponent(item as ComponentMetadata);
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;
94 this.mainCategory = 'Generic';
95 this.subCategory = 'Generic';
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
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;
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;
133 public getComponentSubType = (): string => {
134 return this.componentSubType;