-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Ivan Senic
authored
Mar 30, 2023
1 parent
685b15d
commit d2176cb
Showing
6 changed files
with
124 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
...in/java/io/stargate/sgv2/jsonapi/api/model/command/validation/MaxInsertManyDocuments.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package io.stargate.sgv2.jsonapi.api.model.command.validation; | ||
|
||
import static java.lang.annotation.ElementType.*; | ||
import static java.lang.annotation.RetentionPolicy.RUNTIME; | ||
|
||
import io.stargate.sgv2.jsonapi.config.DocumentLimitsConfig; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.Target; | ||
import javax.validation.Constraint; | ||
import javax.validation.Payload; | ||
|
||
/** | ||
* Limits the maximum amount of documents to insert, as defined in the {@link DocumentLimitsConfig}. | ||
*/ | ||
@Target({METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER, TYPE_USE}) | ||
@Retention(RUNTIME) | ||
@Constraint(validatedBy = {MaxInsertManyDocumentsValidation.class}) | ||
public @interface MaxInsertManyDocuments { | ||
|
||
String message() default "amount of documents to insert is over the max limit"; | ||
|
||
Class<?>[] groups() default {}; | ||
|
||
Class<? extends Payload>[] payload() default {}; | ||
} |
29 changes: 29 additions & 0 deletions
29
.../stargate/sgv2/jsonapi/api/model/command/validation/MaxInsertManyDocumentsValidation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package io.stargate.sgv2.jsonapi.api.model.command.validation; | ||
|
||
import com.fasterxml.jackson.databind.JsonNode; | ||
import java.util.List; | ||
import javax.enterprise.context.ApplicationScoped; | ||
import javax.validation.ConstraintValidator; | ||
import javax.validation.ConstraintValidatorContext; | ||
import org.eclipse.microprofile.config.inject.ConfigProperty; | ||
|
||
/** Validator for the {@link MaxInsertManyDocuments} annotation. */ | ||
@ApplicationScoped | ||
public class MaxInsertManyDocumentsValidation | ||
implements ConstraintValidator<MaxInsertManyDocuments, List<JsonNode>> { | ||
|
||
private final int limit; | ||
|
||
// due to https://github.com/quarkusio/quarkus/issues/32265 | ||
// I can only inject prop, not the whole config class | ||
public MaxInsertManyDocumentsValidation( | ||
@ConfigProperty(name = "stargate.jsonapi.doc-limits.max-insert-many-documents") int limit) { | ||
this.limit = limit; | ||
} | ||
|
||
/** {@inheritDoc} */ | ||
@Override | ||
public boolean isValid(List<JsonNode> value, ConstraintValidatorContext context) { | ||
return null != value && value.size() <= limit; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters