From cd6f933375c412c2f79a12e909821322d58a8499 Mon Sep 17 00:00:00 2001 From: "andre.schmid" Date: Wed, 29 Jan 2020 17:25:21 +0000 Subject: Configure a new Artifact Type Centralizes artifact configuration in one yaml entry. Allow the configuration of a new artifact type without the need of code changes. The configuration file now is used as a source of artifacts types instead the artifact type enum. The enum will be used as a source of base artifact types and also in hard coded business rules. Change-Id: Id0383d9fca9bce0519a4d52a4ecb3a68c8713f0f Issue-ID: SDC-2754 Signed-off-by: andre.schmid --- .../app/ng2/services/artifact-config.service.ts | 50 ++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 catalog-ui/src/app/ng2/services/artifact-config.service.ts (limited to 'catalog-ui/src/app/ng2/services/artifact-config.service.ts') diff --git a/catalog-ui/src/app/ng2/services/artifact-config.service.ts b/catalog-ui/src/app/ng2/services/artifact-config.service.ts new file mode 100644 index 0000000000..e3f914fa29 --- /dev/null +++ b/catalog-ui/src/app/ng2/services/artifact-config.service.ts @@ -0,0 +1,50 @@ +import {Injectable} from '@angular/core'; +import {CacheService} from './cache.service'; +import {ArtifactType} from "../../utils/constants"; + +@Injectable() +export class ArtifactConfigService { + + artifactConfigList:Array; + + constructor(private cacheService: CacheService) { + const uiConfiguration = cacheService.get('UIConfiguration'); + this.artifactConfigList = uiConfiguration.artifact; + } + + public getConfig() { + return this.artifactConfigList; + } + + public findAllBy(artifactType?:ArtifactType, componentType?:string, resourceType?:string):Array { + return this.artifactConfigList.filter((artifactConfig:any) => { + let hasCategory = true; + if (artifactType) { + hasCategory = artifactConfig.categories && artifactConfig.categories.some(value => value == artifactType); + } + let hasComponentType = true; + if (componentType) { + hasComponentType = artifactConfig.componentTypes && artifactConfig.componentTypes.some(value => value == componentType); + } + let hasResourceType = true; + //resourceTypes are not restrictive, if it was not configured all resources are accepted. + if (resourceType && artifactConfig.resourceTypes) { + hasResourceType = artifactConfig.resourceTypes.some(value => value == resourceType); + } + return hasCategory && hasComponentType && hasResourceType; + }); + } + + + public findAllTypeBy(artifactType?:ArtifactType, componentType?:string, resourceType?:string):Array { + const artifactConfigList = this.findAllBy(artifactType, componentType, resourceType); + if (artifactConfigList) { + return artifactConfigList.map((element: any) => { + return element.type; + }); + } + + return []; + } + +} -- cgit 1.2.3-korg