2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. 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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 import { Injectable, Inject } from "@angular/core";
22 import { Observable } from "rxjs/Observable";
23 import { SdcConfigToken, ISdcConfig } from "../config/sdc-config.config";
24 import { Component, IApi, IComponentsArray } from "app/models";
25 import { ComponentFactory } from 'app/utils/component-factory';
26 import {ResourceType} from "../../utils/constants";
27 import {SharingService} from "./sharing.service";
28 import { HttpClient, HttpParams } from "@angular/common/http";
31 export class CatalogService {
33 protected baseUrl:string;
34 protected baseMicroServiceUrl:string;
36 constructor(private http: HttpClient,
37 @Inject(SdcConfigToken) sdcConfig:ISdcConfig,
38 private componentFactory:ComponentFactory,
39 private sharingService:SharingService) {
40 this.api = sdcConfig.api;
41 this.baseUrl = sdcConfig.api.root ;
42 this.baseMicroServiceUrl = sdcConfig.api.uicache_root;
45 public getCatalog(): Observable<Array<Component>> {
46 let searchParams = new HttpParams();
47 searchParams = searchParams.append('excludeTypes', ResourceType.VFCMT).append('excludeTypes', ResourceType.CONFIGURATION);
48 return this.http.get<IComponentsArray>(this.baseMicroServiceUrl + this.api.GET_uicache_catalog, {params: searchParams})
49 .map(res => this.processComponentsResponse(res, true));
52 public getArchiveCatalog() {
53 return this.http.get<IComponentsArray>(this.baseUrl + '/v1/catalog/archive/', {})
54 .map(res => this.processComponentsResponse(res));
57 private processComponentsResponse(componentsArr: IComponentsArray, addSharing:boolean = false) {
58 const componentsList: Component[] = [];
59 if (componentsArr.resources) {
60 componentsList.push(...this.getResourceItems(componentsArr.resources));
62 if (componentsArr.services) {
63 componentsList.push(...this.getServiceItems(componentsArr.services));
66 componentsList.forEach((item) => this.sharingService.addUuidValue(item.uniqueId, item.uuid));
68 return componentsList;
71 private getResourceItems(resources){
72 let resourceItems = resources.map((resource)=>{
73 return this.componentFactory.createResource(resource)
78 private getServiceItems(services){
79 let serviceItems = services.map((service)=>{
80 return this.componentFactory.createService(service)