diff options
author | Maharajh, Robby (rx2202) <rx2202@us.att.com> | 2017-12-05 09:56:30 -0500 |
---|---|---|
committer | Maharajh, Robby (rx2202) <rx2202@us.att.com> | 2017-12-05 09:56:40 -0500 |
commit | 7cf409f03b535f41ee6ea6e4cb04443f3591c93a (patch) | |
tree | dede2de72a2acbf392c1dd6dbc2e0be82577dd6b /aai-resources/src/main/java/org | |
parent | 944224b1a452ba90913bac6bee842f5a6bd61770 (diff) |
Add limit override for bulk api's
Issue-ID: AAI-535
Change-Id: Ie248a85541f77b786973be54a7791f6e4e7dff16
Signed-off-by: Maharajh, Robby (rx2202) <rx2202@us.att.com>
Diffstat (limited to 'aai-resources/src/main/java/org')
-rw-r--r-- | aai-resources/src/main/java/org/onap/aai/rest/BulkConsumer.java | 43 |
1 files changed, 24 insertions, 19 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 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<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(!isOverride) { + 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)); } - } - if(operationCount > payLoadLimit){ - throw new AAIException("AAI_6147", String.format("Payload limit of %s reached, please reduce payload.", payLoadLimit)); } } } |