Skip to content

Commit

Permalink
Add limitation in the array of events for the endpoint of generate (#227
Browse files Browse the repository at this point in the history
)

* Add limitation in the array of events for the endpoint of generate

* Add limitation in the array of events for the endpoint of generate

* Add limitation in the array of events for the endpoint of generate
  • Loading branch information
shudhansu-shekhar authored Oct 8, 2024
1 parent a870ce4 commit e38806b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.PropertySource;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.RequestEntity;
Expand All @@ -52,7 +53,6 @@
import java.util.Map.Entry;

import static com.ericsson.eiffel.remrem.generate.constants.RemremGenerateServiceConstants.*;

@RestController
@RequestMapping("/*")
@Api(value = "REMReM Generate Service", description = "REST API for generating Eiffel messages")
Expand All @@ -76,6 +76,9 @@ public class RemremGenerateController {
@Value("${lenientValidationEnabledToUsers:false}")
private boolean lenientValidationEnabledToUsers;

@Value("${maxSizeOfInputArray:250}")
private int maxSizeOfInputArray = 250;

public void setLenientValidationEnabledToUsers(boolean lenientValidationEnabledToUsers) {
this.lenientValidationEnabledToUsers = lenientValidationEnabledToUsers;
}
Expand Down Expand Up @@ -159,6 +162,12 @@ public ResponseEntity<?> generate(final String msgProtocol, final String msgType

if (inputData.isJsonArray()) {
JsonArray inputEventJsonArray = inputData.getAsJsonArray();

if (inputEventJsonArray.size() > maxSizeOfInputArray) {
return createResponseEntity(HttpStatus.BAD_REQUEST, JSON_ERROR_STATUS,
"The number of events in the input array is too high: " + inputEventJsonArray.size() + " > "
+ maxSizeOfInputArray + "; you can modify the property 'maxSizeOfInputArray' to increase it.");
}
for (JsonElement element : inputEventJsonArray) {
JsonObject generatedEvent = (processEvent(msgProtocol, msgType,
failIfMultipleFound, failIfNoneFound, lookupInExternalERs, lookupLimit,
Expand Down
5 changes: 4 additions & 1 deletion service/src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,7 @@ event-repository.enabled: false
event-repository.url: http://<host>:<port>/<context-path-if-available>

# lenientValidationEnabledToUsers true will perform the validation only on mandatory fields, non-mandatory validation failures add into Eiffel message as property remremGenerateFailures
lenientValidationEnabledToUsers: false
lenientValidationEnabledToUsers: false

#Maximum number of templates in array passed to generate endpoint
maxSizeOfInputArray: 250

0 comments on commit e38806b

Please sign in to comment.