Extract QL support in a top level module (#2808)

Signed-off-by: Avgustin Marinov <Avgustin.Marinov@bosch.com>
This commit is contained in:
Avgustin Marinov
2025-11-14 14:19:36 +02:00
committed by GitHub
parent df4464406e
commit c5ea265e0f
71 changed files with 454 additions and 485 deletions

View File

@@ -1,41 +0,0 @@
/**
* Copyright (c) 2015 Bosch Software Innovations GmbH and others
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.eclipse.hawkbit.repository.exception;
import java.io.Serial;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import org.eclipse.hawkbit.exception.AbstractServerRtException;
import org.eclipse.hawkbit.exception.SpServerError;
/**
* Exception used by the REST API in case of RSQL search filter query.
*/
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public abstract class QueryException extends AbstractServerRtException {
QueryException(final SpServerError error) {
super(error);
}
QueryException(final SpServerError error, final String message) {
super(error, message);
}
QueryException(final SpServerError error, final Throwable cause) {
super(error, cause);
}
QueryException(final SpServerError error, final String message, final Throwable cause) {
super(error, message, cause);
}
}

View File

@@ -21,7 +21,7 @@ import org.eclipse.hawkbit.exception.SpServerError;
*/
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class RSQLParameterSyntaxException extends QueryException {
public class RSQLParameterSyntaxException extends AbstractServerRtException {
@Serial
private static final long serialVersionUID = 1L;

View File

@@ -21,7 +21,7 @@ import org.eclipse.hawkbit.exception.SpServerError;
*/
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class RSQLParameterUnsupportedFieldException extends QueryException {
public class RSQLParameterUnsupportedFieldException extends AbstractServerRtException {
@Serial
private static final long serialVersionUID = 1L;

View File

@@ -12,6 +12,7 @@ package org.eclipse.hawkbit.repository.qfields;
import java.util.List;
import lombok.Getter;
import org.eclipse.hawkbit.ql.QueryField;
/**
* Sort and search fields for actions.
@@ -29,21 +30,21 @@ public enum ActionFields implements QueryField {
LASTMODIFIEDBY("lastModifiedBy"),
WEIGHT("weight"),
TARGET("target",
TargetFields.ID.getJpaEntityFieldName(), TargetFields.NAME.getJpaEntityFieldName(),
TargetFields.UPDATESTATUS.getJpaEntityFieldName(), TargetFields.IPADDRESS.getJpaEntityFieldName()),
TargetFields.ID.getName(), TargetFields.NAME.getName(),
TargetFields.UPDATESTATUS.getName(), TargetFields.IPADDRESS.getName()),
DISTRIBUTIONSET("distributionSet",
DistributionSetFields.ID.getJpaEntityFieldName(),
DistributionSetFields.NAME.getJpaEntityFieldName(), DistributionSetFields.VERSION.getJpaEntityFieldName(),
DistributionSetFields.TYPE.getJpaEntityFieldName()),
ROLLOUT("rollout", RolloutFields.ID.getJpaEntityFieldName(), RolloutFields.NAME.getJpaEntityFieldName()),
ROLLOUTGROUP("rolloutGroup", RolloutGroupFields.ID.getJpaEntityFieldName(), RolloutGroupFields.NAME.getJpaEntityFieldName()),
DistributionSetFields.ID.getName(),
DistributionSetFields.NAME.getName(), DistributionSetFields.VERSION.getName(),
DistributionSetFields.TYPE.getName()),
ROLLOUT("rollout", RolloutFields.ID.getName(), RolloutFields.NAME.getName()),
ROLLOUTGROUP("rolloutGroup", RolloutGroupFields.ID.getName(), RolloutGroupFields.NAME.getName()),
EXTERNALREF("externalRef");
private final String jpaEntityFieldName;
private final String name;
private final List<String> subEntityAttributes;
ActionFields(final String jpaEntityFieldName, final String... subEntityAttributes) {
this.jpaEntityFieldName = jpaEntityFieldName;
ActionFields(final String name, final String... subEntityAttributes) {
this.name = name;
this.subEntityAttributes = List.of(subEntityAttributes);
}
}

View File

@@ -10,6 +10,7 @@
package org.eclipse.hawkbit.repository.qfields;
import lombok.Getter;
import org.eclipse.hawkbit.ql.QueryField;
/**
* Sort and search fields for action status.
@@ -25,9 +26,9 @@ public enum ActionStatusFields implements QueryField {
CREATEDAT("createdAt"), // same as REPORTEDAT
CREATEDBY("createdBy");
private final String jpaEntityFieldName;
private final String name;
ActionStatusFields(final String jpaEntityFieldName) {
this.jpaEntityFieldName = jpaEntityFieldName;
ActionStatusFields(final String name) {
this.name = name;
}
}

View File

@@ -12,6 +12,7 @@ package org.eclipse.hawkbit.repository.qfields;
import java.util.List;
import lombok.Getter;
import org.eclipse.hawkbit.ql.QueryField;
/**
* Describing the fields of the DistributionSet model which can be used in the
@@ -22,9 +23,9 @@ public enum DistributionSetFields implements QueryField {
ID("id"),
TYPE("type",
DistributionSetTypeFields.ID.getJpaEntityFieldName(),
DistributionSetTypeFields.KEY.getJpaEntityFieldName(),
DistributionSetTypeFields.NAME.getJpaEntityFieldName()),
DistributionSetTypeFields.ID.getName(),
DistributionSetTypeFields.KEY.getName(),
DistributionSetTypeFields.NAME.getName()),
NAME("name"),
DESCRIPTION("description"),
CREATEDAT("createdAt"),
@@ -32,22 +33,22 @@ public enum DistributionSetFields implements QueryField {
LASTMODIFIEDAT("lastModifiedAt"),
LASTMODIFIEDBY("lastModifiedBy"),
VERSION("version"),
MODULE("modules", SoftwareModuleFields.ID.getJpaEntityFieldName(), SoftwareModuleFields.NAME.getJpaEntityFieldName()),
MODULE("modules", SoftwareModuleFields.ID.getName(), SoftwareModuleFields.NAME.getName()),
TAG("tags", "name"),
METADATA("metadata"),
VALID("valid");
private final String jpaEntityFieldName;
private final String name;
private final List<String> subEntityAttributes;
DistributionSetFields(final String jpaEntityFieldName, final String... subEntityAttributes) {
this.jpaEntityFieldName = jpaEntityFieldName;
DistributionSetFields(final String name, final String... subEntityAttributes) {
this.name = name;
this.subEntityAttributes = List.of(subEntityAttributes);
}
@Override
public String getDefaultSubEntityAttribute() {
return this == TYPE ? DistributionSetTypeFields.KEY.getJpaEntityFieldName() : QueryField.super.getDefaultSubEntityAttribute();
return this == TYPE ? DistributionSetTypeFields.KEY.getName() : QueryField.super.getDefaultSubEntityAttribute();
}
@Override

View File

@@ -12,6 +12,7 @@ package org.eclipse.hawkbit.repository.qfields;
import java.util.List;
import lombok.Getter;
import org.eclipse.hawkbit.ql.QueryField;
/**
* Describing the fields of the Tag model which can be used in the REST API e.g.
@@ -22,23 +23,23 @@ import lombok.Getter;
@Getter
public enum DistributionSetTagFields implements QueryField {
ID(TagFields.ID.getJpaEntityFieldName()),
NAME(TagFields.NAME.getJpaEntityFieldName()),
DESCRIPTION(TagFields.DESCRIPTION.getJpaEntityFieldName()),
COLOUR(TagFields.COLOUR.getJpaEntityFieldName()),
ID(TagFields.ID.getName()),
NAME(TagFields.NAME.getName()),
DESCRIPTION(TagFields.DESCRIPTION.getName()),
COLOUR(TagFields.COLOUR.getName()),
CREATEDAT("createdAt"),
CREATEDBY("createdBy"),
LASTMODIFIEDAT("lastModifiedAt"),
LASTMODIFIEDBY("lastModifiedBy"),
DISTRIBUTIONSET(
"assignedToDistributionSet",
DistributionSetFields.ID.getJpaEntityFieldName(), DistributionSetFields.NAME.getJpaEntityFieldName());
DistributionSetFields.ID.getName(), DistributionSetFields.NAME.getName());
private final String jpaEntityFieldName;
private final String name;
private final List<String> subEntityAttributes;
DistributionSetTagFields(final String jpaEntityFieldName, final String... subEntityAttributes) {
this.jpaEntityFieldName = jpaEntityFieldName;
DistributionSetTagFields(final String name, final String... subEntityAttributes) {
this.name = name;
this.subEntityAttributes = List.of(subEntityAttributes);
}
}

View File

@@ -10,6 +10,7 @@
package org.eclipse.hawkbit.repository.qfields;
import lombok.Getter;
import org.eclipse.hawkbit.ql.QueryField;
/**
* Describing the fields of the DistributionSetType model which can be used in
@@ -27,9 +28,9 @@ public enum DistributionSetTypeFields implements QueryField {
LASTMODIFIEDAT("lastModifiedAt"),
LASTMODIFIEDBY("lastModifiedBy");
private final String jpaEntityFieldName;
private final String name;
DistributionSetTypeFields(final String jpaEntityFieldName) {
this.jpaEntityFieldName = jpaEntityFieldName;
DistributionSetTypeFields(final String name) {
this.name = name;
}
}

View File

@@ -1,69 +0,0 @@
/**
* Copyright (c) 2015 Bosch Software Innovations GmbH and others
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.eclipse.hawkbit.repository.qfields;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import jakarta.validation.constraints.NotNull;
/**
* A query field interface extended by all the fields that could be used in queries.
*/
public interface QueryField {
/**
* Separator for the sub attributes
*/
String SUB_ATTRIBUTE_SEPARATOR = ".";
String SUB_ATTRIBUTE_SPLIT_REGEX = "\\" + SUB_ATTRIBUTE_SEPARATOR;
/**
* @return the string representation of the underlying persistence field name e.g. in case of sorting.
*/
@NotNull
String getJpaEntityFieldName();
/**
* @return all sub entities attributes.
*/
default List<String> getSubEntityAttributes() {
return Collections.emptyList();
}
/**
* Return the default sub entity attribute if available. This allows to skip that sub-attribute and call with "shortcut" - the enum name
*
* @return the default sub-attribute or <code>null</code>> if no default is available
*/
default String getDefaultSubEntityAttribute() {
final List<String> subAttributes = getSubEntityAttributes();
return subAttributes.size() == 1 ? subAttributes.get(0) : null;
}
/**
* Returns the name of the field, that identifies the entity.
*
* @return the name of the identifier, by default 'id'
*/
default String getIdentifierFieldName() {
return "id";
}
/**
* Is the entity field a {@link Map} consisting of key-value pairs.
*
* @return <code>true</code> is a map <code>false</code> is not a map
*/
default boolean isMap() {
return false;
}
}

View File

@@ -12,6 +12,7 @@ package org.eclipse.hawkbit.repository.qfields;
import java.util.List;
import lombok.Getter;
import org.eclipse.hawkbit.ql.QueryField;
/**
* Describing the fields of the Rollout model which can be used in the REST API e.g. for sorting etc.
@@ -29,15 +30,15 @@ public enum RolloutFields implements QueryField {
LASTMODIFIEDBY("lastModifiedBy"),
DISTRIBUTIONSET(
"distributionSet",
DistributionSetFields.ID.getJpaEntityFieldName(),
DistributionSetFields.NAME.getJpaEntityFieldName(), DistributionSetFields.VERSION.getJpaEntityFieldName(),
DistributionSetFields.TYPE.getJpaEntityFieldName());
DistributionSetFields.ID.getName(),
DistributionSetFields.NAME.getName(), DistributionSetFields.VERSION.getName(),
DistributionSetFields.TYPE.getName());
private final String jpaEntityFieldName;
private final String name;
private final List<String> subEntityAttributes;
RolloutFields(final String jpaEntityFieldName, final String... subEntityAttributes) {
this.jpaEntityFieldName = jpaEntityFieldName;
RolloutFields(final String name, final String... subEntityAttributes) {
this.name = name;
this.subEntityAttributes = List.of(subEntityAttributes);
}
}

View File

@@ -10,6 +10,7 @@
package org.eclipse.hawkbit.repository.qfields;
import lombok.Getter;
import org.eclipse.hawkbit.ql.QueryField;
/**
* Describing the fields of the RolloutGroup model which can be used in the REST API e.g. for sorting etc.
@@ -25,9 +26,9 @@ public enum RolloutGroupFields implements QueryField {
LASTMODIFIEDAT("lastModifiedAt"),
LASTMODIFIEDBY("lastModifiedBy");
private final String jpaEntityFieldName;
private final String name;
RolloutGroupFields(final String jpaEntityFieldName) {
this.jpaEntityFieldName = jpaEntityFieldName;
RolloutGroupFields(final String name) {
this.name = name;
}
}

View File

@@ -12,6 +12,7 @@ package org.eclipse.hawkbit.repository.qfields;
import java.util.List;
import lombok.Getter;
import org.eclipse.hawkbit.ql.QueryField;
/**
* Describing the fields of the SoftwareModule model which can be used in the REST API e.g. for sorting etc.
@@ -21,9 +22,9 @@ public enum SoftwareModuleFields implements QueryField {
ID("id"),
TYPE("type",
SoftwareModuleTypeFields.ID.getJpaEntityFieldName(),
SoftwareModuleTypeFields.KEY.getJpaEntityFieldName(),
SoftwareModuleTypeFields.NAME.getJpaEntityFieldName()),
SoftwareModuleTypeFields.ID.getName(),
SoftwareModuleTypeFields.KEY.getName(),
SoftwareModuleTypeFields.NAME.getName()),
NAME("name"),
DESCRIPTION("description"),
VERSION("version"),
@@ -33,18 +34,18 @@ public enum SoftwareModuleFields implements QueryField {
LASTMODIFIEDAT("lastModifiedAt"),
LASTMODIFIEDBY("lastModifiedBy");
private final String jpaEntityFieldName;
private final String name;
private final List<String> subEntityAttributes;
SoftwareModuleFields(final String jpaEntityFieldName, final String... subEntityAttributes) {
this.jpaEntityFieldName = jpaEntityFieldName;
SoftwareModuleFields(final String name, final String... subEntityAttributes) {
this.name = name;
this.subEntityAttributes = List.of(subEntityAttributes);
}
@Override
public String getDefaultSubEntityAttribute() {
return this == TYPE ? SoftwareModuleTypeFields.KEY.getJpaEntityFieldName() : QueryField.super.getDefaultSubEntityAttribute();
return this == TYPE ? SoftwareModuleTypeFields.KEY.getName() : QueryField.super.getDefaultSubEntityAttribute();
}
@Override

View File

@@ -10,6 +10,7 @@
package org.eclipse.hawkbit.repository.qfields;
import lombok.Getter;
import org.eclipse.hawkbit.ql.QueryField;
/**
* Describing the fields of the SoftwareModuleType model which can be used in the REST API e.g. for sorting etc.
@@ -27,9 +28,9 @@ public enum SoftwareModuleTypeFields implements QueryField {
LASTMODIFIEDAT("lastModifiedAt"),
LASTMODIFIEDBY("lastModifiedBy");
private final String jpaEntityFieldName;
private final String name;
SoftwareModuleTypeFields(final String jpaEntityFieldName) {
this.jpaEntityFieldName = jpaEntityFieldName;
SoftwareModuleTypeFields(final String name) {
this.name = name;
}
}

View File

@@ -10,6 +10,7 @@
package org.eclipse.hawkbit.repository.qfields;
import lombok.Getter;
import org.eclipse.hawkbit.ql.QueryField;
/**
* Describing the fields of the Tag model which can be used in the REST API e.g. for sorting etc.
@@ -26,9 +27,9 @@ public enum TagFields implements QueryField {
LASTMODIFIEDAT("lastModifiedAt"),
LASTMODIFIEDBY("lastModifiedBy");
private final String jpaEntityFieldName;
private final String name;
TagFields(final String jpaEntityFieldName) {
this.jpaEntityFieldName = jpaEntityFieldName;
TagFields(final String name) {
this.name = name;
}
}

View File

@@ -12,6 +12,7 @@ package org.eclipse.hawkbit.repository.qfields;
import java.util.List;
import lombok.Getter;
import org.eclipse.hawkbit.ql.QueryField;
/**
* Describing the fields of the Target model which can be used in the REST API
@@ -33,36 +34,36 @@ public enum TargetFields implements QueryField {
ATTRIBUTE("controllerAttributes"),
GROUP("group"),
ASSIGNEDDS("assignedDistributionSet",
DistributionSetFields.NAME.getJpaEntityFieldName(), DistributionSetFields.VERSION.getJpaEntityFieldName()),
DistributionSetFields.NAME.getName(), DistributionSetFields.VERSION.getName()),
INSTALLEDDS("installedDistributionSet",
DistributionSetFields.NAME.getJpaEntityFieldName(), DistributionSetFields.VERSION.getJpaEntityFieldName()),
TAG("tags", TagFields.NAME.getJpaEntityFieldName()),
DistributionSetFields.NAME.getName(), DistributionSetFields.VERSION.getName()),
TAG("tags", TagFields.NAME.getName()),
LASTCONTROLLERREQUESTAT("lastTargetQuery"),
METADATA("metadata"),
TYPE("targetType",
TargetTypeFields.ID.getJpaEntityFieldName(),
TargetTypeFields.KEY.getJpaEntityFieldName(),
TargetTypeFields.NAME.getJpaEntityFieldName()),
TargetTypeFields.ID.getName(),
TargetTypeFields.KEY.getName(),
TargetTypeFields.NAME.getName()),
// kept just for backward compatibility for backward compatibility
// could be removed only if in the systems there are no active auto assignments or rollouts (dynamic or starting) with that condition
// to be reconsidered if and when to be removed
@Deprecated(forRemoval = true, since = "0.10.0")
TARGETTYPE("targetType",
TargetTypeFields.ID.getJpaEntityFieldName(),
TargetTypeFields.KEY.getJpaEntityFieldName(),
TargetTypeFields.NAME.getJpaEntityFieldName());
TargetTypeFields.ID.getName(),
TargetTypeFields.KEY.getName(),
TargetTypeFields.NAME.getName());
private final String jpaEntityFieldName;
private final String name;
private final List<String> subEntityAttributes;
TargetFields(final String jpaEntityFieldName, final String... subEntityAttributes) {
this.jpaEntityFieldName = jpaEntityFieldName;
TargetFields(final String name, final String... subEntityAttributes) {
this.name = name;
this.subEntityAttributes = List.of(subEntityAttributes);
}
@Override
public String getDefaultSubEntityAttribute() {
return this == TYPE ? TargetTypeFields.KEY.getJpaEntityFieldName() : QueryField.super.getDefaultSubEntityAttribute();
return this == TYPE ? TargetTypeFields.KEY.getName() : QueryField.super.getDefaultSubEntityAttribute();
}
@Override

View File

@@ -13,6 +13,7 @@ import java.util.Collections;
import java.util.List;
import lombok.Getter;
import org.eclipse.hawkbit.ql.QueryField;
/**
* Describing the fields of the Target model which can be used in the REST API e.g. for sorting etc.
@@ -28,19 +29,19 @@ public enum TargetFilterQueryFields implements QueryField {
LASTMODIFIEDBY("lastModifiedBy"),
AUTOASSIGNDISTRIBUTIONSET("autoAssignDistributionSet", "name", "version");
private final String jpaEntityFieldName;
private final String name;
private final List<String> subEntityAttributes;
TargetFilterQueryFields(final String jpaEntityFieldName) {
this(jpaEntityFieldName, Collections.emptyList());
TargetFilterQueryFields(final String name) {
this(name, Collections.emptyList());
}
TargetFilterQueryFields(final String jpaEntityFieldName, final String... subEntityAttribues) {
this(jpaEntityFieldName, List.of(subEntityAttribues));
TargetFilterQueryFields(final String name, final String... subEntityAttribues) {
this(name, List.of(subEntityAttribues));
}
TargetFilterQueryFields(final String jpaEntityFieldName, final List<String> subEntityAttribues) {
this.jpaEntityFieldName = jpaEntityFieldName;
TargetFilterQueryFields(final String name, final List<String> subEntityAttribues) {
this.name = name;
this.subEntityAttributes = subEntityAttribues;
}
}

View File

@@ -10,6 +10,7 @@
package org.eclipse.hawkbit.repository.qfields;
import lombok.Getter;
import org.eclipse.hawkbit.ql.QueryField;
/**
* Describing the fields of the Tag model which can be used in the REST API e.g. for sorting etc.
@@ -18,18 +19,18 @@ import lombok.Getter;
@Getter
public enum TargetTagFields implements QueryField {
ID(TagFields.ID.getJpaEntityFieldName()),
NAME(TagFields.NAME.getJpaEntityFieldName()),
DESCRIPTION(TagFields.DESCRIPTION.getJpaEntityFieldName()),
COLOUR(TagFields.COLOUR.getJpaEntityFieldName()),
ID(TagFields.ID.getName()),
NAME(TagFields.NAME.getName()),
DESCRIPTION(TagFields.DESCRIPTION.getName()),
COLOUR(TagFields.COLOUR.getName()),
CREATEDAT("createdAt"),
CREATEDBY("createdBy"),
LASTMODIFIEDAT("lastModifiedAt"),
LASTMODIFIEDBY("lastModifiedBy");
private final String jpaEntityFieldName;
private final String name;
TargetTagFields(final String jpaEntityFieldName) {
this.jpaEntityFieldName = jpaEntityFieldName;
TargetTagFields(final String name) {
this.name = name;
}
}

View File

@@ -10,6 +10,7 @@
package org.eclipse.hawkbit.repository.qfields;
import lombok.Getter;
import org.eclipse.hawkbit.ql.QueryField;
/**
* Describing the fields of the TargetType model which can be used in the REST API
@@ -26,9 +27,9 @@ public enum TargetTypeFields implements QueryField {
LASTMODIFIEDAT("lastModifiedAt"),
LASTMODIFIEDBY("lastModifiedBy");
private final String jpaEntityFieldName;
private final String name;
TargetTypeFields(final String jpaEntityFieldName) {
this.jpaEntityFieldName = jpaEntityFieldName;
TargetTypeFields(final String name) {
this.name = name;
}
}

View File

@@ -16,6 +16,7 @@ import java.util.List;
import io.github.classgraph.ClassGraph;
import io.github.classgraph.ClassInfo;
import io.github.classgraph.ScanResult;
import org.eclipse.hawkbit.ql.QueryField;
import org.junit.jupiter.api.Test;
class QueryFieldsTest {