blob: 27b0513b391194bb8e1dedc0df1f857b306fda77 [file] [log] [blame]
Michael Landodd603392017-07-12 00:54:52 +03001/*-
2 * ============LICENSE_START=======================================================
3 * SDC
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
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
Michael Landoed64b5e2017-06-09 03:19:04 +030021'use strict';
Michael Lando75aacbb2017-07-17 21:12:03 +030022import { Service, IApi, IAppConfigurtaion, Resource, Component} from "../models";
Michael Landoed64b5e2017-06-09 03:19:04 +030023import {SharingService} from "./sharing-service";
24import {ComponentFactory} from "../utils/component-factory";
25import {CacheService} from "./cache-service";
Tal Gitelman51d50f02017-12-10 18:55:03 +020026import {ResourceType} from "app/utils";
Michael Landoed64b5e2017-06-09 03:19:04 +030027
28interface IEntityService {
29 getAllComponents():ng.IPromise<Array<Component>>;
30}
31
32interface IComponentsArray {
33 services:Array<Service>;
34 resources:Array<Resource>;
Michael Landoed64b5e2017-06-09 03:19:04 +030035}
36
37export class EntityService implements IEntityService {
38 static '$inject' = ['$http', '$q', 'sdcConfig', 'Sdc.Services.SharingService', 'ComponentFactory', 'Sdc.Services.CacheService'];
39 private api:IApi;
40
41 constructor(private $http:ng.IHttpService,
42 private $q:ng.IQService,
43 private sdcConfig:IAppConfigurtaion,
44 private sharingService:SharingService,
45 private ComponentFactory:ComponentFactory,
46 private cacheService:CacheService) {
47 this.api = sdcConfig.api;
48 }
49
50 getCatalog = ():ng.IPromise<Array<Component>> => {
51 let defer = this.$q.defer<Array<Component>>();
Tal Gitelman51d50f02017-12-10 18:55:03 +020052 this.$http.get(this.api.root + this.api.GET_catalog, {params: {excludeTypes: [ResourceType.VFCMT, ResourceType.CONFIGURATION]}})
Michael Landoed64b5e2017-06-09 03:19:04 +030053 .then((response:any) => {
54 let followedResponse: IComponentsArray = response.data;
55 let componentsList:Array<Component> = new Array();
56
57 followedResponse.services.forEach((serviceResponse:Service) => {
58 let component:Service = this.ComponentFactory.createService(serviceResponse); // new Service(serviceResponse);
59 componentsList.push(component);
60 this.sharingService.addUuidValue(component.uniqueId, component.uuid);
61 });
62
63 followedResponse.resources.forEach((resourceResponse:Resource) => {
64 let component:Resource = this.ComponentFactory.createResource(resourceResponse);
65 componentsList.push(component);
66 this.sharingService.addUuidValue(component.uniqueId, component.uuid);
67 });
68
Michael Landoed64b5e2017-06-09 03:19:04 +030069 this.cacheService.set('breadcrumbsComponents', componentsList);
70 defer.resolve(componentsList);
71 },(responce) => {
72 defer.reject(responce);
73 });
74 return defer.promise;
75 };
76
77 getAllComponents = ():ng.IPromise<Array<Component>> => {
78 let defer = this.$q.defer<Array<Component>>();
79 this.$http.get(this.api.root + this.api.GET_element)
80 .then((response:any) => {
81 let componentResponse:IComponentsArray = response.data;
82 let componentsList:Array<Component> = [];
83
84 componentResponse.services && componentResponse.services.forEach((serviceResponse:Service) => {
85 let component:Service = this.ComponentFactory.createService(serviceResponse);
86 componentsList.push(component);
87 this.sharingService.addUuidValue(component.uniqueId, component.uuid);
88 });
89
90 componentResponse.resources && componentResponse.resources.forEach((resourceResponse:Resource) => {
91 let component:Resource = this.ComponentFactory.createResource(resourceResponse);
92 componentsList.push(component);
93 this.sharingService.addUuidValue(component.uniqueId, component.uuid);
94 });
Michael Lando75aacbb2017-07-17 21:12:03 +030095
Michael Landoed64b5e2017-06-09 03:19:04 +030096 this.cacheService.set('breadcrumbsComponents', componentsList);
97 defer.resolve(componentsList);
98 });
99
100 return defer.promise;
101 };
102}