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 #1291 from finos/v04-delayed-profile
Browse files Browse the repository at this point in the history
V04 delayed profile
  • Loading branch information
pdaulbyscottlogic authored Sep 16, 2019
2 parents 32c8ef9 + 66b699e commit faac22e
Show file tree
Hide file tree
Showing 38 changed files with 759 additions and 479 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,13 @@
* limitations under the License.
*/

package com.scottlogic.deg.profile.dto;
package com.scottlogic.deg.common.profile.constraintdetail;

import java.util.Arrays;

public enum AtomicConstraintType {

IS_EQUAL_TO_CONSTANT("equalTo"),
IS_EQUAL_TO_FIELD("equalToField"),
IS_IN_SET("inSet"),
IS_NULL("null"),
IS_UNIQUE("unique"),
Expand All @@ -44,13 +43,9 @@ public enum AtomicConstraintType {

// DateTime
IS_AFTER_CONSTANT_DATE_TIME("after"),
IS_AFTER_FIELD_DATE_TIME("afterField"),
IS_AFTER_OR_EQUAL_TO_CONSTANT_DATE_TIME("afterOrAt"),
IS_AFTER_OR_EQUAL_TO_FIELD_DATE_TIME("afterOrAtField"),
IS_BEFORE_CONSTANT_DATE_TIME("before"),
IS_BEFORE_FIELD_DATE_TIME("beforeField"),
IS_BEFORE_OR_EQUAL_TO_CONSTANT_DATE_TIME("beforeOrAt"),
IS_BEFORE_OR_EQUAL_TO_FIELD_DATE_TIME("beforeOrAtField"),

IS_GRANULAR_TO("granularTo");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,60 @@

package com.scottlogic.deg.common.profile.constraints.delayed;

import com.scottlogic.deg.common.date.TemporalAdjusterGenerator;
import com.scottlogic.deg.common.profile.Field;
import com.scottlogic.deg.common.profile.constraintdetail.AtomicConstraintType;
import com.scottlogic.deg.common.profile.constraints.Constraint;
import com.scottlogic.deg.common.profile.constraints.atomic.AtomicConstraint;

public interface DelayedAtomicConstraint extends Constraint {
public class DelayedAtomicConstraint implements Constraint {

private final Field field;
private final AtomicConstraintType underlyingConstraint;
private final Field otherField;

private final TemporalAdjusterGenerator offsetGenerator;

private final Integer offsetUnit;
public DelayedAtomicConstraint(Field field, AtomicConstraintType underlyingConstraint, Field otherField, TemporalAdjusterGenerator offsetGenerator, Integer offsetUnit) {
this.field = field;
this.underlyingConstraint = underlyingConstraint;
this.otherField = otherField;
this.offsetGenerator = offsetGenerator;
this.offsetUnit = offsetUnit;
}

public DelayedAtomicConstraint(Field field, AtomicConstraintType underlyingConstraint, Field otherField) {
this(field, underlyingConstraint, otherField, null, null);
}

static void validateFieldsAreDifferent(Field first, Field second) {
if (first.equals(second)) {
throw new IllegalArgumentException("Cannot have a relational field referring to itself");
}
}

AtomicConstraint underlyingConstraint();
public Field getField(){
return field;
}

public AtomicConstraintType getUnderlyingConstraint(){
return underlyingConstraint;
}

Field field();
public Field getOtherField(){
return otherField;
}

default DynamicNotConstraint negate() {
public DelayedAtomicConstraint negate() {
return new DynamicNotConstraint(this);
}

public TemporalAdjusterGenerator getOffsetGenerator() {
return offsetGenerator;
}

public Integer getOffsetUnit() {
return offsetUnit;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,29 +18,29 @@
package com.scottlogic.deg.common.profile.constraints.delayed;

import com.scottlogic.deg.common.profile.Field;
import com.scottlogic.deg.common.profile.constraints.atomic.AtomicConstraint;

import java.util.Objects;

public class DynamicNotConstraint implements DelayedAtomicConstraint {
public class DynamicNotConstraint extends DelayedAtomicConstraint {

private final DelayedAtomicConstraint negatedConstraint;

public DynamicNotConstraint(DelayedAtomicConstraint negatedConstraint) {
super(negatedConstraint.getField(), negatedConstraint.getUnderlyingConstraint(), negatedConstraint.getOtherField());
if (negatedConstraint instanceof DynamicNotConstraint) {
throw new IllegalArgumentException("Nested DynamicNotConstraint not allowed");
}
this.negatedConstraint = negatedConstraint;
}

@Override
public AtomicConstraint underlyingConstraint() {
return negatedConstraint.underlyingConstraint();
public Field getField() {
return negatedConstraint.getField();
}

@Override
public Field field() {
return negatedConstraint.field();
public Field getOtherField() {
return negatedConstraint.getOtherField();
}

@Override
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

25 changes: 25 additions & 0 deletions docs/UserGuide.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@
3. [before](#predicate-before)
4. [beforeOrAt](#predicate-beforeorat)
5. [granularTo](#predicate-granularto-datetime)
6. [Dependent field constraints](#otherfield-constraints)
1. [otherField](#predicate-otherfield)
2. [offset](#predicate-offset)

5. [Grammatical constraints](#Grammatical-Constraints)
1. [not](#not)
Expand Down Expand Up @@ -502,6 +505,28 @@ Is satisfied if `field` is a datetime occurring before or simultaneously with `v

Is satisfied if `field` has at least the [granularity](#DateTime-granularity) specified in `value`.

<div id="otherfield-constraints"></div>
## Dependant field constraints

<div id="predicate-otherfield"></div>
### `otherField`
allows a date field to be dependant on the output of another date field

```javascript
{ "field": "laterDateField", "is": "after", "otherField": "previousDateField" }
```

supported operators are currently
"after", "afterOrAt", "before", "beforeOrAt", "equalTo"

<div id="predicate-offset"></div>
### `offset`
Allows a dependant date to always be a certain offset away from another date

```javascript
{ "field": "threeDaysAfterField", "is": "equalTo", "otherField": "previousDateField", "offset": 3, "offsetUnit": "days" }
```

# Grammatical constraints
<div id="Grammatical-constraints"></div>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ private Stream<ConstraintToFields> mapDelayedConstraintsToFields(ConstraintNode
return node.getDelayedAtomicConstraints().stream()
.map(constraint -> new ConstraintToFields(
new RootLevelConstraint(constraint),
SetUtils.setOf(constraint.field(), constraint.underlyingConstraint().getField())));
SetUtils.setOf(constraint.getField(), constraint.getOtherField())));
}

private Stream<ConstraintToFields> mapDecisionsToFields(ConstraintNode node) {
Expand Down
Loading

0 comments on commit faac22e

Please sign in to comment.