summaryrefslogtreecommitdiffstats
path: root/catalog-ui/src/app/ng2/services/artifact-config.service.ts
diff options
context:
space:
mode:
Diffstat (limited to 'catalog-ui/src/app/ng2/services/artifact-config.service.ts')
-rw-r--r--catalog-ui/src/app/ng2/services/artifact-config.service.ts50
1 files changed, 50 insertions, 0 deletions
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<object>;
+
+ 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<object> {
+ 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<string> {
+ const artifactConfigList = this.findAllBy(artifactType, componentType, resourceType);
+ if (artifactConfigList) {
+ return artifactConfigList.map((element: any) => {
+ return element.type;
+ });
+ }
+
+ return [];
+ }
+
+}