summaryrefslogtreecommitdiffstats
path: root/catalog-ui/src/app/ng2/services
diff options
context:
space:
mode:
Diffstat (limited to 'catalog-ui/src/app/ng2/services')
-rw-r--r--catalog-ui/src/app/ng2/services/artifact-config.service.spec.ts23
-rw-r--r--catalog-ui/src/app/ng2/services/artifact-config.service.ts50
2 files changed, 73 insertions, 0 deletions
diff --git a/catalog-ui/src/app/ng2/services/artifact-config.service.spec.ts b/catalog-ui/src/app/ng2/services/artifact-config.service.spec.ts
new file mode 100644
index 0000000000..bbbd387b4e
--- /dev/null
+++ b/catalog-ui/src/app/ng2/services/artifact-config.service.spec.ts
@@ -0,0 +1,23 @@
+import { TestBed, inject } from '@angular/core/testing';
+
+import { ArtifactConfigService } from './artifact-config.service';
+import {CacheService} from "./cache.service";
+
+describe('ArtifactConfigService', () => {
+ beforeEach(() => {
+ const cacheServiceMock = {
+ get: jest.fn(() => {
+ return {
+ artifact: null
+ }
+ })
+ };
+ TestBed.configureTestingModule({
+ providers: [ArtifactConfigService, {provide: CacheService, useValue: cacheServiceMock}]
+ });
+ });
+
+ it('should be created', inject([ArtifactConfigService], (service: ArtifactConfigService) => {
+ expect(service).toBeTruthy();
+ }));
+});
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 [];
+ }
+
+}