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}dmp-blueprint`; } query(q: DmpBlueprintLookup): Observable> { const url = `${this.apiBase}/query`; return this.http.post>(url, q).pipe(catchError((error: any) => throwError(error))); } getSingle(id: Guid, reqFields: string[] = []): Observable { const url = `${this.apiBase}/${id}`; const options = { params: { f: reqFields } }; return this.http .get(url, options).pipe( catchError((error: any) => throwError(error))); } persist(item: DmpBlueprintPersist): Observable { const url = `${this.apiBase}/persist`; return this.http .post(url, item).pipe( catchError((error: any) => throwError(error))); } delete(id: Guid): Observable { const url = `${this.apiBase}/${id}`; return this.http .delete(url).pipe( catchError((error: any) => throwError(error))); } getPaged(dataTableRequest: DataTableRequest): Observable> { return this.http.post>(this.actionUrl + 'getPaged', dataTableRequest, { headers: this.headers }); } getPagedBlueprint(dataTableRequest: DataTableRequest): Observable> { return this.http.post>(this.actionUrl + 'getPagedBlueprint', dataTableRequest, { headers: this.headers }); } getSingleBlueprint(id: String): Observable { return this.http.get(this.actionUrl + 'getSingleBlueprint/' + id, { headers: this.headers }); } createDmp(dataManagementPlanModel: DmpBlueprint): Observable { return this.http.post(this.actionUrl, dataManagementPlanModel, { headers: this.headers }); } createBlueprint(dmpBlueprint: DmpBlueprint): Observable { return this.http.post(this.actionUrl + 'blueprint', dmpBlueprint, { headers: this.headers }); } public downloadXML(id: string): Observable> { 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> { 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 { return this.http.post(this.actionUrl + 'clone/' + id, { headers: this.headers }); } externalAutocomplete(lookUpItem: RequestItem): Observable { return this.httpClient.post(this.actionUrl + 'search/autocomplete', lookUpItem); } }