-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use var keyword and add validation props
- Loading branch information
Showing
30 changed files
with
153 additions
and
60 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
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
5 changes: 5 additions & 0 deletions
5
libs/essentials/src/main/java/smecalculus/bezmen/configuration/ValidationMode.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,5 @@ | ||
package smecalculus.bezmen.configuration; | ||
|
||
public enum ValidationMode { | ||
HIBERNATE_VALIDATOR | ||
} |
7 changes: 7 additions & 0 deletions
7
libs/essentials/src/main/java/smecalculus/bezmen/configuration/ValidationProps.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,7 @@ | ||
package smecalculus.bezmen.configuration; | ||
|
||
import lombok.Builder; | ||
import lombok.NonNull; | ||
|
||
@Builder | ||
public record ValidationProps(@NonNull ValidationMode validationMode) {} |
8 changes: 8 additions & 0 deletions
8
libs/essentials/src/main/java/smecalculus/bezmen/configuration/ValidationPropsEdge.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,8 @@ | ||
package smecalculus.bezmen.configuration; | ||
|
||
import lombok.Data; | ||
|
||
@Data | ||
public class ValidationPropsEdge { | ||
private String mode; | ||
} |
15 changes: 15 additions & 0 deletions
15
...essentials/src/main/java/smecalculus/bezmen/construction/ConditionalOnValidationMode.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,15 @@ | ||
package smecalculus.bezmen.construction; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
import org.springframework.context.annotation.Conditional; | ||
import smecalculus.bezmen.configuration.ValidationMode; | ||
|
||
@Target({ElementType.TYPE, ElementType.METHOD}) | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@Conditional(ValidationModeCondition.class) | ||
public @interface ConditionalOnValidationMode { | ||
ValidationMode value(); | ||
} |
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
26 changes: 23 additions & 3 deletions
26
libs/essentials/src/main/java/smecalculus/bezmen/construction/ValidationBeans.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 |
---|---|---|
@@ -1,18 +1,38 @@ | ||
package smecalculus.bezmen.construction; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
import static smecalculus.bezmen.configuration.ValidationMode.HIBERNATE_VALIDATOR; | ||
|
||
import jakarta.validation.Validation; | ||
import jakarta.validation.ValidatorFactory; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import smecalculus.bezmen.configuration.PropsKeeper; | ||
import smecalculus.bezmen.configuration.ValidationProps; | ||
import smecalculus.bezmen.configuration.ValidationPropsEdge; | ||
import smecalculus.bezmen.validation.EdgeValidator; | ||
import smecalculus.bezmen.validation.EdgeValidatorHibernateValidator; | ||
import smecalculus.bezmen.validation.ValidationPropsMapper; | ||
|
||
@Configuration(proxyBeanMethods = false) | ||
public class ValidationBeans { | ||
|
||
private static final Logger LOG = LoggerFactory.getLogger(ValidationBeans.class); | ||
|
||
@Bean | ||
ValidationProps validationProps(PropsKeeper keeper, ValidationPropsMapper mapper) { | ||
var propsEdge = keeper.read("bezmen.validation", ValidationPropsEdge.class); | ||
requireNonNull(propsEdge.getMode(), "validation mode must not be null"); | ||
LOG.info("Read {}", propsEdge); | ||
return mapper.toDomain(propsEdge); | ||
} | ||
|
||
@Bean | ||
@ConditionalOnValidationMode(HIBERNATE_VALIDATOR) | ||
EdgeValidator edgeValidatorHibernateValidator() { | ||
ValidatorFactory factory = Validation.buildDefaultValidatorFactory(); | ||
return new EdgeValidatorHibernateValidator(factory.getValidator()); | ||
try (var factory = Validation.buildDefaultValidatorFactory()) { | ||
return new EdgeValidatorHibernateValidator(factory.getValidator()); | ||
} | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
libs/essentials/src/main/java/smecalculus/bezmen/construction/ValidationModeCondition.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,26 @@ | ||
package smecalculus.bezmen.construction; | ||
|
||
import static org.springframework.context.annotation.ConfigurationCondition.ConfigurationPhase.REGISTER_BEAN; | ||
|
||
import lombok.NonNull; | ||
import org.springframework.context.annotation.ConditionContext; | ||
import org.springframework.context.annotation.ConfigurationCondition; | ||
import org.springframework.core.type.AnnotatedTypeMetadata; | ||
import smecalculus.bezmen.configuration.ValidationMode; | ||
import smecalculus.bezmen.configuration.ValidationProps; | ||
|
||
class ValidationModeCondition implements ConfigurationCondition { | ||
|
||
@Override | ||
public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) { | ||
var attributes = metadata.getAnnotationAttributes(ConditionalOnValidationMode.class.getName()); | ||
var mode = (ValidationMode) attributes.get("value"); | ||
var props = context.getBeanFactory().getBean(ValidationProps.class); | ||
return mode == props.validationMode(); | ||
} | ||
|
||
@Override | ||
public @NonNull ConfigurationPhase getConfigurationPhase() { | ||
return REGISTER_BEAN; | ||
} | ||
} |
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
15 changes: 15 additions & 0 deletions
15
libs/essentials/src/main/java/smecalculus/bezmen/validation/ValidationPropsMapper.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,15 @@ | ||
package smecalculus.bezmen.validation; | ||
|
||
import org.mapstruct.Mapping; | ||
import smecalculus.bezmen.configuration.ValidationMode; | ||
import smecalculus.bezmen.configuration.ValidationProps; | ||
import smecalculus.bezmen.configuration.ValidationPropsEdge; | ||
|
||
public interface ValidationPropsMapper { | ||
@Mapping(source = "mode", target = "validationMode") | ||
ValidationProps toDomain(ValidationPropsEdge propsEdge); | ||
|
||
default ValidationMode toValidationMode(String value) { | ||
return ValidationMode.valueOf(value.toUpperCase()); | ||
} | ||
} |
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,5 @@ | ||
bezmen { | ||
validation { | ||
mode = hibernate_validator | ||
} | ||
} |
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 @@ | ||
bezmen.validation.mode=hibernate_validator |
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
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
3 changes: 2 additions & 1 deletion
3
libs/storage/src/main/java/smecalculus/bezmen/configuration/StateMappingProps.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 |
---|---|---|
@@ -1,6 +1,7 @@ | ||
package smecalculus.bezmen.configuration; | ||
|
||
import lombok.Builder; | ||
import lombok.NonNull; | ||
|
||
@Builder | ||
public record StateMappingProps(StateMappingMode mappingMode) {} | ||
public record StateMappingProps(@NonNull StateMappingMode mappingMode) {} |
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
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
Oops, something went wrong.