Refactor RSQL searach fields related classes (3) (#1836)

Signed-off-by: Marinov Avgustin <Avgustin.Marinov@bosch.com>
This commit is contained in:
Avgustin Marinov
2024-09-10 11:38:31 +03:00
committed by GitHub
parent 368c18ed5e
commit dd500b4d53
8 changed files with 127 additions and 113 deletions

View File

@@ -25,7 +25,7 @@ import java.util.Optional;
public enum DistributionSetFields implements RsqlQueryField {
ID("id"),
TYPE("type.key"),
TYPE("type", "key"),
NAME("name"),
DESCRIPTION("description"),
CREATEDAT("createdAt"),
@@ -33,27 +33,27 @@ public enum DistributionSetFields implements RsqlQueryField {
VERSION("version"),
COMPLETE("complete"),
MODULE("modules", SoftwareModuleFields.ID.getJpaEntityFieldName(), SoftwareModuleFields.NAME.getJpaEntityFieldName()),
TAG("tags.name"),
TAG("tags", "name"),
METADATA("metadata", new SimpleImmutableEntry<>("key", "value")),
VALID("valid");
private final String jpaEntityFieldName;
private final Entry<String, String> subEntityMapTuple;
private final List<String> subEntityAttributes;
private final Entry<String, String> subEntityMapTuple;
DistributionSetFields(final String jpaEntityFieldName) {
this(jpaEntityFieldName, null, Collections.emptyList());
this(jpaEntityFieldName, Collections.emptyList(), null);
}
DistributionSetFields(final String jpaEntityFieldName, final String... subEntityAttributes) {
this(jpaEntityFieldName, null, List.of(subEntityAttributes));
this(jpaEntityFieldName, List.of(subEntityAttributes), null);
}
DistributionSetFields(final String jpaEntityFieldName, final Entry<String, String> subEntityMapTuple) {
this(jpaEntityFieldName, subEntityMapTuple, Collections.emptyList());
this(jpaEntityFieldName, Collections.emptyList(), subEntityMapTuple);
}
DistributionSetFields(final String jpaEntityFieldName, final Entry<String, String> subEntityMapTuple, List<String> subEntityAttributes) {
DistributionSetFields(final String jpaEntityFieldName, List<String> subEntityAttributes, final Entry<String, String> subEntityMapTuple) {
this.jpaEntityFieldName = jpaEntityFieldName;
this.subEntityMapTuple = subEntityMapTuple;
this.subEntityAttributes = subEntityAttributes;

View File

@@ -35,23 +35,6 @@ public interface RsqlQueryField {
@NotNull
String getJpaEntityFieldName();
/**
* Returns the sub attributes
*
* @param propertyFieldName the given field
* @return array consisting of sub attributes
*/
default String[] getSubAttributes(final String propertyFieldName) {
if (isMap()) {
final String[] subAttributes = propertyFieldName.split(SUB_ATTRIBUTE_SPLIT_REGEX, 2);
// [0] field name | [1] key name (could miss, e.g. for target attributes)
final String mapKeyName = subAttributes.length == 2 ? subAttributes[1] : null;
return ObjectUtils.isEmpty(mapKeyName) ? new String[] { getJpaEntityFieldName() } : new String[] { getJpaEntityFieldName(), mapKeyName };
} else {
return propertyFieldName.split(SUB_ATTRIBUTE_SPLIT_REGEX);
}
}
/**
* Contains the sub entity the given field.
*

View File

@@ -12,6 +12,8 @@ package org.eclipse.hawkbit.repository;
import lombok.Getter;
import java.util.AbstractMap.SimpleImmutableEntry;
import java.util.Collections;
import java.util.List;
import java.util.Map.Entry;
import java.util.Optional;
@@ -22,22 +24,31 @@ import java.util.Optional;
public enum SoftwareModuleFields implements RsqlQueryField {
ID("id"),
TYPE("type.key"),
TYPE("type", "key"),
NAME("name"),
DESCRIPTION("description"),
VERSION("version"),
METADATA("metadata", new SimpleImmutableEntry<>("key", "value"));
private final String jpaEntityFieldName;
private Entry<String, String> subEntityMapTuple;
private final List<String> subEntityAttributes;
private final Entry<String, String> subEntityMapTuple;
SoftwareModuleFields(final String jpaEntityFieldName) {
this(jpaEntityFieldName, null);
this(jpaEntityFieldName, Collections.emptyList(), null);
}
SoftwareModuleFields(final String jpaEntityFieldName, final String... subEntityAttributes) {
this(jpaEntityFieldName, List.of(subEntityAttributes), null);
}
SoftwareModuleFields(final String jpaEntityFieldName, final Entry<String, String> subEntityMapTuple) {
this(jpaEntityFieldName, Collections.emptyList(), subEntityMapTuple);
}
SoftwareModuleFields(final String jpaEntityFieldName, List<String> subEntityAttributes, final Entry<String, String> subEntityMapTuple) {
this.jpaEntityFieldName = jpaEntityFieldName;
this.subEntityMapTuple = subEntityMapTuple;
this.subEntityAttributes = subEntityAttributes;
}
@Override

View File

@@ -35,7 +35,7 @@ public enum TargetFields implements RsqlQueryField {
ATTRIBUTE("controllerAttributes"),
ASSIGNEDDS("assignedDistributionSet", "name", "version"),
INSTALLEDDS("installedDistributionSet", "name", "version"),
TAG("tags.name"),
TAG("tags", "name"),
LASTCONTROLLERREQUESTAT("lastTargetQuery"),
METADATA("metadata", new SimpleImmutableEntry<>("key", "value")),
TARGETTYPE("targetType", TargetTypeFields.KEY.getJpaEntityFieldName(), TargetTypeFields.NAME.getJpaEntityFieldName());