Skip to content
This repository has been archived by the owner on Apr 14, 2023. It is now read-only.

Commit

Permalink
Merge pull request #1445 from cdowding-sl/hotfix/remove-of-type
Browse files Browse the repository at this point in the history
Remove ofType
  • Loading branch information
cdowding-sl authored Oct 10, 2019
2 parents 83edbea + 8ba97af commit ff2ef9e
Show file tree
Hide file tree
Showing 14 changed files with 11 additions and 351 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,8 @@ public enum AtomicConstraintType {
IS_IN_SET("inSet"),
IS_IN_MAP("inMap"),
IS_NULL("null"),
IS_UNIQUE("unique"),
IS_OF_TYPE("ofType"),

MATCHES_REGEX("matchingRegex"),
CONTAINS_REGEX("containingRegex"),
FORMATTED_AS("formattedAs"),

// String
HAS_LENGTH("ofLength"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@

import com.google.inject.Inject;
import com.google.inject.Provider;
import com.scottlogic.deg.common.profile.constraintdetail.AtomicConstraintType;
import com.scottlogic.deg.generator.generation.GenerationConfigSource;
import com.scottlogic.deg.generator.violations.filters.ConstraintTypeViolationFilter;
import com.scottlogic.deg.generator.violations.filters.ViolationFilter;

Expand All @@ -44,7 +42,6 @@ public List<ViolationFilter> get() {
}

return commandLine.getConstraintsToNotViolate().stream()
.filter(atomicConstraint -> !atomicConstraint.equals(AtomicConstraintType.IS_OF_TYPE))
.map(mapper::toConstraintClass)
.map(ConstraintTypeViolationFilter::new)
.collect(Collectors.toList());
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,11 @@ Feature: The violations mode of the Data Helix app can be run in violations mode
Given there is a field foo
And the data requested is violating
And the generator can generate at most 5 rows
And we do not violate any of type constraints

Scenario: Running the generator in violate mode for not equal to is successful (decimal)
Given foo is anything but equal to 8
And foo has type "decimal"
And foo is granular to 1
And we do not violate any of type constraints
And we do not violate any granular to constraints
And the generation strategy is full
Then the following data should be generated:
Expand All @@ -22,7 +20,6 @@ Feature: The violations mode of the Data Helix app can be run in violations mode
And foo has type "decimal"
And the generation strategy is full
And we do not violate any equal to constraints
And we do not violate any of type constraints
Then the following data should be generated:
| foo |
| 8 |
Expand All @@ -43,7 +40,6 @@ Feature: The violations mode of the Data Helix app can be run in violations mode
And foo has type "decimal"
And the generation strategy is random
And the data requested is violating
And we do not violate any of type constraints
Then 5 rows of data are generated
And foo contains anything but null

Expand All @@ -53,7 +49,6 @@ Feature: The violations mode of the Data Helix app can be run in violations mode
And foo is anything but null
And foo is before 2019-01-01T00:00:00.000Z
And the data requested is violating
And we do not violate any of type constraints
Then 5 rows of data are generated
And foo contains only datetime data
And foo contains datetimes after or at 2019-01-01T00:00:00.000Z
Expand All @@ -64,7 +59,6 @@ Feature: The violations mode of the Data Helix app can be run in violations mode
And the generation strategy is random
And foo is less than 10
And the data requested is violating
And we do not violate any of type constraints
Then 5 rows of data are generated
And foo contains only numeric data
And foo contains numeric values greater than or equal to 10
Expand All @@ -75,7 +69,6 @@ Feature: The violations mode of the Data Helix app can be run in violations mode
And foo is anything but null
And foo is shorter than 10
And the data requested is violating
And we do not violate any of type constraints
Then 5 rows of data are generated
And foo contains only string data
And foo contains strings longer than or equal to 10
Expand All @@ -86,7 +79,6 @@ Feature: The violations mode of the Data Helix app can be run in violations mode
And foo is anything but null
And foo is matching regex /[a-z]{0,9}/
And the data requested is violating
And we do not violate any of type constraints
Then 5 rows of data are generated
And foo contains only string data
And foo contains anything but strings matching /[a-z]{0,9}/
Expand All @@ -97,7 +89,6 @@ Feature: The violations mode of the Data Helix app can be run in violations mode
And the generation strategy is random
And foo is anything but matching regex /[a-z]{0,9}/
And the data requested is violating
And we do not violate any of type constraints
Then 5 rows of data are generated
And foo contains only string data
And foo contains strings matching /[a-z]{0,9}/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1512,122 +1512,6 @@ Feature: Values can be specified by using if, then and else constraints
| foo | bar |
| "dddd" | "4444" |

Scenario: An if constraint that contains an ISIN constraint in the then clause generates valid ISINs when the if clause applies
Given foo is in set:
| "GB0002634946" |
| "bb" |
| "ccc" |
| "dddd" |
And foo is anything but null
And bar is in set:
| "GB0002634946" |
| "22" |
| "333" |
| "4444" |
And bar is anything but null
And foo has type "string"
And bar has type "string"
And there is a constraint:
"""
{
"if": { "field": "foo", "is": "equalTo", "value": "bb" },
"then": { "field": "bar", "is": "ofType", "value": "ISIN" },
"else": { "field": "bar", "is": "equalTo", "value": "333" }
}
"""
Then the following data should be generated:
| foo | bar |
| "GB0002634946" | "333" |
| "bb" | "GB0002634946" |
| "ccc" | "333" |
| "dddd" | "333" |

Scenario: An if constraint that contains an ISIN constraint in the else clause generates valid ISINs when the if clause does not apply
Given foo is in set:
| "GB0002634946" |
| "bb" |
| "ccc" |
| "dddd" |
And foo is anything but null
And bar is in set:
| "GB0002634946" |
| "22" |
| "333" |
| "4444" |
And bar is anything but null
And foo has type "string"
And bar has type "string"
And there is a constraint:
"""
{
"if": { "field": "foo", "is": "equalTo", "value": "bb" },
"then": { "field": "bar", "is": "equalTo", "value": "22" },
"else": { "field": "bar", "is": "ofType", "value": "ISIN" }
}
"""
Then the following data should be generated:
| foo | bar |
| "GB0002634946" | "GB0002634946" |
| "bb" | "22" |
| "ccc" | "GB0002634946" |
| "dddd" | "GB0002634946" |

Scenario: An if constraint that contains an ISIN constraint in the then clause combined with an in set constraint that does not contain any valid ISINs only generates data that matches the else clause
Given foo is in set:
| "aa" |
| "bb" |
| "ccc" |
| "dddd" |
And foo is anything but null
And bar is in set:
| "11" |
| "22" |
| "333" |
| "4444" |
And bar is anything but null
And foo has type "string"
And bar has type "string"
And there is a constraint:
"""
{
"if": { "field": "foo", "is": "equalTo", "value": "ccc" },
"then": { "field": "bar", "is": "ofType", "value": "ISIN" },
"else": { "field": "bar", "is": "equalTo", "value": "333" }
}
"""
Then the following data should be generated:
| foo | bar |
| "aa" | "333" |
| "bb" | "333" |
| "dddd" | "333" |

Scenario: An if constraint with an else clause containing an ISIN constraint which contradicts an in set constraint generates data that only matches the then clause
Given foo is in set:
| "aa" |
| "bb" |
| "ccc" |
| "dddd" |
And foo is anything but null
And bar is in set:
| "11" |
| "22" |
| "333" |
| "4444" |
And bar is anything but null
And foo has type "string"
And bar has type "string"
And there is a constraint:
"""
{
"if": { "field": "foo", "is": "equalTo", "value": "ccc" },
"then": { "field": "bar", "is": "equalTo", "value": "333" },
"else": { "field": "bar", "is": "ofType", "value": "ISIN" }
}
"""
Then the following data should be generated:
| foo | bar |
| "ccc" | "333" |

Scenario: Running an if request that contains a non contradictory greaterThan constraint within its if statement should be successful
Given foo is in set:
| 10 |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,3 @@ Feature: Type mandation validation
And there is a field purchase_time
Then the profile is invalid because "Fields price, purchase_time are not typed; add their type to the field definition"

Scenario: An anyOf constraint whose branches don't all satisfy type mandation should not satisfy type mandation
Given there is a field user_id
And there is a constraint:
"""
{ "anyOf": [
{ "field": "user_id", "is": "ofType", "value": "string" },
{ "not": { "field": "user_id", "is": "null" } }
]}
"""
Then the profile is invalid because "Field \[user_id\]: is not typed; add its type to the field definition"

Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
import com.scottlogic.deg.generator.profile.Rule;
import com.scottlogic.deg.generator.profile.RuleInformation;
import com.scottlogic.deg.profile.dto.ConstraintDTO;
import com.scottlogic.deg.profile.reader.atomic.ConstraintReaderHelpers;
import com.scottlogic.deg.profile.reader.atomic.OfTypeConstraintFactory;
import com.scottlogic.deg.profile.serialisation.ProfileDeserialiser;
import com.scottlogic.deg.profile.dto.ProfileDTO;

Expand Down Expand Up @@ -71,9 +73,6 @@ public Profile read(String profileJson) throws IOException {
throw new InvalidProfileException("Profile is invalid: 'rules' have not been defined.");
}

//This is the types of the field that have not been set by the field def
Map<String, String> fieldTypes = getTypesFromConstraints(profileDto);

List<Field> inMapFields = getInMapConstraints(profileDto).stream()
.map(file ->
new Field(
Expand All @@ -86,14 +85,7 @@ public Profile read(String profileJson) throws IOException {


List<Field> fields = profileDto.fields.stream()
.map(fDto ->
new Field(
fDto.name,
getFieldType(fieldTypes.getOrDefault(fDto.name, fDto.type)),
fDto.unique,
fDto.formatting,
false)
)
.map(fDto -> new Field(fDto.name, ConstraintReaderHelpers.getFieldType(fDto.type), fDto.unique, fDto.formatting,false))
.collect(Collectors.toList());

fields.addAll(inMapFields);
Expand All @@ -119,25 +111,17 @@ public Profile read(String profileJson) throws IOException {

// add types
Collection<Constraint> typeRules = profileDto.fields.stream()
.filter(fieldDTO -> fieldDTO.type != null )
.map(fieldDTO -> create(AtomicConstraintType.IS_OF_TYPE, profileFields.getByName(fieldDTO.name), fieldDTO.type))
.filter(constraint -> !(constraint instanceof RemoveFromTree))
.collect(Collectors.toList());
.filter(fieldDTO -> fieldDTO.type != null )
.map(fieldDTO -> OfTypeConstraintFactory.create(profileFields.getByName(fieldDTO.name), fieldDTO.type))
.filter(Optional::isPresent)
.map(Optional::get)
.collect(Collectors.toList());

if (typeRules.size() > 0) {
rules.add(new Rule(new RuleInformation("type-rules"), typeRules));
}

return new Profile(profileFields, rules, profileDto.description);
}
private Map<String, String> getTypesFromConstraints(ProfileDTO profileDto) {
return getTopLevelConstraintsOfType(profileDto, AtomicConstraintType.IS_OF_TYPE.getText())
.collect(Collectors.toMap(
constraintDTO -> constraintDTO.field,
constraintDTO -> (String)constraintDTO.value,
(a, b) -> a
));
}

private Set<String> getInMapConstraints(ProfileDTO profileDto) {
return profileDto.rules.stream()
Expand All @@ -149,27 +133,11 @@ private Set<String> getInMapConstraints(ProfileDTO profileDto) {
.collect(Collectors.toSet());
}

private Stream<ConstraintDTO> getTopLevelConstraintsOfType(ProfileDTO profileDto, String constraint) {
return profileDto.rules.stream()
.flatMap(ruleDTO -> ruleDTO.constraints.stream())
.flatMap(this::getConstraintOrAllOfConstraints)
.filter(constraintDTO -> constraintDTO.is != null)
.filter(constraintDTO -> constraintDTO.is.equals(constraint));
}

private Stream<ConstraintDTO> getAllAtomicConstraints(Stream<ConstraintDTO> constraints) {
return constraints.flatMap(this::getUnpackedConstraintsToStream);

}

private Stream<ConstraintDTO> getConstraintOrAllOfConstraints(ConstraintDTO constraintDTO) {
if (constraintDTO.allOf != null){
return constraintDTO.allOf.stream();
}

return Stream.of(constraintDTO);
}

private Stream<ConstraintDTO> getUnpackedConstraintsToStream(ConstraintDTO constraintDTO) {
if (constraintDTO.then != null) {
return getAllAtomicConstraints(constraintDTO.else_ == null ?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@ private InMapRelation createInMapRelation(Field field, Field other, DistributedL
Set<Constraint> getSubConstraints(ProfileFields fields, Collection<ConstraintDTO> allOf) {
return allOf.stream()
.map(subConstraintDto -> apply(subConstraintDto, fields))
.filter(constraint -> !(constraint instanceof RemoveFromTree))
.collect(Collectors.toSet());
}
}

This file was deleted.

Loading

0 comments on commit ff2ef9e

Please sign in to comment.