Simplify RSQL fields (#2416)

Signed-off-by: Avgustin Marinov <Avgustin.Marinov@bosch.com>
This commit is contained in:
Avgustin Marinov
2025-05-23 11:17:54 +03:00
committed by GitHub
parent 108f03848f
commit 8184aad13c
12 changed files with 64 additions and 175 deletions

View File

@@ -42,11 +42,6 @@ public enum ActionFields implements RsqlQueryField, FieldValueConverter<ActionFi
private final String jpaEntityFieldName;
private final List<String> subEntityAttributes;
ActionFields(final String jpaEntityFieldName) {
this.jpaEntityFieldName = jpaEntityFieldName;
this.subEntityAttributes = Collections.emptyList();
}
ActionFields(final String jpaEntityFieldName, final String... subEntityAttributes) {
this.jpaEntityFieldName = jpaEntityFieldName;
this.subEntityAttributes = List.of(subEntityAttributes);

View File

@@ -34,33 +34,19 @@ public enum DistributionSetFields implements RsqlQueryField {
COMPLETE("complete"),
MODULE("modules", SoftwareModuleFields.ID.getJpaEntityFieldName(), SoftwareModuleFields.NAME.getJpaEntityFieldName()),
TAG("tags", "name"),
METADATA("metadata", new SimpleImmutableEntry<>("key", "value")),
METADATA("metadata"),
VALID("valid");
private final String jpaEntityFieldName;
private final List<String> subEntityAttributes;
private final Entry<String, String> subEntityMapTuple;
DistributionSetFields(final String jpaEntityFieldName) {
this(jpaEntityFieldName, Collections.emptyList(), null);
}
DistributionSetFields(final String jpaEntityFieldName, final String... subEntityAttributes) {
this(jpaEntityFieldName, List.of(subEntityAttributes), null);
}
DistributionSetFields(final String jpaEntityFieldName, final Entry<String, String> subEntityMapTuple) {
this(jpaEntityFieldName, Collections.emptyList(), subEntityMapTuple);
}
DistributionSetFields(final String jpaEntityFieldName, List<String> subEntityAttributes, final Entry<String, String> subEntityMapTuple) {
this.jpaEntityFieldName = jpaEntityFieldName;
this.subEntityMapTuple = subEntityMapTuple;
this.subEntityAttributes = subEntityAttributes;
this.subEntityAttributes = List.of(subEntityAttributes);
}
@Override
public Optional<Entry<String, String>> getSubEntityMapTuple() {
return Optional.ofNullable(subEntityMapTuple);
public boolean isMap() {
return this == METADATA;
}
}

View File

@@ -27,17 +27,13 @@ public enum DistributionSetTagFields implements RsqlQueryField {
NAME(TagFields.NAME.getJpaEntityFieldName()),
DESCRIPTION(TagFields.DESCRIPTION.getJpaEntityFieldName()),
COLOUR(TagFields.COLOUR.getJpaEntityFieldName()),
DISTRIBUTIONSET("assignedToDistributionSet",
DISTRIBUTIONSET(
"assignedToDistributionSet",
DistributionSetFields.ID.getJpaEntityFieldName(), DistributionSetFields.NAME.getJpaEntityFieldName());
private final String jpaEntityFieldName;
private final List<String> subEntityAttributes;
DistributionSetTagFields(final String jpaEntityFieldName) {
this.jpaEntityFieldName = jpaEntityFieldName;
this.subEntityAttributes = Collections.emptyList();
}
DistributionSetTagFields(final String jpaEntityFieldName, final String... subEntityAttributes) {
this.jpaEntityFieldName = jpaEntityFieldName;
this.subEntityAttributes = List.of(subEntityAttributes);

View File

@@ -13,8 +13,7 @@ package org.eclipse.hawkbit.repository;
* A value convert which converts given string based values into an object which
* can be used for building generic queries. Mapping external API values e.g.
* REST API to inside representation on database. E.g. mapping 'pending' or
* 'finished' values in rest queries to Action#isActive boolean
* value.
* 'finished' values in rest queries to Action#isActive boolean value.
*
* @param <T> the enum parameter
*/

View File

@@ -24,18 +24,15 @@ public enum RolloutFields implements RsqlQueryField {
NAME("name"),
DESCRIPTION("description"),
STATUS("status"),
DISTRIBUTIONSET("distributionSet", DistributionSetFields.ID.getJpaEntityFieldName(),
DISTRIBUTIONSET(
"distributionSet",
DistributionSetFields.ID.getJpaEntityFieldName(),
DistributionSetFields.NAME.getJpaEntityFieldName(), DistributionSetFields.VERSION.getJpaEntityFieldName(),
DistributionSetFields.TYPE.getJpaEntityFieldName());
private final String jpaEntityFieldName;
private final List<String> subEntityAttributes;
RolloutFields(final String jpaEntityFieldName) {
this.jpaEntityFieldName = jpaEntityFieldName;
this.subEntityAttributes = Collections.emptyList();
}
RolloutFields(final String jpaEntityFieldName, final String... subEntityAttributes) {
this.jpaEntityFieldName = jpaEntityFieldName;
this.subEntityAttributes = List.of(subEntityAttributes);

View File

@@ -34,30 +34,6 @@ public interface RsqlQueryField {
@NotNull
String getJpaEntityFieldName();
/**
* Contains the sub entity the given field.
*
* @param propertyField the given field
* @return <code>true</code> contains <code>false</code> contains not
*/
default boolean containsSubEntityAttribute(final String propertyField) {
final List<String> subEntityAttributes = getSubEntityAttributes();
if (subEntityAttributes.contains(propertyField)) {
return true;
}
for (final String attribute : subEntityAttributes) {
final String[] graph = attribute.split(SUB_ATTRIBUTE_SPLIT_REGEX);
for (final String subAttribute : graph) {
if (subAttribute.equalsIgnoreCase(propertyField)) {
return true;
}
}
}
return false;
}
/**
* @return all sub entities attributes.
*/
@@ -65,22 +41,6 @@ public interface RsqlQueryField {
return Collections.emptyList();
}
/**
* @return a key/value tuple of a sub entity.
*/
default Optional<Entry<String, String>> getSubEntityMapTuple() {
return Optional.empty();
}
/**
* 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 getSubEntityMapTuple().isPresent();
}
/**
* Returns the name of the field, that identifies the entity.
*
@@ -89,4 +49,13 @@ public interface RsqlQueryField {
default String identifierFieldName() {
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

@@ -45,25 +45,10 @@ public enum TargetFields implements RsqlQueryField {
private final String jpaEntityFieldName;
private final List<String> subEntityAttributes;
private final Entry<String, String> subEntityMapTuple;
TargetFields(final String jpaEntityFieldName) {
this(jpaEntityFieldName, Collections.emptyList(), null);
}
TargetFields(final String jpaEntityFieldName, final String... subEntityAttributes) {
this(jpaEntityFieldName, List.of(subEntityAttributes), null);
}
TargetFields(final String jpaEntityFieldName, final List<String> subEntityAttributes, final Entry<String, String> subEntityMapTuple) {
this.jpaEntityFieldName = jpaEntityFieldName;
this.subEntityAttributes = subEntityAttributes;
this.subEntityMapTuple = subEntityMapTuple;
}
@Override
public Optional<Entry<String, String>> getSubEntityMapTuple() {
return Optional.ofNullable(subEntityMapTuple);
this.subEntityAttributes = List.of(subEntityAttributes);
}
@Override

View File

@@ -25,7 +25,7 @@ public enum TargetFilterQueryFields implements RsqlQueryField {
AUTOASSIGNDISTRIBUTIONSET("autoAssignDistributionSet", "name", "version");
private final String jpaEntityFieldName;
private List<String> subEntityAttributes;
private final List<String> subEntityAttributes;
TargetFilterQueryFields(final String jpaEntityFieldName) {
this(jpaEntityFieldName, Collections.emptyList());

View File

@@ -36,12 +36,6 @@ class FileNameFieldsTest {
assertThat(matchingClasses).isNotEmpty();
matchingClasses.forEach(providerClass -> {
assertThat(providerClass.getEnumConstants()).isNotEmpty();
for (final RsqlQueryField provider : providerClass.getEnumConstants()) {
if (provider.isMap() && !provider.getSubEntityAttributes().isEmpty()) {
throw new UnsupportedOperationException(
"Currently sub-entity attributes for maps are not supported, alternatively you could use the key/value tuple, defined by SimpleImmutableEntry class");
}
}
});
}
}