Catalog alignment
[sdc.git] / catalog-ui / src / app / ng2 / services / gab.service.ts
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
4  * ================================================================================
5  * Copyright (C) 2019 Nokia. 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
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
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=========================================================
19  */
20
21 import { HttpClient } from '@angular/common/http';
22 import { Inject, Injectable } from '@angular/core';
23 import { Response } from '@angular/http';
24 import { Observable } from 'rxjs';
25 import { ISdcConfig, SdcConfigToken } from '../config/sdc-config.config';
26
27 // tslint:disable-next-line:interface-name
28 export interface IServerResponse {
29   data: [{ [key: string]: string }];
30 }
31
32 export class GabRequest {
33   constructor(public fields: string[],
34               public parentId: string,
35               public artifactUniqueId: string) {
36
37   }
38 }
39
40 // tslint:disable-next-line:max-classes-per-file
41 @Injectable()
42 export class GabService {
43   baseUrl: string;
44   gabUrl: string;
45
46   constructor(@Inject(SdcConfigToken) sdcConfig: ISdcConfig, protected http: HttpClient) {
47     this.baseUrl = sdcConfig.api.root;
48     this.gabUrl = sdcConfig.api.POST_GAB_Search;
49   }
50
51   public getArtifact(artifactUniqueId: string, resourceId: string, columns: string[]): Observable<Response> {
52     const finalUrl: string = this.baseUrl + this.gabUrl;
53     const request: GabRequest = {
54       fields: columns,
55       parentId: resourceId,
56       artifactUniqueId
57     };
58
59     return this.http.post<Response>(finalUrl, request);
60   }
61 }