Skip to content

Commit

Permalink
#301 - Added implementation for mapper [skip ci]
Browse files Browse the repository at this point in the history
  • Loading branch information
starnowski committed Mar 5, 2024
1 parent 7420227 commit 37e4af4
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,12 @@
import com.fasterxml.jackson.datatype.jdk8.Jdk8Module;
import com.github.starnowski.posmulten.configuration.yaml.exceptions.YamlInvalidSchema;
import com.github.starnowski.posmulten.configuration.yaml.model.SharedSchemaContextConfiguration;
import com.github.starnowski.posmulten.configuration.yaml.validation.groups.ValidatorGroupsResolver;
import org.hibernate.validator.internal.engine.path.NodeImpl;
import org.hibernate.validator.internal.engine.path.PathImpl;

import javax.validation.*;
import javax.validation.groups.Default;
import java.io.File;
import java.io.IOException;
import java.lang.reflect.Field;
Expand Down Expand Up @@ -75,7 +77,11 @@ public void save(SharedSchemaContextConfiguration configuration, String filePath
private void validateConfigurationObject(SharedSchemaContextConfiguration configuration) throws YamlInvalidSchema {
ValidatorFactory factory = Validation.buildDefaultValidatorFactory();
Validator validator = factory.getValidator();
Set<ConstraintViolation<SharedSchemaContextConfiguration>> errors = validator.validate(configuration);
ValidatorGroupsResolver validatorGroupsResolver = new ValidatorGroupsResolver();
List<Class> validationGroupsList = validatorGroupsResolver.resolveForSharedSchemaContextConfiguration(configuration, null);
validationGroupsList.add(Default.class);
Class[] validationGroups = validationGroupsList.toArray(new Class[0]);
Set<ConstraintViolation<SharedSchemaContextConfiguration>> errors = validator.validate(configuration, validationGroups);
if (!errors.isEmpty()) {
throw new YamlInvalidSchema(prepareErrorsMessages(errors));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public class SharedSchemaContextConfigurationMapper implements IConfigurationMap
@Override
public SharedSchemaContextConfiguration map(com.github.starnowski.posmulten.configuration.core.model.SharedSchemaContextConfiguration input) {
return input == null ? null : new SharedSchemaContextConfiguration()
.setCreateForeignKeyConstraintWithTenantColumn(input.getCreateForeignKeyConstraintWithTenantColumn())
.setCurrentTenantIdentifierAsDefaultValueForTenantColumnInAllTables(input.getCurrentTenantIdentifierAsDefaultValueForTenantColumnInAllTables())
.setCurrentTenantIdProperty(input.getCurrentTenantIdProperty() == null ? null : valueOf(input.getCurrentTenantIdProperty()))
.setCurrentTenantIdPropertyType(input.getCurrentTenantIdPropertyType() == null ? null : valueOf(input.getCurrentTenantIdPropertyType()))
Expand All @@ -59,6 +60,7 @@ public SharedSchemaContextConfiguration map(com.github.starnowski.posmulten.conf
@Override
public com.github.starnowski.posmulten.configuration.core.model.SharedSchemaContextConfiguration unmap(SharedSchemaContextConfiguration output) {
return output == null ? null : new com.github.starnowski.posmulten.configuration.core.model.SharedSchemaContextConfiguration()
.setCreateForeignKeyConstraintWithTenantColumn(output.getCreateForeignKeyConstraintWithTenantColumn())
.setCurrentTenantIdentifierAsDefaultValueForTenantColumnInAllTables(output.getCurrentTenantIdentifierAsDefaultValueForTenantColumnInAllTables())
.setCurrentTenantIdProperty(output.getCurrentTenantIdProperty() == null ? null : output.getCurrentTenantIdProperty().getValue())
.setCurrentTenantIdPropertyType(output.getCurrentTenantIdPropertyType() == null ? null : output.getCurrentTenantIdPropertyType().getValue())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,5 @@ public class PrimaryKeyDefinition {
@JsonProperty(value = "name_for_function_that_checks_if_record_exists_in_table")
private String nameForFunctionThatChecksIfRecordExistsInTable;

public static class NameForFunctionThatChecksIfRecordExistsInTableNotBlank {}
public interface NameForFunctionThatChecksIfRecordExistsInTableNotBlank {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class ValidatorGroupsResolverTest extends Specification {
def vgr1 = Mock(ValidatorGroupResolver)
def vgr2 = Mock(ValidatorGroupResolver)
def tested = new ValidatorGroupsResolver([vgr1, vgr2])
def sharedSchemaContextConfiguration = Mock(SharedSchemaContextConfiguration)
def sharedSchemaContextConfiguration = new SharedSchemaContextConfiguration()
def validatorGroupResolverContext = Mock(ValidatorGroupResolver.ValidatorGroupResolverContext)

when:
Expand Down

0 comments on commit 37e4af4

Please sign in to comment.