1 import {Injectable} from '@angular/core';
2 import {HttpClient, HttpHeaders} from '@angular/common/http';
3 import { Constants } from '../../shared/utils/constants';
4 import { ServiceType } from "../../shared/models/serviceType";
5 import {GetSubDetailsResponse} from "./responseInterfaces/getSubDetailsResponseInterface";
6 import {Observable} from "rxjs/Observable";
7 import * as _ from 'lodash';
8 import {CategoryParams} from "../../shared/models/categoryParams";
9 import {GetCategoryParamsResponseInterface} from "./responseInterfaces/getCategoryParamsResponseInterface";
10 import {Project} from "../../shared/models/project";
11 import {OwningEntity} from "../../shared/models/owningEntity";
12 import {GetServicesResponseInterface} from "./responseInterfaces/getServicesResponseInterface";
13 import {Subscriber} from "../../shared/models/subscriber";
14 import {GetSubscribersResponse} from "./responseInterfaces/getSubscribersResponseInterface";
15 import {AicZone} from "../../shared/models/aicZone";
16 import {GetAicZonesResponse} from "./responseInterfaces/getAicZonesResponseInterface";
17 import {LcpRegionsAndTenants} from "../../shared/models/lcpRegionsAndTenants";
18 import {LcpRegion} from "../../shared/models/lcpRegion";
19 import {Tenant} from "../../shared/models/tenant";
20 import {ProductFamily} from "../../shared/models/productFamily"
22 updateAicZones, updateCategoryParameters, updateLcpRegionsAndTenants, updateModel, updateProductFamilies,
23 updateServiceTypes, updateSubscribers, updateUserId
24 } from '../../service.actions';
25 import {SelectOption} from '../../shared/models/selectOption';
26 import {NgRedux} from "@angular-redux/store";
27 import {AppState} from "../../store/reducers";
28 import {ResponseContentType, ResponseType} from "@angular/http";
29 import 'rxjs/add/operator/do';
30 import 'rxjs/add/observable/of';
31 import 'rxjs/add/operator/catch';
34 export class AaiService {
36 constructor (private http: HttpClient, private store: NgRedux<AppState>) {}
38 public getServiceModelById(serviceModelId: string): Observable<any> {
39 if (_.has(this.store.getState().service.serviceHierarchy,serviceModelId)){
40 return Observable.of(<any> JSON.parse(JSON.stringify(this.store.getState().service.serviceHierarchy[serviceModelId])));
42 let pathQuery: string = Constants.Path.SERVICES_PATH + serviceModelId;
43 return this.http.get(pathQuery).map(res => res )
45 this.store.dispatch(updateModel(res));
49 public getUserId() : Observable<any>{
50 return this.http.get("../../getuserID",{responseType: 'text'}).do((res)=>this.store.dispatch(updateUserId(res)));
54 public getCRAccordingToNetworkFunctionId(networkCollectionFunction,cloudOwner,cloudRegionId){
55 return this.http.get('../../aai_get_instance_groups_by_cloudregion/'+cloudOwner+'/'+cloudRegionId+'/' + networkCollectionFunction)
56 .map(res=>res).do((res)=>console.log(res));
59 public getCategoryParameters(familyName): Observable<CategoryParams> {
60 familyName = familyName || Constants.Path.PARAMETER_STANDARDIZATION_FAMILY;
61 let pathQuery: string = Constants.Path.GET_CATEGORY_PARAMETERS +"?familyName=" + familyName+ "&r=" + Math.random();
63 return this.http.get<GetCategoryParamsResponseInterface>(pathQuery)
64 .map(this.categoryParametersResponseToProductAndOwningEntity)
66 this.store.dispatch(updateCategoryParameters(res))
72 categoryParametersResponseToProductAndOwningEntity(res: GetCategoryParamsResponseInterface): CategoryParams {
73 if (res && res.categoryParameters) {
74 const owningEntityList = res.categoryParameters.owningEntity.map(owningEntity => new OwningEntity(owningEntity));
75 const projectList = res.categoryParameters.project.map(project => new Project(project));
76 const lineOfBusinessList = res.categoryParameters.lineOfBusiness.map(owningEntity => new SelectOption(owningEntity));
77 const platformList = res.categoryParameters.platform.map(platform => new SelectOption(platform));
79 return new CategoryParams(owningEntityList, projectList, lineOfBusinessList, platformList);
81 return new CategoryParams();
85 public getProductFamilies(): Observable<ProductFamily[]> {
86 return this.getServices().map(res => res.service.map(service => new ProductFamily(service)));
89 public getServices(): Observable<GetServicesResponseInterface> {
90 let pathQuery: string = Constants.Path.AAI_GET_SERVICES + Constants.Path.ASSIGN + Math.random();
92 return this.http.get<GetServicesResponseInterface>(pathQuery);
95 public getSubscribers(): Observable<Subscriber[]> {
96 if (this.store.getState().service.subscribers){
97 return Observable.of(<any> JSON.parse(JSON.stringify(this.store.getState().service.subscribers)));
100 let pathQuery: string = Constants.Path.AAI_GET_SUBSCRIBERS + Constants.Path.ASSIGN + Math.random();
102 return this.http.get<GetSubscribersResponse>(pathQuery).map(res =>
103 res.customer.map( subscriber => new Subscriber(subscriber))).do((res) => {
104 this.store.dispatch(updateSubscribers(res));
108 public getAicZones(): Observable<AicZone[]> {
109 if (this.store.getState().service.aicZones){
110 return Observable.of(<any> JSON.parse(JSON.stringify(this.store.getState().service.aicZones)));
113 let pathQuery: string = Constants.Path.AAI_GET_AIC_ZONES + Constants.Path.ASSIGN + Math.random();
115 return this.http.get<GetAicZonesResponse>(pathQuery).map(res =>
116 res.zone.map(aicZone => new AicZone(aicZone))).do((res) => {
117 this.store.dispatch(updateAicZones(res));
121 public getLcpRegionsAndTenants(globalCustomerId, serviceType): Observable<LcpRegionsAndTenants> {
122 if (this.store.getState().service.lcpRegionsAndTenants.lcpRegionList.length !== 0){
123 return Observable.of(<any> JSON.parse(JSON.stringify(this.store.getState().service.lcpRegionsAndTenants)));
125 let pathQuery: string = Constants.Path.AAI_GET_TENANTS
126 + globalCustomerId + Constants.Path.FORWARD_SLASH + serviceType + Constants.Path.ASSIGN + Math.random();
128 console.log("AaiService:getSubscriptionServiceTypeList: globalCustomerId: "
130 if (globalCustomerId != null) {
131 return this.http.get(pathQuery)
132 .map(this.tenantResponseToLcpRegionsAndTenants).do((res) => {
133 this.store.dispatch(updateLcpRegionsAndTenants(res));
138 tenantResponseToLcpRegionsAndTenants(cloudRegionTenantList): LcpRegionsAndTenants {
140 const lcpRegionsTenantsMap = {};
142 const lcpRegionList = _.uniqBy(cloudRegionTenantList, 'cloudRegionID').map((cloudRegionTenant) => {
143 return new LcpRegion(cloudRegionTenant)
146 lcpRegionList.forEach(region => {
147 lcpRegionsTenantsMap[region.id] = _.filter(cloudRegionTenantList, {'cloudRegionID' : region.id})
148 .map((cloudRegionTenant) => {
149 return new Tenant(cloudRegionTenant)
151 const reducer = (accumulator, currentValue) => {
152 accumulator.isPermitted = accumulator.isPermitted || currentValue.isPermitted;
156 region.isPermitted = lcpRegionsTenantsMap[region.id].reduce(reducer).isPermitted;
159 return new LcpRegionsAndTenants(lcpRegionList, lcpRegionsTenantsMap);
162 public getServiceTypes(subscriberId): Observable<ServiceType[]> {
163 console.log("AaiService:getSubscriptionServiceTypeList: globalCustomerId: " + subscriberId);
164 if (_.has(this.store.getState().service.serviceTypes, subscriberId)){
165 return Observable.of(<any> JSON.parse(JSON.stringify(this.store.getState().service.serviceTypes[subscriberId])));
168 return this.getSubscriberDetails(subscriberId)
169 .map(this.subDetailsResponseToServiceTypes)
170 .do((res) => {this.store.dispatch(updateServiceTypes(res, subscriberId));});
173 public getSubscriberDetails(subscriberId): Observable<GetSubDetailsResponse> {
174 let pathQuery: string = Constants.Path.AAI_SUB_DETAILS_PATH + subscriberId + Constants.Path.ASSIGN + Math.random();
176 if (subscriberId != null) {
177 return this.http.get<GetSubDetailsResponse>(pathQuery);
181 subDetailsResponseToServiceTypes(res: GetSubDetailsResponse): ServiceType[] {
182 if (res && res['service-subscriptions']) {
183 const serviceSubscriptions = res['service-subscriptions']['service-subscription'];
184 return serviceSubscriptions.map((subscription, index) => new ServiceType(String(index), subscription))