diff --git a/common/build.gradle b/common/build.gradle index 3aa786309..2c7634873 100644 --- a/common/build.gradle +++ b/common/build.gradle @@ -31,6 +31,8 @@ dependencies { compile "com.fasterxml.jackson.core:jackson-core:${JACKSON_VERSION}" compile "com.fasterxml.jackson.core:jackson-annotations:${JACKSON_VERSION}" compile "com.fasterxml.jackson.core:jackson-databind:${JACKSON_VERSION}" + compile group: "com.google.inject", name: "guice", version: "${GUICE_VERSION}" + implementation "org.threeten:threeten-extra:${THREE_TEN_VERSION}" testCompile "org.junit.jupiter:junit-jupiter-api:${JUNIT_JUPITER_VERSION}" testCompile "junit:junit:${JUNIT_4_VERSION}" diff --git a/common/src/main/java/com/scottlogic/deg/common/ValidationException.java b/common/src/main/java/com/scottlogic/deg/common/ValidationException.java index 0226a04a1..3fcf39b72 100644 --- a/common/src/main/java/com/scottlogic/deg/common/ValidationException.java +++ b/common/src/main/java/com/scottlogic/deg/common/ValidationException.java @@ -28,7 +28,7 @@ public ValidationException(String msg) { } public ValidationException(List errorMessages){ - super(); + super(String.join("\n", errorMessages)); this.errorMessages = errorMessages; } } diff --git a/common/src/main/java/com/scottlogic/deg/common/commands/Command.java b/common/src/main/java/com/scottlogic/deg/common/commands/Command.java new file mode 100644 index 000000000..3a659a1ee --- /dev/null +++ b/common/src/main/java/com/scottlogic/deg/common/commands/Command.java @@ -0,0 +1,13 @@ +package com.scottlogic.deg.common.commands; + +import java.lang.reflect.Type; + +public abstract class Command +{ + public Type commandType; + + protected Command() + { + commandType = getClass(); + } +} diff --git a/common/src/main/java/com/scottlogic/deg/common/commands/CommandBus.java b/common/src/main/java/com/scottlogic/deg/common/commands/CommandBus.java new file mode 100644 index 000000000..04c3e993b --- /dev/null +++ b/common/src/main/java/com/scottlogic/deg/common/commands/CommandBus.java @@ -0,0 +1,26 @@ +package com.scottlogic.deg.common.commands; + +import org.apache.commons.lang3.tuple.ImmutablePair; +import org.apache.commons.lang3.tuple.Pair; + +import java.util.HashMap; +import java.util.Map; + +public abstract class CommandBus +{ + private final Map, Pair, ? extends CommandHandler>> map = new HashMap<>(); + + protected , TResponse> void register(Class commandClass, CommandHandler handler) + { + map.put(commandClass, new ImmutablePair<>(handler.getClass(), handler)); + } + + public , TResponse> CommandResult send(TCommand command) + { + Class commandClass = command.getClass(); + Class commandHandlerClass = map.get(commandClass).getKey(); + CommandHandler commandHandler = map.get(commandClass).getValue(); + + return commandHandlerClass.cast(commandHandler).handle(command); + } +} diff --git a/common/src/main/java/com/scottlogic/deg/common/commands/CommandHandler.java b/common/src/main/java/com/scottlogic/deg/common/commands/CommandHandler.java new file mode 100644 index 000000000..e86f61dbe --- /dev/null +++ b/common/src/main/java/com/scottlogic/deg/common/commands/CommandHandler.java @@ -0,0 +1,24 @@ +package com.scottlogic.deg.common.commands; + +import com.scottlogic.deg.common.validators.ValidationResult; +import com.scottlogic.deg.common.validators.Validator; + +public abstract class CommandHandler, TResponse> +{ + private final Validator validator; + + protected CommandHandler(Validator validator) + { + this.validator = validator; + } + + public CommandResult handle(TCommand command) + { + ValidationResult validationResult = validator.validate(command); + if(validationResult.isValid) return handleCommand(command); + return CommandResult.failure(validationResult.errors); + } + + public abstract CommandResult handleCommand(TCommand command); +} + diff --git a/common/src/main/java/com/scottlogic/deg/common/commands/CommandResult.java b/common/src/main/java/com/scottlogic/deg/common/commands/CommandResult.java new file mode 100644 index 000000000..91f46c09d --- /dev/null +++ b/common/src/main/java/com/scottlogic/deg/common/commands/CommandResult.java @@ -0,0 +1,52 @@ +package com.scottlogic.deg.common.commands; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.List; +import java.util.function.Function; +import java.util.stream.Collectors; + +public class CommandResult +{ + public final T value; + public final boolean isSuccess; + public final List errors; + + private CommandResult(T value, boolean isSuccess, List errors) + { + this.value = value; + this.isSuccess = isSuccess; + this.errors = errors; + } + + public static CommandResult success(T value) + { + return new CommandResult<>(value, true, new ArrayList<>()); + } + + @SafeVarargs + public static CommandResult failure(List... errors) + { + return new CommandResult<>(null, false, Arrays.stream(errors).flatMap(Collection::stream).collect(Collectors.toList())); + } + + public CommandResult map(Function mapping) + { + return isSuccess ? success(mapping.apply(value)) : failure(errors); + } + + + public static CommandResult> combine(List> results) + { + List values = new ArrayList<>(); + List errors = new ArrayList<>(); + results.forEach(result -> + { + if(result.isSuccess) values.add(result.value); + else errors.addAll(result.errors); + }); + + return values.size() == results.size() ? CommandResult.success(values) : CommandResult.failure(errors); + } +} diff --git a/common/src/main/java/com/scottlogic/deg/common/profile/Field.java b/common/src/main/java/com/scottlogic/deg/common/profile/Field.java index 9d3ee0afe..7770f5240 100644 --- a/common/src/main/java/com/scottlogic/deg/common/profile/Field.java +++ b/common/src/main/java/com/scottlogic/deg/common/profile/Field.java @@ -19,31 +19,51 @@ import java.util.Objects; public class Field { - public final String name; - private final FieldType type; + private final String name; + private final SpecificFieldType type; private final boolean unique; private final String formatting; private final boolean internal; + private final boolean nullable; - public Field(String name, FieldType type, boolean unique, String formatting, boolean internal) { + public Field(String name, SpecificFieldType type, boolean unique, String formatting, boolean internal, boolean nullable) { this.name = name; this.type = type; this.unique = unique; this.formatting = formatting; this.internal = internal; + this.nullable = nullable; } - public boolean isInternal() { - return internal; + public FieldType getType() { + return type.getFieldType(); + } + + public SpecificFieldType getSpecificType() { + return type; } public boolean isUnique() { return unique; } + public String getFormatting() { + return formatting; + } + + public boolean isInternal() { + return internal; + } + + public boolean isNullable() + { + return nullable; + } + + @Override public String toString() { - return this.name; + return this.getName(); } @Override @@ -54,20 +74,17 @@ public boolean equals(Object o) { return Objects.equals(name, field.name) && Objects.equals(unique, field.unique) && Objects.equals(type, field.type) - && Objects.equals(formatting, field.formatting); + && Objects.equals(formatting, field.formatting) + && Objects.equals(nullable, field.nullable); } @Override public int hashCode() { - return Objects.hash(name, unique, formatting, type); - } - - public String getFormatting() { - return formatting; + return Objects.hash(name, unique, formatting, type, nullable); } - public FieldType getType() { - return type; + public String getName() + { + return name; } - } diff --git a/common/src/main/java/com/scottlogic/deg/common/profile/ProfileFields.java b/common/src/main/java/com/scottlogic/deg/common/profile/Fields.java similarity index 86% rename from common/src/main/java/com/scottlogic/deg/common/profile/ProfileFields.java rename to common/src/main/java/com/scottlogic/deg/common/profile/Fields.java index 34eb9bfeb..55c14035b 100644 --- a/common/src/main/java/com/scottlogic/deg/common/profile/ProfileFields.java +++ b/common/src/main/java/com/scottlogic/deg/common/profile/Fields.java @@ -22,16 +22,16 @@ import java.util.List; import java.util.stream.Stream; -public class ProfileFields implements Iterable { +public class Fields implements Iterable { private final List fields; - public ProfileFields(List fields) { + public Fields(List fields) { this.fields = fields; } public Field getByName(String fieldName) { return this.fields.stream() - .filter(f -> f.name.equals(fieldName)) + .filter(f -> f.getName().equals(fieldName)) .findFirst() .orElseThrow(() -> new IllegalArgumentException("Profile fields do not contain " + fieldName)); } @@ -66,8 +66,8 @@ public boolean equals(Object obj) { return false; } - ProfileFields profileFields = (ProfileFields) obj; - return fields.equals(profileFields.fields); + Fields fields = (Fields) obj; + return this.fields.equals(fields.fields); } @Override diff --git a/common/src/main/java/com/scottlogic/deg/common/validators/ValidationResult.java b/common/src/main/java/com/scottlogic/deg/common/validators/ValidationResult.java new file mode 100644 index 000000000..2782921c3 --- /dev/null +++ b/common/src/main/java/com/scottlogic/deg/common/validators/ValidationResult.java @@ -0,0 +1,54 @@ +package com.scottlogic.deg.common.validators; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; + +public class ValidationResult +{ + public final boolean isValid; + public final List errors; + + private ValidationResult(boolean isValid, List errors) + { + this.isValid = isValid; + this.errors = errors; + } + + public static ValidationResult success(){ + return new ValidationResult(true, new ArrayList<>()); + } + + public static ValidationResult failure(String... errors) + { + return new ValidationResult(false, Arrays.stream(errors).collect(Collectors.toList())); + } + + public static ValidationResult failure(List errors) + { + return new ValidationResult(false, errors); + } + + public static ValidationResult combine(List validationResults) + { + boolean isValid = validationResults.stream() + .allMatch(validationResult -> validationResult.isValid); + List errors = validationResults.stream() + .flatMap(validationResult -> validationResult.errors.stream()) + .collect(Collectors.toList()); + return new ValidationResult(isValid, errors); + } + + public static ValidationResult combine(ValidationResult... validationResults) + { + boolean isValid = Arrays.stream(validationResults) + .allMatch(validationResult -> validationResult.isValid); + List errors = Arrays.stream(validationResults) + .flatMap(validationResult -> validationResult.errors.stream()) + .collect(Collectors.toList()); + return new ValidationResult(isValid, errors); + } +} + + diff --git a/common/src/main/java/com/scottlogic/deg/common/validators/Validator.java b/common/src/main/java/com/scottlogic/deg/common/validators/Validator.java new file mode 100644 index 000000000..e2c42672d --- /dev/null +++ b/common/src/main/java/com/scottlogic/deg/common/validators/Validator.java @@ -0,0 +1,6 @@ +package com.scottlogic.deg.common.validators; + +public interface Validator +{ + ValidationResult validate(T obj); +} diff --git a/common/src/test/java/com/scottlogic/deg/common/profile/FieldBuilder.java b/common/src/test/java/com/scottlogic/deg/common/profile/FieldBuilder.java index 800671ef4..fa801939d 100644 --- a/common/src/test/java/com/scottlogic/deg/common/profile/FieldBuilder.java +++ b/common/src/test/java/com/scottlogic/deg/common/profile/FieldBuilder.java @@ -18,15 +18,15 @@ public class FieldBuilder { public static Field createField(String name) { - return createField(name, FieldType.STRING); + return createField(name, SpecificFieldType.STRING); } public static Field createInternalField(String name) { - return createInternalField(name, FieldType.STRING); + return createInternalField(name, SpecificFieldType.STRING); } - public static Field createField(String name, FieldType type) { - return new Field(name, type, false, null, false); + public static Field createField(String name, SpecificFieldType type) { + return new Field(name, type, false, null, false, false); } - public static Field createInternalField(String name, FieldType type) { - return new Field(name, type, false, null, true); + public static Field createInternalField(String name, SpecificFieldType type) { + return new Field(name, type, false, null, true, false); } } diff --git a/common/src/test/java/com/scottlogic/deg/common/profile/ProfileFieldsTests.java b/common/src/test/java/com/scottlogic/deg/common/profile/FieldsTests.java similarity index 82% rename from common/src/test/java/com/scottlogic/deg/common/profile/ProfileFieldsTests.java rename to common/src/test/java/com/scottlogic/deg/common/profile/FieldsTests.java index 56d20e466..51aac62c8 100644 --- a/common/src/test/java/com/scottlogic/deg/common/profile/ProfileFieldsTests.java +++ b/common/src/test/java/com/scottlogic/deg/common/profile/FieldsTests.java @@ -23,10 +23,11 @@ import java.util.Arrays; import static com.scottlogic.deg.common.profile.FieldBuilder.createField; -class ProfileFieldsTests { +class FieldsTests +{ @Test void equals_objIsNull_returnsFalse() { - ProfileFields fields = new ProfileFields( + Fields fields = new Fields( Arrays.asList( createField("Test") ) @@ -42,7 +43,7 @@ void equals_objIsNull_returnsFalse() { @Test void equals_objTypeIsNotProfileFields_returnsFalse() { - ProfileFields fields = new ProfileFields( + Fields fields = new Fields( Arrays.asList( createField("Test") ) @@ -58,7 +59,7 @@ void equals_objTypeIsNotProfileFields_returnsFalse() { @Test void equals_rowSpecFieldsLengthNotEqualToOtherObjectFieldsLength_returnsFalse() { - ProfileFields fields = new ProfileFields( + Fields fields = new Fields( Arrays.asList( createField("First Field"), createField("Second Field") @@ -66,7 +67,7 @@ void equals_rowSpecFieldsLengthNotEqualToOtherObjectFieldsLength_returnsFalse() ); boolean result = fields.equals( - new ProfileFields( + new Fields( Arrays.asList( createField("First Field") ) @@ -81,7 +82,7 @@ void equals_rowSpecFieldsLengthNotEqualToOtherObjectFieldsLength_returnsFalse() @Test void equals_rowSpecFieldsLengthEqualToOterObjectFieldsLengthButValuesDiffer_returnsFalse() { - ProfileFields fields = new ProfileFields( + Fields fields = new Fields( Arrays.asList( createField("First Field"), createField("Second Field") @@ -89,7 +90,7 @@ void equals_rowSpecFieldsLengthEqualToOterObjectFieldsLengthButValuesDiffer_retu ); boolean result = fields.equals( - new ProfileFields( + new Fields( Arrays.asList( createField("First Field"), createField("Third Field") @@ -105,7 +106,7 @@ void equals_rowSpecFieldsLengthEqualToOterObjectFieldsLengthButValuesDiffer_retu @Test void equals_rowSpecFieldsAreEqualToTheFieldsOfTheOtherObject_returnsTrue() { - ProfileFields fields = new ProfileFields( + Fields fields = new Fields( Arrays.asList( createField("First Field"), createField("Second Field") @@ -113,7 +114,7 @@ void equals_rowSpecFieldsAreEqualToTheFieldsOfTheOtherObject_returnsTrue() { ); boolean result = fields.equals( - new ProfileFields( + new Fields( Arrays.asList( createField("First Field"), createField("Second Field") @@ -129,13 +130,13 @@ void equals_rowSpecFieldsAreEqualToTheFieldsOfTheOtherObject_returnsTrue() { @Test void hashCode_valuesinFieldsDifferInSize_returnsDifferentHashCodes() { - ProfileFields firstProfileFields = new ProfileFields( + Fields firstFields = new Fields( Arrays.asList( createField("First Field"), createField("Second Field") ) ); - ProfileFields secondProfileFields = new ProfileFields( + Fields secondFields = new Fields( Arrays.asList( createField("First Field"), createField("Second Field"), @@ -143,8 +144,8 @@ void hashCode_valuesinFieldsDifferInSize_returnsDifferentHashCodes() { ) ); - int firstHashCode = firstProfileFields.hashCode(); - int secondHashCode = secondProfileFields.hashCode(); + int firstHashCode = firstFields.hashCode(); + int secondHashCode = secondFields.hashCode(); assertNotEquals( "Expected that when the profile fields length differ the hash codes should not be the same but were equal", @@ -155,21 +156,21 @@ void hashCode_valuesinFieldsDifferInSize_returnsDifferentHashCodes() { @Test void hashCode_valuesInFieldsAreEqualSizeButValuesDiffer_returnsDifferentHashCodes() { - ProfileFields firstProfileFields = new ProfileFields( + Fields firstFields = new Fields( Arrays.asList( createField("First Field"), createField("Second Field") ) ); - ProfileFields secondProfileFields = new ProfileFields( + Fields secondFields = new Fields( Arrays.asList( createField("First Field"), createField("Third Field") ) ); - int firstHashCode = firstProfileFields.hashCode(); - int secondHashCode = secondProfileFields.hashCode(); + int firstHashCode = firstFields.hashCode(); + int secondHashCode = secondFields.hashCode(); assertNotEquals( "Expected when the fields length are equal but their values differ unique hash codes are returned but were equal", @@ -180,21 +181,21 @@ void hashCode_valuesInFieldsAreEqualSizeButValuesDiffer_returnsDifferentHashCode @Test void hashCode_valuesInFieldsAreEqual_identicalHashCodesAreReturned() { - ProfileFields firstProfileFields = new ProfileFields( + Fields firstFields = new Fields( Arrays.asList( createField("First Field"), createField("Second Field") ) ); - ProfileFields secondProfileFields = new ProfileFields( + Fields secondFields = new Fields( Arrays.asList( createField("First Field"), createField("Second Field") ) ); - int firstHashCode = firstProfileFields.hashCode(); - int secondHashCode = secondProfileFields.hashCode(); + int firstHashCode = firstFields.hashCode(); + int secondHashCode = secondFields.hashCode(); assertEquals( "Expected that when the profile fields are equal an equivalent hash code should be returned for both but were different", diff --git a/generator/src/main/java/com/scottlogic/deg/generator/decisiontree/DecisionTree.java b/generator/src/main/java/com/scottlogic/deg/generator/decisiontree/DecisionTree.java index 3328e1b23..5a3a7ccaf 100644 --- a/generator/src/main/java/com/scottlogic/deg/generator/decisiontree/DecisionTree.java +++ b/generator/src/main/java/com/scottlogic/deg/generator/decisiontree/DecisionTree.java @@ -16,13 +16,13 @@ package com.scottlogic.deg.generator.decisiontree; -import com.scottlogic.deg.common.profile.ProfileFields; +import com.scottlogic.deg.common.profile.Fields; public class DecisionTree { public final ConstraintNode rootNode; - public final ProfileFields fields; + public final Fields fields; - public DecisionTree(ConstraintNode rootNode, ProfileFields fields) { + public DecisionTree(ConstraintNode rootNode, Fields fields) { this.rootNode = rootNode; this.fields = fields; } @@ -31,7 +31,7 @@ public ConstraintNode getRootNode() { return rootNode; } - public ProfileFields getFields() { + public Fields getFields() { return fields; } diff --git a/generator/src/main/java/com/scottlogic/deg/generator/decisiontree/treepartitioning/TreePartitioner.java b/generator/src/main/java/com/scottlogic/deg/generator/decisiontree/treepartitioning/TreePartitioner.java index e2e1fed99..7cc00f791 100644 --- a/generator/src/main/java/com/scottlogic/deg/generator/decisiontree/treepartitioning/TreePartitioner.java +++ b/generator/src/main/java/com/scottlogic/deg/generator/decisiontree/treepartitioning/TreePartitioner.java @@ -17,7 +17,7 @@ package com.scottlogic.deg.generator.decisiontree.treepartitioning; import com.scottlogic.deg.common.profile.Field; -import com.scottlogic.deg.common.profile.ProfileFields; +import com.scottlogic.deg.common.profile.Fields; import com.scottlogic.deg.generator.fieldspecs.relations.FieldSpecRelations; import com.scottlogic.deg.generator.profile.constraints.atomic.AtomicConstraint; import com.scottlogic.deg.common.util.FlatMappingSpliterator; @@ -88,12 +88,12 @@ public Stream splitTreeIntoPartitions(DecisionTree decisionTree) { .addRelations(partition.getRelations()) .setDecisions(partition.getDecisionNodes()) .build(), - new ProfileFields(new ArrayList<>(partition.fields)) + new Fields(new ArrayList<>(partition.fields)) )), unpartitionedFields .map(field -> new DecisionTree( new ConstraintNodeBuilder().build(), - new ProfileFields(Collections.singletonList(field)) + new Fields(Collections.singletonList(field)) )) ); } diff --git a/generator/src/main/java/com/scottlogic/deg/generator/decisiontree/visualisation/DecisionTreeVisualisationWriter.java b/generator/src/main/java/com/scottlogic/deg/generator/decisiontree/visualisation/DecisionTreeVisualisationWriter.java index ebd27cd48..3dcae7d74 100644 --- a/generator/src/main/java/com/scottlogic/deg/generator/decisiontree/visualisation/DecisionTreeVisualisationWriter.java +++ b/generator/src/main/java/com/scottlogic/deg/generator/decisiontree/visualisation/DecisionTreeVisualisationWriter.java @@ -203,7 +203,7 @@ String renderNode(String id, DecisionNode node){ String renderNode(String id, ConstraintNode node){ String label = node.getAtomicConstraints() .stream() - .sorted(Comparator.comparing(ac -> ac.getField().name)) + .sorted(Comparator.comparing(ac -> ac.getField().getName())) .map(AtomicConstraint::toString) .collect(Collectors.joining("\r\n")); diff --git a/generator/src/main/java/com/scottlogic/deg/generator/fieldspecs/RowSpec.java b/generator/src/main/java/com/scottlogic/deg/generator/fieldspecs/RowSpec.java index d23f3a466..7bcfe6e8c 100644 --- a/generator/src/main/java/com/scottlogic/deg/generator/fieldspecs/RowSpec.java +++ b/generator/src/main/java/com/scottlogic/deg/generator/fieldspecs/RowSpec.java @@ -17,7 +17,7 @@ package com.scottlogic.deg.generator.fieldspecs; import com.scottlogic.deg.common.profile.Field; -import com.scottlogic.deg.common.profile.ProfileFields; +import com.scottlogic.deg.common.profile.Fields; import com.scottlogic.deg.generator.fieldspecs.relations.FieldSpecRelations; import java.util.*; @@ -28,12 +28,12 @@ * Typically created by combining choices over a decision tree. */ public class RowSpec { - private final ProfileFields fields; + private final Fields fields; private final Map fieldToFieldSpec; private final List relations; - public RowSpec(ProfileFields fields, + public RowSpec(Fields fields, Map fieldToFieldSpec, List relations) { @@ -42,7 +42,7 @@ public RowSpec(ProfileFields fields, this.relations = relations; } - public ProfileFields getFields() { + public Fields getFields() { return fields; } diff --git a/generator/src/main/java/com/scottlogic/deg/generator/fieldspecs/RowSpecMerger.java b/generator/src/main/java/com/scottlogic/deg/generator/fieldspecs/RowSpecMerger.java index 72dba1b43..8e1c63552 100644 --- a/generator/src/main/java/com/scottlogic/deg/generator/fieldspecs/RowSpecMerger.java +++ b/generator/src/main/java/com/scottlogic/deg/generator/fieldspecs/RowSpecMerger.java @@ -18,13 +18,10 @@ import com.google.inject.Inject; import com.scottlogic.deg.common.profile.Field; -import com.scottlogic.deg.common.profile.ProfileFields; import com.scottlogic.deg.generator.fieldspecs.relations.FieldSpecRelations; import com.scottlogic.deg.generator.utils.SetUtils; import java.util.*; -import java.util.function.Function; -import java.util.stream.Collectors; public class RowSpecMerger { private final FieldSpecMerger fieldSpecMerger; diff --git a/generator/src/main/java/com/scottlogic/deg/generator/generation/databags/DataBag.java b/generator/src/main/java/com/scottlogic/deg/generator/generation/databags/DataBag.java index 71e18bb76..cc7bcd2b3 100644 --- a/generator/src/main/java/com/scottlogic/deg/generator/generation/databags/DataBag.java +++ b/generator/src/main/java/com/scottlogic/deg/generator/generation/databags/DataBag.java @@ -76,7 +76,7 @@ public static DataBag merge(DataBag... bags) { entrySetStream -> entrySetStream) .forEach(entry -> { if (newFieldToValue.containsKey(entry.getKey())) - throw new IllegalArgumentException("Databags can't be merged because they overlap on field " + entry.getKey().name); + throw new IllegalArgumentException("Databags can't be merged because they overlap on field " + entry.getKey().getName()); newFieldToValue.put(entry.getKey(), entry.getValue()); }); diff --git a/generator/src/main/java/com/scottlogic/deg/generator/profile/Profile.java b/generator/src/main/java/com/scottlogic/deg/generator/profile/Profile.java index 2b8385aab..a57d99792 100644 --- a/generator/src/main/java/com/scottlogic/deg/generator/profile/Profile.java +++ b/generator/src/main/java/com/scottlogic/deg/generator/profile/Profile.java @@ -17,35 +17,35 @@ package com.scottlogic.deg.generator.profile; import com.scottlogic.deg.common.profile.Field; -import com.scottlogic.deg.common.profile.ProfileFields; +import com.scottlogic.deg.common.profile.Fields; import java.util.Collection; import java.util.List; public class Profile { - private final ProfileFields fields; + private final Fields fields; private final Collection rules; private final String description; public Profile(List fields, Collection rules) { - this(new ProfileFields(fields), rules, null); + this(new Fields(fields), rules, null); } public Profile(List fields, Collection rules, String description) { - this(new ProfileFields(fields), rules, description); + this(new Fields(fields), rules, description); } - public Profile(ProfileFields fields, Collection rules) { + public Profile(Fields fields, Collection rules) { this(fields, rules, null); } - public Profile(ProfileFields fields, Collection rules, String description) { + public Profile(Fields fields, Collection rules, String description) { this.fields = fields; this.rules = rules; this.description = description; } - public ProfileFields getFields() { + public Fields getFields() { return fields; } diff --git a/generator/src/main/java/com/scottlogic/deg/generator/profile/Rule.java b/generator/src/main/java/com/scottlogic/deg/generator/profile/Rule.java index d8f3031bf..a6fcfd5cf 100644 --- a/generator/src/main/java/com/scottlogic/deg/generator/profile/Rule.java +++ b/generator/src/main/java/com/scottlogic/deg/generator/profile/Rule.java @@ -22,17 +22,17 @@ public class Rule { - private final RuleInformation ruleInformation; + private final String description; private final Collection constraints; - public Rule(RuleInformation ruleInformation, Collection constraints) + public Rule(String description, Collection constraints) { - this.ruleInformation = ruleInformation; + this.description = description != null ? description : "Unnamed rule"; this.constraints = constraints; } - public RuleInformation getRuleInformation() { - return ruleInformation; + public String getDescription() { + return description; } public Collection getConstraints() { diff --git a/generator/src/main/java/com/scottlogic/deg/generator/profile/RuleInformation.java b/generator/src/main/java/com/scottlogic/deg/generator/profile/RuleInformation.java deleted file mode 100644 index c4a607958..000000000 --- a/generator/src/main/java/com/scottlogic/deg/generator/profile/RuleInformation.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright 2019 Scott Logic Ltd - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.scottlogic.deg.generator.profile; - -import java.util.Objects; - -public class RuleInformation { - private final String description; - - public RuleInformation(){ - this(null); - } - - public RuleInformation(String rule) { - this.description = rule != null ? rule : "Unnamed rule"; - } - - public String getDescription() { - return this.description; - } - - @Override - public String toString() { - return this.description; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - RuleInformation that = (RuleInformation) o; - return Objects.equals(description, that.description); - } - - @Override - public int hashCode() { - return description.hashCode(); - } -} diff --git a/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/IsAfterConstantDateTimeConstraint.java b/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/AfterConstraint.java similarity index 85% rename from generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/IsAfterConstantDateTimeConstraint.java rename to generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/AfterConstraint.java index 8f4fd0060..9d61710d9 100644 --- a/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/IsAfterConstantDateTimeConstraint.java +++ b/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/AfterConstraint.java @@ -29,11 +29,11 @@ import static com.scottlogic.deg.generator.restrictions.linear.LinearRestrictionsFactory.createDateTimeRestrictions; import static com.scottlogic.deg.generator.utils.Defaults.DATETIME_MAX_LIMIT; -public class IsAfterConstantDateTimeConstraint implements AtomicConstraint { +public class AfterConstraint implements AtomicConstraint { public final Field field; public final HelixDateTime referenceValue; - public IsAfterConstantDateTimeConstraint(Field field, HelixDateTime referenceValue) { + public AfterConstraint(Field field, HelixDateTime referenceValue) { this.field = field; this.referenceValue = referenceValue; } @@ -45,7 +45,7 @@ public Field getField() { @Override public AtomicConstraint negate() { - return new IsBeforeOrEqualToConstantDateTimeConstraint(field, referenceValue); + return new BeforeOrAtConstraint(field, referenceValue); } @Override @@ -61,7 +61,7 @@ public boolean equals(Object o){ return o.equals(this); } if (o == null || getClass() != o.getClass()) return false; - IsAfterConstantDateTimeConstraint constraint = (IsAfterConstantDateTimeConstraint) o; + AfterConstraint constraint = (AfterConstraint) o; return Objects.equals(field, constraint.field) && Objects.equals(referenceValue, constraint.referenceValue); } @@ -72,6 +72,6 @@ public int hashCode(){ @Override public String toString(){ - return String.format("`%s` > %s", field.name, referenceValue); + return String.format("`%s` > %s", field.getName(), referenceValue); } } diff --git a/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/IsAfterOrEqualToConstantDateTimeConstraint.java b/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/AfterOrAtConstraint.java similarity index 84% rename from generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/IsAfterOrEqualToConstantDateTimeConstraint.java rename to generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/AfterOrAtConstraint.java index 697080788..2d17739d4 100644 --- a/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/IsAfterOrEqualToConstantDateTimeConstraint.java +++ b/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/AfterOrAtConstraint.java @@ -30,11 +30,11 @@ import static com.scottlogic.deg.generator.restrictions.linear.LinearRestrictionsFactory.createDateTimeRestrictions; import static com.scottlogic.deg.generator.utils.Defaults.DATETIME_MAX_LIMIT; -public class IsAfterOrEqualToConstantDateTimeConstraint implements AtomicConstraint { +public class AfterOrAtConstraint implements AtomicConstraint { public final Field field; public final HelixDateTime referenceValue; - public IsAfterOrEqualToConstantDateTimeConstraint(Field field, HelixDateTime referenceValue) { + public AfterOrAtConstraint(Field field, HelixDateTime referenceValue) { this.field = field; this.referenceValue = referenceValue; } @@ -46,7 +46,7 @@ public Field getField() { @Override public AtomicConstraint negate() { - return new IsBeforeConstantDateTimeConstraint(field, referenceValue); + return new BeforeConstraint(field, referenceValue); } @Override @@ -62,7 +62,7 @@ public boolean equals(Object o){ return o.equals(this); } if (o == null || getClass() != o.getClass()) return false; - IsAfterOrEqualToConstantDateTimeConstraint constraint = (IsAfterOrEqualToConstantDateTimeConstraint) o; + AfterOrAtConstraint constraint = (AfterOrAtConstraint) o; return Objects.equals(field, constraint.field) && Objects.equals(referenceValue, constraint.referenceValue); } @@ -73,6 +73,6 @@ public int hashCode(){ @Override public String toString(){ - return String.format("`%s` >= %s", field.name, referenceValue); + return String.format("`%s` >= %s", field.getName(), referenceValue); } } diff --git a/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/IsBeforeConstantDateTimeConstraint.java b/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/BeforeConstraint.java similarity index 85% rename from generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/IsBeforeConstantDateTimeConstraint.java rename to generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/BeforeConstraint.java index eff25d0b1..1b034147b 100644 --- a/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/IsBeforeConstantDateTimeConstraint.java +++ b/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/BeforeConstraint.java @@ -29,11 +29,11 @@ import static com.scottlogic.deg.generator.restrictions.linear.LinearRestrictionsFactory.createDateTimeRestrictions; import static com.scottlogic.deg.generator.utils.Defaults.DATETIME_MIN_LIMIT; -public class IsBeforeConstantDateTimeConstraint implements AtomicConstraint { +public class BeforeConstraint implements AtomicConstraint { public final Field field; public final HelixDateTime referenceValue; - public IsBeforeConstantDateTimeConstraint(Field field, HelixDateTime referenceValue) { + public BeforeConstraint(Field field, HelixDateTime referenceValue) { this.field = field; this.referenceValue = referenceValue; } @@ -45,7 +45,7 @@ public Field getField() { @Override public AtomicConstraint negate() { - return new IsAfterOrEqualToConstantDateTimeConstraint(field, referenceValue); + return new AfterOrAtConstraint(field, referenceValue); } @Override @@ -61,7 +61,7 @@ public boolean equals(Object o){ return o.equals(this); } if (o == null || getClass() != o.getClass()) return false; - IsBeforeConstantDateTimeConstraint constraint = (IsBeforeConstantDateTimeConstraint) o; + BeforeConstraint constraint = (BeforeConstraint) o; return Objects.equals(field, constraint.field) && Objects.equals(referenceValue, constraint.referenceValue); } @@ -72,6 +72,6 @@ public int hashCode(){ @Override public String toString() { - return String.format("`%s` < %s", field.name, referenceValue); + return String.format("`%s` < %s", field.getName(), referenceValue); } } diff --git a/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/IsBeforeOrEqualToConstantDateTimeConstraint.java b/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/BeforeOrAtConstraint.java similarity index 84% rename from generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/IsBeforeOrEqualToConstantDateTimeConstraint.java rename to generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/BeforeOrAtConstraint.java index 8074b7068..87601fd2e 100644 --- a/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/IsBeforeOrEqualToConstantDateTimeConstraint.java +++ b/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/BeforeOrAtConstraint.java @@ -29,11 +29,11 @@ import static com.scottlogic.deg.generator.restrictions.linear.LinearRestrictionsFactory.createDateTimeRestrictions; import static com.scottlogic.deg.generator.utils.Defaults.DATETIME_MIN_LIMIT; -public class IsBeforeOrEqualToConstantDateTimeConstraint implements AtomicConstraint { +public class BeforeOrAtConstraint implements AtomicConstraint { public final Field field; public final HelixDateTime referenceValue; - public IsBeforeOrEqualToConstantDateTimeConstraint(Field field, HelixDateTime referenceValue) { + public BeforeOrAtConstraint(Field field, HelixDateTime referenceValue) { this.field = field; this.referenceValue = referenceValue; } @@ -45,7 +45,7 @@ public Field getField() { @Override public AtomicConstraint negate() { - return new IsAfterConstantDateTimeConstraint(field, referenceValue); + return new AfterConstraint(field, referenceValue); } @Override @@ -61,7 +61,7 @@ public boolean equals(Object o){ return o.equals(this); } if (o == null || getClass() != o.getClass()) return false; - IsBeforeOrEqualToConstantDateTimeConstraint constraint = (IsBeforeOrEqualToConstantDateTimeConstraint) o; + BeforeOrAtConstraint constraint = (BeforeOrAtConstraint) o; return Objects.equals(field, constraint.field) && Objects.equals(referenceValue, constraint.referenceValue); } @@ -72,6 +72,6 @@ public int hashCode(){ @Override public String toString() { - return String.format("`%s` <= %s", field.name, referenceValue); + return String.format("`%s` <= %s", field.getName(), referenceValue); } } \ No newline at end of file diff --git a/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/BlacklistConstraint.java b/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/BlacklistConstraint.java index 1b3e1d7ca..5b6e85b05 100644 --- a/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/BlacklistConstraint.java +++ b/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/BlacklistConstraint.java @@ -19,12 +19,12 @@ public BlacklistConstraint(Field field, DistributedList legalValues) { if (legalValues.isEmpty()) { throw new IllegalArgumentException("Cannot create an IsInSetConstraint for field '" + - field.name + "' with an empty set"); + field.getName() + "' with an empty set"); } if (legalValues.list().contains(null)) { throw new IllegalArgumentException("Cannot create an IsInSetConstraint for field '" + - field.name + "' with a set containing null"); + field.getName() + "' with a set containing null"); } } @@ -35,7 +35,7 @@ public Field getField() { @Override public AtomicConstraint negate() { - return new IsInSetConstraint(field, legalValues); + return new InSetConstraint(field, legalValues); } @Override @@ -46,7 +46,7 @@ public FieldSpec toFieldSpec() { public String toString(){ boolean overLimit = legalValues.list().size() > 3; return String.format("%s in [%s%s](%d values)", - field.name, + field.getName(), legalValues.stream().limit(3).map(Object::toString).collect(Collectors.joining(", ")), overLimit ? ", ..." : "", legalValues.list().size()); diff --git a/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/ContainsRegexConstraint.java b/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/ContainsRegexConstraint.java index 8d874f6b8..58b7f2fb8 100644 --- a/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/ContainsRegexConstraint.java +++ b/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/ContainsRegexConstraint.java @@ -66,7 +66,7 @@ public int hashCode(){ @Override public String toString() { - return String.format("`%s` contains /%s/", field.name, regex); + return String.format("`%s` contains /%s/", field.getName(), regex); } } diff --git a/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/EqualToConstraint.java b/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/EqualToConstraint.java index 9e89cdfdc..6a2d6b66c 100644 --- a/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/EqualToConstraint.java +++ b/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/EqualToConstraint.java @@ -35,7 +35,7 @@ public FieldSpec toFieldSpec() { @Override public String toString(){ - return String.format("`%s` = %s", field.name, value); + return String.format("`%s` = %s", field.getName(), value); } @Override diff --git a/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/IsGranularToDateConstraint.java b/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/GranularToDateConstraint.java similarity index 89% rename from generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/IsGranularToDateConstraint.java rename to generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/GranularToDateConstraint.java index c0396ca22..ab97d62ed 100644 --- a/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/IsGranularToDateConstraint.java +++ b/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/GranularToDateConstraint.java @@ -28,11 +28,11 @@ import static com.scottlogic.deg.generator.utils.Defaults.DATETIME_MAX_LIMIT; import static com.scottlogic.deg.generator.utils.Defaults.DATETIME_MIN_LIMIT; -public class IsGranularToDateConstraint implements AtomicConstraint { +public class GranularToDateConstraint implements AtomicConstraint { public final Field field; public final DateTimeGranularity granularity; - public IsGranularToDateConstraint(Field field, DateTimeGranularity granularity) { + public GranularToDateConstraint(Field field, DateTimeGranularity granularity) { if(field == null) throw new IllegalArgumentException("field must not be null"); if(granularity == null) @@ -64,7 +64,7 @@ public boolean equals(Object o){ return o.equals(this); } if (o == null || getClass() != o.getClass()) return false; - IsGranularToDateConstraint constraint = (IsGranularToDateConstraint) o; + GranularToDateConstraint constraint = (GranularToDateConstraint) o; return (field.equals(constraint.field) && Objects.equals(granularity, constraint.granularity)); } @@ -75,6 +75,6 @@ public int hashCode(){ @Override public String toString() { - return String.format("%s granular to %s", field.name, granularity); + return String.format("%s granular to %s", field.getName(), granularity); } } diff --git a/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/IsGranularToNumericConstraint.java b/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/GranularToNumericConstraint.java similarity index 88% rename from generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/IsGranularToNumericConstraint.java rename to generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/GranularToNumericConstraint.java index 208b397a0..005017df0 100644 --- a/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/IsGranularToNumericConstraint.java +++ b/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/GranularToNumericConstraint.java @@ -28,11 +28,11 @@ import static com.scottlogic.deg.common.util.Defaults.NUMERIC_MAX; import static com.scottlogic.deg.common.util.Defaults.NUMERIC_MIN; -public class IsGranularToNumericConstraint implements AtomicConstraint { +public class GranularToNumericConstraint implements AtomicConstraint { public final Field field; public final NumericGranularity granularity; - public IsGranularToNumericConstraint(Field field, NumericGranularity granularity) { + public GranularToNumericConstraint(Field field, NumericGranularity granularity) { if(field == null) throw new IllegalArgumentException("field must not be null"); if(granularity == null) @@ -64,7 +64,7 @@ public boolean equals(Object o){ return o.equals(this); } if (o == null || getClass() != o.getClass()) return false; - IsGranularToNumericConstraint constraint = (IsGranularToNumericConstraint) o; + GranularToNumericConstraint constraint = (GranularToNumericConstraint) o; return Objects.equals(field, constraint.field) && Objects.equals(granularity, constraint.granularity); } @@ -75,6 +75,6 @@ public int hashCode(){ @Override public String toString() { - return String.format("%s granular to %s", field.name, granularity); + return String.format("%s granular to %s", field.getName(), granularity); } } diff --git a/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/IsGreaterThanConstantConstraint.java b/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/GreaterThanConstraint.java similarity index 85% rename from generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/IsGreaterThanConstantConstraint.java rename to generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/GreaterThanConstraint.java index 1924b1277..9eab3b8bb 100644 --- a/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/IsGreaterThanConstantConstraint.java +++ b/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/GreaterThanConstraint.java @@ -29,11 +29,11 @@ import static com.scottlogic.deg.generator.restrictions.linear.LinearRestrictionsFactory.createNumericRestrictions; import static com.scottlogic.deg.generator.utils.Defaults.NUMERIC_MAX_LIMIT; -public class IsGreaterThanConstantConstraint implements AtomicConstraint { +public class GreaterThanConstraint implements AtomicConstraint { public final Field field; public final HelixNumber referenceValue; - public IsGreaterThanConstantConstraint(Field field, HelixNumber referenceValue) { + public GreaterThanConstraint(Field field, HelixNumber referenceValue) { this.referenceValue = referenceValue; this.field = field; } @@ -45,7 +45,7 @@ public Field getField() { @Override public AtomicConstraint negate() { - return new IsLessThanOrEqualToConstantConstraint(field, referenceValue); + return new LessThanOrEqualToConstraint(field, referenceValue); } @Override @@ -61,7 +61,7 @@ public boolean equals(Object o){ return o.equals(this); } if (o == null || getClass() != o.getClass()) return false; - IsGreaterThanConstantConstraint constraint = (IsGreaterThanConstantConstraint) o; + GreaterThanConstraint constraint = (GreaterThanConstraint) o; return Objects.equals(field, constraint.field) && Objects.equals(referenceValue, constraint.referenceValue); } @@ -72,6 +72,6 @@ public int hashCode(){ @Override public String toString() { - return String.format("`%s` > %s", field.name, referenceValue); + return String.format("`%s` > %s", field.getName(), referenceValue); } } diff --git a/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/IsGreaterThanOrEqualToConstantConstraint.java b/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/GreaterThanOrEqualToConstraint.java similarity index 84% rename from generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/IsGreaterThanOrEqualToConstantConstraint.java rename to generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/GreaterThanOrEqualToConstraint.java index 66da0de38..b949b3056 100644 --- a/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/IsGreaterThanOrEqualToConstantConstraint.java +++ b/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/GreaterThanOrEqualToConstraint.java @@ -29,11 +29,11 @@ import static com.scottlogic.deg.generator.restrictions.linear.LinearRestrictionsFactory.createNumericRestrictions; import static com.scottlogic.deg.generator.utils.Defaults.NUMERIC_MAX_LIMIT; -public class IsGreaterThanOrEqualToConstantConstraint implements AtomicConstraint { +public class GreaterThanOrEqualToConstraint implements AtomicConstraint { public final Field field; public final HelixNumber referenceValue; - public IsGreaterThanOrEqualToConstantConstraint(Field field, HelixNumber referenceValue) { + public GreaterThanOrEqualToConstraint(Field field, HelixNumber referenceValue) { this.referenceValue = referenceValue; this.field = field; } @@ -45,7 +45,7 @@ public Field getField() { @Override public AtomicConstraint negate() { - return new IsLessThanConstantConstraint(field, referenceValue); + return new LessThanConstraint(field, referenceValue); } @Override @@ -61,7 +61,7 @@ public boolean equals(Object o){ return o.equals(this); } if (o == null || getClass() != o.getClass()) return false; - IsGreaterThanOrEqualToConstantConstraint constraint = (IsGreaterThanOrEqualToConstantConstraint) o; + GreaterThanOrEqualToConstraint constraint = (GreaterThanOrEqualToConstraint) o; return Objects.equals(field, constraint.field) && Objects.equals(referenceValue, constraint.referenceValue); } @@ -72,6 +72,6 @@ public int hashCode(){ @Override public String toString() { - return String.format("`%s` >= %s", field.name, referenceValue); + return String.format("`%s` >= %s", field.getName(), referenceValue); } } diff --git a/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/IsInSetConstraint.java b/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/InSetConstraint.java similarity index 88% rename from generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/IsInSetConstraint.java rename to generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/InSetConstraint.java index 980db8757..73930f0fd 100644 --- a/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/IsInSetConstraint.java +++ b/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/InSetConstraint.java @@ -27,22 +27,22 @@ import java.util.Objects; import java.util.stream.Collectors; -public class IsInSetConstraint implements AtomicConstraint { +public class InSetConstraint implements AtomicConstraint { public final Field field; public final DistributedList legalValues; - public IsInSetConstraint(Field field, DistributedList legalValues) { + public InSetConstraint(Field field, DistributedList legalValues) { this.field = field; this.legalValues = legalValues; if (legalValues.distributedList().isEmpty()) { throw new ValidationException("Cannot create an IsInSetConstraint for field '" + - field.name + "' with an empty set"); + field.getName() + "' with an empty set"); } if (legalValues.list().contains(null)) { throw new ValidationException("Cannot create an IsInSetConstraint for field '" + - field.name + "' with a set containing null"); + field.getName() + "' with a set containing null"); } } @@ -68,7 +68,7 @@ public FieldSpec toFieldSpec() { public String toString(){ boolean overLimit = legalValues.list().size() > 3; return String.format("%s in [%s%s](%d values)", - field.name, + field.getName(), legalValues.stream().limit(3).map(Object::toString).collect(Collectors.joining(", ")), overLimit ? ", ..." : "", legalValues.list().size()); @@ -81,7 +81,7 @@ public boolean equals(Object o){ return o.equals(this); } if (o == null || getClass() != o.getClass()) return false; - IsInSetConstraint constraint = (IsInSetConstraint) o; + InSetConstraint constraint = (InSetConstraint) o; return Objects.equals(field, constraint.field) && Objects.equals(legalValues, constraint.legalValues); } diff --git a/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/IsNullConstraint.java b/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/IsNullConstraint.java index 6f2bb64dc..6535f4b7e 100644 --- a/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/IsNullConstraint.java +++ b/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/IsNullConstraint.java @@ -31,7 +31,7 @@ public IsNullConstraint(Field field) { @Override public String toString() { - return String.format("%s is null", field.name); + return String.format("%s is null", field.getName()); } @Override diff --git a/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/IsLessThanConstantConstraint.java b/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/LessThanConstraint.java similarity index 87% rename from generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/IsLessThanConstantConstraint.java rename to generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/LessThanConstraint.java index 9831ae54c..3a2f8c9cb 100644 --- a/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/IsLessThanConstantConstraint.java +++ b/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/LessThanConstraint.java @@ -29,11 +29,11 @@ import static com.scottlogic.deg.generator.restrictions.linear.LinearRestrictionsFactory.createNumericRestrictions; import static com.scottlogic.deg.generator.utils.Defaults.NUMERIC_MIN_LIMIT; -public class IsLessThanConstantConstraint implements AtomicConstraint { +public class LessThanConstraint implements AtomicConstraint { public final Field field; public final HelixNumber referenceValue; - public IsLessThanConstantConstraint(Field field, HelixNumber referenceValue) { + public LessThanConstraint(Field field, HelixNumber referenceValue) { this.referenceValue = referenceValue; this.field = field; } @@ -45,7 +45,7 @@ public Field getField() { @Override public AtomicConstraint negate() { - return new IsGreaterThanOrEqualToConstantConstraint(field, referenceValue); + return new GreaterThanOrEqualToConstraint(field, referenceValue); } @Override @@ -61,7 +61,7 @@ public boolean equals(Object o){ return o.equals(this); } if (o == null || getClass() != o.getClass()) return false; - IsLessThanConstantConstraint constraint = (IsLessThanConstantConstraint) o; + LessThanConstraint constraint = (LessThanConstraint) o; return Objects.equals(field, constraint.field) && Objects.equals(referenceValue, constraint.referenceValue); } @@ -71,5 +71,5 @@ public int hashCode(){ } @Override - public String toString() { return String.format("`%s` < %s", field.name, referenceValue); } + public String toString() { return String.format("`%s` < %s", field.getName(), referenceValue); } } diff --git a/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/IsLessThanOrEqualToConstantConstraint.java b/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/LessThanOrEqualToConstraint.java similarity index 84% rename from generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/IsLessThanOrEqualToConstantConstraint.java rename to generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/LessThanOrEqualToConstraint.java index 6b7eded44..31f4d711c 100644 --- a/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/IsLessThanOrEqualToConstantConstraint.java +++ b/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/LessThanOrEqualToConstraint.java @@ -29,11 +29,11 @@ import static com.scottlogic.deg.generator.restrictions.linear.LinearRestrictionsFactory.createNumericRestrictions; import static com.scottlogic.deg.generator.utils.Defaults.NUMERIC_MIN_LIMIT; -public class IsLessThanOrEqualToConstantConstraint implements AtomicConstraint { +public class LessThanOrEqualToConstraint implements AtomicConstraint { public final Field field; public final HelixNumber referenceValue; - public IsLessThanOrEqualToConstantConstraint(Field field, HelixNumber referenceValue) { + public LessThanOrEqualToConstraint(Field field, HelixNumber referenceValue) { this.referenceValue = referenceValue; this.field = field; } @@ -45,7 +45,7 @@ public Field getField() { @Override public AtomicConstraint negate() { - return new IsGreaterThanConstantConstraint(field, referenceValue); + return new GreaterThanConstraint(field, referenceValue); } @Override @@ -61,7 +61,7 @@ public boolean equals(Object o){ return o.equals(this); } if (o == null || getClass() != o.getClass()) return false; - IsLessThanOrEqualToConstantConstraint constraint = (IsLessThanOrEqualToConstantConstraint) o; + LessThanOrEqualToConstraint constraint = (LessThanOrEqualToConstraint) o; return Objects.equals(field, constraint.field) && Objects.equals(referenceValue, constraint.referenceValue); } @@ -72,7 +72,7 @@ public int hashCode(){ @Override public String toString() { - return String.format("`%s` <= %s", field.name, referenceValue); + return String.format("`%s` <= %s", field.getName(), referenceValue); } } diff --git a/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/IsStringLongerThanConstraint.java b/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/LongerThanConstraint.java similarity index 83% rename from generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/IsStringLongerThanConstraint.java rename to generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/LongerThanConstraint.java index b4d5740bd..c331551e1 100644 --- a/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/IsStringLongerThanConstraint.java +++ b/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/LongerThanConstraint.java @@ -24,11 +24,11 @@ import java.util.Objects; -public class IsStringLongerThanConstraint implements AtomicConstraint { +public class LongerThanConstraint implements AtomicConstraint { public final Field field; public final HelixStringLength referenceValue; - public IsStringLongerThanConstraint(Field field, HelixStringLength referenceValue) { + public LongerThanConstraint(Field field, HelixStringLength referenceValue) { this.referenceValue = referenceValue; this.field = field; } @@ -41,7 +41,7 @@ public Field getField() { @Override public AtomicConstraint negate() { - return new IsStringShorterThanConstraint(field, HelixStringLength.create(referenceValue.getValue() + 1)); + return new ShorterThanConstraint(field, HelixStringLength.create(referenceValue.getValue() + 1)); } @Override @@ -56,7 +56,7 @@ public boolean equals(Object o){ return o.equals(this); } if (o == null || getClass() != o.getClass()) return false; - IsStringLongerThanConstraint constraint = (IsStringLongerThanConstraint) o; + LongerThanConstraint constraint = (LongerThanConstraint) o; return Objects.equals(field, constraint.field) && Objects.equals(referenceValue, constraint.referenceValue); } @@ -66,5 +66,5 @@ public int hashCode(){ } @Override - public String toString() { return String.format("`%s` length > %d", field.name, referenceValue); } + public String toString() { return String.format("`%s` length > %d", field.getName(), referenceValue); } } diff --git a/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/MatchesRegexConstraint.java b/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/MatchesRegexConstraint.java index 6a2abd5d0..e58a96720 100644 --- a/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/MatchesRegexConstraint.java +++ b/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/MatchesRegexConstraint.java @@ -65,5 +65,5 @@ public int hashCode(){ } @Override - public String toString(){ return String.format("`%s` matches /%s/", field.name, regex); } + public String toString(){ return String.format("`%s` matches /%s/", field.getName(), regex); } } diff --git a/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/MatchesStandardConstraint.java b/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/MatchesStandardConstraint.java index d66d7fe58..982066aae 100644 --- a/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/MatchesStandardConstraint.java +++ b/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/MatchesStandardConstraint.java @@ -39,7 +39,7 @@ public MatchesStandardConstraint(Field field, StandardConstraintTypes standard) @Override public String toString(){ - return String.format("%s is a %s", field.name, standard.getClass().getName()); + return String.format("%s is a %s", field.getName(), standard.getClass().getName()); } @Override diff --git a/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/NotContainsRegexConstraint.java b/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/NotContainsRegexConstraint.java index 5ebbc1d8f..012f0dde2 100644 --- a/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/NotContainsRegexConstraint.java +++ b/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/NotContainsRegexConstraint.java @@ -50,7 +50,7 @@ public int hashCode(){ @Override public String toString() { - return String.format("`%s` doesn't contain /%s/", field.name, regex); + return String.format("`%s` doesn't contain /%s/", field.getName(), regex); } } diff --git a/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/NotEqualToConstraint.java b/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/NotEqualToConstraint.java index 84a30d7df..6010118d1 100644 --- a/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/NotEqualToConstraint.java +++ b/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/NotEqualToConstraint.java @@ -34,7 +34,7 @@ public FieldSpec toFieldSpec() { @Override public String toString(){ - return String.format("`%s` = %s", field.name, value); + return String.format("`%s` = %s", field.getName(), value); } @Override diff --git a/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/NotMatchesRegexConstraint.java b/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/NotMatchesRegexConstraint.java index 6f5e33550..c6a27f7fa 100644 --- a/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/NotMatchesRegexConstraint.java +++ b/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/NotMatchesRegexConstraint.java @@ -49,5 +49,5 @@ public int hashCode(){ } @Override - public String toString(){ return String.format("`%s` NOT matches /%s/", field.name, regex); } + public String toString(){ return String.format("`%s` NOT matches /%s/", field.getName(), regex); } } diff --git a/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/NotMatchesStandardConstraint.java b/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/NotMatchesStandardConstraint.java index dd0d47432..9c38d1e96 100644 --- a/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/NotMatchesStandardConstraint.java +++ b/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/NotMatchesStandardConstraint.java @@ -19,7 +19,7 @@ public NotMatchesStandardConstraint(Field field, StandardConstraintTypes standar @Override public String toString(){ - return String.format("%s is a %s", field.name, standard.getClass().getName()); + return String.format("%s is a %s", field.getName(), standard.getClass().getName()); } @Override diff --git a/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/NotNullConstraint.java b/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/NotNullConstraint.java index eaebf0336..74ba1f392 100644 --- a/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/NotNullConstraint.java +++ b/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/NotNullConstraint.java @@ -15,7 +15,7 @@ public NotNullConstraint(Field field) { @Override public String toString() { - return String.format("%s is not null", field.name); + return String.format("%s is not null", field.getName()); } @Override diff --git a/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/NotStringLengthConstraint.java b/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/NotStringLengthConstraint.java index ee2c2d3e1..d2370c97d 100644 --- a/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/NotStringLengthConstraint.java +++ b/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/NotStringLengthConstraint.java @@ -24,7 +24,7 @@ public Field getField() { @Override public AtomicConstraint negate() { - return new StringHasLengthConstraint(field, referenceValue); + return new OfLengthConstraint(field, referenceValue); } @Override @@ -49,5 +49,5 @@ public int hashCode(){ } @Override - public String toString() { return String.format("`%s` length = %s", field.name, referenceValue); } + public String toString() { return String.format("`%s` length = %s", field.getName(), referenceValue); } } diff --git a/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/StringHasLengthConstraint.java b/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/OfLengthConstraint.java similarity index 88% rename from generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/StringHasLengthConstraint.java rename to generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/OfLengthConstraint.java index bd1266d65..21d6e00ab 100644 --- a/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/StringHasLengthConstraint.java +++ b/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/OfLengthConstraint.java @@ -24,11 +24,11 @@ import java.util.Objects; -public class StringHasLengthConstraint implements AtomicConstraint { +public class OfLengthConstraint implements AtomicConstraint { public final Field field; public final HelixStringLength referenceValue; - public StringHasLengthConstraint(Field field, HelixStringLength referenceValue) { + public OfLengthConstraint(Field field, HelixStringLength referenceValue) { this.referenceValue = referenceValue; this.field = field; } @@ -55,7 +55,7 @@ public boolean equals(Object o){ return o.equals(this); } if (o == null || getClass() != o.getClass()) return false; - StringHasLengthConstraint constraint = (StringHasLengthConstraint) o; + OfLengthConstraint constraint = (OfLengthConstraint) o; return Objects.equals(field, constraint.field) && Objects.equals(referenceValue.getValue(), constraint.referenceValue.getValue()); } @@ -65,5 +65,5 @@ public int hashCode(){ } @Override - public String toString() { return String.format("`%s` length = %s", field.name, referenceValue.getValue()); } + public String toString() { return String.format("`%s` length = %s", field.getName(), referenceValue.getValue()); } } diff --git a/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/IsStringShorterThanConstraint.java b/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/ShorterThanConstraint.java similarity index 83% rename from generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/IsStringShorterThanConstraint.java rename to generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/ShorterThanConstraint.java index 8271bd4e4..e56bf244f 100644 --- a/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/IsStringShorterThanConstraint.java +++ b/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/ShorterThanConstraint.java @@ -24,11 +24,11 @@ import java.util.Objects; -public class IsStringShorterThanConstraint implements AtomicConstraint { +public class ShorterThanConstraint implements AtomicConstraint { public final Field field; public final HelixStringLength referenceValue; - public IsStringShorterThanConstraint(Field field, HelixStringLength referenceValue) { + public ShorterThanConstraint(Field field, HelixStringLength referenceValue) { this.referenceValue = referenceValue; this.field = field; } @@ -40,7 +40,7 @@ public Field getField() { @Override public AtomicConstraint negate() { - return new IsStringLongerThanConstraint(field, HelixStringLength.create(referenceValue.getValue() - 1)); + return new LongerThanConstraint(field, HelixStringLength.create(referenceValue.getValue() - 1)); } @Override @@ -55,7 +55,7 @@ public boolean equals(Object o){ return o.equals(this); } if (o == null || getClass() != o.getClass()) return false; - IsStringShorterThanConstraint constraint = (IsStringShorterThanConstraint) o; + ShorterThanConstraint constraint = (ShorterThanConstraint) o; return Objects.equals(field, constraint.field) && Objects.equals(referenceValue, constraint.referenceValue); } @@ -65,5 +65,5 @@ public int hashCode(){ } @Override - public String toString() { return String.format("`%s` length < %d", field.name, referenceValue); } + public String toString() { return String.format("`%s` length < %d", field.getName(), referenceValue); } } diff --git a/generator/src/main/java/com/scottlogic/deg/generator/reducer/ConstraintReducer.java b/generator/src/main/java/com/scottlogic/deg/generator/reducer/ConstraintReducer.java index 643ca413a..45fdae515 100644 --- a/generator/src/main/java/com/scottlogic/deg/generator/reducer/ConstraintReducer.java +++ b/generator/src/main/java/com/scottlogic/deg/generator/reducer/ConstraintReducer.java @@ -18,7 +18,7 @@ import com.google.inject.Inject; import com.scottlogic.deg.common.profile.Field; -import com.scottlogic.deg.common.profile.ProfileFields; +import com.scottlogic.deg.common.profile.Fields; import com.scottlogic.deg.generator.profile.constraints.atomic.AtomicConstraint; import com.scottlogic.deg.generator.decisiontree.ConstraintNode; import com.scottlogic.deg.generator.fieldspecs.*; @@ -40,7 +40,7 @@ public ConstraintReducer( this.fieldSpecMerger = fieldSpecMerger; } - public Optional reduceConstraintsToRowSpec(ProfileFields fields, ConstraintNode node) { + public Optional reduceConstraintsToRowSpec(Fields fields, ConstraintNode node) { Set constraints = node.getAtomicConstraints(); Set relations = node.getRelations(); diff --git a/generator/src/main/java/com/scottlogic/deg/generator/validators/ContradictionDecisionTreeValidator.java b/generator/src/main/java/com/scottlogic/deg/generator/validators/ContradictionDecisionTreeValidator.java index 9b793cd7a..6bc6d8f64 100644 --- a/generator/src/main/java/com/scottlogic/deg/generator/validators/ContradictionDecisionTreeValidator.java +++ b/generator/src/main/java/com/scottlogic/deg/generator/validators/ContradictionDecisionTreeValidator.java @@ -18,7 +18,7 @@ import com.google.inject.Inject; import com.scottlogic.deg.common.profile.Field; -import com.scottlogic.deg.common.profile.ProfileFields; +import com.scottlogic.deg.common.profile.Fields; import com.scottlogic.deg.generator.decisiontree.*; import com.scottlogic.deg.generator.fieldspecs.FieldSpec; import com.scottlogic.deg.generator.fieldspecs.FieldSpecFactory; @@ -44,13 +44,13 @@ public DecisionTree markContradictions(DecisionTree tree) { return new DecisionTree(markContradictions(tree.getRootNode(), tree.getFields()), tree.getFields()); } - private ConstraintNode markContradictions(ConstraintNode node, ProfileFields profileFields){ - return markContradictions(node, getIdentityRowSpec(profileFields), profileFields); + private ConstraintNode markContradictions(ConstraintNode node, Fields fields){ + return markContradictions(node, getIdentityRowSpec(fields), fields); } - private ConstraintNode markContradictions(ConstraintNode node, RowSpec accumulatedSpec, ProfileFields profileFields){ + private ConstraintNode markContradictions(ConstraintNode node, RowSpec accumulatedSpec, Fields fields){ final Optional nominalRowSpec = constraintReducer.reduceConstraintsToRowSpec( - profileFields, + fields, node ); @@ -71,7 +71,7 @@ private ConstraintNode markContradictions(ConstraintNode node, RowSpec accumulat } else { Set decisions = node.getDecisions() .stream() - .map(d -> markContradictions(d, mergedRowSpecOpt.get(), profileFields)) + .map(d -> markContradictions(d, mergedRowSpecOpt.get(), fields)) .collect(Collectors.toSet()); boolean nodeIsContradictory = decisions.stream().allMatch(this::isNodeContradictory); ConstraintNode transformed = node.builder().setDecisions(decisions).build(); @@ -79,12 +79,12 @@ private ConstraintNode markContradictions(ConstraintNode node, RowSpec accumulat } } - private DecisionNode markContradictions(DecisionNode node, RowSpec accumulatedSpec, ProfileFields profileFields){ + private DecisionNode markContradictions(DecisionNode node, RowSpec accumulatedSpec, Fields fields){ if (node.getOptions().isEmpty()){ return node; } Set options = node.getOptions().stream() - .map(c -> markContradictions(c, accumulatedSpec, profileFields)) + .map(c -> markContradictions(c, accumulatedSpec, fields)) .collect(Collectors.toSet()); boolean decisionIsContradictory = options.stream().allMatch(this::isNodeContradictory); @@ -95,11 +95,11 @@ private DecisionNode markContradictions(DecisionNode node, RowSpec accumulatedSp return transformed; } - private RowSpec getIdentityRowSpec(ProfileFields profileFields) { - final Map fieldToFieldSpec = profileFields.stream() + private RowSpec getIdentityRowSpec(Fields fields) { + final Map fieldToFieldSpec = fields.stream() .collect(Collectors.toMap(Function.identity(), field -> FieldSpecFactory.fromType(field.getType()))); - return new RowSpec(profileFields, fieldToFieldSpec, Collections.emptyList()); + return new RowSpec(fields, fieldToFieldSpec, Collections.emptyList()); } private boolean isNodeContradictory(Node node){ diff --git a/generator/src/main/java/com/scottlogic/deg/generator/walker/decisionbased/RowSpecTreeSolver.java b/generator/src/main/java/com/scottlogic/deg/generator/walker/decisionbased/RowSpecTreeSolver.java index 23a4d524d..bc9c5d460 100644 --- a/generator/src/main/java/com/scottlogic/deg/generator/walker/decisionbased/RowSpecTreeSolver.java +++ b/generator/src/main/java/com/scottlogic/deg/generator/walker/decisionbased/RowSpecTreeSolver.java @@ -2,7 +2,7 @@ import com.google.inject.Inject; import com.scottlogic.deg.common.profile.Field; -import com.scottlogic.deg.common.profile.ProfileFields; +import com.scottlogic.deg.common.profile.Fields; import com.scottlogic.deg.generator.fieldspecs.FieldSpecFactory; import com.scottlogic.deg.generator.profile.constraints.atomic.AtomicConstraint; import com.scottlogic.deg.generator.decisiontree.ConstraintNode; @@ -42,7 +42,7 @@ public Stream createRowSpecs(DecisionTree tree) { rootNode -> toRowspec(tree.fields, rootNode)); } - private Stream toRowspec(ProfileFields fields, ConstraintNode rootNode) { + private Stream toRowspec(Fields fields, ConstraintNode rootNode) { Optional result = constraintReducer.reduceConstraintsToRowSpec(fields, rootNode); return result.map(Stream::of).orElseGet(Stream::empty); } diff --git a/generator/src/test/java/com/scottlogic/deg/generator/ConstraintBuilder.java b/generator/src/test/java/com/scottlogic/deg/generator/ConstraintBuilder.java index 48cbf5055..b14c13907 100644 --- a/generator/src/test/java/com/scottlogic/deg/generator/ConstraintBuilder.java +++ b/generator/src/test/java/com/scottlogic/deg/generator/ConstraintBuilder.java @@ -17,7 +17,7 @@ package com.scottlogic.deg.generator; import com.scottlogic.deg.generator.profile.constraints.Constraint; -import com.scottlogic.deg.generator.profile.constraints.atomic.IsInSetConstraint; +import com.scottlogic.deg.generator.profile.constraints.atomic.InSetConstraint; import com.scottlogic.deg.generator.profile.constraints.atomic.IsNullConstraint; import com.scottlogic.deg.generator.profile.constraints.grammatical.AndConstraint; import com.scottlogic.deg.generator.profile.constraints.grammatical.ConditionalConstraint; @@ -32,7 +32,7 @@ public class ConstraintBuilder { private final Map fields; public ConstraintBuilder(List fields) { - this.fields = fields.stream().collect(Collectors.toMap(f -> f.name, f -> f)); + this.fields = fields.stream().collect(Collectors.toMap(f -> f.getName(), f -> f)); } public List build() { @@ -40,13 +40,13 @@ public List build() { } public ConstraintBuilder addInSetConstraint(String fieldname, List values) { - constraints.add(new IsInSetConstraint(fields.get(fieldname), + constraints.add(new InSetConstraint(fields.get(fieldname), DistributedList.uniform(values))); return this; } public ConstraintBuilder addEqualToConstraint(String fieldname, Object value) { - constraints.add(new IsInSetConstraint( + constraints.add(new InSetConstraint( fields.get(fieldname), DistributedList.singleton(value))); return this; diff --git a/generator/src/test/java/com/scottlogic/deg/generator/builders/ConstraintChainBuilder.java b/generator/src/test/java/com/scottlogic/deg/generator/builders/ConstraintChainBuilder.java index 01f674fe6..95a23ce22 100644 --- a/generator/src/test/java/com/scottlogic/deg/generator/builders/ConstraintChainBuilder.java +++ b/generator/src/test/java/com/scottlogic/deg/generator/builders/ConstraintChainBuilder.java @@ -97,16 +97,16 @@ public ConstraintChainBuilder appendBuilder(BaseConstraintBuilder withLessThanConstraint(Field field, int referenceValue) { - return saveAndSet(new IsLessThanConstantConstraint(field, HelixNumber.create(referenceValue))); + return saveAndSet(new LessThanConstraint(field, HelixNumber.create(referenceValue))); } public ConstraintChainBuilder withGreaterThanConstraint(Field field, int referenceValue) { - return saveAndSet(new IsGreaterThanConstantConstraint(field, HelixNumber.create(referenceValue))); + return saveAndSet(new GreaterThanConstraint(field, HelixNumber.create(referenceValue))); } public ConstraintChainBuilder withEqualToConstraint(Field barField, Object referenceValue) { return saveAndSet( - new IsInSetConstraint( + new InSetConstraint( barField, DistributedList.singleton(referenceValue))); } @@ -124,21 +124,21 @@ public ConstraintChainBuilder withIfConstraint(BaseConstraintBuilder withInSetConstraint(Field field, Object[] legalArray) { - return saveAndSet(new IsInSetConstraint( + return saveAndSet(new InSetConstraint( field, DistributedList.uniform(SetUtils.setOf(legalArray)))); } public ConstraintChainBuilder withOfLengthConstraint(Field fooField, int length) { - return saveAndSet(new StringHasLengthConstraint(fooField, HelixStringLength.create(length))); + return saveAndSet(new OfLengthConstraint(fooField, HelixStringLength.create(length))); } public ConstraintChainBuilder withAfterConstraint(Field field, OffsetDateTime dateTime) { - return saveAndSet(new IsAfterConstantDateTimeConstraint(field, HelixDateTime.create(dateTime))); + return saveAndSet(new AfterConstraint(field, HelixDateTime.create(dateTime))); } public ConstraintChainBuilder withBeforeConstraint(Field field, OffsetDateTime dateTime) { - return saveAndSet(new IsBeforeConstantDateTimeConstraint(field, HelixDateTime.create(dateTime))); + return saveAndSet(new BeforeConstraint(field, HelixDateTime.create(dateTime))); } public ConstraintChainBuilder withMatchesRegexConstraint(Field field, Pattern pattern) { diff --git a/generator/src/test/java/com/scottlogic/deg/generator/builders/RuleBuilder.java b/generator/src/test/java/com/scottlogic/deg/generator/builders/RuleBuilder.java index 22573d51b..f40c206a9 100644 --- a/generator/src/test/java/com/scottlogic/deg/generator/builders/RuleBuilder.java +++ b/generator/src/test/java/com/scottlogic/deg/generator/builders/RuleBuilder.java @@ -18,7 +18,6 @@ import com.scottlogic.deg.generator.profile.Rule; import com.scottlogic.deg.generator.profile.constraints.Constraint; -import com.scottlogic.deg.generator.profile.RuleInformation; import java.util.List; @@ -26,13 +25,13 @@ * Defines a builder for a Rule object */ public class RuleBuilder extends ConstraintChainBuilder { - private final RuleInformation ruleInformation; + private final String ruleInformation; public RuleBuilder(String ruleName) { - this.ruleInformation = new RuleInformation(ruleName); + this.ruleInformation = ruleName; } - private RuleBuilder(Constraint headConstraint, List tailConstraints, RuleInformation ruleInformation) { + private RuleBuilder(Constraint headConstraint, List tailConstraints, String ruleInformation) { super(headConstraint, tailConstraints); this.ruleInformation = ruleInformation; } diff --git a/generator/src/test/java/com/scottlogic/deg/generator/builders/TestAtomicConstraintBuilder.java b/generator/src/test/java/com/scottlogic/deg/generator/builders/TestAtomicConstraintBuilder.java index 65f9696ca..a39e63ee0 100644 --- a/generator/src/test/java/com/scottlogic/deg/generator/builders/TestAtomicConstraintBuilder.java +++ b/generator/src/test/java/com/scottlogic/deg/generator/builders/TestAtomicConstraintBuilder.java @@ -18,7 +18,7 @@ import com.scottlogic.deg.common.profile.Field; import com.scottlogic.deg.generator.profile.constraints.atomic.AtomicConstraint; -import com.scottlogic.deg.generator.profile.constraints.atomic.IsInSetConstraint; +import com.scottlogic.deg.generator.profile.constraints.atomic.InSetConstraint; import com.scottlogic.deg.generator.profile.constraints.atomic.IsNullConstraint; import com.scottlogic.deg.generator.fieldspecs.whitelist.DistributedList; import com.scottlogic.deg.generator.utils.SetUtils; @@ -37,15 +37,15 @@ private DistributedList whitelistOf(Object... values) { } public TestConstraintNodeBuilder isInSet(Object... legalValues) { - IsInSetConstraint isInSetConstraint = new IsInSetConstraint( + InSetConstraint inSetConstraint = new InSetConstraint( field, whitelistOf(legalValues)); - testConstraintNodeBuilder.constraints.add(isInSetConstraint); + testConstraintNodeBuilder.constraints.add(inSetConstraint); return testConstraintNodeBuilder; } public TestConstraintNodeBuilder isNotInSet(Object... legalValues) { - AtomicConstraint isInSetConstraint = new IsInSetConstraint( + AtomicConstraint isInSetConstraint = new InSetConstraint( field, whitelistOf(legalValues) ).negate(); diff --git a/generator/src/test/java/com/scottlogic/deg/generator/decisiontree/DecisionTreeFactoryTests.java b/generator/src/test/java/com/scottlogic/deg/generator/decisiontree/DecisionTreeFactoryTests.java index 1727c20f5..5ac3262c1 100644 --- a/generator/src/test/java/com/scottlogic/deg/generator/decisiontree/DecisionTreeFactoryTests.java +++ b/generator/src/test/java/com/scottlogic/deg/generator/decisiontree/DecisionTreeFactoryTests.java @@ -18,17 +18,16 @@ import com.scottlogic.deg.common.profile.Field; import com.scottlogic.deg.common.profile.HelixNumber; -import com.scottlogic.deg.common.profile.ProfileFields; +import com.scottlogic.deg.common.profile.Fields; import com.scottlogic.deg.generator.decisiontree.testutils.*; import com.scottlogic.deg.generator.fieldspecs.whitelist.DistributedList; import com.scottlogic.deg.generator.fieldspecs.whitelist.WeightedElement; import com.scottlogic.deg.generator.profile.Profile; import com.scottlogic.deg.generator.profile.Rule; -import com.scottlogic.deg.generator.profile.RuleInformation; import com.scottlogic.deg.generator.profile.constraints.Constraint; import com.scottlogic.deg.generator.profile.constraints.atomic.AtomicConstraint; -import com.scottlogic.deg.generator.profile.constraints.atomic.IsGreaterThanConstantConstraint; -import com.scottlogic.deg.generator.profile.constraints.atomic.IsInSetConstraint; +import com.scottlogic.deg.generator.profile.constraints.atomic.GreaterThanConstraint; +import com.scottlogic.deg.generator.profile.constraints.atomic.InSetConstraint; import com.scottlogic.deg.generator.profile.constraints.atomic.MatchesRegexConstraint; import com.scottlogic.deg.generator.profile.constraints.grammatical.AndConstraint; import com.scottlogic.deg.generator.profile.constraints.grammatical.ConditionalConstraint; @@ -68,13 +67,13 @@ void beforeEach() { } private void givenRule(Constraint... constraints) { - this.rules.add(new Rule(rule(""), Arrays.asList(constraints))); + this.rules.add(new Rule("", Arrays.asList(constraints))); } private DecisionTree getActualOutput() { if (this.actualOutput == null) { Profile testInput = new Profile( - new ProfileFields( + new Fields( Arrays.asList(this.fieldA, this.fieldB, this.fieldC)), this.rules); @@ -111,21 +110,21 @@ void shouldReturnAnalysedProfileWithCorrectFields() { DecisionTreeFactory testObject = new DecisionTreeFactory(); DecisionTree testOutput = testObject.analyse(testInput); - ProfileFields actualFields = testOutput.getFields(); + Fields actualFields = testOutput.getFields(); - ProfileFields expected = new ProfileFields(inputFieldList); + Fields expected = new Fields(inputFieldList); assertThat(actualFields, sameBeanAs(expected)); } @Test void shouldReturnAnalysedRuleWithNoDecisions_IfProfileContainsOnlyAtomicConstraints() { List inputFieldList = Arrays.asList(createField("one"), createField("two"), createField("three")); - IsInSetConstraint constraint0 = new IsInSetConstraint( + InSetConstraint constraint0 = new InSetConstraint( inputFieldList.get(0), new DistributedList<>(Collections.singletonList(new WeightedElement<>(10, 1.0F)))); - IsGreaterThanConstantConstraint constraint1 = new IsGreaterThanConstantConstraint(inputFieldList.get(0), HelixNumber.create(0)); + GreaterThanConstraint constraint1 = new GreaterThanConstraint(inputFieldList.get(0), HelixNumber.create(0)); MatchesRegexConstraint constraint2 = new MatchesRegexConstraint(inputFieldList.get(1), Pattern.compile("start.*end")); - Rule testRule = new Rule(rule("test"), Arrays.asList(constraint0, constraint1, constraint2)); + Rule testRule = new Rule("test", Arrays.asList(constraint0, constraint1, constraint2)); Profile testInput = new Profile(inputFieldList, Collections.singletonList(testRule)); DecisionTreeFactory testObject = new DecisionTreeFactory(); @@ -142,13 +141,13 @@ void shouldReturnAnalysedRuleWithNoDecisions_IfProfileContainsOnlyAtomicConstrai @Test void shouldReturnAnalysedRuleWithAllConstraintsInAtomicConstraintsCollection_IfProfileContainsOnlyAtomicConstraints() { List inputFieldList = Arrays.asList(createField("one"), createField("two"), createField("three")); - IsInSetConstraint constraint0 = new IsInSetConstraint( + InSetConstraint constraint0 = new InSetConstraint( inputFieldList.get(0), new DistributedList<>(Collections.singletonList(new WeightedElement<>(10, 1.0F)))); - IsGreaterThanConstantConstraint constraint1 = new IsGreaterThanConstantConstraint(inputFieldList.get(0), HelixNumber.create(0)); + GreaterThanConstraint constraint1 = new GreaterThanConstraint(inputFieldList.get(0), HelixNumber.create(0)); MatchesRegexConstraint constraint2 = new MatchesRegexConstraint(inputFieldList.get(1), Pattern.compile("start.*end")); List inputConstraints = Arrays.asList(constraint0, constraint1, constraint2); - Rule testRule = new Rule(rule("test"), inputConstraints); + Rule testRule = new Rule("test", inputConstraints); Profile testInput = new Profile(inputFieldList, Collections.singletonList(testRule)); DecisionTreeFactory testObject = new DecisionTreeFactory(); @@ -167,11 +166,11 @@ void shouldReturnAnalysedRuleWithAllConstraintsInAtomicConstraintsCollection_IfP @Test void shouldReturnAnalysedRuleWithNoDecisions_IfProfileContainsOnlyAtomicConstraintsAndAndConstraints() { List inputFieldList = Arrays.asList(createField("one"), createField("two"), createField("three")); - IsInSetConstraint constraint0 = new IsInSetConstraint(inputFieldList.get(0), new DistributedList<>(Collections.singletonList(new WeightedElement<>(10, 1.0F)))); - IsGreaterThanConstantConstraint constraint1 = new IsGreaterThanConstantConstraint(inputFieldList.get(0), HelixNumber.create(0)); + InSetConstraint constraint0 = new InSetConstraint(inputFieldList.get(0), new DistributedList<>(Collections.singletonList(new WeightedElement<>(10, 1.0F)))); + GreaterThanConstraint constraint1 = new GreaterThanConstraint(inputFieldList.get(0), HelixNumber.create(0)); AndConstraint andConstraint0 = new AndConstraint(Arrays.asList(constraint0, constraint1)); MatchesRegexConstraint constraint2 = new MatchesRegexConstraint(inputFieldList.get(1), Pattern.compile("start.*end")); - Rule testRule = new Rule(rule("test"), Arrays.asList(andConstraint0, constraint2)); + Rule testRule = new Rule("test", Arrays.asList(andConstraint0, constraint2)); Profile testInput = new Profile(inputFieldList, Collections.singletonList(testRule)); DecisionTreeFactory testObject = new DecisionTreeFactory(); @@ -187,11 +186,11 @@ void shouldReturnAnalysedRuleWithNoDecisions_IfProfileContainsOnlyAtomicConstrai @Test void shouldReturnAnalysedRuleWithAllAtomicConstraintsInAtomicConstraintsCollection_IfProfileContainsOnlyAtomicConstraintsAndAndConstraints() { List inputFieldList = Arrays.asList(createField("one"), createField("two"), createField("three")); - IsInSetConstraint constraint0 = new IsInSetConstraint(inputFieldList.get(0), new DistributedList<>(Collections.singletonList(new WeightedElement<>(10, 1.0F)))); - IsGreaterThanConstantConstraint constraint1 = new IsGreaterThanConstantConstraint(inputFieldList.get(0), HelixNumber.create(0)); + InSetConstraint constraint0 = new InSetConstraint(inputFieldList.get(0), new DistributedList<>(Collections.singletonList(new WeightedElement<>(10, 1.0F)))); + GreaterThanConstraint constraint1 = new GreaterThanConstraint(inputFieldList.get(0), HelixNumber.create(0)); AndConstraint andConstraint0 = new AndConstraint(Arrays.asList(constraint0, constraint1)); MatchesRegexConstraint constraint2 = new MatchesRegexConstraint(inputFieldList.get(1), Pattern.compile("start.*end")); - Rule testRule = new Rule(rule("test"), Arrays.asList(andConstraint0, constraint2)); + Rule testRule = new Rule("test", Arrays.asList(andConstraint0, constraint2)); Profile testInput = new Profile(inputFieldList, Collections.singletonList(testRule)); DecisionTreeFactory testObject = new DecisionTreeFactory(); @@ -212,17 +211,17 @@ void shouldReturnAnalysedRuleWithAllAtomicConstraintsInAtomicConstraintsCollecti @Test void shouldReturnAnalysedRuleWithDecisionForEachOrConstraint() { List inputFieldList = Arrays.asList(createField("one"), createField("two"), createField("three")); - IsInSetConstraint constraint0 = new IsInSetConstraint(inputFieldList.get(0), new DistributedList<>(Collections.singletonList(new WeightedElement<>(10, 1.0F)))); - IsGreaterThanConstantConstraint constraint1 = new IsGreaterThanConstantConstraint(inputFieldList.get(0), HelixNumber.create(0)); + InSetConstraint constraint0 = new InSetConstraint(inputFieldList.get(0), new DistributedList<>(Collections.singletonList(new WeightedElement<>(10, 1.0F)))); + GreaterThanConstraint constraint1 = new GreaterThanConstraint(inputFieldList.get(0), HelixNumber.create(0)); OrConstraint orConstraint0 = new OrConstraint(Arrays.asList(constraint0, constraint1)); - IsInSetConstraint constraint2 = new IsInSetConstraint( + InSetConstraint constraint2 = new InSetConstraint( inputFieldList.get(1), new DistributedList<>(Collections.singletonList(new WeightedElement<>("steam", 1.0F)))); - IsInSetConstraint constraint3 = new IsInSetConstraint( + InSetConstraint constraint3 = new InSetConstraint( inputFieldList.get(1), new DistributedList<>(Collections.singletonList(new WeightedElement<>("diesel", 1.0F)))); OrConstraint orConstraint1 = new OrConstraint(Arrays.asList(constraint2, constraint3)); - Rule testRule = new Rule(rule("test"), Arrays.asList(orConstraint0, orConstraint1)); + Rule testRule = new Rule("test", Arrays.asList(orConstraint0, orConstraint1)); Profile testInput = new Profile(inputFieldList, Collections.singletonList(testRule)); DecisionTreeFactory testObject = new DecisionTreeFactory(); @@ -237,17 +236,17 @@ void shouldReturnAnalysedRuleWithDecisionForEachOrConstraint() { @Test void shouldReturnAnalysedRuleWithNoAtomicConstraints_IfAllAtomicConstraintsInProfileAreChildrenOfOrConstraints() { List inputFieldList = Arrays.asList(createField("one"), createField("two"), createField("three")); - IsInSetConstraint constraintA = new IsInSetConstraint(inputFieldList.get(0), new DistributedList<>(Collections.singletonList(new WeightedElement<>(10, 1.0F)))); - IsGreaterThanConstantConstraint constraintB = new IsGreaterThanConstantConstraint(inputFieldList.get(0), HelixNumber.create(0)); + InSetConstraint constraintA = new InSetConstraint(inputFieldList.get(0), new DistributedList<>(Collections.singletonList(new WeightedElement<>(10, 1.0F)))); + GreaterThanConstraint constraintB = new GreaterThanConstraint(inputFieldList.get(0), HelixNumber.create(0)); OrConstraint orConstraint0 = new OrConstraint(Arrays.asList(constraintA, constraintB)); - IsInSetConstraint constraintC = new IsInSetConstraint( + InSetConstraint constraintC = new InSetConstraint( inputFieldList.get(1), new DistributedList<>(Collections.singletonList(new WeightedElement<>("steam", 1.0F)))); - IsInSetConstraint constraintD = new IsInSetConstraint( + InSetConstraint constraintD = new InSetConstraint( inputFieldList.get(1), new DistributedList<>(Collections.singletonList(new WeightedElement<>("diesel", 1.0F)))); OrConstraint orConstraint1 = new OrConstraint(Arrays.asList(constraintC, constraintD)); - Rule testRule = new Rule(rule("test"), Arrays.asList(orConstraint0, orConstraint1)); + Rule testRule = new Rule("test", Arrays.asList(orConstraint0, orConstraint1)); Profile testInput = new Profile(inputFieldList, Collections.singletonList(testRule)); DecisionTreeFactory testObject = new DecisionTreeFactory(); @@ -262,17 +261,17 @@ void shouldReturnAnalysedRuleWithNoAtomicConstraints_IfAllAtomicConstraintsInPro @Test void shouldReturnAnalysedRuleWithCorrectDecisionStructure_IfAllAtomicConstraintsInProfileAreChildrenOfOrConstraints() { List inputFieldList = Arrays.asList(createField("one"), createField("two"), createField("three")); - IsInSetConstraint constraintA = new IsInSetConstraint(inputFieldList.get(0), new DistributedList<>(Collections.singletonList(new WeightedElement<>(10, 1.0F)))); - IsGreaterThanConstantConstraint constraintB = new IsGreaterThanConstantConstraint(inputFieldList.get(0), HelixNumber.create(0)); + InSetConstraint constraintA = new InSetConstraint(inputFieldList.get(0), new DistributedList<>(Collections.singletonList(new WeightedElement<>(10, 1.0F)))); + GreaterThanConstraint constraintB = new GreaterThanConstraint(inputFieldList.get(0), HelixNumber.create(0)); OrConstraint orConstraint0 = new OrConstraint(Arrays.asList(constraintA, constraintB)); - IsInSetConstraint constraintC = new IsInSetConstraint( + InSetConstraint constraintC = new InSetConstraint( inputFieldList.get(1), new DistributedList<>(Collections.singletonList(new WeightedElement<>("steam", 1.0F)))); - IsInSetConstraint constraintD = new IsInSetConstraint( + InSetConstraint constraintD = new InSetConstraint( inputFieldList.get(1), new DistributedList<>(Collections.singletonList(new WeightedElement<>("diesel", 1.0F)))); OrConstraint orConstraint1 = new OrConstraint(Arrays.asList(constraintC, constraintD)); - Rule testRule = new Rule(rule("test"), Arrays.asList(orConstraint0, orConstraint1)); + Rule testRule = new Rule("test", Arrays.asList(orConstraint0, orConstraint1)); Profile testInput = new Profile(inputFieldList, Collections.singletonList(testRule)); DecisionTreeFactory testObject = new DecisionTreeFactory(); @@ -298,19 +297,19 @@ void shouldReturnAnalysedRuleWithCorrectDecisionStructure_IfAllAtomicConstraints @Test void shouldReturnAnalysedRuleWithCorrectDecisionStructure_IfAllAtomicConstraintsInProfileAreChildrenOfOrAndAndConstraints() { List inputFieldList = Arrays.asList(createField("one"), createField("two"), createField("three")); - IsInSetConstraint constraintA = new IsInSetConstraint(inputFieldList.get(0), new DistributedList<>(Collections.singletonList(new WeightedElement<>(10, 1.0F)))); - IsGreaterThanConstantConstraint constraintB = new IsGreaterThanConstantConstraint(inputFieldList.get(0), HelixNumber.create(0)); - IsGreaterThanConstantConstraint constraintC = new IsGreaterThanConstantConstraint(inputFieldList.get(0), HelixNumber.create(5)); + InSetConstraint constraintA = new InSetConstraint(inputFieldList.get(0), new DistributedList<>(Collections.singletonList(new WeightedElement<>(10, 1.0F)))); + GreaterThanConstraint constraintB = new GreaterThanConstraint(inputFieldList.get(0), HelixNumber.create(0)); + GreaterThanConstraint constraintC = new GreaterThanConstraint(inputFieldList.get(0), HelixNumber.create(5)); AndConstraint andConstraint0 = new AndConstraint(Arrays.asList(constraintC, constraintB)); OrConstraint orConstraint0 = new OrConstraint(Arrays.asList(constraintA, andConstraint0)); - IsInSetConstraint constraintD = new IsInSetConstraint( + InSetConstraint constraintD = new InSetConstraint( inputFieldList.get(1), new DistributedList<>(Collections.singletonList(new WeightedElement<>("steam", 1.0F)))); - IsInSetConstraint constraintE = new IsInSetConstraint( + InSetConstraint constraintE = new InSetConstraint( inputFieldList.get(1), new DistributedList<>(Collections.singletonList(new WeightedElement<>("diesel", 1.0F)))); OrConstraint orConstraint1 = new OrConstraint(Arrays.asList(constraintD, constraintE)); - Rule testRule = new Rule(rule("test"), Arrays.asList(orConstraint0, orConstraint1)); + Rule testRule = new Rule("test", Arrays.asList(orConstraint0, orConstraint1)); Profile testInput = new Profile(inputFieldList, Collections.singletonList(testRule)); DecisionTreeFactory testObject = new DecisionTreeFactory(); @@ -336,11 +335,11 @@ void shouldReturnAnalysedRuleWithCorrectDecisionStructure_IfAllAtomicConstraints @Test void shouldReturnAnalysedRuleWithCorrectDecisionStructure_IfConditionalConstraintIsPresent() { List inputFieldList = Arrays.asList(createField("one"), createField("two"), createField("three")); - IsInSetConstraint constraintA = new IsInSetConstraint(inputFieldList.get(0), new DistributedList<>(Collections.singletonList(new WeightedElement<>(10, 1.0F)))); - IsGreaterThanConstantConstraint constraintB = new IsGreaterThanConstantConstraint(inputFieldList.get(1), HelixNumber.create(10)); - IsGreaterThanConstantConstraint constraintC = new IsGreaterThanConstantConstraint(inputFieldList.get(1), HelixNumber.create(20)); + InSetConstraint constraintA = new InSetConstraint(inputFieldList.get(0), new DistributedList<>(Collections.singletonList(new WeightedElement<>(10, 1.0F)))); + GreaterThanConstraint constraintB = new GreaterThanConstraint(inputFieldList.get(1), HelixNumber.create(10)); + GreaterThanConstraint constraintC = new GreaterThanConstraint(inputFieldList.get(1), HelixNumber.create(20)); ConditionalConstraint conditionalConstraint = new ConditionalConstraint(constraintA, constraintB, constraintC); - Rule testRule = new Rule(rule("test"), Collections.singletonList(conditionalConstraint)); + Rule testRule = new Rule("test", Collections.singletonList(conditionalConstraint)); Profile testInput = new Profile(inputFieldList, Collections.singletonList(testRule)); DecisionTreeFactory testObject = new DecisionTreeFactory(); @@ -366,9 +365,9 @@ void shouldReturnAnalysedRuleWithCorrectDecisionStructure_IfConditionalConstrain // Checks IF (A OR B) THEN C @Test void shouldReturnAnalysedRuleWithCorrectDecisionStructure_IfConditionalConstraintWithNestedOrIsPresent() { - AtomicConstraint aEquals10 = new IsInSetConstraint(fieldA, new DistributedList<>(Collections.singletonList(new WeightedElement<>(10, 1.0F)))); - AtomicConstraint aGreaterThan10 = new IsGreaterThanConstantConstraint(fieldA, HelixNumber.create(10)); - AtomicConstraint bGreaterThan20 = new IsGreaterThanConstantConstraint(fieldB, HelixNumber.create(20)); + AtomicConstraint aEquals10 = new InSetConstraint(fieldA, new DistributedList<>(Collections.singletonList(new WeightedElement<>(10, 1.0F)))); + AtomicConstraint aGreaterThan10 = new GreaterThanConstraint(fieldA, HelixNumber.create(10)); + AtomicConstraint bGreaterThan20 = new GreaterThanConstraint(fieldB, HelixNumber.create(20)); givenRule( new ConditionalConstraint( @@ -398,12 +397,12 @@ void shouldReturnAnalysedRuleWithCorrectDecisionStructure_IfConditionalConstrain @Test void shouldReturnAnalysedRuleWithCorrectDecisionStructure_IfNegatedConditionalConstraintIsPresent() { List inputFieldList = Arrays.asList(createField("one"), createField("two"), createField("three")); - IsInSetConstraint constraintA = new IsInSetConstraint(inputFieldList.get(0), new DistributedList<>(Collections.singletonList(new WeightedElement<>(10, 1.0F)))); - IsGreaterThanConstantConstraint constraintB = new IsGreaterThanConstantConstraint(inputFieldList.get(1), HelixNumber.create(20)); - IsGreaterThanConstantConstraint constraintC = new IsGreaterThanConstantConstraint(inputFieldList.get(1), HelixNumber.create(10)); + InSetConstraint constraintA = new InSetConstraint(inputFieldList.get(0), new DistributedList<>(Collections.singletonList(new WeightedElement<>(10, 1.0F)))); + GreaterThanConstraint constraintB = new GreaterThanConstraint(inputFieldList.get(1), HelixNumber.create(20)); + GreaterThanConstraint constraintC = new GreaterThanConstraint(inputFieldList.get(1), HelixNumber.create(10)); ConditionalConstraint conditionalConstraint = new ConditionalConstraint(constraintA, constraintB, constraintC); Constraint notConstraint = conditionalConstraint.negate(); - Rule testRule = new Rule(rule("test"), Collections.singletonList(notConstraint)); + Rule testRule = new Rule("test", Collections.singletonList(notConstraint)); Profile testInput = new Profile(inputFieldList, Collections.singletonList(testRule)); DecisionTreeFactory testObject = new DecisionTreeFactory(); @@ -434,8 +433,8 @@ void shouldReturnAnalysedRuleWithCorrectDecisionStructure_IfNegatedConditionalCo // is equivalent to // A ^ ¬B - AtomicConstraint aEqualTo10 = new IsInSetConstraint(fieldA, new DistributedList<>(Collections.singletonList(new WeightedElement<>(10, 1.0F)))); - AtomicConstraint bGreaterThan20 = new IsGreaterThanConstantConstraint(fieldB, HelixNumber.create(20)); + AtomicConstraint aEqualTo10 = new InSetConstraint(fieldA, new DistributedList<>(Collections.singletonList(new WeightedElement<>(10, 1.0F)))); + AtomicConstraint bGreaterThan20 = new GreaterThanConstraint(fieldB, HelixNumber.create(20)); Constraint inputRule = new ConditionalConstraint(aEqualTo10, bGreaterThan20).negate(); @@ -454,10 +453,10 @@ void shouldReturnAnalysedRuleWithCorrectDecisionStructure_IfNegatedConditionalCo @Test void shouldReturnAnalysedRuleWithCorrectDecisionStructure_IfDoubleNegationIsPresent() { List inputFieldList = Arrays.asList(createField("one"), createField("two"), createField("three")); - IsInSetConstraint constraintA = new IsInSetConstraint(inputFieldList.get(0), new DistributedList<>(Collections.singletonList(new WeightedElement<>(10, 1.0F)))); + InSetConstraint constraintA = new InSetConstraint(inputFieldList.get(0), new DistributedList<>(Collections.singletonList(new WeightedElement<>(10, 1.0F)))); Constraint notConstraint0 = constraintA.negate(); Constraint notConstraint1 = notConstraint0.negate(); - Rule testRule = new Rule(rule("test"), Collections.singletonList(notConstraint1)); + Rule testRule = new Rule("test", Collections.singletonList(notConstraint1)); Profile testInput = new Profile(inputFieldList, Collections.singletonList(testRule)); DecisionTreeFactory testObject = new DecisionTreeFactory(); @@ -477,10 +476,10 @@ void shouldReturnAnalysedRuleWithCorrectDecisionStructure_IfDoubleNegationIsPres @Test void shouldReturnAnalysedRuleWithCorrectDecisionStructure_IfNegatedAndIsPresent() { List inputFieldList = Arrays.asList(createField("one"), createField("two"), createField("three")); - IsInSetConstraint constraintA = new IsInSetConstraint(inputFieldList.get(0), new DistributedList<>(Collections.singletonList(new WeightedElement<>(10, 1.0F)))); - IsGreaterThanConstantConstraint constraintB = new IsGreaterThanConstantConstraint(inputFieldList.get(1), HelixNumber.create(5)); + InSetConstraint constraintA = new InSetConstraint(inputFieldList.get(0), new DistributedList<>(Collections.singletonList(new WeightedElement<>(10, 1.0F)))); + GreaterThanConstraint constraintB = new GreaterThanConstraint(inputFieldList.get(1), HelixNumber.create(5)); NegatedGrammaticalConstraint notConstraint = (NegatedGrammaticalConstraint) new AndConstraint(Arrays.asList(constraintA, constraintB)).negate(); - Rule testRule = new Rule(rule("test"), Collections.singletonList(notConstraint)); + Rule testRule = new Rule("test", Collections.singletonList(notConstraint)); Profile testInput = new Profile(inputFieldList, Collections.singletonList(testRule)); DecisionTreeFactory testObject = new DecisionTreeFactory(); @@ -502,9 +501,9 @@ void shouldReturnAnalysedRuleWithCorrectDecisionStructure_IfNegatedAndIsPresent( // (A OR B) OR C @Test void shouldReturnAnalysedRuleWithCorrectDecisionStructure_IfNestedOrsArePresent() { - AtomicConstraint constraintA = new IsInSetConstraint(fieldA, new DistributedList<>(Collections.singletonList(new WeightedElement<>(10, 1.0F)))); - AtomicConstraint constraintB = new IsGreaterThanConstantConstraint(fieldB, HelixNumber.create(20)); - AtomicConstraint constraintC = new IsGreaterThanConstantConstraint(fieldB, HelixNumber.create(10)); + AtomicConstraint constraintA = new InSetConstraint(fieldA, new DistributedList<>(Collections.singletonList(new WeightedElement<>(10, 1.0F)))); + AtomicConstraint constraintB = new GreaterThanConstraint(fieldB, HelixNumber.create(20)); + AtomicConstraint constraintC = new GreaterThanConstraint(fieldB, HelixNumber.create(10)); givenRule( new OrConstraint( @@ -541,8 +540,4 @@ private boolean isEquivalentTo(ConstraintNode expected, ConstraintNode actual) { return match; } - - private static RuleInformation rule(String description){ - return new RuleInformation(description); - } } diff --git a/generator/src/test/java/com/scottlogic/deg/generator/decisiontree/DecisionTreeOptimiserTest.java b/generator/src/test/java/com/scottlogic/deg/generator/decisiontree/DecisionTreeOptimiserTest.java index 020e5805e..695878687 100644 --- a/generator/src/test/java/com/scottlogic/deg/generator/decisiontree/DecisionTreeOptimiserTest.java +++ b/generator/src/test/java/com/scottlogic/deg/generator/decisiontree/DecisionTreeOptimiserTest.java @@ -17,7 +17,7 @@ package com.scottlogic.deg.generator.decisiontree; import com.scottlogic.deg.common.profile.Field; -import com.scottlogic.deg.common.profile.ProfileFields; +import com.scottlogic.deg.common.profile.Fields; import org.junit.jupiter.api.Test; import java.util.Collections; @@ -55,7 +55,7 @@ public void optimise_circularDependency(){ .where(B).isNotNull()) .build(); - ConstraintNode actual = optimiser.optimiseTree(new DecisionTree(original, new ProfileFields(Collections.EMPTY_LIST))) + ConstraintNode actual = optimiser.optimiseTree(new DecisionTree(original, new Fields(Collections.EMPTY_LIST))) .getRootNode(); assertThat(actual, sameBeanAs(original)); @@ -88,7 +88,7 @@ public void optimise_oneCommonIf(){ .where(A).isNotInSet("a1")) .build(); - ConstraintNode actual = optimiser.optimiseTree(new DecisionTree(original, new ProfileFields(Collections.EMPTY_LIST))) + ConstraintNode actual = optimiser.optimiseTree(new DecisionTree(original, new Fields(Collections.EMPTY_LIST))) .getRootNode(); assertThat(actual, sameBeanAs(original)); diff --git a/generator/src/test/java/com/scottlogic/deg/generator/decisiontree/DecisionTreeSimplifierTests.java b/generator/src/test/java/com/scottlogic/deg/generator/decisiontree/DecisionTreeSimplifierTests.java index 381cf266b..29fe8e7d2 100644 --- a/generator/src/test/java/com/scottlogic/deg/generator/decisiontree/DecisionTreeSimplifierTests.java +++ b/generator/src/test/java/com/scottlogic/deg/generator/decisiontree/DecisionTreeSimplifierTests.java @@ -17,9 +17,9 @@ package com.scottlogic.deg.generator.decisiontree; import com.scottlogic.deg.common.profile.Field; -import com.scottlogic.deg.common.profile.ProfileFields; +import com.scottlogic.deg.common.profile.Fields; import com.scottlogic.deg.generator.profile.constraints.atomic.AtomicConstraint; -import com.scottlogic.deg.generator.profile.constraints.atomic.IsInSetConstraint; +import com.scottlogic.deg.generator.profile.constraints.atomic.InSetConstraint; import com.scottlogic.deg.generator.profile.constraints.atomic.IsNullConstraint; import com.scottlogic.deg.generator.fieldspecs.whitelist.DistributedList; import com.scottlogic.deg.generator.fieldspecs.whitelist.WeightedElement; @@ -45,18 +45,18 @@ private static DistributedList setOf(Object... objects) { void simplify_decisionContainsSingleOptiontWithMatchingConstraintOnRootNode_doesNotSimplifyTree() { DecisionTree tree = new DecisionTree( new ConstraintNodeBuilder().addAtomicConstraints(SetUtils.setOf( - new IsInSetConstraint(createField("Field 1"), setOf(1, 2)), + new InSetConstraint(createField("Field 1"), setOf(1, 2)), new IsNullConstraint(createField("Field 1")).negate() )).setDecisions(Collections.singleton( new DecisionNode( Collections.singleton( new ConstraintNodeBuilder().addAtomicConstraints(Collections.singleton( - new IsInSetConstraint(createField("Field 1"), setOf(1, 2)) + new InSetConstraint(createField("Field 1"), setOf(1, 2)) )).setDecisions(Collections.emptySet()).build() ) ) )).build(), - new ProfileFields( + new Fields( new ArrayList() {{ add(createField("Field 1")); }} ) ); @@ -72,18 +72,18 @@ void simplify_decisionContainsSingleOptiontWithMatchingConstraintOnRootNode_does void simplify_decisionContainsSingleOptionWithDifferingConstraintOnRootNode_simplifiesDecision() { DecisionTree tree = new DecisionTree( new ConstraintNodeBuilder().addAtomicConstraints(SetUtils.setOf( - new IsInSetConstraint(createField("Field 1"), setOf(1, 2)), + new InSetConstraint(createField("Field 1"), setOf(1, 2)), new IsNullConstraint(createField("Field 1")).negate() )).setDecisions(Collections.singleton( new DecisionNode( Collections.singleton( new ConstraintNodeBuilder().addAtomicConstraints(Collections.singleton( - new IsInSetConstraint(createField("Field 2"), setOf("A", "B")) + new InSetConstraint(createField("Field 2"), setOf("A", "B")) )).setDecisions(Collections.emptySet()).build() ) ) )).build(), - new ProfileFields( + new Fields( new ArrayList() {{ add(createField("Field 1")); }} ) ); @@ -92,9 +92,9 @@ void simplify_decisionContainsSingleOptionWithDifferingConstraintOnRootNode_simp final DecisionTree result = simplifier.simplify(tree); final List expectedConstraints = Arrays.asList( - new IsInSetConstraint(createField("Field 1"), setOf(1, 2)), + new InSetConstraint(createField("Field 1"), setOf(1, 2)), new IsNullConstraint(createField("Field 1")).negate(), - new IsInSetConstraint(createField("Field 2"), setOf("A", "B")) + new InSetConstraint(createField("Field 2"), setOf("A", "B")) ); Assert.assertTrue(result.rootNode.getAtomicConstraints().containsAll(expectedConstraints)); Assert.assertTrue(result.rootNode.getDecisions().isEmpty()); diff --git a/generator/src/test/java/com/scottlogic/deg/generator/decisiontree/RowSpecTreeSolverTests.java b/generator/src/test/java/com/scottlogic/deg/generator/decisiontree/RowSpecTreeSolverTests.java index 6dbbaedb0..ceeab8938 100644 --- a/generator/src/test/java/com/scottlogic/deg/generator/decisiontree/RowSpecTreeSolverTests.java +++ b/generator/src/test/java/com/scottlogic/deg/generator/decisiontree/RowSpecTreeSolverTests.java @@ -18,18 +18,16 @@ import com.scottlogic.deg.common.profile.Field; import com.scottlogic.deg.generator.profile.Profile; -import com.scottlogic.deg.common.profile.ProfileFields; +import com.scottlogic.deg.common.profile.Fields; import com.scottlogic.deg.generator.profile.Rule; -import com.scottlogic.deg.generator.profile.RuleInformation; import com.scottlogic.deg.generator.profile.constraints.grammatical.ConditionalConstraint; -import com.scottlogic.deg.generator.profile.constraints.atomic.IsInSetConstraint; +import com.scottlogic.deg.generator.profile.constraints.atomic.InSetConstraint; import com.scottlogic.deg.generator.fieldspecs.*; import com.scottlogic.deg.generator.fieldspecs.whitelist.WeightedElement; import com.scottlogic.deg.generator.fieldspecs.whitelist.DistributedList; import com.scottlogic.deg.generator.generation.databags.DataBag; import com.scottlogic.deg.generator.generation.databags.RowSpecDataBagGenerator; import com.scottlogic.deg.generator.reducer.ConstraintReducer; -import com.scottlogic.deg.generator.restrictions.StringRestrictionsFactory; import com.scottlogic.deg.generator.walker.decisionbased.RowSpecTreeSolver; import com.scottlogic.deg.generator.walker.decisionbased.SequentialOptionPicker; import com.scottlogic.deg.generator.walker.pruner.TreePruner; @@ -86,58 +84,58 @@ void test() { final Field currency = createField("currency"); final Field city = createField("city"); - ProfileFields fields = new ProfileFields(Arrays.asList(country, currency, city)); + Fields fields = new Fields(Arrays.asList(country, currency, city)); List dummyRules = Arrays.asList( new Rule( - rule("US country constrains city"), + "US country constrains city", Collections.singletonList( new ConditionalConstraint( - new IsInSetConstraint( + new InSetConstraint( country, new DistributedList<>(Collections.singletonList(new WeightedElement<>("US", 1.0F))) ), - new IsInSetConstraint( + new InSetConstraint( city, new DistributedList<>(new ArrayList<>(Arrays.asList( new WeightedElement<>("New York", 1.0F), new WeightedElement<>("Washington DC", 1.0F))) ))))), new Rule( - rule("GB country constrains city"), + "GB country constrains city", Collections.singletonList( new ConditionalConstraint( - new IsInSetConstraint( + new InSetConstraint( country, new DistributedList<>(Collections.singletonList(new WeightedElement<>("GB", 1.0F))) ), - new IsInSetConstraint( + new InSetConstraint( city, new DistributedList<>(new ArrayList<>(Arrays.asList( new WeightedElement<>("Bristol", 1.0F), new WeightedElement<>("London", 1.0F))) ))))), new Rule( - rule("US country constrains currency"), + "US country constrains currency", Collections.singletonList( new ConditionalConstraint( - new IsInSetConstraint( + new InSetConstraint( country, new DistributedList<>(Collections.singletonList(new WeightedElement<>("US", 1.0F))) ), - new IsInSetConstraint( + new InSetConstraint( currency, new DistributedList<>(Collections.singletonList(new WeightedElement<>("USD", 1.0F))) )))), new Rule( - rule("GB country constrains currency"), + "GB country constrains currency", Collections.singletonList( new ConditionalConstraint( - new IsInSetConstraint( + new InSetConstraint( country, new DistributedList<>(Collections.singletonList(new WeightedElement<>("GB", 1.0F))) ), - new IsInSetConstraint( + new InSetConstraint( currency, new DistributedList<>(Collections.singletonList(new WeightedElement<>("GBP", 1.0F))) ))))); @@ -153,7 +151,4 @@ void test() { Assert.assertThat(rowSpecs, notNullValue()); } - private static RuleInformation rule(String description){ - return new RuleInformation(description); - } } diff --git a/generator/src/test/java/com/scottlogic/deg/generator/decisiontree/testutils/ProfileFieldComparer.java b/generator/src/test/java/com/scottlogic/deg/generator/decisiontree/testutils/ProfileFieldComparer.java index 9ccc9153d..aaef0a75b 100644 --- a/generator/src/test/java/com/scottlogic/deg/generator/decisiontree/testutils/ProfileFieldComparer.java +++ b/generator/src/test/java/com/scottlogic/deg/generator/decisiontree/testutils/ProfileFieldComparer.java @@ -16,7 +16,7 @@ package com.scottlogic.deg.generator.decisiontree.testutils; -import com.scottlogic.deg.common.profile.ProfileFields; +import com.scottlogic.deg.common.profile.Fields; import java.util.Collection; import java.util.stream.Collectors; @@ -41,12 +41,12 @@ public int getHashCode(Object item) { @Override public boolean equals(Object item1, Object item2) { - return equals((ProfileFields)item1, (ProfileFields)item2); + return equals((Fields)item1, (Fields)item2); } - private boolean equals(ProfileFields firstProfileFields, ProfileFields secondProfileFields) { - Collection firstProfileFieldsCollection = firstProfileFields.stream().collect(Collectors.toList()); - Collection secondProfileFieldsCollection = secondProfileFields.stream().collect(Collectors.toList()); + private boolean equals(Fields firstFields, Fields secondFields) { + Collection firstProfileFieldsCollection = firstFields.stream().collect(Collectors.toList()); + Collection secondProfileFieldsCollection = secondFields.stream().collect(Collectors.toList()); boolean equals = profileFieldsEqualityComparer.equals(firstProfileFieldsCollection, secondProfileFieldsCollection); if (!equals) { diff --git a/generator/src/test/java/com/scottlogic/deg/generator/decisiontree/treepartitioning/ConstraintToFieldMapperTests.java b/generator/src/test/java/com/scottlogic/deg/generator/decisiontree/treepartitioning/ConstraintToFieldMapperTests.java index d0e4f8612..57796a25e 100644 --- a/generator/src/test/java/com/scottlogic/deg/generator/decisiontree/treepartitioning/ConstraintToFieldMapperTests.java +++ b/generator/src/test/java/com/scottlogic/deg/generator/decisiontree/treepartitioning/ConstraintToFieldMapperTests.java @@ -18,8 +18,8 @@ import com.scottlogic.deg.common.profile.Field; import com.scottlogic.deg.common.profile.FieldBuilder; -import com.scottlogic.deg.common.profile.ProfileFields; -import com.scottlogic.deg.generator.profile.constraints.atomic.IsInSetConstraint; +import com.scottlogic.deg.common.profile.Fields; +import com.scottlogic.deg.generator.profile.constraints.atomic.InSetConstraint; import com.scottlogic.deg.generator.profile.constraints.atomic.AtomicConstraint; import com.scottlogic.deg.generator.decisiontree.ConstraintNodeBuilder; import com.scottlogic.deg.generator.decisiontree.DecisionNode; @@ -46,7 +46,7 @@ private DistributedList whitelistOf(Object element) { void shouldFindConstraintMappings() { givenFields("A"); - final AtomicConstraint constraint = new IsInSetConstraint(createField("A"), whitelistOf("test-value")); + final AtomicConstraint constraint = new InSetConstraint(createField("A"), whitelistOf("test-value")); givenConstraints(constraint); givenFields("A"); @@ -57,7 +57,7 @@ void shouldFindConstraintMappings() { void shouldFindRootDecisionNodeMapping() { givenFields("B"); - final AtomicConstraint constraint = new IsInSetConstraint(createField("B"), whitelistOf("test-value")); + final AtomicConstraint constraint = new InSetConstraint(createField("B"), whitelistOf("test-value")); final DecisionNode decision = new DecisionNode( new ConstraintNodeBuilder().addAtomicConstraints(constraint).build()); @@ -70,9 +70,9 @@ void shouldFindRootDecisionNodeMapping() { void shouldCreateCorrectNumberOfMappings() { givenFields("A", "B", "C"); - final AtomicConstraint constraintA = new IsInSetConstraint(createField("A"), whitelistOf("test-value")); - final AtomicConstraint constraintB = new IsInSetConstraint(createField("B"), whitelistOf("test-value")); - final AtomicConstraint constraintC = new IsInSetConstraint(createField("C"), whitelistOf("test-value")); + final AtomicConstraint constraintA = new InSetConstraint(createField("A"), whitelistOf("test-value")); + final AtomicConstraint constraintB = new InSetConstraint(createField("B"), whitelistOf("test-value")); + final AtomicConstraint constraintC = new InSetConstraint(createField("C"), whitelistOf("test-value")); givenConstraints(constraintA, constraintB, constraintC); @@ -83,12 +83,12 @@ void shouldCreateCorrectNumberOfMappings() { void shouldMapTopLevelConstraintsToNestedFields() { givenFields("A", "B", "C", "D", "E", "F"); - final AtomicConstraint constraintA = new IsInSetConstraint(createField("A"), whitelistOf("test-value")); - final AtomicConstraint constraintB = new IsInSetConstraint(createField("B"), whitelistOf("test-value")); - final AtomicConstraint constraintC = new IsInSetConstraint(createField("C"), whitelistOf("test-value")); - final AtomicConstraint constraintD = new IsInSetConstraint(createField("D"), whitelistOf("test-value")); - final AtomicConstraint constraintE = new IsInSetConstraint(createField("E"), whitelistOf("test-value")); - final AtomicConstraint constraintF = new IsInSetConstraint(createField("F"), whitelistOf("test-value")); + final AtomicConstraint constraintA = new InSetConstraint(createField("A"), whitelistOf("test-value")); + final AtomicConstraint constraintB = new InSetConstraint(createField("B"), whitelistOf("test-value")); + final AtomicConstraint constraintC = new InSetConstraint(createField("C"), whitelistOf("test-value")); + final AtomicConstraint constraintD = new InSetConstraint(createField("D"), whitelistOf("test-value")); + final AtomicConstraint constraintE = new InSetConstraint(createField("E"), whitelistOf("test-value")); + final AtomicConstraint constraintF = new InSetConstraint(createField("F"), whitelistOf("test-value")); final DecisionNode decisionABC = new DecisionNode( new ConstraintNodeBuilder().addAtomicConstraints(Collections.emptySet()).setDecisions(SetUtils.setOf( @@ -117,13 +117,13 @@ void shouldMapTopLevelConstraintsToNestedFields() { void beforeEach() { constraintsSet = new HashSet<>(); decisionsSet = new HashSet<>(); - fields = new ProfileFields(Collections.emptyList()); + fields = new Fields(Collections.emptyList()); mappings = null; } private Set constraintsSet; private Set decisionsSet; - private ProfileFields fields; + private Fields fields; private Map> mappings; private void givenConstraints(AtomicConstraint... constraints) { @@ -135,7 +135,7 @@ private void givenDecisions(DecisionNode... decisions) { } private void givenFields(String... fieldNames) { - fields = new ProfileFields( + fields = new Fields( Arrays.stream(fieldNames) .map(FieldBuilder::createField) .collect(Collectors.toList())); diff --git a/generator/src/test/java/com/scottlogic/deg/generator/decisiontree/treepartitioning/TreePartitionerTests.java b/generator/src/test/java/com/scottlogic/deg/generator/decisiontree/treepartitioning/TreePartitionerTests.java index ff0e2b8c2..bc9cf7b2e 100644 --- a/generator/src/test/java/com/scottlogic/deg/generator/decisiontree/treepartitioning/TreePartitionerTests.java +++ b/generator/src/test/java/com/scottlogic/deg/generator/decisiontree/treepartitioning/TreePartitionerTests.java @@ -17,8 +17,8 @@ package com.scottlogic.deg.generator.decisiontree.treepartitioning; import com.scottlogic.deg.common.profile.FieldBuilder; -import com.scottlogic.deg.common.profile.ProfileFields; -import com.scottlogic.deg.generator.profile.constraints.atomic.IsInSetConstraint; +import com.scottlogic.deg.common.profile.Fields; +import com.scottlogic.deg.generator.profile.constraints.atomic.InSetConstraint; import com.scottlogic.deg.generator.profile.constraints.atomic.AtomicConstraint; import com.scottlogic.deg.generator.decisiontree.*; import com.scottlogic.deg.generator.decisiontree.testutils.*; @@ -270,7 +270,7 @@ private AtomicConstraint atomicConstraint(String fieldName) { AtomicConstraint constraint = this.constraints.get(fieldName); if (constraint == null) { - constraint = new IsInSetConstraint( + constraint = new InSetConstraint( createField(fieldName), new DistributedList<>( Collections.singletonList( @@ -285,14 +285,14 @@ private DecisionNode decision(ConstraintNode... constraints) { return new DecisionNode(constraints); } - private ProfileFields fields(String... fieldNames) { - return new ProfileFields( + private Fields fields(String... fieldNames) { + return new Fields( Stream.of(fieldNames) .map(FieldBuilder::createField) .collect(Collectors.toList())); } - private DecisionTree tree(ProfileFields fields, ConstraintNode rootNode) { + private DecisionTree tree(Fields fields, ConstraintNode rootNode) { return new DecisionTree(rootNode, fields); } diff --git a/generator/src/test/java/com/scottlogic/deg/generator/fieldspecs/RowSpecMergerTest.java b/generator/src/test/java/com/scottlogic/deg/generator/fieldspecs/RowSpecMergerTest.java index c2493dc30..ddb689bb1 100644 --- a/generator/src/test/java/com/scottlogic/deg/generator/fieldspecs/RowSpecMergerTest.java +++ b/generator/src/test/java/com/scottlogic/deg/generator/fieldspecs/RowSpecMergerTest.java @@ -2,7 +2,7 @@ import com.google.common.collect.ImmutableMap; import com.scottlogic.deg.common.profile.Field; -import com.scottlogic.deg.common.profile.ProfileFields; +import com.scottlogic.deg.common.profile.Fields; import com.scottlogic.deg.common.profile.FieldType; import org.junit.jupiter.api.Test; @@ -20,7 +20,7 @@ class RowSpecMergerTest { FieldSpec notNull = FieldSpecFactory.fromType(FieldType.STRING).withNotNull(); Field A = createField("A"); Field B = createField("B"); - ProfileFields fields = new ProfileFields(Arrays.asList(A, B)); + Fields fields = new Fields(Arrays.asList(A, B)); @Test void merge_notContradictoryForField() { diff --git a/generator/src/test/java/com/scottlogic/deg/generator/fieldspecs/relations/AfterDateRelationTest.java b/generator/src/test/java/com/scottlogic/deg/generator/fieldspecs/relations/AfterDateRelationTest.java index daeaae61c..a9e056677 100644 --- a/generator/src/test/java/com/scottlogic/deg/generator/fieldspecs/relations/AfterDateRelationTest.java +++ b/generator/src/test/java/com/scottlogic/deg/generator/fieldspecs/relations/AfterDateRelationTest.java @@ -16,10 +16,7 @@ package com.scottlogic.deg.generator.fieldspecs.relations; -import com.scottlogic.deg.common.profile.Field; -import com.scottlogic.deg.common.profile.FieldType; -import com.scottlogic.deg.common.profile.DateTimeGranularity; -import com.scottlogic.deg.common.profile.Granularity; +import com.scottlogic.deg.common.profile.*; import com.scottlogic.deg.common.util.defaults.DateTimeDefaults; import com.scottlogic.deg.generator.fieldspecs.FieldSpec; import com.scottlogic.deg.generator.fieldspecs.FieldSpecFactory; @@ -36,8 +33,8 @@ public class AfterDateRelationTest { - private final Field a = new Field("a", FieldType.DATETIME, false, "", false); - private final Field b = new Field("b", FieldType.DATETIME, false, "", false); + private final Field a = new Field("a", SpecificFieldType.DATETIME, false, "", false, false); + private final Field b = new Field("b", SpecificFieldType.DATETIME, false, "", false, false); @Test public void testReduceToFieldSpec_withNotNull_reducesToSpec() { diff --git a/generator/src/test/java/com/scottlogic/deg/generator/fieldspecs/relations/BeforeDateRelationTest.java b/generator/src/test/java/com/scottlogic/deg/generator/fieldspecs/relations/BeforeDateRelationTest.java index e69b7f856..676d8affb 100644 --- a/generator/src/test/java/com/scottlogic/deg/generator/fieldspecs/relations/BeforeDateRelationTest.java +++ b/generator/src/test/java/com/scottlogic/deg/generator/fieldspecs/relations/BeforeDateRelationTest.java @@ -16,10 +16,7 @@ package com.scottlogic.deg.generator.fieldspecs.relations; -import com.scottlogic.deg.common.profile.Field; -import com.scottlogic.deg.common.profile.FieldType; -import com.scottlogic.deg.common.profile.DateTimeGranularity; -import com.scottlogic.deg.common.profile.Granularity; +import com.scottlogic.deg.common.profile.*; import com.scottlogic.deg.common.util.defaults.DateTimeDefaults; import com.scottlogic.deg.generator.fieldspecs.FieldSpec; import com.scottlogic.deg.generator.fieldspecs.FieldSpecFactory; @@ -36,8 +33,8 @@ public class BeforeDateRelationTest { - private final Field a = new Field("a", FieldType.DATETIME, false, "", false); - private final Field b = new Field("b", FieldType.DATETIME, false, "", false); + private final Field a = new Field("a", SpecificFieldType.DATETIME, false, "", false, false); + private final Field b = new Field("b", SpecificFieldType.DATETIME, false, "", false, false); @Test public void testReduceToFieldSpec_withNotNull_reducesToSpec() { diff --git a/generator/src/test/java/com/scottlogic/deg/generator/fieldspecs/relations/EqualToDateRelationTest.java b/generator/src/test/java/com/scottlogic/deg/generator/fieldspecs/relations/EqualToDateRelationTest.java index 533e649ad..4e92c61c3 100644 --- a/generator/src/test/java/com/scottlogic/deg/generator/fieldspecs/relations/EqualToDateRelationTest.java +++ b/generator/src/test/java/com/scottlogic/deg/generator/fieldspecs/relations/EqualToDateRelationTest.java @@ -1,7 +1,7 @@ package com.scottlogic.deg.generator.fieldspecs.relations; import com.scottlogic.deg.common.profile.Field; -import com.scottlogic.deg.common.profile.FieldType; +import com.scottlogic.deg.common.profile.SpecificFieldType; import com.scottlogic.deg.generator.fieldspecs.FieldSpec; import com.scottlogic.deg.generator.fieldspecs.FieldSpecFactory; import com.scottlogic.deg.generator.fieldspecs.whitelist.DistributedList; @@ -16,8 +16,8 @@ class EqualToDateRelationTest { - private final Field a = new Field("a", FieldType.DATETIME, false ,"", false); - private final Field b = new Field("b", FieldType.DATETIME, false, "", false); + private final Field a = new Field("a", SpecificFieldType.DATETIME, false ,"", false, false); + private final Field b = new Field("b", SpecificFieldType.DATETIME, false, "", false, false); private final FieldSpecRelations equalToDateRelations = new EqualToRelation(a, b); @Test diff --git a/generator/src/test/java/com/scottlogic/deg/generator/fieldspecs/relations/FieldSpecRelationsTest.java b/generator/src/test/java/com/scottlogic/deg/generator/fieldspecs/relations/FieldSpecRelationsTest.java index f41e83b17..4c95fb2e8 100644 --- a/generator/src/test/java/com/scottlogic/deg/generator/fieldspecs/relations/FieldSpecRelationsTest.java +++ b/generator/src/test/java/com/scottlogic/deg/generator/fieldspecs/relations/FieldSpecRelationsTest.java @@ -1,8 +1,8 @@ package com.scottlogic.deg.generator.fieldspecs.relations; -import com.scottlogic.deg.common.profile.Field; -import com.scottlogic.deg.common.profile.FieldType; import com.scottlogic.deg.common.profile.DateTimeGranularity; +import com.scottlogic.deg.common.profile.Field; +import com.scottlogic.deg.common.profile.SpecificFieldType; import com.scottlogic.deg.common.util.defaults.DateTimeDefaults; import com.scottlogic.deg.generator.fieldspecs.FieldSpec; import com.scottlogic.deg.generator.fieldspecs.FieldSpecFactory; @@ -15,15 +15,14 @@ import static com.scottlogic.deg.common.profile.FieldBuilder.createField; import static com.scottlogic.deg.common.util.Defaults.ISO_MAX_DATE; import static com.scottlogic.deg.common.util.Defaults.ISO_MIN_DATE; -import static com.scottlogic.deg.generator.restrictions.linear.LinearRestrictionsFactory.createDateTimeRestrictions; import static com.shazam.shazamcrest.MatcherAssert.assertThat; import static com.shazam.shazamcrest.matcher.Matchers.sameBeanAs; import static java.time.temporal.ChronoUnit.MILLIS; import static java.time.temporal.ChronoUnit.YEARS; class FieldSpecRelationsTest { - private Field main = createField("main", FieldType.DATETIME); - private Field other = createField("other", FieldType.DATETIME); + private Field main = createField("main", SpecificFieldType.DATETIME); + private Field other = createField("other", SpecificFieldType.DATETIME); @Test public void equalTo_exactValue_returnsSame(){ diff --git a/generator/src/test/java/com/scottlogic/deg/generator/generation/FieldSpecValueGeneratorTests.java b/generator/src/test/java/com/scottlogic/deg/generator/generation/FieldSpecValueGeneratorTests.java index 9783b1d7d..d6fc53c9f 100644 --- a/generator/src/test/java/com/scottlogic/deg/generator/generation/FieldSpecValueGeneratorTests.java +++ b/generator/src/test/java/com/scottlogic/deg/generator/generation/FieldSpecValueGeneratorTests.java @@ -17,6 +17,7 @@ package com.scottlogic.deg.generator.generation; import com.scottlogic.deg.common.profile.Field; +import com.scottlogic.deg.common.profile.SpecificFieldType; import com.scottlogic.deg.generator.fieldspecs.FieldSpec; import com.scottlogic.deg.generator.fieldspecs.FieldSpecFactory; import com.scottlogic.deg.generator.fieldspecs.WhitelistFieldSpec; @@ -31,13 +32,13 @@ import org.junit.jupiter.api.Test; import java.math.BigDecimal; -import java.util.*; +import java.util.Arrays; +import java.util.HashSet; +import java.util.Set; import java.util.stream.Collectors; import java.util.stream.Stream; import static com.scottlogic.deg.common.profile.FieldBuilder.createField; -import static com.scottlogic.deg.common.profile.FieldType.NUMERIC; -import static com.scottlogic.deg.common.profile.FieldType.STRING; import static com.scottlogic.deg.generator.config.detail.DataGenerationType.*; import static com.shazam.shazamcrest.MatcherAssert.assertThat; import static com.shazam.shazamcrest.matcher.Matchers.sameBeanAs; @@ -74,7 +75,7 @@ void generate_fieldSpecMustContainRestrictionNullAndNumericRestrictionApplied_re new JavaUtilRandomNumberGenerator()); final Set result = - fieldSpecFulfiller.generate(createField(null, NUMERIC), fieldSpec).collect(Collectors.toSet()); + fieldSpecFulfiller.generate(createField(null, SpecificFieldType.DECIMAL), fieldSpec).collect(Collectors.toSet()); Set expectedDataBags = new HashSet<>( Arrays.asList( @@ -116,7 +117,7 @@ void generateRandom_uniqueFieldSpec_returnsAllValues() { randomNumberGenerator ); - fieldSpecFulfiller.generate(new Field(null, STRING, true, null, false), fieldSpec).collect(Collectors.toSet()); + fieldSpecFulfiller.generate(new Field(null, SpecificFieldType.STRING, true, null, false, false), fieldSpec).collect(Collectors.toSet()); verify(fieldValueSource, times(1)).generateAllValues(); verify(fieldValueSource, times(0)).generateInterestingValues(); @@ -144,7 +145,7 @@ void generateInteresting_uniqueFieldSpec_returnsAllValues() { randomNumberGenerator ); - fieldSpecFulfiller.generate(new Field(null, STRING, true, null, false), fieldSpec).collect(Collectors.toSet()); + fieldSpecFulfiller.generate(new Field(null, SpecificFieldType.STRING, true, null, false, false), fieldSpec).collect(Collectors.toSet()); verify(fieldValueSource, times(1)).generateAllValues(); verify(fieldValueSource, times(0)).generateInterestingValues(); diff --git a/generator/src/test/java/com/scottlogic/deg/generator/generation/UpfrontTreePrunerTests.java b/generator/src/test/java/com/scottlogic/deg/generator/generation/UpfrontTreePrunerTests.java index 10234afdd..02d273511 100644 --- a/generator/src/test/java/com/scottlogic/deg/generator/generation/UpfrontTreePrunerTests.java +++ b/generator/src/test/java/com/scottlogic/deg/generator/generation/UpfrontTreePrunerTests.java @@ -17,7 +17,7 @@ package com.scottlogic.deg.generator.generation; import com.scottlogic.deg.common.profile.Field; -import com.scottlogic.deg.common.profile.ProfileFields; +import com.scottlogic.deg.common.profile.Fields; import com.scottlogic.deg.generator.builders.TestConstraintNodeBuilder; import com.scottlogic.deg.generator.decisiontree.ConstraintNode; import com.scottlogic.deg.generator.decisiontree.ConstraintNodeBuilder; @@ -63,10 +63,10 @@ void runUpfrontPrune_withOneField_returnsPrunedTree() { fieldSpecs.put(fieldA, FieldSpecFactory.fromType(fieldA.getType())); ConstraintNode unPrunedRoot = Mockito.mock(ConstraintNode.class); - DecisionTree tree = new DecisionTree(unPrunedRoot, new ProfileFields(fields)); + DecisionTree tree = new DecisionTree(unPrunedRoot, new Fields(fields)); DecisionTree treeMarkedWithContradictions = new DecisionTree( new ConstraintNodeBuilder().build().builder().markNode(NodeMarking.CONTRADICTORY).build(), - new ProfileFields(fields)); + new Fields(fields)); Mockito.when(treePruner.pruneConstraintNode(unPrunedRoot, fieldSpecs)).thenReturn(Merged.of(prunedRoot)); Mockito.when(contradictionValidator.markContradictions(tree)).thenReturn(treeMarkedWithContradictions); @@ -88,11 +88,11 @@ void runUpfrontPrune_withTwoFields_returnsPrunedTree() { fieldSpecs.put(fieldB, FieldSpecFactory.fromType(fieldB.getType())); ConstraintNode unPrunedRoot = Mockito.mock(ConstraintNode.class); - DecisionTree tree = new DecisionTree(unPrunedRoot, new ProfileFields(fields)); + DecisionTree tree = new DecisionTree(unPrunedRoot, new Fields(fields)); DecisionTree treeMarkedWithContradictions = new DecisionTree( new ConstraintNodeBuilder().build().builder().markNode(NodeMarking.CONTRADICTORY).build(), - new ProfileFields(fields)); + new Fields(fields)); Mockito.when(treePruner.pruneConstraintNode(unPrunedRoot, fieldSpecs)).thenReturn(Merged.of(prunedRoot)); Mockito.when(contradictionValidator.markContradictions(tree)).thenReturn(treeMarkedWithContradictions); @@ -112,7 +112,7 @@ void runUpfrontPrune_whenTreeWhollyContradictory_returnsPrunedTree() { fieldSpecs.put(fieldA, FieldSpecFactory.fromType(fieldA.getType())); ConstraintNode unPrunedRoot = Mockito.mock(ConstraintNode.class); - DecisionTree tree = new DecisionTree(unPrunedRoot, new ProfileFields(fields)); + DecisionTree tree = new DecisionTree(unPrunedRoot, new Fields(fields)); //Act Mockito.when(treePruner.pruneConstraintNode(unPrunedRoot, fieldSpecs)).thenReturn(Merged.contradictory()); @@ -131,10 +131,10 @@ void runUpfrontPrune_whenTreeNotContradictory_reportsNothing() { fieldSpecs.put(fieldA, FieldSpecFactory.fromType(fieldA.getType())); ConstraintNode unPrunedRoot = Mockito.mock(ConstraintNode.class); - DecisionTree tree = new DecisionTree(unPrunedRoot, new ProfileFields(fields)); + DecisionTree tree = new DecisionTree(unPrunedRoot, new Fields(fields)); DecisionTree completelyUnmarkedTree = new DecisionTree( new ConstraintNodeBuilder().build(), - new ProfileFields(fields)); + new Fields(fields)); //Act Mockito.when(treePruner.pruneConstraintNode(unPrunedRoot, fieldSpecs)).thenReturn(Merged.of(unPrunedRoot)); @@ -154,13 +154,13 @@ void runUpfrontPrune_whenTreePartiallyContradictory_reportsPartialContradiction( fieldSpecs.put(fieldA, FieldSpecFactory.fromType(fieldA.getType())); ConstraintNode unPrunedRoot = Mockito.mock(ConstraintNode.class); - DecisionTree tree = new DecisionTree(unPrunedRoot, new ProfileFields(fields)); + DecisionTree tree = new DecisionTree(unPrunedRoot, new Fields(fields)); ConstraintNode root = constraintNode() .withDecision( constraintNode().markNode(NodeMarking.CONTRADICTORY)).build(); DecisionTree treeMarkedWithContradictions = new DecisionTree( root, - new ProfileFields(fields)); + new Fields(fields)); //Act Mockito.when(treePruner.pruneConstraintNode(unPrunedRoot, fieldSpecs)).thenReturn(Merged.of(root)); @@ -182,10 +182,10 @@ void runUpfrontPrune_whenTreeWhollyContradictory_reportsFullContradiction() { fieldSpecs.put(fieldA, FieldSpecFactory.fromType(fieldA.getType())); ConstraintNode unPrunedRoot = Mockito.mock(ConstraintNode.class); - DecisionTree tree = new DecisionTree(unPrunedRoot, new ProfileFields(fields)); + DecisionTree tree = new DecisionTree(unPrunedRoot, new Fields(fields)); DecisionTree treeMarkedWithContradictions = new DecisionTree( new ConstraintNodeBuilder().build().builder().markNode(NodeMarking.CONTRADICTORY).build(), - new ProfileFields(fields)); + new Fields(fields)); //Act Mockito.when(treePruner.pruneConstraintNode(unPrunedRoot, fieldSpecs)).thenReturn(Merged.contradictory()); @@ -228,7 +228,7 @@ public void runUpfrontPrune_forNonContradictoryTreeWithOneNode_reportsNoContradi .build(); - DecisionTree tree = new DecisionTree(root, new ProfileFields(fields)); + DecisionTree tree = new DecisionTree(root, new Fields(fields)); //Act upfrontPruner.runUpfrontPrune(tree, monitor); @@ -252,7 +252,7 @@ public void runUpfrontPrune_forNonContradictoryTreeWithTwoNonContradictoryChildr .build(); - DecisionTree tree = new DecisionTree(root, new ProfileFields(fields)); + DecisionTree tree = new DecisionTree(root, new Fields(fields)); //Act upfrontPruner.runUpfrontPrune(tree, monitor); @@ -285,7 +285,7 @@ public void runUpfrontPrune_forNonContradictoryTreeWithContradictionsThatAreNotR .build(); - DecisionTree tree = new DecisionTree(root, new ProfileFields(fields)); + DecisionTree tree = new DecisionTree(root, new Fields(fields)); //Act upfrontPruner.runUpfrontPrune(tree, monitor); @@ -322,7 +322,7 @@ public void runUpfrontPrune_forPartiallyContradictoryTreeWithTwoContradictionsIn .build(); - DecisionTree tree = new DecisionTree(root, new ProfileFields(fields)); + DecisionTree tree = new DecisionTree(root, new Fields(fields)); //Act upfrontPruner.runUpfrontPrune(tree, monitor); @@ -348,7 +348,7 @@ public void runUpfrontPrune_forNonContradictoryTreeWithContradictionInOneBranch_ .build(); - DecisionTree tree = new DecisionTree(root, new ProfileFields(fields)); + DecisionTree tree = new DecisionTree(root, new Fields(fields)); //Act upfrontPruner.runUpfrontPrune(tree, monitor); @@ -373,7 +373,7 @@ public void runUpfrontPrune_forPartiallyContradictoryTreeWithOneContradictoryChi .build(); - DecisionTree tree = new DecisionTree(root, new ProfileFields(fields)); + DecisionTree tree = new DecisionTree(root, new Fields(fields)); //Act upfrontPruner.runUpfrontPrune(tree, monitor); @@ -404,7 +404,7 @@ public void runUpfrontPrune_forPartiallyContradictoryTreeWithRootContradictingWi .where(fieldB).isNull())) .build(); - DecisionTree tree = new DecisionTree(root, new ProfileFields(fields)); + DecisionTree tree = new DecisionTree(root, new Fields(fields)); //Act upfrontPruner.runUpfrontPrune(tree, monitor); @@ -441,7 +441,7 @@ public void runUpfrontPrune_forPartiallyContradictoryTreeWithOneContradictionDee .where(fieldB).isNull())) .build(); - DecisionTree tree = new DecisionTree(root, new ProfileFields(fields)); + DecisionTree tree = new DecisionTree(root, new Fields(fields)); //Act upfrontPruner.runUpfrontPrune(tree, monitor); @@ -480,7 +480,7 @@ public void runUpfrontPrune_forPartiallyContradictoryTreeWithTwoSelfContradictin ) .build(); - DecisionTree tree = new DecisionTree(root, new ProfileFields(fields)); + DecisionTree tree = new DecisionTree(root, new Fields(fields)); //Act upfrontPruner.runUpfrontPrune(tree, monitor); @@ -503,7 +503,7 @@ public void runUpfrontPrune_forWhollyContradictoryProfileWithOnlyRoot_reportsFul .build(); - DecisionTree tree = new DecisionTree(root, new ProfileFields(fields)); + DecisionTree tree = new DecisionTree(root, new Fields(fields)); //Act upfrontPruner.runUpfrontPrune(tree, monitor); @@ -531,7 +531,7 @@ public void runUpfrontPrune_forWhollyContradictoryProfileWithContradictoryRoot_r .build(); - DecisionTree tree = new DecisionTree(root, new ProfileFields(fields)); + DecisionTree tree = new DecisionTree(root, new Fields(fields)); //Act upfrontPruner.runUpfrontPrune(tree, monitor); @@ -561,7 +561,7 @@ public void runUpfrontPrune_forWhollyContradictoryProfileWithEveryNodeContradict .build(); - DecisionTree tree = new DecisionTree(root, new ProfileFields(fields)); + DecisionTree tree = new DecisionTree(root, new Fields(fields)); //Act upfrontPruner.runUpfrontPrune(tree, monitor); @@ -592,7 +592,7 @@ public void runUpfrontPrune_forWhollyContradictoryProfileWithContradictionDeepIn .where(fieldA).isNotNull()))) .build(); - DecisionTree tree = new DecisionTree(root, new ProfileFields(fields)); + DecisionTree tree = new DecisionTree(root, new Fields(fields)); //Act upfrontPruner.runUpfrontPrune(tree, monitor); @@ -622,7 +622,7 @@ public void runUpfrontPrune_forWhollyContradictoryProfileWithAllContradictingNod .build(); - DecisionTree tree = new DecisionTree(root, new ProfileFields(fields)); + DecisionTree tree = new DecisionTree(root, new Fields(fields)); //Act upfrontPruner.runUpfrontPrune(tree, monitor); @@ -652,7 +652,7 @@ public void runUpfrontPrune_forWhollyContradictoryProfileWithNonContradictingRoo .build(); - DecisionTree tree = new DecisionTree(root, new ProfileFields(fields)); + DecisionTree tree = new DecisionTree(root, new Fields(fields)); //Act upfrontPruner.runUpfrontPrune(tree, monitor); diff --git a/generator/src/test/java/com/scottlogic/deg/generator/generation/databags/RowSpecDataBagGeneratorTests.java b/generator/src/test/java/com/scottlogic/deg/generator/generation/databags/RowSpecDataBagGeneratorTests.java index 0cfaf6bdd..a2b344a6e 100644 --- a/generator/src/test/java/com/scottlogic/deg/generator/generation/databags/RowSpecDataBagGeneratorTests.java +++ b/generator/src/test/java/com/scottlogic/deg/generator/generation/databags/RowSpecDataBagGeneratorTests.java @@ -17,11 +17,10 @@ package com.scottlogic.deg.generator.generation.databags; import com.scottlogic.deg.common.profile.Field; -import com.scottlogic.deg.common.profile.ProfileFields; +import com.scottlogic.deg.common.profile.Fields; import com.scottlogic.deg.generator.builders.DataBagBuilder; import com.scottlogic.deg.generator.fieldspecs.FieldSpec; import com.scottlogic.deg.generator.fieldspecs.RowSpec; -import com.scottlogic.deg.generator.generation.FieldSpecValueGenerator; import com.scottlogic.deg.generator.generation.combinationstrategies.CombinationStrategy; import com.scottlogic.deg.generator.generation.combinationstrategies.ExhaustiveCombinationStrategy; import com.scottlogic.deg.generator.generation.grouped.FieldSpecGroupValueGenerator; @@ -45,7 +44,7 @@ class RowSpecDataBagGeneratorTests { private Field field = createField("Field1"); Field field2 = createField("field2"); Field field3 = createField("field3"); - private ProfileFields fields = new ProfileFields(Collections.singletonList(field)); + private Fields fields = new Fields(Collections.singletonList(field)); private FieldSpec fieldSpec = mock(FieldSpec.class); private FieldSpec fieldSpec2 = mock(FieldSpec.class); private FieldSpec fieldSpec3 = mock(FieldSpec.class); @@ -82,7 +81,7 @@ void factoryIsCalledForEachField() { put(field2, fieldSpec2); put(field3, fieldSpec3); }}; RowSpec rowSpec = new RowSpec( - new ProfileFields(Arrays.asList(field2, field, field3)), + new Fields(Arrays.asList(field2, field, field3)), map, Collections.emptyList()); diff --git a/generator/src/test/java/com/scottlogic/deg/generator/generation/grouped/RowSpecGrouperTest.java b/generator/src/test/java/com/scottlogic/deg/generator/generation/grouped/RowSpecGrouperTest.java index 431d804b4..18f421155 100644 --- a/generator/src/test/java/com/scottlogic/deg/generator/generation/grouped/RowSpecGrouperTest.java +++ b/generator/src/test/java/com/scottlogic/deg/generator/generation/grouped/RowSpecGrouperTest.java @@ -18,7 +18,7 @@ package com.scottlogic.deg.generator.generation.grouped; import com.scottlogic.deg.common.profile.Field; -import com.scottlogic.deg.common.profile.ProfileFields; +import com.scottlogic.deg.common.profile.Fields; import com.scottlogic.deg.generator.fieldspecs.FieldSpec; import com.scottlogic.deg.generator.fieldspecs.FieldSpecFactory; import com.scottlogic.deg.generator.fieldspecs.FieldSpecGroup; @@ -41,7 +41,7 @@ class RowSpecGrouperTest { void createGroups_withTwoRelatedFields_givesOneGroupOfSizeOne() { Field first = createField("first"); Field second = createField("second"); - ProfileFields fields = new ProfileFields(Arrays.asList(first, second)); + Fields fields = new Fields(Arrays.asList(first, second)); Map fieldSpecMap = fieldSpecMapOf(first, second); @@ -60,7 +60,7 @@ void createGroups_withTwoAndOneFields_givesTwoGroups() { Field first = createField("first"); Field second = createField("second"); Field third = createField("third"); - ProfileFields fields = new ProfileFields(Arrays.asList(first, second, third)); + Fields fields = new Fields(Arrays.asList(first, second, third)); Map fieldSpecMap = fieldSpecMapOf(first, second, third); @@ -79,7 +79,7 @@ void createGroups_withThreeIndependentFields_givesThreeGroups() { Field first = createField("first"); Field second = createField("second"); Field third = createField("third"); - ProfileFields fields = new ProfileFields(Arrays.asList(first, second, third)); + Fields fields = new Fields(Arrays.asList(first, second, third)); Map fieldSpecMap = fieldSpecMapOf(first, second, third); @@ -97,7 +97,7 @@ void createGroups_withThreeCodependentFields_givesOneGroup() { Field first = createField("first"); Field second = createField("second"); Field third = createField("third"); - ProfileFields fields = new ProfileFields(Arrays.asList(first, second, third)); + Fields fields = new Fields(Arrays.asList(first, second, third)); Map fieldSpecMap = fieldSpecMapOf(first, second, third); @@ -115,7 +115,7 @@ void createGroups_withThreeRelatedFieldsWithACircularLink_givesOneGroup() { Field first = createField("first"); Field second = createField("second"); Field third = createField("third"); - ProfileFields fields = new ProfileFields(Arrays.asList(first, second, third)); + Fields fields = new Fields(Arrays.asList(first, second, third)); Map fieldSpecMap = fieldSpecMapOf(first, second, third); @@ -139,7 +139,7 @@ void createGroups_withFiveFields_correctlyGroups() { Field fourth = createField("fourth"); Field fifth = createField("fifth"); - ProfileFields fields = new ProfileFields(Arrays.asList(first, second, third, fourth, fifth)); + Fields fields = new Fields(Arrays.asList(first, second, third, fourth, fifth)); Map fieldSpecMap = fieldSpecMapOf(first, second, third, fourth, fifth); @@ -160,7 +160,7 @@ void createGroups_withMultipleLinksBetweenTwoFields_givesOneGroup() { Field first = createField("first"); Field second = createField("second"); - ProfileFields fields = new ProfileFields(Arrays.asList(first, second)); + Fields fields = new Fields(Arrays.asList(first, second)); Map fieldSpecMap = fieldSpecMapOf(first, second); diff --git a/generator/src/test/java/com/scottlogic/deg/generator/profile/constraints/atomic/IsInSetConstraintTests.java b/generator/src/test/java/com/scottlogic/deg/generator/profile/constraints/atomic/InSetConstraintTests.java similarity index 84% rename from generator/src/test/java/com/scottlogic/deg/generator/profile/constraints/atomic/IsInSetConstraintTests.java rename to generator/src/test/java/com/scottlogic/deg/generator/profile/constraints/atomic/InSetConstraintTests.java index 493f785c1..1cd078866 100644 --- a/generator/src/test/java/com/scottlogic/deg/generator/profile/constraints/atomic/IsInSetConstraintTests.java +++ b/generator/src/test/java/com/scottlogic/deg/generator/profile/constraints/atomic/InSetConstraintTests.java @@ -23,7 +23,8 @@ import org.junit.jupiter.api.Test; import static com.scottlogic.deg.common.profile.FieldBuilder.createField; -public class IsInSetConstraintTests { +public class InSetConstraintTests +{ @Test public void testConstraintThrowsIfGivenEmptySet(){ @@ -31,7 +32,7 @@ public void testConstraintThrowsIfGivenEmptySet(){ Assertions.assertThrows( ValidationException.class, - () -> new IsInSetConstraint(field1, DistributedList.empty())); + () -> new InSetConstraint(field1, DistributedList.empty())); } @Test @@ -40,14 +41,14 @@ public void testConstraintThrowsIfGivenNullInASet(){ Assertions.assertThrows( ValidationException.class, - () -> new IsInSetConstraint(field1, DistributedList.singleton(null))); + () -> new InSetConstraint(field1, DistributedList.singleton(null))); } @Test public void testConstraintThrowsNothingIfGivenAValidSet(){ Field field1 = createField("TestField"); Assertions.assertDoesNotThrow( - () -> new IsInSetConstraint(field1, DistributedList.singleton("foo"))); + () -> new InSetConstraint(field1, DistributedList.singleton("foo"))); } } diff --git a/generator/src/test/java/com/scottlogic/deg/generator/profile/constraints/grammatical/NotConstraintTests.java b/generator/src/test/java/com/scottlogic/deg/generator/profile/constraints/grammatical/NotConstraintTests.java index 8e1c481f0..ef1d27fcb 100644 --- a/generator/src/test/java/com/scottlogic/deg/generator/profile/constraints/grammatical/NotConstraintTests.java +++ b/generator/src/test/java/com/scottlogic/deg/generator/profile/constraints/grammatical/NotConstraintTests.java @@ -18,7 +18,7 @@ import com.scottlogic.deg.common.profile.Field; import com.scottlogic.deg.generator.profile.constraints.Constraint; -import com.scottlogic.deg.generator.profile.constraints.atomic.IsInSetConstraint; +import com.scottlogic.deg.generator.profile.constraints.atomic.InSetConstraint; import com.scottlogic.deg.generator.profile.constraints.atomic.IsNullConstraint; import com.scottlogic.deg.generator.fieldspecs.whitelist.DistributedList; import org.hamcrest.Matchers; @@ -68,11 +68,11 @@ public void testConstraintIsNotEqualDueToField() { public void testConstraintIsNotEqualDueToValue() { Field field1 = createField("TestField"); Field field2 = createField("TestField"); - Constraint constraint1 = new IsInSetConstraint( + Constraint constraint1 = new InSetConstraint( field1, DistributedList.singleton("abc") ).negate(); - Constraint constraint2 = new IsInSetConstraint( + Constraint constraint2 = new InSetConstraint( field2, DistributedList.singleton("abcd") ).negate(); diff --git a/generator/src/test/java/com/scottlogic/deg/generator/restrictions/ConstraintToFieldSpecTests.java b/generator/src/test/java/com/scottlogic/deg/generator/restrictions/ConstraintToFieldSpecTests.java index eadc30f93..de215f7c0 100644 --- a/generator/src/test/java/com/scottlogic/deg/generator/restrictions/ConstraintToFieldSpecTests.java +++ b/generator/src/test/java/com/scottlogic/deg/generator/restrictions/ConstraintToFieldSpecTests.java @@ -18,11 +18,10 @@ import com.scottlogic.deg.common.profile.Field; import com.scottlogic.deg.common.profile.HelixStringLength; -import com.scottlogic.deg.generator.fieldspecs.FieldSpec; import com.scottlogic.deg.generator.fieldspecs.RestrictionsFieldSpec; -import com.scottlogic.deg.generator.profile.constraints.atomic.IsStringLongerThanConstraint; -import com.scottlogic.deg.generator.profile.constraints.atomic.IsStringShorterThanConstraint; -import com.scottlogic.deg.generator.profile.constraints.atomic.StringHasLengthConstraint; +import com.scottlogic.deg.generator.profile.constraints.atomic.LongerThanConstraint; +import com.scottlogic.deg.generator.profile.constraints.atomic.ShorterThanConstraint; +import com.scottlogic.deg.generator.profile.constraints.atomic.OfLengthConstraint; import com.scottlogic.deg.generator.profile.constraints.atomic.ViolatedAtomicConstraint; import org.junit.jupiter.api.Test; @@ -34,7 +33,7 @@ class ConstraintToFieldSpecTests { @Test void construct_stringHasLengthConstraintRetrievedTwice_returnsTheSameGeneratorInstance() { - StringHasLengthConstraint constraint = new StringHasLengthConstraint(testField, HelixStringLength.create(10)); + OfLengthConstraint constraint = new OfLengthConstraint(testField, HelixStringLength.create(10)); final RestrictionsFieldSpec firstInstance = (RestrictionsFieldSpec)constraint.toFieldSpec(); final RestrictionsFieldSpec secondInstance = (RestrictionsFieldSpec)constraint.toFieldSpec(); @@ -44,7 +43,7 @@ void construct_stringHasLengthConstraintRetrievedTwice_returnsTheSameGeneratorIn @Test void construct_stringHasLengthConstraintViolatedTwice_returnsTheSameGeneratorInstance() { - ViolatedAtomicConstraint constraint = new ViolatedAtomicConstraint(new StringHasLengthConstraint(testField,HelixStringLength.create(10))); + ViolatedAtomicConstraint constraint = new ViolatedAtomicConstraint(new OfLengthConstraint(testField,HelixStringLength.create(10))); final RestrictionsFieldSpec firstInstance = (RestrictionsFieldSpec) constraint.toFieldSpec(); final RestrictionsFieldSpec secondInstance = (RestrictionsFieldSpec) constraint.toFieldSpec(); @@ -54,8 +53,8 @@ void construct_stringHasLengthConstraintViolatedTwice_returnsTheSameGeneratorIns @Test void construct_twoInstancesOfStringHasLengthConstraintCalledWithEqualValues_returnsTheSameGeneratorInstance() { - StringHasLengthConstraint firstConstraint = new StringHasLengthConstraint(testField,HelixStringLength.create(20)); - StringHasLengthConstraint secondConstraint = new StringHasLengthConstraint( testField, HelixStringLength.create(20)); + OfLengthConstraint firstConstraint = new OfLengthConstraint(testField,HelixStringLength.create(20)); + OfLengthConstraint secondConstraint = new OfLengthConstraint( testField, HelixStringLength.create(20)); final RestrictionsFieldSpec firstInstance = (RestrictionsFieldSpec) firstConstraint.toFieldSpec(); final RestrictionsFieldSpec secondInstance = (RestrictionsFieldSpec) secondConstraint.toFieldSpec(); @@ -65,7 +64,7 @@ void construct_twoInstancesOfStringHasLengthConstraintCalledWithEqualValues_retu @Test void construct_isStringLongerThanConstraintRetrievedTwice_returnsTheSameGeneratorInstance() { - IsStringLongerThanConstraint constraint = new IsStringLongerThanConstraint(testField, HelixStringLength.create(15)); + LongerThanConstraint constraint = new LongerThanConstraint(testField, HelixStringLength.create(15)); final RestrictionsFieldSpec firstInstance = (RestrictionsFieldSpec) constraint.toFieldSpec(); final RestrictionsFieldSpec secondInstance = (RestrictionsFieldSpec) constraint.toFieldSpec(); @@ -76,7 +75,7 @@ void construct_isStringLongerThanConstraintRetrievedTwice_returnsTheSameGenerato @Test void construct_isStringLongerThanConstraintViolatedTwice_returnsTheSameGeneratorInstance() { ViolatedAtomicConstraint constraint = new ViolatedAtomicConstraint( - new IsStringLongerThanConstraint( testField,HelixStringLength.create(10)) + new LongerThanConstraint( testField,HelixStringLength.create(10)) ); final RestrictionsFieldSpec firstInstance = (RestrictionsFieldSpec) constraint.toFieldSpec(); @@ -87,8 +86,8 @@ void construct_isStringLongerThanConstraintViolatedTwice_returnsTheSameGenerator @Test void construct_twoInstancesOfIsStringLongerThanConstraintCalledWithEqualValues_returnsTheSameGeneratorInstance() { - IsStringLongerThanConstraint firstConstraint = new IsStringLongerThanConstraint(testField, HelixStringLength.create(20)); - IsStringLongerThanConstraint secondConstraint = new IsStringLongerThanConstraint(testField, HelixStringLength.create(20)); + LongerThanConstraint firstConstraint = new LongerThanConstraint(testField, HelixStringLength.create(20)); + LongerThanConstraint secondConstraint = new LongerThanConstraint(testField, HelixStringLength.create(20)); final RestrictionsFieldSpec firstInstance = (RestrictionsFieldSpec) firstConstraint.toFieldSpec(); final RestrictionsFieldSpec secondInstance = (RestrictionsFieldSpec) secondConstraint.toFieldSpec(); @@ -98,7 +97,7 @@ void construct_twoInstancesOfIsStringLongerThanConstraintCalledWithEqualValues_r @Test void construct_isStringShorterThanConstraintRetrievedTwice_returnsTheSameGeneratorInstance() { - IsStringShorterThanConstraint constraint = new IsStringShorterThanConstraint(testField, HelixStringLength.create(25)); + ShorterThanConstraint constraint = new ShorterThanConstraint(testField, HelixStringLength.create(25)); final RestrictionsFieldSpec firstInstance = (RestrictionsFieldSpec) constraint.toFieldSpec(); final RestrictionsFieldSpec secondInstance = (RestrictionsFieldSpec) constraint.toFieldSpec(); @@ -109,7 +108,7 @@ void construct_isStringShorterThanConstraintRetrievedTwice_returnsTheSameGenerat @Test void construct_isStringShorterThanConstraintViolatedTwice_returnsTheSameGeneratorInstance() { ViolatedAtomicConstraint constraint = new ViolatedAtomicConstraint( - new IsStringShorterThanConstraint(testField, HelixStringLength.create(10)) + new ShorterThanConstraint(testField, HelixStringLength.create(10)) ); final RestrictionsFieldSpec firstInstance = (RestrictionsFieldSpec) constraint.toFieldSpec(); @@ -120,8 +119,8 @@ void construct_isStringShorterThanConstraintViolatedTwice_returnsTheSameGenerato @Test void construct_twoInstancesOfIsStringShorterThanConstraintCalledWithEqualValues_returnsTheSameGeneratorInstance() { - IsStringShorterThanConstraint firstConstraint = new IsStringShorterThanConstraint(testField, HelixStringLength.create(20)); - IsStringShorterThanConstraint secondConstraint = new IsStringShorterThanConstraint(testField, HelixStringLength.create(20)); + ShorterThanConstraint firstConstraint = new ShorterThanConstraint(testField, HelixStringLength.create(20)); + ShorterThanConstraint secondConstraint = new ShorterThanConstraint(testField, HelixStringLength.create(20)); final RestrictionsFieldSpec firstInstance = (RestrictionsFieldSpec) firstConstraint.toFieldSpec(); final RestrictionsFieldSpec secondInstance = (RestrictionsFieldSpec) secondConstraint.toFieldSpec(); diff --git a/generator/src/test/java/com/scottlogic/deg/generator/violations/filters/ConstraintTypeViolationFilterTests.java b/generator/src/test/java/com/scottlogic/deg/generator/violations/filters/ConstraintTypeViolationFilterTests.java index 6987a3d9b..a7171ee23 100644 --- a/generator/src/test/java/com/scottlogic/deg/generator/violations/filters/ConstraintTypeViolationFilterTests.java +++ b/generator/src/test/java/com/scottlogic/deg/generator/violations/filters/ConstraintTypeViolationFilterTests.java @@ -20,8 +20,8 @@ import com.scottlogic.deg.generator.fieldspecs.whitelist.DistributedList; import com.scottlogic.deg.generator.fieldspecs.whitelist.WeightedElement; import com.scottlogic.deg.generator.profile.constraints.Constraint; -import com.scottlogic.deg.generator.profile.constraints.atomic.IsGreaterThanConstantConstraint; -import com.scottlogic.deg.generator.profile.constraints.atomic.IsInSetConstraint; +import com.scottlogic.deg.generator.profile.constraints.atomic.GreaterThanConstraint; +import com.scottlogic.deg.generator.profile.constraints.atomic.InSetConstraint; import org.junit.Assert; import org.junit.Before; import org.junit.Test; @@ -38,7 +38,7 @@ public class ConstraintTypeViolationFilterTests { @Before public void setup() { - target = new ConstraintTypeViolationFilter(IsInSetConstraint.class); + target = new ConstraintTypeViolationFilter(InSetConstraint.class); } /** @@ -47,7 +47,7 @@ public void setup() { @Test public void canViolate_withMatchingTypeConstraint_returnsFalse() { //Arrange - Constraint inputConstraint = new IsInSetConstraint( + Constraint inputConstraint = new InSetConstraint( null, new DistributedList<>(Collections.singletonList(new WeightedElement<>("", 1.0F)))); @@ -64,7 +64,7 @@ public void canViolate_withMatchingTypeConstraint_returnsFalse() { @Test public void canViolate_withNonMatchingTypeConstraint_returnsTrue() { //Arrange - Constraint inputConstraint = new IsGreaterThanConstantConstraint(null, HelixNumber.create(100)); + Constraint inputConstraint = new GreaterThanConstraint(null, HelixNumber.create(100)); //Act boolean actual = target.canViolate(inputConstraint); diff --git a/generator/src/test/java/com/scottlogic/deg/generator/walker/decisionbased/RowSpecTreeSolverTests.java b/generator/src/test/java/com/scottlogic/deg/generator/walker/decisionbased/RowSpecTreeSolverTests.java index 258f0c7c2..c37e4f7f5 100644 --- a/generator/src/test/java/com/scottlogic/deg/generator/walker/decisionbased/RowSpecTreeSolverTests.java +++ b/generator/src/test/java/com/scottlogic/deg/generator/walker/decisionbased/RowSpecTreeSolverTests.java @@ -1,7 +1,7 @@ package com.scottlogic.deg.generator.walker.decisionbased; import com.scottlogic.deg.common.profile.Field; -import com.scottlogic.deg.common.profile.ProfileFields; +import com.scottlogic.deg.common.profile.Fields; import com.scottlogic.deg.generator.builders.TestConstraintNodeBuilder; import com.scottlogic.deg.generator.decisiontree.ConstraintNode; import com.scottlogic.deg.generator.decisiontree.DecisionTree; @@ -22,7 +22,7 @@ class RowSpecTreeSolverTests { private Field fieldA = createField("A"); private Field fieldB = createField("B"); - private ProfileFields profileFields = new ProfileFields(Arrays.asList(fieldA, fieldB)); + private Fields fields = new Fields(Arrays.asList(fieldA, fieldB)); private FieldSpecMerger fieldSpecMerger = new FieldSpecMerger(); private ConstraintReducer constraintReducer = new ConstraintReducer(fieldSpecMerger); private TreePruner pruner = new TreePruner(fieldSpecMerger, constraintReducer, new FieldSpecHelper()); @@ -33,7 +33,7 @@ class RowSpecTreeSolverTests { void createRowSpecs_whenRootNodeHasNoDecisions_returnsRowSpecOfRoot() { //Arrange ConstraintNode root = TestConstraintNodeBuilder.constraintNode().build(); - DecisionTree tree = new DecisionTree(root, profileFields); + DecisionTree tree = new DecisionTree(root, fields); //Act Stream rowSpecs = rowSpecTreeSolver.createRowSpecs(tree); @@ -43,7 +43,7 @@ void createRowSpecs_whenRootNodeHasNoDecisions_returnsRowSpecOfRoot() { Map fieldToFieldSpec = new HashMap<>(); fieldToFieldSpec.put(fieldA, FieldSpecFactory.fromType(fieldA.getType())); fieldToFieldSpec.put(fieldB, FieldSpecFactory.fromType(fieldB.getType())); - expectedRowSpecs.add(new RowSpec(profileFields, fieldToFieldSpec, Collections.emptyList())); + expectedRowSpecs.add(new RowSpec(fields, fieldToFieldSpec, Collections.emptyList())); assertThat(expectedRowSpecs, sameBeanAs(rowSpecs.collect(Collectors.toList()))); } @@ -52,7 +52,7 @@ void createRowSpecs_whenRootNodeHasNoDecisions_returnsRowSpecOfRoot() { void createRowSpecs_whenRootNodeHasNoDecisionsButSomeConstraints_returnsRowSpecOfRoot() { //Arrange ConstraintNode root = TestConstraintNodeBuilder.constraintNode().where(fieldA).isInSet("1", "2", "3").build(); - DecisionTree tree = new DecisionTree(root, profileFields); + DecisionTree tree = new DecisionTree(root, fields); //Act Stream rowSpecs = rowSpecTreeSolver.createRowSpecs(tree); @@ -62,7 +62,7 @@ void createRowSpecs_whenRootNodeHasNoDecisionsButSomeConstraints_returnsRowSpecO Map fieldToFieldSpec = new HashMap<>(); fieldToFieldSpec.put(fieldA, FieldSpecFactory.fromList(DistributedList.uniform(Arrays.asList("1", "2", "3")))); fieldToFieldSpec.put(fieldB, FieldSpecFactory.fromType(fieldB.getType())); - expectedRowSpecs.add(new RowSpec(profileFields, fieldToFieldSpec, Collections.emptyList())); + expectedRowSpecs.add(new RowSpec(fields, fieldToFieldSpec, Collections.emptyList())); assertThat(rowSpecs.collect(Collectors.toList()), sameBeanAs(expectedRowSpecs)); } @@ -77,7 +77,7 @@ void createRowSpecs_whenRootNodeHasSomeDecisions_returnsRowSpecOfRoot() { TestConstraintNodeBuilder.constraintNode() .where(fieldB).isInSet("1", "2", "3")) .build(); - DecisionTree tree = new DecisionTree(root, profileFields); + DecisionTree tree = new DecisionTree(root, fields); //Act Set rowSpecs = rowSpecTreeSolver.createRowSpecs(tree).collect(Collectors.toSet()); @@ -87,11 +87,11 @@ void createRowSpecs_whenRootNodeHasSomeDecisions_returnsRowSpecOfRoot() { Map option0 = new HashMap<>(); option0.put(fieldA, FieldSpecFactory.fromType(fieldA.getType())); option0.put(fieldB, FieldSpecFactory.nullOnly()); - expectedRowSpecs.add(new RowSpec(profileFields, option0, Collections.emptyList())); + expectedRowSpecs.add(new RowSpec(fields, option0, Collections.emptyList())); Map option1 = new HashMap<>(); option1.put(fieldA, FieldSpecFactory.fromType(fieldA.getType())); option1.put(fieldB, FieldSpecFactory.fromList(DistributedList.uniform(Arrays.asList("1","2","3")))); - expectedRowSpecs.add(new RowSpec(profileFields, option1, Collections.emptyList())); + expectedRowSpecs.add(new RowSpec(fields, option1, Collections.emptyList())); assertThat(rowSpecs, sameBeanAs(expectedRowSpecs)); } diff --git a/generator/src/test/java/com/scottlogic/deg/generator/walker/pruner/TreePrunerTests.java b/generator/src/test/java/com/scottlogic/deg/generator/walker/pruner/TreePrunerTests.java index 844d2a4be..36c51b331 100644 --- a/generator/src/test/java/com/scottlogic/deg/generator/walker/pruner/TreePrunerTests.java +++ b/generator/src/test/java/com/scottlogic/deg/generator/walker/pruner/TreePrunerTests.java @@ -26,8 +26,8 @@ import com.scottlogic.deg.generator.fieldspecs.FieldSpecMerger; import com.scottlogic.deg.generator.fieldspecs.whitelist.DistributedList; import com.scottlogic.deg.generator.generation.databags.DataBagValue; -import com.scottlogic.deg.generator.profile.constraints.atomic.IsStringLongerThanConstraint; -import com.scottlogic.deg.generator.profile.constraints.atomic.IsStringShorterThanConstraint; +import com.scottlogic.deg.generator.profile.constraints.atomic.LongerThanConstraint; +import com.scottlogic.deg.generator.profile.constraints.atomic.ShorterThanConstraint; import com.scottlogic.deg.generator.reducer.ConstraintReducer; import org.junit.jupiter.api.Test; @@ -68,7 +68,7 @@ class TreePrunerTests { public void pruneConstraintNode_leafNodeContradictionsWithParent_returnsContradictory() { //Arrange Set inputWhitelist = new HashSet<>(Arrays.asList("a", "b")); - ConstraintNode tree = new ConstraintNodeBuilder().addAtomicConstraints(new IsStringLongerThanConstraint(field, HelixStringLength.create(5))).build(); + ConstraintNode tree = new ConstraintNodeBuilder().addAtomicConstraints(new LongerThanConstraint(field, HelixStringLength.create(5))).build(); FieldSpec inputFieldSpec = FieldSpecFactory.fromList(DistributedList.uniform(inputWhitelist)) .withNotNull(); @@ -87,7 +87,7 @@ public void pruneConstraintNode_leafNodeContradictionsWithParent_returnsContradi public void pruneConstraintNode_leafNodeNoContradictionsWithParent_returnsLeafNode() { //Arrange Set inputWhitelist = new HashSet<>(Arrays.asList("a", "b")); - ConstraintNode tree = new ConstraintNodeBuilder().addAtomicConstraints(new IsStringShorterThanConstraint(field, HelixStringLength.create(5))).build(); + ConstraintNode tree = new ConstraintNodeBuilder().addAtomicConstraints(new ShorterThanConstraint(field, HelixStringLength.create(5))).build(); FieldSpec inputFieldSpec = FieldSpecFactory.fromList( (DistributedList.uniform(inputWhitelist))); diff --git a/orchestrator/src/main/java/com/scottlogic/deg/orchestrator/violate/AtomicConstraintTypeMapper.java b/orchestrator/src/main/java/com/scottlogic/deg/orchestrator/violate/AtomicConstraintTypeMapper.java index e3df7dd18..6c38ac842 100644 --- a/orchestrator/src/main/java/com/scottlogic/deg/orchestrator/violate/AtomicConstraintTypeMapper.java +++ b/orchestrator/src/main/java/com/scottlogic/deg/orchestrator/violate/AtomicConstraintTypeMapper.java @@ -29,33 +29,33 @@ public Class toConstraintClass(ConstraintType type) { case CONTAINS_REGEX: return ContainsRegexConstraint.class; case OF_LENGTH: - return StringHasLengthConstraint.class; + return OfLengthConstraint.class; case LONGER_THAN: - return IsStringLongerThanConstraint.class; + return LongerThanConstraint.class; case SHORTER_THAN: - return IsStringShorterThanConstraint.class; + return ShorterThanConstraint.class; case GREATER_THAN: - return IsGreaterThanConstantConstraint.class; + return GreaterThanConstraint.class; case GREATER_THAN_OR_EQUAL_TO: - return IsGreaterThanOrEqualToConstantConstraint.class; + return GreaterThanOrEqualToConstraint.class; case LESS_THAN: - return IsLessThanConstantConstraint.class; + return LessThanConstraint.class; case LESS_THAN_OR_EQUAL_TO: - return IsLessThanOrEqualToConstantConstraint.class; + return LessThanOrEqualToConstraint.class; case AFTER: - return IsAfterConstantDateTimeConstraint.class; + return AfterConstraint.class; case AFTER_OR_AT: - return IsAfterOrEqualToConstantDateTimeConstraint.class; + return AfterOrAtConstraint.class; case BEFORE: - return IsBeforeConstantDateTimeConstraint.class; + return BeforeConstraint.class; case BEFORE_OR_AT: - return IsBeforeOrEqualToConstantDateTimeConstraint.class; + return BeforeOrAtConstraint.class; case GRANULAR_TO: - return IsGranularToNumericConstraint.class; + return GranularToNumericConstraint.class; case EQUAL_TO: return EqualToConstraint.class; case IN_SET: - return IsInSetConstraint.class; + return InSetConstraint.class; default: throw new UnsupportedOperationException(); } diff --git a/orchestrator/src/main/java/com/scottlogic/deg/orchestrator/violate/ViolatedProfile.java b/orchestrator/src/main/java/com/scottlogic/deg/orchestrator/violate/ViolatedProfile.java index 3f9151bf2..427134488 100644 --- a/orchestrator/src/main/java/com/scottlogic/deg/orchestrator/violate/ViolatedProfile.java +++ b/orchestrator/src/main/java/com/scottlogic/deg/orchestrator/violate/ViolatedProfile.java @@ -17,7 +17,7 @@ package com.scottlogic.deg.orchestrator.violate; import com.scottlogic.deg.generator.profile.Profile; -import com.scottlogic.deg.common.profile.ProfileFields; +import com.scottlogic.deg.common.profile.Fields; import com.scottlogic.deg.generator.profile.Rule; import java.util.Collection; @@ -36,7 +36,7 @@ public class ViolatedProfile extends Profile { * violated. * @param description Description of profile. */ - public ViolatedProfile(Rule violatedRule, ProfileFields fields, Collection rules, String description){ + public ViolatedProfile(Rule violatedRule, Fields fields, Collection rules, String description){ super(fields, rules, description); this.violatedRule = violatedRule; } diff --git a/orchestrator/src/main/java/com/scottlogic/deg/orchestrator/violate/manifest/ManifestWriter.java b/orchestrator/src/main/java/com/scottlogic/deg/orchestrator/violate/manifest/ManifestWriter.java index f8382a93d..42859df9d 100644 --- a/orchestrator/src/main/java/com/scottlogic/deg/orchestrator/violate/manifest/ManifestWriter.java +++ b/orchestrator/src/main/java/com/scottlogic/deg/orchestrator/violate/manifest/ManifestWriter.java @@ -52,7 +52,7 @@ public void writeManifest(List result) throws IOException { .stream() .map(profile -> new ManifestDTO.TestCaseDTO( intFormatter.format(dataSetIndex.getAndIncrement()), - Collections.singleton(profile.violatedRule.getRuleInformation().getDescription()))) + Collections.singleton(profile.violatedRule.getDescription()))) .collect(Collectors.toList()); write(new ManifestDTO(testCaseDtos), outputPath.resolve("manifest.json")); diff --git a/orchestrator/src/main/java/com/scottlogic/deg/orchestrator/violate/violator/ProfileViolator.java b/orchestrator/src/main/java/com/scottlogic/deg/orchestrator/violate/violator/ProfileViolator.java index 4ded634c1..7dc688c56 100644 --- a/orchestrator/src/main/java/com/scottlogic/deg/orchestrator/violate/violator/ProfileViolator.java +++ b/orchestrator/src/main/java/com/scottlogic/deg/orchestrator/violate/violator/ProfileViolator.java @@ -81,6 +81,6 @@ private ViolatedProfile violateRuleOnProfile(Profile profile, Rule violatedRule) violatedRule, profile.getFields(), newRules, - String.format("%s -- Violating: %s", profile.getDescription(), violatedRule.getRuleInformation().getDescription())); + String.format("%s -- Violating: %s", profile.getDescription(), violatedRule.getDescription())); } } diff --git a/orchestrator/src/main/java/com/scottlogic/deg/orchestrator/violate/violator/RuleViolator.java b/orchestrator/src/main/java/com/scottlogic/deg/orchestrator/violate/violator/RuleViolator.java index e8ae7eb00..21bb13a79 100644 --- a/orchestrator/src/main/java/com/scottlogic/deg/orchestrator/violate/violator/RuleViolator.java +++ b/orchestrator/src/main/java/com/scottlogic/deg/orchestrator/violate/violator/RuleViolator.java @@ -64,7 +64,7 @@ public Rule violateRule(Rule rule) { : new AndConstraint(violate) )); } - return new Rule(rule.getRuleInformation(), newConstraints); + return new Rule(rule.getDescription(), newConstraints); } /** diff --git a/orchestrator/src/test/java/com/scottlogic/deg/orchestrator/cucumber/testframework/utils/CucumberProfileReader.java b/orchestrator/src/test/java/com/scottlogic/deg/orchestrator/cucumber/testframework/utils/CucumberProfileReader.java index c844957ff..d024dd5ba 100644 --- a/orchestrator/src/test/java/com/scottlogic/deg/orchestrator/cucumber/testframework/utils/CucumberProfileReader.java +++ b/orchestrator/src/test/java/com/scottlogic/deg/orchestrator/cucumber/testframework/utils/CucumberProfileReader.java @@ -17,6 +17,7 @@ package com.scottlogic.deg.orchestrator.cucumber.testframework.utils; import com.google.inject.Inject; +import com.scottlogic.deg.common.commands.CommandBus; import com.scottlogic.deg.generator.profile.Profile; import com.scottlogic.deg.profile.dtos.ProfileDTO; import com.scottlogic.deg.profile.dtos.RuleDTO; @@ -31,8 +32,8 @@ public class CucumberProfileReader extends JsonProfileReader { private final CucumberTestState state; @Inject - public CucumberProfileReader(CucumberTestState state, ConstraintReader mainConstraintReader) { - super(null, mainConstraintReader); + public CucumberProfileReader(CucumberTestState state, CommandBus commandBus) { + super(null, commandBus); this.state = state; } diff --git a/orchestrator/src/test/java/com/scottlogic/deg/orchestrator/cucumber/testframework/utils/CucumberTestModule.java b/orchestrator/src/test/java/com/scottlogic/deg/orchestrator/cucumber/testframework/utils/CucumberTestModule.java index 7b581c65e..3056223d5 100644 --- a/orchestrator/src/test/java/com/scottlogic/deg/orchestrator/cucumber/testframework/utils/CucumberTestModule.java +++ b/orchestrator/src/test/java/com/scottlogic/deg/orchestrator/cucumber/testframework/utils/CucumberTestModule.java @@ -27,11 +27,11 @@ import com.scottlogic.deg.orchestrator.violate.manifest.ManifestWriter; import com.scottlogic.deg.output.outputtarget.OutputTargetFactory; import com.scottlogic.deg.output.outputtarget.SingleDatasetOutputTarget; -import com.scottlogic.deg.profile.dtos.NoopVersionChecker; -import com.scottlogic.deg.profile.dtos.SchemaVersionValidator; +import com.scottlogic.deg.profile.NoopVersionChecker; +import com.scottlogic.deg.profile.SchemaVersionValidator; import com.scottlogic.deg.profile.reader.FileReader; import com.scottlogic.deg.profile.reader.ProfileReader; -import com.scottlogic.deg.profile.reader.validation.ConfigValidator; +import com.scottlogic.deg.profile.reader.ConfigValidator; import java.util.stream.Stream; diff --git a/orchestrator/src/test/java/com/scottlogic/deg/orchestrator/cucumber/testframework/utils/CucumberTestState.java b/orchestrator/src/test/java/com/scottlogic/deg/orchestrator/cucumber/testframework/utils/CucumberTestState.java index 26dfbfa89..87054e894 100644 --- a/orchestrator/src/test/java/com/scottlogic/deg/orchestrator/cucumber/testframework/utils/CucumberTestState.java +++ b/orchestrator/src/test/java/com/scottlogic/deg/orchestrator/cucumber/testframework/utils/CucumberTestState.java @@ -24,6 +24,11 @@ import com.scottlogic.deg.profile.common.ConstraintType; import com.scottlogic.deg.profile.dtos.FieldDTO; import com.scottlogic.deg.profile.dtos.constraints.*; +import com.scottlogic.deg.profile.dtos.constraints.atomic.*; +import com.scottlogic.deg.profile.dtos.constraints.grammatical.AllOfConstraintDTO; +import com.scottlogic.deg.profile.dtos.constraints.grammatical.AnyOfConstraintDTO; +import com.scottlogic.deg.profile.dtos.constraints.grammatical.ConditionalConstraintDTO; +import com.scottlogic.deg.profile.dtos.constraints.relations.*; import java.io.IOException; import java.util.*; @@ -144,7 +149,7 @@ private ConstraintDTO createConstraint(String fieldName, ConstraintType type, Ob values = (Collection) _value; }}; case IS_NULL: - return new NullConstraintDTO() {{ + return new IsNullConstraintDTO() {{ field = fieldName; isNull = (boolean) _value; }}; @@ -293,7 +298,7 @@ private ConstraintDTO createInMapConstraint(String fieldName, String key, String } private void createIfConstraint(int total) { - IfConstraintDTO dto = new IfConstraintDTO(); + ConditionalConstraintDTO dto = new ConditionalConstraintDTO(); if (total == 3) { dto.elseConstraint = constraints.remove(constraints.size() - 1); total--; diff --git a/orchestrator/src/test/java/com/scottlogic/deg/orchestrator/cucumber/testframework/utils/InMemoryOutputTarget.java b/orchestrator/src/test/java/com/scottlogic/deg/orchestrator/cucumber/testframework/utils/InMemoryOutputTarget.java index d4b84f415..01e40f617 100644 --- a/orchestrator/src/test/java/com/scottlogic/deg/orchestrator/cucumber/testframework/utils/InMemoryOutputTarget.java +++ b/orchestrator/src/test/java/com/scottlogic/deg/orchestrator/cucumber/testframework/utils/InMemoryOutputTarget.java @@ -17,7 +17,7 @@ package com.scottlogic.deg.orchestrator.cucumber.testframework.utils; import com.scottlogic.deg.common.output.GeneratedObject; -import com.scottlogic.deg.common.profile.ProfileFields; +import com.scottlogic.deg.common.profile.Fields; import com.scottlogic.deg.output.outputtarget.SingleDatasetOutputTarget; import com.scottlogic.deg.output.writer.DataSetWriter; @@ -36,15 +36,15 @@ public class InMemoryOutputTarget implements SingleDatasetOutputTarget { } @Override - public DataSetWriter openWriter(ProfileFields fields) { + public DataSetWriter openWriter(Fields fields) { return new DummyWriter(fields, testState.generatedObjects); } private class DummyWriter implements DataSetWriter { - private final ProfileFields fields; + private final Fields fields; private final List> listToAppendTo; - DummyWriter(ProfileFields fields, List> listToAppendTo) { + DummyWriter(Fields fields, List> listToAppendTo) { this.fields = fields; this.listToAppendTo = listToAppendTo; } @@ -56,7 +56,7 @@ public void writeRow(GeneratedObject row) { } Map values = new HashMap<>(); - fields.getExternalStream().forEach(field -> values.put(field.name, row.getFormattedValue(field))); + fields.getExternalStream().forEach(field -> values.put(field.getName(), row.getFormattedValue(field))); listToAppendTo.add(values); } diff --git a/orchestrator/src/test/java/com/scottlogic/deg/orchestrator/validator/ConfigValidatorTests.java b/orchestrator/src/test/java/com/scottlogic/deg/orchestrator/validator/ConfigValidatorTests.java index d0b612e2e..302dd85e5 100644 --- a/orchestrator/src/test/java/com/scottlogic/deg/orchestrator/validator/ConfigValidatorTests.java +++ b/orchestrator/src/test/java/com/scottlogic/deg/orchestrator/validator/ConfigValidatorTests.java @@ -18,7 +18,7 @@ import com.scottlogic.deg.common.ValidationException; import com.scottlogic.deg.common.util.FileUtils; -import com.scottlogic.deg.profile.reader.validation.ConfigValidator; +import com.scottlogic.deg.profile.reader.ConfigValidator; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; diff --git a/orchestrator/src/test/java/com/scottlogic/deg/orchestrator/validator/ProfileValidationTests.java b/orchestrator/src/test/java/com/scottlogic/deg/orchestrator/validator/ProfileValidationTests.java index 7124e6c9c..e46804549 100644 --- a/orchestrator/src/test/java/com/scottlogic/deg/orchestrator/validator/ProfileValidationTests.java +++ b/orchestrator/src/test/java/com/scottlogic/deg/orchestrator/validator/ProfileValidationTests.java @@ -16,8 +16,8 @@ package com.scottlogic.deg.orchestrator.validator; -import com.scottlogic.deg.profile.dtos.ProfileSchemaFileLoader; -import com.scottlogic.deg.profile.dtos.ProfileSchemaValidatorLeadPony; +import com.scottlogic.deg.profile.ProfileSchemaFileLoader; +import com.scottlogic.deg.profile.ProfileSchemaValidatorLeadPony; import org.junit.jupiter.api.DynamicTest; import org.junit.jupiter.api.TestFactory; diff --git a/orchestrator/src/test/java/com/scottlogic/deg/orchestrator/violate/violator/ProfileViolationTests.java b/orchestrator/src/test/java/com/scottlogic/deg/orchestrator/violate/violator/ProfileViolationTests.java index cc9dc9861..c5294c8f6 100644 --- a/orchestrator/src/test/java/com/scottlogic/deg/orchestrator/violate/violator/ProfileViolationTests.java +++ b/orchestrator/src/test/java/com/scottlogic/deg/orchestrator/violate/violator/ProfileViolationTests.java @@ -80,25 +80,25 @@ private static Stream allAtomicConstraints() { .collect(Collectors.toList())); return Stream.of( - Arguments.of(IsInSetConstraint.class, sampleSet), + Arguments.of(InSetConstraint.class, sampleSet), Arguments.of(IsNullConstraint.class, null), Arguments.of(MatchesStandardConstraint.class, StandardConstraintTypes.ISIN), Arguments.of(ContainsRegexConstraint.class, Pattern.compile("\\w+")), Arguments.of(MatchesRegexConstraint.class, Pattern.compile("\\d+")), - Arguments.of(IsStringLongerThanConstraint.class, HelixStringLength.create(10)), - Arguments.of(IsStringShorterThanConstraint.class, HelixStringLength.create(20)), - Arguments.of(StringHasLengthConstraint.class, HelixStringLength.create(15)), - - Arguments.of(IsAfterConstantDateTimeConstraint.class, HelixDateTime.create(sampleDate)), - Arguments.of(IsAfterOrEqualToConstantDateTimeConstraint.class, HelixDateTime.create(sampleDate.plusDays(1))), - Arguments.of(IsBeforeConstantDateTimeConstraint.class, HelixDateTime.create(sampleDate.minusDays(1))), - Arguments.of(IsBeforeOrEqualToConstantDateTimeConstraint.class, HelixDateTime.create(sampleDate.plusDays(2))), - - Arguments.of(IsGreaterThanConstantConstraint.class, HelixNumber.create(100)), - Arguments.of(IsGreaterThanOrEqualToConstantConstraint.class, HelixNumber.create(200)), - Arguments.of(IsLessThanConstantConstraint.class, HelixNumber.create(300)), - Arguments.of(IsLessThanOrEqualToConstantConstraint.class, HelixNumber.create(400)) + Arguments.of(LongerThanConstraint.class, HelixStringLength.create(10)), + Arguments.of(ShorterThanConstraint.class, HelixStringLength.create(20)), + Arguments.of(OfLengthConstraint.class, HelixStringLength.create(15)), + + Arguments.of(AfterConstraint.class, HelixDateTime.create(sampleDate)), + Arguments.of(AfterOrAtConstraint.class, HelixDateTime.create(sampleDate.plusDays(1))), + Arguments.of(BeforeConstraint.class, HelixDateTime.create(sampleDate.minusDays(1))), + Arguments.of(BeforeOrAtConstraint.class, HelixDateTime.create(sampleDate.plusDays(2))), + + Arguments.of(GreaterThanConstraint.class, HelixNumber.create(100)), + Arguments.of(GreaterThanOrEqualToConstraint.class, HelixNumber.create(200)), + Arguments.of(LessThanConstraint.class, HelixNumber.create(300)), + Arguments.of(LessThanOrEqualToConstraint.class, HelixNumber.create(400)) ); } @@ -237,7 +237,7 @@ public void violate_withFilteredConstraintType_producesViolatedProfile() throws .withGreaterThanConstraint(field1, 100) .build(); - constraintsToNotViolate.add(new ConstraintTypeViolationFilter(IsGreaterThanConstantConstraint.class)); + constraintsToNotViolate.add(new ConstraintTypeViolationFilter(GreaterThanConstraint.class)); TestProfiles testProfiles = createTestProfiles( "Input Profile", @@ -1046,9 +1046,9 @@ private Profile createViolatedProfile(String description, .map(h -> h.getRule().equals(rule) ? h.getViolatedRule() : h.getRule()) .collect(Collectors.toList()); - String processedDescription = description + " -- Violating: " + rule.getRuleInformation().getDescription(); + String processedDescription = description + " -- Violating: " + rule.getDescription(); - return new ViolatedProfile(rule, new ProfileFields(fields), newRuleList, processedDescription); + return new ViolatedProfile(rule, new Fields(fields), newRuleList, processedDescription); } private List getRulesFromPair(List pair) { diff --git a/orchestrator/src/test/java/com/scottlogic/deg/orchestrator/violate/violator/ProfileViolatorTests.java b/orchestrator/src/test/java/com/scottlogic/deg/orchestrator/violate/violator/ProfileViolatorTests.java index e5ac2e831..2c59cb367 100644 --- a/orchestrator/src/test/java/com/scottlogic/deg/orchestrator/violate/violator/ProfileViolatorTests.java +++ b/orchestrator/src/test/java/com/scottlogic/deg/orchestrator/violate/violator/ProfileViolatorTests.java @@ -18,13 +18,12 @@ import com.scottlogic.deg.common.profile.Field; import com.scottlogic.deg.common.profile.HelixNumber; -import com.scottlogic.deg.common.profile.ProfileFields; +import com.scottlogic.deg.common.profile.Fields; import com.scottlogic.deg.generator.profile.Profile; import com.scottlogic.deg.generator.profile.Rule; -import com.scottlogic.deg.generator.profile.RuleInformation; import com.scottlogic.deg.generator.profile.constraints.Constraint; -import com.scottlogic.deg.generator.profile.constraints.atomic.IsGreaterThanConstantConstraint; -import com.scottlogic.deg.generator.profile.constraints.atomic.IsLessThanConstantConstraint; +import com.scottlogic.deg.generator.profile.constraints.atomic.GreaterThanConstraint; +import com.scottlogic.deg.generator.profile.constraints.atomic.LessThanConstraint; import com.scottlogic.deg.orchestrator.violate.ViolatedProfile; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -88,7 +87,7 @@ public void violate_withSingleRuleProfile_returnsSingleViolatedProfile() throws Collections.singletonList( new ViolatedProfile( rule1, - new ProfileFields(Arrays.asList(fooField, barField)), + new Fields(Arrays.asList(fooField, barField)), Collections.singletonList(violatedRule1), "Input profile description -- Violating: Rule 1 description" ) @@ -125,13 +124,13 @@ public void violate_withMultipleRuleProfile_returnsMultipleViolatedProfile() thr Arrays.asList( new ViolatedProfile( rule1, - new ProfileFields(Arrays.asList(fooField, barField)), + new Fields(Arrays.asList(fooField, barField)), Arrays.asList(violatedRule1, rule2), "Input profile description -- Violating: Rule 1 description" ), new ViolatedProfile( rule2, - new ProfileFields(Arrays.asList(fooField, barField)), + new Fields(Arrays.asList(fooField, barField)), Arrays.asList(rule1, violatedRule2), "Input profile description -- Violating: Rule 2 description" ) @@ -147,31 +146,31 @@ public void violate_withMultipleRuleProfile_returnsMultipleViolatedProfile() thr private void initRules() { //Rule 1 consists of 2 constraints, "foo is greater than 100" and "bar is greater than 50" - RuleInformation ruleInformation1 = new RuleInformation("Rule 1 description"); + String ruleInformation1 = "Rule 1 description"; fooField = createField("foo"); barField = createField("bar"); - Constraint constraint1 = new IsGreaterThanConstantConstraint( + Constraint constraint1 = new GreaterThanConstraint( fooField, HelixNumber.create(100) ); - Constraint constraint2 = new IsGreaterThanConstantConstraint( + Constraint constraint2 = new GreaterThanConstraint( barField, HelixNumber.create(50) ); rule1 = new Rule(ruleInformation1, Arrays.asList(constraint1, constraint2)); //Violated Rule 1 consists of two constraints, "foo is less than to 101" and "bar is less than 51" - Constraint constraint3 = new IsLessThanConstantConstraint( + Constraint constraint3 = new LessThanConstraint( fooField, HelixNumber.create(101) ); - Constraint constraint4 = new IsLessThanConstantConstraint( + Constraint constraint4 = new LessThanConstraint( barField, HelixNumber.create(51) ); violatedRule1 = new Rule(ruleInformation1, Arrays.asList(constraint3, constraint4)); - RuleInformation ruleInformation2 = new RuleInformation("Rule 2 description"); + String ruleInformation2 = "Rule 2 description"; rule2 = new Rule(ruleInformation2, Arrays.asList(constraint1,constraint4)); violatedRule2 = new Rule(ruleInformation2, Arrays.asList(constraint2,constraint3)); } diff --git a/orchestrator/src/test/java/com/scottlogic/deg/orchestrator/violate/violator/RuleViolatorTests.java b/orchestrator/src/test/java/com/scottlogic/deg/orchestrator/violate/violator/RuleViolatorTests.java index e7478586d..6faa0efa4 100644 --- a/orchestrator/src/test/java/com/scottlogic/deg/orchestrator/violate/violator/RuleViolatorTests.java +++ b/orchestrator/src/test/java/com/scottlogic/deg/orchestrator/violate/violator/RuleViolatorTests.java @@ -19,10 +19,9 @@ import com.scottlogic.deg.common.profile.HelixNumber; import com.scottlogic.deg.common.profile.UnviolatableConstraintException; import com.scottlogic.deg.generator.profile.Rule; -import com.scottlogic.deg.generator.profile.RuleInformation; import com.scottlogic.deg.generator.profile.constraints.Constraint; import com.scottlogic.deg.generator.profile.constraints.atomic.AtomicConstraint; -import com.scottlogic.deg.generator.profile.constraints.atomic.IsLessThanConstantConstraint; +import com.scottlogic.deg.generator.profile.constraints.atomic.LessThanConstraint; import com.scottlogic.deg.generator.profile.constraints.atomic.ViolatedAtomicConstraint; import com.scottlogic.deg.generator.profile.constraints.grammatical.AndConstraint; import com.scottlogic.deg.generator.profile.constraints.grammatical.ConditionalConstraint; @@ -55,7 +54,7 @@ public class RuleViolatorTests { private AtomicConstraint atomicConstraint1; private AtomicConstraint atomicConstraint2; private AtomicConstraint atomicConstraint3; - private RuleInformation ruleInformation; + private String ruleInformation; @Mock private ViolationFilter mockFilter; @@ -70,10 +69,9 @@ public void commonTestSetup() { target = new RuleViolator(inputFilters); - atomicConstraint1 = new IsLessThanConstantConstraint(createField("foo"), HelixNumber.create(10)); - atomicConstraint2 = new IsLessThanConstantConstraint(createField("bar"), HelixNumber.create(20)); - atomicConstraint3 = new IsLessThanConstantConstraint(createField("foobar"), HelixNumber.create(30)); - ruleInformation = new RuleInformation(); + atomicConstraint1 = new LessThanConstraint(createField("foo"), HelixNumber.create(10)); + atomicConstraint2 = new LessThanConstraint(createField("bar"), HelixNumber.create(20)); + atomicConstraint3 = new LessThanConstraint(createField("foobar"), HelixNumber.create(30)); } /** diff --git a/orchestrator/src/test/java/com/scottlogic/deg/orchestrator/violation/ViolationFiltersProviderTest.java b/orchestrator/src/test/java/com/scottlogic/deg/orchestrator/violation/ViolationFiltersProviderTest.java index 80894656e..1041dc038 100644 --- a/orchestrator/src/test/java/com/scottlogic/deg/orchestrator/violation/ViolationFiltersProviderTest.java +++ b/orchestrator/src/test/java/com/scottlogic/deg/orchestrator/violation/ViolationFiltersProviderTest.java @@ -17,8 +17,8 @@ package com.scottlogic.deg.orchestrator.violation; import com.scottlogic.deg.common.profile.HelixStringLength; -import com.scottlogic.deg.generator.profile.constraints.atomic.IsStringShorterThanConstraint; -import com.scottlogic.deg.generator.profile.constraints.atomic.StringHasLengthConstraint; +import com.scottlogic.deg.generator.profile.constraints.atomic.ShorterThanConstraint; +import com.scottlogic.deg.generator.profile.constraints.atomic.OfLengthConstraint; import com.scottlogic.deg.generator.violations.filters.ConstraintTypeViolationFilter; import com.scottlogic.deg.generator.violations.filters.ViolationFilter; import com.scottlogic.deg.orchestrator.violate.AtomicConstraintTypeMapper; @@ -72,11 +72,11 @@ void hasLengthConstraintsToViolate_ReturnsOneFilter_ThatDoesNotAcceptHasLengthCo assertThat(filter.canViolate( - new StringHasLengthConstraint(null, HelixStringLength.create(2))), + new OfLengthConstraint(null, HelixStringLength.create(2))), is(false)); assertThat(filter.canViolate( - new IsStringShorterThanConstraint(null, HelixStringLength.create(5))), + new ShorterThanConstraint(null, HelixStringLength.create(5))), is(true)); } diff --git a/output/src/main/java/com/scottlogic/deg/output/outputtarget/FileOutputTarget.java b/output/src/main/java/com/scottlogic/deg/output/outputtarget/FileOutputTarget.java index 696b575f0..16fd9e95f 100644 --- a/output/src/main/java/com/scottlogic/deg/output/outputtarget/FileOutputTarget.java +++ b/output/src/main/java/com/scottlogic/deg/output/outputtarget/FileOutputTarget.java @@ -18,7 +18,7 @@ import com.google.inject.Inject; import com.google.inject.name.Named; -import com.scottlogic.deg.common.profile.ProfileFields; +import com.scottlogic.deg.common.profile.Fields; import com.scottlogic.deg.common.util.FileUtils; import com.scottlogic.deg.output.OutputPath; import com.scottlogic.deg.output.writer.DataSetWriter; @@ -47,7 +47,7 @@ public FileOutputTarget( } @Override - public DataSetWriter openWriter(ProfileFields fields) throws IOException { + public DataSetWriter openWriter(Fields fields) throws IOException { final OutputStream stream = new FileOutputStream( this.filePath.toFile(), false); diff --git a/output/src/main/java/com/scottlogic/deg/output/outputtarget/SingleDatasetOutputTarget.java b/output/src/main/java/com/scottlogic/deg/output/outputtarget/SingleDatasetOutputTarget.java index 914ccee6a..16695e460 100644 --- a/output/src/main/java/com/scottlogic/deg/output/outputtarget/SingleDatasetOutputTarget.java +++ b/output/src/main/java/com/scottlogic/deg/output/outputtarget/SingleDatasetOutputTarget.java @@ -16,12 +16,12 @@ package com.scottlogic.deg.output.outputtarget; -import com.scottlogic.deg.common.profile.ProfileFields; +import com.scottlogic.deg.common.profile.Fields; import com.scottlogic.deg.output.writer.DataSetWriter; import java.io.IOException; public interface SingleDatasetOutputTarget { - DataSetWriter openWriter(ProfileFields fields) throws IOException; + DataSetWriter openWriter(Fields fields) throws IOException; default void validate() throws OutputTargetValidationException, IOException {} } diff --git a/output/src/main/java/com/scottlogic/deg/output/outputtarget/StdoutOutputTarget.java b/output/src/main/java/com/scottlogic/deg/output/outputtarget/StdoutOutputTarget.java index 321aba7df..b835b85f1 100644 --- a/output/src/main/java/com/scottlogic/deg/output/outputtarget/StdoutOutputTarget.java +++ b/output/src/main/java/com/scottlogic/deg/output/outputtarget/StdoutOutputTarget.java @@ -17,7 +17,7 @@ package com.scottlogic.deg.output.outputtarget; import com.google.inject.Inject; -import com.scottlogic.deg.common.profile.ProfileFields; +import com.scottlogic.deg.common.profile.Fields; import com.scottlogic.deg.output.writer.DataSetWriter; import com.scottlogic.deg.output.writer.OutputWriterFactory; @@ -32,7 +32,7 @@ public StdoutOutputTarget(OutputWriterFactory formattingWriterFactory) { } @Override - public DataSetWriter openWriter(ProfileFields fields) throws IOException { + public DataSetWriter openWriter(Fields fields) throws IOException { return formattingWriterFactory.createWriter(System.out, fields); } } diff --git a/output/src/main/java/com/scottlogic/deg/output/writer/OutputWriterFactory.java b/output/src/main/java/com/scottlogic/deg/output/writer/OutputWriterFactory.java index a15cde5dc..6965f838e 100644 --- a/output/src/main/java/com/scottlogic/deg/output/writer/OutputWriterFactory.java +++ b/output/src/main/java/com/scottlogic/deg/output/writer/OutputWriterFactory.java @@ -16,8 +16,7 @@ package com.scottlogic.deg.output.writer; -import com.scottlogic.deg.common.profile.ProfileFields; -import com.scottlogic.deg.output.writer.DataSetWriter; +import com.scottlogic.deg.common.profile.Fields; import java.io.IOException; import java.io.OutputStream; @@ -27,7 +26,7 @@ public interface OutputWriterFactory { DataSetWriter createWriter( OutputStream stream, - ProfileFields profileFields) throws IOException; + Fields fields) throws IOException; Optional getFileExtensionWithoutDot(); } diff --git a/output/src/main/java/com/scottlogic/deg/output/writer/csv/CsvDataSetWriter.java b/output/src/main/java/com/scottlogic/deg/output/writer/csv/CsvDataSetWriter.java index 2b1939373..d26d19352 100644 --- a/output/src/main/java/com/scottlogic/deg/output/writer/csv/CsvDataSetWriter.java +++ b/output/src/main/java/com/scottlogic/deg/output/writer/csv/CsvDataSetWriter.java @@ -17,7 +17,7 @@ package com.scottlogic.deg.output.writer.csv; import com.scottlogic.deg.common.output.GeneratedObject; -import com.scottlogic.deg.common.profile.ProfileFields; +import com.scottlogic.deg.common.profile.Fields; import com.scottlogic.deg.output.writer.DataSetWriter; import org.apache.commons.csv.CSVFormat; import org.apache.commons.csv.CSVPrinter; @@ -37,20 +37,20 @@ class CsvDataSetWriter implements DataSetWriter { private static final CSVFormat writerFormat = CSVFormat.RFC4180; private final CSVPrinter csvPrinter; - private final ProfileFields fieldOrder; + private final Fields fieldOrder; - private CsvDataSetWriter(CSVPrinter csvPrinter, ProfileFields fieldOrder) { + private CsvDataSetWriter(CSVPrinter csvPrinter, Fields fieldOrder) { this.csvPrinter = csvPrinter; this.fieldOrder = fieldOrder; } - static DataSetWriter open(OutputStream stream, ProfileFields fields) throws IOException { + static DataSetWriter open(OutputStream stream, Fields fields) throws IOException { final Appendable outputStreamAsAppendable = new OutputStreamWriter(stream, StandardCharsets.UTF_8); CSVPrinter csvPrinter = writerFormat .withQuoteMode(QuoteMode.MINIMAL) .withHeader(fields.getExternalStream() - .map(f -> f.name) + .map(f -> f.getName()) .toArray(String[]::new)) .print(outputStreamAsAppendable); diff --git a/output/src/main/java/com/scottlogic/deg/output/writer/csv/CsvOutputWriterFactory.java b/output/src/main/java/com/scottlogic/deg/output/writer/csv/CsvOutputWriterFactory.java index 705d0371f..67eaf412e 100644 --- a/output/src/main/java/com/scottlogic/deg/output/writer/csv/CsvOutputWriterFactory.java +++ b/output/src/main/java/com/scottlogic/deg/output/writer/csv/CsvOutputWriterFactory.java @@ -16,7 +16,7 @@ package com.scottlogic.deg.output.writer.csv; -import com.scottlogic.deg.common.profile.ProfileFields; +import com.scottlogic.deg.common.profile.Fields; import com.scottlogic.deg.output.writer.DataSetWriter; import com.scottlogic.deg.output.writer.OutputWriterFactory; @@ -26,8 +26,8 @@ public class CsvOutputWriterFactory implements OutputWriterFactory { @Override - public DataSetWriter createWriter(OutputStream stream, ProfileFields profileFields) throws IOException { - return CsvDataSetWriter.open(stream, profileFields); + public DataSetWriter createWriter(OutputStream stream, Fields fields) throws IOException { + return CsvDataSetWriter.open(stream, fields); } @Override diff --git a/output/src/main/java/com/scottlogic/deg/output/writer/json/JsonDataSetWriter.java b/output/src/main/java/com/scottlogic/deg/output/writer/json/JsonDataSetWriter.java index dc28beec0..a6f578768 100644 --- a/output/src/main/java/com/scottlogic/deg/output/writer/json/JsonDataSetWriter.java +++ b/output/src/main/java/com/scottlogic/deg/output/writer/json/JsonDataSetWriter.java @@ -19,7 +19,7 @@ import com.fasterxml.jackson.databind.SequenceWriter; import com.scottlogic.deg.common.output.GeneratedObject; import com.scottlogic.deg.common.profile.Field; -import com.scottlogic.deg.common.profile.ProfileFields; +import com.scottlogic.deg.common.profile.Fields; import com.scottlogic.deg.output.writer.DataSetWriter; import java.io.IOException; @@ -34,9 +34,9 @@ class JsonDataSetWriter implements DataSetWriter { private static final DateTimeFormatter standardDateFormat = DateTimeFormatter.ISO_OFFSET_DATE_TIME; private final SequenceWriter writer; - private final ProfileFields fields; + private final Fields fields; - JsonDataSetWriter(SequenceWriter writer, ProfileFields fields) { + JsonDataSetWriter(SequenceWriter writer, Fields fields) { this.writer = writer; this.fields = fields; } diff --git a/output/src/main/java/com/scottlogic/deg/output/writer/json/JsonOutputWriterFactory.java b/output/src/main/java/com/scottlogic/deg/output/writer/json/JsonOutputWriterFactory.java index f9d5ea474..f596244c6 100644 --- a/output/src/main/java/com/scottlogic/deg/output/writer/json/JsonOutputWriterFactory.java +++ b/output/src/main/java/com/scottlogic/deg/output/writer/json/JsonOutputWriterFactory.java @@ -22,7 +22,7 @@ import com.fasterxml.jackson.databind.SequenceWriter; import com.google.inject.Inject; import com.google.inject.name.Named; -import com.scottlogic.deg.common.profile.ProfileFields; +import com.scottlogic.deg.common.profile.Fields; import com.scottlogic.deg.output.writer.DataSetWriter; import com.scottlogic.deg.output.writer.OutputWriterFactory; @@ -39,12 +39,12 @@ public JsonOutputWriterFactory(@Named("config:useNdJson") boolean useNdJson) { } @Override - public DataSetWriter createWriter(OutputStream stream, ProfileFields profileFields) throws IOException { + public DataSetWriter createWriter(OutputStream stream, Fields fields) throws IOException { ObjectWriter objectWriter = new ObjectMapper().writer(new DefaultPrettyPrinter(NEW_LINE_DELIMITER)); SequenceWriter writer = objectWriter.writeValues(stream); writer.init(!useNdJson); - return new JsonDataSetWriter(writer, profileFields); + return new JsonDataSetWriter(writer, fields); } @Override diff --git a/output/src/test/java/com/scottlogic/deg/output/writer/csv/CsvDataSetWriterTest.java b/output/src/test/java/com/scottlogic/deg/output/writer/csv/CsvDataSetWriterTest.java index 184b4fb08..6f78aa2ce 100644 --- a/output/src/test/java/com/scottlogic/deg/output/writer/csv/CsvDataSetWriterTest.java +++ b/output/src/test/java/com/scottlogic/deg/output/writer/csv/CsvDataSetWriterTest.java @@ -19,8 +19,8 @@ import com.scottlogic.deg.common.output.GeneratedObject; import com.scottlogic.deg.common.profile.Field; -import com.scottlogic.deg.common.profile.FieldType; -import com.scottlogic.deg.common.profile.ProfileFields; +import com.scottlogic.deg.common.profile.Fields; +import com.scottlogic.deg.common.profile.SpecificFieldType; import com.scottlogic.deg.output.writer.DataSetWriter; import org.junit.Assert; import org.junit.Test; @@ -42,10 +42,10 @@ public class CsvDataSetWriterTest { private ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); - private Field fieldOne = new Field("one", FieldType.STRING,false,null,false); - private Field fieldTwo = new Field("two", FieldType.STRING,false,null,false); + private Field fieldOne = new Field("one", SpecificFieldType.STRING,false,null,false, false); + private Field fieldTwo = new Field("two", SpecificFieldType.STRING,false,null,false, false); - private ProfileFields profileFields = new ProfileFields(new ArrayList<>(Arrays.asList( + private Fields fields = new Fields(new ArrayList<>(Arrays.asList( fieldOne, fieldTwo ))); @@ -58,7 +58,7 @@ public void open_createsCSVWriterThatCorrectlyOutputsCommasAndQuotes() { Mockito.when(row.getFormattedValue(fieldOne)).thenReturn(",,"); Mockito.when(row.getFormattedValue(fieldTwo)).thenReturn(",\""); try { - dataSetWriter = CsvDataSetWriter.open(outputStream, profileFields); + dataSetWriter = CsvDataSetWriter.open(outputStream, fields); dataSetWriter.writeRow(row); String output = outputStream.toString(StandardCharsets.UTF_8.toString()); Assert.assertEquals( diff --git a/output/src/test/java/com/scottlogic/deg/output/writer/csv/CsvOutputWriterFactoryTests.java b/output/src/test/java/com/scottlogic/deg/output/writer/csv/CsvOutputWriterFactoryTests.java index e8aeec4ef..a7916ef93 100644 --- a/output/src/test/java/com/scottlogic/deg/output/writer/csv/CsvOutputWriterFactoryTests.java +++ b/output/src/test/java/com/scottlogic/deg/output/writer/csv/CsvOutputWriterFactoryTests.java @@ -17,7 +17,7 @@ package com.scottlogic.deg.output.writer.csv; import com.scottlogic.deg.common.profile.FieldBuilder; -import com.scottlogic.deg.common.profile.ProfileFields; +import com.scottlogic.deg.common.profile.Fields; import com.scottlogic.deg.common.output.GeneratedObject; import com.scottlogic.deg.output.writer.DataSetWriter; import org.hamcrest.Matcher; @@ -98,7 +98,7 @@ void writeRow_withDateTimeGranularToAMillisecondAndNoFormat_shouldFormatDateUsin @Test void writeRow_withInternalFields_shouldNotWriteInternalFields() throws IOException { - ProfileFields fields = new ProfileFields( + Fields fields = new Fields( Arrays.asList( createField("External"), createInternalField("Internal") @@ -111,14 +111,14 @@ void writeRow_withInternalFields_shouldNotWriteInternalFields() throws IOExcepti ); } - private static ProfileFields fields(String ...names) { - return new ProfileFields( + private static Fields fields(String ...names) { + return new Fields( Arrays.stream(names) .map(FieldBuilder::createField) .collect(Collectors.toList())); } - private static void expectCsv(ProfileFields fields, Object value, Matcher matcher) throws IOException { + private static void expectCsv(Fields fields, Object value, Matcher matcher) throws IOException { // Act GeneratedObject mockGeneratedObject = mock(GeneratedObject.class); when(mockGeneratedObject.getFormattedValue(eq(fields.iterator().next()))).thenReturn(value); @@ -128,7 +128,7 @@ private static void expectCsv(ProfileFields fields, Object value, Matcher matcher) throws IOException { + private static void expectJson(Fields fields, boolean useNdJson, Matcher matcher) throws IOException { // Act GeneratedObject mockGeneratedObject = mock(GeneratedObject.class); when(mockGeneratedObject.getFormattedValue(eq(fields.iterator().next()))).thenReturn("my_value"); @@ -68,7 +68,7 @@ private static void expectJson(ProfileFields fields, boolean useNdJson, Matcher< Assert.assertThat(generateJson, matcher); } - private static String generateJson(ProfileFields fields, GeneratedObject generatedObject, boolean useNdJson) throws IOException { + private static String generateJson(Fields fields, GeneratedObject generatedObject, boolean useNdJson) throws IOException { ByteArrayOutputStream stream = new ByteArrayOutputStream(); try (DataSetWriter writer = new JsonOutputWriterFactory(useNdJson).createWriter(stream, fields)) { diff --git a/profile/build.gradle b/profile/build.gradle index 893396d36..2bbe010c3 100644 --- a/profile/build.gradle +++ b/profile/build.gradle @@ -17,7 +17,6 @@ /* * This file was generated by the Gradle "init" task. */ - dependencies { compile project(":common") compile project(":generator") diff --git a/profile/src/main/java/com/scottlogic/deg/profile/dtos/NoopProfileSchemaLoader.java b/profile/src/main/java/com/scottlogic/deg/profile/NoopProfileSchemaLoader.java similarity index 95% rename from profile/src/main/java/com/scottlogic/deg/profile/dtos/NoopProfileSchemaLoader.java rename to profile/src/main/java/com/scottlogic/deg/profile/NoopProfileSchemaLoader.java index 95feea6bd..4dc7960d1 100644 --- a/profile/src/main/java/com/scottlogic/deg/profile/dtos/NoopProfileSchemaLoader.java +++ b/profile/src/main/java/com/scottlogic/deg/profile/NoopProfileSchemaLoader.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.scottlogic.deg.profile.dtos; +package com.scottlogic.deg.profile; import java.io.File; import java.net.URL; diff --git a/profile/src/main/java/com/scottlogic/deg/profile/dtos/NoopVersionChecker.java b/profile/src/main/java/com/scottlogic/deg/profile/NoopVersionChecker.java similarity index 95% rename from profile/src/main/java/com/scottlogic/deg/profile/dtos/NoopVersionChecker.java rename to profile/src/main/java/com/scottlogic/deg/profile/NoopVersionChecker.java index ede706413..28315f3f8 100644 --- a/profile/src/main/java/com/scottlogic/deg/profile/dtos/NoopVersionChecker.java +++ b/profile/src/main/java/com/scottlogic/deg/profile/NoopVersionChecker.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.scottlogic.deg.profile.dtos; +package com.scottlogic.deg.profile; import java.io.IOException; import java.net.URL; diff --git a/profile/src/main/java/com/scottlogic/deg/profile/ProfileCommandBus.java b/profile/src/main/java/com/scottlogic/deg/profile/ProfileCommandBus.java new file mode 100644 index 000000000..205eb707e --- /dev/null +++ b/profile/src/main/java/com/scottlogic/deg/profile/ProfileCommandBus.java @@ -0,0 +1,25 @@ +package com.scottlogic.deg.profile; + +import com.google.inject.Inject; +import com.scottlogic.deg.common.commands.CommandBus; +import com.scottlogic.deg.profile.reader.FileReader; +import com.scottlogic.deg.profile.reader.commands.CreateConstraints; +import com.scottlogic.deg.profile.reader.commands.CreateFields; +import com.scottlogic.deg.profile.reader.commands.CreateProfile; +import com.scottlogic.deg.profile.reader.handlers.CreateConstraintsHandler; +import com.scottlogic.deg.profile.reader.handlers.CreateFieldsHandler; +import com.scottlogic.deg.profile.reader.handlers.CreateProfileHandler; +import com.scottlogic.deg.profile.reader.validators.CreateConstraintsValidator; +import com.scottlogic.deg.profile.reader.validators.CreateFieldsValidator; +import com.scottlogic.deg.profile.reader.validators.CreateProfileValidator; + +public class ProfileCommandBus extends CommandBus +{ + @Inject + public ProfileCommandBus(FileReader fileReader) + { + register(CreateProfile.class, new CreateProfileHandler(this, new CreateProfileValidator())); + register(CreateFields.class, new CreateFieldsHandler(new CreateFieldsValidator())); + register(CreateConstraints.class, new CreateConstraintsHandler(fileReader, new CreateConstraintsValidator())); + } +} diff --git a/profile/src/main/java/com/scottlogic/deg/profile/dtos/ProfileSchemaFileLoader.java b/profile/src/main/java/com/scottlogic/deg/profile/ProfileSchemaFileLoader.java similarity index 98% rename from profile/src/main/java/com/scottlogic/deg/profile/dtos/ProfileSchemaFileLoader.java rename to profile/src/main/java/com/scottlogic/deg/profile/ProfileSchemaFileLoader.java index f60e5cd6b..7bd36a8a6 100644 --- a/profile/src/main/java/com/scottlogic/deg/profile/dtos/ProfileSchemaFileLoader.java +++ b/profile/src/main/java/com/scottlogic/deg/profile/ProfileSchemaFileLoader.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.scottlogic.deg.profile.dtos; +package com.scottlogic.deg.profile; import com.scottlogic.deg.common.ValidationException; diff --git a/profile/src/main/java/com/scottlogic/deg/profile/dtos/ProfileSchemaLoader.java b/profile/src/main/java/com/scottlogic/deg/profile/ProfileSchemaLoader.java similarity index 96% rename from profile/src/main/java/com/scottlogic/deg/profile/dtos/ProfileSchemaLoader.java rename to profile/src/main/java/com/scottlogic/deg/profile/ProfileSchemaLoader.java index 0d05469f1..cb1129412 100644 --- a/profile/src/main/java/com/scottlogic/deg/profile/dtos/ProfileSchemaLoader.java +++ b/profile/src/main/java/com/scottlogic/deg/profile/ProfileSchemaLoader.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.scottlogic.deg.profile.dtos; +package com.scottlogic.deg.profile; import java.io.File; import java.net.URL; diff --git a/profile/src/main/java/com/scottlogic/deg/profile/dtos/ProfileSchemaValidator.java b/profile/src/main/java/com/scottlogic/deg/profile/ProfileSchemaValidator.java similarity index 96% rename from profile/src/main/java/com/scottlogic/deg/profile/dtos/ProfileSchemaValidator.java rename to profile/src/main/java/com/scottlogic/deg/profile/ProfileSchemaValidator.java index 191b179f7..d727f323f 100644 --- a/profile/src/main/java/com/scottlogic/deg/profile/dtos/ProfileSchemaValidator.java +++ b/profile/src/main/java/com/scottlogic/deg/profile/ProfileSchemaValidator.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.scottlogic.deg.profile.dtos; +package com.scottlogic.deg.profile; /** * Used to validate a DataHelix Profile JSON file. diff --git a/profile/src/main/java/com/scottlogic/deg/profile/dtos/ProfileSchemaValidatorLeadPony.java b/profile/src/main/java/com/scottlogic/deg/profile/ProfileSchemaValidatorLeadPony.java similarity index 99% rename from profile/src/main/java/com/scottlogic/deg/profile/dtos/ProfileSchemaValidatorLeadPony.java rename to profile/src/main/java/com/scottlogic/deg/profile/ProfileSchemaValidatorLeadPony.java index 2368188dc..e4d145280 100644 --- a/profile/src/main/java/com/scottlogic/deg/profile/dtos/ProfileSchemaValidatorLeadPony.java +++ b/profile/src/main/java/com/scottlogic/deg/profile/ProfileSchemaValidatorLeadPony.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.scottlogic.deg.profile.dtos; +package com.scottlogic.deg.profile; import com.scottlogic.deg.common.ValidationException; import org.leadpony.justify.api.JsonSchema; diff --git a/profile/src/main/java/com/scottlogic/deg/profile/dtos/ProfileSchemaValidatorMedeia.java b/profile/src/main/java/com/scottlogic/deg/profile/ProfileSchemaValidatorMedeia.java similarity index 98% rename from profile/src/main/java/com/scottlogic/deg/profile/dtos/ProfileSchemaValidatorMedeia.java rename to profile/src/main/java/com/scottlogic/deg/profile/ProfileSchemaValidatorMedeia.java index ec578522b..18c176e88 100644 --- a/profile/src/main/java/com/scottlogic/deg/profile/dtos/ProfileSchemaValidatorMedeia.java +++ b/profile/src/main/java/com/scottlogic/deg/profile/ProfileSchemaValidatorMedeia.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.scottlogic.deg.profile.dtos; +package com.scottlogic.deg.profile; import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.databind.ObjectMapper; diff --git a/profile/src/main/java/com/scottlogic/deg/profile/serialisation/SchemaVersionGetter.java b/profile/src/main/java/com/scottlogic/deg/profile/SchemaVersionGetter.java similarity index 93% rename from profile/src/main/java/com/scottlogic/deg/profile/serialisation/SchemaVersionGetter.java rename to profile/src/main/java/com/scottlogic/deg/profile/SchemaVersionGetter.java index f15abd4a5..2279e36f4 100644 --- a/profile/src/main/java/com/scottlogic/deg/profile/serialisation/SchemaVersionGetter.java +++ b/profile/src/main/java/com/scottlogic/deg/profile/SchemaVersionGetter.java @@ -13,9 +13,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.scottlogic.deg.profile.serialisation; +package com.scottlogic.deg.profile; import com.fasterxml.jackson.databind.ObjectMapper; +import com.scottlogic.deg.profile.dtos.SchemaDto; import java.io.IOException; import java.nio.charset.StandardCharsets; diff --git a/profile/src/main/java/com/scottlogic/deg/profile/dtos/SchemaVersionValidator.java b/profile/src/main/java/com/scottlogic/deg/profile/SchemaVersionValidator.java similarity index 94% rename from profile/src/main/java/com/scottlogic/deg/profile/dtos/SchemaVersionValidator.java rename to profile/src/main/java/com/scottlogic/deg/profile/SchemaVersionValidator.java index 8b273fc41..61e104b40 100644 --- a/profile/src/main/java/com/scottlogic/deg/profile/dtos/SchemaVersionValidator.java +++ b/profile/src/main/java/com/scottlogic/deg/profile/SchemaVersionValidator.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.scottlogic.deg.profile.dtos; +package com.scottlogic.deg.profile; import java.io.IOException; import java.net.URL; diff --git a/profile/src/main/java/com/scottlogic/deg/profile/dtos/SupportedVersionChecker.java b/profile/src/main/java/com/scottlogic/deg/profile/SupportedVersionChecker.java similarity index 95% rename from profile/src/main/java/com/scottlogic/deg/profile/dtos/SupportedVersionChecker.java rename to profile/src/main/java/com/scottlogic/deg/profile/SupportedVersionChecker.java index 52971916c..f2a5178af 100644 --- a/profile/src/main/java/com/scottlogic/deg/profile/dtos/SupportedVersionChecker.java +++ b/profile/src/main/java/com/scottlogic/deg/profile/SupportedVersionChecker.java @@ -13,12 +13,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.scottlogic.deg.profile.dtos; +package com.scottlogic.deg.profile; import com.google.inject.Inject; import com.scottlogic.deg.common.ValidationException; import com.scottlogic.deg.profile.guice.ProfileConfigSource; -import com.scottlogic.deg.profile.serialisation.SchemaVersionGetter; import java.io.IOException; import java.net.URL; diff --git a/profile/src/main/java/com/scottlogic/deg/profile/dtos/SupportedVersionsGetter.java b/profile/src/main/java/com/scottlogic/deg/profile/SupportedVersionsGetter.java similarity index 97% rename from profile/src/main/java/com/scottlogic/deg/profile/dtos/SupportedVersionsGetter.java rename to profile/src/main/java/com/scottlogic/deg/profile/SupportedVersionsGetter.java index e655b55f1..95c597dc0 100644 --- a/profile/src/main/java/com/scottlogic/deg/profile/dtos/SupportedVersionsGetter.java +++ b/profile/src/main/java/com/scottlogic/deg/profile/SupportedVersionsGetter.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.scottlogic.deg.profile.dtos; +package com.scottlogic.deg.profile; import org.leadpony.justify.api.JsonSchema; import org.leadpony.justify.api.JsonValidationService; diff --git a/profile/src/main/java/com/scottlogic/deg/profile/dtos/ProfileDTO.java b/profile/src/main/java/com/scottlogic/deg/profile/dtos/ProfileDTO.java index c0a97c664..1ec25671e 100644 --- a/profile/src/main/java/com/scottlogic/deg/profile/dtos/ProfileDTO.java +++ b/profile/src/main/java/com/scottlogic/deg/profile/dtos/ProfileDTO.java @@ -17,11 +17,11 @@ package com.scottlogic.deg.profile.dtos; import java.util.ArrayList; -import java.util.Collection; +import java.util.List; public class ProfileDTO { public String schemaVersion; - public Collection fields; - public Collection rules = new ArrayList<>(); + public List fields; + public List rules = new ArrayList<>(); public String description; } diff --git a/profile/src/main/java/com/scottlogic/deg/profile/dtos/RuleDTO.java b/profile/src/main/java/com/scottlogic/deg/profile/dtos/RuleDTO.java index 8a295a7ec..1a7579465 100644 --- a/profile/src/main/java/com/scottlogic/deg/profile/dtos/RuleDTO.java +++ b/profile/src/main/java/com/scottlogic/deg/profile/dtos/RuleDTO.java @@ -16,23 +16,14 @@ package com.scottlogic.deg.profile.dtos; -import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.fasterxml.jackson.annotation.JsonProperty; import com.scottlogic.deg.profile.dtos.constraints.ConstraintDTO; -import java.util.Collection; +import java.util.List; -@JsonDeserialize(using = RuleDeserializer.class) -@JsonSerialize(using = RuleSerializer.class) -public class RuleDTO { - public String rule; - public Collection constraints; - - public RuleDTO() { - } - - public RuleDTO(String rule, Collection constraints) { - this.rule = rule; - this.constraints = constraints; - } +public class RuleDTO +{ + @JsonProperty("rule") + public String description; + public List constraints; } diff --git a/profile/src/main/java/com/scottlogic/deg/profile/dtos/RuleDeserializer.java b/profile/src/main/java/com/scottlogic/deg/profile/dtos/RuleDeserializer.java deleted file mode 100644 index bb5ec2053..000000000 --- a/profile/src/main/java/com/scottlogic/deg/profile/dtos/RuleDeserializer.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright 2019 Scott Logic Ltd - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.scottlogic.deg.profile.dtos; - -import com.fasterxml.jackson.core.JsonParser; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.DeserializationContext; -import com.fasterxml.jackson.databind.JsonDeserializer; -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.scottlogic.deg.profile.dtos.constraints.ConstraintDTO; - -import java.io.IOException; -import java.util.*; - -public class RuleDeserializer extends JsonDeserializer { - - @Override - public RuleDTO deserialize( - JsonParser jsonParser, - DeserializationContext deserializationContext) - throws IOException { - - ObjectMapper mapper = (ObjectMapper) jsonParser.getCodec(); - - JsonNode node = mapper.readTree(jsonParser); - - RuleDTO dto = new RuleDTO(); - dto.rule = node.has("rule") - ? node.get("rule").asText() - : null; - - dto.constraints = node.has("constraints") - ? readConstraintsFromArrayNode(node.get("constraints"), mapper) - : Collections.emptySet(); - - return dto; - } - - private Collection readConstraintsFromArrayNode( - JsonNode node, - ObjectMapper mapper) - throws JsonProcessingException { - - List constraints = new ArrayList<>(); - - Iterator constraintNodeIterator = node.elements(); - - while (constraintNodeIterator.hasNext()) { - JsonNode constraintNode = constraintNodeIterator.next(); - - constraints.add( - mapper.treeToValue( - constraintNode, - ConstraintDTO.class)); - } - - return constraints; - } -} - diff --git a/profile/src/main/java/com/scottlogic/deg/profile/dtos/RuleSerializer.java b/profile/src/main/java/com/scottlogic/deg/profile/dtos/RuleSerializer.java deleted file mode 100644 index 3e2bae710..000000000 --- a/profile/src/main/java/com/scottlogic/deg/profile/dtos/RuleSerializer.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright 2019 Scott Logic Ltd - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.scottlogic.deg.profile.dtos; - -import com.fasterxml.jackson.core.JsonGenerator; -import com.fasterxml.jackson.databind.JsonSerializer; -import com.fasterxml.jackson.databind.SerializerProvider; -import com.scottlogic.deg.profile.dtos.constraints.ConstraintDTO; - -import java.io.IOException; - -public class RuleSerializer extends JsonSerializer { - @Override - public void serialize( - RuleDTO rule, - JsonGenerator jsonGenerator, - SerializerProvider serializerProvider) - throws IOException { - - jsonGenerator.writeStartObject(); - jsonGenerator.writeFieldName("rule"); - jsonGenerator.writeString(rule.rule); - jsonGenerator.writeArrayFieldStart("constraints"); - for (ConstraintDTO constraint : rule.constraints) { - jsonGenerator.writeObject(constraint); - } - jsonGenerator.writeEndArray(); - jsonGenerator.writeEndObject(); - } -} diff --git a/profile/src/main/java/com/scottlogic/deg/profile/serialisation/SchemaDto.java b/profile/src/main/java/com/scottlogic/deg/profile/dtos/SchemaDto.java similarity index 93% rename from profile/src/main/java/com/scottlogic/deg/profile/serialisation/SchemaDto.java rename to profile/src/main/java/com/scottlogic/deg/profile/dtos/SchemaDto.java index 9d7af6f67..e78ca117d 100644 --- a/profile/src/main/java/com/scottlogic/deg/profile/serialisation/SchemaDto.java +++ b/profile/src/main/java/com/scottlogic/deg/profile/dtos/SchemaDto.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.scottlogic.deg.profile.serialisation; +package com.scottlogic.deg.profile.dtos; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; diff --git a/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/ConstraintDTO.java b/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/ConstraintDTO.java index 081e2f683..9ab758078 100644 --- a/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/ConstraintDTO.java +++ b/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/ConstraintDTO.java @@ -18,14 +18,14 @@ import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import com.scottlogic.deg.profile.ConstraintDeserializer; +import com.scottlogic.deg.profile.serialisation.ConstraintDeserializer; import com.scottlogic.deg.profile.common.ConstraintType; @JsonDeserialize(using = ConstraintDeserializer.class) public abstract class ConstraintDTO { private final ConstraintType type; - ConstraintDTO(ConstraintType type) { + protected ConstraintDTO(ConstraintType type) { this.type = type; } diff --git a/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/InMapConstraintDTO.java b/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/InMapConstraintDTO.java index a63090ded..db68bd058 100644 --- a/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/InMapConstraintDTO.java +++ b/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/InMapConstraintDTO.java @@ -22,7 +22,9 @@ import com.scottlogic.deg.profile.common.ConstraintTypeJsonProperty; @JsonDeserialize(as = InMapConstraintDTO.class) -public class InMapConstraintDTO extends AtomicConstraintDTO { +public class InMapConstraintDTO extends ConstraintDTO +{ + public String field; @JsonProperty(ConstraintTypeJsonProperty.IN_MAP) public String file; public String key; diff --git a/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/AfterConstraintDTO.java b/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/AfterConstraintDTO.java similarity index 94% rename from profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/AfterConstraintDTO.java rename to profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/AfterConstraintDTO.java index ce1196438..e2d513e58 100644 --- a/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/AfterConstraintDTO.java +++ b/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/AfterConstraintDTO.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.scottlogic.deg.profile.dtos.constraints; +package com.scottlogic.deg.profile.dtos.constraints.atomic; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; diff --git a/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/AfterOrAtConstraintDTO.java b/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/AfterOrAtConstraintDTO.java similarity index 94% rename from profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/AfterOrAtConstraintDTO.java rename to profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/AfterOrAtConstraintDTO.java index 1c620835f..856fcdc53 100644 --- a/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/AfterOrAtConstraintDTO.java +++ b/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/AfterOrAtConstraintDTO.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.scottlogic.deg.profile.dtos.constraints; +package com.scottlogic.deg.profile.dtos.constraints.atomic; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; diff --git a/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/AtomicConstraintDTO.java b/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/AtomicConstraintDTO.java similarity index 80% rename from profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/AtomicConstraintDTO.java rename to profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/AtomicConstraintDTO.java index 03613e718..cb2f56cc2 100644 --- a/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/AtomicConstraintDTO.java +++ b/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/AtomicConstraintDTO.java @@ -14,11 +14,13 @@ * limitations under the License. */ -package com.scottlogic.deg.profile.dtos.constraints; +package com.scottlogic.deg.profile.dtos.constraints.atomic; import com.scottlogic.deg.profile.common.ConstraintType; +import com.scottlogic.deg.profile.dtos.constraints.ConstraintDTO; -public abstract class AtomicConstraintDTO extends ConstraintDTO { +public abstract class AtomicConstraintDTO extends ConstraintDTO +{ public String field; AtomicConstraintDTO(ConstraintType type) { diff --git a/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/BeforeConstraintDTO.java b/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/BeforeConstraintDTO.java similarity index 94% rename from profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/BeforeConstraintDTO.java rename to profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/BeforeConstraintDTO.java index a9ffddb75..0b8300823 100644 --- a/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/BeforeConstraintDTO.java +++ b/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/BeforeConstraintDTO.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.scottlogic.deg.profile.dtos.constraints; +package com.scottlogic.deg.profile.dtos.constraints.atomic; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; diff --git a/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/BeforeOrAtConstraintDTO.java b/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/BeforeOrAtConstraintDTO.java similarity index 95% rename from profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/BeforeOrAtConstraintDTO.java rename to profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/BeforeOrAtConstraintDTO.java index aad0790bb..348038338 100644 --- a/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/BeforeOrAtConstraintDTO.java +++ b/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/BeforeOrAtConstraintDTO.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.scottlogic.deg.profile.dtos.constraints; +package com.scottlogic.deg.profile.dtos.constraints.atomic; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; diff --git a/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/ContainsRegexConstraintDTO.java b/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/ContainsRegexConstraintDTO.java similarity index 95% rename from profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/ContainsRegexConstraintDTO.java rename to profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/ContainsRegexConstraintDTO.java index 7ff00426d..78b13945f 100644 --- a/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/ContainsRegexConstraintDTO.java +++ b/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/ContainsRegexConstraintDTO.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.scottlogic.deg.profile.dtos.constraints; +package com.scottlogic.deg.profile.dtos.constraints.atomic; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; diff --git a/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/EqualToConstraintDTO.java b/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/EqualToConstraintDTO.java similarity index 94% rename from profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/EqualToConstraintDTO.java rename to profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/EqualToConstraintDTO.java index e74da1d83..01559418c 100644 --- a/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/EqualToConstraintDTO.java +++ b/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/EqualToConstraintDTO.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.scottlogic.deg.profile.dtos.constraints; +package com.scottlogic.deg.profile.dtos.constraints.atomic; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; diff --git a/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/GranularToConstraintDTO.java b/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/GranularToConstraintDTO.java similarity index 95% rename from profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/GranularToConstraintDTO.java rename to profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/GranularToConstraintDTO.java index c9944641c..688bf509e 100644 --- a/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/GranularToConstraintDTO.java +++ b/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/GranularToConstraintDTO.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.scottlogic.deg.profile.dtos.constraints; +package com.scottlogic.deg.profile.dtos.constraints.atomic; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; diff --git a/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/GreaterThanConstraintDTO.java b/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/GreaterThanConstraintDTO.java similarity index 95% rename from profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/GreaterThanConstraintDTO.java rename to profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/GreaterThanConstraintDTO.java index 4d63f397d..fc8922a62 100644 --- a/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/GreaterThanConstraintDTO.java +++ b/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/GreaterThanConstraintDTO.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.scottlogic.deg.profile.dtos.constraints; +package com.scottlogic.deg.profile.dtos.constraints.atomic; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; diff --git a/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/GreaterThanOrEqualToConstraintDTO.java b/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/GreaterThanOrEqualToConstraintDTO.java similarity index 95% rename from profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/GreaterThanOrEqualToConstraintDTO.java rename to profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/GreaterThanOrEqualToConstraintDTO.java index 307324b1a..f22f80b62 100644 --- a/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/GreaterThanOrEqualToConstraintDTO.java +++ b/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/GreaterThanOrEqualToConstraintDTO.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.scottlogic.deg.profile.dtos.constraints; +package com.scottlogic.deg.profile.dtos.constraints.atomic; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; diff --git a/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/InSetConstraintDTO.java b/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/InSetConstraintDTO.java similarity index 93% rename from profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/InSetConstraintDTO.java rename to profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/InSetConstraintDTO.java index 7c7d55de3..103c7f284 100644 --- a/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/InSetConstraintDTO.java +++ b/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/InSetConstraintDTO.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.scottlogic.deg.profile.dtos.constraints; +package com.scottlogic.deg.profile.dtos.constraints.atomic; import com.scottlogic.deg.profile.common.ConstraintType; diff --git a/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/InSetFromFileConstraintDTO.java b/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/InSetFromFileConstraintDTO.java similarity index 94% rename from profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/InSetFromFileConstraintDTO.java rename to profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/InSetFromFileConstraintDTO.java index 1eccdb358..0a1e14731 100644 --- a/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/InSetFromFileConstraintDTO.java +++ b/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/InSetFromFileConstraintDTO.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.scottlogic.deg.profile.dtos.constraints; +package com.scottlogic.deg.profile.dtos.constraints.atomic; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; diff --git a/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/InSetOfValuesConstraintDTO.java b/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/InSetOfValuesConstraintDTO.java similarity index 94% rename from profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/InSetOfValuesConstraintDTO.java rename to profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/InSetOfValuesConstraintDTO.java index e5fbb6520..a15cabb17 100644 --- a/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/InSetOfValuesConstraintDTO.java +++ b/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/InSetOfValuesConstraintDTO.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.scottlogic.deg.profile.dtos.constraints; +package com.scottlogic.deg.profile.dtos.constraints.atomic; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; diff --git a/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/NullConstraintDTO.java b/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/IsNullConstraintDTO.java similarity index 82% rename from profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/NullConstraintDTO.java rename to profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/IsNullConstraintDTO.java index 472f984b1..aecf633d2 100644 --- a/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/NullConstraintDTO.java +++ b/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/IsNullConstraintDTO.java @@ -14,19 +14,19 @@ * limitations under the License. */ -package com.scottlogic.deg.profile.dtos.constraints; +package com.scottlogic.deg.profile.dtos.constraints.atomic; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import com.scottlogic.deg.profile.common.ConstraintType; import com.scottlogic.deg.profile.common.ConstraintTypeJsonProperty; -@JsonDeserialize(as = NullConstraintDTO.class) -public class NullConstraintDTO extends AtomicConstraintDTO { +@JsonDeserialize(as = IsNullConstraintDTO.class) +public class IsNullConstraintDTO extends AtomicConstraintDTO { @JsonProperty(ConstraintTypeJsonProperty.IS_NULL) public boolean isNull; - public NullConstraintDTO() { + public IsNullConstraintDTO() { super(ConstraintType.IS_NULL); } } diff --git a/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/LessThanConstraintDTO.java b/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/LessThanConstraintDTO.java similarity index 94% rename from profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/LessThanConstraintDTO.java rename to profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/LessThanConstraintDTO.java index 982e884f0..50a15dd62 100644 --- a/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/LessThanConstraintDTO.java +++ b/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/LessThanConstraintDTO.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.scottlogic.deg.profile.dtos.constraints; +package com.scottlogic.deg.profile.dtos.constraints.atomic; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; diff --git a/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/LessThanOrEqualToConstraintDTO.java b/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/LessThanOrEqualToConstraintDTO.java similarity index 95% rename from profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/LessThanOrEqualToConstraintDTO.java rename to profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/LessThanOrEqualToConstraintDTO.java index b2def2074..22a77a3dc 100644 --- a/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/LessThanOrEqualToConstraintDTO.java +++ b/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/LessThanOrEqualToConstraintDTO.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.scottlogic.deg.profile.dtos.constraints; +package com.scottlogic.deg.profile.dtos.constraints.atomic; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; diff --git a/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/LongerThanConstraintDTO.java b/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/LongerThanConstraintDTO.java similarity index 94% rename from profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/LongerThanConstraintDTO.java rename to profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/LongerThanConstraintDTO.java index f51d87279..521879fca 100644 --- a/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/LongerThanConstraintDTO.java +++ b/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/LongerThanConstraintDTO.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.scottlogic.deg.profile.dtos.constraints; +package com.scottlogic.deg.profile.dtos.constraints.atomic; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; diff --git a/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/MatchesRegexConstraintDTO.java b/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/MatchesRegexConstraintDTO.java similarity index 95% rename from profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/MatchesRegexConstraintDTO.java rename to profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/MatchesRegexConstraintDTO.java index 0b44fd07d..232f08729 100644 --- a/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/MatchesRegexConstraintDTO.java +++ b/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/MatchesRegexConstraintDTO.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.scottlogic.deg.profile.dtos.constraints; +package com.scottlogic.deg.profile.dtos.constraints.atomic; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; diff --git a/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/OfLengthConstraintDTO.java b/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/OfLengthConstraintDTO.java similarity index 94% rename from profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/OfLengthConstraintDTO.java rename to profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/OfLengthConstraintDTO.java index 1877da004..b48ae6cc6 100644 --- a/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/OfLengthConstraintDTO.java +++ b/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/OfLengthConstraintDTO.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.scottlogic.deg.profile.dtos.constraints; +package com.scottlogic.deg.profile.dtos.constraints.atomic; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; diff --git a/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/ShorterThanConstraintDTO.java b/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/ShorterThanConstraintDTO.java similarity index 95% rename from profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/ShorterThanConstraintDTO.java rename to profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/ShorterThanConstraintDTO.java index 0aafc43f3..1a0718350 100644 --- a/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/ShorterThanConstraintDTO.java +++ b/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/ShorterThanConstraintDTO.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.scottlogic.deg.profile.dtos.constraints; +package com.scottlogic.deg.profile.dtos.constraints.atomic; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; diff --git a/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/AllOfConstraintDTO.java b/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/grammatical/AllOfConstraintDTO.java similarity index 79% rename from profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/AllOfConstraintDTO.java rename to profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/grammatical/AllOfConstraintDTO.java index af4960c7b..405d96570 100644 --- a/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/AllOfConstraintDTO.java +++ b/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/grammatical/AllOfConstraintDTO.java @@ -14,19 +14,21 @@ * limitations under the License. */ -package com.scottlogic.deg.profile.dtos.constraints; +package com.scottlogic.deg.profile.dtos.constraints.grammatical; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import com.scottlogic.deg.profile.common.ConstraintType; import com.scottlogic.deg.profile.common.ConstraintTypeJsonProperty; +import com.scottlogic.deg.profile.dtos.constraints.ConstraintDTO; -import java.util.Collection; +import java.util.List; @JsonDeserialize(as = AllOfConstraintDTO.class) -public class AllOfConstraintDTO extends ConstraintDTO { +public class AllOfConstraintDTO extends GrammaticalConstraintDTO +{ @JsonProperty(ConstraintTypeJsonProperty.ALL_OF) - public Collection constraints; + public List constraints; public AllOfConstraintDTO() { super(ConstraintType.ALL_OF); diff --git a/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/AnyOfConstraintDTO.java b/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/grammatical/AnyOfConstraintDTO.java similarity index 79% rename from profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/AnyOfConstraintDTO.java rename to profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/grammatical/AnyOfConstraintDTO.java index 96de2d292..a8433bd35 100644 --- a/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/AnyOfConstraintDTO.java +++ b/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/grammatical/AnyOfConstraintDTO.java @@ -14,19 +14,21 @@ * limitations under the License. */ -package com.scottlogic.deg.profile.dtos.constraints; +package com.scottlogic.deg.profile.dtos.constraints.grammatical; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import com.scottlogic.deg.profile.common.ConstraintType; import com.scottlogic.deg.profile.common.ConstraintTypeJsonProperty; +import com.scottlogic.deg.profile.dtos.constraints.ConstraintDTO; -import java.util.Collection; +import java.util.List; @JsonDeserialize(as = AnyOfConstraintDTO.class) -public class AnyOfConstraintDTO extends ConstraintDTO { +public class AnyOfConstraintDTO extends GrammaticalConstraintDTO +{ @JsonProperty(ConstraintTypeJsonProperty.ANY_OF) - public Collection constraints; + public List constraints; public AnyOfConstraintDTO() { super(ConstraintType.ANY_OF); diff --git a/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/IfConstraintDTO.java b/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/grammatical/ConditionalConstraintDTO.java similarity index 79% rename from profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/IfConstraintDTO.java rename to profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/grammatical/ConditionalConstraintDTO.java index cf34d72e2..d6b4e0bd5 100644 --- a/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/IfConstraintDTO.java +++ b/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/grammatical/ConditionalConstraintDTO.java @@ -14,15 +14,17 @@ * limitations under the License. */ -package com.scottlogic.deg.profile.dtos.constraints; +package com.scottlogic.deg.profile.dtos.constraints.grammatical; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import com.scottlogic.deg.profile.common.ConstraintType; import com.scottlogic.deg.profile.common.ConstraintTypeJsonProperty; +import com.scottlogic.deg.profile.dtos.constraints.ConstraintDTO; -@JsonDeserialize(as = IfConstraintDTO.class) -public class IfConstraintDTO extends ConstraintDTO { +@JsonDeserialize(as = ConditionalConstraintDTO.class) +public class ConditionalConstraintDTO extends GrammaticalConstraintDTO +{ @JsonProperty(ConstraintTypeJsonProperty.IF) public ConstraintDTO ifConstraint; @JsonProperty(ConstraintTypeJsonProperty.THEN) @@ -30,7 +32,7 @@ public class IfConstraintDTO extends ConstraintDTO { @JsonProperty(ConstraintTypeJsonProperty.ELSE) public ConstraintDTO elseConstraint; - public IfConstraintDTO() { + public ConditionalConstraintDTO() { super(ConstraintType.IF); } } diff --git a/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/grammatical/GrammaticalConstraintDTO.java b/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/grammatical/GrammaticalConstraintDTO.java new file mode 100644 index 000000000..40fe283ec --- /dev/null +++ b/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/grammatical/GrammaticalConstraintDTO.java @@ -0,0 +1,28 @@ +/* + * Copyright 2019 Scott Logic Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.scottlogic.deg.profile.dtos.constraints.grammatical; + +import com.scottlogic.deg.profile.common.ConstraintType; +import com.scottlogic.deg.profile.dtos.constraints.ConstraintDTO; + +public abstract class GrammaticalConstraintDTO extends ConstraintDTO +{ + GrammaticalConstraintDTO(ConstraintType type) + { + super(type); + } +} diff --git a/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/AfterFieldConstraintDTO.java b/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/relations/AfterFieldConstraintDTO.java similarity index 95% rename from profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/AfterFieldConstraintDTO.java rename to profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/relations/AfterFieldConstraintDTO.java index 9d4082270..664b5b258 100644 --- a/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/AfterFieldConstraintDTO.java +++ b/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/relations/AfterFieldConstraintDTO.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.scottlogic.deg.profile.dtos.constraints; +package com.scottlogic.deg.profile.dtos.constraints.relations; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; diff --git a/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/AfterOrAtFieldConstraintDTO.java b/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/relations/AfterOrAtFieldConstraintDTO.java similarity index 95% rename from profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/AfterOrAtFieldConstraintDTO.java rename to profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/relations/AfterOrAtFieldConstraintDTO.java index 9195c60fd..7b90bb43a 100644 --- a/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/AfterOrAtFieldConstraintDTO.java +++ b/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/relations/AfterOrAtFieldConstraintDTO.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.scottlogic.deg.profile.dtos.constraints; +package com.scottlogic.deg.profile.dtos.constraints.relations; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; diff --git a/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/BeforeFieldConstraintDTO.java b/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/relations/BeforeFieldConstraintDTO.java similarity index 95% rename from profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/BeforeFieldConstraintDTO.java rename to profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/relations/BeforeFieldConstraintDTO.java index 06f476436..cd148340f 100644 --- a/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/BeforeFieldConstraintDTO.java +++ b/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/relations/BeforeFieldConstraintDTO.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.scottlogic.deg.profile.dtos.constraints; +package com.scottlogic.deg.profile.dtos.constraints.relations; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; diff --git a/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/BeforeOrAtFieldConstraintDTO.java b/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/relations/BeforeOrAtFieldConstraintDTO.java similarity index 95% rename from profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/BeforeOrAtFieldConstraintDTO.java rename to profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/relations/BeforeOrAtFieldConstraintDTO.java index 7f0cc68a4..24f1f4ab2 100644 --- a/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/BeforeOrAtFieldConstraintDTO.java +++ b/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/relations/BeforeOrAtFieldConstraintDTO.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.scottlogic.deg.profile.dtos.constraints; +package com.scottlogic.deg.profile.dtos.constraints.relations; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; diff --git a/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/EqualToFieldConstraintDTO.java b/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/relations/EqualToFieldConstraintDTO.java similarity index 95% rename from profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/EqualToFieldConstraintDTO.java rename to profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/relations/EqualToFieldConstraintDTO.java index b9b017c93..deeda8874 100644 --- a/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/EqualToFieldConstraintDTO.java +++ b/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/relations/EqualToFieldConstraintDTO.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.scottlogic.deg.profile.dtos.constraints; +package com.scottlogic.deg.profile.dtos.constraints.relations; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; diff --git a/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/GreaterThanFieldConstraintDTO.java b/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/relations/GreaterThanFieldConstraintDTO.java similarity index 95% rename from profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/GreaterThanFieldConstraintDTO.java rename to profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/relations/GreaterThanFieldConstraintDTO.java index 840222409..543c14d11 100644 --- a/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/GreaterThanFieldConstraintDTO.java +++ b/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/relations/GreaterThanFieldConstraintDTO.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.scottlogic.deg.profile.dtos.constraints; +package com.scottlogic.deg.profile.dtos.constraints.relations; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; diff --git a/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/GreaterThanOrEqualToFieldConstraintDTO.java b/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/relations/GreaterThanOrEqualToFieldConstraintDTO.java similarity index 95% rename from profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/GreaterThanOrEqualToFieldConstraintDTO.java rename to profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/relations/GreaterThanOrEqualToFieldConstraintDTO.java index 22ed68840..df25dbdec 100644 --- a/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/GreaterThanOrEqualToFieldConstraintDTO.java +++ b/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/relations/GreaterThanOrEqualToFieldConstraintDTO.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.scottlogic.deg.profile.dtos.constraints; +package com.scottlogic.deg.profile.dtos.constraints.relations; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; diff --git a/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/LessThanFieldConstraintDTO.java b/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/relations/LessThanFieldConstraintDTO.java similarity index 95% rename from profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/LessThanFieldConstraintDTO.java rename to profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/relations/LessThanFieldConstraintDTO.java index 3b3f425d3..92c23ae33 100644 --- a/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/LessThanFieldConstraintDTO.java +++ b/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/relations/LessThanFieldConstraintDTO.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.scottlogic.deg.profile.dtos.constraints; +package com.scottlogic.deg.profile.dtos.constraints.relations; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; diff --git a/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/LessThanOrEqualToFieldConstraintDTO.java b/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/relations/LessThanOrEqualToFieldConstraintDTO.java similarity index 95% rename from profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/LessThanOrEqualToFieldConstraintDTO.java rename to profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/relations/LessThanOrEqualToFieldConstraintDTO.java index 4e8c177cf..2a13c7fb5 100644 --- a/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/LessThanOrEqualToFieldConstraintDTO.java +++ b/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/relations/LessThanOrEqualToFieldConstraintDTO.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.scottlogic.deg.profile.dtos.constraints; +package com.scottlogic.deg.profile.dtos.constraints.relations; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; diff --git a/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/RelationalConstraintDTO.java b/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/relations/RelationalConstraintDTO.java similarity index 78% rename from profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/RelationalConstraintDTO.java rename to profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/relations/RelationalConstraintDTO.java index 99d331452..1d2055ad2 100644 --- a/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/RelationalConstraintDTO.java +++ b/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/relations/RelationalConstraintDTO.java @@ -14,11 +14,14 @@ * limitations under the License. */ -package com.scottlogic.deg.profile.dtos.constraints; +package com.scottlogic.deg.profile.dtos.constraints.relations; import com.scottlogic.deg.profile.common.ConstraintType; +import com.scottlogic.deg.profile.dtos.constraints.ConstraintDTO; -public abstract class RelationalConstraintDTO extends AtomicConstraintDTO { +public abstract class RelationalConstraintDTO extends ConstraintDTO +{ + public String field; public int offset; public String offsetUnit; diff --git a/profile/src/main/java/com/scottlogic/deg/profile/guice/ProfileModule.java b/profile/src/main/java/com/scottlogic/deg/profile/guice/ProfileModule.java index b35ce8a09..19000d562 100644 --- a/profile/src/main/java/com/scottlogic/deg/profile/guice/ProfileModule.java +++ b/profile/src/main/java/com/scottlogic/deg/profile/guice/ProfileModule.java @@ -17,10 +17,18 @@ package com.scottlogic.deg.profile.guice; import com.google.inject.AbstractModule; +import com.google.inject.Key; +import com.google.inject.TypeLiteral; import com.google.inject.name.Names; -import com.scottlogic.deg.profile.dtos.*; +import com.scottlogic.deg.common.commands.CommandBus; +import com.scottlogic.deg.common.validators.Validator; +import com.scottlogic.deg.profile.*; +import com.scottlogic.deg.profile.reader.commands.CreateFields; +import com.scottlogic.deg.profile.reader.commands.CreateProfile; import com.scottlogic.deg.profile.reader.JsonProfileReader; import com.scottlogic.deg.profile.reader.ProfileReader; +import com.scottlogic.deg.profile.reader.validators.CreateFieldsValidator; +import com.scottlogic.deg.profile.reader.validators.CreateProfileValidator; import java.io.File; @@ -28,7 +36,8 @@ public class ProfileModule extends AbstractModule { private final ProfileConfigSource profileConfigSource; - public ProfileModule(ProfileConfigSource profileConfigSource) { + public ProfileModule(ProfileConfigSource profileConfigSource) + { this.profileConfigSource = profileConfigSource; } @@ -36,11 +45,9 @@ public ProfileModule(ProfileConfigSource profileConfigSource) { protected void configure() { // Bind command line to correct implementation bind(ProfileConfigSource.class).toInstance(profileConfigSource); - bind(ProfileSchemaValidator.class).to(ProfileSchemaValidatorLeadPony.class); bind(ProfileSchemaLoader.class).toProvider(ProfileSchemaLoaderProvider.class); bind(SchemaVersionValidator.class).to(SupportedVersionChecker.class); - bind(ProfileReader.class).to(JsonProfileReader.class); bind(File.class) @@ -49,5 +56,10 @@ protected void configure() { bind(String.class) .annotatedWith(Names.named("config:filePath")) .toInstance(profileConfigSource.fromFilePath()); + + bind(Key.get(new TypeLiteral>(){})).to(CreateFieldsValidator.class); + bind(Key.get(new TypeLiteral>(){})).to(CreateProfileValidator.class); + bind(CommandBus.class).to(ProfileCommandBus.class); + } } diff --git a/profile/src/main/java/com/scottlogic/deg/profile/guice/ProfileSchemaLoaderProvider.java b/profile/src/main/java/com/scottlogic/deg/profile/guice/ProfileSchemaLoaderProvider.java index 1bcd35c74..016838b00 100644 --- a/profile/src/main/java/com/scottlogic/deg/profile/guice/ProfileSchemaLoaderProvider.java +++ b/profile/src/main/java/com/scottlogic/deg/profile/guice/ProfileSchemaLoaderProvider.java @@ -18,7 +18,10 @@ import com.google.inject.Inject; import com.google.inject.Provider; -import com.scottlogic.deg.profile.dtos.*; +import com.scottlogic.deg.profile.NoopProfileSchemaLoader; +import com.scottlogic.deg.profile.ProfileSchemaFileLoader; +import com.scottlogic.deg.profile.ProfileSchemaLoader; +import com.scottlogic.deg.profile.ProfileSchemaValidator; public class ProfileSchemaLoaderProvider implements Provider { diff --git a/profile/src/main/java/com/scottlogic/deg/profile/reader/AtomicConstraintFactory/AtomicConstraintFactory.java b/profile/src/main/java/com/scottlogic/deg/profile/reader/AtomicConstraintFactory/AtomicConstraintFactory.java deleted file mode 100644 index c1821d8e7..000000000 --- a/profile/src/main/java/com/scottlogic/deg/profile/reader/AtomicConstraintFactory/AtomicConstraintFactory.java +++ /dev/null @@ -1,171 +0,0 @@ -package com.scottlogic.deg.profile.reader.AtomicConstraintFactory; - -import com.scottlogic.deg.common.profile.Field; -import com.scottlogic.deg.common.profile.HelixDateTime; -import com.scottlogic.deg.common.profile.ProfileFields; -import com.scottlogic.deg.common.util.NumberUtils; -import com.scottlogic.deg.generator.fieldspecs.relations.InMapRelation; -import com.scottlogic.deg.generator.fieldspecs.whitelist.DistributedList; -import com.scottlogic.deg.generator.profile.constraints.Constraint; -import com.scottlogic.deg.generator.profile.constraints.atomic.EqualToConstraint; -import com.scottlogic.deg.generator.profile.constraints.atomic.IsInSetConstraint; -import com.scottlogic.deg.generator.profile.constraints.atomic.IsNullConstraint; -import com.scottlogic.deg.profile.dtos.constraints.*; -import com.scottlogic.deg.profile.reader.FileReader; -import com.scottlogic.deg.profile.reader.InvalidProfileException; -import org.jetbrains.annotations.Nullable; - -import java.util.stream.Collectors; - -abstract class AtomicConstraintFactory { - - private final FileReader fileReader; - - AtomicConstraintFactory(FileReader fileReader) { - this.fileReader = fileReader; - } - - Constraint readAtomicConstraintDto(AtomicConstraintDTO dto, ProfileFields profileFields) { - Field field = profileFields.getByName(dto.field); - switch (dto.getType()) { - case EQUAL_TO: - return getEqualToConstraint((EqualToConstraintDTO) dto, field); - case IN_SET: - return getInSetConstraint((InSetConstraintDTO) dto, field); - case IN_MAP: - return getInMapConstraint((InMapConstraintDTO) dto, profileFields, field); - case MATCHES_REGEX: - return getMatchesRegexConstraint((MatchesRegexConstraintDTO) dto, field); - case CONTAINS_REGEX: - return getContainsRegexConstraint((ContainsRegexConstraintDTO) dto, field); - case OF_LENGTH: - return getOfLengthConstraint((OfLengthConstraintDTO) dto, field); - case SHORTER_THAN: - return getShorterThanConstraint((ShorterThanConstraintDTO) dto, field); - case LONGER_THAN: - return getIsLongerThanConstraint((LongerThanConstraintDTO) dto, field); - case GREATER_THAN: - return getIsGreaterThanConstraint((GreaterThanConstraintDTO) dto, field); - case GREATER_THAN_OR_EQUAL_TO: - return getIsGreaterThanOrEqualToConstraint((GreaterThanOrEqualToConstraintDTO) dto, field); - case LESS_THAN: - return getIsLessThanConstraint((LessThanConstraintDTO) dto, field); - case LESS_THAN_OR_EQUAL_TO: - return getLessThanOrEqualToConstraint((LessThanOrEqualToConstraintDTO) dto, field); - case AFTER: - return getAfterConstraint((AfterConstraintDTO) dto, field); - case AFTER_OR_AT: - return getAfterOrAtConstraint((AfterOrAtConstraintDTO) dto, field); - case BEFORE: - return getBeforeConstraint((BeforeConstraintDTO) dto, field); - case BEFORE_OR_AT: - return getBeforeOrAtConstraint((BeforeOrAtConstraintDTO) dto, field); - case GRANULAR_TO: - return getGranularToConstraint((GranularToConstraintDTO) dto, field); - case IS_NULL: - return getIsNullConstraint((NullConstraintDTO) dto, profileFields); - default: - throw new InvalidProfileException("Atomic constraint type not found: " + dto); - } - } - - Constraint getIsNullConstraint(NullConstraintDTO dto, ProfileFields profileFields) { - IsNullConstraint isNullConstraint = new IsNullConstraint(profileFields.getByName(dto.field)); - return dto.isNull - ? isNullConstraint - : isNullConstraint.negate(); - } - - Constraint getInSetConstraint(InSetConstraintDTO dto, Field field) { - return new IsInSetConstraint(field, prepareValuesForSet(dto, field)); - } - - EqualToConstraint getEqualToConstraint(EqualToConstraintDTO dto, Field field){ - return new EqualToConstraint(field, readAnyType(field, dto.value)); - } - - Constraint getGranularToConstraint(GranularToConstraintDTO dto, Field field) { - throw new UnsupportedOperationException("GranularTo Constraint is not supported with type " + field.getType()); - } - - Constraint getBeforeOrAtConstraint(BeforeOrAtConstraintDTO dto, Field field) { - throw new UnsupportedOperationException("beforeOrAt Constraint is not supported with type " + field.getType()); - } - - Constraint getBeforeConstraint(BeforeConstraintDTO dto, Field field) { - throw new UnsupportedOperationException("before Constraint is not supported with type " + field.getType()); - } - - Constraint getAfterOrAtConstraint(AfterOrAtConstraintDTO dto, Field field) { - throw new UnsupportedOperationException("afterOrAt Constraint is not supported with type " + field.getType()); - } - - Constraint getAfterConstraint(AfterConstraintDTO dto, Field field) { - throw new UnsupportedOperationException("after Constraint is not supported with type " + field.getType()); - } - - Constraint getLessThanOrEqualToConstraint(LessThanOrEqualToConstraintDTO dto, Field field) { - throw new UnsupportedOperationException("lessThanOrEqualTo Constraint is not supported with type " + field.getType()); - } - - Constraint getIsLessThanConstraint(LessThanConstraintDTO dto, Field field) { - throw new UnsupportedOperationException("lessThan Constraint is not supported with type " + field.getType()); - } - - Constraint getIsGreaterThanOrEqualToConstraint(GreaterThanOrEqualToConstraintDTO dto, Field field) { - throw new UnsupportedOperationException("isGreaterThanOrEqualTo Constraint is not supported with type " + field.getType()); - } - - Constraint getIsGreaterThanConstraint(GreaterThanConstraintDTO dto, Field field) { - throw new UnsupportedOperationException("greaterThan Constraint is not supported with type " + field.getType()); - } - - Constraint getIsLongerThanConstraint(LongerThanConstraintDTO dto, Field field) { - throw new UnsupportedOperationException("longerThan Constraint is not supported with type " + field.getType()); - } - - Constraint getShorterThanConstraint(ShorterThanConstraintDTO dto, Field field) { - throw new UnsupportedOperationException("shorterThan Constraint is not supported with type " + field.getType()); - } - - Constraint getOfLengthConstraint(OfLengthConstraintDTO dto, Field field) { - throw new UnsupportedOperationException("ofLength Constraint is not supported with type " + field.getType()); - } - - Constraint getContainsRegexConstraint(ContainsRegexConstraintDTO dto, Field field) { - throw new UnsupportedOperationException("containsRegex Constraint is not supported with type " + field.getType()); - } - - Constraint getMatchesRegexConstraint(MatchesRegexConstraintDTO dto, Field field) { - throw new UnsupportedOperationException("matchesRegex Constraint is not supported with type " + field.getType()); - } - - Constraint getInMapConstraint(InMapConstraintDTO dto, ProfileFields profileFields, Field field) { - return new InMapRelation(field, profileFields.getByName(dto.file), - DistributedList.uniform(fileReader.listFromMapFile(dto.file, dto.key).stream() - .map(value -> readAnyType(field, value)) - .collect(Collectors.toList()))); - } - - - @Nullable - private Object readAnyType(Field field, Object value) { - switch (field.getType()) { - case DATETIME: - return HelixDateTime.create((String) value).getValue(); - case NUMERIC: - return NumberUtils.coerceToBigDecimal(value); - default: - return value; - } - } - - private DistributedList prepareValuesForSet(InSetConstraintDTO inSetConstraintDTO, Field field) { - return (inSetConstraintDTO instanceof InSetFromFileConstraintDTO - ? fileReader.setFromFile(((InSetFromFileConstraintDTO) inSetConstraintDTO).file) - : DistributedList.uniform(((InSetOfValuesConstraintDTO) inSetConstraintDTO).values.stream() - .distinct() - .map(o -> readAnyType(field, o)) - .collect(Collectors.toList()))); - } -} diff --git a/profile/src/main/java/com/scottlogic/deg/profile/reader/AtomicConstraintFactory/DateTimeConstraintFactory.java b/profile/src/main/java/com/scottlogic/deg/profile/reader/AtomicConstraintFactory/DateTimeConstraintFactory.java deleted file mode 100644 index 6c54ac7b8..000000000 --- a/profile/src/main/java/com/scottlogic/deg/profile/reader/AtomicConstraintFactory/DateTimeConstraintFactory.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright 2019 Scott Logic Ltd - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -package com.scottlogic.deg.profile.reader.AtomicConstraintFactory; - -import com.google.inject.Inject; -import com.scottlogic.deg.common.profile.DateTimeGranularity; -import com.scottlogic.deg.common.profile.Field; -import com.scottlogic.deg.common.profile.HelixDateTime; -import com.scottlogic.deg.generator.profile.constraints.Constraint; -import com.scottlogic.deg.generator.profile.constraints.atomic.*; -import com.scottlogic.deg.profile.dtos.constraints.*; -import com.scottlogic.deg.profile.reader.FileReader; -import org.jetbrains.annotations.NotNull; - -class DateTimeConstraintFactory extends AtomicConstraintFactory { - - @Inject - DateTimeConstraintFactory(FileReader fileReader) { - super(fileReader); - } - - @Override - Constraint getAfterOrAtConstraint(AfterOrAtConstraintDTO dto, Field field) { - return new IsAfterOrEqualToConstantDateTimeConstraint(field, HelixDateTime.create(dto.value)); - } - - @Override - Constraint getAfterConstraint(AfterConstraintDTO dto, Field field) { - return new IsAfterConstantDateTimeConstraint(field, HelixDateTime.create(dto.value)); - } - - @Override - Constraint getBeforeOrAtConstraint(BeforeOrAtConstraintDTO dto, Field field) { - return new IsBeforeOrEqualToConstantDateTimeConstraint(field, HelixDateTime.create(dto.value)); - } - - @Override - Constraint getBeforeConstraint(BeforeConstraintDTO dto, Field field) { - return new IsBeforeConstantDateTimeConstraint(field, HelixDateTime.create(dto.value)); - } - - @Override - Constraint getGranularToConstraint(GranularToConstraintDTO dto, Field field) { - return new IsGranularToDateConstraint(field, DateTimeGranularity.create((String) dto.value)); - } - -} diff --git a/profile/src/main/java/com/scottlogic/deg/profile/reader/AtomicConstraintFactory/NumericConstraintFactory.java b/profile/src/main/java/com/scottlogic/deg/profile/reader/AtomicConstraintFactory/NumericConstraintFactory.java deleted file mode 100644 index a5e98983f..000000000 --- a/profile/src/main/java/com/scottlogic/deg/profile/reader/AtomicConstraintFactory/NumericConstraintFactory.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright 2019 Scott Logic Ltd - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -package com.scottlogic.deg.profile.reader.AtomicConstraintFactory; - -import com.google.inject.Inject; -import com.scottlogic.deg.common.profile.Field; -import com.scottlogic.deg.common.profile.HelixNumber; -import com.scottlogic.deg.common.profile.NumericGranularity; -import com.scottlogic.deg.generator.profile.constraints.Constraint; -import com.scottlogic.deg.generator.profile.constraints.atomic.*; -import com.scottlogic.deg.profile.dtos.constraints.*; -import com.scottlogic.deg.profile.reader.FileReader; -import org.jetbrains.annotations.NotNull; - -class NumericConstraintFactory extends AtomicConstraintFactory { - - @Inject - NumericConstraintFactory(FileReader fileReader) { - super(fileReader); - } - - @Override - Constraint getGranularToConstraint(GranularToConstraintDTO dto, Field field) { - return new IsGranularToNumericConstraint(field, NumericGranularity.create(dto.value)); - } - - @Override - Constraint getLessThanOrEqualToConstraint(LessThanOrEqualToConstraintDTO dto, Field field) { - return new IsLessThanOrEqualToConstantConstraint(field, HelixNumber.create(dto.value)); - } - - @Override - Constraint getIsLessThanConstraint(LessThanConstraintDTO dto, Field field) { - return new IsLessThanConstantConstraint(field, HelixNumber.create(dto.value)); - } - - @Override - Constraint getIsGreaterThanOrEqualToConstraint(GreaterThanOrEqualToConstraintDTO dto, Field field) { - return new IsGreaterThanOrEqualToConstantConstraint(field, HelixNumber.create(dto.value)); - } - - @Override - Constraint getIsGreaterThanConstraint(GreaterThanConstraintDTO dto, Field field) { - return new IsGreaterThanConstantConstraint(field, HelixNumber.create(dto.value)); - } -} diff --git a/profile/src/main/java/com/scottlogic/deg/profile/reader/AtomicConstraintFactory/StringConstraintFactory.java b/profile/src/main/java/com/scottlogic/deg/profile/reader/AtomicConstraintFactory/StringConstraintFactory.java deleted file mode 100644 index 4f65e6f47..000000000 --- a/profile/src/main/java/com/scottlogic/deg/profile/reader/AtomicConstraintFactory/StringConstraintFactory.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Copyright 2019 Scott Logic Ltd - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -package com.scottlogic.deg.profile.reader.AtomicConstraintFactory; - -import com.google.inject.Inject; -import com.scottlogic.deg.common.profile.Field; -import com.scottlogic.deg.common.profile.HelixStringLength; -import com.scottlogic.deg.generator.profile.constraints.Constraint; -import com.scottlogic.deg.generator.profile.constraints.atomic.*; -import com.scottlogic.deg.profile.dtos.constraints.*; -import com.scottlogic.deg.profile.reader.FileReader; -import com.scottlogic.deg.profile.reader.InvalidProfileException; -import org.jetbrains.annotations.NotNull; - -import java.util.regex.Pattern; - -class StringConstraintFactory extends AtomicConstraintFactory { - - @Inject - StringConstraintFactory(FileReader fileReader) { - super(fileReader); - } - - @Override - Constraint getIsLongerThanConstraint(LongerThanConstraintDTO dto, Field field) { - return new IsStringLongerThanConstraint(field, HelixStringLength.create(dto.value)); - } - - @Override - Constraint getShorterThanConstraint(ShorterThanConstraintDTO dto, Field field) { - return new IsStringShorterThanConstraint(field, HelixStringLength.create(dto.value)); - } - - @Override - Constraint getOfLengthConstraint(OfLengthConstraintDTO dto, Field field) { - return new StringHasLengthConstraint(field, HelixStringLength.create(dto.value)); - } - - @Override - Constraint getContainsRegexConstraint(ContainsRegexConstraintDTO dto, Field field) { - return new ContainsRegexConstraint(field, readPattern(dto.value)); - } - - @Override - Constraint getMatchesRegexConstraint(MatchesRegexConstraintDTO dto, Field field) { - return new MatchesRegexConstraint(field, readPattern(dto.value)); - } - - private Pattern readPattern(Object value) { - if (value instanceof Pattern) return (Pattern) value; - try { - return Pattern.compile((String) value); - } catch (IllegalArgumentException e) { - throw new InvalidProfileException(e.getMessage()); - } - } -} - diff --git a/profile/src/main/java/com/scottlogic/deg/profile/reader/validation/ConfigValidator.java b/profile/src/main/java/com/scottlogic/deg/profile/reader/ConfigValidator.java similarity index 97% rename from profile/src/main/java/com/scottlogic/deg/profile/reader/validation/ConfigValidator.java rename to profile/src/main/java/com/scottlogic/deg/profile/reader/ConfigValidator.java index 64a789b94..12aafb5a1 100644 --- a/profile/src/main/java/com/scottlogic/deg/profile/reader/validation/ConfigValidator.java +++ b/profile/src/main/java/com/scottlogic/deg/profile/reader/ConfigValidator.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.scottlogic.deg.profile.reader.validation; +package com.scottlogic.deg.profile.reader; import com.google.inject.Inject; import com.google.inject.name.Named; diff --git a/profile/src/main/java/com/scottlogic/deg/profile/reader/ConstraintReader.java b/profile/src/main/java/com/scottlogic/deg/profile/reader/ConstraintReader.java deleted file mode 100644 index 3a423dd8a..000000000 --- a/profile/src/main/java/com/scottlogic/deg/profile/reader/ConstraintReader.java +++ /dev/null @@ -1,124 +0,0 @@ -/* - * Copyright 2019 Scott Logic Ltd - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.scottlogic.deg.profile.reader; - -import com.google.inject.Inject; -import com.scottlogic.deg.common.profile.*; -import com.scottlogic.deg.common.util.defaults.DateTimeDefaults; -import com.scottlogic.deg.common.util.defaults.NumericDefaults; -import com.scottlogic.deg.generator.fieldspecs.relations.*; -import com.scottlogic.deg.generator.profile.constraints.Constraint; -import com.scottlogic.deg.generator.profile.constraints.grammatical.AndConstraint; -import com.scottlogic.deg.generator.profile.constraints.grammatical.ConditionalConstraint; -import com.scottlogic.deg.generator.profile.constraints.grammatical.OrConstraint; -import com.scottlogic.deg.profile.dtos.constraints.*; -import com.scottlogic.deg.profile.reader.AtomicConstraintFactory.AtomicConstraintReader; - -import java.util.Collection; -import java.util.Set; -import java.util.stream.Collectors; - -public class ConstraintReader { - - private final AtomicConstraintReader atomicConstraintReader; - - @Inject - public ConstraintReader(AtomicConstraintReader atomicConstraintReader) { - this.atomicConstraintReader = atomicConstraintReader; - } - - public Set read(Collection constraints, ProfileFields fields) { - return constraints.stream() - .map(subConstraintDto -> read(subConstraintDto, fields)) - .collect(Collectors.toSet()); - } - - public Constraint read(ConstraintDTO dto, ProfileFields profileFields) { - if (dto == null) { - throw new InvalidProfileException("Constraint is null"); - } else if (dto instanceof RelationalConstraintDTO) { - return readRelationalConstraintDto((RelationalConstraintDTO) dto, profileFields); - } else if (dto instanceof AtomicConstraintDTO) - return atomicConstraintReader.readAtomicConstraintDto((AtomicConstraintDTO) dto, profileFields); - else { - return readGrammaticalConstraintDto(dto, profileFields); - } - } - - private Constraint readRelationalConstraintDto(RelationalConstraintDTO dto, ProfileFields fields) { - Field main = fields.getByName(dto.field); - Field other = fields.getByName(dto.getOtherField()); - switch (dto.getType()) { - case EQUAL_TO_FIELD: - Granularity offsetGranularity = readGranularity(main.getType(), dto.offsetUnit); - return offsetGranularity != null - ? new EqualToOffsetRelation(main, other, offsetGranularity, dto.offset) - : new EqualToRelation(main, other); - case AFTER_FIELD: - return new AfterRelation(main, other, false, DateTimeDefaults.get()); - case AFTER_OR_AT_FIELD: - return new AfterRelation(main, other, true, DateTimeDefaults.get()); - case BEFORE_FIELD: - return new BeforeRelation(main, other, false, DateTimeDefaults.get()); - case BEFORE_OR_AT_FIELD: - return new BeforeRelation(main, other, true, DateTimeDefaults.get()); - case GREATER_THAN_FIELD: - return new AfterRelation(main, other, false, NumericDefaults.get()); - case GREATER_THAN_OR_EQUAL_TO_FIELD: - return new AfterRelation(main, other, true, NumericDefaults.get()); - case LESS_THAN_FIELD: - return new BeforeRelation(main, other, false, NumericDefaults.get()); - case LESS_THAN_OR_EQUAL_TO_FIELD: - return new BeforeRelation(main, other, true, NumericDefaults.get()); - default: - throw new InvalidProfileException("Unexpected relation data type " + dto.getType()); - } - } - - private Constraint readGrammaticalConstraintDto(ConstraintDTO dto, ProfileFields profileFields) { - switch (dto.getType()) { - case ALL_OF: - return new AndConstraint(read(((AllOfConstraintDTO) dto).constraints, profileFields)); - case ANY_OF: - return new OrConstraint(read(((AnyOfConstraintDTO) dto).constraints, profileFields)); - case IF: - IfConstraintDTO conditionalConstraintDTO = (IfConstraintDTO) dto; - Constraint ifConstraint = read(conditionalConstraintDTO.ifConstraint, profileFields); - Constraint thenConstraint = read(conditionalConstraintDTO.thenConstraint, profileFields); - Constraint elseConstraint = conditionalConstraintDTO.elseConstraint == null ? null - : read(conditionalConstraintDTO.elseConstraint, profileFields); - return new ConditionalConstraint(ifConstraint, thenConstraint, elseConstraint); - case NOT: - return read(((NotConstraintDTO) dto).constraint, profileFields).negate(); - default: - throw new InvalidProfileException("Grammatical constraint type not found: " + dto); - } - } - - private Granularity readGranularity(FieldType type, String offsetUnit) { - if (offsetUnit == null) return null; - switch (type) { - case NUMERIC: - return NumericGranularity.create(offsetUnit); - case DATETIME: - return DateTimeGranularity.create(offsetUnit); - default: - return null; - } - } - -} diff --git a/profile/src/main/java/com/scottlogic/deg/profile/reader/file/CsvInputStreamReader.java b/profile/src/main/java/com/scottlogic/deg/profile/reader/CsvInputStreamReader.java similarity index 98% rename from profile/src/main/java/com/scottlogic/deg/profile/reader/file/CsvInputStreamReader.java rename to profile/src/main/java/com/scottlogic/deg/profile/reader/CsvInputStreamReader.java index d8b7950b7..7af9e6e5d 100644 --- a/profile/src/main/java/com/scottlogic/deg/profile/reader/file/CsvInputStreamReader.java +++ b/profile/src/main/java/com/scottlogic/deg/profile/reader/CsvInputStreamReader.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.scottlogic.deg.profile.reader.file; +package com.scottlogic.deg.profile.reader; import com.scottlogic.deg.common.ValidationException; import com.scottlogic.deg.generator.fieldspecs.whitelist.DistributedList; diff --git a/profile/src/main/java/com/scottlogic/deg/profile/reader/FileReader.java b/profile/src/main/java/com/scottlogic/deg/profile/reader/FileReader.java index a53d95a0d..e96992799 100644 --- a/profile/src/main/java/com/scottlogic/deg/profile/reader/FileReader.java +++ b/profile/src/main/java/com/scottlogic/deg/profile/reader/FileReader.java @@ -5,7 +5,6 @@ import com.scottlogic.deg.common.ValidationException; import com.scottlogic.deg.generator.fieldspecs.whitelist.DistributedList; import com.scottlogic.deg.generator.fieldspecs.whitelist.WeightedElement; -import com.scottlogic.deg.profile.reader.file.CsvInputStreamReader; import java.io.*; import java.util.stream.Collectors; diff --git a/profile/src/main/java/com/scottlogic/deg/profile/reader/JsonProfileReader.java b/profile/src/main/java/com/scottlogic/deg/profile/reader/JsonProfileReader.java index 529d27000..82b3ad825 100644 --- a/profile/src/main/java/com/scottlogic/deg/profile/reader/JsonProfileReader.java +++ b/profile/src/main/java/com/scottlogic/deg/profile/reader/JsonProfileReader.java @@ -18,34 +18,18 @@ import com.google.inject.Inject; import com.google.inject.name.Named; -import com.scottlogic.deg.common.profile.Field; -import com.scottlogic.deg.common.profile.FieldType; -import com.scottlogic.deg.common.profile.ProfileFields; +import com.scottlogic.deg.common.ValidationException; +import com.scottlogic.deg.common.commands.CommandBus; +import com.scottlogic.deg.common.commands.CommandResult; import com.scottlogic.deg.generator.profile.Profile; -import com.scottlogic.deg.generator.profile.Rule; -import com.scottlogic.deg.generator.profile.RuleInformation; -import com.scottlogic.deg.generator.profile.constraints.Constraint; -import com.scottlogic.deg.profile.dtos.FieldDTO; +import com.scottlogic.deg.profile.reader.commands.CreateProfile; import com.scottlogic.deg.profile.dtos.ProfileDTO; -import com.scottlogic.deg.profile.dtos.constraints.ConstraintDTO; -import com.scottlogic.deg.profile.common.ConstraintType; -import com.scottlogic.deg.profile.dtos.constraints.InMapConstraintDTO; -import com.scottlogic.deg.profile.dtos.constraints.AllOfConstraintDTO; -import com.scottlogic.deg.profile.dtos.constraints.AnyOfConstraintDTO; -import com.scottlogic.deg.profile.dtos.constraints.IfConstraintDTO; -import com.scottlogic.deg.profile.dtos.constraints.NullConstraintDTO; -import com.scottlogic.deg.profile.reader.atomic.FieldReader; import com.scottlogic.deg.profile.serialisation.ProfileSerialiser; import java.io.File; import java.io.IOException; import java.nio.charset.StandardCharsets; import java.nio.file.Files; -import java.util.Collection; -import java.util.List; -import java.util.Optional; -import java.util.stream.Collectors; -import java.util.stream.Stream; /** * JsonProfileReader is responsible for reading and validating a profile from a path to a profile JSON file. @@ -53,12 +37,12 @@ */ public class JsonProfileReader implements ProfileReader { private final File profileFile; - private final ConstraintReader constraintReader; + private final CommandBus commandBus; @Inject - public JsonProfileReader(@Named("config:profileFile") File profileFile, ConstraintReader constraintReader) { + public JsonProfileReader(@Named("config:profileFile") File profileFile, CommandBus commandBus) { this.profileFile = profileFile; - this.constraintReader = constraintReader; + this.commandBus = commandBus; } public Profile read() throws IOException { @@ -69,95 +53,8 @@ public Profile read() throws IOException { public Profile read(String profileJson) { ProfileDTO profileDTO = new ProfileSerialiser().deserialise(profileJson); - if (profileDTO.fields == null) - throw new InvalidProfileException("Profile is invalid: 'fields' have not been defined."); - - List fields = profileDTO.fields.stream() - .map(fieldDTO -> new Field( - fieldDTO.name, - fieldDTO.type.getFieldType(), - fieldDTO.unique, - getFormatting(fieldDTO), - false)) - .collect(Collectors.toList()); - - List inMapFields = profileDTO.rules.stream() - .flatMap(ruleDTO -> ruleDTO.constraints.stream()) - .flatMap(constraintDTO -> getInMapConstraints(profileDTO).stream()) - .distinct() - .map(file -> new Field(file, FieldType.NUMERIC, false, null, true) - ).collect(Collectors.toList()); - - fields.addAll(inMapFields); - ProfileFields profileFields = new ProfileFields(fields); - - Collection rules = profileDTO.rules.stream() - .map(r -> new Rule(new RuleInformation(r.rule), constraintReader.read(r.constraints, profileFields))) - .collect(Collectors.toList()); - - Collection nonNullableConstraints = profileDTO.fields.stream() - .filter(fieldDTO -> !fieldDTO.nullable) - .map(fieldDTO -> constraintReader.read(new NullConstraintDTO() {{ - field = fieldDTO.name; - isNull = false; - }}, profileFields)) - .collect(Collectors.toList()); - - Collection typeConstraints = profileDTO.fields.stream() - .map(fieldDto -> FieldReader.read(profileFields.getByName(fieldDto.name), fieldDto.type)) - .filter(Optional::isPresent) - .map(Optional::get) - .collect(Collectors.toList()); - - if (!nonNullableConstraints.isEmpty()) { - rules.add(new Rule(new RuleInformation("nullable-rules"), nonNullableConstraints)); - } - if (!typeConstraints.isEmpty()) { - rules.add(new Rule(new RuleInformation("type-rules"), typeConstraints)); - } - return new Profile(profileFields, rules, profileDTO.description); - } - - private String getFormatting(FieldDTO fDto) { - if (fDto.formatting != null) { - return fDto.formatting; - } else { - return fDto.type.getDefaultFormatting(); - } - } - - private NullConstraintDTO nullDtoOf(FieldDTO fieldDTO) { - NullConstraintDTO nullConstraint = new NullConstraintDTO(); - nullConstraint.field = fieldDTO.name; - return nullConstraint; - } - - private List getInMapConstraints(ProfileDTO profileDto) { - return profileDto.rules.stream() - .flatMap(ruleDTO -> ruleDTO.constraints.stream()) - .flatMap(constraint -> getAllAtomicConstraints(Stream.of(constraint))) - .filter(constraintDTO -> constraintDTO.getType() == ConstraintType.IN_MAP) - .map(constraintDTO -> ((InMapConstraintDTO) constraintDTO).file) - .collect(Collectors.toList()); - } - - private Stream getAllAtomicConstraints(Stream constraints) { - return constraints.flatMap(this::getUnpackedConstraintsToStream); - } - - private Stream getUnpackedConstraintsToStream(ConstraintDTO constraintDTO) { - switch (constraintDTO.getType()) { - case IF: - IfConstraintDTO conditionalConstraintDTO = (IfConstraintDTO) constraintDTO; - return getAllAtomicConstraints(conditionalConstraintDTO.elseConstraint == null - ? Stream.of(((IfConstraintDTO) constraintDTO).thenConstraint) - : Stream.of(((IfConstraintDTO) constraintDTO).thenConstraint, ((IfConstraintDTO) constraintDTO).elseConstraint)); - case ALL_OF: - return getAllAtomicConstraints(((AllOfConstraintDTO) constraintDTO).constraints.stream()); - case ANY_OF: - return getAllAtomicConstraints(((AnyOfConstraintDTO) constraintDTO).constraints.stream()); - default: - return Stream.of(constraintDTO); - } + CommandResult createProfileResult = commandBus.send(new CreateProfile(profileDTO)); + if(!createProfileResult.isSuccess) throw new ValidationException(createProfileResult.errors); + return createProfileResult.value; } } diff --git a/profile/src/main/java/com/scottlogic/deg/profile/reader/file/names/NameRetriever.java b/profile/src/main/java/com/scottlogic/deg/profile/reader/NameRetriever.java similarity index 96% rename from profile/src/main/java/com/scottlogic/deg/profile/reader/file/names/NameRetriever.java rename to profile/src/main/java/com/scottlogic/deg/profile/reader/NameRetriever.java index e95869c76..ca809d748 100644 --- a/profile/src/main/java/com/scottlogic/deg/profile/reader/file/names/NameRetriever.java +++ b/profile/src/main/java/com/scottlogic/deg/profile/reader/NameRetriever.java @@ -14,12 +14,11 @@ * limitations under the License. */ -package com.scottlogic.deg.profile.reader.file.names; +package com.scottlogic.deg.profile.reader; import com.scottlogic.deg.generator.profile.constraints.atomic.NameConstraintTypes; import com.scottlogic.deg.generator.fieldspecs.whitelist.DistributedList; import com.scottlogic.deg.generator.fieldspecs.whitelist.WeightedElement; -import com.scottlogic.deg.profile.reader.file.CsvInputStreamReader; import java.io.IOException; import java.io.InputStream; diff --git a/profile/src/main/java/com/scottlogic/deg/profile/reader/ValidatingProfileReader.java b/profile/src/main/java/com/scottlogic/deg/profile/reader/ValidatingProfileReader.java index 05e8473ab..0ea85ee3a 100644 --- a/profile/src/main/java/com/scottlogic/deg/profile/reader/ValidatingProfileReader.java +++ b/profile/src/main/java/com/scottlogic/deg/profile/reader/ValidatingProfileReader.java @@ -16,18 +16,13 @@ package com.scottlogic.deg.profile.reader; import com.google.inject.Inject; -import com.scottlogic.deg.common.profile.Field; import com.scottlogic.deg.generator.profile.Profile; -import com.scottlogic.deg.common.profile.ProfileFields; +import com.scottlogic.deg.profile.ProfileSchemaLoader; +import com.scottlogic.deg.profile.SchemaVersionValidator; import com.scottlogic.deg.profile.guice.ProfileConfigSource; -import com.scottlogic.deg.profile.reader.validation.ConfigValidator; -import com.scottlogic.deg.profile.dtos.ProfileSchemaLoader; -import com.scottlogic.deg.profile.dtos.SchemaVersionValidator; import java.io.IOException; import java.net.URL; -import java.util.List; -import java.util.stream.Collectors; public class ValidatingProfileReader { @@ -54,22 +49,6 @@ public Profile read() throws IOException { configValidator.checkProfileInputFile(); URL schema = schemaVersionValidator.getSchemaFile(); profileSchemaLoader.validateProfile(configSource.getProfileFile(), schema); - - Profile profile = profileReader.read(); - - validateFieldsAreTyped(profile.getFields()); - return profile; - } - - private void validateFieldsAreTyped(ProfileFields fields) { - List untyped = fields.stream().filter(field -> field.getType() == null).collect(Collectors.toList()); - if (untyped.size() == 1) { - throw new InvalidProfileException("Field [" + untyped.get(0).name + "]: is not typed; add its type to the field definition"); - } - if (!untyped.isEmpty()) { - throw new InvalidProfileException("Fields " - + untyped.stream().map(f -> f.name).reduce((s, z) -> s + ", " + z).get() - + " are not typed; add their type to the field definition"); - } + return profileReader.read(); } } \ No newline at end of file diff --git a/profile/src/main/java/com/scottlogic/deg/profile/reader/atomic/FieldReader.java b/profile/src/main/java/com/scottlogic/deg/profile/reader/atomic/FieldReader.java deleted file mode 100644 index 39d437d8f..000000000 --- a/profile/src/main/java/com/scottlogic/deg/profile/reader/atomic/FieldReader.java +++ /dev/null @@ -1,40 +0,0 @@ -package com.scottlogic.deg.profile.reader.atomic; - -import com.scottlogic.deg.common.profile.DateTimeGranularity; -import com.scottlogic.deg.common.profile.Field; -import com.scottlogic.deg.common.profile.NumericGranularity; -import com.scottlogic.deg.common.profile.SpecificFieldType; -import com.scottlogic.deg.generator.profile.constraints.Constraint; -import com.scottlogic.deg.generator.profile.constraints.atomic.*; -import com.scottlogic.deg.profile.reader.file.names.NameRetriever; - -import java.math.BigDecimal; -import java.time.temporal.ChronoUnit; -import java.util.Optional; - -public class FieldReader { - public static Optional read(Field field, SpecificFieldType type) { - switch (type) { - case DATE: - return Optional.of(new IsGranularToDateConstraint(field, new DateTimeGranularity(ChronoUnit.DAYS))); - case INTEGER: - return Optional.of(new IsGranularToNumericConstraint(field, NumericGranularity.create(BigDecimal.ONE))); - case ISIN: - return Optional.of(new MatchesStandardConstraint(field, StandardConstraintTypes.ISIN)); - case SEDOL: - return Optional.of(new MatchesStandardConstraint(field, StandardConstraintTypes.SEDOL)); - case CUSIP: - return Optional.of(new MatchesStandardConstraint(field, StandardConstraintTypes.CUSIP)); - case RIC: - return Optional.of(new MatchesStandardConstraint(field, StandardConstraintTypes.RIC)); - case FIRST_NAME: - return Optional.of(new IsInSetConstraint(field, NameRetriever.loadNamesFromFile(NameConstraintTypes.FIRST))); - case LAST_NAME: - return Optional.of(new IsInSetConstraint(field, NameRetriever.loadNamesFromFile(NameConstraintTypes.LAST))); - case FULL_NAME: - return Optional.of(new IsInSetConstraint(field, NameRetriever.loadNamesFromFile(NameConstraintTypes.FULL))); - default: - return Optional.empty(); - } - } -} diff --git a/profile/src/main/java/com/scottlogic/deg/profile/reader/commands/CreateConstraints.java b/profile/src/main/java/com/scottlogic/deg/profile/reader/commands/CreateConstraints.java new file mode 100644 index 000000000..ea4b5bc67 --- /dev/null +++ b/profile/src/main/java/com/scottlogic/deg/profile/reader/commands/CreateConstraints.java @@ -0,0 +1,20 @@ +package com.scottlogic.deg.profile.reader.commands; + +import com.scottlogic.deg.common.commands.Command; +import com.scottlogic.deg.common.profile.Fields; +import com.scottlogic.deg.generator.profile.constraints.Constraint; +import com.scottlogic.deg.profile.dtos.constraints.ConstraintDTO; + +import java.util.List; + +public class CreateConstraints extends Command> +{ + public final List constraintDTOs; + public final Fields fields; + + public CreateConstraints(List constraintDTOs, Fields fields) + { + this.constraintDTOs = constraintDTOs; + this.fields = fields; + } +} diff --git a/profile/src/main/java/com/scottlogic/deg/profile/reader/commands/CreateFields.java b/profile/src/main/java/com/scottlogic/deg/profile/reader/commands/CreateFields.java new file mode 100644 index 000000000..0140741bf --- /dev/null +++ b/profile/src/main/java/com/scottlogic/deg/profile/reader/commands/CreateFields.java @@ -0,0 +1,20 @@ +package com.scottlogic.deg.profile.reader.commands; + +import com.scottlogic.deg.common.commands.Command; +import com.scottlogic.deg.common.profile.Fields; +import com.scottlogic.deg.profile.dtos.FieldDTO; +import com.scottlogic.deg.profile.dtos.RuleDTO; + +import java.util.List; + +public class CreateFields extends Command +{ + public final List fieldDTOs; + public final List ruleDTOs; + + public CreateFields(List fieldDTOs, List ruleDTOs) + { + this.fieldDTOs = fieldDTOs; + this.ruleDTOs = ruleDTOs; + } +} diff --git a/profile/src/main/java/com/scottlogic/deg/profile/reader/commands/CreateProfile.java b/profile/src/main/java/com/scottlogic/deg/profile/reader/commands/CreateProfile.java new file mode 100644 index 000000000..592cb90f9 --- /dev/null +++ b/profile/src/main/java/com/scottlogic/deg/profile/reader/commands/CreateProfile.java @@ -0,0 +1,15 @@ +package com.scottlogic.deg.profile.reader.commands; + +import com.scottlogic.deg.common.commands.Command; +import com.scottlogic.deg.generator.profile.Profile; +import com.scottlogic.deg.profile.dtos.ProfileDTO; + +public class CreateProfile extends Command +{ + public final ProfileDTO profileDTO; + + public CreateProfile(ProfileDTO profileDTO) + { + this.profileDTO = profileDTO; + } +} diff --git a/profile/src/main/java/com/scottlogic/deg/profile/reader/handlers/CreateConstraintsHandler.java b/profile/src/main/java/com/scottlogic/deg/profile/reader/handlers/CreateConstraintsHandler.java new file mode 100644 index 000000000..3f8c2ea1d --- /dev/null +++ b/profile/src/main/java/com/scottlogic/deg/profile/reader/handlers/CreateConstraintsHandler.java @@ -0,0 +1,189 @@ +package com.scottlogic.deg.profile.reader.handlers; + +import com.scottlogic.deg.common.commands.CommandHandler; +import com.scottlogic.deg.common.commands.CommandResult; +import com.scottlogic.deg.common.profile.*; +import com.scottlogic.deg.common.util.NumberUtils; +import com.scottlogic.deg.common.util.defaults.DateTimeDefaults; +import com.scottlogic.deg.common.util.defaults.NumericDefaults; +import com.scottlogic.deg.common.validators.Validator; +import com.scottlogic.deg.generator.fieldspecs.relations.*; +import com.scottlogic.deg.generator.fieldspecs.whitelist.DistributedList; +import com.scottlogic.deg.generator.profile.constraints.Constraint; +import com.scottlogic.deg.generator.profile.constraints.grammatical.AndConstraint; +import com.scottlogic.deg.generator.profile.constraints.grammatical.ConditionalConstraint; +import com.scottlogic.deg.generator.profile.constraints.grammatical.GrammaticalConstraint; +import com.scottlogic.deg.generator.profile.constraints.grammatical.OrConstraint; +import com.scottlogic.deg.profile.common.ConstraintType; +import com.scottlogic.deg.profile.dtos.constraints.ConstraintDTO; +import com.scottlogic.deg.profile.dtos.constraints.InMapConstraintDTO; +import com.scottlogic.deg.profile.dtos.constraints.NotConstraintDTO; +import com.scottlogic.deg.profile.dtos.constraints.atomic.AtomicConstraintDTO; +import com.scottlogic.deg.profile.dtos.constraints.grammatical.AllOfConstraintDTO; +import com.scottlogic.deg.profile.dtos.constraints.grammatical.AnyOfConstraintDTO; +import com.scottlogic.deg.profile.dtos.constraints.grammatical.ConditionalConstraintDTO; +import com.scottlogic.deg.profile.dtos.constraints.grammatical.GrammaticalConstraintDTO; +import com.scottlogic.deg.profile.dtos.constraints.relations.EqualToFieldConstraintDTO; +import com.scottlogic.deg.profile.dtos.constraints.relations.RelationalConstraintDTO; +import com.scottlogic.deg.profile.reader.FileReader; +import com.scottlogic.deg.profile.reader.commands.CreateConstraints; +import com.scottlogic.deg.profile.reader.services.constraints.atomic.AtomicConstraintService; + +import java.util.Collections; +import java.util.List; +import java.util.stream.Collectors; + +public class CreateConstraintsHandler extends CommandHandler> +{ + private final FileReader fileReader; + private final AtomicConstraintService atomicConstraintService; + + public CreateConstraintsHandler(FileReader fileReader, Validator validator) + { + super(validator); + this.fileReader = fileReader; + this.atomicConstraintService = new AtomicConstraintService(fileReader); + } + + @Override + public CommandResult> handleCommand(CreateConstraints command) + { + try + { + return CommandResult.success(createConstraints(command.constraintDTOs, command.fields)); + } + catch (Exception e) + { + return CommandResult.failure(Collections.singletonList(e.getMessage())); + } + } + + private List createConstraints(List constraintDTOs, Fields fields) + { + return constraintDTOs.stream().map(dto -> createConstraint(dto, fields)).collect(Collectors.toList()); + } + + private Constraint createConstraint(ConstraintDTO dto, Fields fields) + { + if (dto.getType() == ConstraintType.IN_MAP) + { + return createInMapRelation((InMapConstraintDTO) dto, fields); + } + if (dto.getType() == ConstraintType.NOT) + { + return createConstraint(((NotConstraintDTO) dto).constraint, fields).negate(); + } + if (dto instanceof RelationalConstraintDTO) + { + return createRelation((RelationalConstraintDTO) dto, fields); + } + if (dto instanceof AtomicConstraintDTO) + { + return atomicConstraintService.create((AtomicConstraintDTO) dto, fields); + } + if (dto instanceof GrammaticalConstraintDTO) + { + return createGrammaticalConstraint((GrammaticalConstraintDTO) dto, fields); + } + throw new IllegalStateException("Unexpected constraint type: " + dto.getType()); + } + + private FieldSpecRelations createRelation(RelationalConstraintDTO dto, Fields fields) + { + Field main = fields.getByName(dto.field); + Field other = fields.getByName(dto.getOtherField()); + DateTimeDefaults dateTimeDefaults = DateTimeDefaults.get(); + NumericDefaults numericDefaults = NumericDefaults.get(); + switch (dto.getType()) + { + case EQUAL_TO_FIELD: + return createEqualToRelation((EqualToFieldConstraintDTO) dto, fields); + case AFTER_FIELD: + return new AfterRelation(main, other, false, dateTimeDefaults); + case AFTER_OR_AT_FIELD: + return new AfterRelation(main, other, true, dateTimeDefaults); + case BEFORE_FIELD: + return new BeforeRelation(main, other, false, dateTimeDefaults); + case BEFORE_OR_AT_FIELD: + return new BeforeRelation(main, other, true, dateTimeDefaults); + case GREATER_THAN_FIELD: + return new AfterRelation(main, other, false, numericDefaults); + case GREATER_THAN_OR_EQUAL_TO_FIELD: + return new AfterRelation(main, other, true, numericDefaults); + case LESS_THAN_FIELD: + return new BeforeRelation(main, other, false, numericDefaults); + case LESS_THAN_OR_EQUAL_TO_FIELD: + return new BeforeRelation(main, other, true, numericDefaults); + default: + throw new IllegalStateException("Unexpected relation type: " + dto.getType()); + } + } + + private GrammaticalConstraint createGrammaticalConstraint(GrammaticalConstraintDTO dto, Fields fields) + { + switch (dto.getType()) + { + case ALL_OF: + return new AndConstraint(createConstraints(((AllOfConstraintDTO) dto).constraints, fields)); + case ANY_OF: + return new OrConstraint(createConstraints(((AnyOfConstraintDTO) dto).constraints, fields)); + case IF: + return createConditionalConstraint((ConditionalConstraintDTO) dto, fields); + default: + throw new IllegalStateException("Unexpected grammatical constraint type: " + dto.getType()); + } + } + + + + private InMapRelation createInMapRelation(InMapConstraintDTO dto, Fields fields) + { + Field main = fields.getByName(dto.field); + Field other = fields.getByName(dto.file); + + List values = fileReader.listFromMapFile(dto.file, dto.key).stream() + .map(value -> parseGenericValue(fields.getByName(dto.field), value)) + .collect(Collectors.toList()); + + return new InMapRelation(main, other, DistributedList.uniform(values)); + } + + private FieldSpecRelations createEqualToRelation(EqualToFieldConstraintDTO dto, Fields fields) + { + Field main = fields.getByName(dto.field); + Field other = fields.getByName(dto.getOtherField()); + if( dto.offsetUnit == null) return new EqualToRelation(main, other); + switch (main.getType()) + { + case NUMERIC: + return new EqualToOffsetRelation(main, other, NumericGranularity.create(dto.offsetUnit), dto.offset); + case DATETIME: + return new EqualToOffsetRelation(main, other, DateTimeGranularity.create(dto.offsetUnit), dto.offset); + default: + return new EqualToRelation(main, other); + } + } + + private ConditionalConstraint createConditionalConstraint(ConditionalConstraintDTO dto, Fields fields) + { + Constraint ifConstraint = createConstraint(dto.ifConstraint, fields); + Constraint thenConstraint = createConstraint(dto.thenConstraint, fields); + Constraint elseConstraint = dto.elseConstraint == null ? null : createConstraint(dto.elseConstraint, fields); + + return new ConditionalConstraint(ifConstraint, thenConstraint, elseConstraint); + } + + + private Object parseGenericValue(Field field, Object value) + { + switch (field.getType()) + { + case DATETIME: + return HelixDateTime.create((String) value).getValue(); + case NUMERIC: + return NumberUtils.coerceToBigDecimal(value); + default: + return value; + } + } +} diff --git a/profile/src/main/java/com/scottlogic/deg/profile/reader/handlers/CreateFieldsHandler.java b/profile/src/main/java/com/scottlogic/deg/profile/reader/handlers/CreateFieldsHandler.java new file mode 100644 index 000000000..18b286b84 --- /dev/null +++ b/profile/src/main/java/com/scottlogic/deg/profile/reader/handlers/CreateFieldsHandler.java @@ -0,0 +1,87 @@ +package com.scottlogic.deg.profile.reader.handlers; + +import com.scottlogic.deg.common.commands.CommandHandler; +import com.scottlogic.deg.common.commands.CommandResult; +import com.scottlogic.deg.common.profile.Field; +import com.scottlogic.deg.common.profile.Fields; +import com.scottlogic.deg.common.profile.SpecificFieldType; +import com.scottlogic.deg.common.validators.Validator; +import com.scottlogic.deg.profile.reader.commands.CreateFields; +import com.scottlogic.deg.profile.common.ConstraintType; +import com.scottlogic.deg.profile.dtos.FieldDTO; +import com.scottlogic.deg.profile.dtos.RuleDTO; +import com.scottlogic.deg.profile.dtos.constraints.*; +import com.scottlogic.deg.profile.dtos.constraints.InMapConstraintDTO; +import com.scottlogic.deg.profile.dtos.constraints.grammatical.AllOfConstraintDTO; +import com.scottlogic.deg.profile.dtos.constraints.grammatical.AnyOfConstraintDTO; +import com.scottlogic.deg.profile.dtos.constraints.grammatical.ConditionalConstraintDTO; + +import java.util.List; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +public class CreateFieldsHandler extends CommandHandler +{ + public CreateFieldsHandler(Validator validator) + { + super(validator); + } + + @Override + public CommandResult handleCommand(CreateFields command) + { + List fields = createFields(command.fieldDTOs); + getInMapFiles(command.ruleDTOs).stream().map(this::createField).forEach(fields::add); + return CommandResult.success(new Fields(fields)); + } + + private List createFields(List fieldDTOs) + { + return fieldDTOs.stream().map(this::createField).collect(Collectors.toList()); + } + + private Field createField(FieldDTO fieldDTO) + { + String formatting = fieldDTO.formatting != null ? fieldDTO.formatting : fieldDTO.type.getDefaultFormatting(); + return new Field(fieldDTO.name, fieldDTO.type, fieldDTO.unique,formatting, false, fieldDTO.nullable); + } + + private Field createField(String inMapFile) + { + return new Field(inMapFile, SpecificFieldType.INTEGER, false, null, true, false); + } + + private List getInMapFiles(List ruleDTOs) + { + return ruleDTOs.stream() + .flatMap(ruleDTO -> ruleDTO.constraints.stream()) + .flatMap(constraint -> getAllAtomicConstraints(Stream.of(constraint))) + .filter(constraintDTO -> constraintDTO.getType() == ConstraintType.IN_MAP) + .map(constraintDTO -> ((InMapConstraintDTO) constraintDTO).file) + .distinct() + .collect(Collectors.toList()); + } + + private Stream getAllAtomicConstraints(Stream constraintDTOs) + { + return constraintDTOs.flatMap(this::getUnpackedConstraintsToStream); + } + + private Stream getUnpackedConstraintsToStream(ConstraintDTO constraintDTO) + { + switch (constraintDTO.getType()) + { + case IF: + ConditionalConstraintDTO conditionalConstraintDTO = (ConditionalConstraintDTO) constraintDTO; + return getAllAtomicConstraints(conditionalConstraintDTO.elseConstraint == null + ? Stream.of(((ConditionalConstraintDTO) constraintDTO).thenConstraint) + : Stream.of(((ConditionalConstraintDTO) constraintDTO).thenConstraint, ((ConditionalConstraintDTO) constraintDTO).elseConstraint)); + case ALL_OF: + return getAllAtomicConstraints(((AllOfConstraintDTO) constraintDTO).constraints.stream()); + case ANY_OF: + return getAllAtomicConstraints(((AnyOfConstraintDTO) constraintDTO).constraints.stream()); + default: + return Stream.of(constraintDTO); + } + } +} diff --git a/profile/src/main/java/com/scottlogic/deg/profile/reader/handlers/CreateProfileHandler.java b/profile/src/main/java/com/scottlogic/deg/profile/reader/handlers/CreateProfileHandler.java new file mode 100644 index 000000000..8fd87312d --- /dev/null +++ b/profile/src/main/java/com/scottlogic/deg/profile/reader/handlers/CreateProfileHandler.java @@ -0,0 +1,117 @@ +package com.scottlogic.deg.profile.reader.handlers; + +import com.scottlogic.deg.common.commands.CommandBus; +import com.scottlogic.deg.common.commands.CommandHandler; +import com.scottlogic.deg.common.commands.CommandResult; +import com.scottlogic.deg.common.profile.DateTimeGranularity; +import com.scottlogic.deg.common.profile.Field; +import com.scottlogic.deg.common.profile.Fields; +import com.scottlogic.deg.common.profile.NumericGranularity; +import com.scottlogic.deg.common.validators.Validator; +import com.scottlogic.deg.generator.profile.Profile; +import com.scottlogic.deg.generator.profile.Rule; +import com.scottlogic.deg.generator.profile.constraints.Constraint; +import com.scottlogic.deg.generator.profile.constraints.atomic.*; +import com.scottlogic.deg.profile.reader.commands.CreateConstraints; +import com.scottlogic.deg.profile.reader.commands.CreateFields; +import com.scottlogic.deg.profile.reader.commands.CreateProfile; +import com.scottlogic.deg.profile.dtos.RuleDTO; +import com.scottlogic.deg.profile.reader.NameRetriever; + +import java.math.BigDecimal; +import java.time.temporal.ChronoUnit; +import java.util.List; +import java.util.Optional; +import java.util.stream.Collectors; + +public class CreateProfileHandler extends CommandHandler +{ + private final CommandBus bus; + + public CreateProfileHandler(CommandBus bus, Validator validator) + { + super(validator); + this.bus = bus; + } + + @Override + public CommandResult handleCommand(CreateProfile command) + { + CommandResult createFieldsResult = bus.send(new CreateFields(command.profileDTO.fields, command.profileDTO.rules)); + if (!createFieldsResult.isSuccess) return CommandResult.failure(createFieldsResult.errors); + Fields fields = createFieldsResult.value; + + CommandResult> createRulesResult = createRules(command.profileDTO.rules, fields); + if (!createRulesResult.isSuccess) return CommandResult.failure(createRulesResult.errors); + List rules = createRulesResult.value; + + createNotNullableRule(fields).ifPresent(rules::add); + createSpecificTypeRule(fields).ifPresent(rules::add); + + return CommandResult.success(new Profile(fields, rules, command.profileDTO.description)); + } + + private CommandResult> createRules(List ruleDTOs, Fields fields) + { + return CommandResult.combine(ruleDTOs.stream() + .map(ruleDTO -> createRule(ruleDTO, fields)) + .collect(Collectors.toList())); + } + + private CommandResult createRule(RuleDTO ruleDTO, Fields fields) + { + return bus.send(new CreateConstraints(ruleDTO.constraints, fields)) + .map(constraints -> new Rule(ruleDTO.description, constraints)); + } + + private Optional createNotNullableRule(Fields fields) + { + List notNullableConstraints = fields.stream() + .filter(field -> !field.isNullable()) + .map(field -> new IsNullConstraint(field).negate()) + .collect(Collectors.toList()); + + return notNullableConstraints.isEmpty() + ? Optional.empty() + : Optional.of(new Rule("not-nullable", notNullableConstraints)); + } + + private Optional createSpecificTypeRule(Fields fields) + { + List specificTypeConstraints = fields.stream() + .map(this::createSpecificTypeConstraint) + .filter(Optional::isPresent) + .map(Optional::get) + .collect(Collectors.toList()); + + return specificTypeConstraints.isEmpty() + ? Optional.empty() + : Optional.of(new Rule("specific-types", specificTypeConstraints)); + } + + private Optional createSpecificTypeConstraint(Field field) + { + switch (field.getSpecificType()) { + case DATE: + return Optional.of(new GranularToDateConstraint(field, new DateTimeGranularity(ChronoUnit.DAYS))); + case INTEGER: + return Optional.of(new GranularToNumericConstraint(field, NumericGranularity.create(BigDecimal.ONE))); + case ISIN: + return Optional.of(new MatchesStandardConstraint(field, StandardConstraintTypes.ISIN)); + case SEDOL: + return Optional.of(new MatchesStandardConstraint(field, StandardConstraintTypes.SEDOL)); + case CUSIP: + return Optional.of(new MatchesStandardConstraint(field, StandardConstraintTypes.CUSIP)); + case RIC: + return Optional.of(new MatchesStandardConstraint(field, StandardConstraintTypes.RIC)); + case FIRST_NAME: + return Optional.of(new InSetConstraint(field, NameRetriever.loadNamesFromFile(NameConstraintTypes.FIRST))); + case LAST_NAME: + return Optional.of(new InSetConstraint(field, NameRetriever.loadNamesFromFile(NameConstraintTypes.LAST))); + case FULL_NAME: + return Optional.of(new InSetConstraint(field, NameRetriever.loadNamesFromFile(NameConstraintTypes.FULL))); + default: + return Optional.empty(); + } + } +} diff --git a/profile/src/main/java/com/scottlogic/deg/profile/reader/services/constraints/atomic/AtomicConstraintFactory.java b/profile/src/main/java/com/scottlogic/deg/profile/reader/services/constraints/atomic/AtomicConstraintFactory.java new file mode 100644 index 000000000..6873ab1c7 --- /dev/null +++ b/profile/src/main/java/com/scottlogic/deg/profile/reader/services/constraints/atomic/AtomicConstraintFactory.java @@ -0,0 +1,102 @@ +package com.scottlogic.deg.profile.reader.services.constraints.atomic; + +import com.scottlogic.deg.common.profile.Field; +import com.scottlogic.deg.common.profile.Fields; +import com.scottlogic.deg.generator.fieldspecs.whitelist.DistributedList; +import com.scottlogic.deg.generator.profile.constraints.atomic.*; +import com.scottlogic.deg.profile.dtos.constraints.atomic.*; +import com.scottlogic.deg.profile.reader.FileReader; +import com.scottlogic.deg.profile.reader.InvalidProfileException; + +import java.util.stream.Collectors; + +abstract class AtomicConstraintFactory { + + private final FileReader fileReader; + + AtomicConstraintFactory(FileReader fileReader) { + this.fileReader = fileReader; + } + + AtomicConstraint createAtomicConstraint(AtomicConstraintDTO dto, Fields fields) { + Field field = fields.getByName(dto.field); + switch (dto.getType()) { + case EQUAL_TO: + return new EqualToConstraint(field, parseValue(((EqualToConstraintDTO)dto).value)); + case IN_SET: + return createInSetConstraint((InSetConstraintDTO) dto, field); + case MATCHES_REGEX: + return createMatchesRegexConstraint((MatchesRegexConstraintDTO) dto, field); + case CONTAINS_REGEX: + return createContainsRegexConstraint((ContainsRegexConstraintDTO) dto, field); + case OF_LENGTH: + return createOfLengthConstraint((OfLengthConstraintDTO) dto, field); + case SHORTER_THAN: + return createShorterThanConstraint((ShorterThanConstraintDTO) dto, field); + case LONGER_THAN: + return createLongerThanConstraint((LongerThanConstraintDTO) dto, field); + case GREATER_THAN: + return createGreaterThanConstraint((GreaterThanConstraintDTO) dto, field); + case GREATER_THAN_OR_EQUAL_TO: + return createGreaterThanOrEqualToConstraint((GreaterThanOrEqualToConstraintDTO) dto, field); + case LESS_THAN: + return createLessThanConstraint((LessThanConstraintDTO) dto, field); + case LESS_THAN_OR_EQUAL_TO: + return createLessThanOrEqualToConstraint((LessThanOrEqualToConstraintDTO) dto, field); + case AFTER: + return createAfterConstraint((AfterConstraintDTO) dto, field); + case AFTER_OR_AT: + return createAfterOrAtConstraint((AfterOrAtConstraintDTO) dto, field); + case BEFORE: + return createBeforeConstraint((BeforeConstraintDTO) dto, field); + case BEFORE_OR_AT: + return createBeforeOrAtConstraint((BeforeOrAtConstraintDTO) dto, field); + case GRANULAR_TO: + return createGranularToConstraint((GranularToConstraintDTO) dto, field); + case IS_NULL: + return createIsNullConstraint((IsNullConstraintDTO) dto, fields); + default: + throw new InvalidProfileException("Atomic constraint type not found: " + dto); + } + } + + abstract Object parseValue(Object value); + abstract MatchesRegexConstraint createMatchesRegexConstraint(MatchesRegexConstraintDTO dto, Field field); + abstract ContainsRegexConstraint createContainsRegexConstraint(ContainsRegexConstraintDTO dto, Field field); + abstract OfLengthConstraint createOfLengthConstraint(OfLengthConstraintDTO dto, Field field); + abstract ShorterThanConstraint createShorterThanConstraint(ShorterThanConstraintDTO dto, Field field); + abstract LongerThanConstraint createLongerThanConstraint(LongerThanConstraintDTO dto, Field field); + abstract GreaterThanConstraint createGreaterThanConstraint(GreaterThanConstraintDTO dto, Field field); + abstract GreaterThanOrEqualToConstraint createGreaterThanOrEqualToConstraint(GreaterThanOrEqualToConstraintDTO dto, Field field); + abstract LessThanConstraint createLessThanConstraint(LessThanConstraintDTO dto, Field field); + abstract LessThanOrEqualToConstraint createLessThanOrEqualToConstraint(LessThanOrEqualToConstraintDTO dto, Field field); + abstract AfterConstraint createAfterConstraint(AfterConstraintDTO dto, Field field); + abstract AfterOrAtConstraint createAfterOrAtConstraint(AfterOrAtConstraintDTO dto, Field field); + abstract BeforeConstraint createBeforeConstraint(BeforeConstraintDTO dto, Field field); + abstract BeforeOrAtConstraint createBeforeOrAtConstraint(BeforeOrAtConstraintDTO dto, Field field); + abstract AtomicConstraint createGranularToConstraint(GranularToConstraintDTO dto, Field field); + + private InSetConstraint createInSetConstraint(InSetConstraintDTO dto, Field field) + { + if (dto instanceof InSetFromFileConstraintDTO) + { + return new InSetConstraint(field, fileReader.setFromFile(((InSetFromFileConstraintDTO) dto).file)); + } + if (dto instanceof InSetOfValuesConstraintDTO) + { + DistributedList values = DistributedList.uniform(((InSetOfValuesConstraintDTO) dto).values.stream() + .distinct() + .map(this::parseValue) + .collect(Collectors.toList())); + + return new InSetConstraint(field, values); + } + throw new IllegalStateException("Unexpected value: " + dto.getType()); + } + + private AtomicConstraint createIsNullConstraint(IsNullConstraintDTO dto, Fields fields) + { + IsNullConstraint isNullConstraint = new IsNullConstraint(fields.getByName(dto.field)); + return dto.isNull ? isNullConstraint : isNullConstraint.negate(); + } +} diff --git a/profile/src/main/java/com/scottlogic/deg/profile/reader/AtomicConstraintFactory/AtomicConstraintReader.java b/profile/src/main/java/com/scottlogic/deg/profile/reader/services/constraints/atomic/AtomicConstraintService.java similarity index 52% rename from profile/src/main/java/com/scottlogic/deg/profile/reader/AtomicConstraintFactory/AtomicConstraintReader.java rename to profile/src/main/java/com/scottlogic/deg/profile/reader/services/constraints/atomic/AtomicConstraintService.java index d82a986da..37ded07ee 100644 --- a/profile/src/main/java/com/scottlogic/deg/profile/reader/AtomicConstraintFactory/AtomicConstraintReader.java +++ b/profile/src/main/java/com/scottlogic/deg/profile/reader/services/constraints/atomic/AtomicConstraintService.java @@ -14,40 +14,28 @@ * limitations under the License. */ -package com.scottlogic.deg.profile.reader.AtomicConstraintFactory; +package com.scottlogic.deg.profile.reader.services.constraints.atomic; import com.google.inject.Inject; -import com.scottlogic.deg.common.profile.*; -import com.scottlogic.deg.common.util.NumberUtils; -import com.scottlogic.deg.generator.fieldspecs.relations.InMapRelation; -import com.scottlogic.deg.generator.fieldspecs.whitelist.DistributedList; -import com.scottlogic.deg.generator.profile.constraints.Constraint; -import com.scottlogic.deg.generator.profile.constraints.atomic.*; -import com.scottlogic.deg.profile.dtos.constraints.*; -import com.scottlogic.deg.profile.reader.AtomicConstraintFactory.AtomicConstraintFactory; -import com.scottlogic.deg.profile.reader.AtomicConstraintFactory.StringConstraintFactory; +import com.scottlogic.deg.common.profile.FieldType; +import com.scottlogic.deg.common.profile.Fields; +import com.scottlogic.deg.generator.profile.constraints.atomic.AtomicConstraint; +import com.scottlogic.deg.profile.dtos.constraints.atomic.AtomicConstraintDTO; import com.scottlogic.deg.profile.reader.FileReader; -import com.scottlogic.deg.profile.reader.InvalidProfileException; -import org.jetbrains.annotations.Nullable; - -import javax.activation.UnsupportedDataTypeException; -import java.util.regex.Pattern; -import java.util.stream.Collectors; - -public class AtomicConstraintReader { +public class AtomicConstraintService +{ private final FileReader fileReader; @Inject - public AtomicConstraintReader(FileReader fileReader) { + public AtomicConstraintService(FileReader fileReader) { this.fileReader = fileReader; } - public Constraint readAtomicConstraintDto(AtomicConstraintDTO dto, ProfileFields profileFields) { - + public AtomicConstraint create(AtomicConstraintDTO dto, Fields fields) + { AtomicConstraintFactory constraintFactory; - - FieldType fieldType = profileFields.getByName(dto.field).getType(); + FieldType fieldType = fields.getByName(dto.field).getType(); switch(fieldType) { case STRING: constraintFactory = new StringConstraintFactory(fileReader); @@ -61,6 +49,6 @@ public Constraint readAtomicConstraintDto(AtomicConstraintDTO dto, ProfileFields default: throw new UnsupportedOperationException("No constraint factory for type " + fieldType); } - return constraintFactory.readAtomicConstraintDto(dto, profileFields); + return constraintFactory.createAtomicConstraint(dto, fields); } } diff --git a/profile/src/main/java/com/scottlogic/deg/profile/reader/services/constraints/atomic/DateTimeConstraintFactory.java b/profile/src/main/java/com/scottlogic/deg/profile/reader/services/constraints/atomic/DateTimeConstraintFactory.java new file mode 100644 index 000000000..4db3c4473 --- /dev/null +++ b/profile/src/main/java/com/scottlogic/deg/profile/reader/services/constraints/atomic/DateTimeConstraintFactory.java @@ -0,0 +1,120 @@ +/* + * Copyright 2019 Scott Logic Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +package com.scottlogic.deg.profile.reader.services.constraints.atomic; + +import com.google.inject.Inject; +import com.scottlogic.deg.common.profile.DateTimeGranularity; +import com.scottlogic.deg.common.profile.Field; +import com.scottlogic.deg.common.profile.HelixDateTime; +import com.scottlogic.deg.generator.profile.constraints.atomic.*; +import com.scottlogic.deg.profile.dtos.constraints.atomic.*; +import com.scottlogic.deg.profile.reader.FileReader; + +class DateTimeConstraintFactory extends AtomicConstraintFactory { + + @Inject + DateTimeConstraintFactory(FileReader fileReader) { + super(fileReader); + } + + @Override + Object parseValue(Object value) + { + return HelixDateTime.create((String) value).getValue(); + } + + @Override + MatchesRegexConstraint createMatchesRegexConstraint(MatchesRegexConstraintDTO dto, Field field) + { + return null; + } + + @Override + ContainsRegexConstraint createContainsRegexConstraint(ContainsRegexConstraintDTO dto, Field field) + { + return null; + } + + @Override + OfLengthConstraint createOfLengthConstraint(OfLengthConstraintDTO dto, Field field) + { + return null; + } + + @Override + ShorterThanConstraint createShorterThanConstraint(ShorterThanConstraintDTO dto, Field field) + { + return null; + } + + @Override + LongerThanConstraint createLongerThanConstraint(LongerThanConstraintDTO dto, Field field) + { + return null; + } + + @Override + GreaterThanConstraint createGreaterThanConstraint(GreaterThanConstraintDTO dto, Field field) + { + return null; + } + + @Override + GreaterThanOrEqualToConstraint createGreaterThanOrEqualToConstraint(GreaterThanOrEqualToConstraintDTO dto, Field field) + { + return null; + } + + @Override + LessThanConstraint createLessThanConstraint(LessThanConstraintDTO dto, Field field) + { + return null; + } + + @Override + LessThanOrEqualToConstraint createLessThanOrEqualToConstraint(LessThanOrEqualToConstraintDTO dto, Field field) + { + return null; + } + + @Override + AfterOrAtConstraint createAfterOrAtConstraint(AfterOrAtConstraintDTO dto, Field field) { + return new AfterOrAtConstraint(field, HelixDateTime.create(dto.value)); + } + + @Override + AfterConstraint createAfterConstraint(AfterConstraintDTO dto, Field field) { + return new AfterConstraint(field, HelixDateTime.create(dto.value)); + } + + @Override + BeforeOrAtConstraint createBeforeOrAtConstraint(BeforeOrAtConstraintDTO dto, Field field) { + return new BeforeOrAtConstraint(field, HelixDateTime.create(dto.value)); + } + + @Override + BeforeConstraint createBeforeConstraint(BeforeConstraintDTO dto, Field field) { + return new BeforeConstraint(field, HelixDateTime.create(dto.value)); + } + + @Override + AtomicConstraint createGranularToConstraint(GranularToConstraintDTO dto, Field field) { + return new GranularToDateConstraint(field, DateTimeGranularity.create((String) dto.value)); + } + +} diff --git a/profile/src/main/java/com/scottlogic/deg/profile/reader/services/constraints/atomic/NumericConstraintFactory.java b/profile/src/main/java/com/scottlogic/deg/profile/reader/services/constraints/atomic/NumericConstraintFactory.java new file mode 100644 index 000000000..8839f5737 --- /dev/null +++ b/profile/src/main/java/com/scottlogic/deg/profile/reader/services/constraints/atomic/NumericConstraintFactory.java @@ -0,0 +1,127 @@ +/* + * Copyright 2019 Scott Logic Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +package com.scottlogic.deg.profile.reader.services.constraints.atomic; + +import com.google.inject.Inject; +import com.scottlogic.deg.common.profile.Field; +import com.scottlogic.deg.common.profile.HelixNumber; +import com.scottlogic.deg.common.profile.NumericGranularity; +import com.scottlogic.deg.common.util.NumberUtils; +import com.scottlogic.deg.generator.profile.constraints.atomic.*; +import com.scottlogic.deg.profile.dtos.constraints.atomic.*; +import com.scottlogic.deg.profile.reader.FileReader; + +class NumericConstraintFactory extends AtomicConstraintFactory +{ + + @Inject + NumericConstraintFactory(FileReader fileReader) + { + super(fileReader); + } + + @Override + Object parseValue(Object value) + { + return NumberUtils.coerceToBigDecimal(value); + } + + @Override + MatchesRegexConstraint createMatchesRegexConstraint(MatchesRegexConstraintDTO dto, Field field) + { + return null; + } + + @Override + ContainsRegexConstraint createContainsRegexConstraint(ContainsRegexConstraintDTO dto, Field field) + { + return null; + } + + @Override + OfLengthConstraint createOfLengthConstraint(OfLengthConstraintDTO dto, Field field) + { + return null; + } + + @Override + ShorterThanConstraint createShorterThanConstraint(ShorterThanConstraintDTO dto, Field field) + { + return null; + } + + @Override + LongerThanConstraint createLongerThanConstraint(LongerThanConstraintDTO dto, Field field) + { + return null; + } + + @Override + GreaterThanConstraint createGreaterThanConstraint(GreaterThanConstraintDTO dto, Field field) + { + return new GreaterThanConstraint(field, HelixNumber.create(dto.value)); + } + + @Override + GreaterThanOrEqualToConstraint createGreaterThanOrEqualToConstraint(GreaterThanOrEqualToConstraintDTO dto, Field field) + { + return new GreaterThanOrEqualToConstraint(field, HelixNumber.create(dto.value)); + } + + @Override + LessThanConstraint createLessThanConstraint(LessThanConstraintDTO dto, Field field) + { + return new LessThanConstraint(field, HelixNumber.create(dto.value)); + } + + @Override + LessThanOrEqualToConstraint createLessThanOrEqualToConstraint(LessThanOrEqualToConstraintDTO dto, Field field) + { + return new LessThanOrEqualToConstraint(field, HelixNumber.create(dto.value)); + } + + @Override + AfterConstraint createAfterConstraint(AfterConstraintDTO dto, Field field) + { + return null; + } + + @Override + AfterOrAtConstraint createAfterOrAtConstraint(AfterOrAtConstraintDTO dto, Field field) + { + return null; + } + + @Override + BeforeConstraint createBeforeConstraint(BeforeConstraintDTO dto, Field field) + { + return null; + } + + @Override + BeforeOrAtConstraint createBeforeOrAtConstraint(BeforeOrAtConstraintDTO dto, Field field) + { + return null; + } + + @Override + AtomicConstraint createGranularToConstraint(GranularToConstraintDTO dto, Field field) + { + return new GranularToNumericConstraint(field, NumericGranularity.create(dto.value)); + } +} diff --git a/profile/src/main/java/com/scottlogic/deg/profile/reader/services/constraints/atomic/StringConstraintFactory.java b/profile/src/main/java/com/scottlogic/deg/profile/reader/services/constraints/atomic/StringConstraintFactory.java new file mode 100644 index 000000000..3a11b7290 --- /dev/null +++ b/profile/src/main/java/com/scottlogic/deg/profile/reader/services/constraints/atomic/StringConstraintFactory.java @@ -0,0 +1,126 @@ +/* + * Copyright 2019 Scott Logic Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +package com.scottlogic.deg.profile.reader.services.constraints.atomic; + +import com.google.inject.Inject; +import com.scottlogic.deg.common.profile.Field; +import com.scottlogic.deg.common.profile.HelixStringLength; +import com.scottlogic.deg.generator.profile.constraints.atomic.*; +import com.scottlogic.deg.profile.dtos.constraints.atomic.*; +import com.scottlogic.deg.profile.reader.FileReader; + +import java.util.regex.Pattern; + +class StringConstraintFactory extends AtomicConstraintFactory { + + @Inject + StringConstraintFactory(FileReader fileReader) { + super(fileReader); + } + + @Override + Object parseValue(Object value) + { + return value; + } + + @Override + MatchesRegexConstraint createMatchesRegexConstraint(MatchesRegexConstraintDTO dto, Field field) { + return new MatchesRegexConstraint(field, createPattern(dto.value)); + } + + @Override + ContainsRegexConstraint createContainsRegexConstraint(ContainsRegexConstraintDTO dto, Field field) { + return new ContainsRegexConstraint(field, createPattern(dto.value)); + } + + @Override + OfLengthConstraint createOfLengthConstraint(OfLengthConstraintDTO dto, Field field) { + return new OfLengthConstraint(field, HelixStringLength.create(dto.value)); + } + + @Override + ShorterThanConstraint createShorterThanConstraint(ShorterThanConstraintDTO dto, Field field) { + return new ShorterThanConstraint(field, HelixStringLength.create(dto.value)); + } + + @Override + LongerThanConstraint createLongerThanConstraint(LongerThanConstraintDTO dto, Field field) { + return new LongerThanConstraint(field, HelixStringLength.create(dto.value)); + } + + @Override + GreaterThanConstraint createGreaterThanConstraint(GreaterThanConstraintDTO dto, Field field) + { + return null; + } + + @Override + GreaterThanOrEqualToConstraint createGreaterThanOrEqualToConstraint(GreaterThanOrEqualToConstraintDTO dto, Field field) + { + return null; + } + + @Override + LessThanConstraint createLessThanConstraint(LessThanConstraintDTO dto, Field field) + { + return null; + } + + @Override + LessThanOrEqualToConstraint createLessThanOrEqualToConstraint(LessThanOrEqualToConstraintDTO dto, Field field) + { + return null; + } + + @Override + AfterConstraint createAfterConstraint(AfterConstraintDTO dto, Field field) + { + return null; + } + + @Override + AfterOrAtConstraint createAfterOrAtConstraint(AfterOrAtConstraintDTO dto, Field field) + { + return null; + } + + @Override + BeforeConstraint createBeforeConstraint(BeforeConstraintDTO dto, Field field) + { + return null; + } + + @Override + BeforeOrAtConstraint createBeforeOrAtConstraint(BeforeOrAtConstraintDTO dto, Field field) + { + return null; + } + + @Override + AtomicConstraint createGranularToConstraint(GranularToConstraintDTO dto, Field field) + { + return null; + } + + private Pattern createPattern(Object value) + { + return value instanceof Pattern ? (Pattern) value : Pattern.compile((String) value); + } +} + diff --git a/profile/src/main/java/com/scottlogic/deg/profile/reader/validators/CreateConstraintsValidator.java b/profile/src/main/java/com/scottlogic/deg/profile/reader/validators/CreateConstraintsValidator.java new file mode 100644 index 000000000..ec9d6eef6 --- /dev/null +++ b/profile/src/main/java/com/scottlogic/deg/profile/reader/validators/CreateConstraintsValidator.java @@ -0,0 +1,15 @@ +package com.scottlogic.deg.profile.reader.validators; + +import com.scottlogic.deg.common.validators.ValidationResult; +import com.scottlogic.deg.common.validators.Validator; +import com.scottlogic.deg.profile.reader.commands.CreateConstraints; + +public class CreateConstraintsValidator implements Validator +{ + @Override + public ValidationResult validate(CreateConstraints createConstraints) + { + //TODO + return ValidationResult.success(); + } +} diff --git a/profile/src/main/java/com/scottlogic/deg/profile/reader/validators/CreateFieldsValidator.java b/profile/src/main/java/com/scottlogic/deg/profile/reader/validators/CreateFieldsValidator.java new file mode 100644 index 000000000..62bd2c16d --- /dev/null +++ b/profile/src/main/java/com/scottlogic/deg/profile/reader/validators/CreateFieldsValidator.java @@ -0,0 +1,15 @@ +package com.scottlogic.deg.profile.reader.validators; + +import com.scottlogic.deg.common.validators.ValidationResult; +import com.scottlogic.deg.common.validators.Validator; +import com.scottlogic.deg.profile.reader.commands.CreateFields; + +public class CreateFieldsValidator implements Validator +{ + @Override + public ValidationResult validate(CreateFields createFields) + { + //TODO + return ValidationResult.success(); + } +} diff --git a/profile/src/main/java/com/scottlogic/deg/profile/reader/validators/CreateProfileValidator.java b/profile/src/main/java/com/scottlogic/deg/profile/reader/validators/CreateProfileValidator.java new file mode 100644 index 000000000..2c5c1e3ab --- /dev/null +++ b/profile/src/main/java/com/scottlogic/deg/profile/reader/validators/CreateProfileValidator.java @@ -0,0 +1,15 @@ +package com.scottlogic.deg.profile.reader.validators; + +import com.scottlogic.deg.common.validators.ValidationResult; +import com.scottlogic.deg.common.validators.Validator; +import com.scottlogic.deg.profile.reader.commands.CreateProfile; + +public class CreateProfileValidator implements Validator +{ + @Override + public ValidationResult validate(CreateProfile createProfile) + { + //TODO + return ValidationResult.success(); + } +} diff --git a/profile/src/main/java/com/scottlogic/deg/profile/ConstraintDeserializer.java b/profile/src/main/java/com/scottlogic/deg/profile/serialisation/ConstraintDeserializer.java similarity index 90% rename from profile/src/main/java/com/scottlogic/deg/profile/ConstraintDeserializer.java rename to profile/src/main/java/com/scottlogic/deg/profile/serialisation/ConstraintDeserializer.java index 65739998c..a79aa9e88 100644 --- a/profile/src/main/java/com/scottlogic/deg/profile/ConstraintDeserializer.java +++ b/profile/src/main/java/com/scottlogic/deg/profile/serialisation/ConstraintDeserializer.java @@ -1,4 +1,4 @@ -package com.scottlogic.deg.profile; +package com.scottlogic.deg.profile.serialisation; import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.databind.DeserializationContext; @@ -8,6 +8,11 @@ import com.scottlogic.deg.profile.common.ConstraintType; import com.scottlogic.deg.profile.common.ConstraintTypeJsonProperty; import com.scottlogic.deg.profile.dtos.constraints.*; +import com.scottlogic.deg.profile.dtos.constraints.atomic.*; +import com.scottlogic.deg.profile.dtos.constraints.grammatical.AllOfConstraintDTO; +import com.scottlogic.deg.profile.dtos.constraints.grammatical.AnyOfConstraintDTO; +import com.scottlogic.deg.profile.dtos.constraints.grammatical.ConditionalConstraintDTO; +import com.scottlogic.deg.profile.dtos.constraints.relations.*; import com.scottlogic.deg.profile.reader.InvalidProfileException; import java.io.IOException; @@ -39,7 +44,7 @@ public ConstraintDTO deserialize(JsonParser jsonParser, DeserializationContext c case IN_MAP: return mapper.treeToValue(node, InMapConstraintDTO.class); case IS_NULL: - return mapper.treeToValue(node, NullConstraintDTO.class); + return mapper.treeToValue(node, IsNullConstraintDTO.class); case GRANULAR_TO: return mapper.treeToValue(node, GranularToConstraintDTO.class); case MATCHES_REGEX: @@ -92,7 +97,7 @@ public ConstraintDTO deserialize(JsonParser jsonParser, DeserializationContext c return mapper.treeToValue(node, AllOfConstraintDTO.class); case IF: if (node.hasNonNull(ConstraintTypeJsonProperty.THEN)) { - return mapper.treeToValue(node, IfConstraintDTO.class); + return mapper.treeToValue(node, ConditionalConstraintDTO.class); } throw new InvalidProfileException("If constraint types require a then property: " + node); default: diff --git a/profile/src/test/java/com/scottlogic/deg/profile/AtomicConstraintDeserialiserTests.java b/profile/src/test/java/com/scottlogic/deg/profile/AtomicConstraintDeserialiserTests.java index 78f04718a..146da7b74 100644 --- a/profile/src/test/java/com/scottlogic/deg/profile/AtomicConstraintDeserialiserTests.java +++ b/profile/src/test/java/com/scottlogic/deg/profile/AtomicConstraintDeserialiserTests.java @@ -19,6 +19,8 @@ import com.fasterxml.jackson.core.JsonParseException; import com.fasterxml.jackson.databind.ObjectMapper; import com.scottlogic.deg.profile.dtos.constraints.*; +import com.scottlogic.deg.profile.dtos.constraints.atomic.*; +import com.scottlogic.deg.profile.dtos.constraints.relations.*; import com.scottlogic.deg.profile.reader.InvalidProfileException; import org.junit.Assert; import org.junit.Rule; @@ -138,7 +140,7 @@ public void shouldDeserialiseNullWithoutException() throws IOException { ConstraintDTO actual = deserialiseJsonString(json); // Assert - NullConstraintDTO expected = new NullConstraintDTO(); + IsNullConstraintDTO expected = new IsNullConstraintDTO(); expected.field = "country"; expected.isNull = true; diff --git a/profile/src/test/java/com/scottlogic/deg/profile/GrammaticalConstraintDeserialiserTests.java b/profile/src/test/java/com/scottlogic/deg/profile/GrammaticalConstraintDeserialiserTests.java index d6a24310f..fbb76ae69 100644 --- a/profile/src/test/java/com/scottlogic/deg/profile/GrammaticalConstraintDeserialiserTests.java +++ b/profile/src/test/java/com/scottlogic/deg/profile/GrammaticalConstraintDeserialiserTests.java @@ -21,6 +21,13 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException; import com.scottlogic.deg.profile.dtos.constraints.*; +import com.scottlogic.deg.profile.dtos.constraints.atomic.EqualToConstraintDTO; +import com.scottlogic.deg.profile.dtos.constraints.atomic.GreaterThanConstraintDTO; +import com.scottlogic.deg.profile.dtos.constraints.atomic.LessThanConstraintDTO; +import com.scottlogic.deg.profile.dtos.constraints.atomic.IsNullConstraintDTO; +import com.scottlogic.deg.profile.dtos.constraints.grammatical.AllOfConstraintDTO; +import com.scottlogic.deg.profile.dtos.constraints.grammatical.AnyOfConstraintDTO; +import com.scottlogic.deg.profile.dtos.constraints.grammatical.ConditionalConstraintDTO; import com.scottlogic.deg.profile.reader.InvalidProfileException; import org.junit.Assert; import org.junit.jupiter.api.Test; @@ -49,7 +56,7 @@ public void shouldDeserialiseAnyOfWithoutException() throws IOException { EqualToConstraintDTO expectedEqualsTo = new EqualToConstraintDTO(); expectedEqualsTo.field = "foo"; expectedEqualsTo.value = "0"; - NullConstraintDTO expectedNull = new NullConstraintDTO(); + IsNullConstraintDTO expectedNull = new IsNullConstraintDTO(); expectedNull.field = "foo"; expectedNull.isNull = true; @@ -73,7 +80,7 @@ public void shouldDeserialiseAnyOfAndThrowInvalidFieldException() throws IOExcep deserialiseJsonString(json); Assert.fail("should have thrown an exception"); } catch (UnrecognizedPropertyException e) { - String expectedMessage = "Unrecognized field \"fild\" (class com.scottlogic.deg.profile.dtos.constraints.EqualToConstraintDTO), not marked as ignorable (2 known properties: \"field\", \"equalTo\"])\n at [Source: UNKNOWN; line: -1, column: -1] (through reference chain: com.scottlogic.deg.profile.dtos.constraints.AnyOfConstraintDTO[\"anyOf\"]->java.util.ArrayList[0]->com.scottlogic.deg.profile.dtos.constraints.EqualToConstraintDTO[\"fild\"])"; + String expectedMessage = "Unrecognized field \"fild\" (class com.scottlogic.deg.profile.dtos.constraints.atomic.EqualToConstraintDTO), not marked as ignorable (2 known properties: \"field\", \"equalTo\"])\n at [Source: UNKNOWN; line: -1, column: -1] (through reference chain: com.scottlogic.deg.profile.dtos.constraints.grammatical.AnyOfConstraintDTO[\"anyOf\"]->java.util.ArrayList[0]->com.scottlogic.deg.profile.dtos.constraints.atomic.EqualToConstraintDTO[\"fild\"])"; assertThat(e.getMessage(), sameBeanAs(expectedMessage)); } } @@ -111,7 +118,7 @@ public void shouldDeserialiseAnyOfAndThrowInvalidConstraintValueException() thro deserialiseJsonString(json); Assert.fail("should have thrown an exception"); } catch (JsonMappingException e) { - String expectedMessage = "The constraint json object node for field foo doesn't contain any of the expected keywords as properties: {\"field\":\"foo\",\"isNll\":\"true\"} (through reference chain: com.scottlogic.deg.profile.dtos.constraints.AnyOfConstraintDTO[\"anyOf\"]->java.util.ArrayList[1])"; + String expectedMessage = "The constraint json object node for field foo doesn't contain any of the expected keywords as properties: {\"field\":\"foo\",\"isNll\":\"true\"} (through reference chain: com.scottlogic.deg.profile.dtos.constraints.grammatical.AnyOfConstraintDTO[\"anyOf\"]->java.util.ArrayList[1])"; assertThat(e.getMessage(), sameBeanAs(expectedMessage)); } } @@ -152,7 +159,7 @@ public void shouldDeserialiseNotWithoutException() throws IOException { ConstraintDTO actual = deserialiseJsonString(json); // Assert - NullConstraintDTO expectedNull = new NullConstraintDTO(); + IsNullConstraintDTO expectedNull = new IsNullConstraintDTO(); expectedNull.field = "foo"; expectedNull.isNull = true; @@ -184,7 +191,7 @@ public void shouldDeserialiseIfWithoutException() throws IOException { expectedEqualTo.field = "bar"; expectedEqualTo.value = "500"; - IfConstraintDTO expected= new IfConstraintDTO(); + ConditionalConstraintDTO expected= new ConditionalConstraintDTO(); expected.ifConstraint = expectedLessThan; expected.thenConstraint = expectedGreaterThan; diff --git a/profile/src/test/java/com/scottlogic/deg/profile/ProfileSchemaImmutabilityTests.java b/profile/src/test/java/com/scottlogic/deg/profile/ProfileSchemaImmutabilityTests.java index b8737bc72..8be968a1b 100644 --- a/profile/src/test/java/com/scottlogic/deg/profile/ProfileSchemaImmutabilityTests.java +++ b/profile/src/test/java/com/scottlogic/deg/profile/ProfileSchemaImmutabilityTests.java @@ -16,7 +16,6 @@ package com.scottlogic.deg.profile; -import com.scottlogic.deg.profile.dtos.SupportedVersionsGetter; import org.apache.commons.io.IOUtils; import org.junit.jupiter.api.Test; import org.leadpony.justify.api.JsonSchema; diff --git a/profile/src/test/java/com/scottlogic/deg/profile/ProfileSerialiserTests.java b/profile/src/test/java/com/scottlogic/deg/profile/ProfileSerialiserTests.java deleted file mode 100644 index 9dc463a95..000000000 --- a/profile/src/test/java/com/scottlogic/deg/profile/ProfileSerialiserTests.java +++ /dev/null @@ -1,126 +0,0 @@ -/* - * Copyright 2019 Scott Logic Ltd - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.scottlogic.deg.profile; - -import com.scottlogic.deg.profile.dtos.ProfileDTO; -import com.scottlogic.deg.profile.serialisation.ProfileSerialiser; -import org.junit.jupiter.api.Test; - -import java.io.IOException; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -public class ProfileSerialiserTests -{ - @Test - public void shouldDeserialisev0_1ProfileWithoutException() throws IOException { - // Arrange - final String json = "{" + - " \"schemaVersion\" : \"0.1\"," + - " \"fields\": [" + - " { \"name\": \"id\" }," + - " { \"name\": \"type\" }," + - " { \"name\": \"time\" }," + - " { \"name\": \"country\" }," + - " { \"name\": \"tariff\" }," + - " { \"name\": \"low_price\" }," + - " { \"name\": \"high_price\" }" + - " ]," + - " \"rules\": [" + - " { \"field\": \"id\", \"is\": \"ofType\", \"value\": \"datetime\" }," + - " { \"not\": { \"field\": \"id\", \"is\": \"null\" } }," + - - " { \"field\": \"low_price\", \"is\": \"ofType\", \"value\": \"numeric\" }," + - " { \"not\": { \"field\": \"low_price\", \"is\": \"null\" } }," + - " { \"field\": \"low_price\", \"is\": \"greaterThanOrEqual\", \"value\": \"0\" }," + - - " {" + - " \"rule\": \"Some rule\"," + - " \"constraints\": [" + - " { \"field\": \"country\", \"inSet\": [ \"USA\", \"GB\", \"FRANCE\" ] }" + - " ]" + - " }," + - - " {" + - " \"if\": {" + - " \"anyOf\": [" + - " { \"field\": \"type\", \"equalTo\": \"USA\" }," + - " { \"field\": \"type\", \"is\": \"null\" }" + - " ]" + - " }," + - " \"then\": { \"field\": \"tariff\", \"is\": \"null\" }," + - " \"else\": { \"not\": { \"field\": \"tariff\", \"is\": \"null\" } }" + - " }" + - " ]" + - "}"; - - // Act - final ProfileDTO profile = new ProfileSerialiser().deserialise(json); - - // Assert - assertEquals("0.1", profile.schemaVersion); - } - @Test - public void shouldDeserialisev0_2ProfileWithoutException() throws IOException { - // Arrange - final String json = "{" + - " \"schemaVersion\" : \"0.2\"," + - " \"fields\": [" + - " { \"name\": \"id\" }," + - " { \"name\": \"type\" }," + - " { \"name\": \"time\" }," + - " { \"name\": \"country\" }," + - " { \"name\": \"tariff\" }," + - " { \"name\": \"low_price\" }," + - " { \"name\": \"high_price\" }" + - " ]," + - " \"rules\": [" + - " { \"field\": \"id\", \"is\": \"ofType\", \"value\": \"datetime\" }," + - " { \"not\": { \"field\": \"id\", \"is\": \"null\" } }," + - " { \"field\": \"id\", \"is\": \"unique\" }," + - - " { \"field\": \"low_price\", \"is\": \"ofType\", \"value\": \"numeric\" }," + - " { \"not\": { \"field\": \"low_price\", \"is\": \"null\" } }," + - " { \"field\": \"low_price\", \"is\": \"greaterThanOrEqual\", \"value\": \"0\" }," + - - " {" + - " \"rule\": \"Some rule\"," + - " \"constraints\": [" + - " { \"field\": \"country\", \"inSet\": [ \"USA\", \"GB\", \"FRANCE\" ] }" + - " ]" + - " }," + - - " {" + - " \"if\": {" + - " \"anyOf\": [" + - " { \"field\": \"type\", \"equalTo\": \"USA\" }," + - " { \"field\": \"type\", \"is\": \"null\" }" + - " ]" + - " }," + - " \"then\": { \"field\": \"tariff\", \"is\": \"null\" }," + - " \"else\": { \"not\": { \"field\": \"tariff\", \"is\": \"null\" } }" + - " }" + - " ]" + - "}"; - - // Act - final ProfileDTO profile = new ProfileSerialiser().deserialise(json); - - // Assert - assertEquals("0.2", profile.schemaVersion); - } -} diff --git a/profile/src/test/java/com/scottlogic/deg/profile/dtos/ProfileSchemaValidatorLeadPonyTests.java b/profile/src/test/java/com/scottlogic/deg/profile/dtos/ProfileSchemaValidatorLeadPonyTests.java index 039f9c087..cc8757169 100644 --- a/profile/src/test/java/com/scottlogic/deg/profile/dtos/ProfileSchemaValidatorLeadPonyTests.java +++ b/profile/src/test/java/com/scottlogic/deg/profile/dtos/ProfileSchemaValidatorLeadPonyTests.java @@ -16,6 +16,9 @@ package com.scottlogic.deg.profile.dtos; +import com.scottlogic.deg.profile.ProfileSchemaValidator; +import com.scottlogic.deg.profile.ProfileSchemaValidatorLeadPony; + class ProfileSchemaValidatorLeadPonyTests extends ProfileSchemaValidatorTests { private ProfileSchemaValidator profileValidator = new ProfileSchemaValidatorLeadPony(); diff --git a/profile/src/test/java/com/scottlogic/deg/profile/dtos/ProfileSchemaValidatorMedeiaTests.java b/profile/src/test/java/com/scottlogic/deg/profile/dtos/ProfileSchemaValidatorMedeiaTests.java index 5b885055b..926f9b7cb 100644 --- a/profile/src/test/java/com/scottlogic/deg/profile/dtos/ProfileSchemaValidatorMedeiaTests.java +++ b/profile/src/test/java/com/scottlogic/deg/profile/dtos/ProfileSchemaValidatorMedeiaTests.java @@ -16,6 +16,9 @@ package com.scottlogic.deg.profile.dtos; +import com.scottlogic.deg.profile.ProfileSchemaValidator; +import com.scottlogic.deg.profile.ProfileSchemaValidatorMedeia; + class ProfileSchemaValidatorMedeiaTests extends ProfileSchemaValidatorTests { private ProfileSchemaValidator profileValidator = new ProfileSchemaValidatorMedeia(); diff --git a/profile/src/test/java/com/scottlogic/deg/profile/dtos/ProfileSchemaValidatorTests.java b/profile/src/test/java/com/scottlogic/deg/profile/dtos/ProfileSchemaValidatorTests.java index 98bd0cd7b..525c3e597 100644 --- a/profile/src/test/java/com/scottlogic/deg/profile/dtos/ProfileSchemaValidatorTests.java +++ b/profile/src/test/java/com/scottlogic/deg/profile/dtos/ProfileSchemaValidatorTests.java @@ -17,6 +17,7 @@ package com.scottlogic.deg.profile.dtos; import com.scottlogic.deg.common.ValidationException; +import com.scottlogic.deg.profile.ProfileSchemaValidator; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.leadpony.justify.api.JsonSchema; diff --git a/profile/src/test/java/com/scottlogic/deg/profile/dtos/SupportedVersionCheckerTests.java b/profile/src/test/java/com/scottlogic/deg/profile/dtos/SupportedVersionCheckerTests.java index 4b12b75bd..2e7ab2ac3 100644 --- a/profile/src/test/java/com/scottlogic/deg/profile/dtos/SupportedVersionCheckerTests.java +++ b/profile/src/test/java/com/scottlogic/deg/profile/dtos/SupportedVersionCheckerTests.java @@ -17,8 +17,10 @@ package com.scottlogic.deg.profile.dtos; import com.scottlogic.deg.common.ValidationException; +import com.scottlogic.deg.profile.SupportedVersionChecker; +import com.scottlogic.deg.profile.SupportedVersionsGetter; import com.scottlogic.deg.profile.guice.ProfileConfigSource; -import com.scottlogic.deg.profile.serialisation.SchemaVersionGetter; +import com.scottlogic.deg.profile.SchemaVersionGetter; import org.junit.jupiter.api.Test; import java.io.File; diff --git a/profile/src/test/java/com/scottlogic/deg/profile/dtos/SupportedVersionsGetterTests.java b/profile/src/test/java/com/scottlogic/deg/profile/dtos/SupportedVersionsGetterTests.java index d8e559c94..4d9924899 100644 --- a/profile/src/test/java/com/scottlogic/deg/profile/dtos/SupportedVersionsGetterTests.java +++ b/profile/src/test/java/com/scottlogic/deg/profile/dtos/SupportedVersionsGetterTests.java @@ -16,6 +16,7 @@ package com.scottlogic.deg.profile.dtos; +import com.scottlogic.deg.profile.SupportedVersionsGetter; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.*; diff --git a/profile/src/test/java/com/scottlogic/deg/profile/reader/JsonProfileReaderTests.java b/profile/src/test/java/com/scottlogic/deg/profile/reader/JsonProfileReaderTests.java index e0eea541b..f9e9cb40c 100644 --- a/profile/src/test/java/com/scottlogic/deg/profile/reader/JsonProfileReaderTests.java +++ b/profile/src/test/java/com/scottlogic/deg/profile/reader/JsonProfileReaderTests.java @@ -30,7 +30,7 @@ import com.scottlogic.deg.generator.profile.constraints.grammatical.AndConstraint; import com.scottlogic.deg.generator.profile.constraints.grammatical.ConditionalConstraint; import com.scottlogic.deg.generator.profile.constraints.grammatical.OrConstraint; -import com.scottlogic.deg.profile.reader.AtomicConstraintFactory.AtomicConstraintReader; +import com.scottlogic.deg.profile.ProfileCommandBus; import org.junit.Assert; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; @@ -78,7 +78,8 @@ public DistributedList listFromMapFile(String file, String Key) private final String schemaVersion = "\"0.7\""; private String json; - private JsonProfileReader jsonProfileReader = new JsonProfileReader(null, new ConstraintReader(new AtomicConstraintReader(new MockFromFileReader()))); + private JsonProfileReader jsonProfileReader = new JsonProfileReader(null, + new ProfileCommandBus(new MockFromFileReader())); @@ -100,7 +101,7 @@ private void expectRules(Consumer... ruleAssertions) throws IOException { } private Consumer ruleWithDescription(String expectedDescription) { - return rule -> Assert.assertThat(rule.getRuleInformation().getDescription(), equalTo(expectedDescription)); + return rule -> Assert.assertThat(rule.getDescription(), equalTo(expectedDescription)); } private Consumer ruleWithConstraints(Consumer... constraintAsserters) { @@ -116,7 +117,7 @@ private Consumer typedConstraint(Class constraintType, Consum } private Consumer fieldWithName(String expectedName) { - return field -> Assert.assertThat(field.name, equalTo(expectedName)); + return field -> Assert.assertThat(field.getName(), equalTo(expectedName)); } private void expectFields(Consumer... fieldAssertions) throws IOException { @@ -191,7 +192,7 @@ public void shouldGiveDefaultNameToUnnamedRules() throws IOException { ruleWithDescription("Unnamed rule")); expectFields( field -> { - Assert.assertThat(field.name, equalTo("foo")); + Assert.assertThat(field.getName(), equalTo("foo")); Assert.assertEquals(field.getType(), FieldType.STRING); }); } @@ -268,7 +269,7 @@ public void shouldDeserialiseIsOfTypeConstraint() throws IOException { expectRules(); expectFields( field -> { - Assert.assertThat(field.name, equalTo("foo")); + Assert.assertThat(field.getName(), equalTo("foo")); Assert.assertEquals(field.getType(), FieldType.STRING); }); } @@ -286,7 +287,7 @@ public void shouldDeserialiseIsOfTypeConstraint_whenInteger() throws IOException expectRules( ruleWithConstraints( typedConstraint( - IsGranularToNumericConstraint.class, + GranularToNumericConstraint.class, c -> { Assert.assertThat( c.granularity, @@ -336,7 +337,7 @@ public void shouldDeserialiseFormatConstraint() throws IOException { expectFields( field -> { - Assert.assertThat(field.name, equalTo("foo")); + Assert.assertThat(field.getName(), equalTo("foo")); Assert.assertThat(field.getFormatting(), equalTo("%.5s")); } ); @@ -360,7 +361,7 @@ public void shouldDeserialiseIsOfLengthConstraint() throws IOException { expectRules( ruleWithConstraints( typedConstraint( - StringHasLengthConstraint.class, + OfLengthConstraint.class, c -> Assert.assertThat(c.referenceValue.getValue(), equalTo(5))))); } @@ -479,11 +480,11 @@ public void shouldDeserialiseIfConstraint() throws IOException { Assert.assertThat( c.whenConditionIsTrue, - instanceOf(IsInSetConstraint.class)); + instanceOf(InSetConstraint.class)); Assert.assertThat( c.whenConditionIsFalse, - instanceOf(IsStringLongerThanConstraint.class)); + instanceOf(LongerThanConstraint.class)); }))); } @@ -542,7 +543,7 @@ public void shouldDeserialiseOneAsNumericGranularToConstraint() throws IOExcepti expectRules( ruleWithConstraints( typedConstraint( - IsGranularToNumericConstraint.class, + GranularToNumericConstraint.class, c -> { Assert.assertThat( c.granularity, @@ -568,7 +569,7 @@ public void shouldDeserialiseTenthAsNumericGranularToConstraint() throws IOExcep expectRules( ruleWithConstraints( typedConstraint( - IsGranularToNumericConstraint.class, + GranularToNumericConstraint.class, c -> { Assert.assertThat( c.granularity, @@ -594,7 +595,7 @@ public void shouldDisregardTrailingZeroesInNumericGranularities() throws IOExcep expectRules( ruleWithConstraints( typedConstraint( - IsGranularToNumericConstraint.class, + GranularToNumericConstraint.class, c -> { Assert.assertThat( c.granularity, @@ -621,12 +622,12 @@ public void shouldAllowValidISO8601DateTime() throws IOException { expectRules( rule -> { // This is different because the ordering would switch depending on if the whole file was run or just this test - IsAfterOrEqualToConstantDateTimeConstraint isAfter = (IsAfterOrEqualToConstantDateTimeConstraint) rule.getConstraints().stream() - .filter(f -> f.getClass() == IsAfterOrEqualToConstantDateTimeConstraint.class) + AfterOrAtConstraint isAfter = (AfterOrAtConstraint) rule.getConstraints().stream() + .filter(f -> f.getClass() == AfterOrAtConstraint.class) .findFirst() .get(); - IsBeforeConstantDateTimeConstraint isBefore = (IsBeforeConstantDateTimeConstraint) rule.getConstraints().stream() - .filter(f -> f.getClass() == IsBeforeConstantDateTimeConstraint.class) + BeforeConstraint isBefore = (BeforeConstraint) rule.getConstraints().stream() + .filter(f -> f.getClass() == BeforeConstraint.class) .findFirst() .get(); Assert.assertEquals(OffsetDateTime.parse("2019-01-01T00:00:00.000Z"), isAfter.referenceValue.getValue()); @@ -776,7 +777,7 @@ public void unique_setsFieldPropertyToTrue_whenSetToTrue() throws IOException { expectFields( field -> { - Assert.assertThat(field.name, equalTo("foo")); + Assert.assertThat(field.getName(), equalTo("foo")); Assert.assertTrue(field.isUnique()); } ); @@ -795,7 +796,7 @@ public void unique_setsFieldPropertyToFalse_whenOmitted() throws IOException { "}"); expectFields( field -> { - Assert.assertThat(field.name, equalTo("foo")); + Assert.assertThat(field.getName(), equalTo("foo")); Assert.assertFalse(field.isUnique()); } ); @@ -816,7 +817,7 @@ public void unique_setsFieldPropertyToFalse_whenSetToFalse() throws IOException expectFields( field -> { - Assert.assertThat(field.name, equalTo("foo")); + Assert.assertThat(field.getName(), equalTo("foo")); Assert.assertFalse(field.isUnique()); } ); @@ -841,12 +842,12 @@ public void nullable_addsConstraintForField_whenSetToFalse() throws IOException NotNullConstraint.class, c -> { Assert.assertEquals( - c.getField().name, + c.getField().getName(), "foo"); } ) ), - ruleWithDescription("type-rules") + ruleWithDescription("specific-types") ); } @@ -863,7 +864,7 @@ public void nullable_DoesNotAddConstraintForField_whenSetToTrue() throws IOExcep " \"rules\": []" + "}"); - expectRules(ruleWithDescription("type-rules")); + expectRules(ruleWithDescription("specific-types")); } @Test @@ -889,7 +890,7 @@ public void nullable_addsConstraintForFields_whenSetToFalse() throws IOException NotNullConstraint.class, c -> { Assert.assertEquals( - c.getField().name, + c.getField().getName(), "foo"); } ), @@ -897,12 +898,12 @@ public void nullable_addsConstraintForFields_whenSetToFalse() throws IOException NotNullConstraint.class, c -> { Assert.assertEquals( - c.getField().name, + c.getField().getName(), "bar"); } ) ), - ruleWithDescription("type-rules") + ruleWithDescription("specific-types") ); } @@ -929,12 +930,12 @@ public void nullable_addsConstraintForFields_whenOneSetToFalse() throws IOExcept NotNullConstraint.class, c -> { Assert.assertEquals( - c.getField().name, + c.getField().getName(), "bar"); } ) ), - ruleWithDescription("type-rules") + ruleWithDescription("specific-types") ); } @@ -991,15 +992,15 @@ void parser_createsInternalField_whenProfileHasAnInMapConstraint() throws IOExce expectFields( field -> { - Assert.assertEquals("foo", field.name); + Assert.assertEquals("foo", field.getName()); Assert.assertFalse(field.isInternal()); }, field -> { - Assert.assertEquals("bar", field.name); + Assert.assertEquals("bar", field.getName()); Assert.assertFalse(field.isInternal()); }, field -> { - Assert.assertEquals("foobar.csv", field.name); + Assert.assertEquals("foobar.csv", field.getName()); Assert.assertTrue(field.isInternal()); } ); @@ -1041,19 +1042,19 @@ void parser_createsInternalField_whenProfileHasANestedInMapConstraint() throws I expectFields( field -> { - Assert.assertEquals("foo", field.name); + Assert.assertEquals("foo", field.getName()); Assert.assertFalse(field.isInternal()); }, field -> { - Assert.assertEquals("bar", field.name); + Assert.assertEquals("bar", field.getName()); Assert.assertFalse(field.isInternal()); }, field -> { - Assert.assertEquals("other", field.name); + Assert.assertEquals("other", field.getName()); Assert.assertFalse(field.isInternal()); }, field -> { - Assert.assertEquals("foobar.csv", field.name); + Assert.assertEquals("foobar.csv", field.getName()); Assert.assertTrue(field.isInternal()); Assert.assertEquals(FieldType.NUMERIC, field.getType()); } @@ -1076,7 +1077,7 @@ public void formatting_withDateType_shouldSetCorrectGranularity() throws IOExcep expectRules( ruleWithConstraints( typedConstraint( - IsGranularToDateConstraint.class, + GranularToDateConstraint.class, c -> Assert.assertThat(c.granularity, equalTo(new DateTimeGranularity(ChronoUnit.DAYS))) ) ) diff --git a/profile/src/test/java/com/scottlogic/deg/profile/reader/atomic/FieldReaderTest.java b/profile/src/test/java/com/scottlogic/deg/profile/reader/atomic/FieldReaderTest.java deleted file mode 100644 index f8b9c4e12..000000000 --- a/profile/src/test/java/com/scottlogic/deg/profile/reader/atomic/FieldReaderTest.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Copyright 2019 Scott Logic Ltd - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -package com.scottlogic.deg.profile.reader.atomic; - -import com.scottlogic.deg.common.profile.*; -import com.scottlogic.deg.generator.profile.constraints.Constraint; -import com.scottlogic.deg.generator.profile.constraints.atomic.*; -import com.scottlogic.deg.profile.reader.file.names.NameRetriever; -import org.junit.jupiter.api.Test; - -import java.time.temporal.ChronoUnit; -import java.util.Optional; - -import static org.junit.jupiter.api.Assertions.*; - -class FieldReaderTest -{ - - private Field field = FieldBuilder.createField("test"); - - @Test - void returnsNullWhenPassedDecimalLowerCase() { - Optional constraint = FieldReader.read(field, SpecificFieldType.DECIMAL); - assertFalse(constraint.isPresent()); - } - - @Test - void returnsGranularToOneWhenPassedInteger() { - Optional constraint = FieldReader.read(field,SpecificFieldType.INTEGER); - assertTrue(constraint.isPresent()); - assertEquals(((IsGranularToNumericConstraint) constraint.get()).granularity, new NumericGranularity(0)); - } - - @Test - void returnsStandardRICConstraintWhenPassedUpperCaseRIC() { - Optional constraint = FieldReader.read(field,SpecificFieldType.RIC); - assertTrue(constraint.isPresent()); - assertEquals(((MatchesStandardConstraint) constraint.get()).standard, StandardConstraintTypes.RIC); - } - - @Test - void returnsInSetConstraintWhenPassedLowerCaseFullName() { - Optional constraint = FieldReader.read(field,SpecificFieldType.FULL_NAME); - IsInSetConstraint isInSetConstraint = new IsInSetConstraint( - field, - NameRetriever.loadNamesFromFile(NameConstraintTypes.lookupProfileText("fullname")) - ); - - assertTrue(constraint.isPresent()); - assertEquals((constraint.get()), isInSetConstraint); - } - - @Test - void returnsGranularToDateConstraintWhenPassedDate() { - Optional constraint = FieldReader.read(field,SpecificFieldType.DATE); - IsGranularToDateConstraint isGranularToDateConstraint = new IsGranularToDateConstraint( - field, - new DateTimeGranularity(ChronoUnit.DAYS) - ); - - assertTrue(constraint.isPresent()); - assertEquals((constraint.get()), isGranularToDateConstraint); - } -} \ No newline at end of file diff --git a/profile/src/test/java/com/scottlogic/deg/profile/reader/file/CsvInputStreamReaderTest.java b/profile/src/test/java/com/scottlogic/deg/profile/reader/file/CsvInputStreamReaderTest.java index 9858c6c5c..cff0a5882 100644 --- a/profile/src/test/java/com/scottlogic/deg/profile/reader/file/CsvInputStreamReaderTest.java +++ b/profile/src/test/java/com/scottlogic/deg/profile/reader/file/CsvInputStreamReaderTest.java @@ -2,6 +2,7 @@ import com.scottlogic.deg.generator.fieldspecs.whitelist.DistributedList; import com.scottlogic.deg.generator.fieldspecs.whitelist.WeightedElement; +import com.scottlogic.deg.profile.reader.CsvInputStreamReader; import org.junit.jupiter.api.Test; import java.io.InputStream; diff --git a/profile/src/test/java/com/scottlogic/deg/profile/reader/file/names/NameRetrieverTest.java b/profile/src/test/java/com/scottlogic/deg/profile/reader/file/names/NameRetrieverTest.java index 14889d47f..c6b1f7494 100644 --- a/profile/src/test/java/com/scottlogic/deg/profile/reader/file/names/NameRetrieverTest.java +++ b/profile/src/test/java/com/scottlogic/deg/profile/reader/file/names/NameRetrieverTest.java @@ -19,6 +19,7 @@ import com.scottlogic.deg.generator.profile.constraints.atomic.NameConstraintTypes; import com.scottlogic.deg.generator.fieldspecs.whitelist.DistributedList; +import com.scottlogic.deg.profile.reader.NameRetriever; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.EnumSource;