Skip to content

Commit

Permalink
#48 - add packageName, simpleName and fieldName to MalioValidationExc…
Browse files Browse the repository at this point in the history
…eption - done (#49)
  • Loading branch information
FrankHossfeld authored Jun 10, 2023
1 parent 471670e commit fd145af
Show file tree
Hide file tree
Showing 26 changed files with 146 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
public class ArrayItemMaxLengthConstraint
extends AbstractConstraint<String> {

private int maxLength;
private final int maxLength;

public ArrayItemMaxLengthConstraint(String packageName,
String simpleName,
Expand All @@ -40,7 +40,10 @@ public ArrayItemMaxLengthConstraint(String packageName,
public void check(String value)
throws MalioValidationException {
if (value != null && value.length() > maxLength) {
throw new MalioValidationException(getMessage(value));
throw new MalioValidationException(getMessage(value),
super.getClassName(),
super.getSimpleName(),
super.getFieldName());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
public class ArrayItemMinLengthConstraint
extends AbstractConstraint<String> {

private int minLength;
private final int minLength;

public ArrayItemMinLengthConstraint(String packageName,
String simpleName,
Expand All @@ -40,7 +40,10 @@ public ArrayItemMinLengthConstraint(String packageName,
public void check(String value)
throws MalioValidationException {
if (value != null && value.length() < minLength) {
throw new MalioValidationException(getMessage(value));
throw new MalioValidationException(getMessage(value),
super.getClassName(),
super.getSimpleName(),
super.getFieldName());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ protected String getSpecializedMessage(String value) {
public void check(String value)
throws MalioValidationException {
if (Objects.nonNull(value) && value.isEmpty()) {
throw new MalioValidationException(getMessage(value));
throw new MalioValidationException(getMessage(value),
super.getClassName(),
super.getSimpleName(),
super.getFieldName());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ protected String getSpecializedMessage(T value) {
public void check(T value)
throws MalioValidationException {
if (Objects.isNull(value)) {
throw new MalioValidationException(getMessage(value));
throw new MalioValidationException(getMessage(value),
super.getClassName(),
super.getSimpleName(),
super.getFieldName());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,11 @@ public void check(Object[] value)

private void internCheck(int size) {
if (size < this.min || size > this.max) {
throw new MalioValidationException(getMessage(null));
throw new MalioValidationException(getMessage(null),
super.getClassName(),
super.getSimpleName(),
super.getFieldName());
}

}

public void isValid(Object[] value,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
public class BlacklistConstraint
extends AbstractConstraint<String> {

private List<String> blacklist;
private final List<String> blacklist;

public BlacklistConstraint(String packageName,
String simpleName,
Expand All @@ -44,7 +44,10 @@ public void check(String value)
throws MalioValidationException {

if (value != null && blacklist.contains(value)) {
throw new MalioValidationException(getMessage(value));
throw new MalioValidationException(getMessage(value),
super.getClassName(),
super.getSimpleName(),
super.getFieldName());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
public class CollectionItemMaxLengthConstraint
extends AbstractConstraint<String> {

private int maxLength;
private final int maxLength;

public CollectionItemMaxLengthConstraint(String packageName,
String simpleName,
Expand All @@ -40,7 +40,10 @@ public CollectionItemMaxLengthConstraint(String packageName,
public void check(String value)
throws MalioValidationException {
if (value != null && value.length() > maxLength) {
throw new MalioValidationException(getMessage(value));
throw new MalioValidationException(getMessage(value),
super.getClassName(),
super.getSimpleName(),
super.getFieldName());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
public class CollectionItemMinLengthConstraint
extends AbstractConstraint<String> {

private int minLength;
private final int minLength;

public CollectionItemMinLengthConstraint(String packageName,
String simpleName,
Expand All @@ -40,7 +40,10 @@ public CollectionItemMinLengthConstraint(String packageName,
public void check(String value)
throws MalioValidationException {
if (value != null && value.length() < minLength) {
throw new MalioValidationException(getMessage(value));
throw new MalioValidationException(getMessage(value),
super.getClassName(),
super.getSimpleName(),
super.getFieldName());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ protected String getSpecializedMessage(String value) {
public void check(String value)
throws MalioValidationException {
if (Objects.nonNull(value) && value.isEmpty()) {
throw new MalioValidationException(getMessage(value));
throw new MalioValidationException(getMessage(value),
super.getClassName(),
super.getSimpleName(),
super.getFieldName());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ protected String getSpecializedMessage(T value) {
public void check(T value)
throws MalioValidationException {
if (Objects.isNull(value)) {
throw new MalioValidationException(getMessage(value));
throw new MalioValidationException(getMessage(value),
super.getClassName(),
super.getSimpleName(),
super.getFieldName());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@ protected String getSpecializedMessage(String value) {
public void check(String value)
throws MalioValidationException {
if (Objects.nonNull(value) && !EmailConstraint.regExp.test(value)) {
throw new MalioValidationException(getMessage(value));
throw new MalioValidationException(getMessage(value),
super.getClassName(),
super.getSimpleName(),
super.getFieldName());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
public class MaxConstraint
extends AbstractConstraint<Number> {

private Long maxValue;
private final Long maxValue;

public MaxConstraint(String packageName,
String simpleName,
Expand All @@ -40,7 +40,10 @@ public MaxConstraint(String packageName,
public void check(Number value)
throws MalioValidationException {
if (value != null && value.longValue() > this.maxValue) {
throw new MalioValidationException(getMessage(value));
throw new MalioValidationException(getMessage(value),
super.getClassName(),
super.getSimpleName(),
super.getFieldName());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
public class MaxDecimalConstraint
extends AbstractConstraint<BigDecimal> {

private BigDecimal maxValue;
private final BigDecimal maxValue;

public MaxDecimalConstraint(String packageName,
String simpleName,
Expand All @@ -42,7 +42,10 @@ public MaxDecimalConstraint(String packageName,
public void check(BigDecimal value)
throws MalioValidationException {
if (value != null && value.compareTo(this.maxValue) > 0) {
throw new MalioValidationException(getMessage(value));
throw new MalioValidationException(getMessage(value),
super.getClassName(),
super.getSimpleName(),
super.getFieldName());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
public class MaxLengthConstraint
extends AbstractConstraint<String> {

private int maxLength;
private final int maxLength;

public MaxLengthConstraint(String packageName,
String simpleName,
Expand All @@ -40,7 +40,10 @@ public MaxLengthConstraint(String packageName,
public void check(String value)
throws MalioValidationException {
if (value != null && value.length() > maxLength) {
throw new MalioValidationException(getMessage(value));
throw new MalioValidationException(getMessage(value),
super.getClassName(),
super.getSimpleName(),
super.getFieldName());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
public class MinConstraint
extends AbstractConstraint<Number> {

private Long minValue;
private final Long minValue;

public MinConstraint(String packageName,
String simpleName,
Expand All @@ -40,7 +40,10 @@ public MinConstraint(String packageName,
public void check(Number value)
throws MalioValidationException {
if (value != null && value.longValue() < this.minValue) {
throw new MalioValidationException(getMessage(value));
throw new MalioValidationException(getMessage(value),
super.getClassName(),
super.getSimpleName(),
super.getFieldName());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
public class MinDecimalConstraint
extends AbstractConstraint<BigDecimal> {

private BigDecimal minValue;
private final BigDecimal minValue;

public MinDecimalConstraint(String packageName,
String simpleName,
Expand All @@ -42,7 +42,10 @@ public MinDecimalConstraint(String packageName,
public void check(BigDecimal value)
throws MalioValidationException {
if (value != null && value.compareTo(this.minValue) < 0) {
throw new MalioValidationException(getMessage(value));
throw new MalioValidationException(getMessage(value),
super.getClassName(),
super.getSimpleName(),
super.getFieldName());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
public class MinLengthConstraint
extends AbstractConstraint<String> {

private int minLength;
private final int minLength;

public MinLengthConstraint(String packageName,
String simpleName,
Expand All @@ -40,7 +40,10 @@ public MinLengthConstraint(String packageName,
public void check(String value)
throws MalioValidationException {
if (value != null && value.length() < minLength) {
throw new MalioValidationException(getMessage(value));
throw new MalioValidationException(getMessage(value),
super.getClassName(),
super.getSimpleName(),
super.getFieldName());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ protected String getSpecializedMessage(String value) {
public void check(String value)
throws MalioValidationException {
if (Objects.nonNull(value) && value.isEmpty()) {
throw new MalioValidationException(getMessage(value));
throw new MalioValidationException(getMessage(value),
super.getClassName(),
super.getSimpleName(),
super.getFieldName());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@ protected String getSpecializedMessage(T value) {
public void check(T value)
throws MalioValidationException {
if (Objects.nonNull(value) && value.isEmpty()) {
throw new MalioValidationException(getMessage(value));
throw new MalioValidationException(getMessage(value),
super.getClassName(),
super.getSimpleName(),
super.getFieldName());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ protected String getSpecializedMessage(T value) {
public void check(T value)
throws MalioValidationException {
if (Objects.isNull(value)) {
throw new MalioValidationException(getMessage(value));
throw new MalioValidationException(getMessage(value),
super.getClassName(),
super.getSimpleName(),
super.getFieldName());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
public class NotZeroConstraint
extends AbstractConstraint<Number> {

private boolean allowNegativeValues;
private final boolean allowNegativeValues;

public NotZeroConstraint(String packageName,
String simpleName,
Expand All @@ -47,12 +47,18 @@ public void check(Number value)

if (!this.allowNegativeValues) {
if (value.longValue() < 0) {
throw new MalioValidationException(getMessage(value));
throw new MalioValidationException(getMessage(value),
super.getClassName(),
super.getSimpleName(),
super.getFieldName());
}
}

if (value.longValue() == 0) {
throw new MalioValidationException(getMessage(value));
throw new MalioValidationException(getMessage(value),
super.getClassName(),
super.getSimpleName(),
super.getFieldName());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
public class RegexpConstraint
extends AbstractConstraint<String> {

private RegExp regExp;
private final RegExp regExp;

public RegexpConstraint(String packageName,
String simpleName,
Expand All @@ -42,7 +42,10 @@ public void check(String value)
throws MalioValidationException {
if (value != null) {
if (!this.regExp.test(value)) {
throw new MalioValidationException(getMessage(value));
throw new MalioValidationException(getMessage(value),
super.getClassName(),
super.getSimpleName(),
super.getFieldName());
}
}
}
Expand Down
Loading

0 comments on commit fd145af

Please sign in to comment.