import { HttpClient, HttpHeaders, HttpResponse } from '@angular/common/http'; import { Injectable } from '@angular/core'; import { Observable } from 'rxjs'; import { takeUntil } from "rxjs/operators"; import { environment } from '../../../../environments/environment'; import { BaseHttpParams } from '../../../common/http/base-http-params'; import { InterceptorType } from '../../../common/http/interceptors/interceptor-type'; import { DatasetProfileEditorModel } from '../../../ui/admin/dataset-profile/editor/dataset-profile-editor-model'; import { BaseService } from "../../common/base/base.service"; import { DatasetProfile } from '../../model/admin/dataset-profile/dataset-profile'; import { DataTableData } from '../../model/data-table/data-table-data'; import { DataTableRequest } from '../../model/data-table/data-table-request'; import { DatasetProfileDefinitionModel } from '../../model/dataset-profile-definition/dataset-profile-definition'; import { DatasetListingModel } from '../../model/dataset/dataset-listing'; import { DatasetProfileCriteria } from '../../query/dataset-profile/dataset-profile-criteria'; import { BaseHttpService } from '../http/base-http.service'; @Injectable() export class DatasetProfileService extends BaseService { private rdaCommonStandards: String[]; private rdaCommonStandardsLoading: boolean; private actionUrl: string; private headers = new HttpHeaders(); constructor(private http: BaseHttpService, private httpClient: HttpClient) { super(); this.actionUrl = environment.Server + 'admin/'; } createForm(data) { return this.http.post(this.actionUrl + 'addDmp', data); } updateForm(id, data) { return this.http.post(this.actionUrl + 'addDmp/' + id, data); } getDatasetProfileById(datasetProfileID) { return this.http.get(this.actionUrl + 'get/' + datasetProfileID); } getPaged(dataTableRequest: DataTableRequest): Observable> { return this.http.post>(this.actionUrl + 'datasetprofiles/getPaged', dataTableRequest); } preview(data: DatasetProfile): Observable { return this.http.post(this.actionUrl + 'preview', data); } clone(id: string): Observable { return this.http.post(this.actionUrl + 'datasetprofile/clone/' + id, {}); } newVersion(id, data) { return this.http.post(this.actionUrl + 'newVersion/' + id, data); } delete(id: string, data): Observable { //return this.http.post(this.actionUrl + 'addDmp/' + id, data); return this.http.delete(this.actionUrl + id, {}); } 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 }); } getRDACommonStandards(): String[] { if (!this.rdaCommonStandards && !this.rdaCommonStandardsLoading) { this.getRDACommonStandardsInternal(); } return this.rdaCommonStandards; } private getRDACommonStandardsInternal() { this.rdaCommonStandardsLoading = true; return this.http.get(this.actionUrl + "getRDACommonStandards").pipe(takeUntil(this._destroyed)).subscribe(x => { this.rdaCommonStandards = x; this.rdaCommonStandardsLoading = false; }); } }