Skip to content

Commit

Permalink
addressed issue #43
Browse files Browse the repository at this point in the history
  • Loading branch information
benni committed Dec 17, 2019
1 parent 99cea46 commit bd27513
Showing 1 changed file with 16 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public class EntityService {
String appendOverwriteFlag;
@Value("${entity.index.topic}")
String ENTITY_INDEX;

@Value("${batchoperations.maxnumber.create:-1}")
int maxCreateBatch;
@Value("${batchoperations.maxnumber.update:-1}")
Expand Down Expand Up @@ -821,8 +821,9 @@ public BatchResult createMultipleMessage(String payload) throws ResponseExceptio
"This interface only supports arrays of entities");
}
ArrayNode myArray = (ArrayNode) myTree;
if(maxCreateBatch != -1 && myArray.size() > maxCreateBatch) {
throw new ResponseException(ErrorType.RequestEntityTooLarge, "Maximum allowed number of entities for this operation is " + maxCreateBatch);
if (maxCreateBatch != -1 && myArray.size() > maxCreateBatch) {
throw new ResponseException(ErrorType.RequestEntityTooLarge,
"Maximum allowed number of entities for this operation is " + maxCreateBatch);
}
Iterator<JsonNode> it = myArray.iterator();
while (it.hasNext()) {
Expand All @@ -831,7 +832,7 @@ public BatchResult createMultipleMessage(String payload) throws ResponseExceptio
try {
result.addSuccess(createMessage(objectMapper.writeValueAsString(next)));
} catch (Exception e) {

String entityId = "NOT AVAILABLE";
if (next.hasNonNull(NGSIConstants.JSON_LD_ID)) {
entityId = next.get(NGSIConstants.JSON_LD_ID).asText();
Expand Down Expand Up @@ -864,8 +865,9 @@ public BatchResult deleteMultipleMessage(String payload) throws ResponseExceptio
"This interface only supports arrays of entities");
}
ArrayNode myArray = (ArrayNode) myTree;
if(maxDeleteBatch != -1 && myArray.size() > maxDeleteBatch) {
throw new ResponseException(ErrorType.RequestEntityTooLarge, "Maximum allowed number of entities for this operation is " + maxDeleteBatch);
if (maxDeleteBatch != -1 && myArray.size() > maxDeleteBatch) {
throw new ResponseException(ErrorType.RequestEntityTooLarge,
"Maximum allowed number of entities for this operation is " + maxDeleteBatch);
}

Iterator<JsonNode> it = myArray.iterator();
Expand Down Expand Up @@ -904,8 +906,9 @@ public BatchResult updateMultipleMessage(String resolved) throws ResponseExcepti
"This interface only supports arrays of entities");
}
ArrayNode myArray = (ArrayNode) myTree;
if(maxUpdateBatch != -1 && myArray.size() > maxUpdateBatch) {
throw new ResponseException(ErrorType.RequestEntityTooLarge, "Maximum allowed number of entities for this operation is " + maxUpdateBatch);
if (maxUpdateBatch != -1 && myArray.size() > maxUpdateBatch) {
throw new ResponseException(ErrorType.RequestEntityTooLarge,
"Maximum allowed number of entities for this operation is " + maxUpdateBatch);
}
Iterator<JsonNode> it = myArray.iterator();
while (it.hasNext()) {
Expand All @@ -929,7 +932,7 @@ public BatchResult updateMultipleMessage(String resolved) throws ResponseExcepti
}

} catch (Exception e) {

RestResponse response;
if (e instanceof ResponseException) {
response = new RestResponse((ResponseException) e);
Expand Down Expand Up @@ -957,8 +960,9 @@ public BatchResult upsertMultipleMessage(String resolved) throws ResponseExcepti
"This interface only supports arrays of entities");
}
ArrayNode myArray = (ArrayNode) myTree;
if(maxUpsertBatch != -1 && myArray.size() > maxUpsertBatch) {
throw new ResponseException(ErrorType.RequestEntityTooLarge, "Maximum allowed number of entities for this operation is " + maxUpsertBatch);
if (maxUpsertBatch != -1 && myArray.size() > maxUpsertBatch) {
throw new ResponseException(ErrorType.RequestEntityTooLarge,
"Maximum allowed number of entities for this operation is " + maxUpsertBatch);
}
Iterator<JsonNode> it = myArray.iterator();
while (it.hasNext()) {
Expand All @@ -977,7 +981,7 @@ public BatchResult upsertMultipleMessage(String resolved) throws ResponseExcepti
result.addSuccess(createMessage(entityString));

} catch (Exception e) {

RestResponse response;
if (e instanceof ResponseException) {
ResponseException responseException = ((ResponseException) e);
Expand Down

0 comments on commit bd27513

Please sign in to comment.