/*-------------------------------------------------------------------------------------------------------------- * Copyright (c) insite-gmbh. All rights reserved. * Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------------------------*/ import { Observable } from 'rxjs/Rx'; import { Injectable } from '@angular/core'; import { Http, Headers, Response } from '@angular/http'; import { InaxConfiguration, ProfileService, Result } from '../../../@inax/common'; @Injectable() export class InaxFrontendService { constructor(private _http: Http, private _configuration: InaxConfiguration, private _profileService: ProfileService) { } /*********************************************************************** * WEB API * ********************************************************************/ /** * Returns the name and the IP address of the caller. * @method whoAmI * @return {Observable} TODO */ public whoAmI(): Observable { let accessUrl = this._configuration.buildRestUrl("Frontend", "WhoAmI"); let headers = this._profileService.addAuthorization(new Headers()); return this._http.get(accessUrl, { headers }).map(res => res.json()); } /** * Read configuration values from the INAX.config * @method whoAmI * @return {Observable} TODO */ public readConfigValue(propertyName: string, defaultValue: string): Observable { let accessUrl = this._configuration.buildRestUrl("Frontend","ReadConfigValue") + "?propertyName=" + propertyName + "&defaultValue=" + defaultValue; let headers = this._profileService.addAuthorization(new Headers()); return this._http.get(accessUrl, { headers }).map(res => res.json()); } /** * Returns false if INAX is not licensed at the time of checking * @method whoAmI * @return {Observable} TODO */ public isInaxLicensed(): Observable { let accessUrl = this._configuration.buildRestUrl("Frontend","IsInaxLicensed"); let headers = this._profileService.addAuthorization(new Headers()); return this._http.get(accessUrl, { headers }).map(res => res.json()); } /** * INAX restarts the Webservice * @method whoAmI * @return {Observable} TODO */ public restartWebServer(uri: string): Observable { let accessUrl = this._configuration.buildRestUrl("Frontend","RestartWebServer") + "?uri=" + uri; let headers = this._profileService.addAuthorization(new Headers()); return this._http.post(accessUrl, null, { headers }).map(res => res.json()); } /** * Reload the user defined types * @method whoAmI * @return {Observable} TODO */ public reloadCustomData(path: string): Observable { let accessUrl = this._configuration.buildRestUrl("Frontend","ReloadCustomData") + "?path=" + path; let headers = this._profileService.addAuthorization(new Headers()); return this._http.post(accessUrl, null, { headers }).map(res => res.json()); } /** * All components will be restarted * @method whoAmI * @return {Observable} TODO */ public restartComponents(): Observable { let accessUrl = this._configuration.buildRestUrl("Frontend","RestartComponents"); let headers = this._profileService.addAuthorization(new Headers()); return this._http.post(accessUrl, null, { headers }).map(res => res.json()); } /** * Restart the given component * @method whoAmI * @return {Observable} TODO */ public restartComponent(componentName: string): Observable { let accessUrl = this._configuration.buildRestUrl("Frontend","RestartComponents") + "?componentName=" + componentName; let headers = this._profileService.addAuthorization(new Headers()); return this._http.post(accessUrl, null, { headers }).map(res => res.json()); } }