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 #1391 from finos/1235-generic-dependent-fields
Browse files Browse the repository at this point in the history
1235 Fix dependent fields
  • Loading branch information
pdaulbyscottlogic authored Oct 2, 2019
2 parents cd7a652 + 01a3be4 commit 6cf439b
Show file tree
Hide file tree
Showing 25 changed files with 448 additions and 704 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public TemporalAdjusterGenerator(ChronoUnit chronoUnit, boolean workingDay) {
}

public TemporalAdjuster adjuster(int value) {
int adjustedValue = negated ? value : -value;
int adjustedValue = negated ? -value : value;
return workingDay ? getWorkingDayAdjusterFunction(adjustedValue) : getAdjusterFunction(chronoUnit, adjustedValue);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,16 @@ public static FieldSpec fromList(DistributedList<Object> whitelist) {
public static FieldSpec fromRestriction(TypedRestrictions restrictions) {
return new FieldSpec(null, restrictions, true, Collections.emptySet());
}

public static FieldSpec empty() {
return new FieldSpec(null, null, true, Collections.emptySet());
}

public static FieldSpec nullOnly() {
return new FieldSpec(NO_VALUES, null, true, Collections.emptySet());
}

private final boolean nullable;
private final DistributedList<Object> whitelist;
private final Set<Object> blacklist;

private final TypedRestrictions restrictions;

private FieldSpec(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,10 @@
*/
public class RowSpec {
private final ProfileFields fields;

private final Map<Field, FieldSpec> fieldToFieldSpec;
private final List<FieldSpecRelations> relations;

private final List<FieldSpecRelations> relations;
public RowSpec(ProfileFields fields,
Map<Field, FieldSpec> fieldToFieldSpec,
List<FieldSpecRelations> relations) {
Expand Down Expand Up @@ -59,6 +60,10 @@ public List<FieldSpecRelations> getRelations() {
return relations;
}

public Map<Field, FieldSpec> getFieldToFieldSpec() {
return fieldToFieldSpec;
}

@Override
public String toString() {
return Objects.toString(fieldToFieldSpec);
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -17,40 +17,61 @@
package com.scottlogic.deg.generator.fieldspecs.relations;

import com.scottlogic.deg.common.profile.Field;
import com.scottlogic.deg.generator.fieldspecs.FieldSpec;
import com.scottlogic.deg.generator.restrictions.linear.Limit;
import com.scottlogic.deg.generator.restrictions.linear.LinearRestrictions;
import com.scottlogic.deg.generator.restrictions.linear.LinearRestrictionsFactory;

import java.time.OffsetDateTime;

import static com.scottlogic.deg.common.util.Defaults.ISO_MAX_DATE;
import static com.scottlogic.deg.generator.utils.Defaults.DATETIME_MAX_LIMIT;
import static com.scottlogic.deg.generator.utils.Defaults.DATETIME_MIN_LIMIT;


public class AfterDateRelation extends AbstractDateInequalityRelation {
public class AfterDateRelation implements FieldSpecRelations {
private final Field main;
private final Field other;
private final boolean inclusive;

public AfterDateRelation(Field main, Field other, boolean inclusive) {
super(main, other);
this.main = main;
this.other = other;
this.inclusive = inclusive;
}

@Override
protected OffsetDateTime dateTimeLimitExtractingFunction(LinearRestrictions<OffsetDateTime> restrictions) {
if (restrictions != null) {
return restrictions.getMax();
} else {
return null;
public FieldSpec reduceToRelatedFieldSpec(FieldSpec otherValue) {
LinearRestrictions<OffsetDateTime> lr = (LinearRestrictions) otherValue.getRestrictions();
if (lr == null){
return FieldSpec.empty();
}
}

@Override
protected LinearRestrictions<OffsetDateTime> appendValueToRestrictions(OffsetDateTime value) {
return LinearRestrictionsFactory.createDateTimeRestrictions(DATETIME_MIN_LIMIT, new Limit<>(value, inclusive));
OffsetDateTime min = lr.getMin();
if (!inclusive){
min = lr.getGranularity().getNext(min);
}

return FieldSpec.fromRestriction(new LinearRestrictions<>(min, ISO_MAX_DATE, lr.getGranularity()));
}

@Override
public FieldSpecRelations inverse() {
return new BeforeDateRelation(other(), main(), inclusive);
}

@Override
public Field main() {
return main;
}

@Override
public Field other() {
return other;
}

@Override
public String toString() {
return String.format("%s is after %s%s", main(), inclusive ? "or equal to " : "", other());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,38 +17,62 @@
package com.scottlogic.deg.generator.fieldspecs.relations;

import com.scottlogic.deg.common.profile.Field;
import com.scottlogic.deg.generator.fieldspecs.FieldSpec;
import com.scottlogic.deg.generator.restrictions.linear.Limit;
import com.scottlogic.deg.generator.restrictions.linear.LinearRestrictions;
import com.scottlogic.deg.generator.restrictions.linear.LinearRestrictionsFactory;

import java.time.OffsetDateTime;

import static com.scottlogic.deg.common.util.Defaults.ISO_MAX_DATE;
import static com.scottlogic.deg.common.util.Defaults.ISO_MIN_DATE;
import static com.scottlogic.deg.generator.utils.Defaults.DATETIME_MAX_LIMIT;
import static com.scottlogic.deg.generator.utils.Defaults.DATETIME_MIN_LIMIT;

public class BeforeDateRelation extends AbstractDateInequalityRelation {
public class BeforeDateRelation implements FieldSpecRelations {
private final Field main;
private final Field other;
private final boolean inclusive;

public BeforeDateRelation(Field main, Field other, boolean inclusive) {
super(main, other);
this.main = main;
this.other = other;
this.inclusive = inclusive;
}

@Override
public OffsetDateTime dateTimeLimitExtractingFunction(LinearRestrictions<OffsetDateTime> restrictions) {
if (restrictions != null) {
return restrictions.getMin();
} else {
return null;
public FieldSpec reduceToRelatedFieldSpec(FieldSpec otherValue) {
LinearRestrictions<OffsetDateTime> lr = (LinearRestrictions) otherValue.getRestrictions();
if (lr == null){
return FieldSpec.empty();
}

OffsetDateTime max = lr.getMax();
if (!inclusive){
max = lr.getGranularity().getPrevious(max);
}

return FieldSpec.fromRestriction(new LinearRestrictions<>(ISO_MIN_DATE, max, lr.getGranularity()));
}


@Override
public Field main() {
return main;
}

@Override
protected LinearRestrictions<OffsetDateTime> appendValueToRestrictions(OffsetDateTime value) {
return LinearRestrictionsFactory.createDateTimeRestrictions(new Limit<>(value, inclusive), DATETIME_MAX_LIMIT);
public Field other() {
return other;
}

@Override
public FieldSpecRelations inverse() {
return new AfterDateRelation(other(), main(), inclusive);
}

@Override
public String toString() {
return String.format("%s is before %s%s", main(), inclusive ? "or equal to " : "", other());
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -17,55 +17,32 @@
package com.scottlogic.deg.generator.generation.databags;

import com.google.inject.Inject;
import com.scottlogic.deg.common.profile.Field;
import com.scottlogic.deg.generator.fieldspecs.FieldSpec;
import com.scottlogic.deg.generator.fieldspecs.FieldSpecGroup;
import com.scottlogic.deg.generator.fieldspecs.RowSpec;
import com.scottlogic.deg.generator.fieldspecs.relations.FieldSpecRelations;
import com.scottlogic.deg.generator.generation.grouped.FieldGroup;
import com.scottlogic.deg.generator.generation.combinationstrategies.CombinationStrategy;
import com.scottlogic.deg.generator.generation.grouped.FieldSpecGroupValueGenerator;
import com.scottlogic.deg.generator.generation.FieldSpecValueGenerator;
import com.scottlogic.deg.generator.generation.grouped.RowSpecGrouper;
import com.scottlogic.deg.generator.generation.combinationstrategies.CombinationStrategy;

import java.util.Map;
import java.util.*;
import java.util.function.Supplier;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class RowSpecDataBagGenerator {
private final FieldSpecValueGenerator generator;
private final FieldSpecGroupValueGenerator generator;
private final CombinationStrategy combinationStrategy;

@Inject
public RowSpecDataBagGenerator(
FieldSpecValueGenerator generator,
FieldSpecGroupValueGenerator generator,
CombinationStrategy combinationStrategy) {
this.generator = generator;
this.combinationStrategy = combinationStrategy;
}

public Stream<DataBag> createDataBags(RowSpec rowSpec) {
Stream<Supplier<Stream<DataBag>>> dataBagsForGroups = RowSpecGrouper.createGroups(rowSpec).stream()
.map(group -> () -> generateDataForGroup(rowSpec, group));
Stream<Supplier<Stream<DataBag>>> dataBagsForGroups =
RowSpecGrouper.createGroups(rowSpec).stream()
.map(group -> () -> generator.generate(group));

return combinationStrategy.permute(dataBagsForGroups);
}

private Stream<DataBag> generateDataForGroup(RowSpec rowSpec, FieldGroup group) {
List<Field> fields = group.fields();
List<FieldSpecRelations> relations = rowSpec.getRelations().stream()
.filter(relation -> fields.contains(relation.main()) || fields.contains(relation.other()))
.collect(Collectors.toList());

Map<Field, FieldSpec> fieldSpecMap = fields.stream()
.collect(Collectors.toMap(field -> field, rowSpec::getSpecForField));

FieldSpecGroup specGroup = new FieldSpecGroup(fieldSpecMap, relations);

FieldSpecGroupValueGenerator groupGenerator = new FieldSpecGroupValueGenerator(generator);

return groupGenerator.generate(specGroup);
}
}
Loading

0 comments on commit 6cf439b

Please sign in to comment.