1 |
61381
|
k.triantaf
|
import {Injectable} from '@angular/core';
|
2 |
|
|
import {HttpClient, HttpErrorResponse} from "@angular/common/http";
|
3 |
|
|
import {throwError} from 'rxjs';
|
4 |
|
|
|
5 |
|
|
|
6 |
|
|
import { CustomOptions } from '../../services/servicesUtils/customOptions.class';
|
7 |
|
|
import {catchError} from "rxjs/operators";
|
8 |
|
|
|
9 |
|
|
@Injectable()
|
10 |
|
|
export class ClaimsByTokenService {
|
11 |
|
|
|
12 |
|
|
constructor(private http: HttpClient ) {}
|
13 |
|
|
|
14 |
|
|
getClaims(openaireId: string, apiURL:string):any {
|
15 |
|
|
|
16 |
|
|
//let url = apiURL+"project/claims?projectToken="+token;
|
17 |
|
|
let url = apiURL+"projects/"+openaireId+"/all_claims";
|
18 |
|
|
|
19 |
|
|
let key = url;
|
20 |
|
|
|
21 |
|
|
return this.http.get(url, CustomOptions.getAuthOptions());
|
22 |
|
|
//.map(res => <any> res.text())
|
23 |
|
|
//.map(request => <any> request.json());
|
24 |
|
|
|
25 |
|
|
}
|
26 |
|
|
|
27 |
|
|
|
28 |
|
|
/*
|
29 |
|
|
getClaims(email: string, token: string, user_token: string):any {
|
30 |
|
|
let url = OpenaireProperties.getClaimsAPIURL(); // What else?
|
31 |
|
|
let body = JSON.stringify( {"email": email, "token": token} );
|
32 |
|
|
console.warn('Json body: : '+body);
|
33 |
|
|
let headers = new Headers({ 'Content-Type': 'application/json' });
|
34 |
|
|
let options = new RequestOptions({ headers: headers });
|
35 |
|
|
return this.http.post(url, body, options)
|
36 |
|
|
.map(res => res.json())
|
37 |
|
|
.do(request => console.info("Insert Response:"+request.status) )
|
38 |
|
|
.catch(this.handleError);
|
39 |
|
|
}
|
40 |
|
|
*/
|
41 |
|
|
|
42 |
|
|
updateClaimsCuration( selectedRight: Set<string>, selectedWrong: Set<string>, apiURL:string) {
|
43 |
|
|
let url = apiURL + "curate/bulk";
|
44 |
|
|
let claimsCurationInfo: any = []; //e.g.: [{"id":"2","approved":true},{"id":"1","approved":true}]
|
45 |
|
|
|
46 |
|
|
selectedRight.forEach(function(selected) {
|
47 |
|
|
//console.info(selected);
|
48 |
|
|
let claimCurationInfo: {"id": string, "approved": boolean} = {"id": selected, "approved": true};
|
49 |
|
|
claimsCurationInfo.push(claimCurationInfo);
|
50 |
|
|
});
|
51 |
|
|
|
52 |
|
|
selectedWrong.forEach(function(selected) {
|
53 |
|
|
let claimCurationInfo: any = {"id": selected, "approved": false};
|
54 |
|
|
claimsCurationInfo.push(claimCurationInfo);
|
55 |
|
|
});
|
56 |
|
|
|
57 |
|
|
|
58 |
|
|
let body = JSON.stringify( claimsCurationInfo );
|
59 |
|
|
//console.warn('Json body: : '+body);
|
60 |
|
|
|
61 |
|
|
return this.http.post(url, body, CustomOptions.getAuthOptionsWithBody())
|
62 |
|
|
//.map(res => res.json())
|
63 |
|
|
//.do(request => console.info("Insert Response:"+request.status) )
|
64 |
|
|
.pipe(catchError(this.handleError));
|
65 |
|
|
}
|
66 |
|
|
|
67 |
|
|
|
68 |
|
|
updateClaimCuration( claimCurationInfo: {"id": string, "approved": boolean}, apiURL:string) {
|
69 |
|
|
let url = apiURL + "curate/bulk";
|
70 |
|
|
let claimsCurationInfo: any = []; //e.g.: [{"id":"2","approved":true},{"id":"1","approved":true}]
|
71 |
|
|
claimsCurationInfo.push(claimCurationInfo);
|
72 |
|
|
|
73 |
|
|
|
74 |
|
|
let body = JSON.stringify( claimsCurationInfo );
|
75 |
|
|
//console.warn('Json body: : '+body);
|
76 |
|
|
|
77 |
|
|
return this.http.post(url, body, CustomOptions.getAuthOptionsWithBody())
|
78 |
|
|
//.map(res => res.json())
|
79 |
|
|
.pipe(catchError(this.handleError));
|
80 |
|
|
}
|
81 |
|
|
|
82 |
|
|
private handleError (error: HttpErrorResponse) {
|
83 |
|
|
// in a real world app, we may send the error to some remote logging infrastructure
|
84 |
|
|
// instead of just logging it to the console
|
85 |
|
|
console.log(error);
|
86 |
|
|
return throwError(error || 'Server error');
|
87 |
|
|
//return Observable.throw(error || 'Server error');
|
88 |
|
|
}
|
89 |
|
|
}
|