blob: c497c0fa21a338ccbb373f69fcc301ae70fd6dde [file] [log] [blame]
/********************************************************************************
* Copyright (c) 2015-2018 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* SPDX-License-Identifier: EPL-2.0
*
********************************************************************************/
import { Injectable } from '@angular/core';
import { Http, Response, Headers, RequestOptions } from '@angular/http';
import { PropertyService } from '../core/property.service';
import { plainToClass } from 'class-transformer';
import { HttpErrorHandler } from '../core/http-error-handler';
import { throwError as observableThrowError, Observable } from 'rxjs';
import { map, catchError } from 'rxjs/operators';
import { Node } from '../navigator/node';
@Injectable()
export class CatalogService {
private prefEndpoint: string;
constructor(private http: Http,
private httpErrorHandler: HttpErrorHandler,
private _prop: PropertyService) {
this.prefEndpoint = _prop.getUrl('mdm/environments/');
}
getTplRootsForType(scope: string, type: string): Observable<Node[]> {
return this.http.get(this.prefEndpoint + scope + '/tplroots/' + type).pipe(
map(response => plainToClass(Node, response.json().data)),
catchError(this.handleError));
}
getTplCompForRoot(scope: string, type: string, rootId: string): Observable<Node[]> {
return this.http.get(this.prefEndpoint + scope + '/tplroots/' + type + '/' + rootId + '/tplcomps').pipe(
map(response => plainToClass(Node, response.json().data)),
catchError(this.handleError));
}
getTplAttrsForComp(scope: string, type: string, rootId: string, tplCompId: string): Observable<Node[]> {
return this.http.get(this.prefEndpoint + scope + '/tplroots/' + type + '/' + rootId + '/tplcomps/' + tplCompId + '/tplattrs').pipe(
map(response => plainToClass(Node, response.json().data)),
catchError(this.handleError));
}
getCatCompsForType(scope: string, type: string): Observable<Node[]> {
return this.http.get(this.prefEndpoint + scope + '/catcomps/' + type).pipe(
map(response => plainToClass(Node, response.json().data)),
catchError(this.handleError));
}
getCatAttrsForComp(scope: string, type: string, catCompId: string): Observable<Node[]> {
return this.http.get(this.prefEndpoint + scope + '/catcomps/' + type + '/' + catCompId + '/catattrs').pipe(
map(response => plainToClass(Node, response.json().data)),
catchError(this.handleError));
}
private handleError(e: Error | any) {
if (e instanceof Response) {
let response = <Response> e;
if (response.status !== 200) {
return observableThrowError('Could not request catalog element! '
+ 'Please check if application server is running and database is configured correctly.');
}
}
return this.httpErrorHandler.handleError(e);
}
}