Compare View

switch
from
...
to
 
Commits (29)
.gitignore
1   -/bin/
2   -
3   -# Eclipse files
4   -.classpath
5   -.project
6   -.settings/
7   -/target/
  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
... ...
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-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   -
  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 +
137 142 </project>
138 143 \ No newline at end of file
... ...
src/main/java/org/um/dsi/gavea/orcid/client/BaseOrcidOAuthClient.java
... ... @@ -11,9 +11,11 @@ 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;
14 16 import org.slf4j.Logger;
15 17 import org.slf4j.LoggerFactory;
16   -import org.glassfish.jersey.client.ClientProperties;
  18 +import org.um.dsi.gavea.orcid.client.configurator.JacksonConfigurator;
17 19 import org.um.dsi.gavea.orcid.client.constants.OrcidConstants;
18 20 import org.um.dsi.gavea.orcid.client.exception.OrcidClientException;
19 21 import org.um.dsi.gavea.orcid.client.util.RecordUtil;
... ... @@ -74,8 +76,7 @@ public class BaseOrcidOAuthClient implements Serializable {
74 76 return response;
75 77 }
76 78  
77   - protected <T> Response post(final String authorizationCode, final MultivaluedMap<String, String> formData)
78   - throws OrcidClientException {
  79 + protected <T> Response post(final String authorizationCode, final MultivaluedMap<String, String> formData) throws OrcidClientException {
79 80 createConnection(OrcidConstants.ENDPOINT_OAUTH_TOKEN, null, null);
80 81  
81 82 if (debugMode || _log.isTraceEnabled()) {
... ... @@ -84,7 +85,7 @@ public class BaseOrcidOAuthClient implements Serializable {
84 85 Response response = target.request(MediaType.APPLICATION_JSON_TYPE).post(Entity.form(formData));
85 86 _log.debug("[getAccessTokens][post].[Response.Status] " + response.getStatus());
86 87 _log.debug("[getAccessTokens][post].[Response.Reason] " + response.getStatusInfo().getReasonPhrase());
87   -
  88 +
88 89 exceptionBuilder(response);
89 90  
90 91 return response;
... ... @@ -100,8 +101,7 @@ public class BaseOrcidOAuthClient implements Serializable {
100 101 _log.debug("[post].[Request.entity] " + RecordUtil.convertToString(entity.getEntity()));
101 102 }
102 103  
103   - response = target.request(OrcidConstants.APPLICATION_ORCID_XML)
104   - .header("Authorization", "Bearer" + token.getAccess_token()).post(entity);
  104 + response = target.request(OrcidConstants.APPLICATION_ORCID_XML).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,8 +124,7 @@ 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)
128   - .header("Authorization", "Bearer" + token.getAccess_token()).put(entity);
  127 + response = target.request(OrcidConstants.APPLICATION_ORCID_XML).header("Authorization", "Bearer" + token.getAccess_token()).put(entity);
129 128 _log.debug("[put].[Response.Status] " + response.getStatus());
130 129 _log.debug("[put].[Response.Reason] " + response.getStatusInfo().getReasonPhrase());
131 130  
... ... @@ -144,8 +143,7 @@ public class BaseOrcidOAuthClient implements Serializable {
144 143 try {
145 144 createConnection(endpoint, token.getOrcid(), putCode);
146 145  
147   - response = target.request(OrcidConstants.APPLICATION_ORCID_XML)
148   - .header("Authorization", "Bearer" + token.getAccess_token()).delete();
  146 + response = target.request(OrcidConstants.APPLICATION_ORCID_XML).header("Authorization", "Bearer" + token.getAccess_token()).delete();
149 147 _log.debug("[delete].[Response.Status] " + response.getStatus());
150 148 _log.debug("[delete].[Response.Reason] " + response.getStatusInfo().getReasonPhrase());
151 149  
... ... @@ -163,6 +161,8 @@ public class BaseOrcidOAuthClient implements Serializable {
163 161 restClient = ClientBuilder.newClient();
164 162 restClient.property(ClientProperties.CONNECT_TIMEOUT, OrcidConstants.CLIENT_CONNECT_TIMEOUT);
165 163 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,11 +192,12 @@ 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   - throw new OrcidClientException(error.getResponseCode(), error.getUserMessage(), error.getErrorCode(),
196   - error.getDeveloperMessage());
  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());
197 199 } else
198   - throw new OrcidClientException(response.getStatus(),
199   - response.getStatus() + " - " + response.getStatusInfo().getReasonPhrase());
  200 + throw new OrcidClientException(response.getStatus(), response.getStatus() + " - " + response.getStatusInfo().getReasonPhrase());
200 201 }
201 202 }
202 203  
... ...
src/main/java/org/um/dsi/gavea/orcid/client/OrcidOAuthClient.java
... ... @@ -16,6 +16,7 @@ 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;
19 20 import org.um.dsi.gavea.orcid.model.activities.ActivitiesSummary;
20 21 import org.um.dsi.gavea.orcid.model.activities.Fundings;
21 22 import org.um.dsi.gavea.orcid.model.activities.Works;
... ... @@ -192,7 +193,13 @@ public class OrcidOAuthClient extends BaseOrcidOAuthClient {
192 193 try {
193 194 response = get(OrcidConstants.ENDPOINT_WORKS, token, null);
194 195  
195   - return response.readEntity(Works.class);
  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;
196 203 } finally {
197 204 if (response != null)
198 205 response.close();
... ... @@ -205,7 +212,13 @@ public class OrcidOAuthClient extends BaseOrcidOAuthClient {
205 212 try {
206 213 response = get(OrcidConstants.ENDPOINT_FUNDINGS, token, null);
207 214  
208   - return response.readEntity(Fundings.class);
  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;
209 222 } finally {
210 223 if (response != null)
211 224 response.close();
... ... @@ -477,7 +490,13 @@ public class OrcidOAuthClient extends BaseOrcidOAuthClient {
477 490 try {
478 491 response = get(OrcidConstants.ENDPOINT_FUNDING, token, putCode);
479 492  
480   - return response.readEntity(Funding.class);
  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;
481 500 } finally {
482 501 if (response != null)
483 502 response.close();
... ... @@ -793,7 +812,13 @@ public class OrcidOAuthClient extends BaseOrcidOAuthClient {
793 812 try {
794 813 response = get(OrcidConstants.ENDPOINT_WORK, token, putCode);
795 814  
796   - return response.readEntity(Work.class);
  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;
797 822 } finally {
798 823 if (response != null)
799 824 response.close();
... ... @@ -805,15 +830,19 @@ public class OrcidOAuthClient extends BaseOrcidOAuthClient {
805 830 try {
806 831 response = get(OrcidConstants.ENDPOINT_WORKS, token, StringUtils.join(putCodes.iterator(), ","));
807 832  
808   - return response.readEntity(Bulk.class);
  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;
809 840 } finally {
810 841 if (response != null)
811 842 response.close();
812 843 }
813 844 }
814 845  
815   -
816   -
817 846 public WorkSummary readWorkSummary(final OrcidAccessToken token, final String putCode) throws OrcidClientException {
818 847 Response response = null;
819 848 try {
... ... @@ -895,4 +924,4 @@ public class OrcidOAuthClient extends BaseOrcidOAuthClient {
895 924 private boolean isValidOrcidId(final String value) {
896 925 return value.matches("([0-9]{4})-([0-9]{4})-([0-9]{4})-([0-9]{3})(?:[0-9X]{1})");
897 926 }
898   -}
  927 +}
899 928 \ No newline at end of file
... ...
src/main/java/org/um/dsi/gavea/orcid/client/configurator/JacksonConfigurator.java
... ... @@ -0,0 +1,34 @@
  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 = "8000";
43   - public final static String CLIENT_CONNECT_TIMEOUT = "8000";
  42 + public final static String CLIENT_READ_TIMEOUT = "120000";
  43 + public final static String CLIENT_CONNECT_TIMEOUT = "15000";
44 44 }
... ...