-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add validation step before code generation
- Loading branch information
Sebastian Hoß
committed
May 31, 2022
1 parent
194ec8c
commit 01f8a20
Showing
37 changed files
with
347 additions
and
169 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
23 changes: 23 additions & 0 deletions
23
yosql-codegen/src/main/java/wtf/metio/yosql/codegen/lifecycle/ValidationLifecycle.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,23 @@ | ||
/* | ||
* This file is part of yosql. It is subject to the license terms in the LICENSE file found in the top-level | ||
* directory of this distribution and at https://creativecommons.org/publicdomain/zero/1.0/. No part of yosql, | ||
* including this file, may be copied, modified, propagated, or distributed except according to the terms contained | ||
* in the LICENSE file. | ||
*/ | ||
|
||
package wtf.metio.yosql.codegen.lifecycle; | ||
|
||
import ch.qos.cal10n.BaseName; | ||
import ch.qos.cal10n.Locale; | ||
import ch.qos.cal10n.LocaleData; | ||
|
||
@LocaleData({@Locale("en"), @Locale("de")}) | ||
@BaseName("validation-lifecycle") | ||
public enum ValidationLifecycle { | ||
|
||
/** | ||
* Signals that the configuration is about to be validated. | ||
*/ | ||
VALIDATE_CONFIGURATION, | ||
|
||
} |
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
37 changes: 0 additions & 37 deletions
37
yosql-codegen/src/main/java/wtf/metio/yosql/codegen/orchestration/OrchestratedYoSQL.java
This file was deleted.
Oops, something went wrong.
23 changes: 0 additions & 23 deletions
23
yosql-codegen/src/main/java/wtf/metio/yosql/codegen/orchestration/Orchestrator.java
This file was deleted.
Oops, something went wrong.
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
29 changes: 29 additions & 0 deletions
29
yosql-codegen/src/main/java/wtf/metio/yosql/codegen/validation/DefaultRuntimeValidator.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 @@ | ||
/* | ||
* This file is part of yosql. It is subject to the license terms in the LICENSE file found in the top-level | ||
* directory of this distribution and at https://creativecommons.org/publicdomain/zero/1.0/. No part of yosql, | ||
* including this file, may be copied, modified, propagated, or distributed except according to the terms contained | ||
* in the LICENSE file. | ||
*/ | ||
|
||
package wtf.metio.yosql.codegen.validation; | ||
|
||
import wtf.metio.yosql.models.immutables.RuntimeConfiguration; | ||
|
||
public final class DefaultRuntimeValidator implements RuntimeValidator { | ||
|
||
private final RuntimeConfiguration runtimeConfiguration; | ||
private final RuntimeConfigurationValidator runtimeConfigurationValidator; | ||
|
||
public DefaultRuntimeValidator( | ||
final RuntimeConfiguration runtimeConfiguration, | ||
final RuntimeConfigurationValidator runtimeConfigurationValidator) { | ||
this.runtimeConfiguration = runtimeConfiguration; | ||
this.runtimeConfigurationValidator = runtimeConfigurationValidator; | ||
} | ||
|
||
@Override | ||
public void validate() { | ||
runtimeConfigurationValidator.validate(runtimeConfiguration); | ||
} | ||
|
||
} |
30 changes: 30 additions & 0 deletions
30
...main/java/wtf/metio/yosql/codegen/validation/DelegatingRuntimeConfigurationValidator.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,30 @@ | ||
/* | ||
* This file is part of yosql. It is subject to the license terms in the LICENSE file found in the top-level | ||
* directory of this distribution and at https://creativecommons.org/publicdomain/zero/1.0/. No part of yosql, | ||
* including this file, may be copied, modified, propagated, or distributed except according to the terms contained | ||
* in the LICENSE file. | ||
*/ | ||
|
||
package wtf.metio.yosql.codegen.validation; | ||
|
||
import wtf.metio.yosql.models.immutables.RuntimeConfiguration; | ||
|
||
import java.util.Set; | ||
|
||
/** | ||
* Delegates {@link RuntimeConfiguration} validation to a set of {@link RuntimeConfigurationValidator}s. | ||
*/ | ||
public final class DelegatingRuntimeConfigurationValidator implements RuntimeConfigurationValidator { | ||
|
||
private final Set<RuntimeConfigurationValidator> validators; | ||
|
||
public DelegatingRuntimeConfigurationValidator(final Set<RuntimeConfigurationValidator> validators) { | ||
this.validators = validators; | ||
} | ||
|
||
@Override | ||
public void validate(final RuntimeConfiguration configuration) { | ||
validators.forEach(validator -> validator.validate(configuration)); | ||
} | ||
|
||
} |
48 changes: 48 additions & 0 deletions
48
...codegen/src/main/java/wtf/metio/yosql/codegen/validation/NamesConfigurationValidator.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,48 @@ | ||
/* | ||
* This file is part of yosql. It is subject to the license terms in the LICENSE file found in the top-level | ||
* directory of this distribution and at https://creativecommons.org/publicdomain/zero/1.0/. No part of yosql, | ||
* including this file, may be copied, modified, propagated, or distributed except according to the terms contained | ||
* in the LICENSE file. | ||
*/ | ||
|
||
package wtf.metio.yosql.codegen.validation; | ||
|
||
import ch.qos.cal10n.IMessageConveyor; | ||
import wtf.metio.yosql.codegen.exceptions.InvalidNameConfigurationException; | ||
import wtf.metio.yosql.codegen.lifecycle.ExecutionErrors; | ||
import wtf.metio.yosql.models.immutables.RuntimeConfiguration; | ||
|
||
import java.util.Map; | ||
import java.util.stream.Collectors; | ||
|
||
import static wtf.metio.yosql.codegen.lifecycle.ApplicationErrors.NAMES_CONFIG_INVALID; | ||
|
||
/** | ||
* Validates {@link wtf.metio.yosql.models.immutables.NamesConfiguration}s. | ||
*/ | ||
public final class NamesConfigurationValidator implements RuntimeConfigurationValidator { | ||
|
||
private final ExecutionErrors errors; | ||
private final IMessageConveyor messages; | ||
|
||
public NamesConfigurationValidator(final ExecutionErrors errors, final IMessageConveyor messages) { | ||
this.errors = errors; | ||
this.messages = messages; | ||
} | ||
|
||
@Override | ||
public void validate(final RuntimeConfiguration configuration) { | ||
final var names = configuration.names(); | ||
|
||
final var counts = names.uniqueValueCount(); | ||
final var duplicates = counts.entrySet().stream() | ||
.filter(entry -> entry.getValue() > 1) | ||
.map(Map.Entry::getKey) | ||
.collect(Collectors.toSet()); | ||
|
||
if (!duplicates.isEmpty()) { | ||
errors.add(new InvalidNameConfigurationException(messages.getMessage(NAMES_CONFIG_INVALID, duplicates))); | ||
} | ||
} | ||
|
||
} |
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.