Commit dd6860788b8b2f7f8c97a843b271acb926bb73dc

Authored by lpedro
0 parents
Exists in master and in 1 other branch API_v3.0

C4071

Showing 233 changed files with 33965 additions and 0 deletions   Show diff stats

Too many changes.

To preserve performance only 100 of 233 files displayed.

@@ -0,0 +1,38 @@ @@ -0,0 +1,38 @@
  1 +<?xml version="1.0" encoding="UTF-8"?>
  2 +<classpath>
  3 + <classpathentry kind="src" output="target/classes" path="src/main/java">
  4 + <attributes>
  5 + <attribute name="optional" value="true"/>
  6 + <attribute name="maven.pomderived" value="true"/>
  7 + </attributes>
  8 + </classpathentry>
  9 + <classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
  10 + <attributes>
  11 + <attribute name="maven.pomderived" value="true"/>
  12 + </attributes>
  13 + </classpathentry>
  14 + <classpathentry kind="src" output="target/test-classes" path="src/test/java">
  15 + <attributes>
  16 + <attribute name="optional" value="true"/>
  17 + <attribute name="maven.pomderived" value="true"/>
  18 + </attributes>
  19 + </classpathentry>
  20 + <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
  21 + <attributes>
  22 + <attribute name="maven.pomderived" value="true"/>
  23 + </attributes>
  24 + </classpathentry>
  25 + <classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
  26 + <attributes>
  27 + <attribute name="maven.pomderived" value="true"/>
  28 + <attribute name="org.eclipse.jst.component.nondependency" value=""/>
  29 + </attributes>
  30 + </classpathentry>
  31 + <classpathentry kind="src" output="target/classes" path="target/generated-sources">
  32 + <attributes>
  33 + <attribute name="optional" value="true"/>
  34 + <attribute name="maven.pomderived" value="true"/>
  35 + </attributes>
  36 + </classpathentry>
  37 + <classpathentry kind="output" path="target/classes"/>
  38 +</classpath>
@@ -0,0 +1,42 @@ @@ -0,0 +1,42 @@
  1 +<?xml version="1.0" encoding="UTF-8"?>
  2 +<projectDescription>
  3 + <name>degois-orcid-client-2.0</name>
  4 + <comment></comment>
  5 + <projects>
  6 + </projects>
  7 + <buildSpec>
  8 + <buildCommand>
  9 + <name>org.eclipse.wst.common.project.facet.core.builder</name>
  10 + <arguments>
  11 + </arguments>
  12 + </buildCommand>
  13 + <buildCommand>
  14 + <name>org.eclipse.jdt.core.javabuilder</name>
  15 + <arguments>
  16 + </arguments>
  17 + </buildCommand>
  18 + <buildCommand>
  19 + <name>org.eclipse.babel.editor.rbeBuilder</name>
  20 + <arguments>
  21 + </arguments>
  22 + </buildCommand>
  23 + <buildCommand>
  24 + <name>org.eclipse.wst.validation.validationbuilder</name>
  25 + <arguments>
  26 + </arguments>
  27 + </buildCommand>
  28 + <buildCommand>
  29 + <name>org.eclipse.m2e.core.maven2Builder</name>
  30 + <arguments>
  31 + </arguments>
  32 + </buildCommand>
  33 + </buildSpec>
  34 + <natures>
  35 + <nature>org.eclipse.jem.workbench.JavaEMFNature</nature>
  36 + <nature>org.eclipse.wst.common.modulecore.ModuleCoreNature</nature>
  37 + <nature>org.eclipse.jdt.core.javanature</nature>
  38 + <nature>org.eclipse.m2e.core.maven2Nature</nature>
  39 + <nature>com.jaspersoft.studio.babel.editor.rbeNature</nature>
  40 + <nature>org.eclipse.wst.common.project.facet.core.nature</nature>
  41 + </natures>
  42 +</projectDescription>
.settings/org.eclipse.core.resources.prefs
@@ -0,0 +1,6 @@ @@ -0,0 +1,6 @@
  1 +eclipse.preferences.version=1
  2 +encoding//src/main/java=UTF-8
  3 +encoding//src/main/resources=UTF-8
  4 +encoding//src/test/java=UTF-8
  5 +encoding//target/generated-sources=UTF-8
  6 +encoding/<project>=UTF-8
.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,9 @@ @@ -0,0 +1,9 @@
  1 +eclipse.preferences.version=1
  2 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
  3 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
  4 +org.eclipse.jdt.core.compiler.compliance=1.8
  5 +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
  6 +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
  7 +org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
  8 +org.eclipse.jdt.core.compiler.source=1.8
  9 +org.eclipse.objectteams.otdt.compiler.option.pure_java=enabled
.settings/org.eclipse.m2e.core.prefs
@@ -0,0 +1,4 @@ @@ -0,0 +1,4 @@
  1 +activeProfiles=
  2 +eclipse.preferences.version=1
  3 +resolveWorkspaceProjects=true
  4 +version=1
.settings/org.eclipse.wst.common.component
@@ -0,0 +1,7 @@ @@ -0,0 +1,7 @@
  1 +<?xml version="1.0" encoding="UTF-8"?><project-modules id="moduleCoreId" project-version="1.5.0">
  2 + <wb-module deploy-name="degois-orcid-client-2.0">
  3 + <wb-resource deploy-path="/" source-path="/src/main/java"/>
  4 + <wb-resource deploy-path="/" source-path="/src/main/resources"/>
  5 + <wb-resource deploy-path="/" source-path="/target/generated-sources"/>
  6 + </wb-module>
  7 +</project-modules>
.settings/org.eclipse.wst.common.project.facet.core.xml
@@ -0,0 +1,5 @@ @@ -0,0 +1,5 @@
  1 +<?xml version="1.0" encoding="UTF-8"?>
  2 +<faceted-project>
  3 + <installed facet="java" version="1.8"/>
  4 + <installed facet="jst.utility" version="1.0"/>
  5 +</faceted-project>
.settings/org.eclipse.wst.validation.prefs
@@ -0,0 +1,2 @@ @@ -0,0 +1,2 @@
  1 +disabled=06target
  2 +eclipse.preferences.version=1
@@ -0,0 +1,137 @@ @@ -0,0 +1,137 @@
  1 +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  2 + <modelVersion>4.0.0</modelVersion>
  3 +
  4 + <groupId>org.um.dsi.gavea</groupId>
  5 + <artifactId>degois-orcid-client</artifactId>
  6 + <version>2.0</version>
  7 +
  8 + <name>Orcid Client</name>
  9 +
  10 + <properties>
  11 + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  12 + <java.version>1.8</java.version>
  13 + <jersey.version>2.22.1</jersey.version>
  14 + <jaxb2-basics.version>0.9.5</jaxb2-basics.version>
  15 + <logback-version>1.1.9</logback-version>
  16 + <junit.version>4.12</junit.version>
  17 + </properties>
  18 +
  19 + <dependencies>
  20 + <!-- Jersey Client -->
  21 + <dependency>
  22 + <groupId>org.glassfish.jersey.core</groupId>
  23 + <artifactId>jersey-client</artifactId>
  24 + <version>${jersey.version}</version>
  25 + </dependency>
  26 + <dependency>
  27 + <groupId>org.glassfish.jersey.containers</groupId>
  28 + <artifactId>jersey-container-servlet</artifactId>
  29 + <version>${jersey.version}</version>
  30 + </dependency>
  31 + <dependency>
  32 + <groupId>org.glassfish.jersey.media</groupId>
  33 + <artifactId>jersey-media-json-jackson</artifactId>
  34 + <version>${jersey.version}</version>
  35 + </dependency>
  36 + <dependency>
  37 + <groupId>org.glassfish.jersey.media</groupId>
  38 + <artifactId>jersey-media-jaxb</artifactId>
  39 + <version>${jersey.version}</version>
  40 + </dependency>
  41 + <!-- JAXB2 Commons -->
  42 + <dependency>
  43 + <groupId>org.jvnet.jaxb2_commons</groupId>
  44 + <artifactId>jaxb2-basics-runtime</artifactId>
  45 + <version>${jaxb2-basics.version}</version>
  46 + </dependency>
  47 + <!-- Logging -->
  48 + <dependency>
  49 + <groupId>ch.qos.logback</groupId>
  50 + <artifactId>logback-classic</artifactId>
  51 + <version>${logback-version}</version>
  52 + </dependency>
  53 + <!-- JUnit -->
  54 + <dependency>
  55 + <groupId>junit</groupId>
  56 + <artifactId>junit</artifactId>
  57 + <version>${junit.version}</version>
  58 + <scope>test</scope>
  59 + </dependency>
  60 + </dependencies>
  61 +
  62 + <build>
  63 + <plugins>
  64 + <plugin>
  65 + <groupId>org.jvnet.jaxb2.maven2</groupId>
  66 + <artifactId>maven-jaxb2-plugin</artifactId>
  67 + <version>0.13.1</version>
  68 + <executions>
  69 + <execution>
  70 + <goals>
  71 + <goal>generate</goal>
  72 + </goals>
  73 + </execution>
  74 + </executions>
  75 + <configuration>
  76 + <noFileHeader>true</noFileHeader>
  77 + <generateDirectory>${project.build.directory}/generated-sources</generateDirectory>
  78 + <bindingDirectory>${basedir}/src/main/resources/binding</bindingDirectory>
  79 + <schemaDirectory>${basedir}/src/main/resources/xsd</schemaDirectory>
  80 + <schemaIncludes>
  81 + <include>common_2.0/*.xsd</include>
  82 + <include>record_2.0/*.xsd</include>
  83 + </schemaIncludes>
  84 + <episode>false</episode>
  85 + <args>
  86 + <arg>-Xsetters</arg>
  87 + <arg>-Xvalue-constructor</arg>
  88 + <arg>-XtoString</arg>
  89 + <arg>-extension</arg>
  90 + <arg>-Xnamespace-prefix</arg>
  91 + </args>
  92 + </configuration>
  93 + <dependencies>
  94 + <dependency>
  95 + <groupId>org.glassfish.jaxb</groupId>
  96 + <artifactId>jaxb-core</artifactId>
  97 + <version>2.2.11</version>
  98 + </dependency>
  99 + <dependency>
  100 + <groupId>org.jvnet.jaxb2_commons</groupId>
  101 + <artifactId>jaxb2-basics</artifactId>
  102 + <version>${jaxb2-basics.version}</version>
  103 + </dependency>
  104 + <dependency>
  105 + <groupId>org.jvnet.jaxb2_commons</groupId>
  106 + <artifactId>jaxb2-value-constructor</artifactId>
  107 + <version>3.0</version>
  108 + </dependency>
  109 + <dependency>
  110 + <groupId>org.jvnet.jaxb2_commons</groupId>
  111 + <artifactId>jaxb2-namespace-prefix</artifactId>
  112 + <version>1.1</version>
  113 + </dependency>
  114 + </dependencies>
  115 + </plugin>
  116 + <plugin>
  117 + <groupId>org.apache.maven.plugins</groupId>
  118 + <artifactId>maven-compiler-plugin</artifactId>
  119 + <version>3.3</version>
  120 + <inherited>true</inherited>
  121 + <configuration>
  122 + <source>${java.version}</source>
  123 + <target>${java.version}</target>
  124 + </configuration>
  125 + </plugin>
  126 + <plugin>
  127 + <groupId>org.apache.maven.plugins</groupId>
  128 + <artifactId>maven-surefire-plugin</artifactId>
  129 + <version>2.19.1</version>
  130 + <configuration>
  131 + <skipTests>true</skipTests>
  132 + </configuration>
  133 + </plugin>
  134 + </plugins>
  135 + </build>
  136 +
  137 +</project>
0 \ No newline at end of file 138 \ No newline at end of file
src/main/java/org/um/dsi/gavea/orcid/client/BaseOrcidOAuthClient.java
@@ -0,0 +1,206 @@ @@ -0,0 +1,206 @@
  1 +package org.um.dsi.gavea.orcid.client;
  2 +
  3 +import java.io.Serializable;
  4 +
  5 +import javax.ws.rs.ProcessingException;
  6 +import javax.ws.rs.client.Client;
  7 +import javax.ws.rs.client.ClientBuilder;
  8 +import javax.ws.rs.client.Entity;
  9 +import javax.ws.rs.client.WebTarget;
  10 +import javax.ws.rs.core.MediaType;
  11 +import javax.ws.rs.core.MultivaluedMap;
  12 +import javax.ws.rs.core.Response;
  13 +
  14 +import org.slf4j.Logger;
  15 +import org.slf4j.LoggerFactory;
  16 +import org.glassfish.jersey.client.ClientProperties;
  17 +import org.um.dsi.gavea.orcid.client.constants.OrcidConstants;
  18 +import org.um.dsi.gavea.orcid.client.exception.OrcidClientException;
  19 +import org.um.dsi.gavea.orcid.client.util.RecordUtil;
  20 +import org.um.dsi.gavea.orcid.model.error.Error;
  21 +
  22 +public class BaseOrcidOAuthClient implements Serializable {
  23 + private static final long serialVersionUID = 8455820192048815978L;
  24 +
  25 + private static final Logger _log = LoggerFactory.getLogger(BaseOrcidOAuthClient.class);
  26 +
  27 + private Client restClient;
  28 + private WebTarget target;
  29 +
  30 + protected final String loginUri;
  31 + protected final String apiUri;
  32 + protected final String clientId;
  33 + protected final String clientSecret;
  34 + protected final String redirectUri;
  35 +
  36 + protected final boolean debugMode;
  37 +
  38 + public BaseOrcidOAuthClient(Client restClient, String loginUri, String apiUri, String clientId, String clientSecret,
  39 + String redirectUri) {
  40 + this(restClient, loginUri, apiUri, clientId, clientSecret, redirectUri, false);
  41 + }
  42 +
  43 + public BaseOrcidOAuthClient(Client restClient, String loginUri, String apiUri, String clientId, String clientSecret,
  44 + String redirectUri, boolean debugMode) {
  45 + if (loginUri == null || apiUri == null || clientId == null || clientSecret == null || redirectUri == null)
  46 + throw new IllegalArgumentException("Cannot create OrcidOAuthClient - missing init parameters");
  47 +
  48 + this.restClient = restClient;
  49 + this.loginUri = loginUri;
  50 + this.apiUri = apiUri;
  51 + this.clientId = clientId;
  52 + this.clientSecret = clientSecret;
  53 + this.redirectUri = redirectUri;
  54 + this.debugMode = debugMode;
  55 + }
  56 +
  57 + protected <T> Response get(final String endpoint, final OrcidAccessToken token, final String putCode)
  58 + throws OrcidClientException {
  59 + Response response = null;
  60 + try {
  61 + createConnection(endpoint, token.getOrcid(), putCode);
  62 +
  63 + response = target.request(OrcidConstants.APPLICATION_ORCID_XML)
  64 + .header("Authorization", "Bearer" + token.getAccess_token()).get();
  65 + _log.debug("[get].[Response.Status] " + response.getStatus());
  66 + _log.debug("[get].[Response.Reason] " + response.getStatusInfo().getReasonPhrase());
  67 +
  68 + exceptionBuilder(response);
  69 + } catch (ProcessingException e) {
  70 + response = Response.serverError().build();
  71 + exceptionBuilder(response);
  72 + }
  73 +
  74 + return response;
  75 + }
  76 +
  77 + protected <T> Response post(final String authorizationCode, final MultivaluedMap<String, String> formData)
  78 + throws OrcidClientException {
  79 + createConnection(OrcidConstants.ENDPOINT_OAUTH_TOKEN, null, null);
  80 +
  81 + if (debugMode || _log.isTraceEnabled()) {
  82 + _log.debug("[getAccessTokens][post].[Request.form] " + formData.toString());
  83 + }
  84 + Response response = target.request(MediaType.APPLICATION_JSON_TYPE).post(Entity.form(formData));
  85 + _log.debug("[getAccessTokens][post].[Response.Status] " + response.getStatus());
  86 + _log.debug("[getAccessTokens][post].[Response.Reason] " + response.getStatusInfo().getReasonPhrase());
  87 +
  88 + exceptionBuilder(response);
  89 +
  90 + return response;
  91 + }
  92 +
  93 + protected <T> Response post(final String endpoint, final OrcidAccessToken token, final Entity<T> entity)
  94 + throws OrcidClientException {
  95 + Response response;
  96 + try {
  97 + createConnection(endpoint, token.getOrcid(), null);
  98 +
  99 + if (debugMode || _log.isTraceEnabled()) {
  100 + _log.debug("[post].[Request.entity] " + RecordUtil.convertToString(entity.getEntity()));
  101 + }
  102 +
  103 + response = target.request(OrcidConstants.APPLICATION_ORCID_XML)
  104 + .header("Authorization", "Bearer" + token.getAccess_token()).post(entity);
  105 + _log.debug("[post].[Response.Status] " + response.getStatus());
  106 + _log.debug("[post].[Response.Reason] " + response.getStatusInfo().getReasonPhrase());
  107 +
  108 + exceptionBuilder(response);
  109 + } catch (ProcessingException e) {
  110 + response = Response.serverError().build();
  111 + exceptionBuilder(response);
  112 + }
  113 +
  114 + return response;
  115 + }
  116 +
  117 + protected <T> Response put(final String endpoint, final OrcidAccessToken token, final String putCode,
  118 + final Entity<T> entity) throws OrcidClientException {
  119 + Response response;
  120 + try {
  121 + createConnection(endpoint, token.getOrcid(), putCode);
  122 +
  123 + if (debugMode || _log.isTraceEnabled()) {
  124 + _log.debug("[put].[Request.entity] " + RecordUtil.convertToString(entity.getEntity()));
  125 + }
  126 +
  127 + response = target.request(OrcidConstants.APPLICATION_ORCID_XML)
  128 + .header("Authorization", "Bearer" + token.getAccess_token()).put(entity);
  129 + _log.debug("[put].[Response.Status] " + response.getStatus());
  130 + _log.debug("[put].[Response.Reason] " + response.getStatusInfo().getReasonPhrase());
  131 +
  132 + exceptionBuilder(response);
  133 + } catch (ProcessingException e) {
  134 + response = Response.serverError().build();
  135 + exceptionBuilder(response);
  136 + }
  137 +
  138 + return response;
  139 + }
  140 +
  141 + protected <T> Response delete(final String endpoint, final OrcidAccessToken token, final String putCode)
  142 + throws OrcidClientException {
  143 + Response response;
  144 + try {
  145 + createConnection(endpoint, token.getOrcid(), putCode);
  146 +
  147 + response = target.request(OrcidConstants.APPLICATION_ORCID_XML)
  148 + .header("Authorization", "Bearer" + token.getAccess_token()).delete();
  149 + _log.debug("[delete].[Response.Status] " + response.getStatus());
  150 + _log.debug("[delete].[Response.Reason] " + response.getStatusInfo().getReasonPhrase());
  151 +
  152 + exceptionBuilder(response);
  153 + } catch (ProcessingException e) {
  154 + response = Response.serverError().build();
  155 + exceptionBuilder(response);
  156 + }
  157 +
  158 + return response;
  159 + }
  160 +
  161 + private void createConnection(final String endpoint, final String orcidId, final String putCode) {
  162 + if (restClient == null) {
  163 + restClient = ClientBuilder.newClient();
  164 + restClient.property(ClientProperties.CONNECT_TIMEOUT, OrcidConstants.CLIENT_CONNECT_TIMEOUT);
  165 + restClient.property(ClientProperties.READ_TIMEOUT, OrcidConstants.CLIENT_READ_TIMEOUT);
  166 + }
  167 +
  168 + target = restClient.target(apiUri).path(buildPath(endpoint, orcidId, putCode));
  169 + if (debugMode || _log.isTraceEnabled()) {
  170 + _log.debug("[connection].[Request.path] " + target.getUri().toString());
  171 + }
  172 + }
  173 +
  174 + private String buildPath(final String endpoint, final String orcidId, final String putCode) {
  175 + StringBuilder sb = new StringBuilder();
  176 +
  177 + if (orcidId != null && !"".equals(orcidId)) {
  178 + sb.append(OrcidConstants.API_VERSION).append("/").append(orcidId);
  179 + }
  180 +
  181 + if (endpoint != null && !"".equals(endpoint))
  182 + sb.append(endpoint);
  183 +
  184 + if (putCode != null && !"".equals(putCode)) {
  185 + sb.append("/").append(putCode);
  186 + }
  187 +
  188 + return sb.toString();
  189 + }
  190 +
  191 + protected void exceptionBuilder(Response response) throws OrcidClientException {
  192 + if (response.getStatus() > 300) {
  193 + if (response.getStatus() == 400) {
  194 + Error error = response.readEntity(Error.class);
  195 + throw new OrcidClientException(error.getResponseCode(), error.getUserMessage(), error.getErrorCode(),
  196 + error.getDeveloperMessage());
  197 + } else
  198 + throw new OrcidClientException(response.getStatus(),
  199 + response.getStatus() + " - " + response.getStatusInfo().getReasonPhrase());
  200 + }
  201 + }
  202 +
  203 + public String getClientId() {
  204 + return clientId;
  205 + }
  206 +}
src/main/java/org/um/dsi/gavea/orcid/client/OrcidAccessToken.java
@@ -0,0 +1,89 @@ @@ -0,0 +1,89 @@
  1 +package org.um.dsi.gavea.orcid.client;
  2 +
  3 +import java.io.Serializable;
  4 +
  5 +public class OrcidAccessToken implements Serializable, Cloneable {
  6 + private static final long serialVersionUID = 6776130415600464081L;
  7 +
  8 +
  9 + private String name;
  10 + private String access_token;
  11 + private String token_type;
  12 + private String refresh_token;
  13 + private int expires_in;
  14 + private String scope;
  15 + private String orcid;
  16 + private String state;
  17 +
  18 +
  19 + public String getName() {
  20 + return name;
  21 + }
  22 + public void setName(String name) {
  23 + this.name = name;
  24 + }
  25 +
  26 + public String getAccess_token() {
  27 + return access_token;
  28 + }
  29 + public void setAccess_token(String access_token) {
  30 + this.access_token = access_token;
  31 + }
  32 +
  33 + public String getToken_type() {
  34 + return token_type;
  35 + }
  36 + public void setToken_type(String token_type) {
  37 + this.token_type = token_type;
  38 + }
  39 +
  40 + public String getRefresh_token() {
  41 + return refresh_token;
  42 + }
  43 + public void setRefresh_token(String refresh_token) {
  44 + this.refresh_token = refresh_token;
  45 + }
  46 +
  47 + public int getExpires_in() {
  48 + return expires_in;
  49 + }
  50 + public void setExpires_in(int expires_in) {
  51 + this.expires_in = expires_in;
  52 + }
  53 +
  54 + public String getScope() {
  55 + return scope;
  56 + }
  57 + public void setScope(String scope) {
  58 + this.scope = scope;
  59 + }
  60 +
  61 + public String getOrcid() {
  62 + return orcid;
  63 + }
  64 + public void setOrcid(String orcid) {
  65 + this.orcid = orcid;
  66 + }
  67 +
  68 + public String getState() {
  69 + return state;
  70 + }
  71 + public void setState(String state) {
  72 + this.state = state;
  73 + }
  74 +
  75 + @Override
  76 + public Object clone() throws CloneNotSupportedException {
  77 + return (OrcidAccessToken) super.clone();
  78 + }
  79 +
  80 + @Override
  81 + public String toString() {
  82 + return "OrcidAccessToken [name=" + name + ", access_token="
  83 + + access_token + ", token_type=" + token_type
  84 + + ", refresh_token=" + refresh_token + ", expires_in="
  85 + + expires_in + ", scope=" + scope + ", orcid=" + orcid
  86 + + ", state=" + state + "]";
  87 + }
  88 +
  89 +}
src/main/java/org/um/dsi/gavea/orcid/client/OrcidOAuthClient.java
@@ -0,0 +1,883 @@ @@ -0,0 +1,883 @@
  1 +package org.um.dsi.gavea.orcid.client;
  2 +
  3 +import java.util.List;
  4 +
  5 +import javax.ws.rs.client.Client;
  6 +import javax.ws.rs.client.Entity;
  7 +import javax.ws.rs.core.MediaType;
  8 +import javax.ws.rs.core.MultivaluedHashMap;
  9 +import javax.ws.rs.core.MultivaluedMap;
  10 +import javax.ws.rs.core.Response;
  11 +import javax.ws.rs.core.UriBuilder;
  12 +
  13 +import org.jvnet.jaxb2_commons.lang.StringUtils;
  14 +import org.slf4j.Logger;
  15 +import org.slf4j.LoggerFactory;
  16 +import org.um.dsi.gavea.orcid.client.constants.OrcidConstants;
  17 +import org.um.dsi.gavea.orcid.client.exception.OrcidClientException;
  18 +import org.um.dsi.gavea.orcid.client.extend.ScopePathTypeExt;
  19 +import org.um.dsi.gavea.orcid.model.activities.ActivitiesSummary;
  20 +import org.um.dsi.gavea.orcid.model.address.Address;
  21 +import org.um.dsi.gavea.orcid.model.address.Addresses;
  22 +import org.um.dsi.gavea.orcid.model.common.ScopePathType;
  23 +import org.um.dsi.gavea.orcid.model.education.Education;
  24 +import org.um.dsi.gavea.orcid.model.education.EducationSummary;
  25 +import org.um.dsi.gavea.orcid.model.email.Emails;
  26 +import org.um.dsi.gavea.orcid.model.employment.Employment;
  27 +import org.um.dsi.gavea.orcid.model.employment.EmploymentSummary;
  28 +import org.um.dsi.gavea.orcid.model.funding.Funding;
  29 +import org.um.dsi.gavea.orcid.model.funding.FundingSummary;
  30 +import org.um.dsi.gavea.orcid.model.keyword.Keyword;
  31 +import org.um.dsi.gavea.orcid.model.keyword.Keywords;
  32 +import org.um.dsi.gavea.orcid.model.othername.OtherName;
  33 +import org.um.dsi.gavea.orcid.model.othername.OtherNames;
  34 +import org.um.dsi.gavea.orcid.model.peerreview.PeerReview;
  35 +import org.um.dsi.gavea.orcid.model.peerreview.PeerReviewSummary;
  36 +import org.um.dsi.gavea.orcid.model.person.Person;
  37 +import org.um.dsi.gavea.orcid.model.person.externalidentifier.ExternalIdentifier;
  38 +import org.um.dsi.gavea.orcid.model.person.externalidentifier.ExternalIdentifiers;
  39 +import org.um.dsi.gavea.orcid.model.personaldetails.Biography;
  40 +import org.um.dsi.gavea.orcid.model.personaldetails.PersonalDetails;
  41 +import org.um.dsi.gavea.orcid.model.researcherurl.ResearcherUrl;
  42 +import org.um.dsi.gavea.orcid.model.researcherurl.ResearcherUrls;
  43 +import org.um.dsi.gavea.orcid.model.work.Work;
  44 +import org.um.dsi.gavea.orcid.model.work.WorkSummary;
  45 +import org.um.dsi.gavea.orcid.model.bulk.Bulk;
  46 +
  47 +
  48 +public class OrcidOAuthClient extends BaseOrcidOAuthClient {
  49 + private static final long serialVersionUID = -6655680509383446710L;
  50 +
  51 + private static final Logger _log = LoggerFactory.getLogger(OrcidOAuthClient.class);
  52 +
  53 + public OrcidOAuthClient(String loginUri, String apiUri, String clientId, String clientSecret, String redirectUri) {
  54 + this(null, loginUri, apiUri, clientId, clientSecret, redirectUri);
  55 + }
  56 +
  57 + public OrcidOAuthClient(String loginUri, String apiUri, String clientId, String clientSecret, String redirectUri, boolean debugMode) {
  58 + this(null, loginUri, apiUri, clientId, clientSecret, redirectUri, debugMode);
  59 + }
  60 +
  61 + public OrcidOAuthClient(Client restClient, String loginUri, String apiUri, String clientId, String clientSecret, String redirectUri) {
  62 + super(restClient, loginUri, apiUri, clientId, clientSecret, redirectUri);
  63 + }
  64 +
  65 + public OrcidOAuthClient(Client restClient, String loginUri, String apiUri, String clientId, String clientSecret, String redirectUri, boolean debugMode) {
  66 + super(restClient, loginUri, apiUri, clientId, clientSecret, redirectUri, debugMode);
  67 + }
  68 +
  69 + /**
  70 + *
  71 + * @param scopes
  72 + * @param state
  73 + * @param orcidOrEmail
  74 + * @return
  75 + * @throws Exception
  76 + */
  77 + public String getAuthorizeUri(final List<ScopePathType> scopes, final String state, final String orcidOrEmail) throws Exception {
  78 +
  79 + String orcidId = null;
  80 + String email = null;
  81 + if (orcidOrEmail != null && !"".equals(orcidOrEmail)) {
  82 + if (isValidOrcidId(orcidOrEmail))
  83 + orcidId = orcidOrEmail;
  84 + else
  85 + email = orcidOrEmail;
  86 + }
  87 +
  88 + return getAuthorizeUri(scopes, state, orcidId, null, null, email, null, true);
  89 + }
  90 +
  91 + /**
  92 + *
  93 + * @param scopes
  94 + * @param state
  95 + * @param familyNames
  96 + * @param givenNames
  97 + * @return
  98 + * @throws Exception
  99 + */
  100 + public String getAuthorizeUri(final List<ScopePathType> scopes, final String state, final String familyNames, final String givenNames) throws Exception {
  101 + return getAuthorizeUri(scopes, state, null, familyNames, givenNames, null, null, false);
  102 + }
  103 +
  104 + /**
  105 + *
  106 + * @param scopes
  107 + * @param state
  108 + * @param orcidId
  109 + * @param familyNames
  110 + * @param givenNames
  111 + * @param email
  112 + * @param lang
  113 + * @param login
  114 + * @return
  115 + * @throws Exception
  116 + */
  117 + private String getAuthorizeUri(final List<ScopePathType> scopes, final String state, final String orcidId, final String familyNames, final String givenNames, final String email, final String lang, final boolean login) throws Exception {
  118 +
  119 + if (scopes == null)
  120 + throw new Exception("Cannot create Authorize Uri - missing scopes");
  121 +
  122 + UriBuilder builder = UriBuilder.fromUri(loginUri);
  123 + builder.path(OrcidConstants.ENDPOINT_OAUTH_AUTHORIZE);
  124 +
  125 + // Required params
  126 + builder.queryParam("client_id", clientId);
  127 + builder.queryParam("scope", ScopePathTypeExt.getScopesAsSingleString(scopes));
  128 + builder.queryParam("response_type", "code");
  129 + builder.queryParam("redirect_uri", redirectUri);
  130 +
  131 + // Optional params
  132 + if (state != null && !"".equals(state))
  133 + builder.queryParam("state", state);
  134 +
  135 + if (orcidId != null && !"".equals(orcidId))
  136 + builder.queryParam("orcid", orcidId);
  137 +
  138 + if (familyNames != null && !"".equals(familyNames))
  139 + builder.queryParam("family_names", familyNames);
  140 +
  141 + if (givenNames != null && !"".equals(givenNames))
  142 + builder.queryParam("given_names", givenNames);
  143 +
  144 + if (email != null && !"".equals(email))
  145 + builder.queryParam("email", email);
  146 +
  147 + if (lang != null && !"".equals(lang))
  148 + builder.queryParam("lang", lang);
  149 +
  150 + builder.queryParam("show_login", login);
  151 +
  152 + _log.debug("[URI] " + builder);
  153 +
  154 + return builder.toString();
  155 + }
  156 +
  157 + /**
  158 + *
  159 + * @param authorizationCode
  160 + * @return
  161 + * @throws OrcidClientException
  162 + */
  163 + public OrcidAccessToken getAccessTokens(final String authorizationCode) throws OrcidClientException {
  164 + MultivaluedMap<String, String> formData = new MultivaluedHashMap<String, String>();
  165 + formData.add("client_id", clientId);
  166 + formData.add("client_secret", clientSecret);
  167 + formData.add("grant_type", "authorization_code");
  168 + formData.add("code", authorizationCode);
  169 +
  170 + return post(authorizationCode, formData).readEntity(OrcidAccessToken.class);
  171 + }
  172 +
  173 +
  174 + /* Activities */
  175 + public ActivitiesSummary readActivitiesSummary(final OrcidAccessToken token) throws OrcidClientException {
  176 + Response response = null;
  177 + try {
  178 + response = get(OrcidConstants.ENDPOINT_ACTIVITIES, token, null);
  179 +
  180 + return response.readEntity(ActivitiesSummary.class);
  181 + } finally {
  182 + if (response != null)
  183 + response.close();
  184 + }
  185 + }
  186 +
  187 + /* Activities - Works */
  188 + public org.um.dsi.gavea.orcid.model.activities.Works readWorksSummary(final OrcidAccessToken token) throws OrcidClientException {
  189 + Response response = null;
  190 + try {
  191 + response = get(OrcidConstants.ENDPOINT_WORKS, token, null);
  192 +
  193 + return response.readEntity(org.um.dsi.gavea.orcid.model.activities.Works.class);
  194 + } finally {
  195 + if (response != null)
  196 + response.close();
  197 + }
  198 + }
  199 +
  200 +
  201 + /* Address */
  202 + public Addresses readAddresses(final OrcidAccessToken token) throws OrcidClientException {
  203 + Response response = null;
  204 + try {
  205 + response = get(OrcidConstants.ENDPOINT_ADDRESS, token, null);
  206 +
  207 + return response.readEntity(Addresses.class);
  208 + } finally {
  209 + if (response != null)
  210 + response.close();
  211 + }
  212 + }
  213 +
  214 + public Address readAddress(final OrcidAccessToken token, final String putCode) throws OrcidClientException {
  215 + Response response = null;
  216 + try {
  217 + response = get(OrcidConstants.ENDPOINT_ADDRESS, token, putCode);
  218 +
  219 + return response.readEntity(Address.class);
  220 + } finally {
  221 + if (response != null)
  222 + response.close();
  223 + }
  224 + }
  225 +
  226 + public void addAddress(final OrcidAccessToken token, Address address) throws OrcidClientException {
  227 + Response response = null;
  228 + try {
  229 + response = post(OrcidConstants.ENDPOINT_ADDRESS, token, Entity.entity(address, MediaType.APPLICATION_XML_TYPE));
  230 + } finally {
  231 + if (response != null)
  232 + response.close();
  233 + }
  234 + }
  235 +
  236 + public void updateAddress(final OrcidAccessToken token, final String putCode, final Address address) throws OrcidClientException {
  237 + Response response = null;
  238 + try {
  239 + response = put(OrcidConstants.ENDPOINT_ADDRESS, token, putCode, Entity.entity(address, MediaType.APPLICATION_XML_TYPE));
  240 + } finally {
  241 + if (response != null)
  242 + response.close();
  243 + }
  244 + }
  245 +
  246 + public void deleteAddress(final OrcidAccessToken token, final String putCode) throws OrcidClientException {
  247 + Response response = null;
  248 + try {
  249 + response = delete(OrcidConstants.ENDPOINT_ADDRESS, token, putCode);
  250 + } finally {
  251 + if (response != null)
  252 + response.close();
  253 + }
  254 + }
  255 +
  256 +
  257 + /* Biography */
  258 + public Biography readBiography(final OrcidAccessToken token) throws OrcidClientException {
  259 + Response response = null;
  260 + try {
  261 + response = get(OrcidConstants.ENDPOINT_BIOGRAPHY, token, null);
  262 +
  263 + return response.readEntity(Biography.class);
  264 + } finally {
  265 + if (response != null)
  266 + response.close();
  267 + }
  268 + }
  269 +
  270 +
  271 + /* Education */
  272 + public Education readEducation(final OrcidAccessToken token, final String putCode) throws OrcidClientException {
  273 + Response response = null;
  274 + try {
  275 + response = get(OrcidConstants.ENDPOINT_EDUCATION, token, putCode);
  276 +
  277 + return response.readEntity(Education.class);
  278 + } finally {
  279 + if (response != null)
  280 + response.close();
  281 + }
  282 + }
  283 +
  284 + public EducationSummary readEducationSummary(final OrcidAccessToken token, final String putCode) throws OrcidClientException {
  285 + Response response = null;
  286 + try {
  287 + response = get(OrcidConstants.ENDPOINT_EDUCATION_SUMMARY, token, putCode);
  288 +
  289 + return response.readEntity(EducationSummary.class);
  290 + } finally {
  291 + if (response != null)
  292 + response.close();
  293 + }
  294 + }
  295 +
  296 + public String addEducation(final OrcidAccessToken token, final Education education) throws OrcidClientException {
  297 + Response response = null;
  298 + try {
  299 + response = post(OrcidConstants.ENDPOINT_EDUCATION, token, Entity.entity(education, MediaType.APPLICATION_XML_TYPE));
  300 +
  301 + return retrievePutCode(response);
  302 + } finally {
  303 + if (response != null)
  304 + response.close();
  305 + }
  306 + }
  307 +
  308 + public void updateEducation(final OrcidAccessToken token, final String putCode, final Education education) throws OrcidClientException {
  309 + Response response = null;
  310 + try {
  311 + response = put(OrcidConstants.ENDPOINT_EDUCATION, token, putCode, Entity.entity(education, MediaType.APPLICATION_XML_TYPE));
  312 + } finally {
  313 + if (response != null)
  314 + response.close();
  315 + }
  316 + }
  317 +
  318 + public void deleteEducation(final OrcidAccessToken token, final String putCode) throws OrcidClientException {
  319 + Response response = null;
  320 + try {
  321 + response = delete(OrcidConstants.ENDPOINT_EDUCATION, token, putCode);
  322 + } finally {
  323 + if (response != null)
  324 + response.close();
  325 + }
  326 + }
  327 +
  328 +
  329 + /* Email */
  330 + public Emails readEmails(final OrcidAccessToken token) throws OrcidClientException {
  331 + Response response = null;
  332 + try {
  333 + response = get(OrcidConstants.ENDPOINT_EMAIL, token, null);
  334 +
  335 + return response.readEntity(Emails.class);
  336 + } finally {
  337 + if (response != null)
  338 + response.close();
  339 + }
  340 + }
  341 +
  342 +
  343 + /* Employment */
  344 + public Employment readEmployment(final OrcidAccessToken token, final String putCode) throws OrcidClientException {
  345 + Response response = null;
  346 + try {
  347 + response = get(OrcidConstants.ENDPOINT_EMPLOYMENT, token, putCode);
  348 +
  349 + return response.readEntity(Employment.class);
  350 + } finally {
  351 + if (response != null)
  352 + response.close();
  353 + }
  354 + }
  355 +
  356 + public EmploymentSummary readEmploymentSummary(final OrcidAccessToken token, final String putCode) throws OrcidClientException {
  357 + Response response = null;
  358 + try {
  359 + response = get(OrcidConstants.ENDPOINT_EMPLOYMENT_SUMMARY, token, putCode);
  360 +
  361 + return response.readEntity(EmploymentSummary.class);
  362 + } finally {
  363 + if (response != null)
  364 + response.close();
  365 + }
  366 + }
  367 +
  368 + public String addEmployment(final OrcidAccessToken token, final Employment employment) throws OrcidClientException {
  369 + Response response = null;
  370 + try {
  371 + response = post(OrcidConstants.ENDPOINT_EMPLOYMENT, token, Entity.entity(employment, MediaType.APPLICATION_XML_TYPE));
  372 +
  373 + return retrievePutCode(response);
  374 + } finally {
  375 + if (response != null)
  376 + response.close();
  377 + }
  378 + }
  379 +
  380 + public void updateEmployment(final OrcidAccessToken token, final String putCode, final Employment employment) throws OrcidClientException {
  381 + Response response = null;
  382 + try {
  383 + response = put(OrcidConstants.ENDPOINT_EMPLOYMENT, token, putCode, Entity.entity(employment, MediaType.APPLICATION_XML_TYPE));
  384 + } finally {
  385 + if (response != null)
  386 + response.close();
  387 + }
  388 + }
  389 +
  390 + public void deleteEmployment(final OrcidAccessToken token, final String putCode) throws OrcidClientException {
  391 + Response response = null;
  392 + try {
  393 + response = delete(OrcidConstants.ENDPOINT_EMPLOYMENT, token, putCode);
  394 + } finally {
  395 + if (response != null)
  396 + response.close();
  397 + }
  398 + }
  399 +
  400 +
  401 + /* External Identifier */
  402 + public ExternalIdentifiers readExternalIdentifiers(final OrcidAccessToken token, final String putCode) throws OrcidClientException {
  403 + Response response = null;
  404 + try {
  405 + response = get(OrcidConstants.ENDPOINT_EXTERNAL_IDENTIFIERS, token, putCode);
  406 +
  407 + return response.readEntity(ExternalIdentifiers.class);
  408 + } finally {
  409 + if (response != null)
  410 + response.close();
  411 + }
  412 + }
  413 +
  414 + public ExternalIdentifier readExternalIdentifier(final OrcidAccessToken token, final String putCode) throws OrcidClientException {
  415 + Response response = null;
  416 + try {
  417 + response = get(OrcidConstants.ENDPOINT_EXTERNAL_IDENTIFIERS, token, putCode);
  418 +
  419 + return response.readEntity(ExternalIdentifier.class);
  420 + } finally {
  421 + if (response != null)
  422 + response.close();
  423 + }
  424 + }
  425 +
  426 + public String addExternalIdentifier(final OrcidAccessToken token, final ExternalIdentifier externalIdentifier) throws OrcidClientException {
  427 + Response response = null;
  428 + try {
  429 + response = post(OrcidConstants.ENDPOINT_EXTERNAL_IDENTIFIERS, token, Entity.entity(externalIdentifier, MediaType.APPLICATION_XML_TYPE));
  430 +
  431 + return retrievePutCode(response);
  432 + } finally {
  433 + if (response != null)
  434 + response.close();
  435 + }
  436 + }
  437 +
  438 + public void updateExternalIdentifier(final OrcidAccessToken token, final String putCode, final ExternalIdentifier externalIdentifier) throws OrcidClientException {
  439 + Response response = null;
  440 + try {
  441 + response = put(OrcidConstants.ENDPOINT_EXTERNAL_IDENTIFIERS, token, putCode, Entity.entity(externalIdentifier, MediaType.APPLICATION_XML_TYPE));
  442 + } finally {
  443 + if (response != null)
  444 + response.close();
  445 + }
  446 + }
  447 +
  448 + public void deleteExternalIdentifier(final OrcidAccessToken token, final String putCode) throws OrcidClientException {
  449 + Response response = null;
  450 + try {
  451 + response = delete(OrcidConstants.ENDPOINT_EXTERNAL_IDENTIFIERS, token, putCode);
  452 + } finally {
  453 + if (response != null)
  454 + response.close();
  455 + }
  456 + }
  457 +
  458 +
  459 + /* Funding */
  460 + public Funding readFunding(final OrcidAccessToken token, final String putCode) throws OrcidClientException {
  461 + Response response = null;
  462 + try {
  463 + response = get(OrcidConstants.ENDPOINT_FUNDING, token, putCode);
  464 +
  465 + return response.readEntity(Funding.class);
  466 + } finally {
  467 + if (response != null)
  468 + response.close();
  469 + }
  470 + }
  471 + public FundingSummary readFundingSummary(final OrcidAccessToken token, final String putCode) throws OrcidClientException {
  472 + Response response = null;
  473 + try {
  474 + response = get(OrcidConstants.ENDPOINT_FUNDING_SUMMARY, token, putCode);
  475 +
  476 + return response.readEntity(FundingSummary.class);
  477 + } finally {
  478 + if (response != null)
  479 + response.close();
  480 + }
  481 + }
  482 +
  483 + public String addFunding(final OrcidAccessToken token, final Funding funding) throws OrcidClientException {
  484 + Response response = null;
  485 + try {
  486 + response = post(OrcidConstants.ENDPOINT_FUNDING, token, Entity.entity(funding, MediaType.APPLICATION_XML_TYPE));
  487 +
  488 + return retrievePutCode(response);
  489 + } finally {
  490 + if (response != null)
  491 + response.close();
  492 + }
  493 + }
  494 +
  495 + public void updateFunding(final OrcidAccessToken token, final String putCode, final Funding funding) throws OrcidClientException {
  496 + Response response = null;
  497 + try {
  498 + response = put(OrcidConstants.ENDPOINT_FUNDING, token, putCode, Entity.entity(funding, MediaType.APPLICATION_XML_TYPE));
  499 + } finally {
  500 + if (response != null)
  501 + response.close();
  502 + }
  503 + }
  504 +
  505 + public void deleteFunding(final OrcidAccessToken token, final String putCode) throws OrcidClientException {
  506 + Response response = null;
  507 + try {
  508 + response = delete(OrcidConstants.ENDPOINT_FUNDING, token, putCode);
  509 + } finally {
  510 + if (response != null)
  511 + response.close();
  512 + }
  513 + }
  514 +
  515 +
  516 + /* Keyword */
  517 + public Keywords readKeywords(final OrcidAccessToken token) throws OrcidClientException {
  518 + Response response = null;
  519 + try {
  520 + response = get(OrcidConstants.ENDPOINT_KEYWORDS, token, null);
  521 +
  522 + return response.readEntity(Keywords.class);
  523 + } finally {
  524 + if (response != null)
  525 + response.close();
  526 + }
  527 + }
  528 +
  529 + public Keyword readKeyword(final OrcidAccessToken token, final String putCode) throws OrcidClientException {
  530 + Response response = null;
  531 + try {
  532 + response = get(OrcidConstants.ENDPOINT_KEYWORDS, token, putCode);
  533 +
  534 + return response.readEntity(Keyword.class);
  535 + } finally {
  536 + if (response != null)
  537 + response.close();
  538 + }
  539 + }
  540 +
  541 + public String addKeyword(final OrcidAccessToken token, final Keyword keyword) throws OrcidClientException {
  542 + Response response = null;
  543 + try {
  544 + response = post(OrcidConstants.ENDPOINT_KEYWORDS, token, Entity.entity(keyword, MediaType.APPLICATION_XML_TYPE));
  545 +
  546 + return retrievePutCode(response);
  547 + } finally {
  548 + if (response != null)
  549 + response.close();
  550 + }
  551 + }
  552 +
  553 + public void updateKeyword(final OrcidAccessToken token, final String putCode, final Keyword keyword) throws OrcidClientException {
  554 + Response response = null;
  555 + try {
  556 + response = put(OrcidConstants.ENDPOINT_KEYWORDS, token, putCode, Entity.entity(keyword, MediaType.APPLICATION_XML_TYPE));
  557 + } finally {
  558 + if (response != null)
  559 + response.close();
  560 + }
  561 + }
  562 +
  563 + public void deleteKeyword(final OrcidAccessToken token, final String putCode) throws OrcidClientException {
  564 + Response response = null;
  565 + try {
  566 + response = delete(OrcidConstants.ENDPOINT_KEYWORDS, token, putCode);
  567 + } finally {
  568 + if (response != null)
  569 + response.close();
  570 + }
  571 + }
  572 +
  573 +
  574 + /* Other Name */
  575 + public OtherNames readOtherNames(final OrcidAccessToken token) throws OrcidClientException {
  576 + Response response = null;
  577 + try {
  578 + response = get(OrcidConstants.ENDPOINT_OTHER_NAMES, token, null);
  579 +
  580 + return response.readEntity(OtherNames.class);
  581 + } finally {
  582 + if (response != null)
  583 + response.close();
  584 + }
  585 + }
  586 +
  587 + public OtherName readOtherName(final OrcidAccessToken token, final String putCode) throws OrcidClientException {
  588 + Response response = null;
  589 + try {
  590 + response = get(OrcidConstants.ENDPOINT_OTHER_NAMES, token, putCode);
  591 +
  592 + return response.readEntity(OtherName.class);
  593 + } finally {
  594 + if (response != null)
  595 + response.close();
  596 + }
  597 + }
  598 +
  599 + public String addOtherName(final OrcidAccessToken token, final OtherName otherName) throws OrcidClientException {
  600 + Response response = null;
  601 + try {
  602 + response = post(OrcidConstants.ENDPOINT_OTHER_NAMES, token, Entity.entity(otherName, MediaType.APPLICATION_XML_TYPE));
  603 +
  604 + return retrievePutCode(response);
  605 + } finally {
  606 + if (response != null)
  607 + response.close();
  608 + }
  609 + }
  610 +
  611 + public void updateOtherName(final OrcidAccessToken token, final String putCode, final OtherName otherName) throws OrcidClientException {
  612 + Response response = null;
  613 + try {
  614 + response = put(OrcidConstants.ENDPOINT_OTHER_NAMES, token, putCode, Entity.entity(otherName, MediaType.APPLICATION_XML_TYPE));
  615 + } finally {
  616 + if (response != null)
  617 + response.close();
  618 + }
  619 + }
  620 +
  621 + public void deleteOtherName(final OrcidAccessToken token, final String putCode) throws OrcidClientException {
  622 + Response response = null;
  623 + try {
  624 + response = delete(OrcidConstants.ENDPOINT_OTHER_NAMES, token, putCode);
  625 + } finally {
  626 + if (response != null)
  627 + response.close();
  628 + }
  629 + }
  630 +
  631 +
  632 + /* Peer Review */
  633 + public PeerReview readPeerReview(final OrcidAccessToken token, final String putCode) throws OrcidClientException {
  634 + Response response = null;
  635 + try {
  636 + response = get(OrcidConstants.ENDPOINT_PEERREVIEW, token, putCode);
  637 +
  638 + return response.readEntity(PeerReview.class);
  639 + } finally {
  640 + if (response != null)
  641 + response.close();
  642 + }
  643 + }
  644 + public PeerReviewSummary readPeerReviewSummary(final OrcidAccessToken token, final String putCode) throws OrcidClientException {
  645 + Response response = null;
  646 + try {
  647 + response = get(OrcidConstants.ENDPOINT_PEERREVIEW_SUMMARY, token, putCode);
  648 +
  649 + return response.readEntity(PeerReviewSummary.class);
  650 + } finally {
  651 + if (response != null)
  652 + response.close();
  653 + }
  654 + }
  655 +
  656 + public String addPeerReview(final OrcidAccessToken token, final PeerReview peerReview) throws OrcidClientException {
  657 + Response response = null;
  658 + try {
  659 + response = post(OrcidConstants.ENDPOINT_PEERREVIEW, token, Entity.entity(peerReview, MediaType.APPLICATION_XML_TYPE));
  660 +
  661 + return retrievePutCode(response);
  662 + } finally {
  663 + if (response != null)