Commit d42c083b91cd0e69fea8a1d3d1ac722f62b90ebe

Authored by Ricardo Pereira
Exists in master and in 1 other branch API_v3.0

merge

.gitignore
1   -# Java related
2   -target/**
3   -*.jar
4   -*.war
5   -*.ear
6   -*.class
7   -
8   -# eclipse specific
9   -.project
10   -.metadata
11   -bin/**
12   -tmp/**
13   -tmp/**/*
14   -*.tmp
15   -*.bak
16   -*.swp
17   -.classpath
18   -.settings/
19   -.loadpath
  1 +/bin/
  2 +
  3 +# Eclipse files
  4 +.classpath
  5 +.project
  6 +.settings/
  7 +/target/
... ...
pom.xml
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.28</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.inject</groupId>
28   - <artifactId>jersey-hk2</artifactId>
29   - <version>${jersey.version}</version>
30   - </dependency>
31   - <dependency>
32   - <groupId>org.glassfish.jersey.containers</groupId>
33   - <artifactId>jersey-container-servlet</artifactId>
34   - <version>${jersey.version}</version>
35   - </dependency>
36   - <dependency>
37   - <groupId>org.glassfish.jersey.media</groupId>
38   - <artifactId>jersey-media-json-jackson</artifactId>
39   - <version>${jersey.version}</version>
40   - </dependency>
41   - <dependency>
42   - <groupId>org.glassfish.jersey.media</groupId>
43   - <artifactId>jersey-media-jaxb</artifactId>
44   - <version>${jersey.version}</version>
45   - </dependency>
46   - <!-- JAXB2 Commons -->
47   - <dependency>
48   - <groupId>org.jvnet.jaxb2_commons</groupId>
49   - <artifactId>jaxb2-basics-runtime</artifactId>
50   - <version>${jaxb2-basics.version}</version>
51   - </dependency>
52   - <!-- Logging -->
53   - <dependency>
54   - <groupId>ch.qos.logback</groupId>
55   - <artifactId>logback-classic</artifactId>
56   - <version>${logback-version}</version>
57   - </dependency>
58   - <!-- JUnit -->
59   - <dependency>
60   - <groupId>junit</groupId>
61   - <artifactId>junit</artifactId>
62   - <version>${junit.version}</version>
63   - <scope>test</scope>
64   - </dependency>
65   - </dependencies>
66   -
67   - <build>
68   - <plugins>
69   - <plugin>
70   - <groupId>org.jvnet.jaxb2.maven2</groupId>
71   - <artifactId>maven-jaxb2-plugin</artifactId>
72   - <version>0.13.1</version>
73   - <executions>
74   - <execution>
75   - <goals>
76   - <goal>generate</goal>
77   - </goals>
78   - </execution>
79   - </executions>
80   - <configuration>
81   - <noFileHeader>true</noFileHeader>
82   - <generateDirectory>${project.build.directory}/generated-sources</generateDirectory>
83   - <bindingDirectory>${basedir}/src/main/resources/binding</bindingDirectory>
84   - <schemaDirectory>${basedir}/src/main/resources/xsd</schemaDirectory>
85   - <schemaIncludes>
86   - <include>common_2.0/*.xsd</include>
87   - <include>record_2.0/*.xsd</include>
88   - </schemaIncludes>
89   - <episode>false</episode>
90   - <args>
91   - <arg>-Xsetters</arg>
92   - <arg>-Xvalue-constructor</arg>
93   - <arg>-XtoString</arg>
94   - <arg>-extension</arg>
95   - <arg>-Xnamespace-prefix</arg>
96   - </args>
97   - </configuration>
98   - <dependencies>
99   - <dependency>
100   - <groupId>org.glassfish.jaxb</groupId>
101   - <artifactId>jaxb-core</artifactId>
102   - <version>2.2.11</version>
103   - </dependency>
104   - <dependency>
105   - <groupId>org.jvnet.jaxb2_commons</groupId>
106   - <artifactId>jaxb2-basics</artifactId>
107   - <version>${jaxb2-basics.version}</version>
108   - </dependency>
109   - <dependency>
110   - <groupId>org.jvnet.jaxb2_commons</groupId>
111   - <artifactId>jaxb2-value-constructor</artifactId>
112   - <version>3.0</version>
113   - </dependency>
114   - <dependency>
115   - <groupId>org.jvnet.jaxb2_commons</groupId>
116   - <artifactId>jaxb2-namespace-prefix</artifactId>
117   - <version>1.1</version>
118   - </dependency>
119   - </dependencies>
120   - </plugin>
121   - <plugin>
122   - <groupId>org.apache.maven.plugins</groupId>
123   - <artifactId>maven-compiler-plugin</artifactId>
124   - <version>3.3</version>
125   - <inherited>true</inherited>
126   - <configuration>
127   - <source>${java.version}</source>
128   - <target>${java.version}</target>
129   - </configuration>
130   - </plugin>
131   - <plugin>
132   - <groupId>org.apache.maven.plugins</groupId>
133   - <artifactId>maven-surefire-plugin</artifactId>
134   - <version>2.19.1</version>
135   - <configuration>
136   - <skipTests>true</skipTests>
137   - </configuration>
138   - </plugin>
139   - </plugins>
140   - </build>
141   -
  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-1-SNAPSHOT</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.3</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 +
142 137 </project>
143 138 \ No newline at end of file
... ...
src/main/java/org/um/dsi/gavea/orcid/client/BaseOrcidOAuthClient.java
... ... @@ -11,11 +11,9 @@ import javax.ws.rs.core.MediaType;
11 11 import javax.ws.rs.core.MultivaluedMap;
12 12 import javax.ws.rs.core.Response;
13 13  
14   -import org.glassfish.jersey.client.ClientProperties;
15   -import org.glassfish.jersey.jackson.JacksonFeature;
16 14 import org.slf4j.Logger;
17 15 import org.slf4j.LoggerFactory;
18   -import org.um.dsi.gavea.orcid.client.configurator.JacksonConfigurator;
  16 +import org.glassfish.jersey.client.ClientProperties;
19 17 import org.um.dsi.gavea.orcid.client.constants.OrcidConstants;
20 18 import org.um.dsi.gavea.orcid.client.exception.OrcidClientException;
21 19 import org.um.dsi.gavea.orcid.client.util.RecordUtil;
... ... @@ -76,7 +74,8 @@ public class BaseOrcidOAuthClient implements Serializable {
76 74 return response;
77 75 }
78 76  
79   - protected <T> Response post(final String authorizationCode, final MultivaluedMap<String, String> formData) throws OrcidClientException {
  77 + protected <T> Response post(final String authorizationCode, final MultivaluedMap<String, String> formData)
  78 + throws OrcidClientException {
80 79 createConnection(OrcidConstants.ENDPOINT_OAUTH_TOKEN, null, null);
81 80  
82 81 if (debugMode || _log.isTraceEnabled()) {
... ... @@ -85,7 +84,7 @@ public class BaseOrcidOAuthClient implements Serializable {
85 84 Response response = target.request(MediaType.APPLICATION_JSON_TYPE).post(Entity.form(formData));
86 85 _log.debug("[getAccessTokens][post].[Response.Status] " + response.getStatus());
87 86 _log.debug("[getAccessTokens][post].[Response.Reason] " + response.getStatusInfo().getReasonPhrase());
88   -
  87 +
89 88 exceptionBuilder(response);
90 89  
91 90 return response;
... ... @@ -101,7 +100,8 @@ public class BaseOrcidOAuthClient implements Serializable {
101 100 _log.debug("[post].[Request.entity] " + RecordUtil.convertToString(entity.getEntity()));
102 101 }
103 102  
104   - response = target.request(OrcidConstants.APPLICATION_ORCID_XML).header("Authorization", "Bearer" + token.getAccess_token()).post(entity);
  103 + response = target.request(OrcidConstants.APPLICATION_ORCID_XML)
  104 + .header("Authorization", "Bearer" + token.getAccess_token()).post(entity);
105 105 _log.debug("[post].[Response.Status] " + response.getStatus());
106 106 _log.debug("[post].[Response.Reason] " + response.getStatusInfo().getReasonPhrase());
107 107  
... ... @@ -124,7 +124,8 @@ public class BaseOrcidOAuthClient implements Serializable {
124 124 _log.debug("[put].[Request.entity] " + RecordUtil.convertToString(entity.getEntity()));
125 125 }
126 126  
127   - response = target.request(OrcidConstants.APPLICATION_ORCID_XML).header("Authorization", "Bearer" + token.getAccess_token()).put(entity);
  127 + response = target.request(OrcidConstants.APPLICATION_ORCID_XML)
  128 + .header("Authorization", "Bearer" + token.getAccess_token()).put(entity);
128 129 _log.debug("[put].[Response.Status] " + response.getStatus());
129 130 _log.debug("[put].[Response.Reason] " + response.getStatusInfo().getReasonPhrase());
130 131  
... ... @@ -143,7 +144,8 @@ public class BaseOrcidOAuthClient implements Serializable {
143 144 try {
144 145 createConnection(endpoint, token.getOrcid(), putCode);
145 146  
146   - response = target.request(OrcidConstants.APPLICATION_ORCID_XML).header("Authorization", "Bearer" + token.getAccess_token()).delete();
  147 + response = target.request(OrcidConstants.APPLICATION_ORCID_XML)
  148 + .header("Authorization", "Bearer" + token.getAccess_token()).delete();
147 149 _log.debug("[delete].[Response.Status] " + response.getStatus());
148 150 _log.debug("[delete].[Response.Reason] " + response.getStatusInfo().getReasonPhrase());
149 151  
... ... @@ -161,8 +163,6 @@ public class BaseOrcidOAuthClient implements Serializable {
161 163 restClient = ClientBuilder.newClient();
162 164 restClient.property(ClientProperties.CONNECT_TIMEOUT, OrcidConstants.CLIENT_CONNECT_TIMEOUT);
163 165 restClient.property(ClientProperties.READ_TIMEOUT, OrcidConstants.CLIENT_READ_TIMEOUT);
164   - restClient.register(JacksonFeature.class);
165   - restClient.register(JacksonConfigurator.class);
166 166 }
167 167  
168 168 target = restClient.target(apiUri).path(buildPath(endpoint, orcidId, putCode));
... ... @@ -192,12 +192,11 @@ public class BaseOrcidOAuthClient implements Serializable {
192 192 if (response.getStatus() > 300) {
193 193 if (response.getStatus() == 400) {
194 194 Error error = response.readEntity(Error.class);
195   - if(error.getUserMessage() != null || error.getErrorCode() != null || error.getDeveloperMessage() != null)
196   - throw new OrcidClientException(error.getResponseCode(), error.getUserMessage(), error.getErrorCode(), error.getDeveloperMessage());
197   - else
198   - throw new OrcidClientException(response.getStatus(), response.getStatus() + " - " + response.getStatusInfo().getReasonPhrase());
  195 + throw new OrcidClientException(error.getResponseCode(), error.getUserMessage(), error.getErrorCode(),
  196 + error.getDeveloperMessage());
199 197 } else
200   - throw new OrcidClientException(response.getStatus(), response.getStatus() + " - " + response.getStatusInfo().getReasonPhrase());
  198 + throw new OrcidClientException(response.getStatus(),
  199 + response.getStatus() + " - " + response.getStatusInfo().getReasonPhrase());
201 200 }
202 201 }
203 202  
... ...
src/main/java/org/um/dsi/gavea/orcid/client/OrcidOAuthClient.java
... ... @@ -16,7 +16,6 @@ import org.slf4j.LoggerFactory;
16 16 import org.um.dsi.gavea.orcid.client.constants.OrcidConstants;
17 17 import org.um.dsi.gavea.orcid.client.exception.OrcidClientException;
18 18 import org.um.dsi.gavea.orcid.client.extend.ScopePathTypeExt;
19   -import org.um.dsi.gavea.orcid.client.util.RecordUtil;
20 19 import org.um.dsi.gavea.orcid.model.activities.ActivitiesSummary;
21 20 import org.um.dsi.gavea.orcid.model.activities.Fundings;
22 21 import org.um.dsi.gavea.orcid.model.activities.Works;
... ... @@ -193,13 +192,7 @@ public class OrcidOAuthClient extends BaseOrcidOAuthClient {
193 192 try {
194 193 response = get(OrcidConstants.ENDPOINT_WORKS, token, null);
195 194  
196   - Works works = response.readEntity(Works.class);
197   -
198   - if (debugMode || _log.isTraceEnabled()) {
199   - _log.debug("[readWorksSummary].[Works] " + RecordUtil.convertToString(works));
200   - }
201   -
202   - return works;
  195 + return response.readEntity(Works.class);
203 196 } finally {
204 197 if (response != null)
205 198 response.close();
... ... @@ -212,13 +205,7 @@ public class OrcidOAuthClient extends BaseOrcidOAuthClient {
212 205 try {
213 206 response = get(OrcidConstants.ENDPOINT_FUNDINGS, token, null);
214 207  
215   - Fundings fundings = response.readEntity(Fundings.class);
216   -
217   - if (debugMode || _log.isTraceEnabled()) {
218   - _log.debug("[readFundingsSummary].[Fundings] " + RecordUtil.convertToString(fundings));
219   - }
220   -
221   - return fundings;
  208 + return response.readEntity(Fundings.class);
222 209 } finally {
223 210 if (response != null)
224 211 response.close();
... ... @@ -490,13 +477,7 @@ public class OrcidOAuthClient extends BaseOrcidOAuthClient {
490 477 try {
491 478 response = get(OrcidConstants.ENDPOINT_FUNDING, token, putCode);
492 479  
493   - Funding funding = response.readEntity(Funding.class);
494   -
495   - if (debugMode || _log.isTraceEnabled()) {
496   - _log.debug("[readFunding].[Funding] " + RecordUtil.convertToString(funding));
497   - }
498   -
499   - return funding;
  480 + return response.readEntity(Funding.class);
500 481 } finally {
501 482 if (response != null)
502 483 response.close();
... ... @@ -812,13 +793,7 @@ public class OrcidOAuthClient extends BaseOrcidOAuthClient {
812 793 try {
813 794 response = get(OrcidConstants.ENDPOINT_WORK, token, putCode);
814 795  
815   - Work work = response.readEntity(Work.class);
816   -
817   - if (debugMode || _log.isTraceEnabled()) {
818   - _log.debug("[readWork].[Work] " + RecordUtil.convertToString(work));
819   - }
820   -
821   - return work;
  796 + return response.readEntity(Work.class);
822 797 } finally {
823 798 if (response != null)
824 799 response.close();
... ... @@ -830,19 +805,15 @@ public class OrcidOAuthClient extends BaseOrcidOAuthClient {
830 805 try {
831 806 response = get(OrcidConstants.ENDPOINT_WORKS, token, StringUtils.join(putCodes.iterator(), ","));
832 807  
833   - Bulk bulk = response.readEntity(Bulk.class);
834   -
835   - if (debugMode || _log.isTraceEnabled()) {
836   - _log.debug("[readWorks].[Bulk] " + RecordUtil.convertToString(bulk));
837   - }
838   -
839   - return bulk;
  808 + return response.readEntity(Bulk.class);
840 809 } finally {
841 810 if (response != null)
842 811 response.close();
843 812 }
844 813 }
845 814  
  815 +
  816 +
846 817 public WorkSummary readWorkSummary(final OrcidAccessToken token, final String putCode) throws OrcidClientException {
847 818 Response response = null;
848 819 try {
... ... @@ -924,4 +895,4 @@ public class OrcidOAuthClient extends BaseOrcidOAuthClient {
924 895 private boolean isValidOrcidId(final String value) {
925 896 return value.matches("([0-9]{4})-([0-9]{4})-([0-9]{4})-([0-9]{3})(?:[0-9X]{1})");
926 897 }
927   -}
928 898 \ No newline at end of file
  899 +}
... ...
src/main/java/org/um/dsi/gavea/orcid/client/configurator/JacksonConfigurator.java
... ... @@ -1,34 +0,0 @@
1   -/**
2   - * Universidade do Minho
3   - * Departamento de Sistemas de Informação
4   - * Grupo Gávea
5   - */
6   -package org.um.dsi.gavea.orcid.client.configurator;
7   -
8   -import javax.ws.rs.ext.ContextResolver;
9   -import javax.ws.rs.ext.Provider;
10   -
11   -import com.fasterxml.jackson.databind.DeserializationFeature;
12   -import com.fasterxml.jackson.databind.ObjectMapper;
13   -
14   -/**
15   -* @author Luís Pedro
16   -*
17   -* Created: 10 Oct 2018 - 15:27:59
18   -*/
19   -@Provider
20   -public class JacksonConfigurator implements ContextResolver<ObjectMapper> {
21   -
22   - private final ObjectMapper mapper;
23   -
24   - public JacksonConfigurator() {
25   - mapper = new ObjectMapper();
26   - mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
27   - }
28   -
29   - @Override
30   - public ObjectMapper getContext(Class<?> type) {
31   - return mapper;
32   - }
33   -
34   -}
src/main/java/org/um/dsi/gavea/orcid/client/constants/OrcidConstants.java
... ... @@ -39,6 +39,6 @@ public final class OrcidConstants {
39 39 public final static String APPLICATION_ORCID_XML = "application/orcid+xml";
40 40 public final static MediaType APPLICATION_ORCID_XML_TYPE = new MediaType("application", "orcid+xml");
41 41  
42   - public final static String CLIENT_READ_TIMEOUT = "120000";
43   - public final static String CLIENT_CONNECT_TIMEOUT = "15000";
  42 + public final static String CLIENT_READ_TIMEOUT = "8000";
  43 + public final static String CLIENT_CONNECT_TIMEOUT = "8000";
44 44 }
... ...