[VIVO-1346] Updates to ORCiD client library integration (preparation for v2.0)

This commit is contained in:
Graham Triggs 2017-07-27 17:33:43 +01:00
parent 6438458892
commit ca6d629e2f
7 changed files with 47 additions and 88 deletions

View file

@ -52,9 +52,9 @@
<version>1.0</version> <version>1.0</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.vivoweb.dependencies</groupId> <groupId>org.vivoweb</groupId>
<artifactId>orcid-api-client</artifactId> <artifactId>orcid-api-client</artifactId>
<version>0.2</version> <version>0.3</version>
</dependency> </dependency>
<dependency> <dependency>

View file

@ -2,15 +2,7 @@
package edu.cornell.mannlib.vivo.orcid; package edu.cornell.mannlib.vivo.orcid;
import static edu.cornell.mannlib.orcidclient.context.OrcidClientContext.Setting.AUTHORIZED_API_BASE_URL; import static edu.cornell.mannlib.orcidclient.context.OrcidClientContext.Setting.*;
import static edu.cornell.mannlib.orcidclient.context.OrcidClientContext.Setting.CALLBACK_PATH;
import static edu.cornell.mannlib.orcidclient.context.OrcidClientContext.Setting.CLIENT_ID;
import static edu.cornell.mannlib.orcidclient.context.OrcidClientContext.Setting.CLIENT_SECRET;
import static edu.cornell.mannlib.orcidclient.context.OrcidClientContext.Setting.MESSAGE_VERSION;
import static edu.cornell.mannlib.orcidclient.context.OrcidClientContext.Setting.OAUTH_AUTHORIZE_URL;
import static edu.cornell.mannlib.orcidclient.context.OrcidClientContext.Setting.OAUTH_TOKEN_URL;
import static edu.cornell.mannlib.orcidclient.context.OrcidClientContext.Setting.PUBLIC_API_BASE_URL;
import static edu.cornell.mannlib.orcidclient.context.OrcidClientContext.Setting.WEBAPP_BASE_URL;
import static edu.cornell.mannlib.vivo.orcid.controller.OrcidIntegrationController.DEFAULT_EXTERNAL_ID_COMMON_NAME; import static edu.cornell.mannlib.vivo.orcid.controller.OrcidIntegrationController.DEFAULT_EXTERNAL_ID_COMMON_NAME;
import static edu.cornell.mannlib.vivo.orcid.controller.OrcidIntegrationController.PROPERTY_EXTERNAL_ID_COMMON_NAME; import static edu.cornell.mannlib.vivo.orcid.controller.OrcidIntegrationController.PROPERTY_EXTERNAL_ID_COMMON_NAME;
@ -66,16 +58,10 @@ public class OrcidContextSetup implements ServletContextListener {
settings.put(CLIENT_ID, props.getProperty("orcid.clientId")); settings.put(CLIENT_ID, props.getProperty("orcid.clientId"));
settings.put(CLIENT_SECRET, settings.put(CLIENT_SECRET,
props.getProperty("orcid.clientPassword")); props.getProperty("orcid.clientPassword"));
settings.put(PUBLIC_API_BASE_URL, settings.put(API_VERSION,
props.getProperty("orcid.publicApiBaseUrl")); props.getProperty("orcid.apiVersion"));
settings.put(AUTHORIZED_API_BASE_URL, settings.put(API_ENVIRONMENT,
props.getProperty("orcid.authorizedApiBaseUrl")); props.getProperty("orcid.api"));
settings.put(OAUTH_AUTHORIZE_URL,
props.getProperty("orcid.oauthAuthorizeUrl"));
settings.put(OAUTH_TOKEN_URL,
props.getProperty("orcid.oauthTokenUrl"));
settings.put(MESSAGE_VERSION,
props.getProperty("orcid.messageVersion"));
settings.put(WEBAPP_BASE_URL, settings.put(WEBAPP_BASE_URL,
props.getProperty("orcid.webappBaseUrl")); props.getProperty("orcid.webappBaseUrl"));
settings.put(CALLBACK_PATH, "orcid/callback"); settings.put(CALLBACK_PATH, "orcid/callback");

View file

@ -12,12 +12,13 @@ import static javax.servlet.http.HttpServletResponse.SC_INTERNAL_SERVER_ERROR;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import edu.cornell.mannlib.orcidclient.actions.ActionManager;
import edu.cornell.mannlib.orcidclient.model.OrcidProfile;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import edu.cornell.mannlib.orcidclient.auth.AuthorizationManager; import edu.cornell.mannlib.orcidclient.auth.AuthorizationManager;
import edu.cornell.mannlib.orcidclient.context.OrcidClientContext; import edu.cornell.mannlib.orcidclient.context.OrcidClientContext;
import edu.cornell.mannlib.orcidclient.orcidmessage.OrcidMessage;
import edu.cornell.mannlib.vedit.beans.LoginStatusBean; import edu.cornell.mannlib.vedit.beans.LoginStatusBean;
import edu.cornell.mannlib.vitro.webapp.beans.Individual; import edu.cornell.mannlib.vitro.webapp.beans.Individual;
import edu.cornell.mannlib.vitro.webapp.beans.ObjectPropertyStatement; import edu.cornell.mannlib.vitro.webapp.beans.ObjectPropertyStatement;
@ -40,6 +41,7 @@ public abstract class OrcidAbstractHandler {
protected final VitroRequest vreq; protected final VitroRequest vreq;
protected final OrcidClientContext occ; protected final OrcidClientContext occ;
protected final AuthorizationManager auth; protected final AuthorizationManager auth;
protected final ActionManager manager;
protected final OrcidConfirmationState state; protected final OrcidConfirmationState state;
protected final UserAccount currentUser; protected final UserAccount currentUser;
@ -47,6 +49,7 @@ public abstract class OrcidAbstractHandler {
this.vreq = vreq; this.vreq = vreq;
this.occ = OrcidClientContext.getInstance(); this.occ = OrcidClientContext.getInstance();
this.auth = this.occ.getAuthorizationManager(vreq); this.auth = this.occ.getAuthorizationManager(vreq);
this.manager = this.occ.getActionManager(vreq);
this.state = OrcidConfirmationState.fetch(vreq); this.state = OrcidConfirmationState.fetch(vreq);
this.currentUser = LoginStatusBean.getCurrentUser(vreq); this.currentUser = LoginStatusBean.getCurrentUser(vreq);
} }
@ -110,8 +113,8 @@ public abstract class OrcidAbstractHandler {
} }
protected ResponseValues showConfirmationPage(Progress p, protected ResponseValues showConfirmationPage(Progress p,
OrcidMessage... messages) { OrcidProfile... profiles) {
state.progress(p, messages); state.progress(p, profiles);
return showConfirmationPage(); return showConfirmationPage();
} }

View file

@ -3,11 +3,12 @@
package edu.cornell.mannlib.vivo.orcid.controller; package edu.cornell.mannlib.vivo.orcid.controller;
import static edu.cornell.mannlib.orcidclient.actions.ApiAction.ADD_EXTERNAL_ID; import static edu.cornell.mannlib.orcidclient.actions.ApiAction.ADD_EXTERNAL_ID;
import static edu.cornell.mannlib.orcidclient.orcidmessage.Visibility.PUBLIC; import static edu.cornell.mannlib.orcidclient.beans.Visibility.PUBLIC;
import static edu.cornell.mannlib.vivo.orcid.controller.OrcidConfirmationState.Progress.ADDED_ID; import static edu.cornell.mannlib.vivo.orcid.controller.OrcidConfirmationState.Progress.ADDED_ID;
import static edu.cornell.mannlib.vivo.orcid.controller.OrcidConfirmationState.Progress.DENIED_ID; import static edu.cornell.mannlib.vivo.orcid.controller.OrcidConfirmationState.Progress.DENIED_ID;
import static edu.cornell.mannlib.vivo.orcid.controller.OrcidConfirmationState.Progress.FAILED_ID; import static edu.cornell.mannlib.vivo.orcid.controller.OrcidConfirmationState.Progress.FAILED_ID;
import edu.cornell.mannlib.orcidclient.model.OrcidProfile;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
@ -15,7 +16,6 @@ import edu.cornell.mannlib.orcidclient.OrcidClientException;
import edu.cornell.mannlib.orcidclient.actions.AddExternalIdAction; import edu.cornell.mannlib.orcidclient.actions.AddExternalIdAction;
import edu.cornell.mannlib.orcidclient.auth.AuthorizationStatus; import edu.cornell.mannlib.orcidclient.auth.AuthorizationStatus;
import edu.cornell.mannlib.orcidclient.beans.ExternalId; import edu.cornell.mannlib.orcidclient.beans.ExternalId;
import edu.cornell.mannlib.orcidclient.orcidmessage.OrcidMessage;
import edu.cornell.mannlib.vitro.webapp.beans.Individual; import edu.cornell.mannlib.vitro.webapp.beans.Individual;
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest; import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.ResponseValues; import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.ResponseValues;
@ -28,7 +28,7 @@ public class OrcidAddExternalIdHandler extends OrcidAbstractHandler {
.getLog(OrcidAddExternalIdHandler.class); .getLog(OrcidAddExternalIdHandler.class);
private AuthorizationStatus status; private AuthorizationStatus status;
private OrcidMessage profile; private OrcidProfile profile;
protected OrcidAddExternalIdHandler(VitroRequest vreq) { protected OrcidAddExternalIdHandler(VitroRequest vreq) {
super(vreq); super(vreq);
@ -53,8 +53,7 @@ public class OrcidAddExternalIdHandler extends OrcidAbstractHandler {
.setUrl(individual.getURI()).setVisibility(PUBLIC); .setUrl(individual.getURI()).setVisibility(PUBLIC);
log.debug("Adding external VIVO ID"); log.debug("Adding external VIVO ID");
profile = new AddExternalIdAction().execute(externalId, profile = manager.createAddExternalIdAction().execute(externalId, status.getAccessToken());
status.getAccessToken());
} }
} }

View file

@ -23,12 +23,11 @@ import javax.xml.namespace.QName;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import edu.cornell.mannlib.orcidclient.orcidmessage.ExternalIdentifier; import edu.cornell.mannlib.orcidclient.model.ExternalIdentifier;
import edu.cornell.mannlib.orcidclient.orcidmessage.ExternalIdentifiers; import edu.cornell.mannlib.orcidclient.model.ExternalIdentifiers;
import edu.cornell.mannlib.orcidclient.orcidmessage.OrcidBio; import edu.cornell.mannlib.orcidclient.model.OrcidBio;
import edu.cornell.mannlib.orcidclient.orcidmessage.OrcidId; import edu.cornell.mannlib.orcidclient.model.OrcidId;
import edu.cornell.mannlib.orcidclient.orcidmessage.OrcidMessage; import edu.cornell.mannlib.orcidclient.model.OrcidProfile;
import edu.cornell.mannlib.orcidclient.orcidmessage.OrcidProfile;
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.UrlBuilder; import edu.cornell.mannlib.vitro.webapp.controller.freemarker.UrlBuilder;
/** /**
@ -73,7 +72,7 @@ class OrcidConfirmationState {
private Progress progress; private Progress progress;
private String individualUri; private String individualUri;
private Set<String> existingOrcids; private Set<String> existingOrcids;
private OrcidMessage profile; private OrcidProfile profile;
private String profilePageUrl; private String profilePageUrl;
public void reset(String uri, String profileUrl) { public void reset(String uri, String profileUrl) {
@ -88,17 +87,17 @@ class OrcidConfirmationState {
existingOrcids = new HashSet<>(existing); existingOrcids = new HashSet<>(existing);
} }
public void progress(Progress p, OrcidMessage... messages) { public void progress(Progress p, OrcidProfile... profiles) {
progress = p; progress = p;
if (requiresMessage.contains(p)) { if (requiresMessage.contains(p)) {
if (messages.length != 1) { if (profiles.length != 1) {
throw new IllegalStateException("Progress to " + p throw new IllegalStateException("Progress to " + p
+ " requires an OrcidMessage"); + " requires an OrcidMessage");
} }
profile = messages[0]; profile = profiles[0];
} else { } else {
if (messages.length != 0) { if (profiles.length != 0) {
throw new IllegalStateException("Progress to " + p throw new IllegalStateException("Progress to " + p
+ " does not accept an OrcidMessage"); + " does not accept an OrcidMessage");
} }
@ -143,7 +142,7 @@ class OrcidConfirmationState {
public ExternalIdentifier getVivoId() { public ExternalIdentifier getVivoId() {
for (ExternalIdentifier id : getExternalIds()) { for (ExternalIdentifier id : getExternalIds()) {
if (individualUri.equals(id.getExternalIdUrl().getValue())) { if (individualUri.equals(id.getExternalIdUrl())) {
return id; return id;
} }
} }
@ -161,17 +160,11 @@ class OrcidConfirmationState {
return Collections.emptyList(); return Collections.emptyList();
} }
ExternalIdentifiers identifiers = bio.getExternalIdentifiers(); if (bio.getExternalIdentifiers() == null) {
if (identifiers == null) {
return Collections.emptyList(); return Collections.emptyList();
} }
List<ExternalIdentifier> list = identifiers.getExternalIdentifier(); return bio.getExternalIdentifiers();
if (list == null) {
return Collections.emptyList();
}
return list;
} }
private String getElementFromOrcidIdentifier(String elementName) { private String getElementFromOrcidIdentifier(String elementName) {
@ -186,19 +179,13 @@ class OrcidConfirmationState {
return ""; return "";
} }
List<JAXBElement<String>> idElements = id.getContent(); if ("path".equalsIgnoreCase(elementName)) {
if (idElements != null) { return id.getPath();
for (JAXBElement<String> idElement : idElements) { } else if ("uri".equalsIgnoreCase(elementName)) {
QName name = idElement.getName(); return id.getUri();
if (name != null && elementName.equals(name.getLocalPart())) {
String value = idElement.getValue();
if (value != null) {
return value;
} }
}
} log.warn("Didn't find the element '' in the ORCID Identifier");
}
log.warn("Didn't find the element '' in the ORCID Identifier: " + idElements);
return ""; return "";
} }
@ -207,12 +194,7 @@ class OrcidConfirmationState {
return null; return null;
} }
OrcidProfile orcidProfile = profile.getOrcidProfile(); return profile;
if (orcidProfile == null) {
return null;
}
return orcidProfile;
} }
public Map<String, Object> toMap() { public Map<String, Object> toMap() {
@ -240,9 +222,9 @@ class OrcidConfirmationState {
List<Map<String, String>> list = new ArrayList<>(); List<Map<String, String>> list = new ArrayList<>();
for (ExternalIdentifier id : getExternalIds()) { for (ExternalIdentifier id : getExternalIds()) {
Map<String, String> map = new HashMap<>(); Map<String, String> map = new HashMap<>();
map.put("commonName", id.getExternalIdCommonName().getContent()); map.put("commonName", id.getExternalIdCommonName());
map.put("reference", id.getExternalIdReference().getContent()); map.put("reference", id.getExternalIdReference());
map.put("uri", id.getExternalIdUrl().getValue()); map.put("uri", id.getExternalIdUrl());
list.add(map); list.add(map);
} }
return list; return list;

View file

@ -8,13 +8,13 @@ import static edu.cornell.mannlib.vivo.orcid.controller.OrcidConfirmationState.P
import static edu.cornell.mannlib.vivo.orcid.controller.OrcidConfirmationState.Progress.GOT_PROFILE; import static edu.cornell.mannlib.vivo.orcid.controller.OrcidConfirmationState.Progress.GOT_PROFILE;
import static edu.cornell.mannlib.vivo.orcid.controller.OrcidConfirmationState.Progress.ID_ALREADY_PRESENT; import static edu.cornell.mannlib.vivo.orcid.controller.OrcidConfirmationState.Progress.ID_ALREADY_PRESENT;
import edu.cornell.mannlib.orcidclient.model.OrcidProfile;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import edu.cornell.mannlib.orcidclient.OrcidClientException; import edu.cornell.mannlib.orcidclient.OrcidClientException;
import edu.cornell.mannlib.orcidclient.actions.ReadPublicBioAction; import edu.cornell.mannlib.orcidclient.actions.ReadPublicBioAction;
import edu.cornell.mannlib.orcidclient.auth.AuthorizationStatus; import edu.cornell.mannlib.orcidclient.auth.AuthorizationStatus;
import edu.cornell.mannlib.orcidclient.orcidmessage.OrcidMessage;
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest; import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.ResponseValues; import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.ResponseValues;
@ -26,7 +26,7 @@ public class OrcidReadProfileHandler extends OrcidAbstractHandler {
.getLog(OrcidReadProfileHandler.class); .getLog(OrcidReadProfileHandler.class);
private AuthorizationStatus status; private AuthorizationStatus status;
private OrcidMessage profile; private OrcidProfile profile;
protected OrcidReadProfileHandler(VitroRequest vreq) { protected OrcidReadProfileHandler(VitroRequest vreq) {
super(vreq); super(vreq);
@ -53,8 +53,7 @@ public class OrcidReadProfileHandler extends OrcidAbstractHandler {
} }
private void readProfile() throws OrcidClientException { private void readProfile() throws OrcidClientException {
profile = new ReadPublicBioAction().execute(status.getAccessToken() profile = manager.createReadPublicBioAction().execute(status.getAccessToken().getOrcid());
.getOrcid());
log.debug("Read profile"); log.debug("Read profile");
} }

View file

@ -195,23 +195,13 @@ VitroConnection.DataSource.validationQuery = SELECT 1
# orcid.clientId = 0000-0000-0000-000X # orcid.clientId = 0000-0000-0000-000X
# orcid.clientPassword = 00000000-0000-0000-0000-000000000000 # orcid.clientPassword = 00000000-0000-0000-0000-000000000000
# orcid.webappBaseUrl = http://localhost:8080/vivo # orcid.webappBaseUrl = http://localhost:8080/vivo
# orcid.messageVersion = 1.0.23
# orcid.externalIdCommonName = VIVO Cornell Identifier # orcid.externalIdCommonName = VIVO Cornell Identifier
# ---- Setup for the sandbox ---- # 1.2, 2.0
# orcid.apiVersion = 1.2
# orcid.publicApiBaseUrl = http://pub.sandbox.orcid.org/v1.1
# orcid.authorizedApiBaseUrl = http://api.sandbox.orcid.org/v1.1
# orcid.oauthAuthorizeUrl = http://sandbox.orcid.org/oauth/authorize
# orcid.oauthTokenUrl = http://api.sandbox.orcid.org/oauth/token
# ---- or for the mockorcid webapp ----
# orcid.publicApiBaseUrl = http://localhost:8080/mockorcid/mock/
# orcid.authorizedApiBaseUrl = http://localhost:8080/mockorcid/mock/
# orcid.oauthAuthorizeUrl = http://localhost:8080/mockorcid/mock/oauth/authorize
# orcid.oauthTokenUrl = http://localhost:8080/mockorcid/mock/oauth/token
# release, sandbox
# orcid.api = sandbox
# ----------------------------------------------------------------------------- # -----------------------------------------------------------------------------
# OTHER OPTIONS # OTHER OPTIONS