Simplify RSQL fields (#2416)
Signed-off-by: Avgustin Marinov <Avgustin.Marinov@bosch.com>
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
|
||||
@@ -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
|
||||
*/
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
|
||||
@@ -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());
|
||||
|
||||
Reference in New Issue
Block a user