2019-07-23 14:23:12 +02:00
|
|
|
import {throwError as observableThrowError} from 'rxjs';
|
2017-12-19 13:53:46 +01:00
|
|
|
import {Injectable} from '@angular/core';
|
2019-07-23 14:23:12 +02:00
|
|
|
import {HttpClient} from '@angular/common/http';
|
|
|
|
import {catchError} from 'rxjs/operators';
|
|
|
|
import {CustomOptions} from '../../../services/servicesUtils/customOptions.class';
|
2019-06-03 15:20:36 +02:00
|
|
|
|
2017-12-19 13:53:46 +01:00
|
|
|
@Injectable()
|
|
|
|
export class ClaimsService {
|
2019-06-03 15:20:36 +02:00
|
|
|
constructor(private http: HttpClient ) {
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private getClaimRequest(size : number, page : number, url :string, fromCache:boolean):any {
|
2023-08-03 11:45:39 +02:00
|
|
|
return this.http.get(url, CustomOptions.getAuthOptionsWithBody());
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
2018-02-05 14:14:59 +01:00
|
|
|
getClaims( size : number, page : number, keyword:string, sortby: string, descending: boolean, types: string, apiUrl:string):any {
|
2022-05-11 11:02:23 +02:00
|
|
|
let url = apiUrl +"claims"+"?offset="+(size*(page-1) + "&limit="+size)+"&keyword="+keyword+"&sortby="+sortby+"&descending="+descending+(types.length>0?"&"+types:types);
|
2017-12-19 13:53:46 +01:00
|
|
|
return this.getClaimRequest(size,page,url,true);
|
|
|
|
|
|
|
|
}
|
2018-02-05 14:14:59 +01:00
|
|
|
getClaimsByUser( size : number, page : number, user:string, keyword:string, sortby: string, descending: boolean, types: string, apiUrl:string):any {
|
2019-02-14 11:15:44 +01:00
|
|
|
//console.info('ClaimsService: getClaims for user : '+user);
|
2022-05-11 11:02:23 +02:00
|
|
|
let url = apiUrl +"users/claims"+"?offset="+(size*(page-1) + "&limit="+size)+"&keyword="+keyword+"&sortby="+sortby+"&descending="+descending+(types.length>0?"&"+types:types);
|
2017-12-19 13:53:46 +01:00
|
|
|
return this.getClaimRequest(size,page,url,false);
|
|
|
|
|
|
|
|
}
|
2018-02-05 14:14:59 +01:00
|
|
|
getClaimsBycontext( size : number, page : number, contextId:string, keyword:string, sortby: string, descending: boolean, types: string , apiUrl:string):any {
|
2019-02-14 11:15:44 +01:00
|
|
|
//console.info('ClaimsService: getClaims for context : '+contextId);
|
2022-05-11 11:02:23 +02:00
|
|
|
let url = apiUrl +"contexts/"+contextId+"/claims"+"?offset="+(size*(page-1) + "&limit="+size)+"&keyword="+keyword+"&sortby="+sortby+"&descending="+descending+(types.length>0?"&"+types:types);
|
2017-12-19 13:53:46 +01:00
|
|
|
return this.getClaimRequest(size,page,url,true);
|
|
|
|
|
|
|
|
}
|
2018-02-05 14:14:59 +01:00
|
|
|
getClaimsByResult( size : number, page : number, resultId:string, keyword:string, sortby: string, descending: boolean, types: string, apiUrl:string ):any {
|
2019-07-23 14:23:12 +02:00
|
|
|
//console.info('ClaimsService: getClaims for entity : '+resultId);
|
2022-05-11 11:02:23 +02:00
|
|
|
let url = apiUrl +"results/"+resultId+"/claims"+"?offset="+(size*(page-1) + "&limit="+size)+"&keyword="+keyword+"&sortby="+sortby+"&descending="+descending+(types.length>0?"&"+types:types);
|
2017-12-19 13:53:46 +01:00
|
|
|
return this.getClaimRequest(size,page,url,true);
|
|
|
|
|
|
|
|
}
|
2018-02-05 14:14:59 +01:00
|
|
|
getClaimsByProject( size : number, page : number, projectId:string, keyword:string, sortby: string, descending: boolean, types: string, apiUrl:string ):any {
|
2019-02-14 11:15:44 +01:00
|
|
|
//console.info('ClaimsService: getClaims for project : '+projectId);
|
2022-05-11 11:02:23 +02:00
|
|
|
let url = apiUrl +"projects/"+projectId+"/claims"+"?offset="+(size*(page-1) + "&limit="+size)+"&keyword="+keyword+"&sortby="+sortby+"&descending="+descending+(types.length>0?"&"+types:types);
|
2017-12-19 13:53:46 +01:00
|
|
|
return this.getClaimRequest(size,page,url,true);
|
|
|
|
}
|
|
|
|
|
2018-02-05 14:14:59 +01:00
|
|
|
deleteClaimById(claimId:string , apiUrl:string):any{
|
2019-02-14 11:15:44 +01:00
|
|
|
//console.warn('Trying to delete claim with id : '+claimId);
|
2018-02-05 14:14:59 +01:00
|
|
|
let url = apiUrl +"claims/"+claimId;
|
2019-06-03 15:20:36 +02:00
|
|
|
return this.http.delete( url, CustomOptions.getAuthOptionsWithBody())//.map(request => <any> request.json())
|
|
|
|
.pipe(catchError(this.handleError));
|
2017-12-19 13:53:46 +01:00
|
|
|
|
|
|
|
}
|
2018-02-05 14:14:59 +01:00
|
|
|
deleteBulk(claimIds:string[], apiUrl:string):any{
|
2017-12-19 13:53:46 +01:00
|
|
|
|
2019-02-14 11:15:44 +01:00
|
|
|
//console.warn('Trying to delete claims with ids : '+claimIds);
|
2017-12-19 13:53:46 +01:00
|
|
|
var url = "";
|
|
|
|
|
|
|
|
for(var claimId of claimIds){
|
|
|
|
url=url+(url.length >0 ?"&":"")+"claimId="+claimId;
|
|
|
|
}
|
2018-02-05 14:14:59 +01:00
|
|
|
url= apiUrl +"claims/bulk?"+url;
|
2017-12-19 13:53:46 +01:00
|
|
|
|
2023-08-03 11:45:39 +02:00
|
|
|
return this.http.delete( url, CustomOptions.getAuthOptionsWithBody())//.map(request => <any> request.json())
|
2019-06-03 15:20:36 +02:00
|
|
|
.pipe(catchError(this.handleError));
|
2017-12-19 13:53:46 +01:00
|
|
|
|
|
|
|
}
|
2018-02-05 14:14:59 +01:00
|
|
|
insertBulkClaims(claims, apiUrl:string):any{
|
2020-03-26 13:18:18 +01:00
|
|
|
// console.warn('Trying toinsert claims : '+claims);
|
2018-02-05 14:14:59 +01:00
|
|
|
let url = apiUrl +"claims/bulk";
|
2017-12-19 13:53:46 +01:00
|
|
|
let body = JSON.stringify( claims );
|
|
|
|
return this.http.post(url, body, CustomOptions.getAuthOptionsWithBody())
|
2019-06-03 15:20:36 +02:00
|
|
|
.pipe(catchError(this.handleError));
|
2017-12-19 13:53:46 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-02-05 14:14:59 +01:00
|
|
|
insertDirectRecords(records, apiUrl:string):any{
|
2019-02-14 11:15:44 +01:00
|
|
|
//console.warn('Trying to feedrecords : '+records);
|
2018-02-05 14:14:59 +01:00
|
|
|
let url = apiUrl +"feed/bulk";
|
2017-12-19 13:53:46 +01:00
|
|
|
let body = JSON.stringify( records );
|
|
|
|
return this.http.post(url, body, CustomOptions.getAuthOptionsWithBody())
|
2019-06-03 15:20:36 +02:00
|
|
|
.pipe(catchError(this.handleError));
|
2017-12-19 13:53:46 +01:00
|
|
|
|
|
|
|
}
|
2023-07-28 11:15:54 +02:00
|
|
|
getStatus(jobId, apiUrl:string):any{
|
|
|
|
|
|
|
|
let url = apiUrl +"jobStatus/" + jobId;
|
|
|
|
|
2023-08-03 11:45:39 +02:00
|
|
|
return this.http.get(url,CustomOptions.getAuthOptionsWithBody())
|
2023-07-28 11:15:54 +02:00
|
|
|
.pipe(catchError(this.handleError));
|
|
|
|
|
|
|
|
}
|
2017-12-19 13:53:46 +01:00
|
|
|
private handleError (error: Response) {
|
|
|
|
// in a real world app, we may send the error to some remote logging infrastructure
|
|
|
|
// instead of just logging it to the console
|
|
|
|
console.log(error);
|
2019-06-03 15:20:36 +02:00
|
|
|
return observableThrowError(error || 'Server error');
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|