Skip to content

Commit 047ae06

Browse files
committed
Updates for identity dates, accounting & bankfeeds
Identity - update and create date issue This was accomplished using "LocalDateTime" instead of "OffsetDatetime" and a custom date deserializer class. The OpenApi spec introduced a new vendor extension - x-format at the proprty level which allows for over riding the default datatype used by the type:stirng and format: date. Accounting -remove createLinkedTransactions as bulk create is not supported BankFeeds and Fixed Assets - add XeroApiExceptionHander for errors when parsing HttpResponses - Change case for tenant id param to Xero-Tenant-Id - Headers passed as params are now being set properly.
1 parent 997ed80 commit 047ae06

113 files changed

Lines changed: 320 additions & 302 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<artifactId>xero-java</artifactId>
66
<packaging>jar</packaging>
77
<name>xero-java</name>
8-
<version>3.1.6</version>
8+
<version>3.1.7</version>
99
<url>https://github.com/XeroAPI/Xero-Java</url>
1010
<description>This is the official Java SDK for Xero API</description>
1111
<licenses>
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package com.xero.api;
2+
3+
import java.io.IOException;
4+
5+
import org.threeten.bp.*;
6+
import org.threeten.bp.format.DateTimeFormatter;
7+
import org.threeten.bp.format.DateTimeFormatterBuilder;
8+
9+
import com.fasterxml.jackson.core.JsonParser;
10+
import com.fasterxml.jackson.core.JsonProcessingException;
11+
import com.fasterxml.jackson.databind.DeserializationContext;
12+
import com.fasterxml.jackson.databind.deser.std.StdDeserializer;
13+
14+
public class CustomLocalDateTimeDeserializer extends StdDeserializer<LocalDateTime> {
15+
private static final long serialVersionUID = 1L;
16+
17+
public CustomLocalDateTimeDeserializer() {
18+
this(null);
19+
}
20+
21+
public CustomLocalDateTimeDeserializer(Class<?> vc) {
22+
super(vc);
23+
}
24+
25+
public LocalDateTime deserialize(JsonParser jsonparser, DeserializationContext context)
26+
throws IOException, JsonProcessingException {
27+
28+
DateTimeFormatter formatter = new DateTimeFormatterBuilder()
29+
// here is the same as your code
30+
.append(DateTimeFormatter.ISO_DATE_TIME)
31+
// create formatter
32+
.toFormatter();
33+
34+
LocalDateTime formatted = null;
35+
String dateString = jsonparser.getText();
36+
37+
if (dateString.isEmpty()) {
38+
throw new IllegalArgumentException("date object null");
39+
}
40+
formatted = LocalDateTime.parse(dateString, formatter);
41+
42+
return formatted;
43+
}
44+
}

src/main/java/com/xero/api/client/AccountingApi.java

Lines changed: 2 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public class AccountingApi {
9999
private ApiClient apiClient;
100100
private static AccountingApi instance = null;
101101
private String userAgent = "Default";
102-
private String version = "3.1.6";
102+
private String version = "3.1.7";
103103

104104
public AccountingApi() {
105105
this(new ApiClient());
@@ -2384,62 +2384,6 @@ public HttpResponse createLinkedTransactionForHttpResponse(String accessToken,
23842384
return requestFactory.buildRequest(HttpMethods.PUT, genericUrl, content).setHeaders(headers).execute();
23852385
}
23862386

2387-
/**
2388-
* Allows you to create linked transactions (billable expenses)
2389-
* <p><b>200</b> - Success - return response of type LinkedTransactions array with newly created LinkedTransaction
2390-
* <p><b>400</b> - A failed request due to validation error
2391-
* @param xeroTenantId Xero identifier for Tenant
2392-
* @param linkedTransactions The linkedTransactions parameter
2393-
* @param accessToken Authorization token for user set in header of each request
2394-
* @return LinkedTransactions
2395-
* @throws IOException if an error occurs while attempting to invoke the API
2396-
**/
2397-
public LinkedTransactions createLinkedTransactions(String accessToken, String xeroTenantId, LinkedTransactions linkedTransactions) throws IOException {
2398-
try {
2399-
TypeReference<LinkedTransactions> typeRef = new TypeReference<LinkedTransactions>() {};
2400-
HttpResponse response = createLinkedTransactionsForHttpResponse(accessToken, xeroTenantId, linkedTransactions);
2401-
return apiClient.getObjectMapper().readValue(response.getContent(), typeRef);
2402-
} catch (HttpResponseException e) {
2403-
XeroApiExceptionHandler handler = new XeroApiExceptionHandler();
2404-
handler.execute(e,apiClient);
2405-
} catch (IOException ioe) {
2406-
throw ioe;
2407-
}
2408-
return null;
2409-
}
2410-
2411-
public HttpResponse createLinkedTransactionsForHttpResponse(String accessToken, String xeroTenantId, LinkedTransactions linkedTransactions) throws IOException {
2412-
// verify the required parameter 'xeroTenantId' is set
2413-
if (xeroTenantId == null) {
2414-
throw new IllegalArgumentException("Missing the required parameter 'xeroTenantId' when calling createLinkedTransactions");
2415-
}// verify the required parameter 'linkedTransactions' is set
2416-
if (linkedTransactions == null) {
2417-
throw new IllegalArgumentException("Missing the required parameter 'linkedTransactions' when calling createLinkedTransactions");
2418-
}
2419-
if (accessToken == null) {
2420-
throw new IllegalArgumentException("Missing the required parameter 'accessToken' when calling createLinkedTransactions");
2421-
}
2422-
HttpHeaders headers = new HttpHeaders();
2423-
headers.set("xero-tenant-id", xeroTenantId);
2424-
headers.setAccept("application/json");
2425-
headers.setUserAgent(this.getUserAgent());
2426-
2427-
String correctPath = "/LinkedTransactions";
2428-
UriBuilder uriBuilder = UriBuilder.fromUri(apiClient.getBasePath() + correctPath);
2429-
String url = uriBuilder.build().toString();
2430-
GenericUrl genericUrl = new GenericUrl(url);
2431-
2432-
2433-
HttpContent content = null;
2434-
content = apiClient.new JacksonJsonHttpContent(linkedTransactions);
2435-
2436-
Credential credential = new Credential(BearerToken.authorizationHeaderAccessMethod()).setAccessToken(accessToken);
2437-
HttpTransport transport = apiClient.getHttpTransport();
2438-
HttpRequestFactory requestFactory = transport.createRequestFactory(credential);
2439-
2440-
return requestFactory.buildRequest(HttpMethods.POST, genericUrl, content).setHeaders(headers).execute();
2441-
}
2442-
24432387
/**
24442388
* Allows you to create a manual journal
24452389
* <p><b>200</b> - Success - return response of type ManualJournals array with newly created ManualJournal
@@ -3181,7 +3125,7 @@ public HttpResponse createPrepaymentHistoryForHttpResponse(String accessToken,
31813125
}
31823126

31833127
/**
3184-
* Allows you to create purchase orders
3128+
* Allows you to create a single purchase order
31853129
* <p><b>200</b> - Success - return response of type PurchaseOrder array for specified PurchaseOrder
31863130
* <p><b>400</b> - A failed request due to validation error
31873131
* @param xeroTenantId Xero identifier for Tenant

src/main/java/com/xero/api/client/AssetApi.java

Lines changed: 49 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public class AssetApi {
4444
private ApiClient apiClient;
4545
private static AssetApi instance = null;
4646
private String userAgent = "Default";
47-
private String version = "3.1.6";
47+
private String version = "3.1.7";
4848

4949
public AssetApi() {
5050
this(new ApiClient());
@@ -88,19 +88,21 @@ public String getUserAgent() {
8888
* @return Asset
8989
* @throws IOException if an error occurs while attempting to invoke the API
9090
**/
91-
public Asset createAsset(String accessToken, String xeroTenantId, Asset asset) throws IOException {
92-
TypeReference<Asset> typeRef = new TypeReference<Asset>() {};
91+
public Asset createAsset(String accessToken, String xeroTenantId, Asset asset) throws IOException {
9392
try {
94-
HttpResponse response = createAssetForHttpResponse(accessToken, xeroTenantId, asset);
93+
TypeReference<Asset> typeRef = new TypeReference<Asset>() {};
94+
HttpResponse response = createAssetForHttpResponse(accessToken, xeroTenantId, asset);
9595
return apiClient.getObjectMapper().readValue(response.getContent(), typeRef);
9696
} catch (HttpResponseException e) {
97-
return apiClient.getObjectMapper().readValue(e.getContent(), typeRef);
97+
XeroApiExceptionHandler handler = new XeroApiExceptionHandler();
98+
handler.execute(e,apiClient);
9899
} catch (IOException ioe) {
99100
throw ioe;
100101
}
102+
return null;
101103
}
102104

103-
public HttpResponse createAssetForHttpResponse(String accessToken, String xeroTenantId, Asset asset) throws IOException {
105+
public HttpResponse createAssetForHttpResponse(String accessToken, String xeroTenantId, Asset asset) throws IOException {
104106
// verify the required parameter 'xeroTenantId' is set
105107
if (xeroTenantId == null) {
106108
throw new IllegalArgumentException("Missing the required parameter 'xeroTenantId' when calling createAsset");
@@ -112,7 +114,7 @@ public HttpResponse createAssetForHttpResponse(String accessToken, String xero
112114
throw new IllegalArgumentException("Missing the required parameter 'accessToken' when calling createAsset");
113115
}
114116
HttpHeaders headers = new HttpHeaders();
115-
headers.set("xero-tenant-id", xeroTenantId);
117+
headers.set("Xero-Tenant-Id", xeroTenantId);
116118
headers.setAccept("application/json");
117119
headers.setUserAgent(this.getUserAgent());
118120

@@ -141,19 +143,21 @@ public HttpResponse createAssetForHttpResponse(String accessToken, String xero
141143
* @return AssetType
142144
* @throws IOException if an error occurs while attempting to invoke the API
143145
**/
144-
public AssetType createAssetType(String accessToken, String xeroTenantId, AssetType assetType) throws IOException {
145-
TypeReference<AssetType> typeRef = new TypeReference<AssetType>() {};
146+
public AssetType createAssetType(String accessToken, String xeroTenantId, AssetType assetType) throws IOException {
146147
try {
147-
HttpResponse response = createAssetTypeForHttpResponse(accessToken, xeroTenantId, assetType);
148+
TypeReference<AssetType> typeRef = new TypeReference<AssetType>() {};
149+
HttpResponse response = createAssetTypeForHttpResponse(accessToken, xeroTenantId, assetType);
148150
return apiClient.getObjectMapper().readValue(response.getContent(), typeRef);
149151
} catch (HttpResponseException e) {
150-
return apiClient.getObjectMapper().readValue(e.getContent(), typeRef);
152+
XeroApiExceptionHandler handler = new XeroApiExceptionHandler();
153+
handler.execute(e,apiClient);
151154
} catch (IOException ioe) {
152155
throw ioe;
153156
}
157+
return null;
154158
}
155159

156-
public HttpResponse createAssetTypeForHttpResponse(String accessToken, String xeroTenantId, AssetType assetType) throws IOException {
160+
public HttpResponse createAssetTypeForHttpResponse(String accessToken, String xeroTenantId, AssetType assetType) throws IOException {
157161
// verify the required parameter 'xeroTenantId' is set
158162
if (xeroTenantId == null) {
159163
throw new IllegalArgumentException("Missing the required parameter 'xeroTenantId' when calling createAssetType");
@@ -162,7 +166,7 @@ public HttpResponse createAssetTypeForHttpResponse(String accessToken, String
162166
throw new IllegalArgumentException("Missing the required parameter 'accessToken' when calling createAssetType");
163167
}
164168
HttpHeaders headers = new HttpHeaders();
165-
headers.set("xero-tenant-id", xeroTenantId);
169+
headers.set("Xero-Tenant-Id", xeroTenantId);
166170
headers.setAccept("application/json");
167171
headers.setUserAgent(this.getUserAgent());
168172

@@ -190,19 +194,21 @@ public HttpResponse createAssetTypeForHttpResponse(String accessToken, String
190194
* @return Asset
191195
* @throws IOException if an error occurs while attempting to invoke the API
192196
**/
193-
public Asset getAssetById(String accessToken, String xeroTenantId, UUID id) throws IOException {
194-
TypeReference<Asset> typeRef = new TypeReference<Asset>() {};
197+
public Asset getAssetById(String accessToken, String xeroTenantId, UUID id) throws IOException {
195198
try {
196-
HttpResponse response = getAssetByIdForHttpResponse(accessToken, xeroTenantId, id);
199+
TypeReference<Asset> typeRef = new TypeReference<Asset>() {};
200+
HttpResponse response = getAssetByIdForHttpResponse(accessToken, xeroTenantId, id);
197201
return apiClient.getObjectMapper().readValue(response.getContent(), typeRef);
198202
} catch (HttpResponseException e) {
199-
return apiClient.getObjectMapper().readValue(e.getContent(), typeRef);
203+
XeroApiExceptionHandler handler = new XeroApiExceptionHandler();
204+
handler.execute(e,apiClient);
200205
} catch (IOException ioe) {
201206
throw ioe;
202207
}
208+
return null;
203209
}
204210

205-
public HttpResponse getAssetByIdForHttpResponse(String accessToken, String xeroTenantId, UUID id) throws IOException {
211+
public HttpResponse getAssetByIdForHttpResponse(String accessToken, String xeroTenantId, UUID id) throws IOException {
206212
// verify the required parameter 'xeroTenantId' is set
207213
if (xeroTenantId == null) {
208214
throw new IllegalArgumentException("Missing the required parameter 'xeroTenantId' when calling getAssetById");
@@ -214,7 +220,7 @@ public HttpResponse getAssetByIdForHttpResponse(String accessToken, String xer
214220
throw new IllegalArgumentException("Missing the required parameter 'accessToken' when calling getAssetById");
215221
}
216222
HttpHeaders headers = new HttpHeaders();
217-
headers.set("xero-tenant-id", xeroTenantId);
223+
headers.set("Xero-Tenant-Id", xeroTenantId);
218224
headers.setAccept("application/json");
219225
headers.setUserAgent(this.getUserAgent());
220226

@@ -245,19 +251,21 @@ public HttpResponse getAssetByIdForHttpResponse(String accessToken, String xer
245251
* @return Setting
246252
* @throws IOException if an error occurs while attempting to invoke the API
247253
**/
248-
public Setting getAssetSettings(String accessToken, String xeroTenantId) throws IOException {
249-
TypeReference<Setting> typeRef = new TypeReference<Setting>() {};
254+
public Setting getAssetSettings(String accessToken, String xeroTenantId) throws IOException {
250255
try {
251-
HttpResponse response = getAssetSettingsForHttpResponse(accessToken, xeroTenantId);
256+
TypeReference<Setting> typeRef = new TypeReference<Setting>() {};
257+
HttpResponse response = getAssetSettingsForHttpResponse(accessToken, xeroTenantId);
252258
return apiClient.getObjectMapper().readValue(response.getContent(), typeRef);
253259
} catch (HttpResponseException e) {
254-
return apiClient.getObjectMapper().readValue(e.getContent(), typeRef);
260+
XeroApiExceptionHandler handler = new XeroApiExceptionHandler();
261+
handler.execute(e,apiClient);
255262
} catch (IOException ioe) {
256263
throw ioe;
257264
}
265+
return null;
258266
}
259267

260-
public HttpResponse getAssetSettingsForHttpResponse(String accessToken, String xeroTenantId) throws IOException {
268+
public HttpResponse getAssetSettingsForHttpResponse(String accessToken, String xeroTenantId) throws IOException {
261269
// verify the required parameter 'xeroTenantId' is set
262270
if (xeroTenantId == null) {
263271
throw new IllegalArgumentException("Missing the required parameter 'xeroTenantId' when calling getAssetSettings");
@@ -266,7 +274,7 @@ public HttpResponse getAssetSettingsForHttpResponse(String accessToken, String
266274
throw new IllegalArgumentException("Missing the required parameter 'accessToken' when calling getAssetSettings");
267275
}
268276
HttpHeaders headers = new HttpHeaders();
269-
headers.set("xero-tenant-id", xeroTenantId);
277+
headers.set("Xero-Tenant-Id", xeroTenantId);
270278
headers.setAccept("application/json");
271279
headers.setUserAgent(this.getUserAgent());
272280

@@ -292,19 +300,21 @@ public HttpResponse getAssetSettingsForHttpResponse(String accessToken, String
292300
* @return List&lt;AssetType&gt;
293301
* @throws IOException if an error occurs while attempting to invoke the API
294302
**/
295-
public List<AssetType> getAssetTypes(String accessToken, String xeroTenantId) throws IOException {
296-
TypeReference<List<AssetType>> typeRef = new TypeReference<List<AssetType>>() {};
303+
public List<AssetType> getAssetTypes(String accessToken, String xeroTenantId) throws IOException {
297304
try {
298-
HttpResponse response = getAssetTypesForHttpResponse(accessToken, xeroTenantId);
305+
TypeReference<List<AssetType>> typeRef = new TypeReference<List<AssetType>>() {};
306+
HttpResponse response = getAssetTypesForHttpResponse(accessToken, xeroTenantId);
299307
return apiClient.getObjectMapper().readValue(response.getContent(), typeRef);
300308
} catch (HttpResponseException e) {
301-
return apiClient.getObjectMapper().readValue(e.getContent(), typeRef);
309+
XeroApiExceptionHandler handler = new XeroApiExceptionHandler();
310+
handler.execute(e,apiClient);
302311
} catch (IOException ioe) {
303312
throw ioe;
304313
}
314+
return null;
305315
}
306316

307-
public HttpResponse getAssetTypesForHttpResponse(String accessToken, String xeroTenantId) throws IOException {
317+
public HttpResponse getAssetTypesForHttpResponse(String accessToken, String xeroTenantId) throws IOException {
308318
// verify the required parameter 'xeroTenantId' is set
309319
if (xeroTenantId == null) {
310320
throw new IllegalArgumentException("Missing the required parameter 'xeroTenantId' when calling getAssetTypes");
@@ -313,7 +323,7 @@ public HttpResponse getAssetTypesForHttpResponse(String accessToken, String xe
313323
throw new IllegalArgumentException("Missing the required parameter 'accessToken' when calling getAssetTypes");
314324
}
315325
HttpHeaders headers = new HttpHeaders();
316-
headers.set("xero-tenant-id", xeroTenantId);
326+
headers.set("Xero-Tenant-Id", xeroTenantId);
317327
headers.setAccept("application/json");
318328
headers.setUserAgent(this.getUserAgent());
319329

@@ -345,19 +355,21 @@ public HttpResponse getAssetTypesForHttpResponse(String accessToken, String xe
345355
* @return Assets
346356
* @throws IOException if an error occurs while attempting to invoke the API
347357
**/
348-
public Assets getAssets(String accessToken, String xeroTenantId, String status, Integer page, Integer pageSize, String orderBy, String sortDirection, String filterBy) throws IOException {
349-
TypeReference<Assets> typeRef = new TypeReference<Assets>() {};
358+
public Assets getAssets(String accessToken, String xeroTenantId, String status, Integer page, Integer pageSize, String orderBy, String sortDirection, String filterBy) throws IOException {
350359
try {
351-
HttpResponse response = getAssetsForHttpResponse(accessToken, xeroTenantId, status, page, pageSize, orderBy, sortDirection, filterBy);
360+
TypeReference<Assets> typeRef = new TypeReference<Assets>() {};
361+
HttpResponse response = getAssetsForHttpResponse(accessToken, xeroTenantId, status, page, pageSize, orderBy, sortDirection, filterBy);
352362
return apiClient.getObjectMapper().readValue(response.getContent(), typeRef);
353363
} catch (HttpResponseException e) {
354-
return apiClient.getObjectMapper().readValue(e.getContent(), typeRef);
364+
XeroApiExceptionHandler handler = new XeroApiExceptionHandler();
365+
handler.execute(e,apiClient);
355366
} catch (IOException ioe) {
356367
throw ioe;
357368
}
369+
return null;
358370
}
359371

360-
public HttpResponse getAssetsForHttpResponse(String accessToken, String xeroTenantId, String status, Integer page, Integer pageSize, String orderBy, String sortDirection, String filterBy) throws IOException {
372+
public HttpResponse getAssetsForHttpResponse(String accessToken, String xeroTenantId, String status, Integer page, Integer pageSize, String orderBy, String sortDirection, String filterBy) throws IOException {
361373
// verify the required parameter 'xeroTenantId' is set
362374
if (xeroTenantId == null) {
363375
throw new IllegalArgumentException("Missing the required parameter 'xeroTenantId' when calling getAssets");
@@ -369,7 +381,7 @@ public HttpResponse getAssetsForHttpResponse(String accessToken, String xeroTe
369381
throw new IllegalArgumentException("Missing the required parameter 'accessToken' when calling getAssets");
370382
}
371383
HttpHeaders headers = new HttpHeaders();
372-
headers.set("xero-tenant-id", xeroTenantId);
384+
headers.set("Xero-Tenant-Id", xeroTenantId);
373385
headers.setAccept("application/json");
374386
headers.setUserAgent(this.getUserAgent());
375387

0 commit comments

Comments
 (0)