You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by zr...@apache.org on 2017/02/23 11:46:47 UTC
camel git commit: CAMEL-10886: Support Limits API response from S...
Repository: camel
Updated Branches:
refs/heads/master 8203136ee -> f0a4852ba
CAMEL-10886: Support Limits API response from S...
...alesforce v39.0
Since version v39.0 (Spring 2017) the Limits API returns along with
`max` and `remaining` additional JSON properties, per connected
application, also containing `max` and `remaining`.
This changes the deserialization of Limits JSON response to include
those per-application Limits.
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/f0a4852b
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/f0a4852b
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/f0a4852b
Branch: refs/heads/master
Commit: f0a4852ba9c3b7b109613a2eb53a4359218c2c27
Parents: 8203136
Author: Zoran Regvart <zr...@apache.org>
Authored: Thu Feb 23 12:45:57 2017 +0100
Committer: Zoran Regvart <zr...@apache.org>
Committed: Thu Feb 23 12:45:57 2017 +0100
----------------------------------------------------------------------
.../component/salesforce/api/dto/Limits.java | 29 +++++++++++++++++++-
.../salesforce/api/dto/LimitsTest.java | 6 +++-
.../component/salesforce/api/dto/limits.json | 12 ++++++--
3 files changed, 43 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/f0a4852b/components/camel-salesforce/camel-salesforce-component/src/main/java/org/apache/camel/component/salesforce/api/dto/Limits.java
----------------------------------------------------------------------
diff --git a/components/camel-salesforce/camel-salesforce-component/src/main/java/org/apache/camel/component/salesforce/api/dto/Limits.java b/components/camel-salesforce/camel-salesforce-component/src/main/java/org/apache/camel/component/salesforce/api/dto/Limits.java
index d80bade..3c84dee 100644
--- a/components/camel-salesforce/camel-salesforce-component/src/main/java/org/apache/camel/component/salesforce/api/dto/Limits.java
+++ b/components/camel-salesforce/camel-salesforce-component/src/main/java/org/apache/camel/component/salesforce/api/dto/Limits.java
@@ -18,9 +18,14 @@ package org.apache.camel.component.salesforce.api.dto;
import java.io.IOException;
import java.io.Serializable;
+import java.util.Collections;
+import java.util.HashMap;
import java.util.Map;
+import java.util.Optional;
+import java.util.Set;
import java.util.stream.Collectors;
+import com.fasterxml.jackson.annotation.JsonAnySetter;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.core.JsonParser;
@@ -95,17 +100,34 @@ public final class Limits implements Serializable {
private final int remaining;
+ private final Map<String, Usage> perApplication = new HashMap<>();
+
@JsonCreator
Usage(@JsonProperty("Max") final int max, @JsonProperty("Remaining") final int remaining) {
this.max = max;
this.remaining = remaining;
}
+ /** Returns {@link Usage} for application */
+ public Optional<Usage> forApplication(final String application) {
+ return Optional.ofNullable(perApplication.get(application));
+ }
+
+ /** Further per application usage. */
+ public Set<String> getApplications() {
+ return perApplication.keySet();
+ }
+
/** Maximum allowed by the limit */
public int getMax() {
return max;
}
+ /** Returns usages per application */
+ public Map<String, Usage> getPerApplicationUsage() {
+ return Collections.unmodifiableMap(perApplication);
+ }
+
/** Remaining invocations allowed */
public int getRemaining() {
return remaining;
@@ -121,7 +143,12 @@ public final class Limits implements Serializable {
return "Undefined";
}
- return "Max: " + max + ", Remaining: " + remaining;
+ return "Max: " + max + ", Remaining: " + remaining + ", per application: " + perApplication;
+ }
+
+ @JsonAnySetter
+ void addApplicationUsage(final String application, final Usage usage) {
+ perApplication.put(application, usage);
}
}
http://git-wip-us.apache.org/repos/asf/camel/blob/f0a4852b/components/camel-salesforce/camel-salesforce-component/src/test/java/org/apache/camel/component/salesforce/api/dto/LimitsTest.java
----------------------------------------------------------------------
diff --git a/components/camel-salesforce/camel-salesforce-component/src/test/java/org/apache/camel/component/salesforce/api/dto/LimitsTest.java b/components/camel-salesforce/camel-salesforce-component/src/test/java/org/apache/camel/component/salesforce/api/dto/LimitsTest.java
index 6b7b0d3..7879b3c 100644
--- a/components/camel-salesforce/camel-salesforce-component/src/test/java/org/apache/camel/component/salesforce/api/dto/LimitsTest.java
+++ b/components/camel-salesforce/camel-salesforce-component/src/test/java/org/apache/camel/component/salesforce/api/dto/LimitsTest.java
@@ -36,6 +36,7 @@ import org.junit.Test;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.core.IsInstanceOf.instanceOf;
import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
@@ -57,7 +58,10 @@ public class LimitsTest {
final Limits limits = (Limits) read;
- assertFalse("Should have some usage present", limits.getDailyApiRequests().isUnknown());
+ final Usage dailyApiRequests = limits.getDailyApiRequests();
+ assertFalse("Should have some usage present", dailyApiRequests.isUnknown());
+ assertFalse("Per application usage should be present", dailyApiRequests.getPerApplicationUsage().isEmpty());
+ assertNotNull("'Camel Salesman' application usage should be present", dailyApiRequests.forApplication("Camel Salesman"));
}
@Test
http://git-wip-us.apache.org/repos/asf/camel/blob/f0a4852b/components/camel-salesforce/camel-salesforce-component/src/test/resources/org/apache/camel/component/salesforce/api/dto/limits.json
----------------------------------------------------------------------
diff --git a/components/camel-salesforce/camel-salesforce-component/src/test/resources/org/apache/camel/component/salesforce/api/dto/limits.json b/components/camel-salesforce/camel-salesforce-component/src/test/resources/org/apache/camel/component/salesforce/api/dto/limits.json
index c355c74..15b466c 100644
--- a/components/camel-salesforce/camel-salesforce-component/src/test/resources/org/apache/camel/component/salesforce/api/dto/limits.json
+++ b/components/camel-salesforce/camel-salesforce-component/src/test/resources/org/apache/camel/component/salesforce/api/dto/limits.json
@@ -9,7 +9,11 @@
},
"DailyApiRequests" : {
"Max" : 15000,
- "Remaining" : 14998
+ "Remaining" : 14998,
+ "Camel Salesman" : {
+ "Max" : 1,
+ "Remaining" : 2
+ }
},
"DailyAsyncApexExecutions" : {
"Max" : 250000,
@@ -17,7 +21,11 @@
},
"DailyBulkApiRequests" : {
"Max" : 5000,
- "Remaining" : 5000
+ "Remaining" : 5000,
+ "Camel Salesman" : {
+ "Max": 3,
+ "Remaining" : 4
+ }
},
"DailyDurableGenericStreamingApiEvents" : {
"Max" : 10000,