[Trunk | Orcid Service]:
1. RecordController.java: Comment file RecordController.java, since it is not used by portal (to be deleted). 2. WorkController.java: Use "apiUrl" property for requests to ORCID API (not string set in the code).
This commit is contained in:
parent
f72dcedbd5
commit
ddefdc5056
|
@ -1,83 +1,83 @@
|
||||||
package eu.dnetlib.uoaorcidservice.controllers;
|
//package eu.dnetlib.uoaorcidservice.controllers;
|
||||||
|
|
||||||
import eu.dnetlib.uoaorcidservice.services.UserTokensService;
|
|
||||||
import org.apache.log4j.Logger;
|
|
||||||
import org.springframework.http.*;
|
|
||||||
import org.springframework.web.bind.annotation.*;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.web.client.DefaultResponseErrorHandler;
|
|
||||||
import org.springframework.web.client.RestTemplate;
|
|
||||||
|
|
||||||
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;
|
|
||||||
|
|
||||||
@RestController
|
|
||||||
@RequestMapping("/orcid")
|
|
||||||
@CrossOrigin(origins = "*")
|
|
||||||
public class RecordController {
|
|
||||||
private final Logger log = Logger.getLogger(this.getClass());
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
UserTokensService userTokensService;
|
|
||||||
|
|
||||||
@RequestMapping(value = {"/record"}, method = RequestMethod.GET)
|
|
||||||
public String getRecord() throws BadPaddingException, InvalidKeyException, NoSuchAlgorithmException, IllegalBlockSizeException, NoSuchPaddingException, InvalidAlgorithmParameterException, InvalidKeySpecException, IOException {
|
|
||||||
String testingUserToken = userTokensService.getUserAccessToken(null);
|
|
||||||
String testingUserOrcid = userTokensService.getCurrentUserOrcid();
|
|
||||||
|
|
||||||
String url = "https://api.sandbox.orcid.org/v3.0/"+testingUserOrcid;//+"/record";
|
|
||||||
|
|
||||||
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 "+testingUserToken);
|
|
||||||
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.GET, request, String.class);
|
|
||||||
if(response.getStatusCode() != HttpStatus.OK) {
|
|
||||||
log.debug("Getting orcid record 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();
|
//import eu.dnetlib.uoaorcidservice.services.UserTokensService;
|
||||||
// con.setRequestProperty("Accept", "application/json");
|
//import org.apache.log4j.Logger;
|
||||||
// con.setRequestProperty("Content-Type", "application/json");
|
//import org.springframework.http.*;
|
||||||
// con.setRequestProperty("Authorization", "Bearer "+testingUserToken);
|
//import org.springframework.web.bind.annotation.*;
|
||||||
|
//import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
//import org.springframework.web.client.DefaultResponseErrorHandler;
|
||||||
|
//import org.springframework.web.client.RestTemplate;
|
||||||
//
|
//
|
||||||
// if (con.getResponseCode() != 200) {
|
//import javax.crypto.BadPaddingException;
|
||||||
// log.debug("User record response code is: " + con.getResponseCode());
|
//import javax.crypto.IllegalBlockSizeException;
|
||||||
// return null;
|
//import javax.crypto.NoSuchPaddingException;
|
||||||
// }
|
//import java.io.IOException;
|
||||||
// BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
|
//import java.security.InvalidAlgorithmParameterException;
|
||||||
// StringBuilder response = new StringBuilder();
|
//import java.security.InvalidKeyException;
|
||||||
// String inputLine;
|
//import java.security.NoSuchAlgorithmException;
|
||||||
// while ((inputLine = in.readLine()) != null) {
|
//import java.security.spec.InvalidKeySpecException;
|
||||||
// response.append(inputLine).append("\n");
|
//
|
||||||
// }
|
//@RestController
|
||||||
// in.close();
|
//@RequestMapping("/orcid")
|
||||||
// log.debug(response);
|
//@CrossOrigin(origins = "*")
|
||||||
// return response;
|
//public class RecordController {
|
||||||
// } catch (Exception e) {
|
// private final Logger log = Logger.getLogger(this.getClass());
|
||||||
// log.error("An error occured while trying to fetch user record ", e);
|
//
|
||||||
|
// @Autowired
|
||||||
|
// UserTokensService userTokensService;
|
||||||
|
//
|
||||||
|
// @RequestMapping(value = {"/record"}, method = RequestMethod.GET)
|
||||||
|
// public String getRecord() throws BadPaddingException, InvalidKeyException, NoSuchAlgorithmException, IllegalBlockSizeException, NoSuchPaddingException, InvalidAlgorithmParameterException, InvalidKeySpecException, IOException {
|
||||||
|
// String testingUserToken = userTokensService.getUserAccessToken(null);
|
||||||
|
// String testingUserOrcid = userTokensService.getCurrentUserOrcid();
|
||||||
|
//
|
||||||
|
// String url = "https://api.sandbox.orcid.org/v3.0/"+testingUserOrcid;//+"/record";
|
||||||
|
//
|
||||||
|
// 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 "+testingUserToken);
|
||||||
|
// 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.GET, request, String.class);
|
||||||
|
// if(response.getStatusCode() != HttpStatus.OK) {
|
||||||
|
// log.debug("Getting orcid record response code is: " + response.getStatusCode());
|
||||||
// return null;
|
// 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/json");
|
||||||
|
//// con.setRequestProperty("Authorization", "Bearer "+testingUserToken);
|
||||||
|
////
|
||||||
|
//// if (con.getResponseCode() != 200) {
|
||||||
|
//// log.debug("User record 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 user record ", e);
|
||||||
|
//// return null;
|
||||||
|
//// }
|
||||||
|
// }
|
||||||
|
//}
|
|
@ -119,7 +119,7 @@ public class WorkController {
|
||||||
// log.debug("Access token: " + userAccessToken);
|
// log.debug("Access token: " + userAccessToken);
|
||||||
// log.debug("User orcid: " + userOrcid);
|
// log.debug("User orcid: " + userOrcid);
|
||||||
|
|
||||||
String url = "https://api.sandbox.orcid.org/v3.0/" + userOrcid + "/work";
|
String url = orcidConfig.getApiURL() + userOrcid + "/work";
|
||||||
|
|
||||||
RestTemplate restTemplate = new RestTemplate();
|
RestTemplate restTemplate = new RestTemplate();
|
||||||
// restTemplate.setRequestFactory(new HttpComponentsClientHttpRequestFactory());
|
// restTemplate.setRequestFactory(new HttpComponentsClientHttpRequestFactory());
|
||||||
|
@ -310,7 +310,7 @@ public class WorkController {
|
||||||
// log.debug("Access token: " + userAccessToken);
|
// log.debug("Access token: " + userAccessToken);
|
||||||
// log.debug("User orcid: " + userOrcid);
|
// log.debug("User orcid: " + userOrcid);
|
||||||
|
|
||||||
String url = "https://api.sandbox.orcid.org/v3.0/"+userOrcid+"/work/" + putCode;
|
String url = orcidConfig.getApiURL()+userOrcid+"/work/" + putCode;
|
||||||
|
|
||||||
RestTemplate restTemplate = new RestTemplate();
|
RestTemplate restTemplate = new RestTemplate();
|
||||||
restTemplate.setErrorHandler(new DefaultResponseErrorHandler() {
|
restTemplate.setErrorHandler(new DefaultResponseErrorHandler() {
|
||||||
|
@ -384,7 +384,7 @@ public class WorkController {
|
||||||
List<String> deletedPutCodes = new ArrayList<>();
|
List<String> deletedPutCodes = new ArrayList<>();
|
||||||
int index = 0;
|
int index = 0;
|
||||||
for(String putCode : putCodes) {
|
for(String putCode : putCodes) {
|
||||||
String url = "https://api.sandbox.orcid.org/v3.0/"+userOrcid+"/work/" + putCode;
|
String url = orcidConfig.getApiURL()+userOrcid+"/work/" + putCode;
|
||||||
// UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(url);
|
// UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(url);
|
||||||
|
|
||||||
orcid_log.info("request: "+request);
|
orcid_log.info("request: "+request);
|
||||||
|
|
Loading…
Reference in New Issue