diff --git a/api/pom.xml b/api/pom.xml index cfafdc23..e6f4bfba 100644 --- a/api/pom.xml +++ b/api/pom.xml @@ -52,9 +52,9 @@ 1.0 - org.vivoweb.dependencies + org.vivoweb orcid-api-client - 0.2 + 0.3 diff --git a/api/src/main/java/edu/cornell/mannlib/vivo/orcid/OrcidContextSetup.java b/api/src/main/java/edu/cornell/mannlib/vivo/orcid/OrcidContextSetup.java index df2c5f4b..5b47e234 100644 --- a/api/src/main/java/edu/cornell/mannlib/vivo/orcid/OrcidContextSetup.java +++ b/api/src/main/java/edu/cornell/mannlib/vivo/orcid/OrcidContextSetup.java @@ -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"); diff --git a/api/src/main/java/edu/cornell/mannlib/vivo/orcid/controller/OrcidAbstractHandler.java b/api/src/main/java/edu/cornell/mannlib/vivo/orcid/controller/OrcidAbstractHandler.java index a84d6398..709f655c 100644 --- a/api/src/main/java/edu/cornell/mannlib/vivo/orcid/controller/OrcidAbstractHandler.java +++ b/api/src/main/java/edu/cornell/mannlib/vivo/orcid/controller/OrcidAbstractHandler.java @@ -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(); } diff --git a/api/src/main/java/edu/cornell/mannlib/vivo/orcid/controller/OrcidAddExternalIdHandler.java b/api/src/main/java/edu/cornell/mannlib/vivo/orcid/controller/OrcidAddExternalIdHandler.java index 9ccd5145..d278cba3 100644 --- a/api/src/main/java/edu/cornell/mannlib/vivo/orcid/controller/OrcidAddExternalIdHandler.java +++ b/api/src/main/java/edu/cornell/mannlib/vivo/orcid/controller/OrcidAddExternalIdHandler.java @@ -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()); } } diff --git a/api/src/main/java/edu/cornell/mannlib/vivo/orcid/controller/OrcidConfirmationState.java b/api/src/main/java/edu/cornell/mannlib/vivo/orcid/controller/OrcidConfirmationState.java index 3f54f50c..72510c97 100644 --- a/api/src/main/java/edu/cornell/mannlib/vivo/orcid/controller/OrcidConfirmationState.java +++ b/api/src/main/java/edu/cornell/mannlib/vivo/orcid/controller/OrcidConfirmationState.java @@ -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 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 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> idElements = id.getContent(); - if (idElements != null) { - for (JAXBElement 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 toMap() { @@ -240,9 +222,9 @@ class OrcidConfirmationState { List> list = new ArrayList<>(); for (ExternalIdentifier id : getExternalIds()) { Map 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; diff --git a/api/src/main/java/edu/cornell/mannlib/vivo/orcid/controller/OrcidReadProfileHandler.java b/api/src/main/java/edu/cornell/mannlib/vivo/orcid/controller/OrcidReadProfileHandler.java index 7fc27fea..c2800094 100644 --- a/api/src/main/java/edu/cornell/mannlib/vivo/orcid/controller/OrcidReadProfileHandler.java +++ b/api/src/main/java/edu/cornell/mannlib/vivo/orcid/controller/OrcidReadProfileHandler.java @@ -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"); } diff --git a/home/src/main/resources/config/example.runtime.properties b/home/src/main/resources/config/example.runtime.properties index a89434a9..3b35a8ee 100644 --- a/home/src/main/resources/config/example.runtime.properties +++ b/home/src/main/resources/config/example.runtime.properties @@ -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