summaryrefslogtreecommitdiffstats
path: root/aai-resources/src/main/java/org/onap
diff options
context:
space:
mode:
authorMaharajh, Robby (rx2202) <rx2202@us.att.com>2017-12-04 16:43:59 -0500
committerMaharajh, Robby (rx2202) <rx2202@us.att.com>2017-12-04 16:44:06 -0500
commit944224b1a452ba90913bac6bee842f5a6bd61770 (patch)
treea9c58365afea882ff9ddfdea33ea1f5bea35b53f /aai-resources/src/main/java/org/onap
parent4febf4b4c10d435e2a12e4df34d590254263e38b (diff)
Update the aai-resources to verify bulk limits
Issue-ID: AAI-529 Change-Id: Ia87e3298ce9c46f3b409587df6e9bd6e2065ec8a Signed-off-by: Maharajh, Robby (rx2202) <rx2202@us.att.com>
Diffstat (limited to 'aai-resources/src/main/java/org/onap')
-rw-r--r--aai-resources/src/main/java/org/onap/aai/rest/BulkConsumer.java55
1 files changed, 49 insertions, 6 deletions
diff --git a/aai-resources/src/main/java/org/onap/aai/rest/BulkConsumer.java b/aai-resources/src/main/java/org/onap/aai/rest/BulkConsumer.java
index 5591ae3..5ff0e35 100644
--- a/aai-resources/src/main/java/org/onap/aai/rest/BulkConsumer.java
+++ b/aai-resources/src/main/java/org/onap/aai/rest/BulkConsumer.java
@@ -24,8 +24,11 @@ package org.onap.aai.rest;
import java.io.UnsupportedEncodingException;
import java.net.URI;
import java.util.ArrayList;
+import java.util.Iterator;
import java.util.List;
import java.util.Map.Entry;
+import java.util.Map;
+import java.util.Set;
import java.util.stream.Collectors;
import javax.servlet.http.HttpServletRequest;
@@ -60,6 +63,8 @@ import org.onap.aai.restcore.HttpMethod;
import org.onap.aai.restcore.RESTAPI;
import org.onap.aai.serialization.engines.QueryStyle;
import org.onap.aai.serialization.engines.TransactionalGraphEngine;
+import org.onap.aai.util.AAIConfig;
+import org.onap.aai.util.AAIConstants;
import org.springframework.web.util.UriComponents;
import org.springframework.web.util.UriComponentsBuilder;
@@ -250,12 +255,7 @@ public abstract class BulkConsumer extends RESTAPI {
throw new AAIException("AAI_6111", String.format("input payload does not follow %s interface", module));
}
JsonArray transactions = transactionsObj.getAsJsonArray();
- if (transactions.size() == 0) {
- //case where user sends a validly formatted transactions object but
- //which has no actual things in it for A&AI to do anything with
- //assuming we should count this as a user error
- throw new AAIException("AAI_6118", "payload had no objects to operate on");
- }
+ validateRequest(transactions);
return transactions;
}
@@ -531,6 +531,49 @@ public abstract class BulkConsumer extends RESTAPI {
}
}
+ /**
+ * Pulls the config value for the limit of operations allowed in a bulk add/process request
+ *
+ * @throws AAIException
+ */
+ private int getPayLoadLimit() throws AAIException{
+ return Integer.parseInt(AAIConfig.get(AAIConstants.AAI_BULKCONSUMER_LIMIT));
+ }
+
+ /**
+ * Validates the amount of operations in a request payload is allowed
+ *
+ * @param transactions - a JsonArray of all the transactions in the request payload
+ * @throws AAIException
+ */
+ private void validateRequest(JsonArray transactions) throws AAIException{
+ if (transactions.size() == 0) {
+ //case where user sends a validly formatted transactions object but
+ //which has no actual things in it for A&AI to do anything with
+ //assuming we should count this as a user error
+ throw new AAIException("AAI_6118", "payload had no objects to operate on");
+ }else if(transactions.size() > getPayLoadLimit()) {
+ throw new AAIException("AAI_6147", String.format("Payload limit of %s reached, please reduce payload.", getPayLoadLimit()));
+ }
+ int operationCount = 0;
+ int payLoadLimit = getPayLoadLimit();
+ for(int i = 0; i < transactions.size(); i++){
+ Set<Entry<String, JsonElement>> entrySet = transactions.get(i).getAsJsonObject().entrySet();
+ Iterator<Entry<String, JsonElement>> it = entrySet.iterator();
+ while(it.hasNext()){
+ Map.Entry<String, JsonElement> element = it.next();
+ if(element.getValue() instanceof JsonArray) {
+ operationCount += ((JsonArray) element.getValue()).size();
+ }else{
+ operationCount++;
+ }
+ }
+ if(operationCount > payLoadLimit){
+ throw new AAIException("AAI_6147", String.format("Payload limit of %s reached, please reduce payload.", payLoadLimit));
+ }
+ }
+ }
+
protected abstract String getModule();
protected abstract boolean functionAllowed(HttpMethod method);