use of org.ambraproject.wombat.service.remote.orcid.OrcidAuthenticationTokenReusedException in project wombat by PLOS.
the class ArticleController method uploadPreprintRevision.
@RequestMapping(name = "uploadPreprintRevision", value = "/article/uploadPreprintRevision")
public String uploadPreprintRevision(HttpServletRequest request, Model model, @SiteParam Site site, @RequestParam("state") String state, @RequestParam("code") String code) throws IOException, URISyntaxException {
final byte[] decodedState = Base64.getDecoder().decode(state);
final String decodedJson = URLDecoder.decode(new String(decodedState), "UTF-8");
Map<String, Object> stateJson = gson.fromJson(decodedJson, HashMap.class);
String correspondingAuthorOrcidId = (String) stateJson.get("orcid_id");
String authenticatedOrcidId = "";
try {
authenticatedOrcidId = orcidApi.getOrcidIdFromAuthorizationCode(site, code);
} catch (OrcidAuthenticationTokenExpiredException | OrcidAuthenticationTokenReusedException e) {
model.addAttribute("orcidAuthenticationError", e.getMessage());
}
boolean isError = true;
if (correspondingAuthorOrcidId.equals(authenticatedOrcidId)) {
model.addAttribute("orcidId", correspondingAuthorOrcidId);
isError = false;
} else if (!Strings.isNullOrEmpty(authenticatedOrcidId)) {
model.addAttribute("orcidAuthenticationError", "ORCID IDs do not match. " + "Corresponding author ORCID ID must be used.");
}
if (isError) {
final RequestedDoiVersion articleId = RequestedDoiVersion.of((String) stateJson.get("doi"));
return renderArticle(request, model, site, articleId);
} else {
return site + "/ftl/article/uploadPreprintRevision";
}
}
Aggregations