1
|
package eu.dnetlib.uoaorcidservice.controllers;
|
2
|
|
3
|
import com.google.gson.Gson;
|
4
|
import com.google.gson.GsonBuilder;
|
5
|
import eu.dnetlib.uoaorcidservice.configuration.properties.OrcidConfig;
|
6
|
import eu.dnetlib.uoaorcidservice.entities.ResultIdAndWork;
|
7
|
import eu.dnetlib.uoaorcidservice.entities.UserTokens;
|
8
|
import eu.dnetlib.uoaorcidservice.entities.Work;
|
9
|
import eu.dnetlib.uoaorcidservice.handlers.ConflictException;
|
10
|
import eu.dnetlib.uoaorcidservice.handlers.ForbiddenException;
|
11
|
import eu.dnetlib.uoaorcidservice.services.UserTokensService;
|
12
|
import eu.dnetlib.uoaorcidservice.services.WorkService;
|
13
|
import org.apache.log4j.Logger;
|
14
|
import org.springframework.beans.factory.annotation.Autowired;
|
15
|
import org.springframework.data.util.Pair;
|
16
|
import org.springframework.http.*;
|
17
|
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
|
18
|
import org.springframework.security.access.AccessDeniedException;
|
19
|
import org.springframework.security.access.AuthorizationServiceException;
|
20
|
import org.springframework.security.access.prepost.PreAuthorize;
|
21
|
import org.springframework.web.bind.annotation.*;
|
22
|
import org.springframework.web.client.DefaultResponseErrorHandler;
|
23
|
import org.springframework.web.client.RestTemplate;
|
24
|
import org.springframework.web.util.UriComponentsBuilder;
|
25
|
|
26
|
import javax.crypto.BadPaddingException;
|
27
|
import javax.crypto.IllegalBlockSizeException;
|
28
|
import javax.crypto.NoSuchPaddingException;
|
29
|
import java.io.IOException;
|
30
|
import java.security.InvalidAlgorithmParameterException;
|
31
|
import java.security.InvalidKeyException;
|
32
|
import java.security.NoSuchAlgorithmException;
|
33
|
import java.security.spec.InvalidKeySpecException;
|
34
|
import java.util.*;
|
35
|
|
36
|
@RestController
|
37
|
//@RequestMapping("/orcid")
|
38
|
@PreAuthorize("isAuthenticated()")
|
39
|
@CrossOrigin(origins = "*")
|
40
|
public class WorkController {
|
41
|
private final Logger log = Logger.getLogger(this.getClass());
|
42
|
private final Logger orcid_log = Logger.getLogger("ORCID-"+this.getClass().getName());
|
43
|
|
44
|
@Autowired
|
45
|
private OrcidConfig orcidConfig;
|
46
|
|
47
|
@Autowired
|
48
|
private UserTokensService userTokensService;
|
49
|
|
50
|
@Autowired
|
51
|
private WorkService workService;
|
52
|
|
53
|
@RequestMapping(value = "/local/put-code", method = RequestMethod.GET)
|
54
|
public List<String> getPutCode(@RequestParam String[] pids) {
|
55
|
String userOrcid = userTokensService.getCurrentUserOrcid();
|
56
|
List<Work> works = workService.getWorks(pids, userOrcid);
|
57
|
if(works != null) {
|
58
|
List<String> putCodes = new ArrayList<>();
|
59
|
for(Work work : works) {
|
60
|
putCodes.add(work.getPutCode());
|
61
|
}
|
62
|
return putCodes;
|
63
|
}
|
64
|
return null;
|
65
|
}
|
66
|
|
67
|
@RequestMapping(value = "/local/put-codes", method = RequestMethod.POST)
|
68
|
public List<List<String>> getPutCodes(@RequestBody String[][] pids) {
|
69
|
String userOrcid = userTokensService.getCurrentUserOrcid();
|
70
|
List<List<String>> putCodes = new ArrayList();
|
71
|
for(int i=0; i<pids.length; i++) {
|
72
|
List<Work> works = workService.getWorks(pids[i], userOrcid);
|
73
|
if (works != null) {
|
74
|
List<String> putCodesOfOneRecord = new ArrayList<>();
|
75
|
for(Work work : works) {
|
76
|
putCodesOfOneRecord.add(work.getPutCode());
|
77
|
}
|
78
|
putCodes.add(putCodesOfOneRecord);
|
79
|
} else {
|
80
|
putCodes.add(null);
|
81
|
}
|
82
|
}
|
83
|
return putCodes;
|
84
|
}
|
85
|
|
86
|
@RequestMapping(value = "/local/works", method = RequestMethod.POST)
|
87
|
public List<List<Work>> getLocalWorks(@RequestBody String[][] pids) {
|
88
|
String userOrcid = userTokensService.getCurrentUserOrcid();
|
89
|
if(userOrcid == null) {
|
90
|
throw new AuthorizationServiceException("User is not registered");
|
91
|
}
|
92
|
|
93
|
List<List<Work>> returnedWorks = new ArrayList();
|
94
|
for(int i=0; i<pids.length; i++) {
|
95
|
List<Work> works = workService.getWorks(pids[i], userOrcid);
|
96
|
returnedWorks.add(works);
|
97
|
}
|
98
|
return returnedWorks;
|
99
|
}
|
100
|
|
101
|
@RequestMapping(value = "/orcid/work/save", method = RequestMethod.POST)
|
102
|
public Work saveWork(@RequestBody String resultString) throws Exception {
|
103
|
log.debug("saveWork: result = " + resultString);
|
104
|
|
105
|
Gson gson = new GsonBuilder().create();
|
106
|
ResultIdAndWork result = gson.fromJson(resultString, ResultIdAndWork.class);
|
107
|
|
108
|
UserTokens userTokens = userTokensService.getUserTokens();
|
109
|
if(userTokens == null) {
|
110
|
throw new AuthorizationServiceException("User is not registered");
|
111
|
}
|
112
|
String userOrcid = userTokens.getOrcid();
|
113
|
String userAccessToken = userTokens.getAccessToken();
|
114
|
|
115
|
if(userOrcid == null || userAccessToken == null) {
|
116
|
throw new AuthorizationServiceException("User is not registered");
|
117
|
}
|
118
|
|
119
|
// log.debug("Access token: " + userAccessToken);
|
120
|
// log.debug("User orcid: " + userOrcid);
|
121
|
|
122
|
String url = orcidConfig.getApiURL() + userOrcid + "/work";
|
123
|
|
124
|
RestTemplate restTemplate = new RestTemplate();
|
125
|
// restTemplate.setRequestFactory(new HttpComponentsClientHttpRequestFactory());
|
126
|
|
127
|
restTemplate.setErrorHandler(new DefaultResponseErrorHandler() {
|
128
|
protected boolean hasError(HttpStatus statusCode) {
|
129
|
if(statusCode == HttpStatus.UNAUTHORIZED) {
|
130
|
orcid_log.error("ORCID service returned UNAUTHORIZED: "+HttpStatus.UNAUTHORIZED);
|
131
|
throw new AuthorizationServiceException("User is not registered");
|
132
|
}
|
133
|
return false;
|
134
|
}
|
135
|
});
|
136
|
HttpHeaders headers = new HttpHeaders();
|
137
|
headers.add("Authorization", "Bearer " + userAccessToken);
|
138
|
headers.add("Content-Type", "application/orcid+json;charset=UTF-8");
|
139
|
|
140
|
HttpEntity<String> request = new HttpEntity<>(gson.toJson(result.getWork()), headers);
|
141
|
|
142
|
orcid_log.info("request: "+request);
|
143
|
orcid_log.info("url: "+url);
|
144
|
ResponseEntity<String> response = restTemplate.exchange(url, HttpMethod.POST, request, String.class);
|
145
|
|
146
|
if (response.getStatusCode() != HttpStatus.CREATED) {
|
147
|
orcid_log.error("Saving work response code is: " + response.getStatusCode());
|
148
|
orcid_log.error("Unexpected Response: "+response.getBody());
|
149
|
|
150
|
if(response.getStatusCode() == HttpStatus.UNAUTHORIZED) {
|
151
|
throw new AuthorizationServiceException("You are not allowed to save work");
|
152
|
} else if(response.getStatusCode() == HttpStatus.CONFLICT) {
|
153
|
throw new ConflictException("Work is already saved");
|
154
|
} else {
|
155
|
throw new Exception("Internal server error");
|
156
|
}
|
157
|
// return null;
|
158
|
} else {
|
159
|
orcid_log.info("Response: "+response);
|
160
|
// log.debug("[success] Saving work response code is: " + response.getStatusCode());
|
161
|
// log.debug(response.toString());
|
162
|
|
163
|
Date date = new Date();
|
164
|
|
165
|
Work workToSave = new Work();
|
166
|
workToSave.setPids(result.getPids());
|
167
|
workToSave.setOrcid(userOrcid);
|
168
|
workToSave.setCreationDate(date);
|
169
|
workToSave.setUpdateDate(date);
|
170
|
|
171
|
HttpHeaders responseHeaders = response.getHeaders();
|
172
|
String locationPath = responseHeaders.getLocation().toString();
|
173
|
String[] locationPathArray = locationPath.split("/");
|
174
|
workToSave.setPutCode(locationPathArray[locationPathArray.length - 1]);
|
175
|
|
176
|
// log.debug(gson.toJson(result.getPids()));
|
177
|
// log.debug(responseHeaders.getLocation().toString());
|
178
|
// log.debug(gson.toJson(workToSave));
|
179
|
|
180
|
workService.saveWork(workToSave);
|
181
|
|
182
|
return workToSave;
|
183
|
// return "\""+workToSave.getPutCode()+"\"";
|
184
|
}
|
185
|
}
|
186
|
|
187
|
@RequestMapping(value = "/orcid/work/update/{putCode}", method = RequestMethod.POST)
|
188
|
public Work updateWork(@PathVariable String putCode,
|
189
|
@RequestBody String resultString) throws Exception {
|
190
|
log.debug("updateWork: putCode = " + putCode);
|
191
|
|
192
|
Gson gson = new GsonBuilder().create();
|
193
|
ResultIdAndWork result = gson.fromJson(resultString, ResultIdAndWork.class);
|
194
|
|
195
|
UserTokens userTokens = userTokensService.getUserTokens();
|
196
|
if(userTokens == null) {
|
197
|
throw new AuthorizationServiceException("User is not registered");
|
198
|
}
|
199
|
String userOrcid = userTokens.getOrcid();
|
200
|
String userAccessToken = userTokens.getAccessToken();
|
201
|
|
202
|
if(userOrcid == null || userAccessToken == null) {
|
203
|
throw new AuthorizationServiceException("User is not registered");
|
204
|
}
|
205
|
|
206
|
// log.debug("Access token: " + userAccessToken);
|
207
|
// log.debug("User orcid: " + userOrcid);
|
208
|
|
209
|
// String url = "https://sandbox.orcid.org/v3.0/" + orcid.toString() + "/works";
|
210
|
// String url = "https://api.sandbox.orcid.org/v3.0/" + userOrcid + "/work/" + putCode;
|
211
|
String url = orcidConfig.getApiURL() + userOrcid + "/work/" + putCode;
|
212
|
|
213
|
RestTemplate restTemplate = new RestTemplate();
|
214
|
restTemplate.setErrorHandler(new DefaultResponseErrorHandler() {
|
215
|
protected boolean hasError(HttpStatus statusCode) {
|
216
|
return false;
|
217
|
}
|
218
|
});
|
219
|
HttpHeaders headers = new HttpHeaders();
|
220
|
// headers.add("Accept", "application/json");
|
221
|
headers.add("Authorization", "Bearer " + userAccessToken);
|
222
|
headers.add("Content-Type", "application/orcid+json;charset=UTF-8");
|
223
|
|
224
|
HttpEntity<String> request = new HttpEntity<>(gson.toJson(result.getWork()), headers);
|
225
|
orcid_log.info("request: "+request);
|
226
|
orcid_log.info("url: "+url);
|
227
|
|
228
|
ResponseEntity<String> response = restTemplate.exchange(url, HttpMethod.PUT, request, String.class);
|
229
|
if (response.getStatusCode() != HttpStatus.OK) {
|
230
|
orcid_log.error("Updating work response code is: " + response.getStatusCode());
|
231
|
orcid_log.error("Unexpected Response: "+response.getBody());
|
232
|
|
233
|
if(response.getStatusCode() == HttpStatus.UNAUTHORIZED) {
|
234
|
throw new AuthorizationServiceException("You are not allowed to update work");
|
235
|
} else if(response.getStatusCode() == HttpStatus.CONFLICT) {
|
236
|
throw new ConflictException("Work is already saved");
|
237
|
} else {
|
238
|
throw new Exception("Internal server error");
|
239
|
}
|
240
|
// return null;
|
241
|
} else {
|
242
|
orcid_log.info("Response: "+response);
|
243
|
Date date = new Date();
|
244
|
|
245
|
Work localWork = workService.getLocalWorkByPutCode(putCode);
|
246
|
localWork.setPids(result.getPids());
|
247
|
localWork.setUpdateDate(date);
|
248
|
|
249
|
workService.saveWork(localWork);
|
250
|
return localWork;
|
251
|
// return null;
|
252
|
}
|
253
|
|
254
|
}
|
255
|
|
256
|
@RequestMapping(value = "/orcid/works", method = RequestMethod.GET)
|
257
|
public String getWorksByPutCodes(@RequestParam String put_codes) throws BadPaddingException, InvalidKeyException, NoSuchAlgorithmException, IllegalBlockSizeException, IOException, NoSuchPaddingException, InvalidAlgorithmParameterException, InvalidKeySpecException {
|
258
|
log.debug("getWorksByPutCodes: put_codes = " + put_codes);
|
259
|
|
260
|
UserTokens userTokens = userTokensService.getUserTokens();
|
261
|
if(userTokens == null) {
|
262
|
throw new AuthorizationServiceException("User is not registered");
|
263
|
}
|
264
|
String userOrcid = userTokens.getOrcid();
|
265
|
String userAccessToken = userTokens.getAccessToken();
|
266
|
|
267
|
if(userOrcid == null || userAccessToken == null) {
|
268
|
throw new AuthorizationServiceException("User is not registered");
|
269
|
}
|
270
|
|
271
|
// log.debug("Access token: " + userAccessToken);
|
272
|
// log.debug("User orcid: " + userOrcid);
|
273
|
|
274
|
// String url = "https://sandbox.orcid.org/v3.0/" + orcid.toString() + "/works";
|
275
|
String url = orcidConfig.getApiURL()+userOrcid+"/works/"+put_codes;
|
276
|
|
277
|
RestTemplate restTemplate = new RestTemplate();
|
278
|
restTemplate.setErrorHandler(new DefaultResponseErrorHandler() {
|
279
|
protected boolean hasError(HttpStatus statusCode) {
|
280
|
return false;
|
281
|
}
|
282
|
});
|
283
|
HttpHeaders headers = new HttpHeaders();
|
284
|
headers.add("Accept", "application/json");
|
285
|
headers.add("Authorization", "Bearer " + userAccessToken);
|
286
|
headers.add("Content-Type", "application/orcid+json;charset=UTF-8");
|
287
|
|
288
|
HttpEntity<String> request = new HttpEntity<>(headers);
|
289
|
orcid_log.info("request: "+request);
|
290
|
orcid_log.info("url: "+url);
|
291
|
|
292
|
ResponseEntity<String> response = restTemplate.exchange(url, HttpMethod.GET, request, String.class);
|
293
|
if (response.getStatusCode() != HttpStatus.OK) {
|
294
|
orcid_log.error("Getting works response code is: " + response.getStatusCode());
|
295
|
orcid_log.error("Unexpected Response: "+response.getBody());
|
296
|
return null;
|
297
|
} else {
|
298
|
orcid_log.info("Response: "+response);
|
299
|
return response.getBody().toString();
|
300
|
}
|
301
|
}
|
302
|
|
303
|
@RequestMapping(value = "/orcid/work/{putCode}/delete", method = RequestMethod.DELETE)
|
304
|
public String deleteWork(@PathVariable String putCode) throws IOException, BadPaddingException, InvalidKeyException, NoSuchAlgorithmException, IllegalBlockSizeException, NoSuchPaddingException, InvalidAlgorithmParameterException, InvalidKeySpecException {
|
305
|
log.debug("deleteWork: putCode = " + putCode);
|
306
|
|
307
|
UserTokens userTokens = userTokensService.getUserTokens();
|
308
|
if(userTokens == null) {
|
309
|
throw new AuthorizationServiceException("User is not registered");
|
310
|
}
|
311
|
String userOrcid = userTokens.getOrcid();
|
312
|
String userAccessToken = userTokens.getAccessToken();
|
313
|
|
314
|
if(userOrcid == null || userAccessToken == null) {
|
315
|
throw new AuthorizationServiceException("User is not registered");
|
316
|
}
|
317
|
|
318
|
// log.debug("Access token: " + userAccessToken);
|
319
|
// log.debug("User orcid: " + userOrcid);
|
320
|
|
321
|
String url = orcidConfig.getApiURL()+userOrcid+"/work/" + putCode;
|
322
|
|
323
|
RestTemplate restTemplate = new RestTemplate();
|
324
|
restTemplate.setErrorHandler(new DefaultResponseErrorHandler() {
|
325
|
protected boolean hasError(HttpStatus statusCode) {
|
326
|
return false;
|
327
|
}
|
328
|
});
|
329
|
HttpHeaders headers = new HttpHeaders();
|
330
|
// headers.add("Accept", "application/json");
|
331
|
headers.add("Authorization", "Bearer " + userAccessToken);
|
332
|
headers.add("Content-Type", "application/orcid+json;charset=UTF-8");
|
333
|
|
334
|
HttpEntity<String> request = new HttpEntity<>(headers);
|
335
|
orcid_log.info("request: "+request);
|
336
|
orcid_log.info("url: "+url);
|
337
|
|
338
|
ResponseEntity<String> response = restTemplate.exchange(url, HttpMethod.DELETE, request, String.class);
|
339
|
if (response.getStatusCode() != HttpStatus.NO_CONTENT) {
|
340
|
orcid_log.error("Deleting work response code is: " + response.getStatusCode());
|
341
|
orcid_log.error("Unexpected Response: "+response.getBody());
|
342
|
|
343
|
if(response.getStatusCode() == HttpStatus.NOT_FOUND) {
|
344
|
workService.deleteWork(putCode);
|
345
|
return putCode;
|
346
|
}
|
347
|
if(response.getStatusCode() == HttpStatus.UNAUTHORIZED) {
|
348
|
throw new AuthorizationServiceException("You are not allowed to delete work");
|
349
|
}
|
350
|
return null;
|
351
|
} else {
|
352
|
orcid_log.info("Response: "+response);
|
353
|
|
354
|
workService.deleteWork(putCode);
|
355
|
|
356
|
return putCode;
|
357
|
}
|
358
|
|
359
|
}
|
360
|
|
361
|
@RequestMapping(value = "/orcid/works/delete", method = RequestMethod.POST)
|
362
|
public List<String> deleteWorks(@RequestBody List<String> putCodes) throws IOException, BadPaddingException, InvalidKeyException, NoSuchAlgorithmException, IllegalBlockSizeException, NoSuchPaddingException, InvalidAlgorithmParameterException, InvalidKeySpecException {
|
363
|
log.debug("deleteWorks: putCodes = " + putCodes);
|
364
|
|
365
|
UserTokens userTokens = userTokensService.getUserTokens();
|
366
|
if(userTokens == null) {
|
367
|
throw new AuthorizationServiceException("User is not registered");
|
368
|
}
|
369
|
String userOrcid = userTokens.getOrcid();
|
370
|
String userAccessToken = userTokens.getAccessToken();
|
371
|
|
372
|
if(userOrcid == null || userAccessToken == null) {
|
373
|
throw new AuthorizationServiceException("User is not registered");
|
374
|
}
|
375
|
|
376
|
// log.debug("Access token: " + userAccessToken);
|
377
|
// log.debug("User orcid: " + userOrcid);
|
378
|
|
379
|
RestTemplate restTemplate = new RestTemplate();
|
380
|
restTemplate.setErrorHandler(new DefaultResponseErrorHandler() {
|
381
|
protected boolean hasError(HttpStatus statusCode) {
|
382
|
return false;
|
383
|
}
|
384
|
});
|
385
|
HttpHeaders headers = new HttpHeaders();
|
386
|
// headers.add("Accept", "application/json");
|
387
|
headers.add("Authorization", "Bearer " + userAccessToken);
|
388
|
headers.add("Content-Type", "application/orcid+json;charset=UTF-8");
|
389
|
|
390
|
HttpEntity<String> request = new HttpEntity<>(headers);
|
391
|
|
392
|
List<String> deletedPutCodes = new ArrayList<>();
|
393
|
int index = 0;
|
394
|
for(String putCode : putCodes) {
|
395
|
String url = orcidConfig.getApiURL()+userOrcid+"/work/" + putCode;
|
396
|
// UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(url);
|
397
|
|
398
|
orcid_log.info("request: "+request);
|
399
|
orcid_log.info("url: "+url);
|
400
|
|
401
|
ResponseEntity<String> response = restTemplate.exchange(url, HttpMethod.DELETE, request, String.class);
|
402
|
if (response.getStatusCode() != HttpStatus.NO_CONTENT) {
|
403
|
orcid_log.error("Deleting work response code is: " + response.getStatusCode());
|
404
|
orcid_log.error("Unexpected Response: "+response.getBody());
|
405
|
|
406
|
if(index == 0 && response.getStatusCode() == HttpStatus.UNAUTHORIZED) {
|
407
|
throw new AuthorizationServiceException("You are not allowed to delete work");
|
408
|
}
|
409
|
if (response.getStatusCode() == HttpStatus.NOT_FOUND) {
|
410
|
workService.deleteWork(putCode);
|
411
|
deletedPutCodes.add(putCode);
|
412
|
} else {
|
413
|
deletedPutCodes.add(null);
|
414
|
}
|
415
|
} else {
|
416
|
orcid_log.info("Response: "+response);
|
417
|
|
418
|
workService.deleteWork(putCode);
|
419
|
|
420
|
deletedPutCodes.add(putCode);
|
421
|
}
|
422
|
index++;
|
423
|
}
|
424
|
return deletedPutCodes;
|
425
|
}
|
426
|
|
427
|
@RequestMapping(value = "/orcid/work", method = RequestMethod.GET)
|
428
|
public List<String> getWorksOfReuslt(@RequestParam String[] pids, @RequestParam String orcid) throws BadPaddingException, InvalidKeyException, NoSuchAlgorithmException, IllegalBlockSizeException, NoSuchPaddingException, InvalidAlgorithmParameterException, InvalidKeySpecException, IOException {
|
429
|
log.debug("getWorks: pids = " + pids + " - orcid = "+orcid);
|
430
|
|
431
|
List<Work> works = workService.getWorks(pids, orcid);
|
432
|
|
433
|
String userAccessToken = userTokensService.getUserAccessToken(orcid);
|
434
|
// log.debug("Access token: " + userAccessToken);
|
435
|
|
436
|
RestTemplate restTemplate = new RestTemplate();
|
437
|
restTemplate.setErrorHandler(new DefaultResponseErrorHandler() {
|
438
|
protected boolean hasError(HttpStatus statusCode) {
|
439
|
return false;
|
440
|
}
|
441
|
});
|
442
|
HttpHeaders headers = new HttpHeaders();
|
443
|
headers.add("Accept", "application/json");
|
444
|
headers.add("Authorization", "Bearer " + userAccessToken);
|
445
|
headers.add("Content-Type", "application/orcid+json;charset=UTF-8");
|
446
|
|
447
|
HttpEntity<String> request = new HttpEntity<>(headers);
|
448
|
|
449
|
List<String> responseValues = new ArrayList<>();
|
450
|
|
451
|
for(Work work : works) {
|
452
|
String url = orcidConfig.getApiURL() + orcid + "/work/" + work.getPutCode();
|
453
|
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(url);
|
454
|
orcid_log.info("request: "+request);
|
455
|
orcid_log.info("url: "+url);
|
456
|
|
457
|
ResponseEntity<String> response = restTemplate.exchange(builder.toUriString(), HttpMethod.GET, request, String.class);
|
458
|
if (response.getStatusCode() != HttpStatus.OK) {
|
459
|
orcid_log.error("Getting work response code is: " + response.getStatusCode());
|
460
|
orcid_log.error("Unexpected Response: "+response.getBody());
|
461
|
|
462
|
if (response.getStatusCode() == HttpStatus.NOT_FOUND) {
|
463
|
// work.setPutCode(null);
|
464
|
// workService.saveWork(work);
|
465
|
workService.deleteWork(work.getPutCode());
|
466
|
}
|
467
|
|
468
|
responseValues.add(null);
|
469
|
} else {
|
470
|
orcid_log.info("Response: "+response);
|
471
|
responseValues.add(response.getBody().toString());
|
472
|
}
|
473
|
}
|
474
|
return responseValues;
|
475
|
}
|
476
|
|
477
|
// @PreAuthorize("isAuthenticated()")
|
478
|
// @RequestMapping(value = "/local/works", method = RequestMethod.GET)
|
479
|
// public Map<String, Object> getLocalWorks(@RequestParam(required = false) Integer page, @RequestParam(required = false) Integer size)
|
480
|
// throws BadPaddingException, InvalidKeyException, NoSuchAlgorithmException, IllegalBlockSizeException, NoSuchPaddingException, InvalidAlgorithmParameterException, InvalidKeySpecException, IOException {
|
481
|
// log.debug("getWorks: page="+page+ " - size="+size);
|
482
|
//
|
483
|
// String userOrcid = userTokensService.getCurrentUserOrcid();
|
484
|
// if(userOrcid == null) {
|
485
|
// throw new AuthorizationServiceException("User is not registered");
|
486
|
// }
|
487
|
//
|
488
|
// List<Work> works = workService.getLocalWorks(userOrcid);
|
489
|
//
|
490
|
// Map<String, Object> response = new HashMap<>();
|
491
|
// response.put("total", works.size());
|
492
|
//
|
493
|
// if(page != null && page > 0 && size != null && size > 0) {
|
494
|
// int from = (page-1)*size;
|
495
|
// int to = page*size;
|
496
|
//
|
497
|
//// log.debug("size: "+works.size());
|
498
|
// if(to > works.size()) {
|
499
|
// to = works.size();
|
500
|
// }
|
501
|
//// log.debug("from="+from+" - to="+to);
|
502
|
//
|
503
|
//// int index = 0;
|
504
|
//// Iterator<Work> iterator = works.iterator();
|
505
|
//// while(iterator.hasNext()) {
|
506
|
//// iterator.next();
|
507
|
//// if(index < from || index > to) {
|
508
|
//// iterator.remove();
|
509
|
//// }
|
510
|
//// index++;
|
511
|
//// }
|
512
|
// if(from < to) {
|
513
|
// response.put("results", works.subList(from, to));
|
514
|
// return response;
|
515
|
// }
|
516
|
// }
|
517
|
// response.put("results", works);
|
518
|
// return response;
|
519
|
// }
|
520
|
|
521
|
@RequestMapping(value = "/local/works", method = RequestMethod.GET)
|
522
|
public List<Work> getMyLocalWorks() {
|
523
|
log.debug("getMyWorks");
|
524
|
//
|
525
|
String userOrcid = userTokensService.getCurrentUserOrcid();
|
526
|
if(userOrcid == null) {
|
527
|
throw new AuthorizationServiceException("User is not registered");
|
528
|
}
|
529
|
//
|
530
|
List<Work> works = workService.getLocalWorks(userOrcid);
|
531
|
//
|
532
|
return works;
|
533
|
}
|
534
|
}
|