From 7cf409f03b535f41ee6ea6e4cb04443f3591c93a Mon Sep 17 00:00:00 2001 From: "Maharajh, Robby (rx2202)" Date: Tue, 5 Dec 2017 09:56:30 -0500 Subject: Add limit override for bulk api's Issue-ID: AAI-535 Change-Id: Ie248a85541f77b786973be54a7791f6e4e7dff16 Signed-off-by: Maharajh, Robby (rx2202) --- .../main/java/org/onap/aai/rest/BulkConsumer.java | 43 ++++++++++++---------- 1 file changed, 24 insertions(+), 19 deletions(-) (limited to 'aai-resources/src/main/java') 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 5ff0e35..1267792 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 @@ -134,7 +134,7 @@ public abstract class BulkConsumer extends RESTAPI { try { DBConnectionType type = this.determineConnectionType(sourceOfTruth, realTime); - JsonArray transactions = getTransactions(content); + JsonArray transactions = getTransactions(content, headers); for (int i = 0; i < transactions.size(); i++){ HttpEntry httpEntry = new HttpEntry(version, introspectorFactoryType, queryStyle, type); @@ -240,7 +240,7 @@ public abstract class BulkConsumer extends RESTAPI { * @throws JsonSyntaxException Parses and breaks the single payload into an array of individual transaction * bodies to be processed. */ - private JsonArray getTransactions(String content) throws AAIException, JsonSyntaxException { + private JsonArray getTransactions(String content, HttpHeaders headers) throws AAIException, JsonSyntaxException { JsonParser parser = new JsonParser(); JsonObject input = parser.parse(content).getAsJsonObject(); @@ -255,7 +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(); - validateRequest(transactions); + validateRequest(transactions, headers); return transactions; } @@ -546,30 +546,35 @@ public abstract class BulkConsumer extends RESTAPI { * @param transactions - a JsonArray of all the transactions in the request payload * @throws AAIException */ - private void validateRequest(JsonArray transactions) throws AAIException{ + private void validateRequest(JsonArray transactions, HttpHeaders headers) throws AAIException{ + String overrideLimit = headers.getRequestHeaders().getFirst("X-OverrideLimit"); + boolean isOverride = overrideLimit != null && !AAIConfig.get(AAIConstants.AAI_BULKCONSUMER_OVERRIDE_LIMIT).equals("false") + && overrideLimit.equals(AAIConfig.get(AAIConstants.AAI_BULKCONSUMER_OVERRIDE_LIMIT)); 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()) { + }else if(!isOverride && 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> entrySet = transactions.get(i).getAsJsonObject().entrySet(); - Iterator> it = entrySet.iterator(); - while(it.hasNext()){ - Map.Entry element = it.next(); - if(element.getValue() instanceof JsonArray) { - operationCount += ((JsonArray) element.getValue()).size(); - }else{ - operationCount++; + if(!isOverride) { + int operationCount = 0; + int payLoadLimit = getPayLoadLimit(); + for (int i = 0; i < transactions.size(); i++) { + Set> entrySet = transactions.get(i).getAsJsonObject().entrySet(); + Iterator> it = entrySet.iterator(); + while (it.hasNext()) { + Map.Entry 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)); } - } - if(operationCount > payLoadLimit){ - throw new AAIException("AAI_6147", String.format("Payload limit of %s reached, please reduce payload.", payLoadLimit)); } } } -- cgit 1.2.3-korg