aboutsummaryrefslogtreecommitdiffstats
path: root/catalog-ui/src/app/ng2/services/artifact-config.service.ts
blob: e3f914fa291eb0d2cbca6fa659a4d4d7b98841c0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
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 [];
  }

}