This repository has been archived by the owner on Apr 14, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1460 from cdowding-sl/feature/profile-update/cons…
…traint-types Constraint types
- Loading branch information
Showing
279 changed files
with
3,694 additions
and
3,009 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 0 additions & 69 deletions
69
common/src/main/java/com/scottlogic/deg/common/profile/ConstraintType.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
common/src/main/java/com/scottlogic/deg/common/profile/HelixDateTime.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
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 = new DateTimeFormatterBuilder() | ||
.append(DateTimeFormatter.ofPattern("u-MM-dd'T'HH:mm:ss'.'SSS")) | ||
.optionalStart() | ||
.appendOffset("+HH", "Z") | ||
.toFormatter() | ||
.withResolverStyle(ResolverStyle.STRICT); | ||
|
||
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: yyyy-MM-ddTHH:mm:ss.SSS[Z] between (inclusive) " + | ||
"0001-01-01T00:00:00.000Z and 9999-12-31T23:59:59.999Z", 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"); | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
common/src/main/java/com/scottlogic/deg/common/profile/HelixNumber.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
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())); | ||
} | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
common/src/main/java/com/scottlogic/deg/common/profile/HelixStringLength.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
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())); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 0 additions & 45 deletions
45
...in/java/com/scottlogic/deg/common/profile/constraintdetail/NumericGranularityFactory.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
common/src/main/java/com/scottlogic/deg/common/util/defaults/DateTimeDefaults.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.