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