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