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=========================================================
20 import { HttpClient } from '@angular/common/http';
21 import { Inject, Injectable } from '@angular/core';
22 import { Component, IApi, Resource, Service } from 'app/models';
23 import { ComponentFactory } from 'app/utils/component-factory';
24 import { Observable } from 'rxjs';
25 import { ISdcConfig, SdcConfigToken } from '../config/sdc-config.config';
26 import { SharingService } from './sharing.service';
28 // tslint:disable-next-line:interface-name
29 interface IComponentsArray {
31 resources: Resource[];
35 export class HomeService {
37 private smallObjectAttributes = [
38 'uniqueId', 'name', 'componentType', 'resourceType', 'lastUpdateDate', 'lifecycleState', 'distributionStatus',
42 constructor(private http: HttpClient,
43 @Inject(SdcConfigToken) private sdcConfig: ISdcConfig,
44 private sharingService: SharingService,
45 private componentFactory: ComponentFactory) {
46 this.api = sdcConfig.api;
49 public getAllComponents(smallObjects?: boolean): Observable<Component[]> {
50 return this.http.get<IComponentsArray>(this.api.root + this.api.GET_element)
52 const componentResponse: IComponentsArray = response;
53 let componentsList: Component[] = [];
55 componentResponse.services && componentResponse.services.forEach((serviceResponse: Service) => {
56 serviceResponse = (smallObjects) ? _.pick(serviceResponse, this.smallObjectAttributes) : serviceResponse;
57 const component: Service = this.componentFactory.createService(serviceResponse);
58 componentsList.push(component);
59 this.sharingService.addUuidValue(component.uniqueId, component.uuid);
62 componentResponse.resources && componentResponse.resources.forEach((resourceResponse: Resource) => {
63 resourceResponse = (smallObjects) ? _.pick(resourceResponse, this.smallObjectAttributes) : resourceResponse;
64 const component: Resource = this.componentFactory.createResource(resourceResponse);
65 componentsList.push(component);
66 this.sharingService.addUuidValue(component.uniqueId, component.uuid);
69 componentsList = _.orderBy(componentsList, ['lastUpdateDate'], ['desc']);
71 return componentsList;