From 1c33ab829a57435eb1619510e4a5607610942f08 Mon Sep 17 00:00:00 2001 From: Charlton Dowding Date: Thu, 7 Nov 2019 13:53:58 +0000 Subject: [PATCH 01/10] Removed HelixNumber --- .../deg/common/profile/HelixNumber.java | 58 ------------------- .../atomic/GreaterThanConstraint.java | 7 +-- .../GreaterThanOrEqualToConstraint.java | 7 +-- .../atomic/LessThanConstraint.java | 7 +-- .../atomic/LessThanOrEqualToConstraint.java | 7 +-- .../builders/ConstraintChainBuilder.java | 6 +- .../DecisionTreeFactoryTests.java | 40 ++++++------- .../reducer/ConstraintReducerTest.java | 20 +++---- .../ConstraintTypeViolationFilterTests.java | 4 +- .../violator/ProfileViolationTests.java | 14 +++-- .../violator/ProfileViolatorTests.java | 10 ++-- .../violate/violator/RuleViolatorTests.java | 8 +-- .../NumericConstraintFactory.java | 9 ++- .../profile/ConstraintValidator.java | 2 + .../atomic/AtomicConstraintValidator.java | 13 ++--- .../atomic/EqualToConstraintValidator.java | 2 +- .../atomic/GranularToConstraintValidator.java | 2 +- .../atomic/InSetConstraintValidator.java | 2 +- .../atomic/NumericConstraintValidator.java | 34 ++++++++--- .../atomic/RegexConstraintValidator.java | 2 +- .../atomic/TemporalConstraintValidator.java | 2 +- 21 files changed, 107 insertions(+), 149 deletions(-) diff --git a/common/src/main/java/com/scottlogic/deg/common/profile/HelixNumber.java b/common/src/main/java/com/scottlogic/deg/common/profile/HelixNumber.java index 338706087..e69de29bb 100644 --- a/common/src/main/java/com/scottlogic/deg/common/profile/HelixNumber.java +++ b/common/src/main/java/com/scottlogic/deg/common/profile/HelixNumber.java @@ -1,58 +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.common.profile; - -import com.scottlogic.deg.common.ValidationException; -import com.scottlogic.deg.common.util.NumberUtils; -import com.scottlogic.deg.common.util.defaults.NumericDefaults; - -import java.math.BigDecimal; - -public class HelixNumber -{ - private final BigDecimal value; - - private HelixNumber(BigDecimal value) - { - this.value = value; - } - - public static HelixNumber create(Object value) - { - BigDecimal number = NumberUtils.coerceToBigDecimal(value); - validateNumberRange(number); - return new HelixNumber(number); - } - - public BigDecimal getValue() - { - return value; - } - - private static void validateNumberRange(BigDecimal number) - { - BigDecimal max = NumericDefaults.get().max(); - BigDecimal min = NumericDefaults.get().min(); - if (number.compareTo(min) < 0) - { - throw new ValidationException(String.format("Number must have a value >= %s, currently is %s", min.toPlainString(), number.toPlainString())); - } - if (number.compareTo(max) > 0) - { - throw new ValidationException(String.format("Number must have a value <= %s, currently is %s", max.toPlainString(), number.toPlainString())); - } - } -} diff --git a/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/GreaterThanConstraint.java b/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/GreaterThanConstraint.java index 9eab3b8bb..4faf1a3e5 100644 --- a/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/GreaterThanConstraint.java +++ b/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/GreaterThanConstraint.java @@ -17,7 +17,6 @@ package com.scottlogic.deg.generator.profile.constraints.atomic; import com.scottlogic.deg.common.profile.Field; -import com.scottlogic.deg.common.profile.HelixNumber; import com.scottlogic.deg.generator.fieldspecs.FieldSpec; import com.scottlogic.deg.generator.fieldspecs.FieldSpecFactory; import com.scottlogic.deg.generator.restrictions.linear.Limit; @@ -31,9 +30,9 @@ public class GreaterThanConstraint implements AtomicConstraint { public final Field field; - public final HelixNumber referenceValue; + public final BigDecimal referenceValue; - public GreaterThanConstraint(Field field, HelixNumber referenceValue) { + public GreaterThanConstraint(Field field, BigDecimal referenceValue) { this.referenceValue = referenceValue; this.field = field; } @@ -50,7 +49,7 @@ public AtomicConstraint negate() { @Override public FieldSpec toFieldSpec() { - LinearRestrictions numericRestrictions = createNumericRestrictions(new Limit<>(referenceValue.getValue(), false), NUMERIC_MAX_LIMIT); + LinearRestrictions numericRestrictions = createNumericRestrictions(new Limit<>(referenceValue, false), NUMERIC_MAX_LIMIT); return FieldSpecFactory.fromRestriction(numericRestrictions); } diff --git a/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/GreaterThanOrEqualToConstraint.java b/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/GreaterThanOrEqualToConstraint.java index b949b3056..de10ca62d 100644 --- a/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/GreaterThanOrEqualToConstraint.java +++ b/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/GreaterThanOrEqualToConstraint.java @@ -17,7 +17,6 @@ package com.scottlogic.deg.generator.profile.constraints.atomic; import com.scottlogic.deg.common.profile.Field; -import com.scottlogic.deg.common.profile.HelixNumber; import com.scottlogic.deg.generator.fieldspecs.FieldSpec; import com.scottlogic.deg.generator.fieldspecs.FieldSpecFactory; import com.scottlogic.deg.generator.restrictions.linear.Limit; @@ -31,9 +30,9 @@ public class GreaterThanOrEqualToConstraint implements AtomicConstraint { public final Field field; - public final HelixNumber referenceValue; + public final BigDecimal referenceValue; - public GreaterThanOrEqualToConstraint(Field field, HelixNumber referenceValue) { + public GreaterThanOrEqualToConstraint(Field field, BigDecimal referenceValue) { this.referenceValue = referenceValue; this.field = field; } @@ -50,7 +49,7 @@ public AtomicConstraint negate() { @Override public FieldSpec toFieldSpec() { - LinearRestrictions numericRestrictions = createNumericRestrictions(new Limit<>(referenceValue.getValue(), true), NUMERIC_MAX_LIMIT); + LinearRestrictions numericRestrictions = createNumericRestrictions(new Limit<>(referenceValue, true), NUMERIC_MAX_LIMIT); return FieldSpecFactory.fromRestriction(numericRestrictions); } diff --git a/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/LessThanConstraint.java b/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/LessThanConstraint.java index 3a2f8c9cb..5e10a22d8 100644 --- a/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/LessThanConstraint.java +++ b/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/LessThanConstraint.java @@ -17,7 +17,6 @@ package com.scottlogic.deg.generator.profile.constraints.atomic; import com.scottlogic.deg.common.profile.Field; -import com.scottlogic.deg.common.profile.HelixNumber; import com.scottlogic.deg.generator.fieldspecs.FieldSpec; import com.scottlogic.deg.generator.fieldspecs.FieldSpecFactory; import com.scottlogic.deg.generator.restrictions.linear.Limit; @@ -31,9 +30,9 @@ public class LessThanConstraint implements AtomicConstraint { public final Field field; - public final HelixNumber referenceValue; + public final BigDecimal referenceValue; - public LessThanConstraint(Field field, HelixNumber referenceValue) { + public LessThanConstraint(Field field, BigDecimal referenceValue) { this.referenceValue = referenceValue; this.field = field; } @@ -50,7 +49,7 @@ public AtomicConstraint negate() { @Override public FieldSpec toFieldSpec() { - final LinearRestrictions numericRestrictions = createNumericRestrictions(NUMERIC_MIN_LIMIT, new Limit<>(referenceValue.getValue(), false)); + final LinearRestrictions numericRestrictions = createNumericRestrictions(NUMERIC_MIN_LIMIT, new Limit<>(referenceValue, false)); return FieldSpecFactory.fromRestriction(numericRestrictions); } diff --git a/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/LessThanOrEqualToConstraint.java b/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/LessThanOrEqualToConstraint.java index 31f4d711c..30b796002 100644 --- a/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/LessThanOrEqualToConstraint.java +++ b/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/LessThanOrEqualToConstraint.java @@ -17,7 +17,6 @@ package com.scottlogic.deg.generator.profile.constraints.atomic; import com.scottlogic.deg.common.profile.Field; -import com.scottlogic.deg.common.profile.HelixNumber; import com.scottlogic.deg.generator.fieldspecs.FieldSpec; import com.scottlogic.deg.generator.fieldspecs.FieldSpecFactory; import com.scottlogic.deg.generator.restrictions.linear.Limit; @@ -31,9 +30,9 @@ public class LessThanOrEqualToConstraint implements AtomicConstraint { public final Field field; - public final HelixNumber referenceValue; + public final BigDecimal referenceValue; - public LessThanOrEqualToConstraint(Field field, HelixNumber referenceValue) { + public LessThanOrEqualToConstraint(Field field, BigDecimal referenceValue) { this.referenceValue = referenceValue; this.field = field; } @@ -50,7 +49,7 @@ public AtomicConstraint negate() { @Override public FieldSpec toFieldSpec() { - final LinearRestrictions numericRestrictions = createNumericRestrictions(NUMERIC_MIN_LIMIT, new Limit<>(referenceValue.getValue(), true)); + final LinearRestrictions numericRestrictions = createNumericRestrictions(NUMERIC_MIN_LIMIT, new Limit<>(referenceValue, true)); return FieldSpecFactory.fromRestriction(numericRestrictions); } 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 95a23ce22..41185fa43 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 @@ -18,8 +18,8 @@ import com.scottlogic.deg.common.profile.Field; import com.scottlogic.deg.common.profile.HelixDateTime; -import com.scottlogic.deg.common.profile.HelixNumber; import com.scottlogic.deg.common.profile.HelixStringLength; +import com.scottlogic.deg.common.util.NumberUtils; import com.scottlogic.deg.generator.fieldspecs.whitelist.DistributedList; import com.scottlogic.deg.generator.profile.constraints.Constraint; import com.scottlogic.deg.generator.profile.constraints.atomic.*; @@ -97,11 +97,11 @@ public ConstraintChainBuilder appendBuilder(BaseConstraintBuilder withLessThanConstraint(Field field, int referenceValue) { - return saveAndSet(new LessThanConstraint(field, HelixNumber.create(referenceValue))); + return saveAndSet(new LessThanConstraint(field, NumberUtils.coerceToBigDecimal(referenceValue))); } public ConstraintChainBuilder withGreaterThanConstraint(Field field, int referenceValue) { - return saveAndSet(new GreaterThanConstraint(field, HelixNumber.create(referenceValue))); + return saveAndSet(new GreaterThanConstraint(field, NumberUtils.coerceToBigDecimal(referenceValue))); } public ConstraintChainBuilder withEqualToConstraint(Field barField, Object referenceValue) { 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 5ac3262c1..055aefe6a 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 @@ -17,8 +17,8 @@ package com.scottlogic.deg.generator.decisiontree; import com.scottlogic.deg.common.profile.Field; -import com.scottlogic.deg.common.profile.HelixNumber; import com.scottlogic.deg.common.profile.Fields; +import com.scottlogic.deg.common.util.NumberUtils; import com.scottlogic.deg.generator.decisiontree.testutils.*; import com.scottlogic.deg.generator.fieldspecs.whitelist.DistributedList; import com.scottlogic.deg.generator.fieldspecs.whitelist.WeightedElement; @@ -122,7 +122,7 @@ void shouldReturnAnalysedRuleWithNoDecisions_IfProfileContainsOnlyAtomicConstrai 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)); + GreaterThanConstraint constraint1 = new GreaterThanConstraint(inputFieldList.get(0), NumberUtils.coerceToBigDecimal(0)); MatchesRegexConstraint constraint2 = new MatchesRegexConstraint(inputFieldList.get(1), Pattern.compile("start.*end")); Rule testRule = new Rule("test", Arrays.asList(constraint0, constraint1, constraint2)); Profile testInput = new Profile(inputFieldList, Collections.singletonList(testRule)); @@ -144,7 +144,7 @@ void shouldReturnAnalysedRuleWithAllConstraintsInAtomicConstraintsCollection_IfP 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)); + GreaterThanConstraint constraint1 = new GreaterThanConstraint(inputFieldList.get(0), NumberUtils.coerceToBigDecimal(0)); MatchesRegexConstraint constraint2 = new MatchesRegexConstraint(inputFieldList.get(1), Pattern.compile("start.*end")); List inputConstraints = Arrays.asList(constraint0, constraint1, constraint2); Rule testRule = new Rule("test", inputConstraints); @@ -167,7 +167,7 @@ void shouldReturnAnalysedRuleWithAllConstraintsInAtomicConstraintsCollection_IfP void shouldReturnAnalysedRuleWithNoDecisions_IfProfileContainsOnlyAtomicConstraintsAndAndConstraints() { List inputFieldList = Arrays.asList(createField("one"), createField("two"), createField("three")); 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)); + GreaterThanConstraint constraint1 = new GreaterThanConstraint(inputFieldList.get(0), NumberUtils.coerceToBigDecimal(0)); AndConstraint andConstraint0 = new AndConstraint(Arrays.asList(constraint0, constraint1)); MatchesRegexConstraint constraint2 = new MatchesRegexConstraint(inputFieldList.get(1), Pattern.compile("start.*end")); Rule testRule = new Rule("test", Arrays.asList(andConstraint0, constraint2)); @@ -187,7 +187,7 @@ void shouldReturnAnalysedRuleWithNoDecisions_IfProfileContainsOnlyAtomicConstrai void shouldReturnAnalysedRuleWithAllAtomicConstraintsInAtomicConstraintsCollection_IfProfileContainsOnlyAtomicConstraintsAndAndConstraints() { List inputFieldList = Arrays.asList(createField("one"), createField("two"), createField("three")); 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)); + GreaterThanConstraint constraint1 = new GreaterThanConstraint(inputFieldList.get(0), NumberUtils.coerceToBigDecimal(0)); AndConstraint andConstraint0 = new AndConstraint(Arrays.asList(constraint0, constraint1)); MatchesRegexConstraint constraint2 = new MatchesRegexConstraint(inputFieldList.get(1), Pattern.compile("start.*end")); Rule testRule = new Rule("test", Arrays.asList(andConstraint0, constraint2)); @@ -212,7 +212,7 @@ void shouldReturnAnalysedRuleWithAllAtomicConstraintsInAtomicConstraintsCollecti void shouldReturnAnalysedRuleWithDecisionForEachOrConstraint() { List inputFieldList = Arrays.asList(createField("one"), createField("two"), createField("three")); 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)); + GreaterThanConstraint constraint1 = new GreaterThanConstraint(inputFieldList.get(0), NumberUtils.coerceToBigDecimal(0)); OrConstraint orConstraint0 = new OrConstraint(Arrays.asList(constraint0, constraint1)); InSetConstraint constraint2 = new InSetConstraint( inputFieldList.get(1), @@ -237,7 +237,7 @@ void shouldReturnAnalysedRuleWithDecisionForEachOrConstraint() { void shouldReturnAnalysedRuleWithNoAtomicConstraints_IfAllAtomicConstraintsInProfileAreChildrenOfOrConstraints() { List inputFieldList = Arrays.asList(createField("one"), createField("two"), createField("three")); 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 constraintB = new GreaterThanConstraint(inputFieldList.get(0), NumberUtils.coerceToBigDecimal(0)); OrConstraint orConstraint0 = new OrConstraint(Arrays.asList(constraintA, constraintB)); InSetConstraint constraintC = new InSetConstraint( inputFieldList.get(1), @@ -262,7 +262,7 @@ void shouldReturnAnalysedRuleWithNoAtomicConstraints_IfAllAtomicConstraintsInPro void shouldReturnAnalysedRuleWithCorrectDecisionStructure_IfAllAtomicConstraintsInProfileAreChildrenOfOrConstraints() { List inputFieldList = Arrays.asList(createField("one"), createField("two"), createField("three")); 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 constraintB = new GreaterThanConstraint(inputFieldList.get(0), NumberUtils.coerceToBigDecimal(0)); OrConstraint orConstraint0 = new OrConstraint(Arrays.asList(constraintA, constraintB)); InSetConstraint constraintC = new InSetConstraint( inputFieldList.get(1), @@ -298,8 +298,8 @@ void shouldReturnAnalysedRuleWithCorrectDecisionStructure_IfAllAtomicConstraints void shouldReturnAnalysedRuleWithCorrectDecisionStructure_IfAllAtomicConstraintsInProfileAreChildrenOfOrAndAndConstraints() { List inputFieldList = Arrays.asList(createField("one"), createField("two"), createField("three")); 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)); + GreaterThanConstraint constraintB = new GreaterThanConstraint(inputFieldList.get(0), NumberUtils.coerceToBigDecimal(0)); + GreaterThanConstraint constraintC = new GreaterThanConstraint(inputFieldList.get(0), NumberUtils.coerceToBigDecimal(5)); AndConstraint andConstraint0 = new AndConstraint(Arrays.asList(constraintC, constraintB)); OrConstraint orConstraint0 = new OrConstraint(Arrays.asList(constraintA, andConstraint0)); InSetConstraint constraintD = new InSetConstraint( @@ -336,8 +336,8 @@ void shouldReturnAnalysedRuleWithCorrectDecisionStructure_IfAllAtomicConstraints void shouldReturnAnalysedRuleWithCorrectDecisionStructure_IfConditionalConstraintIsPresent() { List inputFieldList = Arrays.asList(createField("one"), createField("two"), createField("three")); 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)); + GreaterThanConstraint constraintB = new GreaterThanConstraint(inputFieldList.get(1), NumberUtils.coerceToBigDecimal(10)); + GreaterThanConstraint constraintC = new GreaterThanConstraint(inputFieldList.get(1), NumberUtils.coerceToBigDecimal(20)); ConditionalConstraint conditionalConstraint = new ConditionalConstraint(constraintA, constraintB, constraintC); Rule testRule = new Rule("test", Collections.singletonList(conditionalConstraint)); Profile testInput = new Profile(inputFieldList, Collections.singletonList(testRule)); @@ -366,8 +366,8 @@ void shouldReturnAnalysedRuleWithCorrectDecisionStructure_IfConditionalConstrain @Test void shouldReturnAnalysedRuleWithCorrectDecisionStructure_IfConditionalConstraintWithNestedOrIsPresent() { 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)); + AtomicConstraint aGreaterThan10 = new GreaterThanConstraint(fieldA, NumberUtils.coerceToBigDecimal(10)); + AtomicConstraint bGreaterThan20 = new GreaterThanConstraint(fieldB, NumberUtils.coerceToBigDecimal(20)); givenRule( new ConditionalConstraint( @@ -398,8 +398,8 @@ void shouldReturnAnalysedRuleWithCorrectDecisionStructure_IfConditionalConstrain void shouldReturnAnalysedRuleWithCorrectDecisionStructure_IfNegatedConditionalConstraintIsPresent() { List inputFieldList = Arrays.asList(createField("one"), createField("two"), createField("three")); 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)); + GreaterThanConstraint constraintB = new GreaterThanConstraint(inputFieldList.get(1), NumberUtils.coerceToBigDecimal(20)); + GreaterThanConstraint constraintC = new GreaterThanConstraint(inputFieldList.get(1), NumberUtils.coerceToBigDecimal(10)); ConditionalConstraint conditionalConstraint = new ConditionalConstraint(constraintA, constraintB, constraintC); Constraint notConstraint = conditionalConstraint.negate(); Rule testRule = new Rule("test", Collections.singletonList(notConstraint)); @@ -434,7 +434,7 @@ void shouldReturnAnalysedRuleWithCorrectDecisionStructure_IfNegatedConditionalCo // A ^ ¬B AtomicConstraint aEqualTo10 = new InSetConstraint(fieldA, new DistributedList<>(Collections.singletonList(new WeightedElement<>(10, 1.0F)))); - AtomicConstraint bGreaterThan20 = new GreaterThanConstraint(fieldB, HelixNumber.create(20)); + AtomicConstraint bGreaterThan20 = new GreaterThanConstraint(fieldB, NumberUtils.coerceToBigDecimal(20)); Constraint inputRule = new ConditionalConstraint(aEqualTo10, bGreaterThan20).negate(); @@ -477,7 +477,7 @@ void shouldReturnAnalysedRuleWithCorrectDecisionStructure_IfDoubleNegationIsPres void shouldReturnAnalysedRuleWithCorrectDecisionStructure_IfNegatedAndIsPresent() { List inputFieldList = Arrays.asList(createField("one"), createField("two"), createField("three")); 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)); + GreaterThanConstraint constraintB = new GreaterThanConstraint(inputFieldList.get(1), NumberUtils.coerceToBigDecimal(5)); NegatedGrammaticalConstraint notConstraint = (NegatedGrammaticalConstraint) new AndConstraint(Arrays.asList(constraintA, constraintB)).negate(); Rule testRule = new Rule("test", Collections.singletonList(notConstraint)); Profile testInput = new Profile(inputFieldList, Collections.singletonList(testRule)); @@ -502,8 +502,8 @@ void shouldReturnAnalysedRuleWithCorrectDecisionStructure_IfNegatedAndIsPresent( @Test void shouldReturnAnalysedRuleWithCorrectDecisionStructure_IfNestedOrsArePresent() { 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)); + AtomicConstraint constraintB = new GreaterThanConstraint(fieldB, NumberUtils.coerceToBigDecimal(20)); + AtomicConstraint constraintC = new GreaterThanConstraint(fieldB, NumberUtils.coerceToBigDecimal(10)); givenRule( new OrConstraint( diff --git a/generator/src/test/java/com/scottlogic/deg/generator/reducer/ConstraintReducerTest.java b/generator/src/test/java/com/scottlogic/deg/generator/reducer/ConstraintReducerTest.java index b13cb55c0..bbe3997c0 100644 --- a/generator/src/test/java/com/scottlogic/deg/generator/reducer/ConstraintReducerTest.java +++ b/generator/src/test/java/com/scottlogic/deg/generator/reducer/ConstraintReducerTest.java @@ -719,8 +719,8 @@ // .collect(Collectors.toList())); // // final Set constraints = SetUtils.setOf( -// new IsGreaterThanOrEqualToConstantConstraint(quantityField, HelixNumber.create(0)), -// new IsGreaterThanConstantConstraint(quantityField, HelixNumber.create(5)).negate(), +// new IsGreaterThanOrEqualToConstantConstraint(quantityField, NumberUtils.coerceToBigDecimal(0)), +// new IsGreaterThanConstantConstraint(quantityField, NumberUtils.coerceToBigDecimal(5)).negate(), // new IsInSetConstraint(countryField, countryAmong)); // // // ACT @@ -767,7 +767,7 @@ // final Field field = createField("test0", NUMERIC); // ProfileFields profileFields = new ProfileFields(Collections.singletonList(field)); // Set constraints = Collections.singleton( -// new IsGreaterThanOrEqualToConstantConstraint(field, HelixNumber.create(5))); +// new IsGreaterThanOrEqualToConstantConstraint(field, NumberUtils.coerceToBigDecimal(5))); // // RowSpec testOutput = constraintReducer.reduceConstraintsToRowSpec(profileFields, nodeFromConstraints(constraints)).get(); // @@ -795,7 +795,7 @@ // final Field field = createField("test0", NUMERIC); // ProfileFields profileFields = new ProfileFields(Collections.singletonList(field)); // Set constraints = Collections.singleton( -// new IsGreaterThanConstantConstraint(field, HelixNumber.create(5)).negate()); +// new IsGreaterThanConstantConstraint(field, NumberUtils.coerceToBigDecimal(5)).negate()); // // RowSpec testOutput = constraintReducer.reduceConstraintsToRowSpec(profileFields, nodeFromConstraints(constraints)).get(); // @@ -821,7 +821,7 @@ // final Field field = createField("test0", NUMERIC); // ProfileFields profileFields = new ProfileFields(Collections.singletonList(field)); // Set constraints = Collections.singleton( -// new IsGreaterThanOrEqualToConstantConstraint(field, HelixNumber.create(5))); +// new IsGreaterThanOrEqualToConstantConstraint(field, NumberUtils.coerceToBigDecimal(5))); // // RowSpec testOutput = constraintReducer.reduceConstraintsToRowSpec(profileFields, nodeFromConstraints(constraints)).get(); // @@ -849,7 +849,7 @@ // final Field field = createField("test0", NUMERIC); // ProfileFields profileFields = new ProfileFields(Collections.singletonList(field)); // Set constraints = Collections.singleton( -// new IsGreaterThanConstantConstraint(field, HelixNumber.create(5)).negate()); +// new IsGreaterThanConstantConstraint(field, NumberUtils.coerceToBigDecimal(5)).negate()); // // RowSpec testOutput = constraintReducer.reduceConstraintsToRowSpec(profileFields, nodeFromConstraints(constraints)).get(); // @@ -875,7 +875,7 @@ // final Field field = createField("test0", NUMERIC); // ProfileFields profileFields = new ProfileFields(Collections.singletonList(field)); // Set constraints = Collections.singleton( -// new IsLessThanOrEqualToConstantConstraint(field, HelixNumber.create(5))); +// new IsLessThanOrEqualToConstantConstraint(field, NumberUtils.coerceToBigDecimal(5))); // // RowSpec testOutput = constraintReducer.reduceConstraintsToRowSpec(profileFields, nodeFromConstraints(constraints)).get(); // @@ -901,7 +901,7 @@ // final Field field = createField("test0", NUMERIC); // ProfileFields profileFields = new ProfileFields(Collections.singletonList(field)); // Set constraints = Collections.singleton( -// new IsLessThanConstantConstraint(field, HelixNumber.create(5)).negate()); +// new IsLessThanConstantConstraint(field, NumberUtils.coerceToBigDecimal(5)).negate()); // // RowSpec testOutput = constraintReducer.reduceConstraintsToRowSpec(profileFields, nodeFromConstraints(constraints)).get(); // @@ -927,7 +927,7 @@ // final Field field = createField("test0", NUMERIC); // ProfileFields profileFields = new ProfileFields(Collections.singletonList(field)); // Set constraints = Collections.singleton( -// new IsLessThanOrEqualToConstantConstraint(field, HelixNumber.create(5))); +// new IsLessThanOrEqualToConstantConstraint(field, NumberUtils.coerceToBigDecimal(5))); // // RowSpec testOutput = constraintReducer.reduceConstraintsToRowSpec(profileFields, nodeFromConstraints(constraints)).get(); // @@ -953,7 +953,7 @@ // final Field field = createField("test0", NUMERIC); // ProfileFields profileFields = new ProfileFields(Collections.singletonList(field)); // Set constraints = Collections.singleton( -// new IsLessThanConstantConstraint(field, HelixNumber.create(5)).negate()); +// new IsLessThanConstantConstraint(field, NumberUtils.coerceToBigDecimal(5)).negate()); // // RowSpec testOutput = constraintReducer.reduceConstraintsToRowSpec(profileFields, nodeFromConstraints(constraints)).get(); // 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 a7171ee23..02fb806cb 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 @@ -16,7 +16,7 @@ package com.scottlogic.deg.generator.violations.filters; -import com.scottlogic.deg.common.profile.HelixNumber; +import com.scottlogic.deg.common.util.NumberUtils; import com.scottlogic.deg.generator.fieldspecs.whitelist.DistributedList; import com.scottlogic.deg.generator.fieldspecs.whitelist.WeightedElement; import com.scottlogic.deg.generator.profile.constraints.Constraint; @@ -64,7 +64,7 @@ public void canViolate_withMatchingTypeConstraint_returnsFalse() { @Test public void canViolate_withNonMatchingTypeConstraint_returnsTrue() { //Arrange - Constraint inputConstraint = new GreaterThanConstraint(null, HelixNumber.create(100)); + Constraint inputConstraint = new GreaterThanConstraint(null, NumberUtils.coerceToBigDecimal(100)); //Act boolean actual = target.canViolate(inputConstraint); 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 c5294c8f6..6a2a28d3a 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 @@ -16,7 +16,11 @@ package com.scottlogic.deg.orchestrator.violate.violator; -import com.scottlogic.deg.common.profile.*; +import com.scottlogic.deg.common.profile.Field; +import com.scottlogic.deg.common.profile.Fields; +import com.scottlogic.deg.common.profile.HelixDateTime; +import com.scottlogic.deg.common.profile.HelixStringLength; +import com.scottlogic.deg.common.util.NumberUtils; import com.scottlogic.deg.generator.builders.*; import com.scottlogic.deg.generator.fieldspecs.whitelist.DistributedList; import com.scottlogic.deg.generator.fieldspecs.whitelist.WeightedElement; @@ -95,10 +99,10 @@ private static Stream allAtomicConstraints() { 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)) + Arguments.of(GreaterThanConstraint.class, NumberUtils.coerceToBigDecimal(100)), + Arguments.of(GreaterThanOrEqualToConstraint.class, NumberUtils.coerceToBigDecimal(200)), + Arguments.of(LessThanConstraint.class, NumberUtils.coerceToBigDecimal(300)), + Arguments.of(LessThanOrEqualToConstraint.class, NumberUtils.coerceToBigDecimal(400)) ); } 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 2c59cb367..2b1a58daa 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 @@ -17,8 +17,8 @@ package com.scottlogic.deg.orchestrator.violate.violator; import com.scottlogic.deg.common.profile.Field; -import com.scottlogic.deg.common.profile.HelixNumber; import com.scottlogic.deg.common.profile.Fields; +import com.scottlogic.deg.common.util.NumberUtils; import com.scottlogic.deg.generator.profile.Profile; import com.scottlogic.deg.generator.profile.Rule; import com.scottlogic.deg.generator.profile.constraints.Constraint; @@ -151,22 +151,22 @@ private void initRules() { barField = createField("bar"); Constraint constraint1 = new GreaterThanConstraint( fooField, - HelixNumber.create(100) + NumberUtils.coerceToBigDecimal(100) ); Constraint constraint2 = new GreaterThanConstraint( barField, - HelixNumber.create(50) + NumberUtils.coerceToBigDecimal(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 LessThanConstraint( fooField, - HelixNumber.create(101) + NumberUtils.coerceToBigDecimal(101) ); Constraint constraint4 = new LessThanConstraint( barField, - HelixNumber.create(51) + NumberUtils.coerceToBigDecimal(51) ); violatedRule1 = new Rule(ruleInformation1, Arrays.asList(constraint3, constraint4)); 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 6faa0efa4..10ee55171 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 @@ -16,8 +16,8 @@ package com.scottlogic.deg.orchestrator.violate.violator; -import com.scottlogic.deg.common.profile.HelixNumber; import com.scottlogic.deg.common.profile.UnviolatableConstraintException; +import com.scottlogic.deg.common.util.NumberUtils; import com.scottlogic.deg.generator.profile.Rule; import com.scottlogic.deg.generator.profile.constraints.Constraint; import com.scottlogic.deg.generator.profile.constraints.atomic.AtomicConstraint; @@ -69,9 +69,9 @@ public void commonTestSetup() { target = new RuleViolator(inputFilters); - atomicConstraint1 = new LessThanConstraint(createField("foo"), HelixNumber.create(10)); - atomicConstraint2 = new LessThanConstraint(createField("bar"), HelixNumber.create(20)); - atomicConstraint3 = new LessThanConstraint(createField("foobar"), HelixNumber.create(30)); + atomicConstraint1 = new LessThanConstraint(createField("foo"), NumberUtils.coerceToBigDecimal(10)); + atomicConstraint2 = new LessThanConstraint(createField("bar"), NumberUtils.coerceToBigDecimal(20)); + atomicConstraint3 = new LessThanConstraint(createField("foobar"), NumberUtils.coerceToBigDecimal(30)); } /** diff --git a/profile/src/main/java/com/scottlogic/deg/profile/factories/constraint_factories/NumericConstraintFactory.java b/profile/src/main/java/com/scottlogic/deg/profile/factories/constraint_factories/NumericConstraintFactory.java index 9862cf531..cb7e23447 100644 --- a/profile/src/main/java/com/scottlogic/deg/profile/factories/constraint_factories/NumericConstraintFactory.java +++ b/profile/src/main/java/com/scottlogic/deg/profile/factories/constraint_factories/NumericConstraintFactory.java @@ -18,7 +18,6 @@ package com.scottlogic.deg.profile.factories.constraint_factories; 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.*; @@ -73,25 +72,25 @@ LongerThanConstraint createLongerThanConstraint(LongerThanConstraintDTO dto, Fie @Override GreaterThanConstraint createGreaterThanConstraint(GreaterThanConstraintDTO dto, Field field) { - return new GreaterThanConstraint(field, HelixNumber.create(dto.value)); + return new GreaterThanConstraint(field, NumberUtils.coerceToBigDecimal(dto.value)); } @Override GreaterThanOrEqualToConstraint createGreaterThanOrEqualToConstraint(GreaterThanOrEqualToConstraintDTO dto, Field field) { - return new GreaterThanOrEqualToConstraint(field, HelixNumber.create(dto.value)); + return new GreaterThanOrEqualToConstraint(field, NumberUtils.coerceToBigDecimal(dto.value)); } @Override LessThanConstraint createLessThanConstraint(LessThanConstraintDTO dto, Field field) { - return new LessThanConstraint(field, HelixNumber.create(dto.value)); + return new LessThanConstraint(field, NumberUtils.coerceToBigDecimal(dto.value)); } @Override LessThanOrEqualToConstraint createLessThanOrEqualToConstraint(LessThanOrEqualToConstraintDTO dto, Field field) { - return new LessThanOrEqualToConstraint(field, HelixNumber.create(dto.value)); + return new LessThanOrEqualToConstraint(field, NumberUtils.coerceToBigDecimal(dto.value)); } @Override diff --git a/profile/src/main/java/com/scottlogic/deg/profile/validators/profile/ConstraintValidator.java b/profile/src/main/java/com/scottlogic/deg/profile/validators/profile/ConstraintValidator.java index 1911b04d0..8bd597f39 100644 --- a/profile/src/main/java/com/scottlogic/deg/profile/validators/profile/ConstraintValidator.java +++ b/profile/src/main/java/com/scottlogic/deg/profile/validators/profile/ConstraintValidator.java @@ -148,4 +148,6 @@ protected ValidationResult validateGranularity(T dto, String field, Object value return ValidationResult.success(); } + + } diff --git a/profile/src/main/java/com/scottlogic/deg/profile/validators/profile/constraints/atomic/AtomicConstraintValidator.java b/profile/src/main/java/com/scottlogic/deg/profile/validators/profile/constraints/atomic/AtomicConstraintValidator.java index 3d6e33f2c..a004d1bc9 100644 --- a/profile/src/main/java/com/scottlogic/deg/profile/validators/profile/constraints/atomic/AtomicConstraintValidator.java +++ b/profile/src/main/java/com/scottlogic/deg/profile/validators/profile/constraints/atomic/AtomicConstraintValidator.java @@ -37,8 +37,7 @@ protected String getErrorInfo(T atomicConstraint) return " | Field: " + atomicConstraint.field + super.getErrorInfo(atomicConstraint); } - - ValidationResult valueMustBeValid(T dto, FieldType expectedFieldType) + ValidationResult fieldTypeMustMatchValueType(T dto, FieldType expectedFieldType) { FieldType fieldType = fields.stream().filter(f -> f.name.equals(dto.field)).findFirst().get().type.getFieldType(); if (expectedFieldType != fieldType) @@ -48,7 +47,7 @@ ValidationResult valueMustBeValid(T dto, FieldType expectedFieldType) return ValidationResult.success(); } - ValidationResult valueMustBeValid(T dto, Object value) + ValidationResult fieldTypeMustMatchValueType(T dto, Object value) { if(value == null) { @@ -71,16 +70,12 @@ private static boolean isNumber(String s) try { Double.parseDouble(s); + return true; } - catch (NumberFormatException e) - { - return false; - } - catch (NullPointerException e) + catch (NumberFormatException | NullPointerException e) { return false; } - return true; } diff --git a/profile/src/main/java/com/scottlogic/deg/profile/validators/profile/constraints/atomic/EqualToConstraintValidator.java b/profile/src/main/java/com/scottlogic/deg/profile/validators/profile/constraints/atomic/EqualToConstraintValidator.java index 12331db71..6137553c5 100644 --- a/profile/src/main/java/com/scottlogic/deg/profile/validators/profile/constraints/atomic/EqualToConstraintValidator.java +++ b/profile/src/main/java/com/scottlogic/deg/profile/validators/profile/constraints/atomic/EqualToConstraintValidator.java @@ -33,7 +33,7 @@ public final ValidationResult validate(EqualToConstraintDTO dto) { ValidationResult fieldMustBeValid = fieldMustBeValid(dto); if(!fieldMustBeValid.isSuccess) return fieldMustBeValid; - return valueMustBeValid(dto, dto.value); + return fieldTypeMustMatchValueType(dto, dto.value); } } diff --git a/profile/src/main/java/com/scottlogic/deg/profile/validators/profile/constraints/atomic/GranularToConstraintValidator.java b/profile/src/main/java/com/scottlogic/deg/profile/validators/profile/constraints/atomic/GranularToConstraintValidator.java index d560a8b07..8395f87f6 100644 --- a/profile/src/main/java/com/scottlogic/deg/profile/validators/profile/constraints/atomic/GranularToConstraintValidator.java +++ b/profile/src/main/java/com/scottlogic/deg/profile/validators/profile/constraints/atomic/GranularToConstraintValidator.java @@ -33,7 +33,7 @@ public final ValidationResult validate(GranularToConstraintDTO dto) { ValidationResult fieldMustBeValid = fieldMustBeValid(dto); if(!fieldMustBeValid.isSuccess) return fieldMustBeValid; - ValidationResult valueMustBeValid = valueMustBeValid(dto, dto.value); + ValidationResult valueMustBeValid = fieldTypeMustMatchValueType(dto, dto.value); if(!valueMustBeValid.isSuccess) return valueMustBeValid; return validateGranularity(dto, dto.field, dto.value); diff --git a/profile/src/main/java/com/scottlogic/deg/profile/validators/profile/constraints/atomic/InSetConstraintValidator.java b/profile/src/main/java/com/scottlogic/deg/profile/validators/profile/constraints/atomic/InSetConstraintValidator.java index e92706940..2d910a933 100644 --- a/profile/src/main/java/com/scottlogic/deg/profile/validators/profile/constraints/atomic/InSetConstraintValidator.java +++ b/profile/src/main/java/com/scottlogic/deg/profile/validators/profile/constraints/atomic/InSetConstraintValidator.java @@ -46,6 +46,6 @@ private ValidationResult valuesMustBeSpecified(InSetConstraintDTO dto) private ValidationResult fieldTypeMustBeValid(InSetConstraintDTO dto) { - return ValidationResult.combine(dto.values.stream().map(v -> valueMustBeValid(dto, v))); + return ValidationResult.combine(dto.values.stream().map(v -> fieldTypeMustMatchValueType(dto, v))); } } diff --git a/profile/src/main/java/com/scottlogic/deg/profile/validators/profile/constraints/atomic/NumericConstraintValidator.java b/profile/src/main/java/com/scottlogic/deg/profile/validators/profile/constraints/atomic/NumericConstraintValidator.java index 090a3a258..19cab3ab9 100644 --- a/profile/src/main/java/com/scottlogic/deg/profile/validators/profile/constraints/atomic/NumericConstraintValidator.java +++ b/profile/src/main/java/com/scottlogic/deg/profile/validators/profile/constraints/atomic/NumericConstraintValidator.java @@ -17,10 +17,13 @@ import com.scottlogic.deg.common.profile.FieldType; +import com.scottlogic.deg.common.util.NumberUtils; +import com.scottlogic.deg.common.util.defaults.NumericDefaults; import com.scottlogic.deg.common.validators.ValidationResult; import com.scottlogic.deg.profile.dtos.FieldDTO; import com.scottlogic.deg.profile.dtos.constraints.atomic.numeric.NumericConstraintDTO; +import java.math.BigDecimal; import java.util.List; public class NumericConstraintValidator extends AtomicConstraintValidator @@ -39,16 +42,33 @@ public final ValidationResult validate(NumericConstraintDTO dto) ValidationResult fieldMustBeValid = fieldMustBeValid(dto); if(!fieldMustBeValid.isSuccess) return fieldMustBeValid; - ValidationResult numberMustBeSpecified = numberMustBeSpecified(dto); - if(!numberMustBeSpecified.isSuccess) return numberMustBeSpecified; + ValidationResult numberMustBeValid = numberMustBeValid(dto); + if(!numberMustBeValid.isSuccess) return numberMustBeValid; - return valueMustBeValid(dto, expectedFieldType); + return fieldTypeMustMatchValueType(dto, expectedFieldType); } - private ValidationResult numberMustBeSpecified(NumericConstraintDTO dto) + private ValidationResult numberMustBeValid(NumericConstraintDTO dto) { - return dto.getNumber() != null - ? ValidationResult.success() - : ValidationResult.failure("Number must be specified" + getErrorInfo(dto)); + if (dto.getNumber() == null) + { + return ValidationResult.failure("Number must be specified" + getErrorInfo(dto)); + } + BigDecimal number = NumberUtils.coerceToBigDecimal(dto.getNumber()); + if(number == null) + { + return ValidationResult.failure("Number cannot be converted to big decimal" + getErrorInfo(dto)); + } + BigDecimal min = NumericDefaults.get().min(); + if (number.compareTo(min) < 0) + { + return ValidationResult.failure(String.format("Number must have a value >= %s, currently is %s", min.toPlainString(), number.toPlainString())); + } + BigDecimal max = NumericDefaults.get().max(); + if (number.compareTo(max) > 0) + { + return ValidationResult.failure(String.format("Number must have a value <= %s, currently is %s", max.toPlainString(), number.toPlainString())); + } + return ValidationResult.success(); } } diff --git a/profile/src/main/java/com/scottlogic/deg/profile/validators/profile/constraints/atomic/RegexConstraintValidator.java b/profile/src/main/java/com/scottlogic/deg/profile/validators/profile/constraints/atomic/RegexConstraintValidator.java index 0fe52175d..d61d91de3 100644 --- a/profile/src/main/java/com/scottlogic/deg/profile/validators/profile/constraints/atomic/RegexConstraintValidator.java +++ b/profile/src/main/java/com/scottlogic/deg/profile/validators/profile/constraints/atomic/RegexConstraintValidator.java @@ -40,7 +40,7 @@ public final ValidationResult validate(RegexConstraintDTO dto) ValidationResult regexMustBeValid = regexMustBeValid(dto); if(!regexMustBeValid.isSuccess) return regexMustBeValid; - return valueMustBeValid(dto, FieldType.STRING); + return fieldTypeMustMatchValueType(dto, FieldType.STRING); } private ValidationResult regexMustBeValid(RegexConstraintDTO dto) diff --git a/profile/src/main/java/com/scottlogic/deg/profile/validators/profile/constraints/atomic/TemporalConstraintValidator.java b/profile/src/main/java/com/scottlogic/deg/profile/validators/profile/constraints/atomic/TemporalConstraintValidator.java index a2271c8eb..eff13c1f3 100644 --- a/profile/src/main/java/com/scottlogic/deg/profile/validators/profile/constraints/atomic/TemporalConstraintValidator.java +++ b/profile/src/main/java/com/scottlogic/deg/profile/validators/profile/constraints/atomic/TemporalConstraintValidator.java @@ -39,7 +39,7 @@ public final ValidationResult validate(TemporalConstraintDTO dto) ValidationResult dateMustBeSpecified = dateMustBeSpecified(dto); if(!dateMustBeSpecified.isSuccess) return dateMustBeSpecified; - return valueMustBeValid(dto, FieldType.DATETIME); + return fieldTypeMustMatchValueType(dto, FieldType.DATETIME); } From 25c317e97fda12736c10cbd8cf29d0b1bc494fdd Mon Sep 17 00:00:00 2001 From: Charlton Dowding Date: Thu, 7 Nov 2019 14:23:06 +0000 Subject: [PATCH 02/10] Removed HelixDateTime --- .../deg/common/profile/HelixDateTime.java | 100 ------------------ .../constraints/atomic/AfterConstraint.java | 7 +- .../atomic/AfterOrAtConstraint.java | 7 +- .../constraints/atomic/BeforeConstraint.java | 7 +- .../atomic/BeforeOrAtConstraint.java | 7 +- .../builders/ConstraintChainBuilder.java | 5 +- .../features/operators/temporal/After.feature | 6 +- .../operators/temporal/AfterOrAt.feature | 6 +- .../operators/temporal/Before.feature | 8 +- .../operators/temporal/BeforeOrAt.feature | 6 +- .../violator/ProfileViolationTests.java | 9 +- .../profile/factories/DateTimeFactory.java | 55 ++++++++++ .../DateTimeConstraintFactory.java | 12 +-- .../atomic/TemporalConstraintValidator.java | 33 ++++-- .../reader/JsonProfileReaderTests.java | 4 +- 15 files changed, 118 insertions(+), 154 deletions(-) create mode 100644 profile/src/main/java/com/scottlogic/deg/profile/factories/DateTimeFactory.java diff --git a/common/src/main/java/com/scottlogic/deg/common/profile/HelixDateTime.java b/common/src/main/java/com/scottlogic/deg/common/profile/HelixDateTime.java index e91c37811..e69de29bb 100644 --- a/common/src/main/java/com/scottlogic/deg/common/profile/HelixDateTime.java +++ b/common/src/main/java/com/scottlogic/deg/common/profile/HelixDateTime.java @@ -1,100 +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.common.profile; - -import com.scottlogic.deg.common.ValidationException; -import java.time.LocalDateTime; -import java.time.OffsetDateTime; -import java.time.ZoneOffset; -import java.time.format.DateTimeFormatter; -import java.time.format.DateTimeFormatterBuilder; -import java.time.format.DateTimeParseException; -import java.time.format.ResolverStyle; -import java.time.temporal.ChronoField; -import java.time.temporal.TemporalAccessor; - -public class HelixDateTime -{ - private static final HelixDateTime NOW = new HelixDateTime(OffsetDateTime.now()); - private static final DateTimeFormatter FORMATTER = getDateTimeFormatter(); - private final OffsetDateTime value; - - private HelixDateTime(OffsetDateTime value) - { - this.value = value; - } - - public static HelixDateTime create(String dateTime) - { - if(dateTime == null) throw new ValidationException("HelixDateTime cannot be null"); - if (dateTime.equalsIgnoreCase("NOW")) return NOW; - OffsetDateTime offsetDateTime = fromString(dateTime); - validateDateRange(offsetDateTime); - return new HelixDateTime(offsetDateTime); - } - - public static HelixDateTime create(OffsetDateTime dateTime) - { - validateDateRange(dateTime); - return new HelixDateTime(dateTime); - } - - public OffsetDateTime getValue() - { - return value; - } - - private static OffsetDateTime fromString(String dateTime) - { - try - { - TemporalAccessor temporalAccessor = FORMATTER.parse(dateTime); - return temporalAccessor.isSupported(ChronoField.OFFSET_SECONDS) - ? OffsetDateTime.from(temporalAccessor) - : LocalDateTime.from(temporalAccessor).atOffset(ZoneOffset.UTC); - } - catch (DateTimeParseException exception) - { - throw new ValidationException(String.format("Date string '%s' must be in ISO-8601 format: Either yyyy-MM-ddTHH:mm:ss.SSS[Z] between " + - "0001-01-01T00:00:00.000Z and 9999-12-31T23:59:59.999Z or yyyy-mm-dd between 0001-01-01 and 9999-12-31", dateTime)); - } - } - - private static void validateDateRange(OffsetDateTime dateTime) - { - if (dateTime != null && dateTime.getYear() <= 9999 && dateTime.getYear() >= 1) return; - throw new ValidationException("Dates must be between 0001-01-01T00:00:00.000Z and 9999-12-31T23:59:59.999Z"); - } - - private static DateTimeFormatter getDateTimeFormatter() { - DateTimeFormatter dateFormat = new DateTimeFormatterBuilder() - .appendPattern("u-MM-dd") - .parseDefaulting(ChronoField.SECOND_OF_DAY,0) - .toFormatter(); - - DateTimeFormatter dateTimeFormatter = new DateTimeFormatterBuilder() - .append(DateTimeFormatter.ofPattern("u-MM-dd'T'HH:mm:ss'.'SSS")) - .optionalStart() - .appendOffset("+HH", "Z") - .toFormatter(); - - return new DateTimeFormatterBuilder() - .appendOptional(dateTimeFormatter) - .appendOptional(dateFormat) - .toFormatter() - .withResolverStyle(ResolverStyle.STRICT); - } -} diff --git a/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/AfterConstraint.java b/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/AfterConstraint.java index 9d61710d9..66fead496 100644 --- a/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/AfterConstraint.java +++ b/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/AfterConstraint.java @@ -17,7 +17,6 @@ package com.scottlogic.deg.generator.profile.constraints.atomic; import com.scottlogic.deg.common.profile.Field; -import com.scottlogic.deg.common.profile.HelixDateTime; import com.scottlogic.deg.generator.fieldspecs.FieldSpec; import com.scottlogic.deg.generator.fieldspecs.FieldSpecFactory; import com.scottlogic.deg.generator.restrictions.linear.Limit; @@ -31,9 +30,9 @@ public class AfterConstraint implements AtomicConstraint { public final Field field; - public final HelixDateTime referenceValue; + public final OffsetDateTime referenceValue; - public AfterConstraint(Field field, HelixDateTime referenceValue) { + public AfterConstraint(Field field, OffsetDateTime referenceValue) { this.field = field; this.referenceValue = referenceValue; } @@ -50,7 +49,7 @@ public AtomicConstraint negate() { @Override public FieldSpec toFieldSpec() { - final LinearRestrictions dateTimeRestrictions = createDateTimeRestrictions(new Limit<>(referenceValue.getValue(), false), DATETIME_MAX_LIMIT); + final LinearRestrictions dateTimeRestrictions = createDateTimeRestrictions(new Limit<>(referenceValue, false), DATETIME_MAX_LIMIT); return FieldSpecFactory.fromRestriction(dateTimeRestrictions); } diff --git a/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/AfterOrAtConstraint.java b/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/AfterOrAtConstraint.java index 2d17739d4..05af94961 100644 --- a/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/AfterOrAtConstraint.java +++ b/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/AfterOrAtConstraint.java @@ -17,7 +17,6 @@ package com.scottlogic.deg.generator.profile.constraints.atomic; import com.scottlogic.deg.common.profile.Field; -import com.scottlogic.deg.common.profile.HelixDateTime; import com.scottlogic.deg.generator.fieldspecs.FieldSpec; import com.scottlogic.deg.generator.fieldspecs.FieldSpecFactory; import com.scottlogic.deg.generator.restrictions.linear.Limit; @@ -32,9 +31,9 @@ public class AfterOrAtConstraint implements AtomicConstraint { public final Field field; - public final HelixDateTime referenceValue; + public final OffsetDateTime referenceValue; - public AfterOrAtConstraint(Field field, HelixDateTime referenceValue) { + public AfterOrAtConstraint(Field field, OffsetDateTime referenceValue) { this.field = field; this.referenceValue = referenceValue; } @@ -51,7 +50,7 @@ public AtomicConstraint negate() { @Override public FieldSpec toFieldSpec() { - final LinearRestrictions dateTimeRestrictions = createDateTimeRestrictions(new Limit<>(referenceValue.getValue(), true), DATETIME_MAX_LIMIT); + final LinearRestrictions dateTimeRestrictions = createDateTimeRestrictions(new Limit<>(referenceValue, true), DATETIME_MAX_LIMIT); return FieldSpecFactory.fromRestriction(dateTimeRestrictions); } diff --git a/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/BeforeConstraint.java b/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/BeforeConstraint.java index 1b034147b..3490aef09 100644 --- a/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/BeforeConstraint.java +++ b/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/BeforeConstraint.java @@ -17,7 +17,6 @@ package com.scottlogic.deg.generator.profile.constraints.atomic; import com.scottlogic.deg.common.profile.Field; -import com.scottlogic.deg.common.profile.HelixDateTime; import com.scottlogic.deg.generator.fieldspecs.FieldSpec; import com.scottlogic.deg.generator.fieldspecs.FieldSpecFactory; import com.scottlogic.deg.generator.restrictions.linear.Limit; @@ -31,9 +30,9 @@ public class BeforeConstraint implements AtomicConstraint { public final Field field; - public final HelixDateTime referenceValue; + public final OffsetDateTime referenceValue; - public BeforeConstraint(Field field, HelixDateTime referenceValue) { + public BeforeConstraint(Field field, OffsetDateTime referenceValue) { this.field = field; this.referenceValue = referenceValue; } @@ -50,7 +49,7 @@ public AtomicConstraint negate() { @Override public FieldSpec toFieldSpec() { - final LinearRestrictions dateTimeRestrictions = createDateTimeRestrictions(DATETIME_MIN_LIMIT, new Limit<>(referenceValue.getValue(), false)); + final LinearRestrictions dateTimeRestrictions = createDateTimeRestrictions(DATETIME_MIN_LIMIT, new Limit<>(referenceValue, false)); return FieldSpecFactory.fromRestriction(dateTimeRestrictions); } diff --git a/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/BeforeOrAtConstraint.java b/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/BeforeOrAtConstraint.java index 87601fd2e..4aba195b2 100644 --- a/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/BeforeOrAtConstraint.java +++ b/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/BeforeOrAtConstraint.java @@ -17,7 +17,6 @@ package com.scottlogic.deg.generator.profile.constraints.atomic; import com.scottlogic.deg.common.profile.Field; -import com.scottlogic.deg.common.profile.HelixDateTime; import com.scottlogic.deg.generator.fieldspecs.FieldSpec; import com.scottlogic.deg.generator.fieldspecs.FieldSpecFactory; import com.scottlogic.deg.generator.restrictions.linear.Limit; @@ -31,9 +30,9 @@ public class BeforeOrAtConstraint implements AtomicConstraint { public final Field field; - public final HelixDateTime referenceValue; + public final OffsetDateTime referenceValue; - public BeforeOrAtConstraint(Field field, HelixDateTime referenceValue) { + public BeforeOrAtConstraint(Field field, OffsetDateTime referenceValue) { this.field = field; this.referenceValue = referenceValue; } @@ -50,7 +49,7 @@ public AtomicConstraint negate() { @Override public FieldSpec toFieldSpec() { - final LinearRestrictions dateTimeRestrictions = createDateTimeRestrictions(DATETIME_MIN_LIMIT, new Limit<>(referenceValue.getValue(), true)); + final LinearRestrictions dateTimeRestrictions = createDateTimeRestrictions(DATETIME_MIN_LIMIT, new Limit<>(referenceValue, true)); return FieldSpecFactory.fromRestriction(dateTimeRestrictions); } 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 41185fa43..f27108ff3 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 @@ -17,7 +17,6 @@ package com.scottlogic.deg.generator.builders; import com.scottlogic.deg.common.profile.Field; -import com.scottlogic.deg.common.profile.HelixDateTime; import com.scottlogic.deg.common.profile.HelixStringLength; import com.scottlogic.deg.common.util.NumberUtils; import com.scottlogic.deg.generator.fieldspecs.whitelist.DistributedList; @@ -134,11 +133,11 @@ public ConstraintChainBuilder withOfLengthConstraint(Field fooField, int leng } public ConstraintChainBuilder withAfterConstraint(Field field, OffsetDateTime dateTime) { - return saveAndSet(new AfterConstraint(field, HelixDateTime.create(dateTime))); + return saveAndSet(new AfterConstraint(field, dateTime)); } public ConstraintChainBuilder withBeforeConstraint(Field field, OffsetDateTime dateTime) { - return saveAndSet(new BeforeConstraint(field, HelixDateTime.create(dateTime))); + return saveAndSet(new BeforeConstraint(field, dateTime)); } public ConstraintChainBuilder withMatchesRegexConstraint(Field field, Pattern pattern) { diff --git a/orchestrator/src/test/java/com/scottlogic/deg/orchestrator/cucumber/features/operators/temporal/After.feature b/orchestrator/src/test/java/com/scottlogic/deg/orchestrator/cucumber/features/operators/temporal/After.feature index aa60c463b..e78e3b288 100644 --- a/orchestrator/src/test/java/com/scottlogic/deg/orchestrator/cucumber/features/operators/temporal/After.feature +++ b/orchestrator/src/test/java/com/scottlogic/deg/orchestrator/cucumber/features/operators/temporal/After.feature @@ -24,7 +24,7 @@ Feature: User can specify that a datetime date is after, but not equal to, a spe Scenario Outline: 'After' invalid datetime fails with error Given foo is after - Then the profile is invalid because "Date string '\d{4}-\d{2}-\d{2}T\d{2}:00:00.000Z' must be in ISO-8601 format: Either yyyy-MM-ddTHH:mm:ss.SSS\[Z\] between 0001-01-01T00:00:00.000Z and 9999-12-31T23:59:59.999Z or yyyy-mm-dd between 0001-01-01 and 9999-12-31" + Then the profile is invalid with error containing "must be in ISO-8601 format" And no data is created Examples: | dateValue | @@ -34,7 +34,7 @@ Feature: User can specify that a datetime date is after, but not equal to, a spe Scenario: 'After' non-existent leap year date fails with error Given foo is after 2019-02-29T00:00:00.000Z - Then the profile is invalid because "Date string '2019-02-29T00:00:00.000Z' must be in ISO-8601 format: Either yyyy-MM-ddTHH:mm:ss.SSS\[Z\] between 0001-01-01T00:00:00.000Z and 9999-12-31T23:59:59.999Z or yyyy-mm-dd between 0001-01-01 and 9999-12-31" + Then the profile is invalid with error containing "must be in ISO-8601 format" And no data is created ### after ### @@ -228,4 +228,4 @@ Feature: User can specify that a datetime date is after, but not equal to, a spe Scenario: Running a 'after' request that specifies the highest valid system date should be unsuccessful Given foo is after 10000-01-01T00:00:00.000Z - Then the profile is invalid because "Dates must be between 0001-01-01T00:00:00.000Z and 9999-12-31T23:59:59.999Z" + Then the profile is invalid with error containing "Dates must be between 0001-01-01T00:00:00.000Z and 9999-12-31T23:59:59.999Z | Field: foo | Constraint: after | Rule: Unnamed rule" diff --git a/orchestrator/src/test/java/com/scottlogic/deg/orchestrator/cucumber/features/operators/temporal/AfterOrAt.feature b/orchestrator/src/test/java/com/scottlogic/deg/orchestrator/cucumber/features/operators/temporal/AfterOrAt.feature index f0f222602..c642bc033 100644 --- a/orchestrator/src/test/java/com/scottlogic/deg/orchestrator/cucumber/features/operators/temporal/AfterOrAt.feature +++ b/orchestrator/src/test/java/com/scottlogic/deg/orchestrator/cucumber/features/operators/temporal/AfterOrAt.feature @@ -35,17 +35,17 @@ Feature: User can specify that a datetime date is more than, or the same as, a s Scenario: Running afterOrAt request that includes datetime field with date (YYYY-MM-DD) values that has invalid date should fail Given foo is after or at 2019-15-32T00:00:00.000Z - Then the profile is invalid because "Date string '2019-15-32T00:00:00.000Z' must be in ISO-8601 format: Either yyyy-MM-ddTHH:mm:ss.SSS\[Z\] between 0001-01-01T00:00:00.000Z and 9999-12-31T23:59:59.999Z or yyyy-mm-dd between 0001-01-01 and 9999-12-31" + Then the profile is invalid with error containing "must be in ISO-8601 format" And no data is created Scenario: Running afterOrAt request that includes datetime field with date and time (YYYY-MM-DDTHH:MM:SS) values that has invalid time should fail Given foo is after or at 2018-10-01T25:25:05.000Z - Then the profile is invalid because "Date string '2018-10-01T25:25:05.000Z' must be in ISO-8601 format: Either yyyy-MM-ddTHH:mm:ss.SSS\[Z\] between 0001-01-01T00:00:00.000Z and 9999-12-31T23:59:59.999Z or yyyy-mm-dd between 0001-01-01 and 9999-12-31" + Then the profile is invalid with error containing "must be in ISO-8601 format" And no data is created Scenario: Running afterOrAt request that includes datetime field with date and time (YYYY-MM-DDTHH:MM:SS) values that has invalid year should fail Given foo is after or at 0000-01-10T00:00:00.000Z - Then the profile is invalid because "Dates must be between 0001-01-01T00:00:00.000Z and 9999-12-31T23:59:59.999Z" + Then the profile is invalid with error containing "Dates must be between 0001-01-01T00:00:00.000Z and 9999-12-31T23:59:59.999Z | Field: foo | Constraint: afterOrAt | Rule: Unnamed rule" And no data is created Scenario: Running afterOrAt request that includes datetime field with date and time (YYYY-MM-DDTHH:MM:SS) values that has leap year diff --git a/orchestrator/src/test/java/com/scottlogic/deg/orchestrator/cucumber/features/operators/temporal/Before.feature b/orchestrator/src/test/java/com/scottlogic/deg/orchestrator/cucumber/features/operators/temporal/Before.feature index 4d1f78e20..e07050502 100644 --- a/orchestrator/src/test/java/com/scottlogic/deg/orchestrator/cucumber/features/operators/temporal/Before.feature +++ b/orchestrator/src/test/java/com/scottlogic/deg/orchestrator/cucumber/features/operators/temporal/Before.feature @@ -15,17 +15,17 @@ Feature: User can specify that a datetime date is lower than, but not equal to, Scenario: Running a 'before' request that specifies an invalid date should be unsuccessful Given foo is before 2019-30-30T00:00:00.000Z - Then the profile is invalid because "Date string '2019-30-30T00:00:00.000Z' must be in ISO-8601 format: Either yyyy-MM-ddTHH:mm:ss.SSS\[Z\] between 0001-01-01T00:00:00.000Z and 9999-12-31T23:59:59.999Z or yyyy-mm-dd between 0001-01-01 and 9999-12-31" + Then the profile is invalid with error containing "must be in ISO-8601 format" And no data is created Scenario: Running a 'before' request that specifies an invalid time should be unsuccessful Given foo is before 2019-01-01T24:00:00.000Z - Then the profile is invalid because "Date string '2019-01-01T24:00:00.000Z' must be in ISO-8601 format: Either yyyy-MM-ddTHH:mm:ss.SSS\[Z\] between 0001-01-01T00:00:00.000Z and 9999-12-31T23:59:59.999Z or yyyy-mm-dd between 0001-01-01 and 9999-12-31" + Then the profile is invalid with error containing "must be in ISO-8601 format" And no data is created Scenario: Running a 'before' request that specifies an invalid leap year should be unsuccessful Given foo is before 2019-02-29T00:00:00.000Z - Then the profile is invalid because "Date string '2019-02-29T00:00:00.000Z' must be in ISO-8601 format: Either yyyy-MM-ddTHH:mm:ss.SSS\[Z\] between 0001-01-01T00:00:00.000Z and 9999-12-31T23:59:59.999Z or yyyy-mm-dd between 0001-01-01 and 9999-12-31" + Then the profile is invalid with error containing "must be in ISO-8601 format" And no data is created #before @@ -95,4 +95,4 @@ Feature: User can specify that a datetime date is lower than, but not equal to, Scenario: Running a 'before' request that specifies the highest valid system date should be unsuccessful Given foo is before 0000-01-01T00:00:00.000Z - Then the profile is invalid because "Dates must be between 0001-01-01T00:00:00.000Z and 9999-12-31T23:59:59.999Z" + Then the profile is invalid with error containing "Dates must be between 0001-01-01T00:00:00.000Z and 9999-12-31T23:59:59.999Z | Field: foo | Constraint: before | Rule: Unnamed rule" diff --git a/orchestrator/src/test/java/com/scottlogic/deg/orchestrator/cucumber/features/operators/temporal/BeforeOrAt.feature b/orchestrator/src/test/java/com/scottlogic/deg/orchestrator/cucumber/features/operators/temporal/BeforeOrAt.feature index a664ee88b..3651809ca 100644 --- a/orchestrator/src/test/java/com/scottlogic/deg/orchestrator/cucumber/features/operators/temporal/BeforeOrAt.feature +++ b/orchestrator/src/test/java/com/scottlogic/deg/orchestrator/cucumber/features/operators/temporal/BeforeOrAt.feature @@ -8,18 +8,18 @@ Feature: User can specify that a datetime date is lower than, or the same as, a Scenario: Running beforeOrAt request that includes datetime field with date (YYYY-MM-DD) values that has invalid date should fail Given foo is before or at 2019-15-32T00:00:00.000Z And the generator can generate at most 5 rows - Then the profile is invalid because "Date string '2019-15-32T00:00:00.000Z' must be in ISO-8601 format: Either yyyy-MM-ddTHH:mm:ss.SSS\[Z\] between 0001-01-01T00:00:00.000Z and 9999-12-31T23:59:59.999Z or yyyy-mm-dd between 0001-01-01 and 9999-12-31" + Then the profile is invalid with error containing "must be in ISO-8601 format" And no data is created Scenario: Running beforeOrAt request that includes datetime field with date and time (YYYY-MM-DDTHH:MM:SS) values that has invalid time should fail Given foo is before or at 2018-10-01T25:25:05.000Z And the generator can generate at most 5 rows - Then the profile is invalid because "Date string '2018-10-01T25:25:05.000Z' must be in ISO-8601 format: Either yyyy-MM-ddTHH:mm:ss.SSS\[Z\] between 0001-01-01T00:00:00.000Z and 9999-12-31T23:59:59.999Z or yyyy-mm-dd between 0001-01-01 and 9999-12-31" + Then the profile is invalid with error containing "must be in ISO-8601 format" And no data is created Scenario: Running beforeOrAt request that includes datetime field with date and time (YYYY-MM-DDTHH:MM:SS) values that has invalid year should fail Given foo is before or at 0000-01-10T00:00:00.000Z - Then the profile is invalid because "Dates must be between 0001-01-01T00:00:00.000Z and 9999-12-31T23:59:59.999Z" + Then the profile is invalid with error containing "Dates must be between 0001-01-01T00:00:00.000Z and 9999-12-31T23:59:59.999Z | Field: foo | Constraint: beforeOrAt | Rule: Unnamed rule" And no data is created Scenario: Running beforeOrAt request against a non-contradicting beforeOrAt constraint should be successful 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 6a2a28d3a..998ff0a8b 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 @@ -18,7 +18,6 @@ import com.scottlogic.deg.common.profile.Field; import com.scottlogic.deg.common.profile.Fields; -import com.scottlogic.deg.common.profile.HelixDateTime; import com.scottlogic.deg.common.profile.HelixStringLength; import com.scottlogic.deg.common.util.NumberUtils; import com.scottlogic.deg.generator.builders.*; @@ -94,10 +93,10 @@ private static Stream allAtomicConstraints() { 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(AfterConstraint.class, sampleDate), + Arguments.of(AfterOrAtConstraint.class, sampleDate.plusDays(1)), + Arguments.of(BeforeConstraint.class, sampleDate.minusDays(1)), + Arguments.of(BeforeOrAtConstraint.class, sampleDate.plusDays(2)), Arguments.of(GreaterThanConstraint.class, NumberUtils.coerceToBigDecimal(100)), Arguments.of(GreaterThanOrEqualToConstraint.class, NumberUtils.coerceToBigDecimal(200)), diff --git a/profile/src/main/java/com/scottlogic/deg/profile/factories/DateTimeFactory.java b/profile/src/main/java/com/scottlogic/deg/profile/factories/DateTimeFactory.java new file mode 100644 index 000000000..8e386d5ce --- /dev/null +++ b/profile/src/main/java/com/scottlogic/deg/profile/factories/DateTimeFactory.java @@ -0,0 +1,55 @@ +package com.scottlogic.deg.profile.factories; + +import com.scottlogic.deg.common.ValidationException; + +import java.time.LocalDateTime; +import java.time.OffsetDateTime; +import java.time.ZoneOffset; +import java.time.format.DateTimeFormatter; +import java.time.format.DateTimeFormatterBuilder; +import java.time.format.DateTimeParseException; +import java.time.format.ResolverStyle; +import java.time.temporal.ChronoField; +import java.time.temporal.TemporalAccessor; + +public class DateTimeFactory +{ + private static final DateTimeFormatter FORMATTER = getDateTimeFormatter(); + private static final OffsetDateTime NOW = OffsetDateTime.now(); + + public static OffsetDateTime create(String dateTime) + { + try + { + if (dateTime.equalsIgnoreCase("NOW")) return NOW; + TemporalAccessor temporalAccessor = FORMATTER.parse(dateTime); + return temporalAccessor.isSupported(ChronoField.OFFSET_SECONDS) + ? OffsetDateTime.from(temporalAccessor) + : LocalDateTime.from(temporalAccessor).atOffset(ZoneOffset.UTC); + } catch (DateTimeParseException exception) + { + throw new ValidationException(String.format("Date string '%s' must be in ISO-8601 format: Either yyyy-MM-ddTHH:mm:ss.SSS[Z] between " + + "0001-01-01T00:00:00.000Z and 9999-12-31T23:59:59.999Z or yyyy-mm-dd between 0001-01-01 and 9999-12-31", dateTime)); + } + } + + private static DateTimeFormatter getDateTimeFormatter() + { + DateTimeFormatter dateFormat = new DateTimeFormatterBuilder() + .appendPattern("u-MM-dd") + .parseDefaulting(ChronoField.SECOND_OF_DAY,0) + .toFormatter(); + + DateTimeFormatter dateTimeFormatter = new DateTimeFormatterBuilder() + .append(DateTimeFormatter.ofPattern("u-MM-dd'T'HH:mm:ss'.'SSS")) + .optionalStart() + .appendOffset("+HH", "Z") + .toFormatter(); + + return new DateTimeFormatterBuilder() + .appendOptional(dateTimeFormatter) + .appendOptional(dateFormat) + .toFormatter() + .withResolverStyle(ResolverStyle.STRICT); + } +} diff --git a/profile/src/main/java/com/scottlogic/deg/profile/factories/constraint_factories/DateTimeConstraintFactory.java b/profile/src/main/java/com/scottlogic/deg/profile/factories/constraint_factories/DateTimeConstraintFactory.java index 9935ef8ad..b29e58729 100644 --- a/profile/src/main/java/com/scottlogic/deg/profile/factories/constraint_factories/DateTimeConstraintFactory.java +++ b/profile/src/main/java/com/scottlogic/deg/profile/factories/constraint_factories/DateTimeConstraintFactory.java @@ -19,7 +19,6 @@ 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.GranularToConstraintDTO; import com.scottlogic.deg.profile.dtos.constraints.atomic.numeric.*; @@ -29,12 +28,13 @@ import com.scottlogic.deg.profile.dtos.constraints.atomic.temporal.BeforeOrAtConstraintDTO; import com.scottlogic.deg.profile.dtos.constraints.atomic.textual.ContainsRegexConstraintDTO; import com.scottlogic.deg.profile.dtos.constraints.atomic.textual.MatchesRegexConstraintDTO; +import com.scottlogic.deg.profile.factories.DateTimeFactory; public class DateTimeConstraintFactory extends AtomicConstraintFactory { @Override Object parseValue(Object value) { - return HelixDateTime.create((String) value).getValue(); + return DateTimeFactory.create((String) value); } @Override @@ -93,22 +93,22 @@ LessThanOrEqualToConstraint createLessThanOrEqualToConstraint(LessThanOrEqualToC @Override AfterOrAtConstraint createAfterOrAtConstraint(AfterOrAtConstraintDTO dto, Field field) { - return new AfterOrAtConstraint(field, HelixDateTime.create(dto.value)); + return new AfterOrAtConstraint(field, DateTimeFactory.create(dto.value)); } @Override AfterConstraint createAfterConstraint(AfterConstraintDTO dto, Field field) { - return new AfterConstraint(field, HelixDateTime.create(dto.value)); + return new AfterConstraint(field, DateTimeFactory.create(dto.value)); } @Override BeforeOrAtConstraint createBeforeOrAtConstraint(BeforeOrAtConstraintDTO dto, Field field) { - return new BeforeOrAtConstraint(field, HelixDateTime.create(dto.value)); + return new BeforeOrAtConstraint(field, DateTimeFactory.create(dto.value)); } @Override BeforeConstraint createBeforeConstraint(BeforeConstraintDTO dto, Field field) { - return new BeforeConstraint(field, HelixDateTime.create(dto.value)); + return new BeforeConstraint(field, DateTimeFactory.create(dto.value)); } @Override diff --git a/profile/src/main/java/com/scottlogic/deg/profile/validators/profile/constraints/atomic/TemporalConstraintValidator.java b/profile/src/main/java/com/scottlogic/deg/profile/validators/profile/constraints/atomic/TemporalConstraintValidator.java index eff13c1f3..b8b232f39 100644 --- a/profile/src/main/java/com/scottlogic/deg/profile/validators/profile/constraints/atomic/TemporalConstraintValidator.java +++ b/profile/src/main/java/com/scottlogic/deg/profile/validators/profile/constraints/atomic/TemporalConstraintValidator.java @@ -20,11 +20,14 @@ import com.scottlogic.deg.common.validators.ValidationResult; import com.scottlogic.deg.profile.dtos.FieldDTO; import com.scottlogic.deg.profile.dtos.constraints.atomic.temporal.TemporalConstraintDTO; +import com.scottlogic.deg.profile.factories.DateTimeFactory; +import java.time.OffsetDateTime; import java.util.List; public class TemporalConstraintValidator extends AtomicConstraintValidator { + public TemporalConstraintValidator(String rule, List fields) { super(rule, fields); @@ -34,20 +37,32 @@ public TemporalConstraintValidator(String rule, List fields) public final ValidationResult validate(TemporalConstraintDTO dto) { ValidationResult fieldMustBeValid = fieldMustBeValid(dto); - if(!fieldMustBeValid.isSuccess) return fieldMustBeValid; + if (!fieldMustBeValid.isSuccess) return fieldMustBeValid; - ValidationResult dateMustBeSpecified = dateMustBeSpecified(dto); - if(!dateMustBeSpecified.isSuccess) return dateMustBeSpecified; + ValidationResult dateTimeMustBeValid = dateTimeMustBeValid(dto); + if (!dateTimeMustBeValid.isSuccess) return dateTimeMustBeValid; return fieldTypeMustMatchValueType(dto, FieldType.DATETIME); } - - private ValidationResult dateMustBeSpecified(TemporalConstraintDTO dto) + private ValidationResult dateTimeMustBeValid(TemporalConstraintDTO dto) { - String date = dto.getDate(); - return date != null && !date.isEmpty() - ? ValidationResult.success() - : ValidationResult.failure("Date must be specified" + getErrorInfo(dto)); + String dateTime = dto.getDate(); + if (dateTime == null || dateTime.isEmpty()) + { + return ValidationResult.failure("DateTime must be specified" + getErrorInfo(dto)); + } + try + { + OffsetDateTime offsetDateTime = DateTimeFactory.create(dateTime); + if (offsetDateTime.getYear() > 9999 || offsetDateTime.getYear() < 1) + { + return ValidationResult.failure("Dates must be between 0001-01-01T00:00:00.000Z and 9999-12-31T23:59:59.999Z" + getErrorInfo(dto)); + } + return ValidationResult.success(); + } catch (Exception e) + { + return ValidationResult.failure(e.getMessage() + getErrorInfo(dto)); + } } } 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 10939e09f..73289824f 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 @@ -641,8 +641,8 @@ public void shouldAllowValidISO8601DateTime() throws IOException { .filter(f -> f.getClass() == BeforeConstraint.class) .findFirst() .get(); - Assert.assertEquals(OffsetDateTime.parse("2019-01-01T00:00:00.000Z"), isAfter.referenceValue.getValue()); - Assert.assertEquals(OffsetDateTime.parse("2019-01-03T00:00:00.000Z"), isBefore.referenceValue.getValue()); + Assert.assertEquals(OffsetDateTime.parse("2019-01-01T00:00:00.000Z"), isAfter.referenceValue); + Assert.assertEquals(OffsetDateTime.parse("2019-01-03T00:00:00.000Z"), isBefore.referenceValue); } ); } From cce4587272ba493986390c690c4edbd4e192019c Mon Sep 17 00:00:00 2001 From: Charlton Dowding Date: Thu, 7 Nov 2019 14:40:35 +0000 Subject: [PATCH 03/10] Removed HelixStringLength --- .../deg/common/profile/HelixStringLength.java | 67 ------------------- .../atomic/LongerThanConstraint.java | 9 ++- .../atomic/NotStringLengthConstraint.java | 7 +- .../atomic/OfLengthConstraint.java | 13 ++-- .../atomic/ShorterThanConstraint.java | 9 ++- .../builders/ConstraintChainBuilder.java | 3 +- .../ConstraintToFieldSpecTests.java | 25 ++++--- .../walker/pruner/TreePrunerTests.java | 5 +- .../violator/ProfileViolationTests.java | 7 +- .../ViolationFiltersProviderTest.java | 5 +- .../atomic/numeric/IntegerConstraintDTO.java | 32 +++++++++ .../numeric/LongerThanConstraintDTO.java | 4 +- .../atomic/numeric/OfLengthConstraintDTO.java | 6 +- .../numeric/ShorterThanConstraintDTO.java | 4 +- .../StringConstraintFactory.java | 7 +- .../profile/ConstraintValidator.java | 3 +- .../atomic/IntegerConstraintValidator.java | 49 ++++++++++++++ .../reader/JsonProfileReaderTests.java | 2 +- 18 files changed, 130 insertions(+), 127 deletions(-) create mode 100644 profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/numeric/IntegerConstraintDTO.java create mode 100644 profile/src/main/java/com/scottlogic/deg/profile/validators/profile/constraints/atomic/IntegerConstraintValidator.java diff --git a/common/src/main/java/com/scottlogic/deg/common/profile/HelixStringLength.java b/common/src/main/java/com/scottlogic/deg/common/profile/HelixStringLength.java index f1e37bbab..e69de29bb 100644 --- a/common/src/main/java/com/scottlogic/deg/common/profile/HelixStringLength.java +++ b/common/src/main/java/com/scottlogic/deg/common/profile/HelixStringLength.java @@ -1,67 +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.common.profile; - -import com.scottlogic.deg.common.ValidationException; -import com.scottlogic.deg.common.util.Defaults; -import com.scottlogic.deg.common.util.NumberUtils; - -import java.math.BigDecimal; - -public class HelixStringLength -{ - private final int value; - - private HelixStringLength(int value) - { - this.value = value; - } - - public static HelixStringLength create(Object value) - { - BigDecimal stringLength = NumberUtils.coerceToBigDecimal(value); - validateIsInteger(stringLength); - validateNumberRange(stringLength); - return new HelixStringLength(stringLength.intValueExact()); - } - - public int getValue() - { - return value; - } - - private static void validateIsInteger(BigDecimal stringLength) - { - if (stringLength.stripTrailingZeros().scale() > 0) - { - throw new ValidationException(String.format("String length `%s` is not an integer", stringLength)); - } - } - - private static void validateNumberRange(BigDecimal stringLength) - { - BigDecimal max = BigDecimal.valueOf(Defaults.MAX_STRING_LENGTH); - BigDecimal min = BigDecimal.ZERO; - if (stringLength.compareTo(min) < 0) - { - throw new ValidationException(String.format("String length must have a value >= %s, currently is %s", min.toPlainString(), stringLength.toPlainString())); - } - if (stringLength.compareTo(max) > 0) - { - throw new ValidationException(String.format("String length must have a value <= %s, currently is %s", max.toPlainString(), stringLength.toPlainString())); - } - } -} diff --git a/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/LongerThanConstraint.java b/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/LongerThanConstraint.java index c331551e1..e70270a07 100644 --- a/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/LongerThanConstraint.java +++ b/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/LongerThanConstraint.java @@ -17,7 +17,6 @@ package com.scottlogic.deg.generator.profile.constraints.atomic; 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.FieldSpecFactory; import com.scottlogic.deg.generator.restrictions.StringRestrictionsFactory; @@ -26,9 +25,9 @@ public class LongerThanConstraint implements AtomicConstraint { public final Field field; - public final HelixStringLength referenceValue; + public final int referenceValue; - public LongerThanConstraint(Field field, HelixStringLength referenceValue) { + public LongerThanConstraint(Field field, int referenceValue) { this.referenceValue = referenceValue; this.field = field; } @@ -41,12 +40,12 @@ public Field getField() { @Override public AtomicConstraint negate() { - return new ShorterThanConstraint(field, HelixStringLength.create(referenceValue.getValue() + 1)); + return new ShorterThanConstraint(field, referenceValue + 1); } @Override public FieldSpec toFieldSpec() { - return FieldSpecFactory.fromRestriction(StringRestrictionsFactory.forMinLength(referenceValue.getValue() + 1)); + return FieldSpecFactory.fromRestriction(StringRestrictionsFactory.forMinLength(referenceValue + 1)); } @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 2444215b2..78a84fedd 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 @@ -16,7 +16,6 @@ package com.scottlogic.deg.generator.profile.constraints.atomic; 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.FieldSpecFactory; import com.scottlogic.deg.generator.restrictions.StringRestrictionsFactory; @@ -25,9 +24,9 @@ public class NotStringLengthConstraint implements AtomicConstraint { public final Field field; - public final HelixStringLength referenceValue; + public final int referenceValue; - public NotStringLengthConstraint(Field field, HelixStringLength referenceValue) { + public NotStringLengthConstraint(Field field, int referenceValue) { this.referenceValue = referenceValue; this.field = field; } @@ -44,7 +43,7 @@ public AtomicConstraint negate() { @Override public FieldSpec toFieldSpec() { - return FieldSpecFactory.fromRestriction(StringRestrictionsFactory.forLength(referenceValue.getValue(), true)); + return FieldSpecFactory.fromRestriction(StringRestrictionsFactory.forLength(referenceValue, true)); } @Override diff --git a/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/OfLengthConstraint.java b/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/OfLengthConstraint.java index 21d6e00ab..4b940b52c 100644 --- a/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/OfLengthConstraint.java +++ b/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/OfLengthConstraint.java @@ -17,7 +17,6 @@ package com.scottlogic.deg.generator.profile.constraints.atomic; 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.FieldSpecFactory; import com.scottlogic.deg.generator.restrictions.StringRestrictionsFactory; @@ -26,9 +25,9 @@ public class OfLengthConstraint implements AtomicConstraint { public final Field field; - public final HelixStringLength referenceValue; + public final int referenceValue; - public OfLengthConstraint(Field field, HelixStringLength referenceValue) { + public OfLengthConstraint(Field field, int referenceValue) { this.referenceValue = referenceValue; this.field = field; } @@ -45,7 +44,7 @@ public AtomicConstraint negate() { @Override public FieldSpec toFieldSpec() { - return FieldSpecFactory.fromRestriction(StringRestrictionsFactory.forLength(referenceValue.getValue(), false)); + return FieldSpecFactory.fromRestriction(StringRestrictionsFactory.forLength(referenceValue, false)); } @Override @@ -56,14 +55,14 @@ public boolean equals(Object o){ } if (o == null || getClass() != o.getClass()) return false; OfLengthConstraint constraint = (OfLengthConstraint) o; - return Objects.equals(field, constraint.field) && Objects.equals(referenceValue.getValue(), constraint.referenceValue.getValue()); + return Objects.equals(field, constraint.field) && Objects.equals(referenceValue, constraint.referenceValue); } @Override public int hashCode(){ - return Objects.hash(field, referenceValue.getValue()); + return Objects.hash(field, referenceValue); } @Override - public String toString() { return String.format("`%s` length = %s", field.getName(), referenceValue.getValue()); } + 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/ShorterThanConstraint.java b/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/ShorterThanConstraint.java index e56bf244f..1bc6c5c20 100644 --- a/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/ShorterThanConstraint.java +++ b/generator/src/main/java/com/scottlogic/deg/generator/profile/constraints/atomic/ShorterThanConstraint.java @@ -17,7 +17,6 @@ package com.scottlogic.deg.generator.profile.constraints.atomic; 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.FieldSpecFactory; import com.scottlogic.deg.generator.restrictions.StringRestrictionsFactory; @@ -26,9 +25,9 @@ public class ShorterThanConstraint implements AtomicConstraint { public final Field field; - public final HelixStringLength referenceValue; + public final int referenceValue; - public ShorterThanConstraint(Field field, HelixStringLength referenceValue) { + public ShorterThanConstraint(Field field, int referenceValue) { this.referenceValue = referenceValue; this.field = field; } @@ -40,12 +39,12 @@ public Field getField() { @Override public AtomicConstraint negate() { - return new LongerThanConstraint(field, HelixStringLength.create(referenceValue.getValue() - 1)); + return new LongerThanConstraint(field, referenceValue - 1); } @Override public FieldSpec toFieldSpec() { - return FieldSpecFactory.fromRestriction(StringRestrictionsFactory.forMaxLength(referenceValue.getValue() - 1)); + return FieldSpecFactory.fromRestriction(StringRestrictionsFactory.forMaxLength(referenceValue - 1)); } @Override 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 f27108ff3..c19dcd17b 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 @@ -17,7 +17,6 @@ package com.scottlogic.deg.generator.builders; import com.scottlogic.deg.common.profile.Field; -import com.scottlogic.deg.common.profile.HelixStringLength; import com.scottlogic.deg.common.util.NumberUtils; import com.scottlogic.deg.generator.fieldspecs.whitelist.DistributedList; import com.scottlogic.deg.generator.profile.constraints.Constraint; @@ -129,7 +128,7 @@ public ConstraintChainBuilder withInSetConstraint(Field field, Object[] legal } public ConstraintChainBuilder withOfLengthConstraint(Field fooField, int length) { - return saveAndSet(new OfLengthConstraint(fooField, HelixStringLength.create(length))); + return saveAndSet(new OfLengthConstraint(fooField, length)); } public ConstraintChainBuilder withAfterConstraint(Field field, OffsetDateTime dateTime) { 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 de215f7c0..9648f9227 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 @@ -17,7 +17,6 @@ package com.scottlogic.deg.generator.restrictions; import com.scottlogic.deg.common.profile.Field; -import com.scottlogic.deg.common.profile.HelixStringLength; import com.scottlogic.deg.generator.fieldspecs.RestrictionsFieldSpec; import com.scottlogic.deg.generator.profile.constraints.atomic.LongerThanConstraint; import com.scottlogic.deg.generator.profile.constraints.atomic.ShorterThanConstraint; @@ -33,7 +32,7 @@ class ConstraintToFieldSpecTests { @Test void construct_stringHasLengthConstraintRetrievedTwice_returnsTheSameGeneratorInstance() { - OfLengthConstraint constraint = new OfLengthConstraint(testField, HelixStringLength.create(10)); + OfLengthConstraint constraint = new OfLengthConstraint(testField, 10); final RestrictionsFieldSpec firstInstance = (RestrictionsFieldSpec)constraint.toFieldSpec(); final RestrictionsFieldSpec secondInstance = (RestrictionsFieldSpec)constraint.toFieldSpec(); @@ -43,7 +42,7 @@ void construct_stringHasLengthConstraintRetrievedTwice_returnsTheSameGeneratorIn @Test void construct_stringHasLengthConstraintViolatedTwice_returnsTheSameGeneratorInstance() { - ViolatedAtomicConstraint constraint = new ViolatedAtomicConstraint(new OfLengthConstraint(testField,HelixStringLength.create(10))); + ViolatedAtomicConstraint constraint = new ViolatedAtomicConstraint(new OfLengthConstraint(testField,10)); final RestrictionsFieldSpec firstInstance = (RestrictionsFieldSpec) constraint.toFieldSpec(); final RestrictionsFieldSpec secondInstance = (RestrictionsFieldSpec) constraint.toFieldSpec(); @@ -53,8 +52,8 @@ void construct_stringHasLengthConstraintViolatedTwice_returnsTheSameGeneratorIns @Test void construct_twoInstancesOfStringHasLengthConstraintCalledWithEqualValues_returnsTheSameGeneratorInstance() { - OfLengthConstraint firstConstraint = new OfLengthConstraint(testField,HelixStringLength.create(20)); - OfLengthConstraint secondConstraint = new OfLengthConstraint( testField, HelixStringLength.create(20)); + OfLengthConstraint firstConstraint = new OfLengthConstraint(testField,20); + OfLengthConstraint secondConstraint = new OfLengthConstraint( testField, 20); final RestrictionsFieldSpec firstInstance = (RestrictionsFieldSpec) firstConstraint.toFieldSpec(); final RestrictionsFieldSpec secondInstance = (RestrictionsFieldSpec) secondConstraint.toFieldSpec(); @@ -64,7 +63,7 @@ void construct_twoInstancesOfStringHasLengthConstraintCalledWithEqualValues_retu @Test void construct_isStringLongerThanConstraintRetrievedTwice_returnsTheSameGeneratorInstance() { - LongerThanConstraint constraint = new LongerThanConstraint(testField, HelixStringLength.create(15)); + LongerThanConstraint constraint = new LongerThanConstraint(testField, 15); final RestrictionsFieldSpec firstInstance = (RestrictionsFieldSpec) constraint.toFieldSpec(); final RestrictionsFieldSpec secondInstance = (RestrictionsFieldSpec) constraint.toFieldSpec(); @@ -75,7 +74,7 @@ void construct_isStringLongerThanConstraintRetrievedTwice_returnsTheSameGenerato @Test void construct_isStringLongerThanConstraintViolatedTwice_returnsTheSameGeneratorInstance() { ViolatedAtomicConstraint constraint = new ViolatedAtomicConstraint( - new LongerThanConstraint( testField,HelixStringLength.create(10)) + new LongerThanConstraint( testField,10) ); final RestrictionsFieldSpec firstInstance = (RestrictionsFieldSpec) constraint.toFieldSpec(); @@ -86,8 +85,8 @@ void construct_isStringLongerThanConstraintViolatedTwice_returnsTheSameGenerator @Test void construct_twoInstancesOfIsStringLongerThanConstraintCalledWithEqualValues_returnsTheSameGeneratorInstance() { - LongerThanConstraint firstConstraint = new LongerThanConstraint(testField, HelixStringLength.create(20)); - LongerThanConstraint secondConstraint = new LongerThanConstraint(testField, HelixStringLength.create(20)); + LongerThanConstraint firstConstraint = new LongerThanConstraint(testField, 20); + LongerThanConstraint secondConstraint = new LongerThanConstraint(testField, 20); final RestrictionsFieldSpec firstInstance = (RestrictionsFieldSpec) firstConstraint.toFieldSpec(); final RestrictionsFieldSpec secondInstance = (RestrictionsFieldSpec) secondConstraint.toFieldSpec(); @@ -97,7 +96,7 @@ void construct_twoInstancesOfIsStringLongerThanConstraintCalledWithEqualValues_r @Test void construct_isStringShorterThanConstraintRetrievedTwice_returnsTheSameGeneratorInstance() { - ShorterThanConstraint constraint = new ShorterThanConstraint(testField, HelixStringLength.create(25)); + ShorterThanConstraint constraint = new ShorterThanConstraint(testField,25); final RestrictionsFieldSpec firstInstance = (RestrictionsFieldSpec) constraint.toFieldSpec(); final RestrictionsFieldSpec secondInstance = (RestrictionsFieldSpec) constraint.toFieldSpec(); @@ -108,7 +107,7 @@ void construct_isStringShorterThanConstraintRetrievedTwice_returnsTheSameGenerat @Test void construct_isStringShorterThanConstraintViolatedTwice_returnsTheSameGeneratorInstance() { ViolatedAtomicConstraint constraint = new ViolatedAtomicConstraint( - new ShorterThanConstraint(testField, HelixStringLength.create(10)) + new ShorterThanConstraint(testField, 10) ); final RestrictionsFieldSpec firstInstance = (RestrictionsFieldSpec) constraint.toFieldSpec(); @@ -119,8 +118,8 @@ void construct_isStringShorterThanConstraintViolatedTwice_returnsTheSameGenerato @Test void construct_twoInstancesOfIsStringShorterThanConstraintCalledWithEqualValues_returnsTheSameGeneratorInstance() { - ShorterThanConstraint firstConstraint = new ShorterThanConstraint(testField, HelixStringLength.create(20)); - ShorterThanConstraint secondConstraint = new ShorterThanConstraint(testField, HelixStringLength.create(20)); + ShorterThanConstraint firstConstraint = new ShorterThanConstraint(testField, 20); + ShorterThanConstraint secondConstraint = new ShorterThanConstraint(testField, 20); final RestrictionsFieldSpec firstInstance = (RestrictionsFieldSpec) firstConstraint.toFieldSpec(); final RestrictionsFieldSpec secondInstance = (RestrictionsFieldSpec) secondConstraint.toFieldSpec(); 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 36c51b331..fe36720a7 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 @@ -17,7 +17,6 @@ package com.scottlogic.deg.generator.walker.pruner; import com.scottlogic.deg.common.profile.Field; -import com.scottlogic.deg.common.profile.HelixStringLength; import com.scottlogic.deg.generator.decisiontree.ConstraintNode; import com.scottlogic.deg.generator.decisiontree.ConstraintNodeBuilder; import com.scottlogic.deg.generator.fieldspecs.FieldSpec; @@ -68,7 +67,7 @@ class TreePrunerTests { public void pruneConstraintNode_leafNodeContradictionsWithParent_returnsContradictory() { //Arrange Set inputWhitelist = new HashSet<>(Arrays.asList("a", "b")); - ConstraintNode tree = new ConstraintNodeBuilder().addAtomicConstraints(new LongerThanConstraint(field, HelixStringLength.create(5))).build(); + ConstraintNode tree = new ConstraintNodeBuilder().addAtomicConstraints(new LongerThanConstraint(field, 5)).build(); FieldSpec inputFieldSpec = FieldSpecFactory.fromList(DistributedList.uniform(inputWhitelist)) .withNotNull(); @@ -87,7 +86,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 ShorterThanConstraint(field, HelixStringLength.create(5))).build(); + ConstraintNode tree = new ConstraintNodeBuilder().addAtomicConstraints(new ShorterThanConstraint(field, 5)).build(); FieldSpec inputFieldSpec = FieldSpecFactory.fromList( (DistributedList.uniform(inputWhitelist))); 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 998ff0a8b..f21f6cc30 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 @@ -18,7 +18,6 @@ import com.scottlogic.deg.common.profile.Field; import com.scottlogic.deg.common.profile.Fields; -import com.scottlogic.deg.common.profile.HelixStringLength; import com.scottlogic.deg.common.util.NumberUtils; import com.scottlogic.deg.generator.builders.*; import com.scottlogic.deg.generator.fieldspecs.whitelist.DistributedList; @@ -89,9 +88,9 @@ private static Stream allAtomicConstraints() { Arguments.of(ContainsRegexConstraint.class, Pattern.compile("\\w+")), Arguments.of(MatchesRegexConstraint.class, Pattern.compile("\\d+")), - Arguments.of(LongerThanConstraint.class, HelixStringLength.create(10)), - Arguments.of(ShorterThanConstraint.class, HelixStringLength.create(20)), - Arguments.of(OfLengthConstraint.class, HelixStringLength.create(15)), + Arguments.of(LongerThanConstraint.class, 10), + Arguments.of(ShorterThanConstraint.class,20), + Arguments.of(OfLengthConstraint.class,15), Arguments.of(AfterConstraint.class, sampleDate), Arguments.of(AfterOrAtConstraint.class, sampleDate.plusDays(1)), 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 31f0177f3..d63d77cfd 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 @@ -16,7 +16,6 @@ package com.scottlogic.deg.orchestrator.violation; -import com.scottlogic.deg.common.profile.HelixStringLength; 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; @@ -72,11 +71,11 @@ void hasLengthConstraintsToViolate_ReturnsOneFilter_ThatDoesNotAcceptHasLengthCo assertThat(filter.canViolate( - new OfLengthConstraint(null, HelixStringLength.create(2))), + new OfLengthConstraint(null,2)), is(false)); assertThat(filter.canViolate( - new ShorterThanConstraint(null, HelixStringLength.create(5))), + new ShorterThanConstraint(null, 5)), is(true)); } diff --git a/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/numeric/IntegerConstraintDTO.java b/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/numeric/IntegerConstraintDTO.java new file mode 100644 index 000000000..11a435cd4 --- /dev/null +++ b/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/numeric/IntegerConstraintDTO.java @@ -0,0 +1,32 @@ +/* + * 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.atomic.numeric; + +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.scottlogic.deg.profile.dtos.constraints.ConstraintType; +import com.scottlogic.deg.profile.dtos.constraints.atomic.AtomicConstraintDTO; + +public abstract class IntegerConstraintDTO extends AtomicConstraintDTO +{ + IntegerConstraintDTO(ConstraintType type) + { + super(type); + } + + @JsonIgnore + public abstract int getInt(); +} diff --git a/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/numeric/LongerThanConstraintDTO.java b/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/numeric/LongerThanConstraintDTO.java index e49263213..27bb8d3e1 100644 --- a/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/numeric/LongerThanConstraintDTO.java +++ b/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/numeric/LongerThanConstraintDTO.java @@ -23,7 +23,7 @@ import com.scottlogic.deg.profile.dtos.constraints.ConstraintTypeJsonProperty; @JsonDeserialize(as = LongerThanConstraintDTO.class) -public class LongerThanConstraintDTO extends NumericConstraintDTO +public class LongerThanConstraintDTO extends IntegerConstraintDTO { @JsonProperty(ConstraintTypeJsonProperty.LONGER_THAN) public int value; @@ -34,7 +34,7 @@ public LongerThanConstraintDTO() { @Override @JsonIgnore - public Number getNumber() + public int getInt() { return value; } diff --git a/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/numeric/OfLengthConstraintDTO.java b/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/numeric/OfLengthConstraintDTO.java index 09e1cf063..1fb357eda 100644 --- a/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/numeric/OfLengthConstraintDTO.java +++ b/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/numeric/OfLengthConstraintDTO.java @@ -16,14 +16,13 @@ package com.scottlogic.deg.profile.dtos.constraints.atomic.numeric; -import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import com.scottlogic.deg.profile.dtos.constraints.ConstraintType; import com.scottlogic.deg.profile.dtos.constraints.ConstraintTypeJsonProperty; @JsonDeserialize(as = OfLengthConstraintDTO.class) -public class OfLengthConstraintDTO extends NumericConstraintDTO +public class OfLengthConstraintDTO extends IntegerConstraintDTO { @JsonProperty(ConstraintTypeJsonProperty.OF_LENGTH) public int value; @@ -33,8 +32,7 @@ public OfLengthConstraintDTO() { } @Override - @JsonIgnore - public Number getNumber() + public int getInt() { return value; } diff --git a/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/numeric/ShorterThanConstraintDTO.java b/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/numeric/ShorterThanConstraintDTO.java index 1e6b2abd8..655ef7878 100644 --- a/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/numeric/ShorterThanConstraintDTO.java +++ b/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/numeric/ShorterThanConstraintDTO.java @@ -23,7 +23,7 @@ import com.scottlogic.deg.profile.dtos.constraints.ConstraintTypeJsonProperty; @JsonDeserialize(as = ShorterThanConstraintDTO.class) -public class ShorterThanConstraintDTO extends NumericConstraintDTO +public class ShorterThanConstraintDTO extends IntegerConstraintDTO { @JsonProperty(ConstraintTypeJsonProperty.SHORTER_THAN) public int value; @@ -34,7 +34,7 @@ public ShorterThanConstraintDTO() { @Override @JsonIgnore - public Number getNumber() + public int getInt() { return value; } diff --git a/profile/src/main/java/com/scottlogic/deg/profile/factories/constraint_factories/StringConstraintFactory.java b/profile/src/main/java/com/scottlogic/deg/profile/factories/constraint_factories/StringConstraintFactory.java index 11009e25c..1adbd2db7 100644 --- a/profile/src/main/java/com/scottlogic/deg/profile/factories/constraint_factories/StringConstraintFactory.java +++ b/profile/src/main/java/com/scottlogic/deg/profile/factories/constraint_factories/StringConstraintFactory.java @@ -18,7 +18,6 @@ package com.scottlogic.deg.profile.factories.constraint_factories; 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.GranularToConstraintDTO; import com.scottlogic.deg.profile.dtos.constraints.atomic.numeric.*; @@ -51,17 +50,17 @@ ContainsRegexConstraint createContainsRegexConstraint(ContainsRegexConstraintDTO @Override OfLengthConstraint createOfLengthConstraint(OfLengthConstraintDTO dto, Field field) { - return new OfLengthConstraint(field, HelixStringLength.create(dto.value)); + return new OfLengthConstraint(field, dto.value); } @Override ShorterThanConstraint createShorterThanConstraint(ShorterThanConstraintDTO dto, Field field) { - return new ShorterThanConstraint(field, HelixStringLength.create(dto.value)); + return new ShorterThanConstraint(field, dto.value); } @Override LongerThanConstraint createLongerThanConstraint(LongerThanConstraintDTO dto, Field field) { - return new LongerThanConstraint(field, HelixStringLength.create(dto.value)); + return new LongerThanConstraint(field, dto.value); } @Override diff --git a/profile/src/main/java/com/scottlogic/deg/profile/validators/profile/ConstraintValidator.java b/profile/src/main/java/com/scottlogic/deg/profile/validators/profile/ConstraintValidator.java index 8bd597f39..301859a7f 100644 --- a/profile/src/main/java/com/scottlogic/deg/profile/validators/profile/ConstraintValidator.java +++ b/profile/src/main/java/com/scottlogic/deg/profile/validators/profile/ConstraintValidator.java @@ -24,6 +24,7 @@ import com.scottlogic.deg.profile.dtos.constraints.NotConstraintDTO; import com.scottlogic.deg.profile.dtos.constraints.atomic.InSetConstraintDTO; import com.scottlogic.deg.profile.dtos.constraints.atomic.IsNullConstraintDTO; +import com.scottlogic.deg.profile.dtos.constraints.atomic.numeric.IntegerConstraintDTO; 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; @@ -92,7 +93,7 @@ protected static ValidationResult validateConstraint(ConstraintDTO dto, String r case OF_LENGTH: case LONGER_THAN: case SHORTER_THAN: - return new NumericConstraintValidator(rule, fields, FieldType.STRING).validate((NumericConstraintDTO) dto); + return new IntegerConstraintValidator(rule, fields, FieldType.STRING).validate((IntegerConstraintDTO) dto); case GREATER_THAN: case GREATER_THAN_OR_EQUAL_TO: case LESS_THAN: diff --git a/profile/src/main/java/com/scottlogic/deg/profile/validators/profile/constraints/atomic/IntegerConstraintValidator.java b/profile/src/main/java/com/scottlogic/deg/profile/validators/profile/constraints/atomic/IntegerConstraintValidator.java new file mode 100644 index 000000000..047fa5095 --- /dev/null +++ b/profile/src/main/java/com/scottlogic/deg/profile/validators/profile/constraints/atomic/IntegerConstraintValidator.java @@ -0,0 +1,49 @@ +package com.scottlogic.deg.profile.validators.profile.constraints.atomic; + +import com.scottlogic.deg.common.profile.FieldType; +import com.scottlogic.deg.common.util.Defaults; +import com.scottlogic.deg.common.validators.ValidationResult; +import com.scottlogic.deg.profile.dtos.FieldDTO; +import com.scottlogic.deg.profile.dtos.constraints.atomic.numeric.IntegerConstraintDTO; + +import java.math.BigDecimal; +import java.util.List; + +public class IntegerConstraintValidator extends AtomicConstraintValidator +{ + private final FieldType expectedFieldType; + + public IntegerConstraintValidator(String rule, List fields, FieldType expectedFieldType) + { + super(rule, fields); + this.expectedFieldType = expectedFieldType; + } + + @Override + public final ValidationResult validate(IntegerConstraintDTO dto) + { + ValidationResult fieldMustBeValid = fieldMustBeValid(dto); + if(!fieldMustBeValid.isSuccess) return fieldMustBeValid; + + ValidationResult integerMustBeValid = integerMustBeValid(dto); + if(!integerMustBeValid.isSuccess) return integerMustBeValid; + + return fieldTypeMustMatchValueType(dto, expectedFieldType); + } + + private ValidationResult integerMustBeValid(IntegerConstraintDTO dto) + { + BigDecimal integer = BigDecimal.valueOf(dto.getInt()); + BigDecimal max = BigDecimal.valueOf(Defaults.MAX_STRING_LENGTH); + BigDecimal min = BigDecimal.ZERO; + if (integer.compareTo(min) < 0) + { + return ValidationResult.failure(String.format("String length must have a value >= %s, currently is %s", min.toPlainString(), integer.toPlainString())); + } + if (integer.compareTo(max) > 0) + { + return ValidationResult.failure(String.format("String length must have a value <= %s, currently is %s", max.toPlainString(), integer.toPlainString())); + } + return ValidationResult.success(); + } +} 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 73289824f..c3b108a97 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 @@ -373,7 +373,7 @@ public void shouldDeserialiseIsOfLengthConstraint() throws IOException { ruleWithConstraints( typedConstraint( OfLengthConstraint.class, - c -> Assert.assertThat(c.referenceValue.getValue(), equalTo(5))))); + c -> Assert.assertThat(c.referenceValue, equalTo(5))))); } @Test From da48922365a9f5066a56cc0fa41e83fb9f996935 Mon Sep 17 00:00:00 2001 From: Charlton Dowding Date: Thu, 7 Nov 2019 14:43:25 +0000 Subject: [PATCH 04/10] feat(#1474): Removed Helix data types --- .../com/scottlogic/deg/profile/factories/DateTimeFactory.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/profile/src/main/java/com/scottlogic/deg/profile/factories/DateTimeFactory.java b/profile/src/main/java/com/scottlogic/deg/profile/factories/DateTimeFactory.java index 8e386d5ce..f74c038ba 100644 --- a/profile/src/main/java/com/scottlogic/deg/profile/factories/DateTimeFactory.java +++ b/profile/src/main/java/com/scottlogic/deg/profile/factories/DateTimeFactory.java @@ -39,13 +39,11 @@ private static DateTimeFormatter getDateTimeFormatter() .appendPattern("u-MM-dd") .parseDefaulting(ChronoField.SECOND_OF_DAY,0) .toFormatter(); - DateTimeFormatter dateTimeFormatter = new DateTimeFormatterBuilder() .append(DateTimeFormatter.ofPattern("u-MM-dd'T'HH:mm:ss'.'SSS")) .optionalStart() .appendOffset("+HH", "Z") .toFormatter(); - return new DateTimeFormatterBuilder() .appendOptional(dateTimeFormatter) .appendOptional(dateFormat) From 8edb2e95dda150c96f4daa615b1dc97d49e71972 Mon Sep 17 00:00:00 2001 From: Charlton Dowding Date: Thu, 7 Nov 2019 15:52:51 +0000 Subject: [PATCH 05/10] Restuctured ConstraintType --- .../testframework/steps/BooleanValueStep.java | 2 +- .../testframework/steps/GeneralTestStep.java | 2 +- .../testframework/steps/NullValueStep.java | 2 +- .../utils/CucumberTestState.java | 4 + .../dtos/constraints/ConstraintDTO.java | 17 +-- .../dtos/constraints/ConstraintType.java | 104 ++++++++++++------ .../ConstraintTypeJsonProperty.java | 53 --------- .../constraints/InvalidConstraintDTO.java | 4 +- .../atomic/AtomicConstraintDTO.java | 6 - .../atomic/EqualToConstraintDTO.java | 12 +- .../atomic/GranularToConstraintDTO.java | 10 +- .../atomic/InMapFromFileConstraintDTO.java | 10 +- .../atomic/InSetConstraintDTO.java | 11 +- .../atomic/InSetFromFileConstraintDTO.java | 14 +-- .../atomic/IsNullConstraintDTO.java | 13 +-- .../IntegerConstraintDTO.java | 8 +- .../LongerThanConstraintDTO.java | 14 +-- .../OfLengthConstraintDTO.java | 12 +- .../ShorterThanConstraintDTO.java | 15 +-- .../numeric/GreaterThanConstraintDTO.java | 16 +-- .../GreaterThanOrEqualToConstraintDTO.java | 15 +-- .../atomic/numeric/LessThanConstraintDTO.java | 12 +- .../LessThanOrEqualToConstraintDTO.java | 12 +- .../atomic/numeric/NumericConstraintDTO.java | 6 - .../atomic/temporal/AfterConstraintDTO.java | 12 +- .../temporal/AfterOrAtConstraintDTO.java | 13 +-- .../atomic/temporal/BeforeConstraintDTO.java | 13 +-- .../temporal/BeforeOrAtConstraintDTO.java | 12 +- .../temporal/TemporalConstraintDTO.java | 6 - .../textual/ContainsRegexConstraintDTO.java | 10 +- .../textual/MatchesRegexConstraintDTO.java | 10 +- .../atomic/textual/RegexConstraintDTO.java | 6 - .../grammatical/AllOfConstraintDTO.java | 10 +- .../grammatical/AnyOfConstraintDTO.java | 10 +- .../grammatical/ConditionalConstraintDTO.java | 16 ++- .../grammatical/GrammaticalConstraintDTO.java | 5 - .../{ => grammatical}/NotConstraintDTO.java | 14 +-- .../relations/AfterFieldConstraintDTO.java | 16 ++- .../AfterOrAtFieldConstraintDTO.java | 16 ++- .../relations/BeforeFieldConstraintDTO.java | 16 ++- .../BeforeOrAtFieldConstraintDTO.java | 16 ++- .../relations/EqualToFieldConstraintDTO.java | 16 ++- .../GreaterThanFieldConstraintDTO.java | 16 ++- ...reaterThanOrEqualToFieldConstraintDTO.java | 18 ++- .../relations/InMapConstraintDTO.java | 9 +- .../relations/LessThanFieldConstraintDTO.java | 16 ++- .../LessThanOrEqualToFieldConstraintDTO.java | 13 +-- .../relations/RelationalConstraintDTO.java | 5 - .../AtomicConstraintFactory.java | 3 + .../DateTimeConstraintFactory.java | 3 + .../NumericConstraintFactory.java | 3 + .../StringConstraintFactory.java | 3 + .../serialisation/ConstraintDeserializer.java | 82 ++------------ .../profile/services/ConstraintService.java | 2 +- .../deg/profile/services/FieldService.java | 2 +- .../profile/ConstraintValidator.java | 8 +- .../constraints/NotConstraintValidator.java | 2 +- .../atomic/IntegerConstraintValidator.java | 2 +- .../AtomicConstraintDeserialiserTests.java | 3 + ...rammaticalConstraintDeserialiserTests.java | 2 +- .../deg/profile/dtos/ConstraintTypeTest.java | 4 +- 61 files changed, 277 insertions(+), 510 deletions(-) rename profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/{numeric => integer}/IntegerConstraintDTO.java (79%) rename profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/{numeric => integer}/LongerThanConstraintDTO.java (68%) rename profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/{numeric => integer}/OfLengthConstraintDTO.java (72%) rename profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/{numeric => integer}/ShorterThanConstraintDTO.java (68%) rename profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/{ => grammatical}/NotConstraintDTO.java (75%) diff --git a/orchestrator/src/test/java/com/scottlogic/deg/orchestrator/cucumber/testframework/steps/BooleanValueStep.java b/orchestrator/src/test/java/com/scottlogic/deg/orchestrator/cucumber/testframework/steps/BooleanValueStep.java index c06b582c7..1d8ba2515 100644 --- a/orchestrator/src/test/java/com/scottlogic/deg/orchestrator/cucumber/testframework/steps/BooleanValueStep.java +++ b/orchestrator/src/test/java/com/scottlogic/deg/orchestrator/cucumber/testframework/steps/BooleanValueStep.java @@ -34,6 +34,6 @@ public void whenFieldIsConstrainedByNumericValue(String fieldName, Boolean value @When("{fieldVar} is anything but {operator} {boolean}") public void whenFieldIsNotConstrainedByNumericValue(String fieldName, String constraintName, Boolean value) { - this.state.addNotConstraint(fieldName, ConstraintType.fromPropertyName(constraintName), value); + this.state.addNotConstraint(fieldName, ConstraintType.fromName(constraintName), value); } } diff --git a/orchestrator/src/test/java/com/scottlogic/deg/orchestrator/cucumber/testframework/steps/GeneralTestStep.java b/orchestrator/src/test/java/com/scottlogic/deg/orchestrator/cucumber/testframework/steps/GeneralTestStep.java index 637ff8739..5adbddb0f 100644 --- a/orchestrator/src/test/java/com/scottlogic/deg/orchestrator/cucumber/testframework/steps/GeneralTestStep.java +++ b/orchestrator/src/test/java/com/scottlogic/deg/orchestrator/cucumber/testframework/steps/GeneralTestStep.java @@ -81,7 +81,7 @@ public void setTheCombinationStrategy(CombinationStrategyType strategy) { @When("we do not violate any {operator} constraints") public void constraintTypeIsNotViolated(String operator) { - this.state.addConstraintToNotViolate(ConstraintType.fromPropertyName(operator)); + this.state.addConstraintToNotViolate(ConstraintType.fromName(operator)); } @Given("the data requested is {generationMode}") diff --git a/orchestrator/src/test/java/com/scottlogic/deg/orchestrator/cucumber/testframework/steps/NullValueStep.java b/orchestrator/src/test/java/com/scottlogic/deg/orchestrator/cucumber/testframework/steps/NullValueStep.java index 5623e97b3..56664c7a1 100644 --- a/orchestrator/src/test/java/com/scottlogic/deg/orchestrator/cucumber/testframework/steps/NullValueStep.java +++ b/orchestrator/src/test/java/com/scottlogic/deg/orchestrator/cucumber/testframework/steps/NullValueStep.java @@ -41,7 +41,7 @@ public void whenFieldIsConstrainedByTextValue(String fieldName) { @When("{fieldVar} is anything but {operator} null") public void whenFieldIsNotConstrainedByTextValue(String fieldName, String constraintName) { - state.addNotConstraint(fieldName, ConstraintType.fromPropertyName(constraintName), null); + state.addNotConstraint(fieldName, ConstraintType.fromName(constraintName), null); } @Then("{fieldVar} contains anything but null") 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 59c0560ce..62f42d3dc 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 @@ -27,6 +27,9 @@ import com.scottlogic.deg.profile.dtos.constraints.atomic.*; import com.scottlogic.deg.profile.dtos.constraints.atomic.EqualToConstraintDTO; import com.scottlogic.deg.profile.dtos.constraints.atomic.GranularToConstraintDTO; +import com.scottlogic.deg.profile.dtos.constraints.atomic.integer.LongerThanConstraintDTO; +import com.scottlogic.deg.profile.dtos.constraints.atomic.integer.OfLengthConstraintDTO; +import com.scottlogic.deg.profile.dtos.constraints.atomic.integer.ShorterThanConstraintDTO; import com.scottlogic.deg.profile.dtos.constraints.atomic.numeric.*; import com.scottlogic.deg.profile.dtos.constraints.atomic.temporal.AfterConstraintDTO; import com.scottlogic.deg.profile.dtos.constraints.atomic.temporal.AfterOrAtConstraintDTO; @@ -37,6 +40,7 @@ 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.NotConstraintDTO; import com.scottlogic.deg.profile.dtos.constraints.relations.*; import java.io.IOException; 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 e87b6733f..115247d7d 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 @@ -21,20 +21,13 @@ import com.scottlogic.deg.profile.serialisation.ConstraintDeserializer; @JsonDeserialize(using = ConstraintDeserializer.class) -public abstract class ConstraintDTO { - private final ConstraintType type; - - protected ConstraintDTO(ConstraintType type) { - this.type = type; - } +public abstract class ConstraintDTO +{ + private final ConstraintType type = ConstraintType.fromClass(getClass()); @JsonIgnore - public ConstraintType getType() { + public final ConstraintType getType() + { return type; } - - @JsonIgnore - public String getName() { - return type.propertyName; - } } diff --git a/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/ConstraintType.java b/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/ConstraintType.java index 3205f2389..f09204c28 100644 --- a/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/ConstraintType.java +++ b/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/ConstraintType.java @@ -15,53 +15,85 @@ */ package com.scottlogic.deg.profile.dtos.constraints; -import com.fasterxml.jackson.annotation.JsonValue; + +import com.scottlogic.deg.profile.dtos.constraints.atomic.EqualToConstraintDTO; +import com.scottlogic.deg.profile.dtos.constraints.atomic.GranularToConstraintDTO; +import com.scottlogic.deg.profile.dtos.constraints.atomic.InSetConstraintDTO; +import com.scottlogic.deg.profile.dtos.constraints.atomic.IsNullConstraintDTO; +import com.scottlogic.deg.profile.dtos.constraints.atomic.integer.LongerThanConstraintDTO; +import com.scottlogic.deg.profile.dtos.constraints.atomic.integer.OfLengthConstraintDTO; +import com.scottlogic.deg.profile.dtos.constraints.atomic.integer.ShorterThanConstraintDTO; +import com.scottlogic.deg.profile.dtos.constraints.atomic.numeric.GreaterThanConstraintDTO; +import com.scottlogic.deg.profile.dtos.constraints.atomic.numeric.GreaterThanOrEqualToConstraintDTO; +import com.scottlogic.deg.profile.dtos.constraints.atomic.numeric.LessThanConstraintDTO; +import com.scottlogic.deg.profile.dtos.constraints.atomic.numeric.LessThanOrEqualToConstraintDTO; +import com.scottlogic.deg.profile.dtos.constraints.atomic.temporal.AfterConstraintDTO; +import com.scottlogic.deg.profile.dtos.constraints.atomic.temporal.AfterOrAtConstraintDTO; +import com.scottlogic.deg.profile.dtos.constraints.atomic.temporal.BeforeConstraintDTO; +import com.scottlogic.deg.profile.dtos.constraints.atomic.temporal.BeforeOrAtConstraintDTO; +import com.scottlogic.deg.profile.dtos.constraints.atomic.textual.ContainsRegexConstraintDTO; +import com.scottlogic.deg.profile.dtos.constraints.atomic.textual.MatchesRegexConstraintDTO; +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.NotConstraintDTO; +import com.scottlogic.deg.profile.dtos.constraints.relations.*; import java.util.Arrays; public enum ConstraintType { - EQUAL_TO(ConstraintTypeJsonProperty.EQUAL_TO), - EQUAL_TO_FIELD(ConstraintTypeJsonProperty.EQUAL_TO_FIELD), - IN_SET(ConstraintTypeJsonProperty.IN_SET), - IN_MAP(ConstraintTypeJsonProperty.IN_MAP), - IS_NULL(ConstraintTypeJsonProperty.IS_NULL), - GRANULAR_TO(ConstraintTypeJsonProperty.GRANULAR_TO), - MATCHES_REGEX(ConstraintTypeJsonProperty.MATCHES_REGEX), - CONTAINS_REGEX(ConstraintTypeJsonProperty.CONTAINS_REGEX), - OF_LENGTH(ConstraintTypeJsonProperty.OF_LENGTH), - LONGER_THAN(ConstraintTypeJsonProperty.LONGER_THAN), - SHORTER_THAN(ConstraintTypeJsonProperty.SHORTER_THAN), - GREATER_THAN(ConstraintTypeJsonProperty.GREATER_THAN), - GREATER_THAN_FIELD(ConstraintTypeJsonProperty.GREATER_THAN_FIELD), - GREATER_THAN_OR_EQUAL_TO(ConstraintTypeJsonProperty.GREATER_THAN_OR_EQUAL_TO), - GREATER_THAN_OR_EQUAL_TO_FIELD(ConstraintTypeJsonProperty.GREATER_THAN_OR_EQUAL_TO_FIELD), - LESS_THAN(ConstraintTypeJsonProperty.LESS_THAN), - LESS_THAN_FIELD(ConstraintTypeJsonProperty.LESS_THAN_FIELD), - LESS_THAN_OR_EQUAL_TO(ConstraintTypeJsonProperty.LESS_THAN_OR_EQUAL_TO), - LESS_THAN_OR_EQUAL_TO_FIELD(ConstraintTypeJsonProperty.LESS_THAN_OR_EQUAL_TO_FIELD), - AFTER(ConstraintTypeJsonProperty.AFTER), - AFTER_FIELD(ConstraintTypeJsonProperty.AFTER_FIELD), - AFTER_OR_AT(ConstraintTypeJsonProperty.AFTER_OR_AT), - AFTER_OR_AT_FIELD(ConstraintTypeJsonProperty.AFTER_OR_AT_FIELD), - BEFORE(ConstraintTypeJsonProperty.BEFORE), - BEFORE_FIELD(ConstraintTypeJsonProperty.BEFORE_FIELD), - BEFORE_OR_AT(ConstraintTypeJsonProperty.BEFORE_OR_AT), - BEFORE_OR_AT_FIELD(ConstraintTypeJsonProperty.BEFORE_OR_AT_FIELD), - NOT(ConstraintTypeJsonProperty.NOT), - ANY_OF(ConstraintTypeJsonProperty.ANY_OF), - ALL_OF(ConstraintTypeJsonProperty.ALL_OF), - IF(ConstraintTypeJsonProperty.IF); + EQUAL_TO(EqualToConstraintDTO.NAME, EqualToConstraintDTO.class), + EQUAL_TO_FIELD(EqualToFieldConstraintDTO.NAME, EqualToFieldConstraintDTO.class), + IN_SET(InSetConstraintDTO.NAME, InSetConstraintDTO.class), + IN_MAP(InMapConstraintDTO.NAME, InMapConstraintDTO.class), + IS_NULL(IsNullConstraintDTO.NAME, IsNullConstraintDTO.class), + GRANULAR_TO(GranularToConstraintDTO.NAME, GranularToConstraintDTO.class), + MATCHES_REGEX(MatchesRegexConstraintDTO.NAME, MatchesRegexConstraintDTO.class), + CONTAINS_REGEX(ContainsRegexConstraintDTO.NAME, ContainsRegexConstraintDTO.class), + OF_LENGTH(OfLengthConstraintDTO.NAME, OfLengthConstraintDTO.class), + LONGER_THAN(LongerThanConstraintDTO.NAME, LongerThanConstraintDTO.class), + SHORTER_THAN(ShorterThanConstraintDTO.NAME, ShorterThanConstraintDTO.class), + GREATER_THAN(GreaterThanConstraintDTO.NAME, GreaterThanConstraintDTO.class), + GREATER_THAN_FIELD(GreaterThanFieldConstraintDTO.NAME, GreaterThanFieldConstraintDTO.class), + GREATER_THAN_OR_EQUAL_TO(GreaterThanOrEqualToConstraintDTO.NAME, GreaterThanOrEqualToConstraintDTO.class), + GREATER_THAN_OR_EQUAL_TO_FIELD(GreaterThanOrEqualToFieldConstraintDTO.NAME, GreaterThanOrEqualToFieldConstraintDTO.class), + LESS_THAN(LessThanConstraintDTO.NAME, LessThanConstraintDTO.class), + LESS_THAN_FIELD(LessThanFieldConstraintDTO.NAME, LessThanFieldConstraintDTO.class), + LESS_THAN_OR_EQUAL_TO(LessThanOrEqualToConstraintDTO.NAME, LessThanOrEqualToConstraintDTO.class), + LESS_THAN_OR_EQUAL_TO_FIELD(LessThanOrEqualToFieldConstraintDTO.NAME, LessThanOrEqualToFieldConstraintDTO.class), + AFTER(AfterConstraintDTO.NAME, AfterConstraintDTO.class), + AFTER_FIELD(AfterFieldConstraintDTO.NAME, AfterFieldConstraintDTO.class), + AFTER_OR_AT(AfterOrAtConstraintDTO.NAME, AfterOrAtConstraintDTO.class), + AFTER_OR_AT_FIELD(AfterOrAtFieldConstraintDTO.NAME, AfterOrAtFieldConstraintDTO.class), + BEFORE(BeforeConstraintDTO.NAME, BeforeConstraintDTO.class), + BEFORE_FIELD(BeforeFieldConstraintDTO.NAME, BeforeFieldConstraintDTO.class), + BEFORE_OR_AT(BeforeOrAtConstraintDTO.NAME, BeforeOrAtConstraintDTO.class), + BEFORE_OR_AT_FIELD(BeforeOrAtFieldConstraintDTO.NAME, BeforeOrAtFieldConstraintDTO.class), + NOT(NotConstraintDTO.NAME, NotConstraintDTO.class), + ANY_OF(AnyOfConstraintDTO.NAME, AnyOfConstraintDTO.class), + ALL_OF(AllOfConstraintDTO.NAME, AllOfConstraintDTO.class), + IF(ConditionalConstraintDTO.NAME, ConditionalConstraintDTO.class), + INVALID(InvalidConstraintDTO.NAME, InvalidConstraintDTO.class); + - @JsonValue public final String propertyName; + public final Class clazz; + + ConstraintType(String propertyName, Class clazz) { - ConstraintType(String propertyName) { this.propertyName = propertyName; + this.clazz = clazz; + } + + public static ConstraintType fromName(String name) { + return Arrays.stream(values()) + .filter(x->x.propertyName.equalsIgnoreCase(name)) + .findFirst().orElse(null); } - public static ConstraintType fromPropertyName(String propertyName) { + public static ConstraintType fromClass(Class clazz) { return Arrays.stream(values()) - .filter(x->x.propertyName.equalsIgnoreCase(propertyName)) + .filter(x->x.clazz.equals(clazz)) .findFirst().orElse(null); } } diff --git a/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/ConstraintTypeJsonProperty.java b/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/ConstraintTypeJsonProperty.java index 69f487b79..e69de29bb 100644 --- a/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/ConstraintTypeJsonProperty.java +++ b/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/ConstraintTypeJsonProperty.java @@ -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.profile.dtos.constraints; - -public class ConstraintTypeJsonProperty { - public static final String EQUAL_TO = "equalTo"; - public static final String EQUAL_TO_FIELD = "equalToField"; - public static final String IN_SET = "inSet"; - public static final String IN_MAP = "inMap"; - public static final String IS_NULL = "isNull"; - public static final String GRANULAR_TO = "granularTo"; - public static final String MATCHES_REGEX = "matchingRegex"; - public static final String CONTAINS_REGEX = "containingRegex"; - public static final String OF_LENGTH = "ofLength"; - public static final String LONGER_THAN = "longerThan"; - public static final String SHORTER_THAN = "shorterThan"; - public static final String GREATER_THAN = "greaterThan"; - public static final String GREATER_THAN_FIELD = "greaterThanField"; - public static final String GREATER_THAN_OR_EQUAL_TO = "greaterThanOrEqualTo"; - public static final String GREATER_THAN_OR_EQUAL_TO_FIELD = "greaterThanOrEqualToField"; - public static final String LESS_THAN = "lessThan"; - public static final String LESS_THAN_FIELD = "lessThanField"; - public static final String LESS_THAN_OR_EQUAL_TO = "lessThanOrEqualTo"; - public static final String LESS_THAN_OR_EQUAL_TO_FIELD = "lessThanOrEqualToField"; - public static final String AFTER = "after"; - public static final String AFTER_FIELD = "afterField"; - public static final String AFTER_OR_AT = "afterOrAt"; - public static final String AFTER_OR_AT_FIELD = "afterOrAtField"; - public static final String BEFORE = "before"; - public static final String BEFORE_FIELD = "beforeField"; - public static final String BEFORE_OR_AT = "beforeOrAt"; - public static final String BEFORE_OR_AT_FIELD = "beforeOrAtField"; - public static final String NOT = "not"; - public static final String ANY_OF = "anyOf"; - public static final String ALL_OF = "allOf"; - public static final String IF = "if"; - public static final String THEN = "then"; - public static final String ELSE = "else"; -} - diff --git a/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/InvalidConstraintDTO.java b/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/InvalidConstraintDTO.java index 889e40eb4..5f99c1f15 100644 --- a/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/InvalidConstraintDTO.java +++ b/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/InvalidConstraintDTO.java @@ -17,10 +17,12 @@ package com.scottlogic.deg.profile.dtos.constraints; public class InvalidConstraintDTO extends ConstraintDTO { + public static final String NAME = "invalid"; + public final String json; + public InvalidConstraintDTO(String json) { - super(null); this.json = json; } } diff --git a/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/AtomicConstraintDTO.java b/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/AtomicConstraintDTO.java index 5794dfd07..1c60f9d5b 100644 --- a/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/AtomicConstraintDTO.java +++ b/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/AtomicConstraintDTO.java @@ -16,15 +16,9 @@ package com.scottlogic.deg.profile.dtos.constraints.atomic; -import com.scottlogic.deg.profile.dtos.constraints.ConstraintType; import com.scottlogic.deg.profile.dtos.constraints.ConstraintDTO; public abstract class AtomicConstraintDTO extends ConstraintDTO { public String field; - - protected AtomicConstraintDTO(ConstraintType type) { - super(type); - } - } diff --git a/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/EqualToConstraintDTO.java b/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/EqualToConstraintDTO.java index 9838ad6ca..d6fe44477 100644 --- a/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/EqualToConstraintDTO.java +++ b/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/EqualToConstraintDTO.java @@ -18,17 +18,13 @@ import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import com.scottlogic.deg.profile.dtos.constraints.ConstraintType; -import com.scottlogic.deg.profile.dtos.constraints.ConstraintTypeJsonProperty; @JsonDeserialize(as = EqualToConstraintDTO.class) public class EqualToConstraintDTO extends AtomicConstraintDTO { - @JsonProperty(ConstraintTypeJsonProperty.EQUAL_TO) - public Object value; + public static final String NAME = "equalTo"; - public EqualToConstraintDTO() { - super(ConstraintType.EQUAL_TO); - } + @JsonProperty(NAME) + public Object value; -} +} \ No newline at end of file diff --git a/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/GranularToConstraintDTO.java b/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/GranularToConstraintDTO.java index 67c6cf29e..39cb8c07a 100644 --- a/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/GranularToConstraintDTO.java +++ b/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/GranularToConstraintDTO.java @@ -18,17 +18,13 @@ import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import com.scottlogic.deg.profile.dtos.constraints.ConstraintType; -import com.scottlogic.deg.profile.dtos.constraints.ConstraintTypeJsonProperty; @JsonDeserialize(as = GranularToConstraintDTO.class) public class GranularToConstraintDTO extends AtomicConstraintDTO { - @JsonProperty(ConstraintTypeJsonProperty.GRANULAR_TO) - public Object value; + public static final String NAME = "granularTo"; - public GranularToConstraintDTO() { - super(ConstraintType.GRANULAR_TO); - } + @JsonProperty(NAME) + public Object value; } diff --git a/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/InMapFromFileConstraintDTO.java b/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/InMapFromFileConstraintDTO.java index 0fdbecc9c..174275b11 100644 --- a/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/InMapFromFileConstraintDTO.java +++ b/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/InMapFromFileConstraintDTO.java @@ -18,17 +18,13 @@ import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import com.scottlogic.deg.profile.dtos.constraints.ConstraintType; -import com.scottlogic.deg.profile.dtos.constraints.ConstraintTypeJsonProperty; @JsonDeserialize(as = InMapFromFileConstraintDTO.class) public class InMapFromFileConstraintDTO extends AtomicConstraintDTO { - @JsonProperty(ConstraintTypeJsonProperty.IN_MAP) + public static final String NAME = "inMap"; + + @JsonProperty(NAME) public String file; public String key; - - public InMapFromFileConstraintDTO() { - super(ConstraintType.IN_MAP); - } } diff --git a/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/InSetConstraintDTO.java b/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/InSetConstraintDTO.java index f3066b6e1..c0ac33238 100644 --- a/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/InSetConstraintDTO.java +++ b/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/InSetConstraintDTO.java @@ -18,19 +18,14 @@ import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import com.scottlogic.deg.profile.dtos.constraints.ConstraintType; -import com.scottlogic.deg.profile.dtos.constraints.ConstraintTypeJsonProperty; import java.util.List; @JsonDeserialize(as = InSetConstraintDTO.class) public class InSetConstraintDTO extends AtomicConstraintDTO { - @JsonProperty(ConstraintTypeJsonProperty.IN_SET) - public List values; + public static final String NAME = "inSet"; - public InSetConstraintDTO() - { - super(ConstraintType.IN_SET); - } + @JsonProperty(NAME) + public List values; } diff --git a/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/InSetFromFileConstraintDTO.java b/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/InSetFromFileConstraintDTO.java index d05b6bcc8..28decb95b 100644 --- a/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/InSetFromFileConstraintDTO.java +++ b/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/InSetFromFileConstraintDTO.java @@ -18,16 +18,12 @@ import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import com.scottlogic.deg.profile.dtos.constraints.ConstraintType; -import com.scottlogic.deg.profile.dtos.constraints.ConstraintTypeJsonProperty; @JsonDeserialize(as = InSetFromFileConstraintDTO.class) -public class InSetFromFileConstraintDTO extends AtomicConstraintDTO { - @JsonProperty(ConstraintTypeJsonProperty.IN_SET) - public String file; +public class InSetFromFileConstraintDTO extends AtomicConstraintDTO +{ + public static final String NAME = "inSet"; - public InSetFromFileConstraintDTO() - { - super(ConstraintType.IN_SET); - } + @JsonProperty(NAME) + public String file; } diff --git a/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/IsNullConstraintDTO.java b/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/IsNullConstraintDTO.java index 6cc20ce91..36fac4c9b 100644 --- a/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/IsNullConstraintDTO.java +++ b/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/IsNullConstraintDTO.java @@ -18,15 +18,12 @@ import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import com.scottlogic.deg.profile.dtos.constraints.ConstraintType; -import com.scottlogic.deg.profile.dtos.constraints.ConstraintTypeJsonProperty; @JsonDeserialize(as = IsNullConstraintDTO.class) -public class IsNullConstraintDTO extends AtomicConstraintDTO { - @JsonProperty(ConstraintTypeJsonProperty.IS_NULL) - public boolean isNull; +public class IsNullConstraintDTO extends AtomicConstraintDTO +{ + public static final String NAME = "isNull"; - public IsNullConstraintDTO() { - super(ConstraintType.IS_NULL); - } + @JsonProperty(NAME) + public boolean isNull; } diff --git a/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/numeric/IntegerConstraintDTO.java b/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/integer/IntegerConstraintDTO.java similarity index 79% rename from profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/numeric/IntegerConstraintDTO.java rename to profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/integer/IntegerConstraintDTO.java index 11a435cd4..9465467d5 100644 --- a/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/numeric/IntegerConstraintDTO.java +++ b/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/integer/IntegerConstraintDTO.java @@ -14,19 +14,13 @@ * limitations under the License. */ -package com.scottlogic.deg.profile.dtos.constraints.atomic.numeric; +package com.scottlogic.deg.profile.dtos.constraints.atomic.integer; import com.fasterxml.jackson.annotation.JsonIgnore; -import com.scottlogic.deg.profile.dtos.constraints.ConstraintType; import com.scottlogic.deg.profile.dtos.constraints.atomic.AtomicConstraintDTO; public abstract class IntegerConstraintDTO extends AtomicConstraintDTO { - IntegerConstraintDTO(ConstraintType type) - { - super(type); - } - @JsonIgnore public abstract int getInt(); } diff --git a/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/numeric/LongerThanConstraintDTO.java b/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/integer/LongerThanConstraintDTO.java similarity index 68% rename from profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/numeric/LongerThanConstraintDTO.java rename to profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/integer/LongerThanConstraintDTO.java index 27bb8d3e1..b65291a8c 100644 --- a/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/numeric/LongerThanConstraintDTO.java +++ b/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/integer/LongerThanConstraintDTO.java @@ -14,26 +14,20 @@ * limitations under the License. */ -package com.scottlogic.deg.profile.dtos.constraints.atomic.numeric; +package com.scottlogic.deg.profile.dtos.constraints.atomic.integer; -import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import com.scottlogic.deg.profile.dtos.constraints.ConstraintType; -import com.scottlogic.deg.profile.dtos.constraints.ConstraintTypeJsonProperty; @JsonDeserialize(as = LongerThanConstraintDTO.class) public class LongerThanConstraintDTO extends IntegerConstraintDTO { - @JsonProperty(ConstraintTypeJsonProperty.LONGER_THAN) - public int value; + public static final String NAME ="longerThan"; - public LongerThanConstraintDTO() { - super(ConstraintType.LONGER_THAN); - } + @JsonProperty(NAME) + public int value; @Override - @JsonIgnore public int getInt() { return value; diff --git a/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/numeric/OfLengthConstraintDTO.java b/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/integer/OfLengthConstraintDTO.java similarity index 72% rename from profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/numeric/OfLengthConstraintDTO.java rename to profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/integer/OfLengthConstraintDTO.java index 1fb357eda..3b835bfbe 100644 --- a/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/numeric/OfLengthConstraintDTO.java +++ b/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/integer/OfLengthConstraintDTO.java @@ -14,22 +14,18 @@ * limitations under the License. */ -package com.scottlogic.deg.profile.dtos.constraints.atomic.numeric; +package com.scottlogic.deg.profile.dtos.constraints.atomic.integer; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import com.scottlogic.deg.profile.dtos.constraints.ConstraintType; -import com.scottlogic.deg.profile.dtos.constraints.ConstraintTypeJsonProperty; @JsonDeserialize(as = OfLengthConstraintDTO.class) public class OfLengthConstraintDTO extends IntegerConstraintDTO { - @JsonProperty(ConstraintTypeJsonProperty.OF_LENGTH) - public int value; + public static final String NAME = "ofLength"; - public OfLengthConstraintDTO() { - super(ConstraintType.OF_LENGTH); - } + @JsonProperty(NAME) + public int value; @Override public int getInt() diff --git a/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/numeric/ShorterThanConstraintDTO.java b/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/integer/ShorterThanConstraintDTO.java similarity index 68% rename from profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/numeric/ShorterThanConstraintDTO.java rename to profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/integer/ShorterThanConstraintDTO.java index 655ef7878..a53881cd5 100644 --- a/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/numeric/ShorterThanConstraintDTO.java +++ b/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/integer/ShorterThanConstraintDTO.java @@ -14,28 +14,23 @@ * limitations under the License. */ -package com.scottlogic.deg.profile.dtos.constraints.atomic.numeric; +package com.scottlogic.deg.profile.dtos.constraints.atomic.integer; -import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import com.scottlogic.deg.profile.dtos.constraints.ConstraintType; -import com.scottlogic.deg.profile.dtos.constraints.ConstraintTypeJsonProperty; @JsonDeserialize(as = ShorterThanConstraintDTO.class) public class ShorterThanConstraintDTO extends IntegerConstraintDTO { - @JsonProperty(ConstraintTypeJsonProperty.SHORTER_THAN) - public int value; + public static final String NAME = "shorterThan"; - public ShorterThanConstraintDTO() { - super(ConstraintType.SHORTER_THAN); - } + @JsonProperty(NAME) + public int value; @Override - @JsonIgnore public int getInt() { return value; } + } diff --git a/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/numeric/GreaterThanConstraintDTO.java b/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/numeric/GreaterThanConstraintDTO.java index 4ae89ac64..2d8ee5a7a 100644 --- a/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/numeric/GreaterThanConstraintDTO.java +++ b/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/numeric/GreaterThanConstraintDTO.java @@ -16,25 +16,21 @@ package com.scottlogic.deg.profile.dtos.constraints.atomic.numeric; -import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import com.scottlogic.deg.profile.dtos.constraints.ConstraintType; -import com.scottlogic.deg.profile.dtos.constraints.ConstraintTypeJsonProperty; @JsonDeserialize(as = GreaterThanConstraintDTO.class) -public class GreaterThanConstraintDTO extends NumericConstraintDTO { - @JsonProperty(ConstraintTypeJsonProperty.GREATER_THAN) - public Number value; +public class GreaterThanConstraintDTO extends NumericConstraintDTO +{ + public static final String NAME = "greaterThan"; - public GreaterThanConstraintDTO() { - super(ConstraintType.GREATER_THAN); - } + @JsonProperty(NAME) + public Number value; @Override - @JsonIgnore public Number getNumber() { return value; } + } diff --git a/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/numeric/GreaterThanOrEqualToConstraintDTO.java b/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/numeric/GreaterThanOrEqualToConstraintDTO.java index 0fca220e4..d0434e756 100644 --- a/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/numeric/GreaterThanOrEqualToConstraintDTO.java +++ b/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/numeric/GreaterThanOrEqualToConstraintDTO.java @@ -16,26 +16,21 @@ package com.scottlogic.deg.profile.dtos.constraints.atomic.numeric; -import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import com.scottlogic.deg.profile.dtos.constraints.ConstraintType; -import com.scottlogic.deg.profile.dtos.constraints.ConstraintTypeJsonProperty; @JsonDeserialize(as = GreaterThanOrEqualToConstraintDTO.class) public class GreaterThanOrEqualToConstraintDTO extends NumericConstraintDTO { - @JsonProperty(ConstraintTypeJsonProperty.GREATER_THAN_OR_EQUAL_TO) - public Number value; + public static final String NAME = "greaterThanOrEqualTo"; - public GreaterThanOrEqualToConstraintDTO() { - super(ConstraintType.GREATER_THAN_OR_EQUAL_TO); - } + @JsonProperty(NAME) + public Number value; @Override - @JsonIgnore public Number getNumber() { return value; } -} + +} \ No newline at end of file diff --git a/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/numeric/LessThanConstraintDTO.java b/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/numeric/LessThanConstraintDTO.java index c027a2c4f..94aa184eb 100644 --- a/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/numeric/LessThanConstraintDTO.java +++ b/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/numeric/LessThanConstraintDTO.java @@ -16,24 +16,18 @@ package com.scottlogic.deg.profile.dtos.constraints.atomic.numeric; -import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import com.scottlogic.deg.profile.dtos.constraints.ConstraintType; -import com.scottlogic.deg.profile.dtos.constraints.ConstraintTypeJsonProperty; @JsonDeserialize(as = LessThanConstraintDTO.class) public class LessThanConstraintDTO extends NumericConstraintDTO { - @JsonProperty(ConstraintTypeJsonProperty.LESS_THAN) - public Number value; + public static final String NAME = "lessThan"; - public LessThanConstraintDTO() { - super(ConstraintType.LESS_THAN); - } + @JsonProperty(NAME) + public Number value; @Override - @JsonIgnore public Number getNumber() { return value; diff --git a/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/numeric/LessThanOrEqualToConstraintDTO.java b/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/numeric/LessThanOrEqualToConstraintDTO.java index 5302d2291..7b05a1b8a 100644 --- a/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/numeric/LessThanOrEqualToConstraintDTO.java +++ b/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/numeric/LessThanOrEqualToConstraintDTO.java @@ -16,24 +16,18 @@ package com.scottlogic.deg.profile.dtos.constraints.atomic.numeric; -import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import com.scottlogic.deg.profile.dtos.constraints.ConstraintType; -import com.scottlogic.deg.profile.dtos.constraints.ConstraintTypeJsonProperty; @JsonDeserialize(as = LessThanOrEqualToConstraintDTO.class) public class LessThanOrEqualToConstraintDTO extends NumericConstraintDTO { - @JsonProperty(ConstraintTypeJsonProperty.LESS_THAN_OR_EQUAL_TO) - public Number value; + public static final String NAME = "lessThanOrEqualTo"; - public LessThanOrEqualToConstraintDTO() { - super(ConstraintType.LESS_THAN_OR_EQUAL_TO); - } + @JsonProperty(NAME) + public Number value; @Override - @JsonIgnore public Number getNumber() { return value; diff --git a/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/numeric/NumericConstraintDTO.java b/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/numeric/NumericConstraintDTO.java index 989c626fb..63cb3d23c 100644 --- a/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/numeric/NumericConstraintDTO.java +++ b/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/numeric/NumericConstraintDTO.java @@ -17,16 +17,10 @@ package com.scottlogic.deg.profile.dtos.constraints.atomic.numeric; import com.fasterxml.jackson.annotation.JsonIgnore; -import com.scottlogic.deg.profile.dtos.constraints.ConstraintType; import com.scottlogic.deg.profile.dtos.constraints.atomic.AtomicConstraintDTO; public abstract class NumericConstraintDTO extends AtomicConstraintDTO { - NumericConstraintDTO(ConstraintType type) - { - super(type); - } - @JsonIgnore public abstract Number getNumber(); } diff --git a/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/temporal/AfterConstraintDTO.java b/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/temporal/AfterConstraintDTO.java index 7e126b57b..9861e5722 100644 --- a/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/temporal/AfterConstraintDTO.java +++ b/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/temporal/AfterConstraintDTO.java @@ -16,24 +16,18 @@ package com.scottlogic.deg.profile.dtos.constraints.atomic.temporal; -import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import com.scottlogic.deg.profile.dtos.constraints.ConstraintType; -import com.scottlogic.deg.profile.dtos.constraints.ConstraintTypeJsonProperty; @JsonDeserialize(as = AfterConstraintDTO.class) public class AfterConstraintDTO extends TemporalConstraintDTO { - @JsonProperty(ConstraintTypeJsonProperty.AFTER) - public String value; + public static final String NAME = "after"; - public AfterConstraintDTO() { - super(ConstraintType.AFTER); - } + @JsonProperty(NAME) + public String value; @Override - @JsonIgnore public String getDate() { return value; diff --git a/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/temporal/AfterOrAtConstraintDTO.java b/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/temporal/AfterOrAtConstraintDTO.java index 554a98ae8..96b3fc224 100644 --- a/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/temporal/AfterOrAtConstraintDTO.java +++ b/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/temporal/AfterOrAtConstraintDTO.java @@ -16,26 +16,21 @@ package com.scottlogic.deg.profile.dtos.constraints.atomic.temporal; -import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import com.scottlogic.deg.profile.dtos.constraints.ConstraintType; -import com.scottlogic.deg.profile.dtos.constraints.ConstraintTypeJsonProperty; @JsonDeserialize(as = AfterOrAtConstraintDTO.class) public class AfterOrAtConstraintDTO extends TemporalConstraintDTO { - @JsonProperty(ConstraintTypeJsonProperty.AFTER_OR_AT) - public String value; + public static final String NAME = "afterOrAt"; - public AfterOrAtConstraintDTO() { - super(ConstraintType.AFTER_OR_AT); - } + @JsonProperty(NAME) + public String value; @Override - @JsonIgnore public String getDate() { return value; } + } diff --git a/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/temporal/BeforeConstraintDTO.java b/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/temporal/BeforeConstraintDTO.java index c160e6ce7..879a61d6a 100644 --- a/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/temporal/BeforeConstraintDTO.java +++ b/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/temporal/BeforeConstraintDTO.java @@ -16,26 +16,21 @@ package com.scottlogic.deg.profile.dtos.constraints.atomic.temporal; -import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import com.scottlogic.deg.profile.dtos.constraints.ConstraintType; -import com.scottlogic.deg.profile.dtos.constraints.ConstraintTypeJsonProperty; @JsonDeserialize(as = BeforeConstraintDTO.class) public class BeforeConstraintDTO extends TemporalConstraintDTO { - @JsonProperty(ConstraintTypeJsonProperty.BEFORE) - public String value; + public static final String NAME = "before"; - public BeforeConstraintDTO() { - super(ConstraintType.BEFORE); - } + @JsonProperty(NAME) + public String value; @Override - @JsonIgnore public String getDate() { return value; } + } diff --git a/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/temporal/BeforeOrAtConstraintDTO.java b/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/temporal/BeforeOrAtConstraintDTO.java index 2071efa9c..c9cd9a44b 100644 --- a/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/temporal/BeforeOrAtConstraintDTO.java +++ b/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/temporal/BeforeOrAtConstraintDTO.java @@ -16,24 +16,18 @@ package com.scottlogic.deg.profile.dtos.constraints.atomic.temporal; -import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import com.scottlogic.deg.profile.dtos.constraints.ConstraintType; -import com.scottlogic.deg.profile.dtos.constraints.ConstraintTypeJsonProperty; @JsonDeserialize(as = BeforeOrAtConstraintDTO.class) public class BeforeOrAtConstraintDTO extends TemporalConstraintDTO { - @JsonProperty(ConstraintTypeJsonProperty.BEFORE_OR_AT) - public String value; + public static final String NAME = "beforeOrAt"; - public BeforeOrAtConstraintDTO() { - super(ConstraintType.BEFORE_OR_AT); - } + @JsonProperty(NAME) + public String value; @Override - @JsonIgnore public String getDate() { return value; diff --git a/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/temporal/TemporalConstraintDTO.java b/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/temporal/TemporalConstraintDTO.java index 0ebbb24d0..21e49c8d7 100644 --- a/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/temporal/TemporalConstraintDTO.java +++ b/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/temporal/TemporalConstraintDTO.java @@ -17,16 +17,10 @@ package com.scottlogic.deg.profile.dtos.constraints.atomic.temporal; import com.fasterxml.jackson.annotation.JsonIgnore; -import com.scottlogic.deg.profile.dtos.constraints.ConstraintType; import com.scottlogic.deg.profile.dtos.constraints.atomic.AtomicConstraintDTO; public abstract class TemporalConstraintDTO extends AtomicConstraintDTO { - TemporalConstraintDTO(ConstraintType type) - { - super(type); - } - @JsonIgnore public abstract String getDate(); } diff --git a/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/textual/ContainsRegexConstraintDTO.java b/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/textual/ContainsRegexConstraintDTO.java index da029e959..952c2695a 100644 --- a/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/textual/ContainsRegexConstraintDTO.java +++ b/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/textual/ContainsRegexConstraintDTO.java @@ -18,18 +18,14 @@ import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import com.scottlogic.deg.profile.dtos.constraints.ConstraintType; -import com.scottlogic.deg.profile.dtos.constraints.ConstraintTypeJsonProperty; @JsonDeserialize(as = ContainsRegexConstraintDTO.class) public class ContainsRegexConstraintDTO extends RegexConstraintDTO { - @JsonProperty(ConstraintTypeJsonProperty.CONTAINS_REGEX) - public String value; + public static final String NAME = "containingRegex"; - public ContainsRegexConstraintDTO() { - super(ConstraintType.CONTAINS_REGEX); - } + @JsonProperty(NAME) + public String value; @Override public String getRegex() diff --git a/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/textual/MatchesRegexConstraintDTO.java b/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/textual/MatchesRegexConstraintDTO.java index 6c3d89d61..ac3e4a8ba 100644 --- a/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/textual/MatchesRegexConstraintDTO.java +++ b/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/textual/MatchesRegexConstraintDTO.java @@ -18,18 +18,14 @@ import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import com.scottlogic.deg.profile.dtos.constraints.ConstraintType; -import com.scottlogic.deg.profile.dtos.constraints.ConstraintTypeJsonProperty; @JsonDeserialize(as = MatchesRegexConstraintDTO.class) public class MatchesRegexConstraintDTO extends RegexConstraintDTO { - @JsonProperty(ConstraintTypeJsonProperty.MATCHES_REGEX) - public String value; + public static final String NAME = "matchingRegex"; - public MatchesRegexConstraintDTO() { - super(ConstraintType.MATCHES_REGEX); - } + @JsonProperty(NAME) + public String value; @Override public String getRegex() diff --git a/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/textual/RegexConstraintDTO.java b/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/textual/RegexConstraintDTO.java index 05800e59f..0cb54c650 100644 --- a/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/textual/RegexConstraintDTO.java +++ b/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/textual/RegexConstraintDTO.java @@ -17,16 +17,10 @@ package com.scottlogic.deg.profile.dtos.constraints.atomic.textual; import com.fasterxml.jackson.annotation.JsonIgnore; -import com.scottlogic.deg.profile.dtos.constraints.ConstraintType; import com.scottlogic.deg.profile.dtos.constraints.atomic.AtomicConstraintDTO; public abstract class RegexConstraintDTO extends AtomicConstraintDTO { - RegexConstraintDTO(ConstraintType type) - { - super(type); - } - @JsonIgnore public abstract String getRegex(); } diff --git a/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/grammatical/AllOfConstraintDTO.java b/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/grammatical/AllOfConstraintDTO.java index 8f3bac2a8..b066954b5 100644 --- a/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/grammatical/AllOfConstraintDTO.java +++ b/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/grammatical/AllOfConstraintDTO.java @@ -18,8 +18,6 @@ import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import com.scottlogic.deg.profile.dtos.constraints.ConstraintType; -import com.scottlogic.deg.profile.dtos.constraints.ConstraintTypeJsonProperty; import com.scottlogic.deg.profile.dtos.constraints.ConstraintDTO; import java.util.List; @@ -27,10 +25,8 @@ @JsonDeserialize(as = AllOfConstraintDTO.class) public class AllOfConstraintDTO extends GrammaticalConstraintDTO { - @JsonProperty(ConstraintTypeJsonProperty.ALL_OF) - public List constraints; + public static final String NAME ="allOf"; - public AllOfConstraintDTO() { - super(ConstraintType.ALL_OF); - } + @JsonProperty(NAME) + public List constraints; } diff --git a/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/grammatical/AnyOfConstraintDTO.java b/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/grammatical/AnyOfConstraintDTO.java index a19825ec7..d7b257d8e 100644 --- a/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/grammatical/AnyOfConstraintDTO.java +++ b/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/grammatical/AnyOfConstraintDTO.java @@ -18,8 +18,6 @@ import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import com.scottlogic.deg.profile.dtos.constraints.ConstraintType; -import com.scottlogic.deg.profile.dtos.constraints.ConstraintTypeJsonProperty; import com.scottlogic.deg.profile.dtos.constraints.ConstraintDTO; import java.util.List; @@ -27,10 +25,8 @@ @JsonDeserialize(as = AnyOfConstraintDTO.class) public class AnyOfConstraintDTO extends GrammaticalConstraintDTO { - @JsonProperty(ConstraintTypeJsonProperty.ANY_OF) - public List constraints; + public static final String NAME ="anyOf"; - public AnyOfConstraintDTO() { - super(ConstraintType.ANY_OF); - } + @JsonProperty(NAME) + public List constraints; } diff --git a/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/grammatical/ConditionalConstraintDTO.java b/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/grammatical/ConditionalConstraintDTO.java index 269ed4277..e4a8b6a3b 100644 --- a/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/grammatical/ConditionalConstraintDTO.java +++ b/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/grammatical/ConditionalConstraintDTO.java @@ -18,21 +18,19 @@ import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import com.scottlogic.deg.profile.dtos.constraints.ConstraintType; -import com.scottlogic.deg.profile.dtos.constraints.ConstraintTypeJsonProperty; import com.scottlogic.deg.profile.dtos.constraints.ConstraintDTO; @JsonDeserialize(as = ConditionalConstraintDTO.class) public class ConditionalConstraintDTO extends GrammaticalConstraintDTO { - @JsonProperty(ConstraintTypeJsonProperty.IF) + public static final String NAME = "if"; + private static final String THEN = "then"; + private static final String ELSE = "else"; + + @JsonProperty(NAME) public ConstraintDTO ifConstraint; - @JsonProperty(ConstraintTypeJsonProperty.THEN) + @JsonProperty(THEN) public ConstraintDTO thenConstraint; - @JsonProperty(ConstraintTypeJsonProperty.ELSE) + @JsonProperty(ELSE) public ConstraintDTO elseConstraint; - - 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 index 0fd8855a1..a8578ad75 100644 --- 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 @@ -16,13 +16,8 @@ package com.scottlogic.deg.profile.dtos.constraints.grammatical; -import com.scottlogic.deg.profile.dtos.constraints.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/NotConstraintDTO.java b/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/grammatical/NotConstraintDTO.java similarity index 75% rename from profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/NotConstraintDTO.java rename to profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/grammatical/NotConstraintDTO.java index 471b5045b..3cc880fce 100644 --- a/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/NotConstraintDTO.java +++ b/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/grammatical/NotConstraintDTO.java @@ -14,17 +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.dtos.constraints.ConstraintDTO; @JsonDeserialize(as = NotConstraintDTO.class) -public class NotConstraintDTO extends ConstraintDTO { - @JsonProperty(ConstraintTypeJsonProperty.NOT) - public ConstraintDTO constraint; +public class NotConstraintDTO extends GrammaticalConstraintDTO +{ + public static final String NAME ="not"; - public NotConstraintDTO() { - super(ConstraintType.NOT); - } + @JsonProperty(NAME) + public ConstraintDTO constraint; } diff --git a/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/relations/AfterFieldConstraintDTO.java b/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/relations/AfterFieldConstraintDTO.java index 7492dbe3c..0ee043e26 100644 --- a/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/relations/AfterFieldConstraintDTO.java +++ b/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/relations/AfterFieldConstraintDTO.java @@ -18,20 +18,18 @@ import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import com.scottlogic.deg.profile.dtos.constraints.ConstraintType; -import com.scottlogic.deg.profile.dtos.constraints.ConstraintTypeJsonProperty; @JsonDeserialize(as = AfterFieldConstraintDTO.class) -public class AfterFieldConstraintDTO extends RelationalConstraintDTO { - @JsonProperty(ConstraintTypeJsonProperty.AFTER_FIELD) - public String otherField; +public class AfterFieldConstraintDTO extends RelationalConstraintDTO +{ + public static final String NAME = "afterField"; - public AfterFieldConstraintDTO() { - super(ConstraintType.AFTER_FIELD); - } + @JsonProperty(NAME) + public String otherField; @Override - public String getOtherField() { + public String getOtherField() + { return otherField; } } diff --git a/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/relations/AfterOrAtFieldConstraintDTO.java b/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/relations/AfterOrAtFieldConstraintDTO.java index eba328e8a..17902d21d 100644 --- a/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/relations/AfterOrAtFieldConstraintDTO.java +++ b/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/relations/AfterOrAtFieldConstraintDTO.java @@ -18,20 +18,18 @@ import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import com.scottlogic.deg.profile.dtos.constraints.ConstraintType; -import com.scottlogic.deg.profile.dtos.constraints.ConstraintTypeJsonProperty; @JsonDeserialize(as = AfterOrAtFieldConstraintDTO.class) -public class AfterOrAtFieldConstraintDTO extends RelationalConstraintDTO { - @JsonProperty(ConstraintTypeJsonProperty.AFTER_OR_AT_FIELD) - public String otherField; +public class AfterOrAtFieldConstraintDTO extends RelationalConstraintDTO +{ + public static final String NAME = "afterOrAtField"; - public AfterOrAtFieldConstraintDTO() { - super(ConstraintType.AFTER_OR_AT_FIELD); - } + @JsonProperty(NAME) + public String otherField; @Override - public String getOtherField() { + public String getOtherField() + { return otherField; } } diff --git a/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/relations/BeforeFieldConstraintDTO.java b/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/relations/BeforeFieldConstraintDTO.java index 7c134cf2e..de854cb91 100644 --- a/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/relations/BeforeFieldConstraintDTO.java +++ b/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/relations/BeforeFieldConstraintDTO.java @@ -18,20 +18,18 @@ import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import com.scottlogic.deg.profile.dtos.constraints.ConstraintType; -import com.scottlogic.deg.profile.dtos.constraints.ConstraintTypeJsonProperty; @JsonDeserialize(as = BeforeFieldConstraintDTO.class) -public class BeforeFieldConstraintDTO extends RelationalConstraintDTO { - @JsonProperty(ConstraintTypeJsonProperty.BEFORE_FIELD) - public String otherField; +public class BeforeFieldConstraintDTO extends RelationalConstraintDTO +{ + public static final String NAME = "beforeField"; - public BeforeFieldConstraintDTO() { - super(ConstraintType.BEFORE_FIELD); - } + @JsonProperty(NAME) + public String otherField; @Override - public String getOtherField() { + public String getOtherField() + { return otherField; } } diff --git a/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/relations/BeforeOrAtFieldConstraintDTO.java b/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/relations/BeforeOrAtFieldConstraintDTO.java index 10a411029..7b95a7aa1 100644 --- a/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/relations/BeforeOrAtFieldConstraintDTO.java +++ b/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/relations/BeforeOrAtFieldConstraintDTO.java @@ -18,20 +18,18 @@ import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import com.scottlogic.deg.profile.dtos.constraints.ConstraintType; -import com.scottlogic.deg.profile.dtos.constraints.ConstraintTypeJsonProperty; @JsonDeserialize(as = BeforeOrAtFieldConstraintDTO.class) -public class BeforeOrAtFieldConstraintDTO extends RelationalConstraintDTO { - @JsonProperty(ConstraintTypeJsonProperty.BEFORE_OR_AT_FIELD) - public String otherField; +public class BeforeOrAtFieldConstraintDTO extends RelationalConstraintDTO +{ + public static final String NAME = "beforeOrAtField"; - public BeforeOrAtFieldConstraintDTO() { - super(ConstraintType.BEFORE_OR_AT_FIELD); - } + @JsonProperty(NAME) + public String otherField; @Override - public String getOtherField() { + public String getOtherField() + { return otherField; } } diff --git a/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/relations/EqualToFieldConstraintDTO.java b/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/relations/EqualToFieldConstraintDTO.java index 34e361161..9662360a5 100644 --- a/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/relations/EqualToFieldConstraintDTO.java +++ b/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/relations/EqualToFieldConstraintDTO.java @@ -18,20 +18,18 @@ import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import com.scottlogic.deg.profile.dtos.constraints.ConstraintType; -import com.scottlogic.deg.profile.dtos.constraints.ConstraintTypeJsonProperty; @JsonDeserialize(as = EqualToFieldConstraintDTO.class) -public class EqualToFieldConstraintDTO extends RelationalConstraintDTO { - @JsonProperty(ConstraintTypeJsonProperty.EQUAL_TO_FIELD) - public String otherField; +public class EqualToFieldConstraintDTO extends RelationalConstraintDTO +{ + public static final String NAME = "equalToField"; - public EqualToFieldConstraintDTO() { - super(ConstraintType.EQUAL_TO_FIELD); - } + @JsonProperty(NAME) + public String otherField; @Override - public String getOtherField() { + public String getOtherField() + { return otherField; } } diff --git a/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/relations/GreaterThanFieldConstraintDTO.java b/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/relations/GreaterThanFieldConstraintDTO.java index dec878b9e..22ef9db8b 100644 --- a/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/relations/GreaterThanFieldConstraintDTO.java +++ b/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/relations/GreaterThanFieldConstraintDTO.java @@ -18,20 +18,18 @@ import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import com.scottlogic.deg.profile.dtos.constraints.ConstraintType; -import com.scottlogic.deg.profile.dtos.constraints.ConstraintTypeJsonProperty; @JsonDeserialize(as = GreaterThanFieldConstraintDTO.class) -public class GreaterThanFieldConstraintDTO extends RelationalConstraintDTO { - @JsonProperty(ConstraintTypeJsonProperty.GREATER_THAN_FIELD) - public String otherField; +public class GreaterThanFieldConstraintDTO extends RelationalConstraintDTO +{ + public static final String NAME = "greaterThanField"; - public GreaterThanFieldConstraintDTO() { - super(ConstraintType.GREATER_THAN_FIELD); - } + @JsonProperty(NAME) + public String otherField; @Override - public String getOtherField() { + public String getOtherField() + { return otherField; } } diff --git a/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/relations/GreaterThanOrEqualToFieldConstraintDTO.java b/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/relations/GreaterThanOrEqualToFieldConstraintDTO.java index 3b605df94..db5a1a97f 100644 --- a/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/relations/GreaterThanOrEqualToFieldConstraintDTO.java +++ b/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/relations/GreaterThanOrEqualToFieldConstraintDTO.java @@ -18,20 +18,18 @@ import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import com.scottlogic.deg.profile.dtos.constraints.ConstraintType; -import com.scottlogic.deg.profile.dtos.constraints.ConstraintTypeJsonProperty; @JsonDeserialize(as = GreaterThanOrEqualToFieldConstraintDTO.class) -public class GreaterThanOrEqualToFieldConstraintDTO extends RelationalConstraintDTO { - @JsonProperty(ConstraintTypeJsonProperty.GREATER_THAN_OR_EQUAL_TO_FIELD) - public String otherField; +public class GreaterThanOrEqualToFieldConstraintDTO extends RelationalConstraintDTO +{ + public static final String NAME = "greaterThanOrEqualToField"; - public GreaterThanOrEqualToFieldConstraintDTO() { - super(ConstraintType.GREATER_THAN_OR_EQUAL_TO_FIELD); - } + @JsonProperty(NAME) + public String otherField; @Override - public String getOtherField() { + public String getOtherField() + { return otherField; } -} +} \ No newline at end of file diff --git a/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/relations/InMapConstraintDTO.java b/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/relations/InMapConstraintDTO.java index 90f266b7e..86b358dc7 100644 --- a/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/relations/InMapConstraintDTO.java +++ b/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/relations/InMapConstraintDTO.java @@ -16,19 +16,18 @@ package com.scottlogic.deg.profile.dtos.constraints.relations; -import com.scottlogic.deg.profile.dtos.constraints.ConstraintType; +import com.fasterxml.jackson.annotation.JsonProperty; import java.util.List; public class InMapConstraintDTO extends RelationalConstraintDTO { + public static final String NAME = "inMap"; + public String otherField; + @JsonProperty(NAME) public List values; - public InMapConstraintDTO() { - super(ConstraintType.IN_MAP); - } - @Override public String getOtherField() { diff --git a/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/relations/LessThanFieldConstraintDTO.java b/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/relations/LessThanFieldConstraintDTO.java index 457e1c461..b2c396bdc 100644 --- a/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/relations/LessThanFieldConstraintDTO.java +++ b/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/relations/LessThanFieldConstraintDTO.java @@ -18,20 +18,18 @@ import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import com.scottlogic.deg.profile.dtos.constraints.ConstraintType; -import com.scottlogic.deg.profile.dtos.constraints.ConstraintTypeJsonProperty; @JsonDeserialize(as = LessThanFieldConstraintDTO.class) -public class LessThanFieldConstraintDTO extends RelationalConstraintDTO { - @JsonProperty(ConstraintTypeJsonProperty.LESS_THAN_FIELD) - public String otherField; +public class LessThanFieldConstraintDTO extends RelationalConstraintDTO +{ + public static final String NAME = "lessThanField"; - public LessThanFieldConstraintDTO() { - super(ConstraintType.LESS_THAN_FIELD); - } + @JsonProperty(NAME) + public String otherField; @Override - public String getOtherField() { + public String getOtherField() + { return otherField; } } diff --git a/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/relations/LessThanOrEqualToFieldConstraintDTO.java b/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/relations/LessThanOrEqualToFieldConstraintDTO.java index 21569cd45..33b9eae07 100644 --- a/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/relations/LessThanOrEqualToFieldConstraintDTO.java +++ b/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/relations/LessThanOrEqualToFieldConstraintDTO.java @@ -18,17 +18,14 @@ import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import com.scottlogic.deg.profile.dtos.constraints.ConstraintType; -import com.scottlogic.deg.profile.dtos.constraints.ConstraintTypeJsonProperty; @JsonDeserialize(as = LessThanOrEqualToFieldConstraintDTO.class) -public class LessThanOrEqualToFieldConstraintDTO extends RelationalConstraintDTO { - @JsonProperty(ConstraintTypeJsonProperty.LESS_THAN_OR_EQUAL_TO_FIELD) - public String otherField; +public class LessThanOrEqualToFieldConstraintDTO extends RelationalConstraintDTO +{ + public static final String NAME ="lessThanOrEqualToField"; - public LessThanOrEqualToFieldConstraintDTO() { - super(ConstraintType.LESS_THAN_OR_EQUAL_TO_FIELD); - } + @JsonProperty(NAME) + public String otherField; @Override public String getOtherField() { diff --git a/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/relations/RelationalConstraintDTO.java b/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/relations/RelationalConstraintDTO.java index fa6d7478a..52a14c77d 100644 --- a/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/relations/RelationalConstraintDTO.java +++ b/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/relations/RelationalConstraintDTO.java @@ -16,7 +16,6 @@ package com.scottlogic.deg.profile.dtos.constraints.relations; -import com.scottlogic.deg.profile.dtos.constraints.ConstraintType; import com.scottlogic.deg.profile.dtos.constraints.ConstraintDTO; public abstract class RelationalConstraintDTO extends ConstraintDTO @@ -25,9 +24,5 @@ public abstract class RelationalConstraintDTO extends ConstraintDTO public int offset; public String offsetUnit; - RelationalConstraintDTO(ConstraintType type) { - super(type); - } - public abstract String getOtherField(); } diff --git a/profile/src/main/java/com/scottlogic/deg/profile/factories/constraint_factories/AtomicConstraintFactory.java b/profile/src/main/java/com/scottlogic/deg/profile/factories/constraint_factories/AtomicConstraintFactory.java index fb10a7ec5..a37f16d5a 100644 --- a/profile/src/main/java/com/scottlogic/deg/profile/factories/constraint_factories/AtomicConstraintFactory.java +++ b/profile/src/main/java/com/scottlogic/deg/profile/factories/constraint_factories/AtomicConstraintFactory.java @@ -22,6 +22,9 @@ 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.dtos.constraints.atomic.integer.LongerThanConstraintDTO; +import com.scottlogic.deg.profile.dtos.constraints.atomic.integer.OfLengthConstraintDTO; +import com.scottlogic.deg.profile.dtos.constraints.atomic.integer.ShorterThanConstraintDTO; import com.scottlogic.deg.profile.dtos.constraints.atomic.numeric.*; import com.scottlogic.deg.profile.dtos.constraints.atomic.temporal.AfterConstraintDTO; import com.scottlogic.deg.profile.dtos.constraints.atomic.temporal.AfterOrAtConstraintDTO; diff --git a/profile/src/main/java/com/scottlogic/deg/profile/factories/constraint_factories/DateTimeConstraintFactory.java b/profile/src/main/java/com/scottlogic/deg/profile/factories/constraint_factories/DateTimeConstraintFactory.java index b29e58729..a11c61acb 100644 --- a/profile/src/main/java/com/scottlogic/deg/profile/factories/constraint_factories/DateTimeConstraintFactory.java +++ b/profile/src/main/java/com/scottlogic/deg/profile/factories/constraint_factories/DateTimeConstraintFactory.java @@ -21,6 +21,9 @@ import com.scottlogic.deg.common.profile.Field; import com.scottlogic.deg.generator.profile.constraints.atomic.*; import com.scottlogic.deg.profile.dtos.constraints.atomic.GranularToConstraintDTO; +import com.scottlogic.deg.profile.dtos.constraints.atomic.integer.LongerThanConstraintDTO; +import com.scottlogic.deg.profile.dtos.constraints.atomic.integer.OfLengthConstraintDTO; +import com.scottlogic.deg.profile.dtos.constraints.atomic.integer.ShorterThanConstraintDTO; import com.scottlogic.deg.profile.dtos.constraints.atomic.numeric.*; import com.scottlogic.deg.profile.dtos.constraints.atomic.temporal.AfterConstraintDTO; import com.scottlogic.deg.profile.dtos.constraints.atomic.temporal.AfterOrAtConstraintDTO; diff --git a/profile/src/main/java/com/scottlogic/deg/profile/factories/constraint_factories/NumericConstraintFactory.java b/profile/src/main/java/com/scottlogic/deg/profile/factories/constraint_factories/NumericConstraintFactory.java index cb7e23447..8982f1b28 100644 --- a/profile/src/main/java/com/scottlogic/deg/profile/factories/constraint_factories/NumericConstraintFactory.java +++ b/profile/src/main/java/com/scottlogic/deg/profile/factories/constraint_factories/NumericConstraintFactory.java @@ -22,6 +22,9 @@ import com.scottlogic.deg.common.util.NumberUtils; import com.scottlogic.deg.generator.profile.constraints.atomic.*; import com.scottlogic.deg.profile.dtos.constraints.atomic.GranularToConstraintDTO; +import com.scottlogic.deg.profile.dtos.constraints.atomic.integer.LongerThanConstraintDTO; +import com.scottlogic.deg.profile.dtos.constraints.atomic.integer.OfLengthConstraintDTO; +import com.scottlogic.deg.profile.dtos.constraints.atomic.integer.ShorterThanConstraintDTO; import com.scottlogic.deg.profile.dtos.constraints.atomic.numeric.*; import com.scottlogic.deg.profile.dtos.constraints.atomic.temporal.AfterConstraintDTO; import com.scottlogic.deg.profile.dtos.constraints.atomic.temporal.AfterOrAtConstraintDTO; diff --git a/profile/src/main/java/com/scottlogic/deg/profile/factories/constraint_factories/StringConstraintFactory.java b/profile/src/main/java/com/scottlogic/deg/profile/factories/constraint_factories/StringConstraintFactory.java index 1adbd2db7..b89555b79 100644 --- a/profile/src/main/java/com/scottlogic/deg/profile/factories/constraint_factories/StringConstraintFactory.java +++ b/profile/src/main/java/com/scottlogic/deg/profile/factories/constraint_factories/StringConstraintFactory.java @@ -20,6 +20,9 @@ import com.scottlogic.deg.common.profile.Field; import com.scottlogic.deg.generator.profile.constraints.atomic.*; import com.scottlogic.deg.profile.dtos.constraints.atomic.GranularToConstraintDTO; +import com.scottlogic.deg.profile.dtos.constraints.atomic.integer.LongerThanConstraintDTO; +import com.scottlogic.deg.profile.dtos.constraints.atomic.integer.OfLengthConstraintDTO; +import com.scottlogic.deg.profile.dtos.constraints.atomic.integer.ShorterThanConstraintDTO; import com.scottlogic.deg.profile.dtos.constraints.atomic.numeric.*; import com.scottlogic.deg.profile.dtos.constraints.atomic.temporal.AfterConstraintDTO; import com.scottlogic.deg.profile.dtos.constraints.atomic.temporal.AfterOrAtConstraintDTO; diff --git a/profile/src/main/java/com/scottlogic/deg/profile/serialisation/ConstraintDeserializer.java b/profile/src/main/java/com/scottlogic/deg/profile/serialisation/ConstraintDeserializer.java index bbb9475cc..c0b5b091c 100644 --- a/profile/src/main/java/com/scottlogic/deg/profile/serialisation/ConstraintDeserializer.java +++ b/profile/src/main/java/com/scottlogic/deg/profile/serialisation/ConstraintDeserializer.java @@ -21,23 +21,13 @@ import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.node.ObjectNode; -import com.scottlogic.deg.profile.dtos.constraints.ConstraintType; -import com.scottlogic.deg.profile.dtos.constraints.ConstraintTypeJsonProperty; import com.scottlogic.deg.profile.dtos.constraints.ConstraintDTO; -import com.scottlogic.deg.profile.dtos.constraints.NotConstraintDTO; +import com.scottlogic.deg.profile.dtos.constraints.ConstraintType; import com.scottlogic.deg.profile.dtos.constraints.InvalidConstraintDTO; -import com.scottlogic.deg.profile.dtos.constraints.atomic.*; -import com.scottlogic.deg.profile.dtos.constraints.atomic.numeric.*; -import com.scottlogic.deg.profile.dtos.constraints.atomic.temporal.AfterConstraintDTO; -import com.scottlogic.deg.profile.dtos.constraints.atomic.temporal.AfterOrAtConstraintDTO; -import com.scottlogic.deg.profile.dtos.constraints.atomic.temporal.BeforeConstraintDTO; -import com.scottlogic.deg.profile.dtos.constraints.atomic.temporal.BeforeOrAtConstraintDTO; -import com.scottlogic.deg.profile.dtos.constraints.atomic.textual.ContainsRegexConstraintDTO; -import com.scottlogic.deg.profile.dtos.constraints.atomic.textual.MatchesRegexConstraintDTO; -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.dtos.constraints.atomic.InMapFromFileConstraintDTO; +import com.scottlogic.deg.profile.dtos.constraints.atomic.InSetConstraintDTO; +import com.scottlogic.deg.profile.dtos.constraints.atomic.InSetFromFileConstraintDTO; +import com.scottlogic.deg.profile.dtos.constraints.relations.InMapConstraintDTO; import com.scottlogic.deg.profile.reader.FileReader; import java.io.IOException; @@ -61,71 +51,15 @@ public ConstraintDTO deserialize(JsonParser jsonParser, DeserializationContext c { switch (type) { - case EQUAL_TO: - return mapper.treeToValue(node, EqualToConstraintDTO.class); - case EQUAL_TO_FIELD: - return mapper.treeToValue(node, EqualToFieldConstraintDTO.class); case IN_SET: - JsonNode inSetNode = node.get(ConstraintTypeJsonProperty.IN_SET); + JsonNode inSetNode = node.get(InSetConstraintDTO.NAME); return (inSetNode.isNull() || inSetNode.isArray()) ? mapper.treeToValue(node, InSetConstraintDTO.class) : map(mapper.treeToValue(node, InSetFromFileConstraintDTO.class)); case IN_MAP: return map(mapper.treeToValue(node, InMapFromFileConstraintDTO.class)); - case IS_NULL: - return mapper.treeToValue(node, IsNullConstraintDTO.class); - case GRANULAR_TO: - return mapper.treeToValue(node, GranularToConstraintDTO.class); - case MATCHES_REGEX: - return mapper.treeToValue(node, MatchesRegexConstraintDTO.class); - case CONTAINS_REGEX: - return mapper.treeToValue(node, ContainsRegexConstraintDTO.class); - case OF_LENGTH: - return mapper.treeToValue(node, OfLengthConstraintDTO.class); - case LONGER_THAN: - return mapper.treeToValue(node, LongerThanConstraintDTO.class); - case SHORTER_THAN: - return mapper.treeToValue(node, ShorterThanConstraintDTO.class); - case GREATER_THAN: - return mapper.treeToValue(node, GreaterThanConstraintDTO.class); - case GREATER_THAN_FIELD: - return mapper.treeToValue(node, GreaterThanFieldConstraintDTO.class); - case GREATER_THAN_OR_EQUAL_TO: - return mapper.treeToValue(node, GreaterThanOrEqualToConstraintDTO.class); - case GREATER_THAN_OR_EQUAL_TO_FIELD: - return mapper.treeToValue(node, GreaterThanOrEqualToFieldConstraintDTO.class); - case LESS_THAN: - return mapper.treeToValue(node, LessThanConstraintDTO.class); - case LESS_THAN_FIELD: - return mapper.treeToValue(node, LessThanFieldConstraintDTO.class); - case LESS_THAN_OR_EQUAL_TO: - return mapper.treeToValue(node, LessThanOrEqualToConstraintDTO.class); - case LESS_THAN_OR_EQUAL_TO_FIELD: - return mapper.treeToValue(node, LessThanOrEqualToFieldConstraintDTO.class); - case AFTER: - return mapper.treeToValue(node, AfterConstraintDTO.class); - case AFTER_FIELD: - return mapper.treeToValue(node, AfterFieldConstraintDTO.class); - case AFTER_OR_AT: - return mapper.treeToValue(node, AfterOrAtConstraintDTO.class); - case AFTER_OR_AT_FIELD: - return mapper.treeToValue(node, AfterOrAtFieldConstraintDTO.class); - case BEFORE: - return mapper.treeToValue(node, BeforeConstraintDTO.class); - case BEFORE_FIELD: - return mapper.treeToValue(node, BeforeFieldConstraintDTO.class); - case BEFORE_OR_AT: - return mapper.treeToValue(node, BeforeOrAtConstraintDTO.class); - case BEFORE_OR_AT_FIELD: - return mapper.treeToValue(node, BeforeOrAtFieldConstraintDTO.class); - case NOT: - return mapper.treeToValue(node, NotConstraintDTO.class); - case ANY_OF: - return mapper.treeToValue(node, AnyOfConstraintDTO.class); - case ALL_OF: - return mapper.treeToValue(node, AllOfConstraintDTO.class); - case IF: - return mapper.treeToValue(node, ConditionalConstraintDTO.class); + default: + return mapper.treeToValue(node, type.clazz); } } return new InvalidConstraintDTO(node.toString()); diff --git a/profile/src/main/java/com/scottlogic/deg/profile/services/ConstraintService.java b/profile/src/main/java/com/scottlogic/deg/profile/services/ConstraintService.java index 53c3ce31b..eb09ea83f 100644 --- a/profile/src/main/java/com/scottlogic/deg/profile/services/ConstraintService.java +++ b/profile/src/main/java/com/scottlogic/deg/profile/services/ConstraintService.java @@ -25,7 +25,7 @@ import com.scottlogic.deg.generator.profile.constraints.grammatical.OrConstraint; import com.scottlogic.deg.profile.dtos.constraints.ConstraintType; import com.scottlogic.deg.profile.dtos.constraints.ConstraintDTO; -import com.scottlogic.deg.profile.dtos.constraints.NotConstraintDTO; +import com.scottlogic.deg.profile.dtos.constraints.grammatical.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; diff --git a/profile/src/main/java/com/scottlogic/deg/profile/services/FieldService.java b/profile/src/main/java/com/scottlogic/deg/profile/services/FieldService.java index eefa27ef9..6a5d46ebe 100644 --- a/profile/src/main/java/com/scottlogic/deg/profile/services/FieldService.java +++ b/profile/src/main/java/com/scottlogic/deg/profile/services/FieldService.java @@ -22,7 +22,7 @@ import com.scottlogic.deg.profile.dtos.RuleDTO; import com.scottlogic.deg.profile.dtos.constraints.ConstraintDTO; import com.scottlogic.deg.profile.dtos.constraints.ConstraintType; -import com.scottlogic.deg.profile.dtos.constraints.NotConstraintDTO; +import com.scottlogic.deg.profile.dtos.constraints.grammatical.NotConstraintDTO; 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; diff --git a/profile/src/main/java/com/scottlogic/deg/profile/validators/profile/ConstraintValidator.java b/profile/src/main/java/com/scottlogic/deg/profile/validators/profile/ConstraintValidator.java index 301859a7f..14ae8950d 100644 --- a/profile/src/main/java/com/scottlogic/deg/profile/validators/profile/ConstraintValidator.java +++ b/profile/src/main/java/com/scottlogic/deg/profile/validators/profile/ConstraintValidator.java @@ -21,10 +21,10 @@ import com.scottlogic.deg.profile.dtos.FieldDTO; import com.scottlogic.deg.profile.dtos.constraints.ConstraintDTO; import com.scottlogic.deg.profile.dtos.constraints.InvalidConstraintDTO; -import com.scottlogic.deg.profile.dtos.constraints.NotConstraintDTO; +import com.scottlogic.deg.profile.dtos.constraints.grammatical.NotConstraintDTO; import com.scottlogic.deg.profile.dtos.constraints.atomic.InSetConstraintDTO; import com.scottlogic.deg.profile.dtos.constraints.atomic.IsNullConstraintDTO; -import com.scottlogic.deg.profile.dtos.constraints.atomic.numeric.IntegerConstraintDTO; +import com.scottlogic.deg.profile.dtos.constraints.atomic.integer.IntegerConstraintDTO; 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; @@ -58,7 +58,7 @@ protected ConstraintValidator(String rule, List fields) protected String getErrorInfo(T constraint) { - return " | Constraint: " + constraint.getName() + " | Rule: " + rule; + return " | Constraint: " + constraint.getType().propertyName + " | Rule: " + rule; } protected static ValidationResult validateConstraint(ConstraintDTO dto, String rule, List fields) @@ -129,7 +129,7 @@ private static ValidationResult constraintMustBeSpecified(ConstraintDTO dto, Str } if(dto.getType() == null) { - return ValidationResult.failure("Constraint type must not be null | Constraint: " + dto.getName() + " | Rule: " + rule); + return ValidationResult.failure("Constraint type must not be null | Constraint: " + dto.getType().propertyName + " | Rule: " + rule); } return ValidationResult.success(); } diff --git a/profile/src/main/java/com/scottlogic/deg/profile/validators/profile/constraints/NotConstraintValidator.java b/profile/src/main/java/com/scottlogic/deg/profile/validators/profile/constraints/NotConstraintValidator.java index 2f014bd69..c997e440d 100644 --- a/profile/src/main/java/com/scottlogic/deg/profile/validators/profile/constraints/NotConstraintValidator.java +++ b/profile/src/main/java/com/scottlogic/deg/profile/validators/profile/constraints/NotConstraintValidator.java @@ -17,7 +17,7 @@ import com.scottlogic.deg.common.validators.ValidationResult; import com.scottlogic.deg.profile.dtos.FieldDTO; -import com.scottlogic.deg.profile.dtos.constraints.NotConstraintDTO; +import com.scottlogic.deg.profile.dtos.constraints.grammatical.NotConstraintDTO; import com.scottlogic.deg.profile.validators.profile.ConstraintValidator; import java.util.List; diff --git a/profile/src/main/java/com/scottlogic/deg/profile/validators/profile/constraints/atomic/IntegerConstraintValidator.java b/profile/src/main/java/com/scottlogic/deg/profile/validators/profile/constraints/atomic/IntegerConstraintValidator.java index 047fa5095..fc349f648 100644 --- a/profile/src/main/java/com/scottlogic/deg/profile/validators/profile/constraints/atomic/IntegerConstraintValidator.java +++ b/profile/src/main/java/com/scottlogic/deg/profile/validators/profile/constraints/atomic/IntegerConstraintValidator.java @@ -4,7 +4,7 @@ import com.scottlogic.deg.common.util.Defaults; import com.scottlogic.deg.common.validators.ValidationResult; import com.scottlogic.deg.profile.dtos.FieldDTO; -import com.scottlogic.deg.profile.dtos.constraints.atomic.numeric.IntegerConstraintDTO; +import com.scottlogic.deg.profile.dtos.constraints.atomic.integer.IntegerConstraintDTO; import java.math.BigDecimal; import java.util.List; 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 304911468..ee62223b5 100644 --- a/profile/src/test/java/com/scottlogic/deg/profile/AtomicConstraintDeserialiserTests.java +++ b/profile/src/test/java/com/scottlogic/deg/profile/AtomicConstraintDeserialiserTests.java @@ -23,6 +23,9 @@ import com.scottlogic.deg.profile.dtos.constraints.atomic.GranularToConstraintDTO; import com.scottlogic.deg.profile.dtos.constraints.atomic.InSetConstraintDTO; import com.scottlogic.deg.profile.dtos.constraints.atomic.IsNullConstraintDTO; +import com.scottlogic.deg.profile.dtos.constraints.atomic.integer.LongerThanConstraintDTO; +import com.scottlogic.deg.profile.dtos.constraints.atomic.integer.OfLengthConstraintDTO; +import com.scottlogic.deg.profile.dtos.constraints.atomic.integer.ShorterThanConstraintDTO; import com.scottlogic.deg.profile.dtos.constraints.atomic.numeric.*; import com.scottlogic.deg.profile.dtos.constraints.atomic.temporal.AfterConstraintDTO; import com.scottlogic.deg.profile.dtos.constraints.atomic.temporal.AfterOrAtConstraintDTO; 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 2fc5e2866..719868088 100644 --- a/profile/src/test/java/com/scottlogic/deg/profile/GrammaticalConstraintDeserialiserTests.java +++ b/profile/src/test/java/com/scottlogic/deg/profile/GrammaticalConstraintDeserialiserTests.java @@ -21,7 +21,7 @@ import com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException; import com.scottlogic.deg.profile.dtos.constraints.ConstraintDTO; import com.scottlogic.deg.profile.dtos.constraints.InvalidConstraintDTO; -import com.scottlogic.deg.profile.dtos.constraints.NotConstraintDTO; +import com.scottlogic.deg.profile.dtos.constraints.grammatical.NotConstraintDTO; import com.scottlogic.deg.profile.dtos.constraints.atomic.EqualToConstraintDTO; import com.scottlogic.deg.profile.dtos.constraints.atomic.IsNullConstraintDTO; import com.scottlogic.deg.profile.dtos.constraints.atomic.numeric.GreaterThanConstraintDTO; diff --git a/profile/src/test/java/com/scottlogic/deg/profile/dtos/ConstraintTypeTest.java b/profile/src/test/java/com/scottlogic/deg/profile/dtos/ConstraintTypeTest.java index 033f0d1bc..53faaa231 100644 --- a/profile/src/test/java/com/scottlogic/deg/profile/dtos/ConstraintTypeTest.java +++ b/profile/src/test/java/com/scottlogic/deg/profile/dtos/ConstraintTypeTest.java @@ -27,14 +27,14 @@ class ConstraintTypeTest{ @Test void fromText() { String greaterThanString = ConstraintType.GREATER_THAN_OR_EQUAL_TO.propertyName; - ConstraintType greaterThanOrEqualTo = ConstraintType.fromPropertyName(greaterThanString); + ConstraintType greaterThanOrEqualTo = ConstraintType.fromName(greaterThanString); Assert.assertThat(greaterThanOrEqualTo, is(ConstraintType.GREATER_THAN_OR_EQUAL_TO)); } @Test void fromTextLowerCase() { - ConstraintType greaterThanOrEqualTo = ConstraintType.fromPropertyName("shorterthan"); + ConstraintType greaterThanOrEqualTo = ConstraintType.fromName("shorterthan"); Assert.assertThat(greaterThanOrEqualTo, is(ConstraintType.SHORTER_THAN)); } From 363b3e77ee0712bb64faa579e7f8decd043c9700 Mon Sep 17 00:00:00 2001 From: Charlton Dowding Date: Thu, 7 Nov 2019 16:09:11 +0000 Subject: [PATCH 06/10] feat(#1473): Restructured ConstraintType enum --- .../serialisation/ConstraintDeserializer.java | 28 +++++++++---------- .../profile/services/ConstraintService.java | 17 ++++------- 2 files changed, 18 insertions(+), 27 deletions(-) diff --git a/profile/src/main/java/com/scottlogic/deg/profile/serialisation/ConstraintDeserializer.java b/profile/src/main/java/com/scottlogic/deg/profile/serialisation/ConstraintDeserializer.java index c0b5b091c..b4d9f19b4 100644 --- a/profile/src/main/java/com/scottlogic/deg/profile/serialisation/ConstraintDeserializer.java +++ b/profile/src/main/java/com/scottlogic/deg/profile/serialisation/ConstraintDeserializer.java @@ -46,23 +46,21 @@ public ConstraintDTO deserialize(JsonParser jsonParser, DeserializationContext c ObjectNode node = mapper.readTree(jsonParser); ConstraintType type = Arrays.stream(ConstraintType.values()) .filter(constraintType -> node.has(constraintType.propertyName)) - .findFirst().orElse(null); - if (type != null) + .findFirst().orElse(ConstraintType.INVALID); + switch (type) { - switch (type) - { - case IN_SET: - JsonNode inSetNode = node.get(InSetConstraintDTO.NAME); - return (inSetNode.isNull() || inSetNode.isArray()) - ? mapper.treeToValue(node, InSetConstraintDTO.class) - : map(mapper.treeToValue(node, InSetFromFileConstraintDTO.class)); - case IN_MAP: - return map(mapper.treeToValue(node, InMapFromFileConstraintDTO.class)); - default: - return mapper.treeToValue(node, type.clazz); - } + case INVALID: + return new InvalidConstraintDTO(node.toString()); + case IN_SET: + JsonNode inSetNode = node.get(InSetConstraintDTO.NAME); + return (inSetNode.isNull() || inSetNode.isArray()) + ? mapper.treeToValue(node, InSetConstraintDTO.class) + : map(mapper.treeToValue(node, InSetFromFileConstraintDTO.class)); + case IN_MAP: + return map(mapper.treeToValue(node, InMapFromFileConstraintDTO.class)); + default: + return mapper.treeToValue(node, type.clazz); } - return new InvalidConstraintDTO(node.toString()); } private InMapConstraintDTO map(InMapFromFileConstraintDTO dto) diff --git a/profile/src/main/java/com/scottlogic/deg/profile/services/ConstraintService.java b/profile/src/main/java/com/scottlogic/deg/profile/services/ConstraintService.java index eb09ea83f..0dca70689 100644 --- a/profile/src/main/java/com/scottlogic/deg/profile/services/ConstraintService.java +++ b/profile/src/main/java/com/scottlogic/deg/profile/services/ConstraintService.java @@ -21,16 +21,11 @@ import com.scottlogic.deg.generator.profile.constraints.atomic.*; 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.dtos.constraints.ConstraintType; import com.scottlogic.deg.profile.dtos.constraints.ConstraintDTO; -import com.scottlogic.deg.profile.dtos.constraints.grammatical.NotConstraintDTO; +import com.scottlogic.deg.profile.dtos.constraints.ConstraintType; 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.grammatical.*; import com.scottlogic.deg.profile.dtos.constraints.relations.InMapConstraintDTO; import com.scottlogic.deg.profile.dtos.constraints.relations.RelationalConstraintDTO; import com.scottlogic.deg.profile.factories.constraint_factories.AtomicConstraintFactory; @@ -107,10 +102,6 @@ private Constraint createConstraint(ConstraintDTO dto, Fields fields) FieldType type = fields.getByName(((InMapConstraintDTO)dto).field).getType(); return atomicConstraintFactoryMap.get(type).createInMapRelation((InMapConstraintDTO) dto, fields); } - if (dto.getType() == ConstraintType.NOT) - { - return createConstraint(((NotConstraintDTO) dto).constraint, fields).negate(); - } if (dto instanceof RelationalConstraintDTO) { FieldType type = fields.getByName(((RelationalConstraintDTO)dto).field).getType(); @@ -128,7 +119,7 @@ private Constraint createConstraint(ConstraintDTO dto, Fields fields) throw new IllegalStateException("Unexpected constraint type: " + dto.getType()); } - private GrammaticalConstraint createGrammaticalConstraint(GrammaticalConstraintDTO dto, Fields fields) + private Constraint createGrammaticalConstraint(GrammaticalConstraintDTO dto, Fields fields) { switch (dto.getType()) { @@ -138,6 +129,8 @@ private GrammaticalConstraint createGrammaticalConstraint(GrammaticalConstraintD return new OrConstraint(createConstraints(((AnyOfConstraintDTO) dto).constraints, fields)); case IF: return createConditionalConstraint((ConditionalConstraintDTO) dto, fields); + case NOT: + return createConstraint(((NotConstraintDTO) dto).constraint, fields).negate(); default: throw new IllegalStateException("Unexpected grammatical constraint type: " + dto.getType()); } From 6df2ede5e3c0dbca57c03cfd6b772464e550b5b3 Mon Sep 17 00:00:00 2001 From: Charlton Dowding Date: Thu, 7 Nov 2019 16:22:48 +0000 Subject: [PATCH 07/10] Addressed Review Comments * Renamed IntegerConstraintDTO * Added liscences --- .../deg/common/commands/Command.java | 1 + .../deg/common/commands/CommandBus.java | 1 + .../deg/common/commands/CommandHandler.java | 1 + .../deg/common/commands/CommandResult.java | 1 + .../common/profile/DateTimeGranularity.java | 1 + .../deg/common/profile/FieldType.java | 1 + .../deg/common/profile/SpecificFieldType.java | 1 + .../deg/profile/commands/CreateProfile.java | 1 + .../dtos/constraints/ConstraintType.java | 1 + .../integer/LongerThanConstraintDTO.java | 4 +-- .../atomic/integer/OfLengthConstraintDTO.java | 4 +-- .../integer/ShorterThanConstraintDTO.java | 4 +-- ...TO.java => StringLengthConstraintDTO.java} | 4 +-- .../profile/factories/DateTimeFactory.java | 16 ++++++++++ .../AtomicConstraintFactory.java | 1 + .../FieldSpecRelationFactory.java | 1 + .../handlers/CreateProfileHandler.java | 1 + .../serialisation/ConstraintDeserializer.java | 1 + .../profile/services/ConstraintService.java | 1 + .../deg/profile/services/FieldService.java | 1 + .../deg/profile/services/RuleService.java | 1 + .../validators/CreateProfileValidator.java | 1 + .../profile/ConstraintValidator.java | 5 ++-- .../validators/profile/FieldValidator.java | 1 + .../validators/profile/ProfileValidator.java | 1 + .../validators/profile/RuleValidator.java | 1 + .../constraints/InMapConstraintValidator.java | 1 + .../constraints/NotConstraintValidator.java | 1 + .../RelationalConstraintValidator.java | 1 + .../atomic/AtomicConstraintValidator.java | 1 + .../atomic/DateTimeGranularityValidator.java | 1 + .../atomic/EqualToConstraintValidator.java | 1 + .../atomic/GranularToConstraintValidator.java | 1 + .../atomic/InSetConstraintValidator.java | 1 + .../atomic/IsNullConstraintValidator.java | 1 + .../atomic/NumericConstraintValidator.java | 1 + .../atomic/RegexConstraintValidator.java | 1 + ...a => StringLengthConstraintValidator.java} | 30 ++++++++++++++----- .../atomic/TemporalConstraintValidator.java | 9 ++++-- .../grammatical/AllOfConstraintValidator.java | 1 + .../grammatical/AnyOfConstraintValidator.java | 1 + .../ConditionalConstraintValidator.java | 1 + .../GrammaticalConstraintValidator.java | 1 + 43 files changed, 92 insertions(+), 19 deletions(-) rename profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/integer/{IntegerConstraintDTO.java => StringLengthConstraintDTO.java} (87%) rename profile/src/main/java/com/scottlogic/deg/profile/validators/profile/constraints/atomic/{IntegerConstraintValidator.java => StringLengthConstraintValidator.java} (56%) 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 index 5f7520fbb..bf57c3e5b 100644 --- a/common/src/main/java/com/scottlogic/deg/common/commands/Command.java +++ b/common/src/main/java/com/scottlogic/deg/common/commands/Command.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.scottlogic.deg.common.commands; import java.lang.reflect.Type; 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 index 1e583b60f..b105fc51a 100644 --- a/common/src/main/java/com/scottlogic/deg/common/commands/CommandBus.java +++ b/common/src/main/java/com/scottlogic/deg/common/commands/CommandBus.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.scottlogic.deg.common.commands; import org.apache.commons.lang3.tuple.ImmutablePair; 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 index 449d492f4..253ce7e6f 100644 --- a/common/src/main/java/com/scottlogic/deg/common/commands/CommandHandler.java +++ b/common/src/main/java/com/scottlogic/deg/common/commands/CommandHandler.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.scottlogic.deg.common.commands; import com.scottlogic.deg.common.validators.ValidationResult; 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 index bc8ce940a..599f37095 100644 --- a/common/src/main/java/com/scottlogic/deg/common/commands/CommandResult.java +++ b/common/src/main/java/com/scottlogic/deg/common/commands/CommandResult.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.scottlogic.deg.common.commands; import java.util.ArrayList; diff --git a/common/src/main/java/com/scottlogic/deg/common/profile/DateTimeGranularity.java b/common/src/main/java/com/scottlogic/deg/common/profile/DateTimeGranularity.java index fd051abeb..36c9ca4fe 100644 --- a/common/src/main/java/com/scottlogic/deg/common/profile/DateTimeGranularity.java +++ b/common/src/main/java/com/scottlogic/deg/common/profile/DateTimeGranularity.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.scottlogic.deg.common.profile; import com.scottlogic.deg.common.ValidationException; diff --git a/common/src/main/java/com/scottlogic/deg/common/profile/FieldType.java b/common/src/main/java/com/scottlogic/deg/common/profile/FieldType.java index 4432c8d62..f111bf6ac 100644 --- a/common/src/main/java/com/scottlogic/deg/common/profile/FieldType.java +++ b/common/src/main/java/com/scottlogic/deg/common/profile/FieldType.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.scottlogic.deg.common.profile; public enum FieldType diff --git a/common/src/main/java/com/scottlogic/deg/common/profile/SpecificFieldType.java b/common/src/main/java/com/scottlogic/deg/common/profile/SpecificFieldType.java index 52b85de40..fd4372737 100644 --- a/common/src/main/java/com/scottlogic/deg/common/profile/SpecificFieldType.java +++ b/common/src/main/java/com/scottlogic/deg/common/profile/SpecificFieldType.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.scottlogic.deg.common.profile; import com.fasterxml.jackson.annotation.JsonValue; diff --git a/profile/src/main/java/com/scottlogic/deg/profile/commands/CreateProfile.java b/profile/src/main/java/com/scottlogic/deg/profile/commands/CreateProfile.java index d0d325f8b..2df019bd0 100644 --- a/profile/src/main/java/com/scottlogic/deg/profile/commands/CreateProfile.java +++ b/profile/src/main/java/com/scottlogic/deg/profile/commands/CreateProfile.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.scottlogic.deg.profile.commands; import com.scottlogic.deg.common.commands.Command; diff --git a/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/ConstraintType.java b/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/ConstraintType.java index f09204c28..084db658b 100644 --- a/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/ConstraintType.java +++ b/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/ConstraintType.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.scottlogic.deg.profile.dtos.constraints; diff --git a/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/integer/LongerThanConstraintDTO.java b/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/integer/LongerThanConstraintDTO.java index b65291a8c..72a303349 100644 --- a/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/integer/LongerThanConstraintDTO.java +++ b/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/integer/LongerThanConstraintDTO.java @@ -20,7 +20,7 @@ import com.fasterxml.jackson.databind.annotation.JsonDeserialize; @JsonDeserialize(as = LongerThanConstraintDTO.class) -public class LongerThanConstraintDTO extends IntegerConstraintDTO +public class LongerThanConstraintDTO extends StringLengthConstraintDTO { public static final String NAME ="longerThan"; @@ -28,7 +28,7 @@ public class LongerThanConstraintDTO extends IntegerConstraintDTO public int value; @Override - public int getInt() + public int stringLength() { return value; } diff --git a/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/integer/OfLengthConstraintDTO.java b/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/integer/OfLengthConstraintDTO.java index 3b835bfbe..e8c85e9bc 100644 --- a/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/integer/OfLengthConstraintDTO.java +++ b/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/integer/OfLengthConstraintDTO.java @@ -20,7 +20,7 @@ import com.fasterxml.jackson.databind.annotation.JsonDeserialize; @JsonDeserialize(as = OfLengthConstraintDTO.class) -public class OfLengthConstraintDTO extends IntegerConstraintDTO +public class OfLengthConstraintDTO extends StringLengthConstraintDTO { public static final String NAME = "ofLength"; @@ -28,7 +28,7 @@ public class OfLengthConstraintDTO extends IntegerConstraintDTO public int value; @Override - public int getInt() + public int stringLength() { return value; } diff --git a/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/integer/ShorterThanConstraintDTO.java b/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/integer/ShorterThanConstraintDTO.java index a53881cd5..cdf46fdbb 100644 --- a/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/integer/ShorterThanConstraintDTO.java +++ b/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/integer/ShorterThanConstraintDTO.java @@ -20,7 +20,7 @@ import com.fasterxml.jackson.databind.annotation.JsonDeserialize; @JsonDeserialize(as = ShorterThanConstraintDTO.class) -public class ShorterThanConstraintDTO extends IntegerConstraintDTO +public class ShorterThanConstraintDTO extends StringLengthConstraintDTO { public static final String NAME = "shorterThan"; @@ -28,7 +28,7 @@ public class ShorterThanConstraintDTO extends IntegerConstraintDTO public int value; @Override - public int getInt() + public int stringLength() { return value; } diff --git a/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/integer/IntegerConstraintDTO.java b/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/integer/StringLengthConstraintDTO.java similarity index 87% rename from profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/integer/IntegerConstraintDTO.java rename to profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/integer/StringLengthConstraintDTO.java index 9465467d5..abc5e75df 100644 --- a/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/integer/IntegerConstraintDTO.java +++ b/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/atomic/integer/StringLengthConstraintDTO.java @@ -19,8 +19,8 @@ import com.fasterxml.jackson.annotation.JsonIgnore; import com.scottlogic.deg.profile.dtos.constraints.atomic.AtomicConstraintDTO; -public abstract class IntegerConstraintDTO extends AtomicConstraintDTO +public abstract class StringLengthConstraintDTO extends AtomicConstraintDTO { @JsonIgnore - public abstract int getInt(); + public abstract int stringLength(); } diff --git a/profile/src/main/java/com/scottlogic/deg/profile/factories/DateTimeFactory.java b/profile/src/main/java/com/scottlogic/deg/profile/factories/DateTimeFactory.java index f74c038ba..b47180e1a 100644 --- a/profile/src/main/java/com/scottlogic/deg/profile/factories/DateTimeFactory.java +++ b/profile/src/main/java/com/scottlogic/deg/profile/factories/DateTimeFactory.java @@ -1,3 +1,19 @@ +/* + * 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.factories; import com.scottlogic.deg.common.ValidationException; diff --git a/profile/src/main/java/com/scottlogic/deg/profile/factories/constraint_factories/AtomicConstraintFactory.java b/profile/src/main/java/com/scottlogic/deg/profile/factories/constraint_factories/AtomicConstraintFactory.java index a37f16d5a..ba3cc705f 100644 --- a/profile/src/main/java/com/scottlogic/deg/profile/factories/constraint_factories/AtomicConstraintFactory.java +++ b/profile/src/main/java/com/scottlogic/deg/profile/factories/constraint_factories/AtomicConstraintFactory.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.scottlogic.deg.profile.factories.constraint_factories; import com.scottlogic.deg.common.ValidationException; diff --git a/profile/src/main/java/com/scottlogic/deg/profile/factories/relation_factories/FieldSpecRelationFactory.java b/profile/src/main/java/com/scottlogic/deg/profile/factories/relation_factories/FieldSpecRelationFactory.java index a7746a782..a6200cf53 100644 --- a/profile/src/main/java/com/scottlogic/deg/profile/factories/relation_factories/FieldSpecRelationFactory.java +++ b/profile/src/main/java/com/scottlogic/deg/profile/factories/relation_factories/FieldSpecRelationFactory.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.scottlogic.deg.profile.factories.relation_factories; import com.scottlogic.deg.common.profile.*; diff --git a/profile/src/main/java/com/scottlogic/deg/profile/handlers/CreateProfileHandler.java b/profile/src/main/java/com/scottlogic/deg/profile/handlers/CreateProfileHandler.java index 09e574e0d..f125bfb07 100644 --- a/profile/src/main/java/com/scottlogic/deg/profile/handlers/CreateProfileHandler.java +++ b/profile/src/main/java/com/scottlogic/deg/profile/handlers/CreateProfileHandler.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.scottlogic.deg.profile.handlers; import com.google.inject.Inject; diff --git a/profile/src/main/java/com/scottlogic/deg/profile/serialisation/ConstraintDeserializer.java b/profile/src/main/java/com/scottlogic/deg/profile/serialisation/ConstraintDeserializer.java index b4d9f19b4..ce65b1cc3 100644 --- a/profile/src/main/java/com/scottlogic/deg/profile/serialisation/ConstraintDeserializer.java +++ b/profile/src/main/java/com/scottlogic/deg/profile/serialisation/ConstraintDeserializer.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.scottlogic.deg.profile.serialisation; import com.fasterxml.jackson.core.JsonParser; diff --git a/profile/src/main/java/com/scottlogic/deg/profile/services/ConstraintService.java b/profile/src/main/java/com/scottlogic/deg/profile/services/ConstraintService.java index 0dca70689..0ba7fb3ac 100644 --- a/profile/src/main/java/com/scottlogic/deg/profile/services/ConstraintService.java +++ b/profile/src/main/java/com/scottlogic/deg/profile/services/ConstraintService.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.scottlogic.deg.profile.services; import com.google.inject.Inject; diff --git a/profile/src/main/java/com/scottlogic/deg/profile/services/FieldService.java b/profile/src/main/java/com/scottlogic/deg/profile/services/FieldService.java index 6a5d46ebe..50976e3d9 100644 --- a/profile/src/main/java/com/scottlogic/deg/profile/services/FieldService.java +++ b/profile/src/main/java/com/scottlogic/deg/profile/services/FieldService.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.scottlogic.deg.profile.services; import com.scottlogic.deg.common.profile.Field; diff --git a/profile/src/main/java/com/scottlogic/deg/profile/services/RuleService.java b/profile/src/main/java/com/scottlogic/deg/profile/services/RuleService.java index c087a58b3..042b5cfdc 100644 --- a/profile/src/main/java/com/scottlogic/deg/profile/services/RuleService.java +++ b/profile/src/main/java/com/scottlogic/deg/profile/services/RuleService.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.scottlogic.deg.profile.services; import com.google.inject.Inject; diff --git a/profile/src/main/java/com/scottlogic/deg/profile/validators/CreateProfileValidator.java b/profile/src/main/java/com/scottlogic/deg/profile/validators/CreateProfileValidator.java index 5aa90c8de..bf058ca68 100644 --- a/profile/src/main/java/com/scottlogic/deg/profile/validators/CreateProfileValidator.java +++ b/profile/src/main/java/com/scottlogic/deg/profile/validators/CreateProfileValidator.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.scottlogic.deg.profile.validators; import com.google.inject.Inject; diff --git a/profile/src/main/java/com/scottlogic/deg/profile/validators/profile/ConstraintValidator.java b/profile/src/main/java/com/scottlogic/deg/profile/validators/profile/ConstraintValidator.java index 14ae8950d..f00f481c1 100644 --- a/profile/src/main/java/com/scottlogic/deg/profile/validators/profile/ConstraintValidator.java +++ b/profile/src/main/java/com/scottlogic/deg/profile/validators/profile/ConstraintValidator.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.scottlogic.deg.profile.validators.profile; import com.scottlogic.deg.common.profile.FieldType; @@ -24,7 +25,7 @@ import com.scottlogic.deg.profile.dtos.constraints.grammatical.NotConstraintDTO; import com.scottlogic.deg.profile.dtos.constraints.atomic.InSetConstraintDTO; import com.scottlogic.deg.profile.dtos.constraints.atomic.IsNullConstraintDTO; -import com.scottlogic.deg.profile.dtos.constraints.atomic.integer.IntegerConstraintDTO; +import com.scottlogic.deg.profile.dtos.constraints.atomic.integer.StringLengthConstraintDTO; 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; @@ -93,7 +94,7 @@ protected static ValidationResult validateConstraint(ConstraintDTO dto, String r case OF_LENGTH: case LONGER_THAN: case SHORTER_THAN: - return new IntegerConstraintValidator(rule, fields, FieldType.STRING).validate((IntegerConstraintDTO) dto); + return new StringLengthConstraintValidator(rule, fields, FieldType.STRING).validate((StringLengthConstraintDTO) dto); case GREATER_THAN: case GREATER_THAN_OR_EQUAL_TO: case LESS_THAN: diff --git a/profile/src/main/java/com/scottlogic/deg/profile/validators/profile/FieldValidator.java b/profile/src/main/java/com/scottlogic/deg/profile/validators/profile/FieldValidator.java index 14435f912..ca5652d85 100644 --- a/profile/src/main/java/com/scottlogic/deg/profile/validators/profile/FieldValidator.java +++ b/profile/src/main/java/com/scottlogic/deg/profile/validators/profile/FieldValidator.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.scottlogic.deg.profile.validators.profile; import com.scottlogic.deg.common.validators.ValidationResult; diff --git a/profile/src/main/java/com/scottlogic/deg/profile/validators/profile/ProfileValidator.java b/profile/src/main/java/com/scottlogic/deg/profile/validators/profile/ProfileValidator.java index 679c2ca4d..f3c8da294 100644 --- a/profile/src/main/java/com/scottlogic/deg/profile/validators/profile/ProfileValidator.java +++ b/profile/src/main/java/com/scottlogic/deg/profile/validators/profile/ProfileValidator.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.scottlogic.deg.profile.validators.profile; import com.google.inject.Inject; diff --git a/profile/src/main/java/com/scottlogic/deg/profile/validators/profile/RuleValidator.java b/profile/src/main/java/com/scottlogic/deg/profile/validators/profile/RuleValidator.java index 08eb82adc..7ce7658bd 100644 --- a/profile/src/main/java/com/scottlogic/deg/profile/validators/profile/RuleValidator.java +++ b/profile/src/main/java/com/scottlogic/deg/profile/validators/profile/RuleValidator.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.scottlogic.deg.profile.validators.profile; import com.scottlogic.deg.common.validators.ValidationResult; diff --git a/profile/src/main/java/com/scottlogic/deg/profile/validators/profile/constraints/InMapConstraintValidator.java b/profile/src/main/java/com/scottlogic/deg/profile/validators/profile/constraints/InMapConstraintValidator.java index e99257fe8..b00939d40 100644 --- a/profile/src/main/java/com/scottlogic/deg/profile/validators/profile/constraints/InMapConstraintValidator.java +++ b/profile/src/main/java/com/scottlogic/deg/profile/validators/profile/constraints/InMapConstraintValidator.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.scottlogic.deg.profile.validators.profile.constraints; import com.scottlogic.deg.common.validators.ValidationResult; diff --git a/profile/src/main/java/com/scottlogic/deg/profile/validators/profile/constraints/NotConstraintValidator.java b/profile/src/main/java/com/scottlogic/deg/profile/validators/profile/constraints/NotConstraintValidator.java index c997e440d..faa1976c0 100644 --- a/profile/src/main/java/com/scottlogic/deg/profile/validators/profile/constraints/NotConstraintValidator.java +++ b/profile/src/main/java/com/scottlogic/deg/profile/validators/profile/constraints/NotConstraintValidator.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.scottlogic.deg.profile.validators.profile.constraints; import com.scottlogic.deg.common.validators.ValidationResult; diff --git a/profile/src/main/java/com/scottlogic/deg/profile/validators/profile/constraints/RelationalConstraintValidator.java b/profile/src/main/java/com/scottlogic/deg/profile/validators/profile/constraints/RelationalConstraintValidator.java index 073f12ce8..d5f7048a2 100644 --- a/profile/src/main/java/com/scottlogic/deg/profile/validators/profile/constraints/RelationalConstraintValidator.java +++ b/profile/src/main/java/com/scottlogic/deg/profile/validators/profile/constraints/RelationalConstraintValidator.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.scottlogic.deg.profile.validators.profile.constraints; import com.scottlogic.deg.common.profile.FieldType; diff --git a/profile/src/main/java/com/scottlogic/deg/profile/validators/profile/constraints/atomic/AtomicConstraintValidator.java b/profile/src/main/java/com/scottlogic/deg/profile/validators/profile/constraints/atomic/AtomicConstraintValidator.java index a004d1bc9..5fe363b75 100644 --- a/profile/src/main/java/com/scottlogic/deg/profile/validators/profile/constraints/atomic/AtomicConstraintValidator.java +++ b/profile/src/main/java/com/scottlogic/deg/profile/validators/profile/constraints/atomic/AtomicConstraintValidator.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.scottlogic.deg.profile.validators.profile.constraints.atomic; import com.scottlogic.deg.common.profile.FieldType; diff --git a/profile/src/main/java/com/scottlogic/deg/profile/validators/profile/constraints/atomic/DateTimeGranularityValidator.java b/profile/src/main/java/com/scottlogic/deg/profile/validators/profile/constraints/atomic/DateTimeGranularityValidator.java index f9f4cf87d..d19c7402b 100644 --- a/profile/src/main/java/com/scottlogic/deg/profile/validators/profile/constraints/atomic/DateTimeGranularityValidator.java +++ b/profile/src/main/java/com/scottlogic/deg/profile/validators/profile/constraints/atomic/DateTimeGranularityValidator.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.scottlogic.deg.profile.validators.profile.constraints.atomic; import com.scottlogic.deg.common.validators.ValidationResult; diff --git a/profile/src/main/java/com/scottlogic/deg/profile/validators/profile/constraints/atomic/EqualToConstraintValidator.java b/profile/src/main/java/com/scottlogic/deg/profile/validators/profile/constraints/atomic/EqualToConstraintValidator.java index 6137553c5..67db9c332 100644 --- a/profile/src/main/java/com/scottlogic/deg/profile/validators/profile/constraints/atomic/EqualToConstraintValidator.java +++ b/profile/src/main/java/com/scottlogic/deg/profile/validators/profile/constraints/atomic/EqualToConstraintValidator.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.scottlogic.deg.profile.validators.profile.constraints.atomic; import com.scottlogic.deg.common.validators.ValidationResult; diff --git a/profile/src/main/java/com/scottlogic/deg/profile/validators/profile/constraints/atomic/GranularToConstraintValidator.java b/profile/src/main/java/com/scottlogic/deg/profile/validators/profile/constraints/atomic/GranularToConstraintValidator.java index 8395f87f6..2b7b88a71 100644 --- a/profile/src/main/java/com/scottlogic/deg/profile/validators/profile/constraints/atomic/GranularToConstraintValidator.java +++ b/profile/src/main/java/com/scottlogic/deg/profile/validators/profile/constraints/atomic/GranularToConstraintValidator.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.scottlogic.deg.profile.validators.profile.constraints.atomic; import com.scottlogic.deg.common.validators.ValidationResult; diff --git a/profile/src/main/java/com/scottlogic/deg/profile/validators/profile/constraints/atomic/InSetConstraintValidator.java b/profile/src/main/java/com/scottlogic/deg/profile/validators/profile/constraints/atomic/InSetConstraintValidator.java index 2d910a933..df2b1aea8 100644 --- a/profile/src/main/java/com/scottlogic/deg/profile/validators/profile/constraints/atomic/InSetConstraintValidator.java +++ b/profile/src/main/java/com/scottlogic/deg/profile/validators/profile/constraints/atomic/InSetConstraintValidator.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.scottlogic.deg.profile.validators.profile.constraints.atomic; import com.scottlogic.deg.common.validators.ValidationResult; diff --git a/profile/src/main/java/com/scottlogic/deg/profile/validators/profile/constraints/atomic/IsNullConstraintValidator.java b/profile/src/main/java/com/scottlogic/deg/profile/validators/profile/constraints/atomic/IsNullConstraintValidator.java index 6e15b7f77..dfef03039 100644 --- a/profile/src/main/java/com/scottlogic/deg/profile/validators/profile/constraints/atomic/IsNullConstraintValidator.java +++ b/profile/src/main/java/com/scottlogic/deg/profile/validators/profile/constraints/atomic/IsNullConstraintValidator.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.scottlogic.deg.profile.validators.profile.constraints.atomic; import com.scottlogic.deg.common.validators.ValidationResult; diff --git a/profile/src/main/java/com/scottlogic/deg/profile/validators/profile/constraints/atomic/NumericConstraintValidator.java b/profile/src/main/java/com/scottlogic/deg/profile/validators/profile/constraints/atomic/NumericConstraintValidator.java index 19cab3ab9..19418777f 100644 --- a/profile/src/main/java/com/scottlogic/deg/profile/validators/profile/constraints/atomic/NumericConstraintValidator.java +++ b/profile/src/main/java/com/scottlogic/deg/profile/validators/profile/constraints/atomic/NumericConstraintValidator.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.scottlogic.deg.profile.validators.profile.constraints.atomic; diff --git a/profile/src/main/java/com/scottlogic/deg/profile/validators/profile/constraints/atomic/RegexConstraintValidator.java b/profile/src/main/java/com/scottlogic/deg/profile/validators/profile/constraints/atomic/RegexConstraintValidator.java index d61d91de3..4730b1a7f 100644 --- a/profile/src/main/java/com/scottlogic/deg/profile/validators/profile/constraints/atomic/RegexConstraintValidator.java +++ b/profile/src/main/java/com/scottlogic/deg/profile/validators/profile/constraints/atomic/RegexConstraintValidator.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.scottlogic.deg.profile.validators.profile.constraints.atomic; diff --git a/profile/src/main/java/com/scottlogic/deg/profile/validators/profile/constraints/atomic/IntegerConstraintValidator.java b/profile/src/main/java/com/scottlogic/deg/profile/validators/profile/constraints/atomic/StringLengthConstraintValidator.java similarity index 56% rename from profile/src/main/java/com/scottlogic/deg/profile/validators/profile/constraints/atomic/IntegerConstraintValidator.java rename to profile/src/main/java/com/scottlogic/deg/profile/validators/profile/constraints/atomic/StringLengthConstraintValidator.java index fc349f648..9d876ddfd 100644 --- a/profile/src/main/java/com/scottlogic/deg/profile/validators/profile/constraints/atomic/IntegerConstraintValidator.java +++ b/profile/src/main/java/com/scottlogic/deg/profile/validators/profile/constraints/atomic/StringLengthConstraintValidator.java @@ -1,39 +1,55 @@ +/* + * 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.validators.profile.constraints.atomic; import com.scottlogic.deg.common.profile.FieldType; import com.scottlogic.deg.common.util.Defaults; import com.scottlogic.deg.common.validators.ValidationResult; import com.scottlogic.deg.profile.dtos.FieldDTO; -import com.scottlogic.deg.profile.dtos.constraints.atomic.integer.IntegerConstraintDTO; +import com.scottlogic.deg.profile.dtos.constraints.atomic.integer.StringLengthConstraintDTO; import java.math.BigDecimal; import java.util.List; -public class IntegerConstraintValidator extends AtomicConstraintValidator +public class StringLengthConstraintValidator extends AtomicConstraintValidator { private final FieldType expectedFieldType; - public IntegerConstraintValidator(String rule, List fields, FieldType expectedFieldType) + public StringLengthConstraintValidator(String rule, List fields, FieldType expectedFieldType) { super(rule, fields); this.expectedFieldType = expectedFieldType; } @Override - public final ValidationResult validate(IntegerConstraintDTO dto) + public final ValidationResult validate(StringLengthConstraintDTO dto) { ValidationResult fieldMustBeValid = fieldMustBeValid(dto); if(!fieldMustBeValid.isSuccess) return fieldMustBeValid; - ValidationResult integerMustBeValid = integerMustBeValid(dto); + ValidationResult integerMustBeValid = stringLengthMustBeValid(dto); if(!integerMustBeValid.isSuccess) return integerMustBeValid; return fieldTypeMustMatchValueType(dto, expectedFieldType); } - private ValidationResult integerMustBeValid(IntegerConstraintDTO dto) + private ValidationResult stringLengthMustBeValid(StringLengthConstraintDTO dto) { - BigDecimal integer = BigDecimal.valueOf(dto.getInt()); + BigDecimal integer = BigDecimal.valueOf(dto.stringLength()); BigDecimal max = BigDecimal.valueOf(Defaults.MAX_STRING_LENGTH); BigDecimal min = BigDecimal.ZERO; if (integer.compareTo(min) < 0) diff --git a/profile/src/main/java/com/scottlogic/deg/profile/validators/profile/constraints/atomic/TemporalConstraintValidator.java b/profile/src/main/java/com/scottlogic/deg/profile/validators/profile/constraints/atomic/TemporalConstraintValidator.java index b8b232f39..6ad1e3eab 100644 --- a/profile/src/main/java/com/scottlogic/deg/profile/validators/profile/constraints/atomic/TemporalConstraintValidator.java +++ b/profile/src/main/java/com/scottlogic/deg/profile/validators/profile/constraints/atomic/TemporalConstraintValidator.java @@ -13,10 +13,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.scottlogic.deg.profile.validators.profile.constraints.atomic; import com.scottlogic.deg.common.profile.FieldType; +import com.scottlogic.deg.common.util.defaults.DateTimeDefaults; import com.scottlogic.deg.common.validators.ValidationResult; import com.scottlogic.deg.profile.dtos.FieldDTO; import com.scottlogic.deg.profile.dtos.constraints.atomic.temporal.TemporalConstraintDTO; @@ -55,12 +57,15 @@ private ValidationResult dateTimeMustBeValid(TemporalConstraintDTO dto) try { OffsetDateTime offsetDateTime = DateTimeFactory.create(dateTime); - if (offsetDateTime.getYear() > 9999 || offsetDateTime.getYear() < 1) + OffsetDateTime max = DateTimeDefaults.get().max(); + OffsetDateTime min = DateTimeDefaults.get().min(); + if (offsetDateTime.compareTo(max) > 0 || offsetDateTime.compareTo(min) < 0) { return ValidationResult.failure("Dates must be between 0001-01-01T00:00:00.000Z and 9999-12-31T23:59:59.999Z" + getErrorInfo(dto)); } return ValidationResult.success(); - } catch (Exception e) + } + catch (Exception e) { return ValidationResult.failure(e.getMessage() + getErrorInfo(dto)); } diff --git a/profile/src/main/java/com/scottlogic/deg/profile/validators/profile/constraints/grammatical/AllOfConstraintValidator.java b/profile/src/main/java/com/scottlogic/deg/profile/validators/profile/constraints/grammatical/AllOfConstraintValidator.java index 0403a24f7..085a4eda4 100644 --- a/profile/src/main/java/com/scottlogic/deg/profile/validators/profile/constraints/grammatical/AllOfConstraintValidator.java +++ b/profile/src/main/java/com/scottlogic/deg/profile/validators/profile/constraints/grammatical/AllOfConstraintValidator.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.scottlogic.deg.profile.validators.profile.constraints.grammatical; import com.scottlogic.deg.common.validators.ValidationResult; diff --git a/profile/src/main/java/com/scottlogic/deg/profile/validators/profile/constraints/grammatical/AnyOfConstraintValidator.java b/profile/src/main/java/com/scottlogic/deg/profile/validators/profile/constraints/grammatical/AnyOfConstraintValidator.java index 77b8cf271..1b53d534e 100644 --- a/profile/src/main/java/com/scottlogic/deg/profile/validators/profile/constraints/grammatical/AnyOfConstraintValidator.java +++ b/profile/src/main/java/com/scottlogic/deg/profile/validators/profile/constraints/grammatical/AnyOfConstraintValidator.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.scottlogic.deg.profile.validators.profile.constraints.grammatical; import com.scottlogic.deg.common.validators.ValidationResult; diff --git a/profile/src/main/java/com/scottlogic/deg/profile/validators/profile/constraints/grammatical/ConditionalConstraintValidator.java b/profile/src/main/java/com/scottlogic/deg/profile/validators/profile/constraints/grammatical/ConditionalConstraintValidator.java index 307c29071..d54cccd13 100644 --- a/profile/src/main/java/com/scottlogic/deg/profile/validators/profile/constraints/grammatical/ConditionalConstraintValidator.java +++ b/profile/src/main/java/com/scottlogic/deg/profile/validators/profile/constraints/grammatical/ConditionalConstraintValidator.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.scottlogic.deg.profile.validators.profile.constraints.grammatical; import com.scottlogic.deg.common.validators.ValidationResult; diff --git a/profile/src/main/java/com/scottlogic/deg/profile/validators/profile/constraints/grammatical/GrammaticalConstraintValidator.java b/profile/src/main/java/com/scottlogic/deg/profile/validators/profile/constraints/grammatical/GrammaticalConstraintValidator.java index 2dffb0dd0..5ad80234b 100644 --- a/profile/src/main/java/com/scottlogic/deg/profile/validators/profile/constraints/grammatical/GrammaticalConstraintValidator.java +++ b/profile/src/main/java/com/scottlogic/deg/profile/validators/profile/constraints/grammatical/GrammaticalConstraintValidator.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.scottlogic.deg.profile.validators.profile.constraints.grammatical; import com.scottlogic.deg.common.validators.ValidationResult; From 4f25ef0b2c7d05db95cc885e8cff833d87eae2aa Mon Sep 17 00:00:00 2001 From: Charlton Dowding Date: Fri, 8 Nov 2019 11:01:40 +0000 Subject: [PATCH 08/10] Import optimisation --- .../utils/CucumberTestState.java | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) 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 62f42d3dc..c26efc5d5 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 @@ -25,22 +25,11 @@ 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.atomic.EqualToConstraintDTO; -import com.scottlogic.deg.profile.dtos.constraints.atomic.GranularToConstraintDTO; -import com.scottlogic.deg.profile.dtos.constraints.atomic.integer.LongerThanConstraintDTO; -import com.scottlogic.deg.profile.dtos.constraints.atomic.integer.OfLengthConstraintDTO; -import com.scottlogic.deg.profile.dtos.constraints.atomic.integer.ShorterThanConstraintDTO; +import com.scottlogic.deg.profile.dtos.constraints.atomic.textual.*; +import com.scottlogic.deg.profile.dtos.constraints.atomic.integer.*; import com.scottlogic.deg.profile.dtos.constraints.atomic.numeric.*; -import com.scottlogic.deg.profile.dtos.constraints.atomic.temporal.AfterConstraintDTO; -import com.scottlogic.deg.profile.dtos.constraints.atomic.temporal.AfterOrAtConstraintDTO; -import com.scottlogic.deg.profile.dtos.constraints.atomic.temporal.BeforeConstraintDTO; -import com.scottlogic.deg.profile.dtos.constraints.atomic.temporal.BeforeOrAtConstraintDTO; -import com.scottlogic.deg.profile.dtos.constraints.atomic.textual.ContainsRegexConstraintDTO; -import com.scottlogic.deg.profile.dtos.constraints.atomic.textual.MatchesRegexConstraintDTO; -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.NotConstraintDTO; +import com.scottlogic.deg.profile.dtos.constraints.atomic.temporal.*; +import com.scottlogic.deg.profile.dtos.constraints.grammatical.*; import com.scottlogic.deg.profile.dtos.constraints.relations.*; import java.io.IOException; From 56c4cbc91d7cc4a576b0771dfbc0738bb09e1dec Mon Sep 17 00:00:00 2001 From: Charlton Dowding Date: Fri, 8 Nov 2019 11:16:39 +0000 Subject: [PATCH 09/10] Removed commented out test --- .../reducer/ConstraintReducerTest.java | 1309 ----------------- 1 file changed, 1309 deletions(-) delete mode 100644 generator/src/test/java/com/scottlogic/deg/generator/reducer/ConstraintReducerTest.java diff --git a/generator/src/test/java/com/scottlogic/deg/generator/reducer/ConstraintReducerTest.java b/generator/src/test/java/com/scottlogic/deg/generator/reducer/ConstraintReducerTest.java deleted file mode 100644 index bbe3997c0..000000000 --- a/generator/src/test/java/com/scottlogic/deg/generator/reducer/ConstraintReducerTest.java +++ /dev/null @@ -1,1309 +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.reducer; -//// -////import com.scottlogic.deg.common.profile.Field; -////import com.scottlogic.deg.common.profile.ProfileFields; -////import com.scottlogic.deg.generator.decisiontree.ConstraintNode; -////import com.scottlogic.deg.generator.decisiontree.ConstraintNodeBuilder; -////import com.scottlogic.deg.generator.fieldspecs.FieldSpec; -////import com.scottlogic.deg.generator.fieldspecs.FieldSpecFactory; -////import com.scottlogic.deg.generator.fieldspecs.FieldSpecMerger; -////import com.scottlogic.deg.generator.fieldspecs.RowSpec; -////import com.scottlogic.deg.generator.fieldspecs.whitelist.DistributedList; -////import com.scottlogic.deg.generator.fieldspecs.whitelist.WeightedElement; -////import com.scottlogic.deg.generator.profile.constraints.atomic.*; -////import com.scottlogic.deg.generator.restrictions.linear.LinearRestrictions; -////import com.scottlogic.deg.generator.utils.SetUtils; -////import org.hamcrest.core.Is; -////import org.hamcrest.core.IsNull; -////import org.junit.Assert; -////import org.junit.jupiter.api.Test; -//// -////import java.math.BigDecimal; -////import java.time.OffsetDateTime; -////import java.time.ZoneOffset; -////import java.util.*; -////import java.util.regex.Pattern; -////import java.util.stream.Collectors; -////import java.util.stream.Stream; -//// -////import static com.scottlogic.deg.common.profile.FieldType.*; -////import static com.scottlogic.deg.common.util.Defaults.*; -////import static org.hamcrest.Matchers.*; -////import static com.scottlogic.deg.common.profile.FieldBuilder.createField; -//// -////class ConstraintReducerTest { -//// -//// private final ConstraintReducer constraintReducer = new ConstraintReducer( -//// new FieldSpecMerger() -//// ); -//// -//// private static ConstraintNode nodeFromConstraints(Set constraints) { -//// return new ConstraintNodeBuilder().addAtomicConstraints(constraints).build(); -//// } -//// -//// @Test -//// void shouldProduceCorrectFieldSpecsForExample() { -//// // ARRANGE -//// final Field quantityField = createField("quantity", NUMERIC); -//// final Field countryField = createField("country"); -//// final Field cityField = createField("city"); -//// -//// ProfileFields fieldList = new ProfileFields( -//// Arrays.asList(quantityField, countryField, cityField)); -//// -//// final DistributedList countryAmong = new DistributedList<>(Stream.of("UK", "US") -//// .map(string -> new WeightedElement<>((Object) string, 1.0F)) -//// .collect(Collectors.toList())); -//// -//// final Set constraints = SetUtils.setOf( -//// new IsGreaterThanOrEqualToConstantConstraint(quantityField, BigDecimal.valueOf(0)), -//// new IsGreaterThanConstantConstraint(quantityField, BigDecimal.valueOf(5)).negate(), -//// new IsInSetConstraint(countryField, countryAmong)); -//// -//// // ACT -//// final RowSpec reducedConstraints = constraintReducer.reduceConstraintsToRowSpec( -//// fieldList, -//// nodeFromConstraints(constraints)).get(); -//// -//// // ASSERT -//// FieldSpec quantityFieldSpec = reducedConstraints.getSpecForField(quantityField); -//// Assert.assertThat("Quantity fieldspec has no set restrictions", quantityFieldSpec.getWhitelist(), -//// Is.is(IsNull.nullValue())); -//// Assert.assertThat("Quantity fieldspec has no null restrictions", quantityFieldSpec.isNullable(), -//// Is.is(true)); -//// Assert.assertThat("Quantity fieldspec has numeric restrictions", quantityFieldSpec.getRestrictions(), -//// Is.is(IsNull.notNullValue())); -//// Assert.assertThat("Quantity fieldspec has correct lower bound limit", -//// ((LinearRestrictions) quantityFieldSpec.getRestrictions()).getMin(), Is.is(BigDecimal.ZERO)); -//// Assert.assertThat("Quantity fieldspec has correct upper bound limit", -//// ((LinearRestrictions) quantityFieldSpec.getRestrictions()).getMax(), Is.is(BigDecimal.valueOf(5))); -//// -//// FieldSpec countryFieldSpec = reducedConstraints.getSpecForField(countryField); -//// Assert.assertThat("Country fieldspec has no null restrictions", countryFieldSpec.isNullable(), -//// Is.is(true)); -//// Assert.assertThat("Country fieldspec set restrictions have whitelist", -//// countryFieldSpec.getWhitelist().list(), notNullValue()); -//// Assert.assertThat("Country fieldspec set restrictions whitelist has correct size", -//// countryFieldSpec.getWhitelist().list().size(), Is.is(2)); -//// Assert.assertThat("Country fieldspec set restrictions whitelist contains 'UK'", -//// countryFieldSpec.getWhitelist().list().contains("UK"), Is.is(true)); -//// Assert.assertThat("Country fieldspec set restrictions whitelist contains 'US'", -//// countryFieldSpec.getWhitelist().list().contains("US"), Is.is(true)); -//// -//// FieldSpec cityFieldSpec = reducedConstraints.getSpecForField(cityField); -//// Assert.assertThat("City fieldspec has no set restrictions", cityFieldSpec.getWhitelist(), -//// Is.is(IsNull.nullValue())); -//// Assert.assertThat("City fieldspec has the default string restrictions", cityFieldSpec.getRestrictions(), -//// Is.is(FieldSpecFactory.fromType(STRING).getRestrictions())); -//// Assert.assertThat("City fieldspec has no null restrictions", cityFieldSpec.isNullable(), -//// Is.is(true)); -//// } -//// -//// @Test -//// void shouldReduceIsGreaterThanConstantConstraint() { -//// final Field field = createField("test0", NUMERIC); -//// ProfileFields profileFields = new ProfileFields(Collections.singletonList(field)); -//// Set constraints = Collections.singleton( -//// new IsGreaterThanOrEqualToConstantConstraint(field, BigDecimal.valueOf(5))); -//// -//// RowSpec testOutput = constraintReducer.reduceConstraintsToRowSpec(profileFields, nodeFromConstraints(constraints)).get(); -//// -//// Assert.assertThat("Output is not null", testOutput, Is.is(IsNull.notNullValue())); -//// FieldSpec outputSpec = testOutput.getSpecForField(field); -//// Assert.assertThat("Fieldspec is not null", outputSpec, Is.is(IsNull.notNullValue())); -//// Assert.assertThat("Fieldspec has no set restrictions", outputSpec.getWhitelist(), -//// Is.is(IsNull.nullValue())); -//// Assert.assertThat("Fieldspec has no null restrictions", outputSpec.isNullable(), -//// Is.is(true)); -//// Assert.assertThat("Fieldspec has numeric restrictions", outputSpec.getRestrictions(), -//// Is.is(IsNull.notNullValue())); -//// Assert.assertThat("Fieldspec numeric restrictions have no upper bound", -//// ((LinearRestrictions) outputSpec.getRestrictions()).getMax(), -//// Is.is(equalTo(NUMERIC_MAX))); -//// Assert.assertThat("Fieldspec numeric restrictions have lower bound", -//// ((LinearRestrictions) outputSpec.getRestrictions()).getMin(), -//// Is.is(not(equalTo(NUMERIC_MIN)))); -//// Assert.assertThat("Fieldspec numeric restriction lower bound is correct", -//// ((LinearRestrictions) outputSpec.getRestrictions()).getMin(), Is.is(BigDecimal.valueOf(5))); -//// } -//// -//// @Test -//// void shouldReduceNegatedIsGreaterThanConstantConstraint() { -//// final Field field = createField("test0", NUMERIC); -//// ProfileFields profileFields = new ProfileFields(Collections.singletonList(field)); -//// Set constraints = Collections.singleton( -//// new IsGreaterThanConstantConstraint(field, BigDecimal.valueOf(5)).negate()); -//// -//// RowSpec testOutput = constraintReducer.reduceConstraintsToRowSpec(profileFields, nodeFromConstraints(constraints)).get(); -//// -//// Assert.assertThat("Output is not null", testOutput, Is.is(IsNull.notNullValue())); -//// FieldSpec outputSpec = testOutput.getSpecForField(field); -//// Assert.assertThat("Fieldspec is not null", outputSpec, Is.is(IsNull.notNullValue())); -//// Assert.assertThat("Fieldspec has no set restrictions", outputSpec.getWhitelist(), -//// Is.is(IsNull.nullValue())); -//// Assert.assertThat("Fieldspec has no null restrictions", outputSpec.isNullable(), -//// Is.is(true)); -//// Assert.assertThat("Fieldspec has numeric restrictions", outputSpec.getRestrictions(), -//// Is.is(IsNull.notNullValue())); -//// Assert.assertThat("Fieldspec numeric restrictions have no lower bound", -//// ((LinearRestrictions) outputSpec.getRestrictions()).getMin(), Is.is(equalTo(NUMERIC_MIN))); -//// Assert.assertThat("Fieldspec numeric restrictions have upper bound", -//// ((LinearRestrictions) outputSpec.getRestrictions()).getMax(), Is.is(not(equalTo(NUMERIC_MAX)))); -//// Assert.assertThat("Fieldspec numeric restrictions upper bound limit is correct", -//// ((LinearRestrictions) outputSpec.getRestrictions()).getMax(), Is.is(BigDecimal.valueOf(5))); -//// } -//// -//// @Test -//// void shouldReduceIsGreaterThanOrEqualToConstantConstraint() { -//// final Field field = createField("test0", NUMERIC); -//// ProfileFields profileFields = new ProfileFields(Collections.singletonList(field)); -//// Set constraints = Collections.singleton( -//// new IsGreaterThanOrEqualToConstantConstraint(field, BigDecimal.valueOf(5))); -//// -//// RowSpec testOutput = constraintReducer.reduceConstraintsToRowSpec(profileFields, nodeFromConstraints(constraints)).get(); -//// -//// Assert.assertThat("Output is not null", testOutput, Is.is(IsNull.notNullValue())); -//// FieldSpec outputSpec = testOutput.getSpecForField(field); -//// Assert.assertThat("Fieldspec is not null", outputSpec, Is.is(IsNull.notNullValue())); -//// Assert.assertThat("Fieldspec has no set restrictions", outputSpec.getWhitelist(), -//// Is.is(IsNull.nullValue())); -//// Assert.assertThat("Fieldspec has no null restrictions", outputSpec.isNullable(), -//// Is.is(true)); -//// Assert.assertThat("Fieldspec has numeric restrictions", outputSpec.getRestrictions(), -//// Is.is(IsNull.notNullValue())); -//// Assert.assertThat("Fieldspec numeric restrictions have no upper bound", -//// ((LinearRestrictions) outputSpec.getRestrictions()).getMax(), -//// Is.is(NUMERIC_MAX)); -//// Assert.assertThat("Fieldspec numeric restrictions have lower bound", -//// ((LinearRestrictions) outputSpec.getRestrictions()).getMin(), -//// Is.is(not(NUMERIC_MIN))); -//// Assert.assertThat("Fieldspec numeric restriction lower bound is correct", -//// ((LinearRestrictions) outputSpec.getRestrictions()).getMin(), Is.is(BigDecimal.valueOf(5))); -//// } -//// -//// @Test -//// void shouldReduceNegatedIsGreaterThanOrEqualToConstantConstraint() { -//// final Field field = createField("test0", NUMERIC); -//// ProfileFields profileFields = new ProfileFields(Collections.singletonList(field)); -//// Set constraints = Collections.singleton( -//// new IsGreaterThanConstantConstraint(field, BigDecimal.valueOf(5)).negate()); -//// -//// RowSpec testOutput = constraintReducer.reduceConstraintsToRowSpec(profileFields, nodeFromConstraints(constraints)).get(); -//// -//// Assert.assertThat("Output is not null", testOutput, Is.is(IsNull.notNullValue())); -//// FieldSpec outputSpec = testOutput.getSpecForField(field); -//// Assert.assertThat("Fieldspec is not null", outputSpec, Is.is(IsNull.notNullValue())); -//// Assert.assertThat("Fieldspec has no set restrictions", outputSpec.getWhitelist(), -//// Is.is(IsNull.nullValue())); -//// Assert.assertThat("Fieldspec has no null restrictions", outputSpec.isNullable(), -//// Is.is(true)); -//// Assert.assertThat("Fieldspec has numeric restrictions", outputSpec.getRestrictions(), -//// Is.is(IsNull.notNullValue())); -//// Assert.assertThat("Fieldspec numeric restrictions have no lower bound", -//// ((LinearRestrictions) outputSpec.getRestrictions()).getMin(), Is.is(NUMERIC_MIN)); -//// Assert.assertThat("Fieldspec numeric restrictions have upper bound", -//// ((LinearRestrictions) outputSpec.getRestrictions()).getMax(), Is.is(not(NUMERIC_MAX))); -//// Assert.assertThat("Fieldspec numeric restrictions upper bound limit is correct", -//// ((LinearRestrictions) outputSpec.getRestrictions()).getMax(), Is.is(BigDecimal.valueOf(5))); -//// } -//// -//// @Test -//// void shouldReduceIsLessThanConstantConstraint() { -//// final Field field = createField("test0", NUMERIC); -//// ProfileFields profileFields = new ProfileFields(Collections.singletonList(field)); -//// Set constraints = Collections.singleton( -//// new IsLessThanOrEqualToConstantConstraint(field, BigDecimal.valueOf(5))); -//// -//// RowSpec testOutput = constraintReducer.reduceConstraintsToRowSpec(profileFields, nodeFromConstraints(constraints)).get(); -//// -//// Assert.assertThat("Output is not null", testOutput, Is.is(IsNull.notNullValue())); -//// FieldSpec outputSpec = testOutput.getSpecForField(field); -//// Assert.assertThat("Fieldspec is not null", outputSpec, Is.is(IsNull.notNullValue())); -//// Assert.assertThat("Fieldspec has no set restrictions", outputSpec.getWhitelist(), -//// Is.is(IsNull.nullValue())); -//// Assert.assertThat("Fieldspec has no null restrictions", outputSpec.isNullable(), -//// Is.is(true)); -//// Assert.assertThat("Fieldspec has numeric restrictions", outputSpec.getRestrictions(), -//// Is.is(IsNull.notNullValue())); -//// Assert.assertThat("Fieldspec numeric restrictions have no lower bound", -//// ((LinearRestrictions) outputSpec.getRestrictions()).getMin(), Is.is(NUMERIC_MIN)); -//// Assert.assertThat("Fieldspec numeric restrictions have upper bound", -//// ((LinearRestrictions) outputSpec.getRestrictions()).getMax(), Is.is(not(NUMERIC_MAX))); -//// Assert.assertThat("Fieldspec numeric restrictions upper bound limit is correct", -//// ((LinearRestrictions) outputSpec.getRestrictions()).getMax(), Is.is(BigDecimal.valueOf(5))); -//// } -//// -//// @Test -//// void shouldReduceNegatedIsLessThanConstantConstraint() { -//// final Field field = createField("test0", NUMERIC); -//// ProfileFields profileFields = new ProfileFields(Collections.singletonList(field)); -//// Set constraints = Collections.singleton( -//// new IsLessThanConstantConstraint(field, BigDecimal.valueOf(5)).negate()); -//// -//// RowSpec testOutput = constraintReducer.reduceConstraintsToRowSpec(profileFields, nodeFromConstraints(constraints)).get(); -//// -//// Assert.assertThat("Output is not null", testOutput, Is.is(IsNull.notNullValue())); -//// FieldSpec outputSpec = testOutput.getSpecForField(field); -//// Assert.assertThat("Fieldspec is not null", outputSpec, Is.is(IsNull.notNullValue())); -//// Assert.assertThat("Fieldspec has no set restrictions", outputSpec.getWhitelist(), -//// Is.is(IsNull.nullValue())); -//// Assert.assertThat("Fieldspec has no null restrictions", outputSpec.isNullable(), -//// Is.is(true)); -//// Assert.assertThat("Fieldspec has numeric restrictions", outputSpec.getRestrictions(), -//// Is.is(IsNull.notNullValue())); -//// Assert.assertThat("Fieldspec numeric restrictions have no upper bound", -//// ((LinearRestrictions) outputSpec.getRestrictions()).getMax(), Is.is(NUMERIC_MAX)); -//// Assert.assertThat("Fieldspec numeric restrictions have lower bound", -//// ((LinearRestrictions) outputSpec.getRestrictions()).getMin(), Is.is(not(NUMERIC_MIN))); -//// Assert.assertThat("Fieldspec numeric restriction lower bound is correct", -//// ((LinearRestrictions) outputSpec.getRestrictions()).getMin(), Is.is(BigDecimal.valueOf(5))); -//// } -//// -//// @Test -//// void shouldReduceIsLessThanOrEqualToConstantConstraint() { -//// final Field field = createField("test0", NUMERIC); -//// ProfileFields profileFields = new ProfileFields(Collections.singletonList(field)); -//// Set constraints = Collections.singleton( -//// new IsLessThanOrEqualToConstantConstraint(field, BigDecimal.valueOf(5))); -//// -//// RowSpec testOutput = constraintReducer.reduceConstraintsToRowSpec(profileFields, nodeFromConstraints(constraints)).get(); -//// -//// Assert.assertThat("Output is not null", testOutput, Is.is(IsNull.notNullValue())); -//// FieldSpec outputSpec = testOutput.getSpecForField(field); -//// Assert.assertThat("Fieldspec is not null", outputSpec, Is.is(IsNull.notNullValue())); -//// Assert.assertThat("Fieldspec has no set restrictions", outputSpec.getWhitelist(), -//// Is.is(IsNull.nullValue())); -//// Assert.assertThat("Fieldspec has no null restrictions", outputSpec.isNullable(), -//// Is.is(true)); -//// Assert.assertThat("Fieldspec has numeric restrictions", outputSpec.getRestrictions(), -//// Is.is(IsNull.notNullValue())); -//// Assert.assertThat("Fieldspec numeric restrictions have no lower bound", -//// ((LinearRestrictions) outputSpec.getRestrictions()).getMin(), Is.is(NUMERIC_MIN)); -//// Assert.assertThat("Fieldspec numeric restrictions have upper bound", -//// ((LinearRestrictions) outputSpec.getRestrictions()).getMax(), Is.is(not(NUMERIC_MAX))); -//// Assert.assertThat("Fieldspec numeric restrictions upper bound limit is correct", -//// ((LinearRestrictions) outputSpec.getRestrictions()).getMax(), Is.is(BigDecimal.valueOf(5))); -//// } -//// -//// @Test -//// void shouldReduceNegatedIsLessThanOrEqualToConstantConstraint() { -//// final Field field = createField("test0", NUMERIC); -//// ProfileFields profileFields = new ProfileFields(Collections.singletonList(field)); -//// Set constraints = Collections.singleton( -//// new IsLessThanConstantConstraint(field, BigDecimal.valueOf(5)).negate()); -//// -//// RowSpec testOutput = constraintReducer.reduceConstraintsToRowSpec(profileFields, nodeFromConstraints(constraints)).get(); -//// -//// Assert.assertThat("Output is not null", testOutput, Is.is(IsNull.notNullValue())); -//// FieldSpec outputSpec = testOutput.getSpecForField(field); -//// Assert.assertThat("Fieldspec is not null", outputSpec, Is.is(IsNull.notNullValue())); -//// Assert.assertThat("Fieldspec has no set restrictions", outputSpec.getWhitelist(), -//// Is.is(IsNull.nullValue())); -//// Assert.assertThat("Fieldspec has no null restrictions", outputSpec.isNullable(), -//// Is.is(true)); -//// Assert.assertThat("Fieldspec has numeric restrictions", outputSpec.getRestrictions(), -//// Is.is(IsNull.notNullValue())); -//// Assert.assertThat("Fieldspec numeric restrictions have no upper bound", -//// ((LinearRestrictions) outputSpec.getRestrictions()).getMax(), Is.is(equalTo(NUMERIC_MAX))); -//// Assert.assertThat("Fieldspec numeric restrictions have lower bound", -//// ((LinearRestrictions) outputSpec.getRestrictions()).getMin(), Is.is(not(equalTo(NUMERIC_MIN)))); -//// Assert.assertThat("Fieldspec numeric restriction lower bound is correct", -//// ((LinearRestrictions) outputSpec.getRestrictions()).getMin(), Is.is(BigDecimal.valueOf(5))); -//// } -//// -//// @Test -//// void shouldreduceIsAfterConstantDateTimeConstraint() { -//// final Field field = createField("test0", DATETIME); -//// final OffsetDateTime testTimestamp = OffsetDateTime.of(2018, 2, 4, 23, 25, 16, 0, ZoneOffset.UTC); -//// ProfileFields profileFields = new ProfileFields(Collections.singletonList(field)); -//// Set constraints = Collections.singleton( -//// new IsAfterOrEqualToConstantDateTimeConstraint(field, testTimestamp)); -//// -//// RowSpec testOutput = constraintReducer.reduceConstraintsToRowSpec(profileFields, nodeFromConstraints(constraints)).get(); -//// -//// Assert.assertThat("Output is not null", testOutput, Is.is(IsNull.notNullValue())); -//// FieldSpec outputSpec = testOutput.getSpecForField(field); -//// Assert.assertThat("Fieldspec is not null", outputSpec, Is.is(IsNull.notNullValue())); -//// Assert.assertThat("Fieldspec has no set restrictions", outputSpec.getWhitelist(), -//// Is.is(IsNull.nullValue())); -//// Assert.assertThat("Fieldspec has no null restrictions", outputSpec.isNullable(), -//// Is.is(true)); -//// Assert.assertThat("Fieldspec has datetime restrictions", outputSpec.getRestrictions(), -//// Is.is(IsNull.notNullValue())); -//// Assert.assertThat("Fieldspec datetime restrictions have no upper bound", -//// ((LinearRestrictions) outputSpec.getRestrictions()).getMax(), Is.is(equalTo(ISO_MAX_DATE))); -//// Assert.assertThat("Fieldspec datetime restrictions have lower bound", -//// ((LinearRestrictions) outputSpec.getRestrictions()).getMin(), Is.is(not(equalTo(ISO_MIN_DATE)))); -//// Assert.assertThat("Fieldspec datetime restrictions have correct lower bound limit", -//// ((LinearRestrictions) outputSpec.getRestrictions()).getMin(), Is.is(testTimestamp)); -//// } -//// -//// @Test -//// void shouldreduceNegatedIsAfterConstantDateTimeConstraint() { -//// final Field field = createField("test0", DATETIME); -//// final OffsetDateTime testTimestamp = OffsetDateTime.of(2018, 2, 4, 23, 25, 16,0, ZoneOffset.UTC); -//// ProfileFields profileFields = new ProfileFields(Collections.singletonList(field)); -//// Set constraints = Collections.singleton( -//// new IsAfterConstantDateTimeConstraint(field, testTimestamp).negate()); -//// -//// RowSpec testOutput = constraintReducer.reduceConstraintsToRowSpec(profileFields, nodeFromConstraints(constraints)).get(); -//// -//// Assert.assertThat("Output is not null", testOutput, Is.is(IsNull.notNullValue())); -//// FieldSpec outputSpec = testOutput.getSpecForField(field); -//// Assert.assertThat("Fieldspec is not null", outputSpec, Is.is(IsNull.notNullValue())); -//// Assert.assertThat("Fieldspec has no set restrictions", outputSpec.getWhitelist(), -//// Is.is(IsNull.nullValue())); -//// Assert.assertThat("Fieldspec has no null restrictions", outputSpec.isNullable(), -//// Is.is(true)); -//// Assert.assertThat("Fieldspec has datetime restrictions", outputSpec.getRestrictions(), -//// Is.is(IsNull.notNullValue())); -//// Assert.assertThat("Fieldspec datetime restrictions have no lower bound", -//// ((LinearRestrictions) outputSpec.getRestrictions()).getMin(), Is.is(equalTo(ISO_MIN_DATE))); -//// Assert.assertThat("Fieldspec datetime restrictions have upper bound", -//// ((LinearRestrictions) outputSpec.getRestrictions()).getMax(), Is.is(not(equalTo(ISO_MAX_DATE)))); -//// Assert.assertThat("Fieldspec datetime restrictions have correct upper bound limit", -//// ((LinearRestrictions) outputSpec.getRestrictions()).getMax(), Is.is(testTimestamp)); -//// } -//// -//// @Test -//// void shouldreduceIsAfterOrEqualToConstantDateTimeConstraint() { -//// final Field field = createField("test0", DATETIME); -//// final OffsetDateTime testTimestamp = OffsetDateTime.of(2018, 2, 4, 23, 25, 16, 0, ZoneOffset.UTC); -//// ProfileFields profileFields = new ProfileFields(Collections.singletonList(field)); -//// Set constraints = Collections.singleton( -//// new IsAfterOrEqualToConstantDateTimeConstraint(field, testTimestamp)); -//// -//// RowSpec testOutput = constraintReducer.reduceConstraintsToRowSpec(profileFields, nodeFromConstraints(constraints)).get(); -//// -//// Assert.assertThat("Output is not null", testOutput, Is.is(IsNull.notNullValue())); -//// FieldSpec outputSpec = testOutput.getSpecForField(field); -//// Assert.assertThat("Fieldspec is not null", outputSpec, Is.is(IsNull.notNullValue())); -//// Assert.assertThat("Fieldspec has no set restrictions", outputSpec.getWhitelist(), -//// Is.is(IsNull.nullValue())); -//// Assert.assertThat("Fieldspec has no null restrictions", outputSpec.isNullable(), -//// Is.is(true)); -//// Assert.assertThat("Fieldspec has datetime restrictions", outputSpec.getRestrictions(), -//// Is.is(IsNull.notNullValue())); -//// Assert.assertThat("Fieldspec datetime restrictions have no upper bound", -//// ((LinearRestrictions) outputSpec.getRestrictions()).getMax(), Is.is(equalTo(ISO_MAX_DATE))); -//// Assert.assertThat("Fieldspec datetime restrictions have lower bound", -//// ((LinearRestrictions) outputSpec.getRestrictions()).getMin(), Is.is(not(equalTo(ISO_MAX_DATE)))); -//// Assert.assertThat("Fieldspec datetime restrictions have correct lower bound limit", -//// ((LinearRestrictions) outputSpec.getRestrictions()).getMin(), Is.is(testTimestamp)); -//// } -//// -//// @Test -//// void shouldreduceNegatedIsAfterOrEqualToConstantDateTimeConstraint() { -//// final Field field = createField("test0", DATETIME); -//// final OffsetDateTime testTimestamp = OffsetDateTime.of(2018, 2, 4, 23, 25, 16, 0, ZoneOffset.UTC); -//// ProfileFields profileFields = new ProfileFields(Collections.singletonList(field)); -//// Set constraints = Collections.singleton( -//// new IsAfterConstantDateTimeConstraint(field, testTimestamp).negate()); -//// -//// RowSpec testOutput = constraintReducer.reduceConstraintsToRowSpec(profileFields, nodeFromConstraints(constraints)).get(); -//// -//// Assert.assertThat("Output is not null", testOutput, Is.is(IsNull.notNullValue())); -//// FieldSpec outputSpec = testOutput.getSpecForField(field); -//// Assert.assertThat("Fieldspec is not null", outputSpec, Is.is(IsNull.notNullValue())); -//// Assert.assertThat("Fieldspec has no set restrictions", outputSpec.getWhitelist(), -//// Is.is(IsNull.nullValue())); -//// Assert.assertThat("Fieldspec has no null restrictions", outputSpec.isNullable(), -//// Is.is(true)); -//// Assert.assertThat("Fieldspec has datetime restrictions", outputSpec.getRestrictions(), -//// Is.is(IsNull.notNullValue())); -//// Assert.assertThat("Fieldspec datetime restrictions have no lower bound", -//// ((LinearRestrictions) outputSpec.getRestrictions()).getMin(), Is.is(equalTo(ISO_MIN_DATE))); -//// Assert.assertThat("Fieldspec datetime restrictions have upper bound", -//// ((LinearRestrictions) outputSpec.getRestrictions()).getMax(), Is.is(not(equalTo(ISO_MAX_DATE)))); -//// Assert.assertThat("Fieldspec datetime restrictions have correct upper bound limit", -//// ((LinearRestrictions) outputSpec.getRestrictions()).getMax(), Is.is(testTimestamp)); -//// } -//// -//// @Test -//// void shouldreduceIsBeforeConstantDateTimeConstraint() { -//// final Field field = createField("test0", DATETIME); -//// final OffsetDateTime testTimestamp = OffsetDateTime.of(2018, 2, 4, 23, 25, 16, 0, ZoneOffset.UTC); -//// ProfileFields profileFields = new ProfileFields(Collections.singletonList(field)); -//// Set constraints = Collections.singleton( -//// new IsBeforeOrEqualToConstantDateTimeConstraint(field, testTimestamp)); -//// -//// RowSpec testOutput = constraintReducer.reduceConstraintsToRowSpec(profileFields, nodeFromConstraints(constraints)).get(); -//// -//// Assert.assertThat("Output is not null", testOutput, Is.is(IsNull.notNullValue())); -//// FieldSpec outputSpec = testOutput.getSpecForField(field); -//// Assert.assertThat("Fieldspec is not null", outputSpec, Is.is(IsNull.notNullValue())); -//// Assert.assertThat("Fieldspec has no set restrictions", outputSpec.getWhitelist(), -//// Is.is(IsNull.nullValue())); -//// Assert.assertThat("Fieldspec has no null restrictions", outputSpec.isNullable(), -//// Is.is(true)); -//// Assert.assertThat("Fieldspec has datetime restrictions", outputSpec.getRestrictions(), -//// Is.is(IsNull.notNullValue())); -//// Assert.assertThat("Fieldspec datetime restrictions have no lower bound", -//// ((LinearRestrictions) outputSpec.getRestrictions()).getMin(), Is.is(equalTo(ISO_MIN_DATE))); -//// Assert.assertThat("Fieldspec datetime restrictions have upper bound", -//// ((LinearRestrictions) outputSpec.getRestrictions()).getMax(), Is.is(not(equalTo(ISO_MAX_DATE)))); -//// Assert.assertThat("Fieldspec datetime restrictions have correct upper bound limit", -//// ((LinearRestrictions) outputSpec.getRestrictions()).getMax(), Is.is(testTimestamp)); -//// } -//// -//// @Test -//// void shouldreduceNegatedIsBeforeConstantDateTimeConstraint() { -//// final Field field = createField("test0", DATETIME); -//// final OffsetDateTime testTimestamp = OffsetDateTime.of(2018, 2, 4, 23, 25, 16, 0, ZoneOffset.UTC); -//// ProfileFields profileFields = new ProfileFields(Collections.singletonList(field)); -//// Set constraints = Collections.singleton( -//// new IsBeforeConstantDateTimeConstraint(field, testTimestamp).negate()); -//// -//// RowSpec testOutput = constraintReducer.reduceConstraintsToRowSpec(profileFields, nodeFromConstraints(constraints)).get(); -//// -//// Assert.assertThat("Output is not null", testOutput, Is.is(IsNull.notNullValue())); -//// FieldSpec outputSpec = testOutput.getSpecForField(field); -//// Assert.assertThat("Fieldspec is not null", outputSpec, Is.is(IsNull.notNullValue())); -//// Assert.assertThat("Fieldspec has no set restrictions", outputSpec.getWhitelist(), -//// Is.is(IsNull.nullValue())); -//// Assert.assertThat("Fieldspec has no null restrictions", outputSpec.isNullable(), -//// Is.is(true)); -//// Assert.assertThat("Fieldspec has datetime restrictions", outputSpec.getRestrictions(), -//// Is.is(IsNull.notNullValue())); -//// Assert.assertThat("Fieldspec datetime restrictions have no upper bound", -//// ((LinearRestrictions) outputSpec.getRestrictions()).getMax(), Is.is(equalTo(ISO_MAX_DATE))); -//// Assert.assertThat("Fieldspec datetime restrictions have lower bound", -//// ((LinearRestrictions) outputSpec.getRestrictions()).getMin(), Is.is(not(equalTo(ISO_MIN_DATE)))); -//// Assert.assertThat("Fieldspec datetime restrictions have correct lower bound limit", -//// ((LinearRestrictions) outputSpec.getRestrictions()).getMin(), Is.is(testTimestamp)); -//// } -//// -//// @Test -//// void shouldreduceIsBeforeOrEqualToConstantDateTimeConstraint() { -//// final Field field = createField("test0", DATETIME); -//// final OffsetDateTime testTimestamp = OffsetDateTime.of(2018, 2, 4, 23, 25, 16, 0, ZoneOffset.UTC); -//// ProfileFields profileFields = new ProfileFields(Collections.singletonList(field)); -//// Set constraints = Collections.singleton( -//// new IsBeforeOrEqualToConstantDateTimeConstraint(field, testTimestamp)); -//// -//// RowSpec testOutput = constraintReducer.reduceConstraintsToRowSpec(profileFields, nodeFromConstraints(constraints)).get(); -//// -//// Assert.assertThat("Output is not null", testOutput, Is.is(IsNull.notNullValue())); -//// FieldSpec outputSpec = testOutput.getSpecForField(field); -//// Assert.assertThat("Fieldspec is not null", outputSpec, Is.is(IsNull.notNullValue())); -//// Assert.assertThat("Fieldspec has no set restrictions", outputSpec.getWhitelist(), -//// Is.is(IsNull.nullValue())); -//// Assert.assertThat("Fieldspec has no null restrictions", outputSpec.isNullable(), -//// Is.is(true)); -//// Assert.assertThat("Fieldspec has datetime restrictions", outputSpec.getRestrictions(), -//// Is.is(IsNull.notNullValue())); -//// Assert.assertThat("Fieldspec datetime restrictions have no lower bound", -//// ((LinearRestrictions) outputSpec.getRestrictions()).getMin(), Is.is((equalTo(ISO_MIN_DATE)))); -//// Assert.assertThat("Fieldspec datetime restrictions have upper bound", -//// ((LinearRestrictions) outputSpec.getRestrictions()).getMax(), Is.is(not(equalTo(ISO_MAX_DATE)))); -//// Assert.assertThat("Fieldspec datetime restrictions have correct upper bound limit", -//// ((LinearRestrictions) outputSpec.getRestrictions()).getMax(), Is.is(testTimestamp)); -//// } -//// -//// @Test -//// void shouldreduceNegatedIsBeforeorEqualToConstantDateTimeConstraint() { -//// final Field field = createField("test0", DATETIME); -//// final OffsetDateTime testTimestamp = OffsetDateTime.of(2018, 2, 4, 23, 25, 16, 0, ZoneOffset.UTC); -//// ProfileFields profileFields = new ProfileFields(Collections.singletonList(field)); -//// Set constraints = Collections.singleton( -//// new IsBeforeConstantDateTimeConstraint(field, testTimestamp).negate()); -//// -//// RowSpec testOutput = constraintReducer.reduceConstraintsToRowSpec(profileFields, nodeFromConstraints(constraints)).get(); -//// -//// Assert.assertThat("Output is not null", testOutput, Is.is(IsNull.notNullValue())); -//// FieldSpec outputSpec = testOutput.getSpecForField(field); -//// Assert.assertThat("Fieldspec is not null", outputSpec, Is.is(IsNull.notNullValue())); -//// Assert.assertThat("Fieldspec has no set restrictions", outputSpec.getWhitelist(), -//// Is.is(IsNull.nullValue())); -//// Assert.assertThat("Fieldspec has no null restrictions", outputSpec.isNullable(), -//// Is.is(true)); -//// Assert.assertThat("Fieldspec has datetime restrictions", outputSpec.getRestrictions(), -//// Is.is(IsNull.notNullValue())); -//// Assert.assertThat("Fieldspec datetime restrictions have no upper bound", -//// ((LinearRestrictions) outputSpec.getRestrictions()).getMax(), Is.is(equalTo(ISO_MAX_DATE))); -//// Assert.assertThat("Fieldspec datetime restrictions have lower bound", -//// ((LinearRestrictions) outputSpec.getRestrictions()).getMin(), Is.is(not(equalTo(ISO_MIN_DATE)))); -//// Assert.assertThat("Fieldspec datetime restrictions have correct lower bound limit", -//// ((LinearRestrictions) outputSpec.getRestrictions()).getMin(), Is.is(testTimestamp)); -//// } -//// -//// @Test -//// void shouldMergeAndReduceIsAfterConstantDateTimeConstraintWithIsBeforeConstantDateTimeConstraint() { -//// final Field field = createField("test0", DATETIME); -//// final OffsetDateTime startTimestamp = OffsetDateTime.of(2013, 11, 19, 10, 43, 12, 0, ZoneOffset.UTC); -//// final OffsetDateTime endTimestamp = OffsetDateTime.of(2018, 2, 4, 23, 25, 8, 0, ZoneOffset.UTC); -//// ProfileFields profileFields = new ProfileFields(Collections.singletonList(field)); -//// Set constraints = SetUtils.setOf( -//// new IsAfterOrEqualToConstantDateTimeConstraint(field, startTimestamp), -//// new IsBeforeOrEqualToConstantDateTimeConstraint(field, endTimestamp)); -//// -//// RowSpec testOutput = constraintReducer.reduceConstraintsToRowSpec(profileFields, nodeFromConstraints(constraints)).get(); -//// -//// Assert.assertThat("Output is not null", testOutput, Is.is(IsNull.notNullValue())); -//// FieldSpec outputSpec = testOutput.getSpecForField(field); -//// Assert.assertThat("Fieldspec is not null", outputSpec, Is.is(IsNull.notNullValue())); -//// Assert.assertThat("Fieldspec has no set restrictions", outputSpec.getWhitelist(), -//// Is.is(IsNull.nullValue())); -//// Assert.assertThat("Fieldspec has no null restrictions", outputSpec.isNullable(), -//// Is.is(true)); -//// Assert.assertThat("Fieldspec has datetime restrictions", outputSpec.getRestrictions(), -//// Is.is(IsNull.notNullValue())); -//// Assert.assertThat("Fieldspec datetime restrictions have lower bound", -//// ((LinearRestrictions) outputSpec.getRestrictions()).getMin(), Is.is(IsNull.notNullValue())); -//// Assert.assertThat("Fieldspec datetime restrictions have correct lower bound limit", -//// ((LinearRestrictions) outputSpec.getRestrictions()).getMin(), Is.is(startTimestamp)); -//// Assert.assertThat("Fieldspec datetime restrictions have upper bound", -//// ((LinearRestrictions) outputSpec.getRestrictions()).getMax(), Is.is(IsNull.notNullValue())); -//// Assert.assertThat("Fieldspec datetime restrictions have correct upper bound limit", -//// ((LinearRestrictions) outputSpec.getRestrictions()).getMax(), Is.is(endTimestamp)); -//// } -//// -//// @Test -//// void shouldReduceMatchesRegexConstraint() { -//// final Field field = createField("test0"); -//// String pattern = ".*\\..*"; -//// ProfileFields profileFields = new ProfileFields(Collections.singletonList(field)); -//// Set constraints = Collections.singleton( -//// new MatchesRegexConstraint(field, Pattern.compile(pattern))); -//// -//// RowSpec testOutput = constraintReducer.reduceConstraintsToRowSpec(profileFields, nodeFromConstraints(constraints)).get(); -//// -//// Assert.assertThat("Output is not null", testOutput, Is.is(IsNull.notNullValue())); -//// FieldSpec outputSpec = testOutput.getSpecForField(field); -//// Assert.assertThat("Fieldspec is not null", outputSpec, Is.is(IsNull.notNullValue())); -//// Assert.assertThat("Fieldspec has no set restrictions", outputSpec.getWhitelist(), -//// Is.is(IsNull.nullValue())); -//// Assert.assertThat("Fieldspec has no null restrictions", outputSpec.isNullable(), -//// Is.is(true)); -//// Assert.assertThat("Fieldspec has string restrictions", outputSpec.getRestrictions(), -//// Is.is(IsNull.notNullValue())); -//// } -//// -//// @Test -//// void shouldReduceStringLongerThanConstraint() { -//// final Field field = createField("test0"); -//// -//// ProfileFields profileFields = new ProfileFields(Collections.singletonList(field)); -//// Set constraints = Collections.singleton( -//// new IsStringLongerThanConstraint(field, 5) -//// ); -//// -//// RowSpec testOutput = constraintReducer.reduceConstraintsToRowSpec(profileFields, nodeFromConstraints(constraints)).get(); -//// -//// Assert.assertThat("Output is not null", testOutput, Is.is(IsNull.notNullValue())); -//// FieldSpec outputSpec = testOutput.getSpecForField(field); -//// Assert.assertThat("Fieldspec is not null", outputSpec, Is.is(IsNull.notNullValue())); -//// Assert.assertThat("Fieldspec has no set restrictions", outputSpec.getWhitelist(), -//// Is.is(IsNull.nullValue())); -//// Assert.assertThat("Fieldspec has no null restrictions", outputSpec.isNullable(), -//// Is.is(true)); -//// Assert.assertThat("Fieldspec has string restrictions", outputSpec.getRestrictions(), -//// Is.is(IsNull.notNullValue())); -//// } -//// -//// @Test -//// void shouldReduceStringShorterThanConstraint() { -//// final Field field = createField("test0"); -//// -//// ProfileFields profileFields = new ProfileFields(Collections.singletonList(field)); -//// Set constraints = Collections.singleton( -//// new IsStringShorterThanConstraint(field, 5) -//// ); -//// -//// RowSpec testOutput = constraintReducer.reduceConstraintsToRowSpec(profileFields, nodeFromConstraints(constraints)).get(); -//// -//// Assert.assertThat("Output is not null", testOutput, Is.is(IsNull.notNullValue())); -//// FieldSpec outputSpec = testOutput.getSpecForField(field); -//// Assert.assertThat("Fieldspec is not null", outputSpec, Is.is(IsNull.notNullValue())); -//// Assert.assertThat("Fieldspec has no set restrictions", outputSpec.getWhitelist(), -//// Is.is(IsNull.nullValue())); -//// Assert.assertThat("Fieldspec has no null restrictions", outputSpec.isNullable(), -//// Is.is(true)); -//// Assert.assertThat("Fieldspec has string restrictions", outputSpec.getRestrictions(), -//// Is.is(IsNull.notNullValue())); -//// } -//// -//// @Test -//// void shouldReduceStringHasLengthConstraint() { -//// final Field field = createField("test0"); -//// -//// ProfileFields profileFields = new ProfileFields(Collections.singletonList(field)); -//// Set constraints = Collections.singleton( -//// new StringHasLengthConstraint(field, 5) -//// ); -//// -//// RowSpec testOutput = constraintReducer.reduceConstraintsToRowSpec(profileFields, nodeFromConstraints(constraints)).get(); -//// -//// Assert.assertThat("Output is not null", testOutput, Is.is(IsNull.notNullValue())); -//// FieldSpec outputSpec = testOutput.getSpecForField(field); -//// Assert.assertThat("Fieldspec has no set restrictions", outputSpec.getWhitelist(), -//// Is.is(IsNull.nullValue())); -//// Assert.assertThat("Fieldspec has no null restrictions", outputSpec.isNullable(), -//// Is.is(true)); -//// Assert.assertThat("Fieldspec has string restrictions", outputSpec.getRestrictions(), -//// Is.is(IsNull.notNullValue())); -//// } -////} -// -//package com.scottlogic.deg.generator.reducer; -// -//import com.scottlogic.deg.common.profile.*; -//import com.scottlogic.deg.generator.decisiontree.ConstraintNode; -//import com.scottlogic.deg.generator.decisiontree.ConstraintNodeBuilder; -//import com.scottlogic.deg.generator.fieldspecs.FieldSpec; -//import com.scottlogic.deg.generator.fieldspecs.FieldSpecMerger; -//import com.scottlogic.deg.generator.fieldspecs.RowSpec; -//import com.scottlogic.deg.generator.fieldspecs.whitelist.DistributedList; -//import com.scottlogic.deg.generator.fieldspecs.whitelist.WeightedElement; -//import com.scottlogic.deg.generator.profile.constraints.atomic.*; -//import com.scottlogic.deg.generator.restrictions.linear.LinearRestrictions; -//import com.scottlogic.deg.generator.utils.SetUtils; -//import org.hamcrest.core.Is; -//import org.hamcrest.core.IsNull; -//import org.junit.Assert; -//import org.junit.jupiter.api.Test; -// -//import java.math.BigDecimal; -//import java.time.OffsetDateTime; -//import java.time.ZoneOffset; -//import java.util.Arrays; -//import java.util.Collections; -//import java.util.Set; -//import java.util.regex.Pattern; -//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.*; -//import static com.scottlogic.deg.common.util.Defaults.*; -//import static org.hamcrest.Matchers.*; -// -//class ConstraintReducerTest { -// -// private final ConstraintReducer constraintReducer = new ConstraintReducer( -// new FieldSpecMerger() -// ); -// -// private static ConstraintNode nodeFromConstraints(Set constraints) { -// return new ConstraintNodeBuilder().addAtomicConstraints(constraints).build(); -// } -// -// @Test -// void shouldProduceCorrectFieldSpecsForExample() { -// // ARRANGE -// final Field quantityField = createField("quantity", NUMERIC); -// final Field countryField = createField("country"); -// final Field cityField = createField("city"); -// -// ProfileFields fieldList = new ProfileFields( -// Arrays.asList(quantityField, countryField, cityField)); -// -// final DistributedList countryAmong = new DistributedList<>(Stream.of("UK", "US") -// .map(string -> new WeightedElement<>((Object) string, 1.0F)) -// .collect(Collectors.toList())); -// -// final Set constraints = SetUtils.setOf( -// new IsGreaterThanOrEqualToConstantConstraint(quantityField, NumberUtils.coerceToBigDecimal(0)), -// new IsGreaterThanConstantConstraint(quantityField, NumberUtils.coerceToBigDecimal(5)).negate(), -// new IsInSetConstraint(countryField, countryAmong)); -// -// // ACT -// final RowSpec reducedConstraints = constraintReducer.reduceConstraintsToRowSpec( -// fieldList, -// nodeFromConstraints(constraints)).get(); -// -// // ASSERT -// FieldSpec quantityFieldSpec = reducedConstraints.getSpecForField(quantityField); -// Assert.assertThat("Quantity fieldspec has no set restrictions", quantityFieldSpec.getWhitelist(), -// Is.is(IsNull.nullValue())); -// Assert.assertThat("Quantity fieldspec has no null restrictions", quantityFieldSpec.isNullable(), -// Is.is(true)); -// Assert.assertThat("Quantity fieldspec has numeric restrictions", quantityFieldSpec.getRestrictions(), -// Is.is(IsNull.notNullValue())); -// Assert.assertThat("Quantity fieldspec has correct lower bound limit", -// ((LinearRestrictions) quantityFieldSpec.getRestrictions()).getMin(), Is.is(BigDecimal.ZERO)); -// Assert.assertThat("Quantity fieldspec has correct upper bound limit", -// ((LinearRestrictions) quantityFieldSpec.getRestrictions()).getMax(), Is.is(BigDecimal.valueOf(5))); -// -// FieldSpec countryFieldSpec = reducedConstraints.getSpecForField(countryField); -// Assert.assertThat("Country fieldspec has no null restrictions", countryFieldSpec.isNullable(), -// Is.is(true)); -// Assert.assertThat("Country fieldspec set restrictions have whitelist", -// countryFieldSpec.getWhitelist().list(), notNullValue()); -// Assert.assertThat("Country fieldspec set restrictions whitelist has correct size", -// countryFieldSpec.getWhitelist().list().size(), Is.is(2)); -// Assert.assertThat("Country fieldspec set restrictions whitelist contains 'UK'", -// countryFieldSpec.getWhitelist().list().contains("UK"), Is.is(true)); -// Assert.assertThat("Country fieldspec set restrictions whitelist contains 'US'", -// countryFieldSpec.getWhitelist().list().contains("US"), Is.is(true)); -// -// FieldSpec cityFieldSpec = reducedConstraints.getSpecForField(cityField); -// Assert.assertThat("City fieldspec has no set restrictions", cityFieldSpec.getWhitelist(), -// Is.is(IsNull.nullValue())); -// Assert.assertThat("City fieldspec has the default string restrictions", cityFieldSpec.getRestrictions(), -// Is.is(FieldSpec.fromType(STRING).getRestrictions())); -// Assert.assertThat("City fieldspec has no null restrictions", cityFieldSpec.isNullable(), -// Is.is(true)); -// } -// -// @Test -// void shouldReduceIsGreaterThanConstantConstraint() { -// final Field field = createField("test0", NUMERIC); -// ProfileFields profileFields = new ProfileFields(Collections.singletonList(field)); -// Set constraints = Collections.singleton( -// new IsGreaterThanOrEqualToConstantConstraint(field, NumberUtils.coerceToBigDecimal(5))); -// -// RowSpec testOutput = constraintReducer.reduceConstraintsToRowSpec(profileFields, nodeFromConstraints(constraints)).get(); -// -// Assert.assertThat("Output is not null", testOutput, Is.is(IsNull.notNullValue())); -// FieldSpec outputSpec = testOutput.getSpecForField(field); -// Assert.assertThat("Fieldspec is not null", outputSpec, Is.is(IsNull.notNullValue())); -// Assert.assertThat("Fieldspec has no set restrictions", outputSpec.getWhitelist(), -// Is.is(IsNull.nullValue())); -// Assert.assertThat("Fieldspec has no null restrictions", outputSpec.isNullable(), -// Is.is(true)); -// Assert.assertThat("Fieldspec has numeric restrictions", outputSpec.getRestrictions(), -// Is.is(IsNull.notNullValue())); -// Assert.assertThat("Fieldspec numeric restrictions have no upper bound", -// ((LinearRestrictions) outputSpec.getRestrictions()).getMax(), -// Is.is(equalTo(NUMERIC_MAX))); -// Assert.assertThat("Fieldspec numeric restrictions have lower bound", -// ((LinearRestrictions) outputSpec.getRestrictions()).getMin(), -// Is.is(not(equalTo(NUMERIC_MIN)))); -// Assert.assertThat("Fieldspec numeric restriction lower bound is correct", -// ((LinearRestrictions) outputSpec.getRestrictions()).getMin(), Is.is(BigDecimal.valueOf(5))); -// } -// -// @Test -// void shouldReduceNegatedIsGreaterThanConstantConstraint() { -// final Field field = createField("test0", NUMERIC); -// ProfileFields profileFields = new ProfileFields(Collections.singletonList(field)); -// Set constraints = Collections.singleton( -// new IsGreaterThanConstantConstraint(field, NumberUtils.coerceToBigDecimal(5)).negate()); -// -// RowSpec testOutput = constraintReducer.reduceConstraintsToRowSpec(profileFields, nodeFromConstraints(constraints)).get(); -// -// Assert.assertThat("Output is not null", testOutput, Is.is(IsNull.notNullValue())); -// FieldSpec outputSpec = testOutput.getSpecForField(field); -// Assert.assertThat("Fieldspec is not null", outputSpec, Is.is(IsNull.notNullValue())); -// Assert.assertThat("Fieldspec has no set restrictions", outputSpec.getWhitelist(), -// Is.is(IsNull.nullValue())); -// Assert.assertThat("Fieldspec has no null restrictions", outputSpec.isNullable(), -// Is.is(true)); -// Assert.assertThat("Fieldspec has numeric restrictions", outputSpec.getRestrictions(), -// Is.is(IsNull.notNullValue())); -// Assert.assertThat("Fieldspec numeric restrictions have no lower bound", -// ((LinearRestrictions) outputSpec.getRestrictions()).getMin(), Is.is(equalTo(NUMERIC_MIN))); -// Assert.assertThat("Fieldspec numeric restrictions have upper bound", -// ((LinearRestrictions) outputSpec.getRestrictions()).getMax(), Is.is(not(equalTo(NUMERIC_MAX)))); -// Assert.assertThat("Fieldspec numeric restrictions upper bound limit is correct", -// ((LinearRestrictions) outputSpec.getRestrictions()).getMax(), Is.is(BigDecimal.valueOf(5))); -// } -// -// @Test -// void shouldReduceIsGreaterThanOrEqualToConstantConstraint() { -// final Field field = createField("test0", NUMERIC); -// ProfileFields profileFields = new ProfileFields(Collections.singletonList(field)); -// Set constraints = Collections.singleton( -// new IsGreaterThanOrEqualToConstantConstraint(field, NumberUtils.coerceToBigDecimal(5))); -// -// RowSpec testOutput = constraintReducer.reduceConstraintsToRowSpec(profileFields, nodeFromConstraints(constraints)).get(); -// -// Assert.assertThat("Output is not null", testOutput, Is.is(IsNull.notNullValue())); -// FieldSpec outputSpec = testOutput.getSpecForField(field); -// Assert.assertThat("Fieldspec is not null", outputSpec, Is.is(IsNull.notNullValue())); -// Assert.assertThat("Fieldspec has no set restrictions", outputSpec.getWhitelist(), -// Is.is(IsNull.nullValue())); -// Assert.assertThat("Fieldspec has no null restrictions", outputSpec.isNullable(), -// Is.is(true)); -// Assert.assertThat("Fieldspec has numeric restrictions", outputSpec.getRestrictions(), -// Is.is(IsNull.notNullValue())); -// Assert.assertThat("Fieldspec numeric restrictions have no upper bound", -// ((LinearRestrictions) outputSpec.getRestrictions()).getMax(), -// Is.is(NUMERIC_MAX)); -// Assert.assertThat("Fieldspec numeric restrictions have lower bound", -// ((LinearRestrictions) outputSpec.getRestrictions()).getMin(), -// Is.is(not(NUMERIC_MIN))); -// Assert.assertThat("Fieldspec numeric restriction lower bound is correct", -// ((LinearRestrictions) outputSpec.getRestrictions()).getMin(), Is.is(BigDecimal.valueOf(5))); -// } -// -// @Test -// void shouldReduceNegatedIsGreaterThanOrEqualToConstantConstraint() { -// final Field field = createField("test0", NUMERIC); -// ProfileFields profileFields = new ProfileFields(Collections.singletonList(field)); -// Set constraints = Collections.singleton( -// new IsGreaterThanConstantConstraint(field, NumberUtils.coerceToBigDecimal(5)).negate()); -// -// RowSpec testOutput = constraintReducer.reduceConstraintsToRowSpec(profileFields, nodeFromConstraints(constraints)).get(); -// -// Assert.assertThat("Output is not null", testOutput, Is.is(IsNull.notNullValue())); -// FieldSpec outputSpec = testOutput.getSpecForField(field); -// Assert.assertThat("Fieldspec is not null", outputSpec, Is.is(IsNull.notNullValue())); -// Assert.assertThat("Fieldspec has no set restrictions", outputSpec.getWhitelist(), -// Is.is(IsNull.nullValue())); -// Assert.assertThat("Fieldspec has no null restrictions", outputSpec.isNullable(), -// Is.is(true)); -// Assert.assertThat("Fieldspec has numeric restrictions", outputSpec.getRestrictions(), -// Is.is(IsNull.notNullValue())); -// Assert.assertThat("Fieldspec numeric restrictions have no lower bound", -// ((LinearRestrictions) outputSpec.getRestrictions()).getMin(), Is.is(NUMERIC_MIN)); -// Assert.assertThat("Fieldspec numeric restrictions have upper bound", -// ((LinearRestrictions) outputSpec.getRestrictions()).getMax(), Is.is(not(NUMERIC_MAX))); -// Assert.assertThat("Fieldspec numeric restrictions upper bound limit is correct", -// ((LinearRestrictions) outputSpec.getRestrictions()).getMax(), Is.is(BigDecimal.valueOf(5))); -// } -// -// @Test -// void shouldReduceIsLessThanConstantConstraint() { -// final Field field = createField("test0", NUMERIC); -// ProfileFields profileFields = new ProfileFields(Collections.singletonList(field)); -// Set constraints = Collections.singleton( -// new IsLessThanOrEqualToConstantConstraint(field, NumberUtils.coerceToBigDecimal(5))); -// -// RowSpec testOutput = constraintReducer.reduceConstraintsToRowSpec(profileFields, nodeFromConstraints(constraints)).get(); -// -// Assert.assertThat("Output is not null", testOutput, Is.is(IsNull.notNullValue())); -// FieldSpec outputSpec = testOutput.getSpecForField(field); -// Assert.assertThat("Fieldspec is not null", outputSpec, Is.is(IsNull.notNullValue())); -// Assert.assertThat("Fieldspec has no set restrictions", outputSpec.getWhitelist(), -// Is.is(IsNull.nullValue())); -// Assert.assertThat("Fieldspec has no null restrictions", outputSpec.isNullable(), -// Is.is(true)); -// Assert.assertThat("Fieldspec has numeric restrictions", outputSpec.getRestrictions(), -// Is.is(IsNull.notNullValue())); -// Assert.assertThat("Fieldspec numeric restrictions have no lower bound", -// ((LinearRestrictions) outputSpec.getRestrictions()).getMin(), Is.is(NUMERIC_MIN)); -// Assert.assertThat("Fieldspec numeric restrictions have upper bound", -// ((LinearRestrictions) outputSpec.getRestrictions()).getMax(), Is.is(not(NUMERIC_MAX))); -// Assert.assertThat("Fieldspec numeric restrictions upper bound limit is correct", -// ((LinearRestrictions) outputSpec.getRestrictions()).getMax(), Is.is(BigDecimal.valueOf(5))); -// } -// -// @Test -// void shouldReduceNegatedIsLessThanConstantConstraint() { -// final Field field = createField("test0", NUMERIC); -// ProfileFields profileFields = new ProfileFields(Collections.singletonList(field)); -// Set constraints = Collections.singleton( -// new IsLessThanConstantConstraint(field, NumberUtils.coerceToBigDecimal(5)).negate()); -// -// RowSpec testOutput = constraintReducer.reduceConstraintsToRowSpec(profileFields, nodeFromConstraints(constraints)).get(); -// -// Assert.assertThat("Output is not null", testOutput, Is.is(IsNull.notNullValue())); -// FieldSpec outputSpec = testOutput.getSpecForField(field); -// Assert.assertThat("Fieldspec is not null", outputSpec, Is.is(IsNull.notNullValue())); -// Assert.assertThat("Fieldspec has no set restrictions", outputSpec.getWhitelist(), -// Is.is(IsNull.nullValue())); -// Assert.assertThat("Fieldspec has no null restrictions", outputSpec.isNullable(), -// Is.is(true)); -// Assert.assertThat("Fieldspec has numeric restrictions", outputSpec.getRestrictions(), -// Is.is(IsNull.notNullValue())); -// Assert.assertThat("Fieldspec numeric restrictions have no upper bound", -// ((LinearRestrictions) outputSpec.getRestrictions()).getMax(), Is.is(NUMERIC_MAX)); -// Assert.assertThat("Fieldspec numeric restrictions have lower bound", -// ((LinearRestrictions) outputSpec.getRestrictions()).getMin(), Is.is(not(NUMERIC_MIN))); -// Assert.assertThat("Fieldspec numeric restriction lower bound is correct", -// ((LinearRestrictions) outputSpec.getRestrictions()).getMin(), Is.is(BigDecimal.valueOf(5))); -// } -// -// @Test -// void shouldReduceIsLessThanOrEqualToConstantConstraint() { -// final Field field = createField("test0", NUMERIC); -// ProfileFields profileFields = new ProfileFields(Collections.singletonList(field)); -// Set constraints = Collections.singleton( -// new IsLessThanOrEqualToConstantConstraint(field, NumberUtils.coerceToBigDecimal(5))); -// -// RowSpec testOutput = constraintReducer.reduceConstraintsToRowSpec(profileFields, nodeFromConstraints(constraints)).get(); -// -// Assert.assertThat("Output is not null", testOutput, Is.is(IsNull.notNullValue())); -// FieldSpec outputSpec = testOutput.getSpecForField(field); -// Assert.assertThat("Fieldspec is not null", outputSpec, Is.is(IsNull.notNullValue())); -// Assert.assertThat("Fieldspec has no set restrictions", outputSpec.getWhitelist(), -// Is.is(IsNull.nullValue())); -// Assert.assertThat("Fieldspec has no null restrictions", outputSpec.isNullable(), -// Is.is(true)); -// Assert.assertThat("Fieldspec has numeric restrictions", outputSpec.getRestrictions(), -// Is.is(IsNull.notNullValue())); -// Assert.assertThat("Fieldspec numeric restrictions have no lower bound", -// ((LinearRestrictions) outputSpec.getRestrictions()).getMin(), Is.is(NUMERIC_MIN)); -// Assert.assertThat("Fieldspec numeric restrictions have upper bound", -// ((LinearRestrictions) outputSpec.getRestrictions()).getMax(), Is.is(not(NUMERIC_MAX))); -// Assert.assertThat("Fieldspec numeric restrictions upper bound limit is correct", -// ((LinearRestrictions) outputSpec.getRestrictions()).getMax(), Is.is(BigDecimal.valueOf(5))); -// } -// -// @Test -// void shouldReduceNegatedIsLessThanOrEqualToConstantConstraint() { -// final Field field = createField("test0", NUMERIC); -// ProfileFields profileFields = new ProfileFields(Collections.singletonList(field)); -// Set constraints = Collections.singleton( -// new IsLessThanConstantConstraint(field, NumberUtils.coerceToBigDecimal(5)).negate()); -// -// RowSpec testOutput = constraintReducer.reduceConstraintsToRowSpec(profileFields, nodeFromConstraints(constraints)).get(); -// -// Assert.assertThat("Output is not null", testOutput, Is.is(IsNull.notNullValue())); -// FieldSpec outputSpec = testOutput.getSpecForField(field); -// Assert.assertThat("Fieldspec is not null", outputSpec, Is.is(IsNull.notNullValue())); -// Assert.assertThat("Fieldspec has no set restrictions", outputSpec.getWhitelist(), -// Is.is(IsNull.nullValue())); -// Assert.assertThat("Fieldspec has no null restrictions", outputSpec.isNullable(), -// Is.is(true)); -// Assert.assertThat("Fieldspec has numeric restrictions", outputSpec.getRestrictions(), -// Is.is(IsNull.notNullValue())); -// Assert.assertThat("Fieldspec numeric restrictions have no upper bound", -// ((LinearRestrictions) outputSpec.getRestrictions()).getMax(), Is.is(equalTo(NUMERIC_MAX))); -// Assert.assertThat("Fieldspec numeric restrictions have lower bound", -// ((LinearRestrictions) outputSpec.getRestrictions()).getMin(), Is.is(not(equalTo(NUMERIC_MIN)))); -// Assert.assertThat("Fieldspec numeric restriction lower bound is correct", -// ((LinearRestrictions) outputSpec.getRestrictions()).getMin(), Is.is(BigDecimal.valueOf(5))); -// } -// -// @Test -// void shouldreduceIsAfterConstantDateTimeConstraint() { -// final Field field = createField("test0", DATETIME); -// final OffsetDateTime testTimestamp = OffsetDateTime.of(2018, 2, 4, 23, 25, 16, 0, ZoneOffset.UTC); -// ProfileFields profileFields = new ProfileFields(Collections.singletonList(field)); -// Set constraints = Collections.singleton( -// new IsAfterOrEqualToConstantDateTimeConstraint(field, HelixDateTime.create(testTimestamp))); -// -// RowSpec testOutput = constraintReducer.reduceConstraintsToRowSpec(profileFields, nodeFromConstraints(constraints)).get(); -// -// Assert.assertThat("Output is not null", testOutput, Is.is(IsNull.notNullValue())); -// FieldSpec outputSpec = testOutput.getSpecForField(field); -// Assert.assertThat("Fieldspec is not null", outputSpec, Is.is(IsNull.notNullValue())); -// Assert.assertThat("Fieldspec has no set restrictions", outputSpec.getWhitelist(), -// Is.is(IsNull.nullValue())); -// Assert.assertThat("Fieldspec has no null restrictions", outputSpec.isNullable(), -// Is.is(true)); -// Assert.assertThat("Fieldspec has datetime restrictions", outputSpec.getRestrictions(), -// Is.is(IsNull.notNullValue())); -// Assert.assertThat("Fieldspec datetime restrictions have no upper bound", -// ((LinearRestrictions) outputSpec.getRestrictions()).getMax(), Is.is(equalTo(ISO_MAX_DATE))); -// Assert.assertThat("Fieldspec datetime restrictions have lower bound", -// ((LinearRestrictions) outputSpec.getRestrictions()).getMin(), Is.is(not(equalTo(ISO_MIN_DATE)))); -// Assert.assertThat("Fieldspec datetime restrictions have correct lower bound limit", -// ((LinearRestrictions) outputSpec.getRestrictions()).getMin(), Is.is(testTimestamp)); -// } -// -// @Test -// void shouldreduceNegatedIsAfterConstantDateTimeConstraint() { -// final Field field = createField("test0", DATETIME); -// final OffsetDateTime testTimestamp = OffsetDateTime.of(2018, 2, 4, 23, 25, 16,0, ZoneOffset.UTC); -// ProfileFields profileFields = new ProfileFields(Collections.singletonList(field)); -// Set constraints = Collections.singleton( -// new IsAfterConstantDateTimeConstraint(field, HelixDateTime.create(testTimestamp)).negate()); -// -// RowSpec testOutput = constraintReducer.reduceConstraintsToRowSpec(profileFields, nodeFromConstraints(constraints)).get(); -// -// Assert.assertThat("Output is not null", testOutput, Is.is(IsNull.notNullValue())); -// FieldSpec outputSpec = testOutput.getSpecForField(field); -// Assert.assertThat("Fieldspec is not null", outputSpec, Is.is(IsNull.notNullValue())); -// Assert.assertThat("Fieldspec has no set restrictions", outputSpec.getWhitelist(), -// Is.is(IsNull.nullValue())); -// Assert.assertThat("Fieldspec has no null restrictions", outputSpec.isNullable(), -// Is.is(true)); -// Assert.assertThat("Fieldspec has datetime restrictions", outputSpec.getRestrictions(), -// Is.is(IsNull.notNullValue())); -// Assert.assertThat("Fieldspec datetime restrictions have no lower bound", -// ((LinearRestrictions) outputSpec.getRestrictions()).getMin(), Is.is(equalTo(ISO_MIN_DATE))); -// Assert.assertThat("Fieldspec datetime restrictions have upper bound", -// ((LinearRestrictions) outputSpec.getRestrictions()).getMax(), Is.is(not(equalTo(ISO_MAX_DATE)))); -// Assert.assertThat("Fieldspec datetime restrictions have correct upper bound limit", -// ((LinearRestrictions) outputSpec.getRestrictions()).getMax(), Is.is(testTimestamp)); -// } -// -// @Test -// void shouldreduceIsAfterOrEqualToConstantDateTimeConstraint() { -// final Field field = createField("test0", DATETIME); -// final OffsetDateTime testTimestamp = OffsetDateTime.of(2018, 2, 4, 23, 25, 16, 0, ZoneOffset.UTC); -// ProfileFields profileFields = new ProfileFields(Collections.singletonList(field)); -// Set constraints = Collections.singleton( -// new IsAfterOrEqualToConstantDateTimeConstraint(field, HelixDateTime.create(testTimestamp))); -// -// RowSpec testOutput = constraintReducer.reduceConstraintsToRowSpec(profileFields, nodeFromConstraints(constraints)).get(); -// -// Assert.assertThat("Output is not null", testOutput, Is.is(IsNull.notNullValue())); -// FieldSpec outputSpec = testOutput.getSpecForField(field); -// Assert.assertThat("Fieldspec is not null", outputSpec, Is.is(IsNull.notNullValue())); -// Assert.assertThat("Fieldspec has no set restrictions", outputSpec.getWhitelist(), -// Is.is(IsNull.nullValue())); -// Assert.assertThat("Fieldspec has no null restrictions", outputSpec.isNullable(), -// Is.is(true)); -// Assert.assertThat("Fieldspec has datetime restrictions", outputSpec.getRestrictions(), -// Is.is(IsNull.notNullValue())); -// Assert.assertThat("Fieldspec datetime restrictions have no upper bound", -// ((LinearRestrictions) outputSpec.getRestrictions()).getMax(), Is.is(equalTo(ISO_MAX_DATE))); -// Assert.assertThat("Fieldspec datetime restrictions have lower bound", -// ((LinearRestrictions) outputSpec.getRestrictions()).getMin(), Is.is(not(equalTo(ISO_MAX_DATE)))); -// Assert.assertThat("Fieldspec datetime restrictions have correct lower bound limit", -// ((LinearRestrictions) outputSpec.getRestrictions()).getMin(), Is.is(testTimestamp)); -// } -// -// @Test -// void shouldreduceNegatedIsAfterOrEqualToConstantDateTimeConstraint() { -// final Field field = createField("test0", DATETIME); -// final OffsetDateTime testTimestamp = OffsetDateTime.of(2018, 2, 4, 23, 25, 16, 0, ZoneOffset.UTC); -// ProfileFields profileFields = new ProfileFields(Collections.singletonList(field)); -// Set constraints = Collections.singleton( -// new IsAfterConstantDateTimeConstraint(field, HelixDateTime.create(testTimestamp)).negate()); -// -// RowSpec testOutput = constraintReducer.reduceConstraintsToRowSpec(profileFields, nodeFromConstraints(constraints)).get(); -// -// Assert.assertThat("Output is not null", testOutput, Is.is(IsNull.notNullValue())); -// FieldSpec outputSpec = testOutput.getSpecForField(field); -// Assert.assertThat("Fieldspec is not null", outputSpec, Is.is(IsNull.notNullValue())); -// Assert.assertThat("Fieldspec has no set restrictions", outputSpec.getWhitelist(), -// Is.is(IsNull.nullValue())); -// Assert.assertThat("Fieldspec has no null restrictions", outputSpec.isNullable(), -// Is.is(true)); -// Assert.assertThat("Fieldspec has datetime restrictions", outputSpec.getRestrictions(), -// Is.is(IsNull.notNullValue())); -// Assert.assertThat("Fieldspec datetime restrictions have no lower bound", -// ((LinearRestrictions) outputSpec.getRestrictions()).getMin(), Is.is(equalTo(ISO_MIN_DATE))); -// Assert.assertThat("Fieldspec datetime restrictions have upper bound", -// ((LinearRestrictions) outputSpec.getRestrictions()).getMax(), Is.is(not(equalTo(ISO_MAX_DATE)))); -// Assert.assertThat("Fieldspec datetime restrictions have correct upper bound limit", -// ((LinearRestrictions) outputSpec.getRestrictions()).getMax(), Is.is(testTimestamp)); -// } -// -// @Test -// void shouldreduceIsBeforeConstantDateTimeConstraint() { -// final Field field = createField("test0", DATETIME); -// final OffsetDateTime testTimestamp = OffsetDateTime.of(2018, 2, 4, 23, 25, 16, 0, ZoneOffset.UTC); -// ProfileFields profileFields = new ProfileFields(Collections.singletonList(field)); -// Set constraints = Collections.singleton( -// new IsBeforeOrEqualToConstantDateTimeConstraint(field, HelixDateTime.create(testTimestamp))); -// -// RowSpec testOutput = constraintReducer.reduceConstraintsToRowSpec(profileFields, nodeFromConstraints(constraints)).get(); -// -// Assert.assertThat("Output is not null", testOutput, Is.is(IsNull.notNullValue())); -// FieldSpec outputSpec = testOutput.getSpecForField(field); -// Assert.assertThat("Fieldspec is not null", outputSpec, Is.is(IsNull.notNullValue())); -// Assert.assertThat("Fieldspec has no set restrictions", outputSpec.getWhitelist(), -// Is.is(IsNull.nullValue())); -// Assert.assertThat("Fieldspec has no null restrictions", outputSpec.isNullable(), -// Is.is(true)); -// Assert.assertThat("Fieldspec has datetime restrictions", outputSpec.getRestrictions(), -// Is.is(IsNull.notNullValue())); -// Assert.assertThat("Fieldspec datetime restrictions have no lower bound", -// ((LinearRestrictions) outputSpec.getRestrictions()).getMin(), Is.is(equalTo(ISO_MIN_DATE))); -// Assert.assertThat("Fieldspec datetime restrictions have upper bound", -// ((LinearRestrictions) outputSpec.getRestrictions()).getMax(), Is.is(not(equalTo(ISO_MAX_DATE)))); -// Assert.assertThat("Fieldspec datetime restrictions have correct upper bound limit", -// ((LinearRestrictions) outputSpec.getRestrictions()).getMax(), Is.is(testTimestamp)); -// } -// -// @Test -// void shouldreduceNegatedIsBeforeConstantDateTimeConstraint() { -// final Field field = createField("test0", DATETIME); -// final OffsetDateTime testTimestamp = OffsetDateTime.of(2018, 2, 4, 23, 25, 16, 0, ZoneOffset.UTC); -// ProfileFields profileFields = new ProfileFields(Collections.singletonList(field)); -// Set constraints = Collections.singleton( -// new IsBeforeConstantDateTimeConstraint(field, HelixDateTime.create(testTimestamp)).negate()); -// -// RowSpec testOutput = constraintReducer.reduceConstraintsToRowSpec(profileFields, nodeFromConstraints(constraints)).get(); -// -// Assert.assertThat("Output is not null", testOutput, Is.is(IsNull.notNullValue())); -// FieldSpec outputSpec = testOutput.getSpecForField(field); -// Assert.assertThat("Fieldspec is not null", outputSpec, Is.is(IsNull.notNullValue())); -// Assert.assertThat("Fieldspec has no set restrictions", outputSpec.getWhitelist(), -// Is.is(IsNull.nullValue())); -// Assert.assertThat("Fieldspec has no null restrictions", outputSpec.isNullable(), -// Is.is(true)); -// Assert.assertThat("Fieldspec has datetime restrictions", outputSpec.getRestrictions(), -// Is.is(IsNull.notNullValue())); -// Assert.assertThat("Fieldspec datetime restrictions have no upper bound", -// ((LinearRestrictions) outputSpec.getRestrictions()).getMax(), Is.is(equalTo(ISO_MAX_DATE))); -// Assert.assertThat("Fieldspec datetime restrictions have lower bound", -// ((LinearRestrictions) outputSpec.getRestrictions()).getMin(), Is.is(not(equalTo(ISO_MIN_DATE)))); -// Assert.assertThat("Fieldspec datetime restrictions have correct lower bound limit", -// ((LinearRestrictions) outputSpec.getRestrictions()).getMin(), Is.is(testTimestamp)); -// } -// -// @Test -// void shouldreduceIsBeforeOrEqualToConstantDateTimeConstraint() { -// final Field field = createField("test0", DATETIME); -// final OffsetDateTime testTimestamp = OffsetDateTime.of(2018, 2, 4, 23, 25, 16, 0, ZoneOffset.UTC); -// ProfileFields profileFields = new ProfileFields(Collections.singletonList(field)); -// Set constraints = Collections.singleton( -// new IsBeforeOrEqualToConstantDateTimeConstraint(field, HelixDateTime.create(testTimestamp))); -// -// RowSpec testOutput = constraintReducer.reduceConstraintsToRowSpec(profileFields, nodeFromConstraints(constraints)).get(); -// -// Assert.assertThat("Output is not null", testOutput, Is.is(IsNull.notNullValue())); -// FieldSpec outputSpec = testOutput.getSpecForField(field); -// Assert.assertThat("Fieldspec is not null", outputSpec, Is.is(IsNull.notNullValue())); -// Assert.assertThat("Fieldspec has no set restrictions", outputSpec.getWhitelist(), -// Is.is(IsNull.nullValue())); -// Assert.assertThat("Fieldspec has no null restrictions", outputSpec.isNullable(), -// Is.is(true)); -// Assert.assertThat("Fieldspec has datetime restrictions", outputSpec.getRestrictions(), -// Is.is(IsNull.notNullValue())); -// Assert.assertThat("Fieldspec datetime restrictions have no lower bound", -// ((LinearRestrictions) outputSpec.getRestrictions()).getMin(), Is.is((equalTo(ISO_MIN_DATE)))); -// Assert.assertThat("Fieldspec datetime restrictions have upper bound", -// ((LinearRestrictions) outputSpec.getRestrictions()).getMax(), Is.is(not(equalTo(ISO_MAX_DATE)))); -// Assert.assertThat("Fieldspec datetime restrictions have correct upper bound limit", -// ((LinearRestrictions) outputSpec.getRestrictions()).getMax(), Is.is(testTimestamp)); -// } -// -// @Test -// void shouldreduceNegatedIsBeforeorEqualToConstantDateTimeConstraint() { -// final Field field = createField("test0", DATETIME); -// final OffsetDateTime testTimestamp = OffsetDateTime.of(2018, 2, 4, 23, 25, 16, 0, ZoneOffset.UTC); -// ProfileFields profileFields = new ProfileFields(Collections.singletonList(field)); -// Set constraints = Collections.singleton( -// new IsBeforeConstantDateTimeConstraint(field, HelixDateTime.create(testTimestamp)).negate()); -// -// RowSpec testOutput = constraintReducer.reduceConstraintsToRowSpec(profileFields, nodeFromConstraints(constraints)).get(); -// -// Assert.assertThat("Output is not null", testOutput, Is.is(IsNull.notNullValue())); -// FieldSpec outputSpec = testOutput.getSpecForField(field); -// Assert.assertThat("Fieldspec is not null", outputSpec, Is.is(IsNull.notNullValue())); -// Assert.assertThat("Fieldspec has no set restrictions", outputSpec.getWhitelist(), -// Is.is(IsNull.nullValue())); -// Assert.assertThat("Fieldspec has no null restrictions", outputSpec.isNullable(), -// Is.is(true)); -// Assert.assertThat("Fieldspec has datetime restrictions", outputSpec.getRestrictions(), -// Is.is(IsNull.notNullValue())); -// Assert.assertThat("Fieldspec datetime restrictions have no upper bound", -// ((LinearRestrictions) outputSpec.getRestrictions()).getMax(), Is.is(equalTo(ISO_MAX_DATE))); -// Assert.assertThat("Fieldspec datetime restrictions have lower bound", -// ((LinearRestrictions) outputSpec.getRestrictions()).getMin(), Is.is(not(equalTo(ISO_MIN_DATE)))); -// Assert.assertThat("Fieldspec datetime restrictions have correct lower bound limit", -// ((LinearRestrictions) outputSpec.getRestrictions()).getMin(), Is.is(testTimestamp)); -// } -// -// @Test -// void shouldMergeAndReduceIsAfterConstantDateTimeConstraintWithIsBeforeConstantDateTimeConstraint() { -// final Field field = createField("test0", DATETIME); -// final OffsetDateTime startTimestamp = OffsetDateTime.of(2013, 11, 19, 10, 43, 12, 0, ZoneOffset.UTC); -// final OffsetDateTime endTimestamp = OffsetDateTime.of(2018, 2, 4, 23, 25, 8, 0, ZoneOffset.UTC); -// ProfileFields profileFields = new ProfileFields(Collections.singletonList(field)); -// Set constraints = SetUtils.setOf( -// new IsAfterOrEqualToConstantDateTimeConstraint(field, HelixDateTime.create(startTimestamp)), -// new IsBeforeOrEqualToConstantDateTimeConstraint(field, HelixDateTime.create(endTimestamp))); -// -// RowSpec testOutput = constraintReducer.reduceConstraintsToRowSpec(profileFields, nodeFromConstraints(constraints)).get(); -// -// Assert.assertThat("Output is not null", testOutput, Is.is(IsNull.notNullValue())); -// FieldSpec outputSpec = testOutput.getSpecForField(field); -// Assert.assertThat("Fieldspec is not null", outputSpec, Is.is(IsNull.notNullValue())); -// Assert.assertThat("Fieldspec has no set restrictions", outputSpec.getWhitelist(), -// Is.is(IsNull.nullValue())); -// Assert.assertThat("Fieldspec has no null restrictions", outputSpec.isNullable(), -// Is.is(true)); -// Assert.assertThat("Fieldspec has datetime restrictions", outputSpec.getRestrictions(), -// Is.is(IsNull.notNullValue())); -// Assert.assertThat("Fieldspec datetime restrictions have lower bound", -// ((LinearRestrictions) outputSpec.getRestrictions()).getMin(), Is.is(IsNull.notNullValue())); -// Assert.assertThat("Fieldspec datetime restrictions have correct lower bound limit", -// ((LinearRestrictions) outputSpec.getRestrictions()).getMin(), Is.is(startTimestamp)); -// Assert.assertThat("Fieldspec datetime restrictions have upper bound", -// ((LinearRestrictions) outputSpec.getRestrictions()).getMax(), Is.is(IsNull.notNullValue())); -// Assert.assertThat("Fieldspec datetime restrictions have correct upper bound limit", -// ((LinearRestrictions) outputSpec.getRestrictions()).getMax(), Is.is(endTimestamp)); -// } -// -// @Test -// void shouldReduceMatchesRegexConstraint() { -// final Field field = createField("test0"); -// String pattern = ".*\\..*"; -// ProfileFields profileFields = new ProfileFields(Collections.singletonList(field)); -// Set constraints = Collections.singleton( -// new MatchesRegexConstraint(field, Pattern.compile(pattern))); -// -// RowSpec testOutput = constraintReducer.reduceConstraintsToRowSpec(profileFields, nodeFromConstraints(constraints)).get(); -// -// Assert.assertThat("Output is not null", testOutput, Is.is(IsNull.notNullValue())); -// FieldSpec outputSpec = testOutput.getSpecForField(field); -// Assert.assertThat("Fieldspec is not null", outputSpec, Is.is(IsNull.notNullValue())); -// Assert.assertThat("Fieldspec has no set restrictions", outputSpec.getWhitelist(), -// Is.is(IsNull.nullValue())); -// Assert.assertThat("Fieldspec has no null restrictions", outputSpec.isNullable(), -// Is.is(true)); -// Assert.assertThat("Fieldspec has string restrictions", outputSpec.getRestrictions(), -// Is.is(IsNull.notNullValue())); -// } -// -// @Test -// void shouldReduceStringLongerThanConstraint() { -// final Field field = createField("test0"); -// -// ProfileFields profileFields = new ProfileFields(Collections.singletonList(field)); -// Set constraints = Collections.singleton( -// new IsStringLongerThanConstraint(field, HelixStringLength.create(5)) -// ); -// -// RowSpec testOutput = constraintReducer.reduceConstraintsToRowSpec(profileFields, nodeFromConstraints(constraints)).get(); -// -// Assert.assertThat("Output is not null", testOutput, Is.is(IsNull.notNullValue())); -// FieldSpec outputSpec = testOutput.getSpecForField(field); -// Assert.assertThat("Fieldspec is not null", outputSpec, Is.is(IsNull.notNullValue())); -// Assert.assertThat("Fieldspec has no set restrictions", outputSpec.getWhitelist(), -// Is.is(IsNull.nullValue())); -// Assert.assertThat("Fieldspec has no null restrictions", outputSpec.isNullable(), -// Is.is(true)); -// Assert.assertThat("Fieldspec has string restrictions", outputSpec.getRestrictions(), -// Is.is(IsNull.notNullValue())); -// } -// -// @Test -// void shouldReduceStringShorterThanConstraint() { -// final Field field = createField("test0"); -// -// ProfileFields profileFields = new ProfileFields(Collections.singletonList(field)); -// Set constraints = Collections.singleton( -// new IsStringShorterThanConstraint(field, HelixStringLength.create(5)) -// ); -// -// RowSpec testOutput = constraintReducer.reduceConstraintsToRowSpec(profileFields, nodeFromConstraints(constraints)).get(); -// -// Assert.assertThat("Output is not null", testOutput, Is.is(IsNull.notNullValue())); -// FieldSpec outputSpec = testOutput.getSpecForField(field); -// Assert.assertThat("Fieldspec is not null", outputSpec, Is.is(IsNull.notNullValue())); -// Assert.assertThat("Fieldspec has no set restrictions", outputSpec.getWhitelist(), -// Is.is(IsNull.nullValue())); -// Assert.assertThat("Fieldspec has no null restrictions", outputSpec.isNullable(), -// Is.is(true)); -// Assert.assertThat("Fieldspec has string restrictions", outputSpec.getRestrictions(), -// Is.is(IsNull.notNullValue())); -// } -// -// @Test -// void shouldReduceStringHasLengthConstraint() { -// final Field field = createField("test0"); -// -// ProfileFields profileFields = new ProfileFields(Collections.singletonList(field)); -// Set constraints = Collections.singleton( -// new StringHasLengthConstraint(field, HelixStringLength.create(5)) -// ); -// -// RowSpec testOutput = constraintReducer.reduceConstraintsToRowSpec(profileFields, nodeFromConstraints(constraints)).get(); -// -// Assert.assertThat("Output is not null", testOutput, Is.is(IsNull.notNullValue())); -// FieldSpec outputSpec = testOutput.getSpecForField(field); -// Assert.assertThat("Fieldspec has no set restrictions", outputSpec.getWhitelist(), -// Is.is(IsNull.nullValue())); -// Assert.assertThat("Fieldspec has no null restrictions", outputSpec.isNullable(), -// Is.is(true)); -// Assert.assertThat("Fieldspec has string restrictions", outputSpec.getRestrictions(), -// Is.is(IsNull.notNullValue())); -// } -//} From 47f4804709d55794c7d9bcf21101e6c3e9ace688 Mon Sep 17 00:00:00 2001 From: Charlton Dowding Date: Fri, 8 Nov 2019 11:20:39 +0000 Subject: [PATCH 10/10] Removed empty files --- .../java/com/scottlogic/deg/common/profile/HelixDateTime.java | 0 .../main/java/com/scottlogic/deg/common/profile/HelixNumber.java | 0 .../java/com/scottlogic/deg/common/profile/HelixStringLength.java | 0 .../deg/profile/dtos/constraints/ConstraintTypeJsonProperty.java | 0 4 files changed, 0 insertions(+), 0 deletions(-) delete mode 100644 common/src/main/java/com/scottlogic/deg/common/profile/HelixDateTime.java delete mode 100644 common/src/main/java/com/scottlogic/deg/common/profile/HelixNumber.java delete mode 100644 common/src/main/java/com/scottlogic/deg/common/profile/HelixStringLength.java delete mode 100644 profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/ConstraintTypeJsonProperty.java diff --git a/common/src/main/java/com/scottlogic/deg/common/profile/HelixDateTime.java b/common/src/main/java/com/scottlogic/deg/common/profile/HelixDateTime.java deleted file mode 100644 index e69de29bb..000000000 diff --git a/common/src/main/java/com/scottlogic/deg/common/profile/HelixNumber.java b/common/src/main/java/com/scottlogic/deg/common/profile/HelixNumber.java deleted file mode 100644 index e69de29bb..000000000 diff --git a/common/src/main/java/com/scottlogic/deg/common/profile/HelixStringLength.java b/common/src/main/java/com/scottlogic/deg/common/profile/HelixStringLength.java deleted file mode 100644 index e69de29bb..000000000 diff --git a/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/ConstraintTypeJsonProperty.java b/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/ConstraintTypeJsonProperty.java deleted file mode 100644 index e69de29bb..000000000