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 {
|
2020-03-26 13:18:18 +01:00
|
|
|
return this.http.get(url, CustomOptions.getAuthOptions());
|
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;
|
2017-12-19 13:53:46 +01:00
|
|
|
// let headers = new Headers({ 'Content-Type': 'application/json' });
|
|
|
|
// let options = new RequestOptions({ headers: headers });
|
2019-06-03 15:20:36 +02:00
|
|
|
return this.http.delete( url, CustomOptions.getAuthOptionsWithBody())//.map(request => <any> request.json())
|
2017-12-19 13:53:46 +01:00
|
|
|
// .do(request => console.info("After delete" ))
|
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
|
|
|
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
|
|
|
|
|
|
|
// let headers = new Headers({ 'Content-Type': 'application/json' });
|
|
|
|
// let options = new RequestOptions({ headers: headers });
|
2019-06-03 15:20:36 +02:00
|
|
|
return this.http.delete( url, CustomOptions.getAuthOptions())//.map(request => <any> request.json())
|
2017-12-19 13:53:46 +01:00
|
|
|
// .do(request => console.info("After delete" ))
|
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 );
|
2019-02-14 11:15:44 +01:00
|
|
|
//console.warn('Json body: : '+body);
|
2017-12-19 13:53:46 +01:00
|
|
|
// let headers = new Headers({ 'Content-Type': 'application/json' });
|
|
|
|
// let options = new RequestOptions({ headers: headers });
|
|
|
|
return this.http.post(url, body, CustomOptions.getAuthOptionsWithBody())
|
2019-06-03 15:20:36 +02:00
|
|
|
//.map(res => res.json())
|
2019-02-14 11:15:44 +01:00
|
|
|
//.do(request => console.info("Insert Response:"+request.status) )
|
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
|
|
|
insertClaim(claim, apiUrl:string):any{
|
2019-02-14 11:15:44 +01:00
|
|
|
//console.warn('Trying toinsert claim : '+claim);
|
2018-02-05 14:14:59 +01:00
|
|
|
let url = apiUrl +"claims";
|
2017-12-19 13:53:46 +01:00
|
|
|
let body = JSON.stringify( claim );
|
|
|
|
// let headers = new Headers({ 'Content-Type': 'application/json' });
|
|
|
|
// let options = new RequestOptions({ headers: headers });
|
|
|
|
return this.http.post(url, body, CustomOptions.getAuthOptionsWithBody())
|
2019-06-03 15:20:36 +02:00
|
|
|
//.map(res => res.json())
|
2019-02-14 11:15:44 +01:00
|
|
|
//.do(request => console.info("Insert Response:"+request.status) )
|
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 );
|
2019-02-14 11:15:44 +01:00
|
|
|
//console.warn('Json body: : '+body);
|
2017-12-19 13:53:46 +01:00
|
|
|
// let headers = new Headers({ 'Content-Type': 'application/json' });
|
|
|
|
// let options = new RequestOptions({ headers: headers });
|
|
|
|
return this.http.post(url, body, CustomOptions.getAuthOptionsWithBody())
|
2019-06-03 15:20:36 +02:00
|
|
|
//.map(res => res.json())
|
2019-02-14 11:15:44 +01:00
|
|
|
//.do(request => console.info("Insert Response:"+request) )
|
2019-06-03 15:20:36 +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
|
|
|
}
|
|
|
|
|
2019-07-23 14:23:12 +02:00
|
|
|
// getClaim(id:string, apiUrl:string):any {
|
|
|
|
// let url = apiUrl+"claims/"+id;
|
|
|
|
// return new Promise((resolve, reject) => {
|
|
|
|
// this.http.get(url)
|
|
|
|
// //.map(res => res.json())
|
|
|
|
// .subscribe(
|
|
|
|
// data => {
|
|
|
|
// resolve(data['data']);
|
|
|
|
// },
|
|
|
|
// err => {
|
|
|
|
// reject(err);
|
|
|
|
// }
|
|
|
|
// )
|
|
|
|
// ;
|
|
|
|
// });
|
|
|
|
// }
|
2017-12-19 13:53:46 +01:00
|
|
|
|
|
|
|
|
|
|
|
}
|