Search in sources :

Example 1 with OrcidAuthenticationTokenExpiredException

use of org.ambraproject.wombat.service.remote.orcid.OrcidAuthenticationTokenExpiredException 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";
    }
}
Also used : RequestedDoiVersion(org.ambraproject.wombat.identity.RequestedDoiVersion) OrcidAuthenticationTokenReusedException(org.ambraproject.wombat.service.remote.orcid.OrcidAuthenticationTokenReusedException) OrcidAuthenticationTokenExpiredException(org.ambraproject.wombat.service.remote.orcid.OrcidAuthenticationTokenExpiredException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

RequestedDoiVersion (org.ambraproject.wombat.identity.RequestedDoiVersion)1 OrcidAuthenticationTokenExpiredException (org.ambraproject.wombat.service.remote.orcid.OrcidAuthenticationTokenExpiredException)1 OrcidAuthenticationTokenReusedException (org.ambraproject.wombat.service.remote.orcid.OrcidAuthenticationTokenReusedException)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1