argos/dmp-frontend/src/app/core/services/dmp/dmp-blueprint.service.ts

108 lines
4.7 KiB
TypeScript

import { HttpClient, HttpHeaders, HttpResponse } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { DataTableData } from '@app/core/model/data-table/data-table-data';
import { DataTableRequest } from '@app/core/model/data-table/data-table-request';
import { DatasetListingModel } from '@app/core/model/dataset/dataset-listing';
import { DmpBlueprint, DmpBlueprintPersist } from '@app/core/model/dmp-blueprint/dmp-blueprint';
import { DmpBlueprintListing } from '@app/core/model/dmp/dmp-blueprint/dmp-blueprint-listing';
import { DmpBlueprintLookup } from '@app/core/query/dmp-blueprint.lookup';
import { DmpBlueprintCriteria } from '@app/core/query/dmp/dmp-blueprint-criteria';
import { DmpBlueprintExternalAutocompleteCriteria } from '@app/core/query/dmp/dmp-profile-external-autocomplete-criteria';
import { RequestItem } from '@app/core/query/request-item';
import { BaseHttpParams } from '@common/http/base-http-params';
import { InterceptorType } from '@common/http/interceptors/interceptor-type';
import { QueryResult } from '@common/model/query-result';
import { Observable, throwError } from 'rxjs';
import { catchError } from 'rxjs/operators';
import { ConfigurationService } from '../configuration/configuration.service';
import { BaseHttpV2Service } from '../http/base-http-v2.service';
import { Guid } from '@common/types/guid';
@Injectable()
export class DmpBlueprintService {
private actionUrl: string;
private headers = new HttpHeaders();
constructor(private http: BaseHttpV2Service, private httpClient: HttpClient, private configurationService: ConfigurationService) {
this.actionUrl = configurationService.server + 'dmpprofile/';
}
private get apiBase(): string { return `${this.configurationService.server}dmpprofile`; }
query(q: DmpBlueprintLookup): Observable<QueryResult<DmpBlueprint>> {
const url = `${this.apiBase}/query`;
return this.http.post<QueryResult<DmpBlueprint>>(url, q).pipe(catchError((error: any) => throwError(error)));
}
getSingle(id: Guid, reqFields: string[] = []): Observable<DmpBlueprint> {
const url = `${this.apiBase}/${id}`;
const options = { params: { f: reqFields } };
return this.http
.get<DmpBlueprint>(url, options).pipe(
catchError((error: any) => throwError(error)));
}
persist(item: DmpBlueprintPersist): Observable<DmpBlueprint> {
const url = `${this.apiBase}/persist`;
return this.http
.post<DmpBlueprint>(url, item).pipe(
catchError((error: any) => throwError(error)));
}
delete(id: Guid): Observable<DmpBlueprint> {
const url = `${this.apiBase}/${id}`;
return this.http
.delete<DmpBlueprint>(url).pipe(
catchError((error: any) => throwError(error)));
}
getPaged(dataTableRequest: DataTableRequest<DmpBlueprintCriteria>): Observable<DataTableData<DmpBlueprintListing>> {
return this.http.post<DataTableData<DmpBlueprintListing>>(this.actionUrl + 'getPaged', dataTableRequest, { headers: this.headers });
}
getPagedBlueprint(dataTableRequest: DataTableRequest<DmpBlueprintCriteria>): Observable<DataTableData<DmpBlueprintListing>> {
return this.http.post<DataTableData<DmpBlueprintListing>>(this.actionUrl + 'getPagedBlueprint', dataTableRequest, { headers: this.headers });
}
getSingleBlueprint(id: String): Observable<DmpBlueprintListing> {
return this.http.get<DmpBlueprintListing>(this.actionUrl + 'getSingleBlueprint/' + id, { headers: this.headers });
}
createDmp(dataManagementPlanModel: DmpBlueprint): Observable<DmpBlueprint> {
return this.http.post<DmpBlueprint>(this.actionUrl, dataManagementPlanModel, { headers: this.headers });
}
createBlueprint(dmpBlueprint: DmpBlueprint): Observable<DmpBlueprint> {
return this.http.post<DmpBlueprint>(this.actionUrl + 'blueprint', dmpBlueprint, { headers: this.headers });
}
public downloadXML(id: string): Observable<HttpResponse<Blob>> {
let headerXml: HttpHeaders = this.headers.set('Content-Type', 'application/xml')
return this.httpClient.get(this.actionUrl + 'getXml/' + id, { responseType: 'blob', observe: 'response', headers: headerXml });
}
uploadFile(file: FileList, labelSent: string): Observable<DataTableData<DatasetListingModel>> {
const params = new BaseHttpParams();
params.interceptorContext = {
excludedInterceptors: [InterceptorType.JSONContentType]
};
const formData = new FormData();
formData.append('file', file[0], labelSent);
return this.http.post(this.actionUrl + "upload", formData, { params: params });
}
clone(id: string): Observable<DmpBlueprint> {
return this.http.post<DmpBlueprint>(this.actionUrl + 'clone/' + id, { headers: this.headers });
}
externalAutocomplete(lookUpItem: RequestItem<DmpBlueprintExternalAutocompleteCriteria>): Observable<any> {
return this.httpClient.post(this.actionUrl + 'search/autocomplete', lookUpItem);
}
}