2 * Copyright (c) 2018 AT&T Intellectual Property.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 import { Injectable, Inject } from '@angular/core';
20 import { Http, Response } from '@angular/http';
21 import 'rxjs/add/operator/toPromise';
22 import {IAppConfigurtaion, ValidationConfiguration, Validations, Plugins, PluginsConfiguration} from "app/models";
23 import {IApi} from "app/models/app-config";
24 import {SdcConfigToken, ISdcConfig} from "../config/sdc-config.config";
27 export class ConfigService {
30 public configuration: IAppConfigurtaion;
33 constructor(private http: Http, @Inject(SdcConfigToken) private sdcConfig:ISdcConfig) {
34 this.api = this.sdcConfig.api;
35 this.baseUrl = this.api.root + this.sdcConfig.api.component_api_root;
38 loadValidationConfiguration(): Promise<ValidationConfiguration> {
39 let url: string = this.sdcConfig.validationConfigPath;
40 let promise: Promise<ValidationConfiguration> = this.http.get(url).map((res: Response) => res.json()).toPromise();
41 promise.then((validationData: Validations) => {
42 ValidationConfiguration.validation = validationData;
44 console.error('Error loading validation.json configuration file, using fallback data', ex);
46 let fallback:Validations = {
52 "validationPatterns": {
53 "string": "^[\\sa-zA-Z0-9+-]+$",
54 "comment": "^[\\sa-zA-Z0-9+-_\\{\\}\"]+$",
55 "integer": "^(([-+]?\\d+)|([-+]?0x[0-9a-fA-F]+))$"
59 ValidationConfiguration.validation = fallback;
66 loadPluginsConfiguration(): Promise<PluginsConfiguration> {
67 let url:string = this.api.no_proxy_root + this.api.GET_plugins_configuration;
68 let promise: Promise<any> = this.http.get(url).map((res: Response) => res.json()).toPromise();
69 return new Promise<PluginsConfiguration>((resolve) => {
70 promise.then((pluginsData: Plugins) => {
71 PluginsConfiguration.plugins = pluginsData;
74 console.error("Error loading plugins configuration from FE", ex);
76 PluginsConfiguration.plugins = [] as Plugins;