/*********************************************************************************************************************************
This class has been automatically generated using KLTT-APIRestGenerator project, don't do manual file modifications.
Fri Jul 13 17:25:45 CEST 2018
"Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements;
and to You under the Apache License, Version 2.0. "
**********************************************************************************************************************************/
import {Subject} from '../model/subject.model' ;
import {Person} from '../model/person.model' ;
import {UniversityPerson} from '../model/university-person.model' ;
import {Teacher} from '../model/teacher.model' ;
import {PAKKK_INHERITANCEEXAMPLE_API_TOKEN} from './pakkk-inheritanceexample-api.token' ;
import {StandardHttpException} from './../utils/standard-http-exception.utils' ;
import {ParserValues} from '../utils/parser-values.utils' ;
import {Observable} from 'rxjs/Rx' ;
import {Injectable, Inject} from '@angular/core' ;
import {HttpClient, HttpHeaders, HttpErrorResponse} from '@angular/common/http' ;
import {ErrorObservable} from 'rxjs/observable/ErrorObservable' ;
/**
* ------------------------------------------------
* @author API Rest Generator
* ------------------------------------------------
*/
@Injectable()
export class PakkkInheritanceexampleApiService
{
/** Constant - API Version - Key */
static API_VERSION_KEY = "PakkkInheritanceexampleApiApiVersion" ;
/** Constant - API Version - Value */
static API_VERSION_VALUE = "1.0.0" ;
constructor(@Inject(PAKKK_INHERITANCEEXAMPLE_API_TOKEN) private baseURI: string, private http: HttpClient)
{
// Empty method
}
getBaseURI(scheme: string)
{
return scheme + "://" + this.baseURI + "/" ;
}
getTeachers(scheme: string) : Observable<Teacher[]> {
// Local Reference of this class
var self = this ;
// Validate the input scheme
var isValidInputScheme = this.getTeachersValidateScheme(scheme) ;
Iif (!isValidInputScheme)
{
throw new Error("Angular5 Client contains an invalid input scheme: '" + scheme + "'. Please use one of the defined in the specification.") ;
}
// Assign a final URL with all the parameters assigned to
var fullURL = this.getTeachersFullUrl(scheme) ;
// Set the header parameters
var headerParameters = this.getTeachersHeaderAssignment() ;
let formDataInstance = null ;
// Return the observable
return this.http
.request<Teacher[]>("GET", fullURL, { body: formDataInstance, headers: headerParameters, responseType : "json" })
.catch((error: HttpErrorResponse): ErrorObservable => {
let outcome ;
var contentValue = error.error ;
outcome = self.generateStandardHttpExceptionFromErrorInstance(error.status, contentValue) ;
return Observable.throw(outcome) ;
});
}
/**
* Validate the input scheme with the expected for this
*/
getTeachersValidateScheme(scheme)
{
return scheme == "http" ;
}
/**
* The following method get the full URL
*/
getTeachersFullUrl(scheme: string)
{
// URL with scheme
var urlWithScheme = this.getBaseURI(scheme) + "api/teacher/" ;
// Replace every path parameter with the input value
var urlWithPaths = this.getTeachersPathAssignment(urlWithScheme) ;
// Replace every query parameter with the input value
var queryParameters = this.getTeachersQueryAssignment() ;
// Return a final URL with all the parameters assigned to
return urlWithPaths + queryParameters ;
}
/**
* The following method assign every path parameter with the value
*/
getTeachersPathAssignment(urlWithScheme: string)
{
return urlWithScheme ;
}
/**
* The following method assign every query parameter with the value
*/
getTeachersQueryAssignment()
{
var outcome = "?" ;
return outcome ;
}
/**
* The following method assign every header parameter with the value
*/
getTeachersHeaderAssignment()
{
let headers = new HttpHeaders() ;
// Add the "ApiVersion" header
headers = headers.set(PakkkInheritanceexampleApiService.API_VERSION_KEY, PakkkInheritanceexampleApiService.API_VERSION_VALUE) ;
return headers ;
}
getPeople(scheme: string) : Observable<Person[]> {
// Local Reference of this class
var self = this ;
// Validate the input scheme
var isValidInputScheme = this.getPeopleValidateScheme(scheme) ;
Iif (!isValidInputScheme)
{
throw new Error("Angular5 Client contains an invalid input scheme: '" + scheme + "'. Please use one of the defined in the specification.") ;
}
// Assign a final URL with all the parameters assigned to
var fullURL = this.getPeopleFullUrl(scheme) ;
// Set the header parameters
var headerParameters = this.getPeopleHeaderAssignment() ;
let formDataInstance = null ;
// Return the observable
return this.http
.request<Person[]>("GET", fullURL, { body: formDataInstance, headers: headerParameters, responseType : "json" })
.catch((error: HttpErrorResponse): ErrorObservable => {
let outcome ;
var contentValue = error.error ;
outcome = self.generateStandardHttpExceptionFromErrorInstance(error.status, contentValue) ;
return Observable.throw(outcome) ;
});
}
/**
* Validate the input scheme with the expected for this
*/
getPeopleValidateScheme(scheme)
{
return scheme == "http" ;
}
/**
* The following method get the full URL
*/
getPeopleFullUrl(scheme: string)
{
// URL with scheme
var urlWithScheme = this.getBaseURI(scheme) + "api/person/" ;
// Replace every path parameter with the input value
var urlWithPaths = this.getPeoplePathAssignment(urlWithScheme) ;
// Replace every query parameter with the input value
var queryParameters = this.getPeopleQueryAssignment() ;
// Return a final URL with all the parameters assigned to
return urlWithPaths + queryParameters ;
}
/**
* The following method assign every path parameter with the value
*/
getPeoplePathAssignment(urlWithScheme: string)
{
return urlWithScheme ;
}
/**
* The following method assign every query parameter with the value
*/
getPeopleQueryAssignment()
{
var outcome = "?" ;
return outcome ;
}
/**
* The following method assign every header parameter with the value
*/
getPeopleHeaderAssignment()
{
let headers = new HttpHeaders() ;
// Add the "ApiVersion" header
headers = headers.set(PakkkInheritanceexampleApiService.API_VERSION_KEY, PakkkInheritanceexampleApiService.API_VERSION_VALUE) ;
return headers ;
}
/**
* @param statusCode with the status code
* @param error with the instance of the error
* @return a new instance of standard HTTP exception
*/
generateStandardHttpExceptionFromErrorInstance(statusCode, error)
{
var errorString ;
var message ;
var exception ;
var path ;
var timestamp ;
if (error != undefined)
{
errorString = error.error ;
message = error.message ;
exception = error.exception ;
path = error.path ;
timestamp = error.timestamp ;
}
return this.generateStandardHttpException(statusCode, errorString, message, exception, path, timestamp) ;
}
/**
* @param statusCode with the status code
* @param errorString with the error message
* @param message with the exception message
* @param exception with the stack trace error
* @param path with the path error
* @param timestamp with the timestamp
* @return a new instance of standard HTTP exception
*/
generateStandardHttpException(statusCode: number, errorString: string, message: string, exception: string, path: string, timestamp: number)
{
var standardHttpException = new StandardHttpException(statusCode) ;
standardHttpException.setError(errorString) ;
standardHttpException.setMessage(message) ;
standardHttpException.setException(exception) ;
standardHttpException.setPath(path) ;
standardHttpException.setTimestamp(timestamp) ;
return standardHttpException ;
}
}
|