Commit bf5199a6 authored by calocedre TAC's avatar calocedre TAC
Browse files

rename ScoringConfigurationItem to ScoringRule

parent 4f0eac2d
......@@ -8,11 +8,11 @@ import java.util.stream.Collectors;
@Slf4j
public abstract class ScoringConfiguration {
public abstract List<? extends ScoringConfigurationItem> getScorings();
public abstract List<? extends ScoringRule> getScorings();
public ScoringConfigurationItem getConfigurationFor(int venueType, int venueCategory1, int venueCategory2) {
public ScoringRule getConfigurationFor(int venueType, int venueCategory1, int venueCategory2) {
log.debug("Fetching rules candidates for venueType : {}, venueCategory1 : {}, venuCategory2: {}", venueType, venueCategory1, venueCategory2);
List<ScoringConfigurationItem> compatibleRules = this.getScorings().stream()
List<ScoringRule> compatibleRules = this.getScorings().stream()
.filter(scoring -> scoring.isCompatibleWith(venueType, venueCategory1, venueCategory2))
.collect(Collectors.toList());
......@@ -27,13 +27,13 @@ public abstract class ScoringConfiguration {
//All are wildcarded, then rule to apply is the default one
if (allAreWilcarded(venueType, venueCategory1, venueCategory2)) {
getConfigurationFor(
ScoringConfigurationItem.wildcardValue,
ScoringConfigurationItem.wildcardValue,
ScoringConfigurationItem.wildcardValue);
ScoringRule.wildcardValue,
ScoringRule.wildcardValue,
ScoringRule.wildcardValue);
}
ScoringConfigurationItem bestRuleCandidate = compatibleRules.get(0);
for (ScoringConfigurationItem rule : compatibleRules) {
ScoringRule bestRuleCandidate = compatibleRules.get(0);
for (ScoringRule rule : compatibleRules) {
if (rule.isFullMatch()) {
log.debug("Found full matching rule {}", rule);
return rule;
......@@ -52,36 +52,36 @@ public abstract class ScoringConfiguration {
private boolean allAreWilcarded(int venueType, int venueCategory1, int venueCategory2) {
int count = 0;
if (venueType == ScoringConfigurationItem.wildcardValue) {
if (venueType == ScoringRule.wildcardValue) {
count++;
}
if (venueCategory1 == ScoringConfigurationItem.wildcardValue) {
if (venueCategory1 == ScoringRule.wildcardValue) {
count++;
}
if (venueCategory2 == ScoringConfigurationItem.wildcardValue) {
if (venueCategory2 == ScoringRule.wildcardValue) {
count++;
}
return count == 3;
}
private boolean eitherOneCategoryIsWildcard(ScoringConfigurationItem rule) {
private boolean eitherOneCategoryIsWildcard(ScoringRule rule) {
return isWildcarded(rule.getVenueCategory1()) || isWildcarded(rule.getVenueCategory2());
}
private boolean bothCategoryAreWildcard(ScoringConfigurationItem rule) {
private boolean bothCategoryAreWildcard(ScoringRule rule) {
return isWildcarded(rule.getVenueCategory1()) && isWildcarded(rule.getVenueCategory2());
}
private boolean isWildcarded(int venueItem) {
return venueItem == ScoringConfigurationItem.wildcardValue;
return venueItem == ScoringRule.wildcardValue;
}
private boolean firstCategoryIsNotWildcarded(ScoringConfigurationItem rule) {
private boolean firstCategoryIsNotWildcarded(ScoringRule rule) {
return isWildcarded(rule.getVenueCategory1());
}
private boolean secondCategoryIsNotWildcarded(ScoringConfigurationItem rule) {
private boolean secondCategoryIsNotWildcarded(ScoringRule rule) {
return isWildcarded(rule.getVenueCategory2());
}
......
......@@ -19,7 +19,7 @@ import java.util.Objects;
@Valid
@ValidateWildcards
@NoDuplicates
public class ScoringConfigurationItem {
public class ScoringRule {
public static int wildcardValue = -1;
......@@ -39,26 +39,26 @@ public class ScoringConfigurationItem {
}
public boolean hasVenueTypeCompatibleWith(int venueType) {
return this.getVenueType() == venueType || this.getVenueType() == ScoringConfigurationItem.wildcardValue;
return this.getVenueType() == venueType || this.getVenueType() == ScoringRule.wildcardValue;
}
public boolean hasVenueCategory1CompatibleWith(int venueCategory1) {
return this.getVenueCategory1() == venueCategory1 || this.getVenueCategory1() == ScoringConfigurationItem.wildcardValue;
return this.getVenueCategory1() == venueCategory1 || this.getVenueCategory1() == ScoringRule.wildcardValue;
}
public boolean hasVenueCategory2CompatibleWith(int venueCategory2) {
return this.getVenueCategory2() == venueCategory2 || this.getVenueCategory2() == ScoringConfigurationItem.wildcardValue;
return this.getVenueCategory2() == venueCategory2 || this.getVenueCategory2() == ScoringRule.wildcardValue;
}
public int getWildCardCount() {
int count = 0;
if (this.venueType == ScoringConfigurationItem.wildcardValue) {
if (this.venueType == ScoringRule.wildcardValue) {
count++;
}
if (this.venueCategory1 == ScoringConfigurationItem.wildcardValue) {
if (this.venueCategory1 == ScoringRule.wildcardValue) {
count++;
}
if (this.venueCategory2 == ScoringConfigurationItem.wildcardValue) {
if (this.venueCategory2 == ScoringRule.wildcardValue) {
count++;
}
return count;
......@@ -72,7 +72,7 @@ public class ScoringConfigurationItem {
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
ScoringConfigurationItem that = (ScoringConfigurationItem) o;
ScoringRule that = (ScoringRule) o;
return getVenueType() == that.getVenueType() && getVenueCategory1() == that.getVenueCategory1() && getVenueCategory2() == that.getVenueCategory2();
}
......
package fr.gouv.clea.clea.scoring.configuration.exposure;
import fr.gouv.clea.clea.scoring.configuration.ScoringConfiguration;
import fr.gouv.clea.clea.scoring.configuration.ScoringConfigurationItem;
import fr.gouv.clea.clea.scoring.configuration.ScoringRule;
import lombok.Setter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.ConfigurationProperties;
......@@ -21,7 +21,7 @@ public class ExposureTimeConfiguration extends ScoringConfiguration {
@NotEmpty
protected List<ExposureTimeRule> rules;
public List<? extends ScoringConfigurationItem> getScorings() {
public List<? extends ScoringRule> getScorings() {
return rules;
}
......
package fr.gouv.clea.clea.scoring.configuration.exposure;
import fr.gouv.clea.clea.scoring.configuration.ScoringConfigurationItem;
import fr.gouv.clea.clea.scoring.configuration.ScoringRule;
import lombok.Getter;
import lombok.ToString;
import lombok.experimental.SuperBuilder;
......@@ -12,7 +12,7 @@ import javax.validation.constraints.Positive;
@SuperBuilder
@ToString(callSuper = true)
@Getter
public class ExposureTimeRule extends ScoringConfigurationItem {
public class ExposureTimeRule extends ScoringRule {
@Positive
private int exposureTimeBackward;
@Positive
......
package fr.gouv.clea.clea.scoring.configuration.risk;
import fr.gouv.clea.clea.scoring.configuration.ScoringConfiguration;
import fr.gouv.clea.clea.scoring.configuration.ScoringConfigurationItem;
import fr.gouv.clea.clea.scoring.configuration.ScoringRule;
import lombok.Setter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.ConfigurationProperties;
......@@ -21,7 +21,7 @@ public class RiskConfiguration extends ScoringConfiguration {
@NotEmpty
protected List<RiskRule> rules;
public List<? extends ScoringConfigurationItem> getScorings() {
public List<? extends ScoringRule> getScorings() {
return rules;
}
......
package fr.gouv.clea.clea.scoring.configuration.risk;
import fr.gouv.clea.clea.scoring.configuration.ScoringConfigurationItem;
import fr.gouv.clea.clea.scoring.configuration.ScoringRule;
import lombok.Getter;
import lombok.ToString;
import lombok.experimental.SuperBuilder;
......@@ -12,7 +12,7 @@ import javax.validation.constraints.Positive;
@SuperBuilder
@ToString(callSuper = true)
@Getter
public class RiskRule extends ScoringConfigurationItem {
public class RiskRule extends ScoringRule {
@Positive
private int clusterThresholdBackward;
@Positive
......
package fr.gouv.clea.clea.scoring.configuration.validators;
import fr.gouv.clea.clea.scoring.configuration.ScoringConfigurationItem;
import fr.gouv.clea.clea.scoring.configuration.ScoringRule;
import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
......@@ -9,7 +9,7 @@ import java.util.List;
public class NoDuplicatesValidator implements ConstraintValidator<NoDuplicates, Object> {
private List<ScoringConfigurationItem> list;
private List<ScoringRule> list;
@Override
public void initialize(NoDuplicates noDuplicates) {
......@@ -19,11 +19,11 @@ public class NoDuplicatesValidator implements ConstraintValidator<NoDuplicates,
@Override
public boolean isValid(Object value, ConstraintValidatorContext context) {
ScoringConfigurationItem scoringConfigurationItem = (ScoringConfigurationItem) value;
if (list.contains(scoringConfigurationItem)) {
ScoringRule scoringRule = (ScoringRule) value;
if (list.contains(scoringRule)) {
return false;
} else {
list.add(scoringConfigurationItem);
list.add(scoringRule);
return true;
}
}
......
package fr.gouv.clea.clea.scoring.configuration.validators;
import fr.gouv.clea.clea.scoring.configuration.ScoringConfigurationItem;
import fr.gouv.clea.clea.scoring.configuration.ScoringRule;
import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
......@@ -10,24 +10,24 @@ public class VenueTypeValidator implements ConstraintValidator<ValidateWildcards
@Override
public boolean isValid(Object value, ConstraintValidatorContext context) {
ScoringConfigurationItem scoringConfigurationItem = (ScoringConfigurationItem) value;
if (allFieldsAreWildcards(scoringConfigurationItem)) {
ScoringRule scoringRule = (ScoringRule) value;
if (allFieldsAreWildcards(scoringRule)) {
return true;
} else {
return venueTypeIsNotWildcarded(scoringConfigurationItem);
return venueTypeIsNotWildcarded(scoringRule);
}
}
private boolean venueTypeIsNotWildcarded(ScoringConfigurationItem scoringConfigurationItem) {
return scoringConfigurationItem.getVenueType() != ScoringConfigurationItem.wildcardValue ||
(scoringConfigurationItem.getVenueCategory1() != ScoringConfigurationItem.wildcardValue &&
scoringConfigurationItem.getVenueCategory2() != ScoringConfigurationItem.wildcardValue);
private boolean venueTypeIsNotWildcarded(ScoringRule scoringRule) {
return scoringRule.getVenueType() != ScoringRule.wildcardValue ||
(scoringRule.getVenueCategory1() != ScoringRule.wildcardValue &&
scoringRule.getVenueCategory2() != ScoringRule.wildcardValue);
}
private boolean allFieldsAreWildcards(ScoringConfigurationItem scoringConfigurationItem) {
return scoringConfigurationItem.getVenueType() == ScoringConfigurationItem.wildcardValue &&
scoringConfigurationItem.getVenueCategory1() == ScoringConfigurationItem.wildcardValue &&
scoringConfigurationItem.getVenueCategory2() == ScoringConfigurationItem.wildcardValue;
private boolean allFieldsAreWildcards(ScoringRule scoringRule) {
return scoringRule.getVenueType() == ScoringRule.wildcardValue &&
scoringRule.getVenueCategory1() == ScoringRule.wildcardValue &&
scoringRule.getVenueCategory2() == ScoringRule.wildcardValue;
}
......
......@@ -34,8 +34,8 @@ class ExposureTimeConfigurationTest {
ExposureTimeRule scoring = (ExposureTimeRule) configuration.getScorings().get(2);
assertThat(scoring.getVenueType()).isEqualTo(3);
assertThat(scoring.getVenueCategory1()).isEqualTo(ScoringConfigurationItem.wildcardValue);
assertThat(scoring.getVenueCategory2()).isEqualTo(ScoringConfigurationItem.wildcardValue);
assertThat(scoring.getVenueCategory1()).isEqualTo(ScoringRule.wildcardValue);
assertThat(scoring.getVenueCategory2()).isEqualTo(ScoringRule.wildcardValue);
assertThat(scoring.getExposureTimeBackward()).isEqualTo(1);
assertThat(scoring.getExposureTimeForward()).isEqualTo(11);
assertThat(scoring.getExposureTimeStaffBackward()).isEqualTo(21);
......
......@@ -34,8 +34,8 @@ public class RiskConfigurationTest {
RiskRule scoring = (RiskRule) configuration.getScorings().get(3);
assertThat(scoring.getVenueType()).isEqualTo(3);
assertThat(scoring.getVenueCategory1()).isEqualTo(ScoringConfigurationItem.wildcardValue);
assertThat(scoring.getVenueCategory2()).isEqualTo(ScoringConfigurationItem.wildcardValue);
assertThat(scoring.getVenueCategory1()).isEqualTo(ScoringRule.wildcardValue);
assertThat(scoring.getVenueCategory2()).isEqualTo(ScoringRule.wildcardValue);
assertThat(scoring.getClusterThresholdBackward()).isEqualTo(3);
assertThat(scoring.getClusterThresholdForward()).isEqualTo(1);
assertThat(scoring.getRiskLevelBackward()).isEqualTo(3.0f);
......
package fr.gouv.clea.clea.scoring.configuration;
import fr.gouv.clea.clea.scoring.configuration.exposure.ExposureTimeConfiguration;
import fr.gouv.clea.clea.scoring.configuration.exposure.ExposureTimeConfigurationConverter;
import fr.gouv.clea.clea.scoring.configuration.risk.RiskConfiguration;
import fr.gouv.clea.clea.scoring.configuration.risk.RiskConfigurationConverter;
import fr.gouv.clea.clea.scoring.configuration.risk.RiskRule;
import lombok.extern.slf4j.Slf4j;
import static org.assertj.core.api.Assertions.assertThat;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -15,15 +11,18 @@ import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import static org.assertj.core.api.Assertions.assertThat;
import fr.gouv.clea.clea.scoring.configuration.exposure.ExposureTimeConfiguration;
import fr.gouv.clea.clea.scoring.configuration.exposure.ExposureTimeConfigurationConverter;
import fr.gouv.clea.clea.scoring.configuration.risk.RiskConfiguration;
import fr.gouv.clea.clea.scoring.configuration.risk.RiskConfigurationConverter;
import fr.gouv.clea.clea.scoring.configuration.risk.RiskRule;
@SpringBootTest()
@ExtendWith(SpringExtension.class)
@EnableConfigurationProperties(value = {RiskConfiguration.class, ExposureTimeConfiguration.class})
@ContextConfiguration(classes = {RiskConfigurationConverter.class, ExposureTimeConfigurationConverter.class})
@ActiveProfiles("test")
@Slf4j
class ScoringConfigurationItemTest {
class ScoringRuleTest {
@Autowired
private RiskConfiguration riskConfiguration;
......@@ -73,7 +72,7 @@ class ScoringConfigurationItemTest {
.isEqualTo(riskConfiguration.getScorings().get(6));
}
private ScoringConfigurationItem buildRiskRule(int venueType, int venueCategory1, int venueCategory2,
private ScoringRule buildRiskRule(int venueType, int venueCategory1, int venueCategory2,
int clusterThresholdBackward, int clusterThresholdForward,
float riskLevelBackward, float riskLevelForward) {
return RiskRule.builder()
......
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