Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F82146875
tln-query.service.ts
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Mon, Sep 9, 20:38
Size
1 KB
Mime Type
text/x-java
Expires
Wed, Sep 11, 20:38 (2 d)
Engine
blob
Format
Raw Data
Handle
20658754
Attached To
rNIETZSCHEBETAAPP Nietzsche-Beta-App
tln-query.service.ts
View Options
import { Injectable, EventEmitter, OnInit } from '@angular/core';
import {HttpClient, HttpHeaders, HttpErrorResponse } from '@angular/common/http';
import { Observable, throwError } from 'rxjs';
import { catchError } from 'rxjs/operators';
import { TlnQueryServiceInterface } from './models';
/**
* This is the internal query service
* that communicates with the SPARQL-endpoint.
* */
@Injectable({ providedIn: 'root'})
export class TlnQueryService implements TlnQueryServiceInterface {
//baseUrl = 'http://localhost:3030/nietzsche/query';
baseUrl = 'https://nietzsche.fuseki.services.dasch.swiss/nietzsche';
reset_data = new EventEmitter<string>();
constructor(private http: HttpClient) {
}
public resetData(key: string){
this.reset_data.emit(key);
}
/**
* Gets the data from an endpoint via http post
*
* @param query: The query to run.
* @returns response
*/
public getData(query: string): Observable<any> {
let httpOptions = {
headers: new HttpHeaders(
{ 'Content-Type': 'application/sparql-query',
'Accept': 'application/sparql-results+json; charset=UTF-8'}
)
};
return this.http.post(this.baseUrl, query, httpOptions).pipe(catchError(this.handleError));
}
private handleError(error: HttpErrorResponse) {
if (error.status === 0) {
// A client-side or network error occurred. Handle it accordingly.
console.error('The backend data server is offline:', error.error);
} else {
// The backend returned an unsuccessful response code.
// The response body may contain clues as to what went wrong.
console.error(
`Backend returned code ${error.status}, ` +
`body was: ${error.error}`);
}
return throwError( 'Something bad happened; please try again later.');
}
}
Event Timeline
Log In to Comment