CSIT Fix for SDC-2585
[sdc.git] / catalog-ui / src / app / ng2 / services / archive.service.ts
1 /*-
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
21 import { Injectable, Inject } from "@angular/core";
22 import { Observable } from "rxjs/Observable";
23 import { HttpService } from "./http.service";
24 import { SdcConfigToken, ISdcConfig } from "../config/sdc-config.config";
25 import { Component } from "../../models";
26 import { ComponentFactory } from 'app/utils/component-factory';
27
28
29 @Injectable()
30 export class ArchiveService {
31     protected baseUrl;
32
33     constructor(private http: HttpService, @Inject(SdcConfigToken) sdcConfig:ISdcConfig, private componentFactory:ComponentFactory/*, @Inject(ComponentFactory) componentFactory */) {
34         this.baseUrl = sdcConfig.api.root ;
35     }
36
37     public getArchiveCatalog() {
38         let archiveCatalogItems:Component[] = [];
39         let archiveCatalogResourceItems:Component[] = []; 
40         let archiveCatalogServiceItems:Component[] = [];
41
42         return this.http.get(this.baseUrl + '/v1/catalog/archive/', {}).map(res => {
43             let archiveCatalogObject = res.json();
44             if (archiveCatalogObject.resources) archiveCatalogResourceItems = this.getResourceItems(archiveCatalogObject.resources);
45             if (archiveCatalogObject.services) archiveCatalogServiceItems = this.getServiceItems(archiveCatalogObject.services);
46             archiveCatalogItems = [].concat(archiveCatalogResourceItems, archiveCatalogServiceItems);
47             
48             return archiveCatalogItems;
49         });
50     }
51
52     
53     private getResourceItems(resources){
54         let resourceItems = resources.map((resource)=>{
55             return this.componentFactory.createResource(resource)
56         })
57         return resourceItems;
58     }
59
60     private getServiceItems(services){
61         let serviceItems = services.map((service)=>{
62             return this.componentFactory.createService(service)
63         })
64         return serviceItems;
65     }
66
67 }