Commit 63bc8776 authored by Figue Orange's avatar Figue Orange Committed by calocedre TAC
Browse files

add default rule presence validators (cant be merged cause super type List<ScoringRule> fail)

parent 84e2be01
......@@ -2,6 +2,7 @@ package fr.gouv.clea.clea.scoring.configuration.exposure;
import fr.gouv.clea.clea.scoring.configuration.ScoringConfiguration;
import fr.gouv.clea.clea.scoring.configuration.ScoringRule;
import fr.gouv.clea.clea.scoring.configuration.validators.CheckDefaultRulePresence;
import lombok.Setter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.ConfigurationProperties;
......@@ -19,6 +20,7 @@ public class ExposureTimeConfiguration extends ScoringConfiguration {
@Setter
@NotEmpty
@CheckDefaultRulePresence
protected List<ExposureTimeRule> rules;
public List<? extends ScoringRule> getScorings() {
......
......@@ -2,6 +2,7 @@ package fr.gouv.clea.clea.scoring.configuration.risk;
import fr.gouv.clea.clea.scoring.configuration.ScoringConfiguration;
import fr.gouv.clea.clea.scoring.configuration.ScoringRule;
import fr.gouv.clea.clea.scoring.configuration.validators.CheckDefaultRulePresence;
import lombok.Setter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.ConfigurationProperties;
......@@ -19,6 +20,7 @@ public class RiskConfiguration extends ScoringConfiguration {
@Setter
@NotEmpty
@CheckDefaultRulePresence
protected List<RiskRule> rules;
public List<? extends ScoringRule> getScorings() {
......
package fr.gouv.clea.clea.scoring.configuration.validators;
import javax.validation.Constraint;
import javax.validation.Payload;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
@Constraint(validatedBy = {CheckDefaultRulePresenceValidator.class})
@Retention(RetentionPolicy.RUNTIME)
public @interface CheckDefaultRulePresence {
String message() default
"Missing default rule with tuple * * *";
Class<?>[] groups() default {};
Class<? extends Payload>[] payload() default {};
}
package fr.gouv.clea.clea.scoring.configuration.validators;
import fr.gouv.clea.clea.scoring.configuration.ScoringRule;
import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
import java.util.List;
public class CheckDefaultRulePresenceValidator implements ConstraintValidator<CheckDefaultRulePresence, List<? extends ScoringRule>> {
@Override
public boolean isValid(List<? extends ScoringRule> ruleList, ConstraintValidatorContext context) {
return ruleList.stream().anyMatch(ScoringRule::isDefaultRule);
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment