487 lines
22 KiB
Java
487 lines
22 KiB
Java
|
package eu.dnetlib.uoaorcidservice.controllers;
|
||
|
|
||
|
import com.google.gson.Gson;
|
||
|
import com.google.gson.GsonBuilder;
|
||
|
import eu.dnetlib.uoaorcidservice.entities.ResultIdAndWork;
|
||
|
import eu.dnetlib.uoaorcidservice.entities.UserTokens;
|
||
|
import eu.dnetlib.uoaorcidservice.entities.Work;
|
||
|
import eu.dnetlib.uoaorcidservice.handlers.ConflictException;
|
||
|
import eu.dnetlib.uoaorcidservice.handlers.ForbiddenException;
|
||
|
import eu.dnetlib.uoaorcidservice.services.UserTokensService;
|
||
|
import eu.dnetlib.uoaorcidservice.services.WorkService;
|
||
|
import org.apache.log4j.Logger;
|
||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||
|
import org.springframework.http.*;
|
||
|
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
|
||
|
import org.springframework.security.access.AuthorizationServiceException;
|
||
|
import org.springframework.security.access.prepost.PreAuthorize;
|
||
|
import org.springframework.web.bind.annotation.*;
|
||
|
import org.springframework.web.client.DefaultResponseErrorHandler;
|
||
|
import org.springframework.web.client.RestTemplate;
|
||
|
import org.springframework.web.util.UriComponentsBuilder;
|
||
|
|
||
|
import javax.crypto.BadPaddingException;
|
||
|
import javax.crypto.IllegalBlockSizeException;
|
||
|
import javax.crypto.NoSuchPaddingException;
|
||
|
import java.io.IOException;
|
||
|
import java.security.InvalidAlgorithmParameterException;
|
||
|
import java.security.InvalidKeyException;
|
||
|
import java.security.NoSuchAlgorithmException;
|
||
|
import java.security.spec.InvalidKeySpecException;
|
||
|
import java.util.ArrayList;
|
||
|
import java.util.Date;
|
||
|
import java.util.List;
|
||
|
|
||
|
@RestController
|
||
|
@RequestMapping("/orcid")
|
||
|
@CrossOrigin(origins = "*")
|
||
|
public class WorkController {
|
||
|
private final Logger log = Logger.getLogger(this.getClass());
|
||
|
|
||
|
@Autowired
|
||
|
private UserTokensService userTokensService;
|
||
|
|
||
|
@Autowired
|
||
|
private WorkService workService;
|
||
|
|
||
|
@PreAuthorize("isAuthenticated()")
|
||
|
@RequestMapping(value = "put-code", method = RequestMethod.GET)
|
||
|
public List<String> getPutCode(@RequestParam String[] pids) {
|
||
|
String userOrcid = userTokensService.getCurrentUserOrcid();
|
||
|
List<Work> works = workService.getWorks(pids, userOrcid);
|
||
|
if(works != null) {
|
||
|
List<String> putCodes = new ArrayList<>();
|
||
|
for(Work work : works) {
|
||
|
putCodes.add(work.getPutCode());
|
||
|
}
|
||
|
return putCodes;
|
||
|
}
|
||
|
return null;
|
||
|
}
|
||
|
|
||
|
@PreAuthorize("isAuthenticated()")
|
||
|
@RequestMapping(value = "put-codes", method = RequestMethod.POST)
|
||
|
public List<List<String>> getPutCodes(@RequestBody String[][] pids) {
|
||
|
String userOrcid = userTokensService.getCurrentUserOrcid();
|
||
|
List<List<String>> putCodes = new ArrayList();
|
||
|
for(int i=0; i<pids.length; i++) {
|
||
|
List<Work> works = workService.getWorks(pids[i], userOrcid);
|
||
|
if (works != null) {
|
||
|
List<String> putCodesOfOneRecord = new ArrayList<>();
|
||
|
for(Work work : works) {
|
||
|
putCodesOfOneRecord.add(work.getPutCode());
|
||
|
}
|
||
|
putCodes.add(putCodesOfOneRecord);
|
||
|
} else {
|
||
|
putCodes.add(null);
|
||
|
}
|
||
|
}
|
||
|
return putCodes;
|
||
|
}
|
||
|
|
||
|
@PreAuthorize("isAuthenticated()")
|
||
|
@RequestMapping(value = "/work/save", method = RequestMethod.POST)
|
||
|
public String saveWork(@RequestBody String resultString) throws IOException, BadPaddingException, InvalidKeyException, NoSuchAlgorithmException, IllegalBlockSizeException, NoSuchPaddingException, InvalidAlgorithmParameterException, InvalidKeySpecException {
|
||
|
log.debug("saveWork: result = " + resultString);
|
||
|
|
||
|
Gson gson = new GsonBuilder().create();
|
||
|
ResultIdAndWork result = gson.fromJson(resultString, ResultIdAndWork.class);
|
||
|
|
||
|
UserTokens userTokens = userTokensService.getUserTokens();
|
||
|
if(userTokens == null) {
|
||
|
throw new AuthorizationServiceException("User is not registered");
|
||
|
}
|
||
|
String userOrcid = userTokens.getOrcid();
|
||
|
String userAccessToken = userTokens.getAccessToken();
|
||
|
|
||
|
if(userOrcid == null || userAccessToken == null) {
|
||
|
throw new AuthorizationServiceException("User is not registered");
|
||
|
}
|
||
|
|
||
|
log.debug("Access token: " + userAccessToken);
|
||
|
log.debug("User orcid: " + userOrcid);
|
||
|
|
||
|
String url = "https://api.sandbox.orcid.org/v3.0/" + userOrcid + "/work";
|
||
|
|
||
|
RestTemplate restTemplate = new RestTemplate();
|
||
|
// restTemplate.setRequestFactory(new HttpComponentsClientHttpRequestFactory());
|
||
|
|
||
|
restTemplate.setErrorHandler(new DefaultResponseErrorHandler() {
|
||
|
protected boolean hasError(HttpStatus statusCode) {
|
||
|
if(statusCode == HttpStatus.UNAUTHORIZED) {
|
||
|
throw new AuthorizationServiceException("User is not registered");
|
||
|
}
|
||
|
return false;
|
||
|
}
|
||
|
});
|
||
|
HttpHeaders headers = new HttpHeaders();
|
||
|
headers.add("Authorization", "Bearer " + userAccessToken);
|
||
|
headers.add("Content-Type", "application/orcid+json;charset=UTF-8");
|
||
|
log.debug(headers.get("Authorization"));
|
||
|
|
||
|
HttpEntity<String> request = new HttpEntity<>(gson.toJson(result.getWork()), headers);
|
||
|
//logger.info(restTemplate.exchange(fooResourceUrl, HttpMethod.GET, request, Object.class));
|
||
|
|
||
|
ResponseEntity<String> response = restTemplate.exchange(url, HttpMethod.POST, request, String.class);
|
||
|
if (response.getStatusCode() != HttpStatus.CREATED) {
|
||
|
log.debug("Saving work response code is: " + response.getStatusCode());
|
||
|
log.debug(response.getBody());
|
||
|
if(response.getStatusCode() == HttpStatus.UNAUTHORIZED) {
|
||
|
throw new AuthorizationServiceException("You are not allowed to save work");
|
||
|
}
|
||
|
if(response.getStatusCode() == HttpStatus.CONFLICT) {
|
||
|
throw new ConflictException("Work is already saved");
|
||
|
}
|
||
|
return null;
|
||
|
} else {
|
||
|
|
||
|
log.debug("[success] Saving work response code is: " + response.getStatusCode());
|
||
|
log.debug(response.toString());
|
||
|
|
||
|
Work workToSave = new Work();
|
||
|
workToSave.setPids(result.getPids());
|
||
|
workToSave.setOrcid(userOrcid);
|
||
|
workToSave.setCreationDate(new Date());
|
||
|
|
||
|
HttpHeaders responseHeaders = response.getHeaders();
|
||
|
String locationPath = responseHeaders.getLocation().toString();
|
||
|
String[] locationPathArray = locationPath.split("/");
|
||
|
workToSave.setPutCode(locationPathArray[locationPathArray.length - 1]);
|
||
|
|
||
|
log.debug(gson.toJson(result.getPids()));
|
||
|
log.debug(responseHeaders.getLocation().toString());
|
||
|
log.debug(gson.toJson(workToSave));
|
||
|
|
||
|
workService.saveWork(workToSave);
|
||
|
|
||
|
return "\""+workToSave.getPutCode()+"\"";
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// @RequestMapping(value = "/{orcid}/work/{putCode}", method = RequestMethod.PUT)
|
||
|
// public String updateWork(@PathVariable String orcid,
|
||
|
// @PathVariable String putCode,
|
||
|
// @RequestBody String work) throws AccessDeniedException {
|
||
|
// log.debug("updateWork: orcid = " + orcid + " - putCode = " + putCode);
|
||
|
//
|
||
|
// String userAccessToken = userTokensService.getUserAccessToken(orcid);
|
||
|
// log.debug("Access token: " + userAccessToken);
|
||
|
//
|
||
|
//// String url = "https://sandbox.orcid.org/v3.0/" + orcid.toString() + "/works";
|
||
|
// String url = "https://api.sandbox.orcid.org/v3.0/" + orcid + "/work/" + putCode;
|
||
|
//
|
||
|
// RestTemplate restTemplate = new RestTemplate();
|
||
|
// restTemplate.setErrorHandler(new DefaultResponseErrorHandler() {
|
||
|
// protected boolean hasError(HttpStatus statusCode) {
|
||
|
// return false;
|
||
|
// }
|
||
|
// });
|
||
|
// HttpHeaders headers = new HttpHeaders();
|
||
|
//// headers.add("Accept", "application/json");
|
||
|
// headers.add("Authorization", "Bearer " + userAccessToken);
|
||
|
// headers.add("Content-Type","application/orcid+json");
|
||
|
//
|
||
|
// HttpEntity<String> request = new HttpEntity<>(work, headers);
|
||
|
// //logger.info(restTemplate.exchange(fooResourceUrl, HttpMethod.GET, request, Object.class));
|
||
|
// ResponseEntity<String> response = restTemplate.exchange(url, HttpMethod.PUT, request, String.class);
|
||
|
// if (response.getStatusCode() != HttpStatus.OK) {
|
||
|
// log.debug("Updating work response code is: " + response.getStatusCode());
|
||
|
// return null;
|
||
|
// } else {
|
||
|
// log.debug(response);
|
||
|
//
|
||
|
// return null;
|
||
|
// }
|
||
|
//
|
||
|
// }
|
||
|
|
||
|
// @RequestMapping(value = "/works/save", method = RequestMethod.POST)
|
||
|
// public String saveWorks(@RequestBody String works) {
|
||
|
// log.debug("saveWorks");
|
||
|
//
|
||
|
// String userAccessToken = userTokensService.getUserAccessToken(null);
|
||
|
// log.debug("Access token: " + userAccessToken);
|
||
|
// log.debug(works);
|
||
|
//
|
||
|
// String url = "https://api.sandbox.orcid.org/v3.0/0000-0001-9541-4617/work";
|
||
|
//
|
||
|
// RestTemplate restTemplate = new RestTemplate();
|
||
|
// restTemplate.setErrorHandler(new DefaultResponseErrorHandler() {
|
||
|
// protected boolean hasError(HttpStatus statusCode) {
|
||
|
// return false;
|
||
|
// }
|
||
|
// });
|
||
|
// HttpHeaders headers = new HttpHeaders();
|
||
|
// headers.add("Authorization", "Bearer " + userAccessToken);
|
||
|
// headers.add("Content-Type", "application/json");
|
||
|
//// List<MediaType> list = new ArrayList();
|
||
|
//// list.add(MediaType.TEXT_HTML);
|
||
|
//// headers.setAccept(list);
|
||
|
//
|
||
|
//
|
||
|
// HttpEntity<String> request = new HttpEntity<>(works.toString(), headers);
|
||
|
//
|
||
|
//// log.debug(restTemplate.exchange(url, HttpMethod.POST, request, Object.class));
|
||
|
//
|
||
|
// ResponseEntity<String> response = restTemplate.exchange(url, HttpMethod.POST, request, String.class);
|
||
|
// if (response.getStatusCode() != HttpStatus.OK) {
|
||
|
// log.debug("Saving works response code is: " + response.getStatusCode());
|
||
|
// log.debug(response.getBody().toString());
|
||
|
// return null;
|
||
|
// } else {
|
||
|
// log.debug("[success] Saving works response code is: " + response.getStatusCode());
|
||
|
// log.debug(response.toString());
|
||
|
//
|
||
|
// return response.toString();
|
||
|
// }
|
||
|
// }
|
||
|
|
||
|
// @RequestMapping(value = "/works", method = RequestMethod.GET)
|
||
|
// public String getAllWorks(@RequestParam String orcid) {
|
||
|
// log.debug("getAllWorks: orcid = |" + orcid + "|");
|
||
|
//
|
||
|
// String userAccessToken = userTokensService.getUserAccessToken(orcid);
|
||
|
// log.debug("Access token: " + userAccessToken);
|
||
|
//
|
||
|
//// String url = "https://sandbox.orcid.org/v3.0/" + orcid.toString() + "/works";
|
||
|
// String url = "https://api.sandbox.orcid.org/v3.0/"+orcid+"/works";
|
||
|
//
|
||
|
// RestTemplate restTemplate = new RestTemplate();
|
||
|
// restTemplate.setErrorHandler(new DefaultResponseErrorHandler() {
|
||
|
// protected boolean hasError(HttpStatus statusCode) {
|
||
|
// return false;
|
||
|
// }
|
||
|
// });
|
||
|
// HttpHeaders headers = new HttpHeaders();
|
||
|
// headers.add("Accept", "application/json");
|
||
|
// headers.add("Authorization", "Bearer " + userAccessToken);
|
||
|
// headers.add("Content-Type", "application/orcid+json");
|
||
|
// log.debug(headers.get("Authorization"));
|
||
|
// HttpEntity<String> request = new HttpEntity<>(headers);
|
||
|
// //logger.info(restTemplate.exchange(fooResourceUrl, HttpMethod.GET, request, Object.class));
|
||
|
// ResponseEntity<String> response = restTemplate.exchange(url, HttpMethod.GET, request, String.class);
|
||
|
// if (response.getStatusCode() != HttpStatus.OK) {
|
||
|
// log.debug("Getting works response code is: " + response.getStatusCode());
|
||
|
// return null;
|
||
|
// } else {
|
||
|
// log.debug(response);
|
||
|
// return response.getBody().toString();
|
||
|
// }
|
||
|
//
|
||
|
//// try {
|
||
|
//// URL obj = new URL(url);
|
||
|
////
|
||
|
//// HttpURLConnection con = (HttpURLConnection) obj.openConnection();
|
||
|
//// con.setRequestProperty("Accept", "application/json");
|
||
|
//// con.setRequestProperty("Content-Type", "application/orcid+json");
|
||
|
//// con.setRequestProperty("Authorization", "Bearer "+userAccessToken);
|
||
|
////
|
||
|
//// if (con.getResponseCode() != 200) {
|
||
|
//// log.debug("Getting works response code is: " + con.getResponseCode());
|
||
|
//// return null;
|
||
|
//// }
|
||
|
//// BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
|
||
|
//// StringBuilder response = new StringBuilder();
|
||
|
//// String inputLine;
|
||
|
//// while ((inputLine = in.readLine()) != null) {
|
||
|
//// response.append(inputLine).append("\n");
|
||
|
//// }
|
||
|
//// in.close();
|
||
|
//// log.debug(response);
|
||
|
//// return response;
|
||
|
//// } catch (Exception e) {
|
||
|
//// log.error("An error occured while trying to fetch works for orcid: "+orcid, e);
|
||
|
//// return null;
|
||
|
//// }
|
||
|
// }
|
||
|
|
||
|
@PreAuthorize("isAuthenticated()")
|
||
|
@RequestMapping(value = "/work/{putCode}/delete", method = RequestMethod.DELETE)
|
||
|
public String deleteWork(@PathVariable String putCode) throws IOException, BadPaddingException, InvalidKeyException, NoSuchAlgorithmException, IllegalBlockSizeException, NoSuchPaddingException, InvalidAlgorithmParameterException, InvalidKeySpecException {
|
||
|
log.debug("deleteWork: putCode = " + putCode);
|
||
|
|
||
|
UserTokens userTokens = userTokensService.getUserTokens();
|
||
|
if(userTokens == null) {
|
||
|
throw new AuthorizationServiceException("User is not registered");
|
||
|
}
|
||
|
String userOrcid = userTokens.getOrcid();
|
||
|
String userAccessToken = userTokens.getAccessToken();
|
||
|
|
||
|
if(userOrcid == null || userAccessToken == null) {
|
||
|
throw new AuthorizationServiceException("User is not registered");
|
||
|
}
|
||
|
|
||
|
log.debug("Access token: " + userAccessToken);
|
||
|
log.debug("User orcid: " + userOrcid);
|
||
|
|
||
|
// String url = "https://sandbox.orcid.org/v3.0/" + orcid.toString() + "/works";
|
||
|
String url = "https://api.sandbox.orcid.org/v3.0/"+userOrcid+"/work/" + putCode;
|
||
|
|
||
|
RestTemplate restTemplate = new RestTemplate();
|
||
|
restTemplate.setErrorHandler(new DefaultResponseErrorHandler() {
|
||
|
protected boolean hasError(HttpStatus statusCode) {
|
||
|
return false;
|
||
|
}
|
||
|
});
|
||
|
HttpHeaders headers = new HttpHeaders();
|
||
|
// headers.add("Accept", "application/json");
|
||
|
headers.add("Authorization", "Bearer " + userAccessToken);
|
||
|
headers.add("Content-Type","application/orcid+json");
|
||
|
|
||
|
HttpEntity<String> request = new HttpEntity<>(headers);
|
||
|
//logger.info(restTemplate.exchange(fooResourceUrl, HttpMethod.GET, request, Object.class));
|
||
|
ResponseEntity<String> response = restTemplate.exchange(url, HttpMethod.DELETE, request, String.class);
|
||
|
if (response.getStatusCode() != HttpStatus.NO_CONTENT) {
|
||
|
log.debug("Deleting work response code is: " + response.getStatusCode());
|
||
|
if(response.getStatusCode() == HttpStatus.NOT_FOUND) {
|
||
|
workService.deleteWork(putCode);
|
||
|
return putCode;
|
||
|
}
|
||
|
if(response.getStatusCode() == HttpStatus.UNAUTHORIZED) {
|
||
|
throw new AuthorizationServiceException("You are not allowed to delete work");
|
||
|
}
|
||
|
return null;
|
||
|
} else {
|
||
|
log.debug(response);
|
||
|
|
||
|
workService.deleteWork(putCode);
|
||
|
|
||
|
return putCode;
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|
||
|
@PreAuthorize("isAuthenticated()")
|
||
|
@RequestMapping(value = "/works/delete", method = RequestMethod.POST)
|
||
|
public List<String> deleteWorks(@RequestBody List<String> putCodes) throws IOException, BadPaddingException, InvalidKeyException, NoSuchAlgorithmException, IllegalBlockSizeException, NoSuchPaddingException, InvalidAlgorithmParameterException, InvalidKeySpecException {
|
||
|
log.debug("deleteWorks: putCodes = " + putCodes);
|
||
|
|
||
|
UserTokens userTokens = userTokensService.getUserTokens();
|
||
|
if(userTokens == null) {
|
||
|
throw new AuthorizationServiceException("User is not registered");
|
||
|
}
|
||
|
String userOrcid = userTokens.getOrcid();
|
||
|
String userAccessToken = userTokens.getAccessToken();
|
||
|
|
||
|
if(userOrcid == null || userAccessToken == null) {
|
||
|
throw new AuthorizationServiceException("User is not registered");
|
||
|
}
|
||
|
|
||
|
log.debug("Access token: " + userAccessToken);
|
||
|
log.debug("User orcid: " + userOrcid);
|
||
|
|
||
|
RestTemplate restTemplate = new RestTemplate();
|
||
|
restTemplate.setErrorHandler(new DefaultResponseErrorHandler() {
|
||
|
protected boolean hasError(HttpStatus statusCode) {
|
||
|
return false;
|
||
|
}
|
||
|
});
|
||
|
HttpHeaders headers = new HttpHeaders();
|
||
|
// headers.add("Accept", "application/json");
|
||
|
headers.add("Authorization", "Bearer " + userAccessToken);
|
||
|
headers.add("Content-Type","application/orcid+json");
|
||
|
|
||
|
HttpEntity<String> request = new HttpEntity<>(headers);
|
||
|
//logger.info(restTemplate.exchange(fooResourceUrl, HttpMethod.GET, request, Object.class));
|
||
|
|
||
|
List<String> deletedPutCodes = new ArrayList<>();
|
||
|
int index = 0;
|
||
|
for(String putCode : putCodes) {
|
||
|
String url = "https://api.sandbox.orcid.org/v3.0/"+userOrcid+"/work/" + putCode;
|
||
|
// UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(url);
|
||
|
|
||
|
ResponseEntity<String> response = restTemplate.exchange(url, HttpMethod.DELETE, request, String.class);
|
||
|
if (response.getStatusCode() != HttpStatus.NO_CONTENT) {
|
||
|
log.debug("Deleting work response code is: " + response.getStatusCode());
|
||
|
if(index == 0 && response.getStatusCode() == HttpStatus.UNAUTHORIZED) {
|
||
|
throw new AuthorizationServiceException("You are not allowed to delete work");
|
||
|
}
|
||
|
if (response.getStatusCode() == HttpStatus.NOT_FOUND) {
|
||
|
workService.deleteWork(putCode);
|
||
|
deletedPutCodes.add(putCode);
|
||
|
} else {
|
||
|
deletedPutCodes.add(null);
|
||
|
}
|
||
|
} else {
|
||
|
log.debug(response);
|
||
|
|
||
|
workService.deleteWork(putCode);
|
||
|
|
||
|
deletedPutCodes.add(putCode);
|
||
|
}
|
||
|
index++;
|
||
|
}
|
||
|
return deletedPutCodes;
|
||
|
}
|
||
|
|
||
|
@PreAuthorize("isAuthenticated()")
|
||
|
@RequestMapping(value = "/work", method = RequestMethod.GET)
|
||
|
public List<String> getWorksOfReuslt(@RequestParam String[] pids, @RequestParam String orcid) throws BadPaddingException, InvalidKeyException, NoSuchAlgorithmException, IllegalBlockSizeException, NoSuchPaddingException, InvalidAlgorithmParameterException, InvalidKeySpecException, IOException {
|
||
|
log.debug("getWorks: pids = " + pids + " - orcid = "+orcid);
|
||
|
|
||
|
List<Work> works = workService.getWorks(pids, orcid);
|
||
|
|
||
|
String userAccessToken = userTokensService.getUserAccessToken(orcid);
|
||
|
log.debug("Access token: " + userAccessToken);
|
||
|
|
||
|
RestTemplate restTemplate = new RestTemplate();
|
||
|
restTemplate.setErrorHandler(new DefaultResponseErrorHandler() {
|
||
|
protected boolean hasError(HttpStatus statusCode) {
|
||
|
return false;
|
||
|
}
|
||
|
});
|
||
|
HttpHeaders headers = new HttpHeaders();
|
||
|
headers.add("Accept", "application/json");
|
||
|
headers.add("Authorization", "Bearer " + userAccessToken);
|
||
|
headers.add("Content-Type", "application/orcid+json");
|
||
|
log.debug(headers.get("Authorization"));
|
||
|
HttpEntity<String> request = new HttpEntity<>(headers);
|
||
|
|
||
|
List<String> responseValues = new ArrayList<>();
|
||
|
|
||
|
for(Work work : works) {
|
||
|
// String url = "https://api.sandbox.orcid.org/v3.0/0000-0001-9541-4617/work/"+work.getPutCode();
|
||
|
String url = "https://api.sandbox.orcid.org/v3.0/" + orcid + "/work/" + work.getPutCode();
|
||
|
log.debug(url);
|
||
|
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(url);
|
||
|
|
||
|
//logger.info(restTemplate.exchange(fooResourceUrl, HttpMethod.GET, request, Object.class));
|
||
|
ResponseEntity<String> response = restTemplate.exchange(builder.toUriString(), HttpMethod.GET, request, String.class);
|
||
|
// ResponseEntity<String> response = restTemplate.exchange(url, HttpMethod.GET, request, String.class);
|
||
|
if (response.getStatusCode() != HttpStatus.OK) {
|
||
|
log.debug("Getting work response code is: " + response.getStatusCode());
|
||
|
|
||
|
if (response.getStatusCode() == HttpStatus.NOT_FOUND) {
|
||
|
// work.setPutCode(null);
|
||
|
// workService.saveWork(work);
|
||
|
workService.deleteWork(work.getPutCode());
|
||
|
}
|
||
|
|
||
|
responseValues.add(null);
|
||
|
} else {
|
||
|
log.debug(response);
|
||
|
responseValues.add(response.getBody().toString());
|
||
|
}
|
||
|
}
|
||
|
return responseValues;
|
||
|
}
|
||
|
|
||
|
@PreAuthorize("isAuthenticated()")
|
||
|
@RequestMapping(value = "/works/local", method = RequestMethod.GET)
|
||
|
public List<Work> getLocalWorks() throws BadPaddingException, InvalidKeyException, NoSuchAlgorithmException, IllegalBlockSizeException, NoSuchPaddingException, InvalidAlgorithmParameterException, InvalidKeySpecException, IOException {
|
||
|
log.debug("getWorks");
|
||
|
|
||
|
UserTokens userTokens = userTokensService.getUserTokens();
|
||
|
if(userTokens == null) {
|
||
|
throw new AuthorizationServiceException("User is not registered");
|
||
|
}
|
||
|
String userOrcid = userTokens.getOrcid();
|
||
|
|
||
|
if(userOrcid == null) {
|
||
|
throw new AuthorizationServiceException("User is not registered");
|
||
|
}
|
||
|
|
||
|
return workService.getLocalWorks(userOrcid);
|
||
|
}
|
||
|
}
|