2018-10-30 16:31:16 +01:00
|
|
|
import {Injectable} from '@angular/core';
|
2019-06-03 16:52:33 +02:00
|
|
|
import {HttpClient, HttpHeaders} from '@angular/common/http';
|
2019-10-04 10:47:16 +02:00
|
|
|
import {EnvProperties} from '../openaireLibrary/utils/properties/env-properties';
|
|
|
|
import {ContentProvider} from '../openaireLibrary/utils/entities/contentProvider';
|
|
|
|
import {Observable} from 'rxjs/Observable';
|
2018-10-30 16:31:16 +01:00
|
|
|
|
|
|
|
@Injectable()
|
|
|
|
export class ManageCommunityContentProvidersService {
|
2019-10-04 10:47:16 +02:00
|
|
|
constructor(private http: HttpClient) {
|
|
|
|
}
|
2019-06-03 16:52:33 +02:00
|
|
|
|
2020-04-08 13:59:20 +02:00
|
|
|
removeContentProvider(properties: EnvProperties, pid: string, id: string): any {
|
2019-06-03 16:52:33 +02:00
|
|
|
let headers = new HttpHeaders({'Content-Type': 'application/json', 'accept': 'application/json'});
|
2020-04-08 13:59:20 +02:00
|
|
|
let url = properties.communityAPI + pid + '/contentproviders';
|
2019-10-04 10:47:16 +02:00
|
|
|
return this.http.request('delete', url, {body: id, headers: headers});
|
2018-10-30 16:31:16 +01:00
|
|
|
}
|
|
|
|
|
2020-04-08 13:59:20 +02:00
|
|
|
addContentProvider(properties: EnvProperties, pid: string, contentProvider: any): Observable<ContentProvider> {
|
|
|
|
let url = properties.communityAPI + pid + '/contentproviders';
|
|
|
|
let communityContentProvider = this.convertSearchContentProviderToCommunityContentProvider(contentProvider, pid);
|
2019-10-04 10:47:16 +02:00
|
|
|
return this.http.post<ContentProvider>(url, communityContentProvider);
|
|
|
|
}
|
2018-10-30 16:31:16 +01:00
|
|
|
|
2019-10-04 10:47:16 +02:00
|
|
|
saveContentProvider(properties: EnvProperties, contentProvider: ContentProvider): Observable<ContentProvider> {
|
|
|
|
let url = properties.communityAPI + contentProvider.communityId + '/contentproviders';
|
|
|
|
return this.http.post<ContentProvider>(url, contentProvider);
|
|
|
|
}
|
2018-10-30 16:31:16 +01:00
|
|
|
|
2019-10-04 10:47:16 +02:00
|
|
|
convertSearchContentProviderToCommunityContentProvider(contentProvider: any, community: string): ContentProvider {
|
|
|
|
let communityContentProvider: ContentProvider = new ContentProvider();
|
|
|
|
communityContentProvider.communityId = community;
|
2018-10-30 16:31:16 +01:00
|
|
|
communityContentProvider.officialname = contentProvider.title.name;
|
|
|
|
communityContentProvider.name = contentProvider.englishname;
|
|
|
|
communityContentProvider.openaireId = contentProvider.id;
|
|
|
|
|
|
|
|
return communityContentProvider;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|