Add simple value support for default query parser mapping (#2700)
Signed-off-by: Avgustin Marinov <Avgustin.Marinov@bosch.com>
This commit is contained in:
@@ -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;
|
||||||
@@ -200,23 +200,38 @@ public class QLSupport {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// just extension points for subclasses
|
// just extension points for subclasses
|
||||||
protected <T extends Enum<T> & QueryField>Object mapKey(final String key, final Comparison comparison, final Class<T> queryFieldType) {
|
protected <T extends Enum<T> & QueryField> Object mapKey(final String key, final Comparison comparison, final Class<T> queryFieldType) {
|
||||||
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<>();
|
||||||
} else {
|
boolean modified = false;
|
||||||
return mapActionStatus(value);
|
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 {
|
||||||
|
return mapSimpleValue(value, comparison, queryFieldType);
|
||||||
}
|
}
|
||||||
return value;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Object mapActionStatus(final Object 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) {
|
||||||
final String strValue = String.valueOf(value);
|
final String strValue = String.valueOf(value);
|
||||||
if ("true".equalsIgnoreCase(strValue) || "false".equalsIgnoreCase(strValue)) {
|
if ("true".equalsIgnoreCase(strValue) || "false".equalsIgnoreCase(strValue)) {
|
||||||
return value;
|
return value;
|
||||||
|
|||||||
Reference in New Issue
Block a user