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=========================================================
22 * Created by ob0695 on 4/9/2017.
25 import { Injectable, Inject } from '@angular/core';
26 import { Http, Response } from '@angular/http';
27 import 'rxjs/add/operator/toPromise';
28 import {IAppConfigurtaion, ValidationConfiguration, Validations, Plugins, PluginsConfiguration} from "app/models";
29 import {IApi} from "app/models/app-config";
30 import {SdcConfigToken, ISdcConfig} from "../config/sdc-config.config";
33 export class ConfigService {
36 public configuration: IAppConfigurtaion;
39 constructor(private http: Http, @Inject(SdcConfigToken) private sdcConfig:ISdcConfig) {
40 this.api = this.sdcConfig.api;
41 this.baseUrl = this.sdcConfig.api.root + this.sdcConfig.api.component_api_root;
44 loadValidationConfiguration(): Promise<ValidationConfiguration> {
45 let url: string = this.sdcConfig.validationConfigPath;
46 let promise: Promise<ValidationConfiguration> = this.http.get(url).map((res: Response) => res.json()).toPromise();
47 promise.then((validationData: Validations) => {
48 ValidationConfiguration.validation = validationData;
50 console.error('Error loading validation.json configuration file, using fallback data', ex);
52 let fallback:Validations = {
58 "validationPatterns": {
59 "string": "^[\\sa-zA-Z0-9+-]+$",
60 "comment": "^[\\sa-zA-Z0-9+-_\\{\\}\"]+$",
61 "integer": "^(([-+]?\\d+)|([-+]?0x[0-9a-fA-F]+))$"
65 ValidationConfiguration.validation = fallback;
72 loadPluginsConfiguration(): Promise<PluginsConfiguration> {
73 let url:string = this.api.no_proxy_root + this.api.GET_plugins_configuration;
74 let promise: Promise<any> = this.http.get(url).map((res: Response) => res.json()).toPromise();
75 promise.then((pluginsData: Plugins) => {
76 PluginsConfiguration.plugins = pluginsData;
78 console.error("Error loading plugins configuration from BE", ex);
80 PluginsConfiguration.plugins = [] as Plugins;