Merge pull request #258 from Kitzanos/feature/GEPAFINBE-201
GEPAFINBE-201 (Fix application filter for number value as string.)
This commit is contained in:
@@ -826,20 +826,48 @@ public class Utils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void applyNumberFilter(Path<?> fieldPath, CriteriaBuilder criteriaBuilder, List<Predicate> predicates, Object value, MatchModeEnum matchMode) {
|
public static void applyNumberFilter(Path<?> fieldPath, CriteriaBuilder criteriaBuilder, List<Predicate> predicates, Object value, MatchModeEnum matchMode) {
|
||||||
|
|
||||||
if (Number.class.isAssignableFrom(fieldPath.getJavaType())) {
|
if (Number.class.isAssignableFrom(fieldPath.getJavaType())) {
|
||||||
Number numberValue = null;
|
Number numberValue = null;
|
||||||
if (value instanceof Number) {
|
|
||||||
numberValue = (Number) value;
|
if (value instanceof String stringValue) {
|
||||||
|
if (isInteger(stringValue)) {
|
||||||
|
numberValue = Long.parseLong(stringValue);
|
||||||
|
} else if (isDecimal(stringValue)) {
|
||||||
|
numberValue = Double.parseDouble(stringValue);
|
||||||
|
}
|
||||||
|
} else if (value instanceof Number number) {
|
||||||
|
numberValue = number;
|
||||||
}
|
}
|
||||||
MatchModeEnum mode = MatchModeEnum.fromObject(matchMode.getValue());
|
if (numberValue != null) {
|
||||||
switch (mode) {
|
MatchModeEnum mode = MatchModeEnum.fromObject(matchMode.getValue());
|
||||||
case EQUALS -> predicates.add(criteriaBuilder.equal(fieldPath, numberValue));
|
|
||||||
|
if (mode == MatchModeEnum.EQUALS) {
|
||||||
|
predicates.add(criteriaBuilder.equal(fieldPath, numberValue));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static boolean isInteger(String value) {
|
||||||
|
|
||||||
|
try {
|
||||||
|
Long.parseLong(value);
|
||||||
|
return true;
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean isDecimal(String value) {
|
||||||
|
|
||||||
|
try {
|
||||||
|
Double.parseDouble(value);
|
||||||
|
return value.contains(".");
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static void applyDateFilter(Path<?> fieldPath, CriteriaBuilder criteriaBuilder, List<Predicate> predicates, Object value, MatchModeEnum matchMode, Root<?> root) {
|
public static void applyDateFilter(Path<?> fieldPath, CriteriaBuilder criteriaBuilder, List<Predicate> predicates, Object value, MatchModeEnum matchMode, Root<?> root) {
|
||||||
if (fieldPath.getJavaType().equals(LocalDateTime.class)) {
|
if (fieldPath.getJavaType().equals(LocalDateTime.class)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user