First level suppor for RsqlQueryFields shortcut support (#2686)

* now it is possible to have a showrtcut for a sub attributes (i.e. calling it directly with enum name, e.g. type -> type.key) with directly specifying the defaultSubEntityAttribute
* no need to have single sub attribute in order to have a default sub attribute
* added TYPE search field for TargetFields (sinonim of targettype)
* targettype is deprecated - to be decided if and when to be removed
* returned back "type" direct search (with meaning type.key) for DistributionSet and SoftwareModule as non-depricated
* add serche with "type" as type.key for Target

Signed-off-by: Avgustin Marinov <Avgustin.Marinov@bosch.com>
This commit is contained in:
Avgustin Marinov
2025-09-23 10:56:26 +03:00
committed by GitHub
parent d98ab779a2
commit 9ab0a8628e
11 changed files with 55 additions and 42 deletions

View File

@@ -46,6 +46,11 @@ public enum DistributionSetFields implements RsqlQueryField {
this.subEntityAttributes = List.of(subEntityAttributes);
}
@Override
public String getDefaultSubEntityAttribute() {
return this == TYPE ? DistributionSetTypeFields.KEY.getJpaEntityFieldName() : RsqlQueryField.super.getDefaultSubEntityAttribute();
}
@Override
public boolean isMap() {
return this == METADATA;

View File

@@ -20,7 +20,7 @@ package org.eclipse.hawkbit.repository;
public interface FieldValueConverter<T extends Enum<T>> {
/**
* Converts the given {@code value} into the representation to build ageneric query.
* Converts the given {@code value} into the representation to build a generic query.
*
* @param enumValue the enum value to build the value for
* @param value the value in string representation

View File

@@ -39,12 +39,22 @@ public interface RsqlQueryField {
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 identifierFieldName() {
default String getIdentifierFieldName() {
return "id";
}

View File

@@ -41,6 +41,12 @@ public enum SoftwareModuleFields implements RsqlQueryField {
this.subEntityAttributes = List.of(subEntityAttributes);
}
@Override
public String getDefaultSubEntityAttribute() {
return this == TYPE ? SoftwareModuleTypeFields.KEY.getJpaEntityFieldName() : RsqlQueryField.super.getDefaultSubEntityAttribute();
}
@Override
public boolean isMap() {
return this == METADATA;

View File

@@ -39,6 +39,14 @@ public enum TargetFields implements RsqlQueryField {
TAG("tags", TagFields.NAME.getJpaEntityFieldName()),
LASTCONTROLLERREQUESTAT("lastTargetQuery"),
METADATA("metadata"),
TYPE("targetType",
TargetTypeFields.ID.getJpaEntityFieldName(),
TargetTypeFields.KEY.getJpaEntityFieldName(),
TargetTypeFields.NAME.getJpaEntityFieldName()),
// 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(),
@@ -52,6 +60,11 @@ public enum TargetFields implements RsqlQueryField {
this.subEntityAttributes = List.of(subEntityAttributes);
}
@Override
public String getDefaultSubEntityAttribute() {
return this == TYPE ? TargetTypeFields.KEY.getJpaEntityFieldName() : RsqlQueryField.super.getDefaultSubEntityAttribute();
}
@Override
public boolean isMap() {
return this == ATTRIBUTE || this == METADATA;