Skip to content

Commit

Permalink
[VIVO-1346] Updates to ORCiD client library integration (preparation …
Browse files Browse the repository at this point in the history
…for v2.0)
  • Loading branch information
grahamtriggs committed Oct 16, 2017
1 parent 9527d87 commit 0e9380e
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 88 deletions.
4 changes: 2 additions & 2 deletions api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -66,16 +58,10 @@ private void initializeOrcidClientContext(ConfigurationProperties props,
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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@
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;
Expand All @@ -40,13 +41,15 @@ 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;

protected OrcidAbstractHandler(VitroRequest vreq) {
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);
}
Expand Down Expand Up @@ -110,8 +113,8 @@ protected ResponseValues show500InternalServerError(String message) {
}

protected ResponseValues showConfirmationPage(Progress p,
OrcidMessage... messages) {
state.progress(p, messages);
OrcidProfile... profiles) {
state.progress(p, profiles);
return showConfirmationPage();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@
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;

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;
Expand All @@ -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);
Expand All @@ -53,8 +53,7 @@ private void addVivoId() throws OrcidClientException {
.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());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,11 @@
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;

/**
Expand Down Expand Up @@ -73,7 +72,7 @@ public enum Progress {
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) {
Expand All @@ -88,17 +87,17 @@ public void setExistingOrcids(Set<String> existing) {
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");
}
Expand Down Expand Up @@ -143,7 +142,7 @@ public String getOrcidUri() {

public ExternalIdentifier getVivoId() {
for (ExternalIdentifier id : getExternalIds()) {
if (individualUri.equals(id.getExternalIdUrl().getValue())) {
if (individualUri.equals(id.getExternalIdUrl())) {
return id;
}
}
Expand All @@ -161,17 +160,11 @@ public List<ExternalIdentifier> getExternalIds() {
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) {
Expand All @@ -186,19 +179,13 @@ private String getElementFromOrcidIdentifier(String elementName) {
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 "";
}

Expand All @@ -207,12 +194,7 @@ private OrcidProfile getOrcidProfile() {
return null;
}

OrcidProfile orcidProfile = profile.getOrcidProfile();
if (orcidProfile == null) {
return null;
}

return orcidProfile;
return profile;
}

public Map<String, Object> toMap() {
Expand Down Expand Up @@ -240,9 +222,9 @@ private List<Map<String, String>> formatExternalIds() {
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
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;

Expand All @@ -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);
Expand All @@ -53,8 +53,7 @@ public ResponseValues exec() throws OrcidClientException {
}

private void readProfile() throws OrcidClientException {
profile = new ReadPublicBioAction().execute(status.getAccessToken()
.getOrcid());
profile = manager.createReadPublicBioAction().execute(status.getAccessToken().getOrcid());
log.debug("Read profile");
}

Expand Down
18 changes: 4 additions & 14 deletions home/src/main/resources/config/example.runtime.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 0e9380e

Please sign in to comment.