[VIVO-1346] Updates to ORCiD client library integration (preparation for v2.0)
This commit is contained in:
parent
6438458892
commit
ca6d629e2f
7 changed files with 47 additions and 88 deletions
|
@ -52,9 +52,9 @@
|
|||
<version>1.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.vivoweb.dependencies</groupId>
|
||||
<groupId>org.vivoweb</groupId>
|
||||
<artifactId>orcid-api-client</artifactId>
|
||||
<version>0.2</version>
|
||||
<version>0.3</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
|
|
|
@ -2,15 +2,7 @@
|
|||
|
||||
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.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.orcidclient.context.OrcidClientContext.Setting.*;
|
||||
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;
|
||||
|
||||
|
@ -66,16 +58,10 @@ public class OrcidContextSetup implements ServletContextListener {
|
|||
settings.put(CLIENT_ID, props.getProperty("orcid.clientId"));
|
||||
settings.put(CLIENT_SECRET,
|
||||
props.getProperty("orcid.clientPassword"));
|
||||
settings.put(PUBLIC_API_BASE_URL,
|
||||
props.getProperty("orcid.publicApiBaseUrl"));
|
||||
settings.put(AUTHORIZED_API_BASE_URL,
|
||||
props.getProperty("orcid.authorizedApiBaseUrl"));
|
||||
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(API_VERSION,
|
||||
props.getProperty("orcid.apiVersion"));
|
||||
settings.put(API_ENVIRONMENT,
|
||||
props.getProperty("orcid.api"));
|
||||
settings.put(WEBAPP_BASE_URL,
|
||||
props.getProperty("orcid.webappBaseUrl"));
|
||||
settings.put(CALLBACK_PATH, "orcid/callback");
|
||||
|
|
|
@ -12,12 +12,13 @@ import static javax.servlet.http.HttpServletResponse.SC_INTERNAL_SERVER_ERROR;
|
|||
import java.util.HashMap;
|
||||
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.LogFactory;
|
||||
|
||||
import edu.cornell.mannlib.orcidclient.auth.AuthorizationManager;
|
||||
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.vitro.webapp.beans.Individual;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.ObjectPropertyStatement;
|
||||
|
@ -40,6 +41,7 @@ public abstract class OrcidAbstractHandler {
|
|||
protected final VitroRequest vreq;
|
||||
protected final OrcidClientContext occ;
|
||||
protected final AuthorizationManager auth;
|
||||
protected final ActionManager manager;
|
||||
protected final OrcidConfirmationState state;
|
||||
protected final UserAccount currentUser;
|
||||
|
||||
|
@ -47,6 +49,7 @@ public abstract class OrcidAbstractHandler {
|
|||
this.vreq = vreq;
|
||||
this.occ = OrcidClientContext.getInstance();
|
||||
this.auth = this.occ.getAuthorizationManager(vreq);
|
||||
this.manager = this.occ.getActionManager(vreq);
|
||||
this.state = OrcidConfirmationState.fetch(vreq);
|
||||
this.currentUser = LoginStatusBean.getCurrentUser(vreq);
|
||||
}
|
||||
|
@ -110,8 +113,8 @@ public abstract class OrcidAbstractHandler {
|
|||
}
|
||||
|
||||
protected ResponseValues showConfirmationPage(Progress p,
|
||||
OrcidMessage... messages) {
|
||||
state.progress(p, messages);
|
||||
OrcidProfile... profiles) {
|
||||
state.progress(p, profiles);
|
||||
return showConfirmationPage();
|
||||
}
|
||||
|
||||
|
|
|
@ -3,11 +3,12 @@
|
|||
package edu.cornell.mannlib.vivo.orcid.controller;
|
||||
|
||||
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.DENIED_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.LogFactory;
|
||||
|
||||
|
@ -15,7 +16,6 @@ import edu.cornell.mannlib.orcidclient.OrcidClientException;
|
|||
import edu.cornell.mannlib.orcidclient.actions.AddExternalIdAction;
|
||||
import edu.cornell.mannlib.orcidclient.auth.AuthorizationStatus;
|
||||
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.controller.VitroRequest;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.ResponseValues;
|
||||
|
@ -28,7 +28,7 @@ public class OrcidAddExternalIdHandler extends OrcidAbstractHandler {
|
|||
.getLog(OrcidAddExternalIdHandler.class);
|
||||
|
||||
private AuthorizationStatus status;
|
||||
private OrcidMessage profile;
|
||||
private OrcidProfile profile;
|
||||
|
||||
protected OrcidAddExternalIdHandler(VitroRequest vreq) {
|
||||
super(vreq);
|
||||
|
@ -53,8 +53,7 @@ public class OrcidAddExternalIdHandler extends OrcidAbstractHandler {
|
|||
.setUrl(individual.getURI()).setVisibility(PUBLIC);
|
||||
|
||||
log.debug("Adding external VIVO ID");
|
||||
profile = new AddExternalIdAction().execute(externalId,
|
||||
status.getAccessToken());
|
||||
profile = manager.createAddExternalIdAction().execute(externalId, status.getAccessToken());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -23,12 +23,11 @@ import javax.xml.namespace.QName;
|
|||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import edu.cornell.mannlib.orcidclient.orcidmessage.ExternalIdentifier;
|
||||
import edu.cornell.mannlib.orcidclient.orcidmessage.ExternalIdentifiers;
|
||||
import edu.cornell.mannlib.orcidclient.orcidmessage.OrcidBio;
|
||||
import edu.cornell.mannlib.orcidclient.orcidmessage.OrcidId;
|
||||
import edu.cornell.mannlib.orcidclient.orcidmessage.OrcidMessage;
|
||||
import edu.cornell.mannlib.orcidclient.orcidmessage.OrcidProfile;
|
||||
import edu.cornell.mannlib.orcidclient.model.ExternalIdentifier;
|
||||
import edu.cornell.mannlib.orcidclient.model.ExternalIdentifiers;
|
||||
import edu.cornell.mannlib.orcidclient.model.OrcidBio;
|
||||
import edu.cornell.mannlib.orcidclient.model.OrcidId;
|
||||
import edu.cornell.mannlib.orcidclient.model.OrcidProfile;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.UrlBuilder;
|
||||
|
||||
/**
|
||||
|
@ -73,7 +72,7 @@ class OrcidConfirmationState {
|
|||
private Progress progress;
|
||||
private String individualUri;
|
||||
private Set<String> existingOrcids;
|
||||
private OrcidMessage profile;
|
||||
private OrcidProfile profile;
|
||||
private String profilePageUrl;
|
||||
|
||||
public void reset(String uri, String profileUrl) {
|
||||
|
@ -88,17 +87,17 @@ class OrcidConfirmationState {
|
|||
existingOrcids = new HashSet<>(existing);
|
||||
}
|
||||
|
||||
public void progress(Progress p, OrcidMessage... messages) {
|
||||
public void progress(Progress p, OrcidProfile... profiles) {
|
||||
progress = p;
|
||||
|
||||
if (requiresMessage.contains(p)) {
|
||||
if (messages.length != 1) {
|
||||
if (profiles.length != 1) {
|
||||
throw new IllegalStateException("Progress to " + p
|
||||
+ " requires an OrcidMessage");
|
||||
}
|
||||
profile = messages[0];
|
||||
profile = profiles[0];
|
||||
} else {
|
||||
if (messages.length != 0) {
|
||||
if (profiles.length != 0) {
|
||||
throw new IllegalStateException("Progress to " + p
|
||||
+ " does not accept an OrcidMessage");
|
||||
}
|
||||
|
@ -143,7 +142,7 @@ class OrcidConfirmationState {
|
|||
|
||||
public ExternalIdentifier getVivoId() {
|
||||
for (ExternalIdentifier id : getExternalIds()) {
|
||||
if (individualUri.equals(id.getExternalIdUrl().getValue())) {
|
||||
if (individualUri.equals(id.getExternalIdUrl())) {
|
||||
return id;
|
||||
}
|
||||
}
|
||||
|
@ -161,17 +160,11 @@ class OrcidConfirmationState {
|
|||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
ExternalIdentifiers identifiers = bio.getExternalIdentifiers();
|
||||
if (identifiers == null) {
|
||||
if (bio.getExternalIdentifiers() == null) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
List<ExternalIdentifier> list = identifiers.getExternalIdentifier();
|
||||
if (list == null) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
return list;
|
||||
return bio.getExternalIdentifiers();
|
||||
}
|
||||
|
||||
private String getElementFromOrcidIdentifier(String elementName) {
|
||||
|
@ -186,19 +179,13 @@ class OrcidConfirmationState {
|
|||
return "";
|
||||
}
|
||||
|
||||
List<JAXBElement<String>> idElements = id.getContent();
|
||||
if (idElements != null) {
|
||||
for (JAXBElement<String> idElement : idElements) {
|
||||
QName name = idElement.getName();
|
||||
if (name != null && elementName.equals(name.getLocalPart())) {
|
||||
String value = idElement.getValue();
|
||||
if (value != null) {
|
||||
return value;
|
||||
if ("path".equalsIgnoreCase(elementName)) {
|
||||
return id.getPath();
|
||||
} else if ("uri".equalsIgnoreCase(elementName)) {
|
||||
return id.getUri();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
log.warn("Didn't find the element '' in the ORCID Identifier: " + idElements);
|
||||
|
||||
log.warn("Didn't find the element '' in the ORCID Identifier");
|
||||
return "";
|
||||
}
|
||||
|
||||
|
@ -207,12 +194,7 @@ class OrcidConfirmationState {
|
|||
return null;
|
||||
}
|
||||
|
||||
OrcidProfile orcidProfile = profile.getOrcidProfile();
|
||||
if (orcidProfile == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return orcidProfile;
|
||||
return profile;
|
||||
}
|
||||
|
||||
public Map<String, Object> toMap() {
|
||||
|
@ -240,9 +222,9 @@ class OrcidConfirmationState {
|
|||
List<Map<String, String>> list = new ArrayList<>();
|
||||
for (ExternalIdentifier id : getExternalIds()) {
|
||||
Map<String, String> map = new HashMap<>();
|
||||
map.put("commonName", id.getExternalIdCommonName().getContent());
|
||||
map.put("reference", id.getExternalIdReference().getContent());
|
||||
map.put("uri", id.getExternalIdUrl().getValue());
|
||||
map.put("commonName", id.getExternalIdCommonName());
|
||||
map.put("reference", id.getExternalIdReference());
|
||||
map.put("uri", id.getExternalIdUrl());
|
||||
list.add(map);
|
||||
}
|
||||
return list;
|
||||
|
|
|
@ -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.ID_ALREADY_PRESENT;
|
||||
|
||||
import edu.cornell.mannlib.orcidclient.model.OrcidProfile;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import edu.cornell.mannlib.orcidclient.OrcidClientException;
|
||||
import edu.cornell.mannlib.orcidclient.actions.ReadPublicBioAction;
|
||||
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.freemarker.responsevalues.ResponseValues;
|
||||
|
||||
|
@ -26,7 +26,7 @@ public class OrcidReadProfileHandler extends OrcidAbstractHandler {
|
|||
.getLog(OrcidReadProfileHandler.class);
|
||||
|
||||
private AuthorizationStatus status;
|
||||
private OrcidMessage profile;
|
||||
private OrcidProfile profile;
|
||||
|
||||
protected OrcidReadProfileHandler(VitroRequest vreq) {
|
||||
super(vreq);
|
||||
|
@ -53,8 +53,7 @@ public class OrcidReadProfileHandler extends OrcidAbstractHandler {
|
|||
}
|
||||
|
||||
private void readProfile() throws OrcidClientException {
|
||||
profile = new ReadPublicBioAction().execute(status.getAccessToken()
|
||||
.getOrcid());
|
||||
profile = manager.createReadPublicBioAction().execute(status.getAccessToken().getOrcid());
|
||||
log.debug("Read profile");
|
||||
}
|
||||
|
||||
|
|
|
@ -195,23 +195,13 @@ VitroConnection.DataSource.validationQuery = SELECT 1
|
|||
# orcid.clientId = 0000-0000-0000-000X
|
||||
# orcid.clientPassword = 00000000-0000-0000-0000-000000000000
|
||||
# orcid.webappBaseUrl = http://localhost:8080/vivo
|
||||
# orcid.messageVersion = 1.0.23
|
||||
# orcid.externalIdCommonName = VIVO Cornell Identifier
|
||||
|
||||
# ---- Setup for the sandbox ----
|
||||
|
||||
# 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
|
||||
# 1.2, 2.0
|
||||
# orcid.apiVersion = 1.2
|
||||
|
||||
# release, sandbox
|
||||
# orcid.api = sandbox
|
||||
|
||||
# -----------------------------------------------------------------------------
|
||||
# OTHER OPTIONS
|
||||
|
|
Loading…
Add table
Reference in a new issue