Skip to content

Add limitation in the array of events for the endpoint of generate #227

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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