Add simple value support for default query parser mapping (#2700)

Signed-off-by: Avgustin Marinov <Avgustin.Marinov@bosch.com>
This commit is contained in:
Avgustin Marinov
2025-09-26 17:09:42 +03:00
committed by GitHub
parent a6867219b1
commit 1954fbe829

View File

@@ -9,8 +9,8 @@
*/ */
package org.eclipse.hawkbit.repository.jpa.ql; package org.eclipse.hawkbit.repository.jpa.ql;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.Objects; import java.util.Objects;
import jakarta.persistence.EntityManager; import jakarta.persistence.EntityManager;
@@ -204,16 +204,31 @@ public class QLSupport {
return key; return key;
} }
// just extension points for subclasses // internal, override only if you really want to replace whole lists
protected <T extends Enum<T> & QueryField> Object mapValue(final Object value, final Comparison comparison, final Class<T> queryFieldType) { protected <T extends Enum<T> & QueryField> Object mapValue(
if (queryFieldType == (Class<?>)ActionFields.class && "active".equalsIgnoreCase(comparison.getKey())) { final Object value, final Comparison comparison, final Class<T> queryFieldType) {
if (value instanceof List) { if (value instanceof List<?> list) {
return ((List<?>)value).stream().map(DefaultQueryParser::mapActionStatus).toList(); final List<Object> mappedList = new ArrayList<>();
boolean modified = false;
for (final Object e : list) {
final Object mapped = mapSimpleValue(e, comparison, queryFieldType);
if (!Objects.equals(mapped, value)) {
modified = true;
}
mappedList.add(mapped);
}
return modified ? mappedList : list;
} else { } else {
return mapActionStatus(value); return mapSimpleValue(value, comparison, queryFieldType);
} }
} }
return value;
// just extension points for subclasses
protected <T extends Enum<T> & QueryField> Object mapSimpleValue(
final Object value, final Comparison comparison, final Class<T> queryFieldType) {
return queryFieldType == (Class<?>) ActionFields.class && "active".equalsIgnoreCase(comparison.getKey())
? mapActionStatus(value)
: value;
} }
private static Object mapActionStatus(final Object value) { private static Object mapActionStatus(final Object value) {