Small serach fields refactoring (add lombok & style) (#1823)

Signed-off-by: Marinov Avgustin <Avgustin.Marinov@bosch.com>
This commit is contained in:
Avgustin Marinov
2024-08-23 12:24:29 +03:00
committed by GitHub
parent ac34b952d9
commit 55cc600114
23 changed files with 238 additions and 693 deletions

View File

@@ -9,110 +9,57 @@
*/ */
package org.eclipse.hawkbit.repository; package org.eclipse.hawkbit.repository;
import java.util.Arrays; import lombok.Getter;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
/** /**
* Sort and search fields for actions. * Sort and search fields for actions.
*/ */
@Getter
public enum ActionFields implements FieldNameProvider, FieldValueConverter<ActionFields> { public enum ActionFields implements FieldNameProvider, FieldValueConverter<ActionFields> {
/**
* The status field.
*/
STATUS("active"),
/**
* The detailed action status
*/
DETAILSTATUS("status"),
/**
* The last action status code
*/
LASTSTATUSCODE("lastActionStatusCode"),
/**
* The id field.
*/
ID("id"), ID("id"),
STATUS("active"),
/** DETAILSTATUS("status"),
* The weight field. LASTSTATUSCODE("lastActionStatusCode"),
*/
WEIGHT("weight"), WEIGHT("weight"),
TARGET("target",
/** TargetFields.ID.getFieldName(), TargetFields.NAME.getFieldName(),
* The target field
*/
TARGET("target", TargetFields.ID.getFieldName(), TargetFields.NAME.getFieldName(),
TargetFields.UPDATESTATUS.getFieldName(), TargetFields.IPADDRESS.getFieldName()), TargetFields.UPDATESTATUS.getFieldName(), TargetFields.IPADDRESS.getFieldName()),
DISTRIBUTIONSET("distributionSet",
/** DistributionSetFields.ID.getFieldName(),
* The distribution set field
*/
DISTRIBUTIONSET("distributionSet", DistributionSetFields.ID.getFieldName(),
DistributionSetFields.NAME.getFieldName(), DistributionSetFields.VERSION.getFieldName(), DistributionSetFields.NAME.getFieldName(), DistributionSetFields.VERSION.getFieldName(),
DistributionSetFields.TYPE.getFieldName()), DistributionSetFields.TYPE.getFieldName()),
/**
* The rollout field
*/
ROLLOUT("rollout", RolloutFields.ID.getFieldName(), RolloutFields.NAME.getFieldName()), ROLLOUT("rollout", RolloutFields.ID.getFieldName(), RolloutFields.NAME.getFieldName()),
/**
* The rollout field
*/
ROLLOUTGROUP("rolloutGroup", RolloutGroupFields.ID.getFieldName(), RolloutGroupFields.NAME.getFieldName()), ROLLOUTGROUP("rolloutGroup", RolloutGroupFields.ID.getFieldName(), RolloutGroupFields.NAME.getFieldName()),
/**
* The weight field.
*/
EXTERNALREF("externalRef"); EXTERNALREF("externalRef");
private static final String ACTIVE = "pending"; private static final String ACTIVE = "pending";
private static final String INACTIVE = "finished"; private static final String INACTIVE = "finished";
private final String fieldName; private final String fieldName;
private final List<String> subEntityAttributes;
private List<String> subEntityAttributes; ActionFields(final String fieldName) {
private ActionFields(final String fieldName) {
this.fieldName = fieldName; this.fieldName = fieldName;
this.subEntityAttributes = Collections.emptyList(); this.subEntityAttributes = Collections.emptyList();
} }
private ActionFields(final String fieldName, final String... subEntityAttributes) { ActionFields(final String fieldName, final String... subEntityAttributes) {
this.fieldName = fieldName; this.fieldName = fieldName;
this.subEntityAttributes = Arrays.asList(subEntityAttributes); this.subEntityAttributes = List.of(subEntityAttributes);
}
@Override
public List<String> getSubEntityAttributes() {
return subEntityAttributes;
}
@Override
public String getFieldName() {
return fieldName;
} }
@Override @Override
public Object convertValue(final ActionFields e, final String value) { public Object convertValue(final ActionFields e, final String value) {
if (STATUS == e) { return STATUS == e ? convertStatusValue(value) : value;
return convertStatusValue(value);
}
return value;
} }
@Override @Override
public String[] possibleValues(final ActionFields e) { public String[] possibleValues(final ActionFields e) {
if (STATUS == e) { return STATUS == e ? new String[] { ACTIVE, INACTIVE } : new String[0];
return new String[] { ACTIVE, INACTIVE };
}
return new String[0];
} }
private static Object convertStatusValue(final String value) { private static Object convertStatusValue(final String value) {

View File

@@ -9,33 +9,20 @@
*/ */
package org.eclipse.hawkbit.repository; package org.eclipse.hawkbit.repository;
import lombok.Getter;
/** /**
* Sort fields for {@link ActionStatusRest}. * Sort and search fields for action status.
*
*
*
*
*/ */
@Getter
public enum ActionStatusFields implements FieldNameProvider { public enum ActionStatusFields implements FieldNameProvider {
/**
* The id field.
*/
ID("id"), ID("id"),
/**
* The reportedAt field.
*/
REPORTEDAT("createdAt"); REPORTEDAT("createdAt");
private final String fieldName; private final String fieldName;
private ActionStatusFields(final String fieldName) { ActionStatusFields(final String fieldName) {
this.fieldName = fieldName; this.fieldName = fieldName;
} }
}
@Override
public String getFieldName() {
return fieldName;
}
}

View File

@@ -9,8 +9,9 @@
*/ */
package org.eclipse.hawkbit.repository; package org.eclipse.hawkbit.repository;
import lombok.Getter;
import java.util.AbstractMap.SimpleImmutableEntry; import java.util.AbstractMap.SimpleImmutableEntry;
import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Map.Entry; import java.util.Map.Entry;
@@ -19,104 +20,47 @@ import java.util.Optional;
/** /**
* Describing the fields of the DistributionSet model which can be used in the * Describing the fields of the DistributionSet model which can be used in the
* REST API e.g. for sorting etc. * REST API e.g. for sorting etc.
*
*
*
*
*/ */
@Getter
public enum DistributionSetFields implements FieldNameProvider { public enum DistributionSetFields implements FieldNameProvider {
/**
* The name field.
*/
NAME("name"),
/**
* The description field.
*/
DESCRIPTION("description"),
/**
* The createdAt field.
*/
CREATEDAT("createdAt"),
/**
* The lastModifiedAt field.
*/
LASTMODIFIEDAT("lastModifiedAt"),
/**
* The version field.
*/
VERSION("version"),
/**
* The complete field.
*/
COMPLETE("complete"),
/**
* The id field.
*/
ID("id"), ID("id"),
/**
* The module field.
*/
MODULE("modules", SoftwareModuleFields.ID.getFieldName(), SoftwareModuleFields.NAME.getFieldName()),
/**
* The tags field.
*/
TAG("tags.name"),
/**
* The sw type key field.
*/
TYPE("type.key"), TYPE("type.key"),
/** NAME("name"),
* The metadata. DESCRIPTION("description"),
*/ CREATEDAT("createdAt"),
LASTMODIFIEDAT("lastModifiedAt"),
VERSION("version"),
COMPLETE("complete"),
MODULE("modules", SoftwareModuleFields.ID.getFieldName(), SoftwareModuleFields.NAME.getFieldName()),
TAG("tags.name"),
METADATA("metadata", new SimpleImmutableEntry<>("key", "value")), METADATA("metadata", new SimpleImmutableEntry<>("key", "value")),
/**
* The valid field.
*/
VALID("valid"); VALID("valid");
private final String fieldName; private final String fieldName;
private boolean mapField; private final Entry<String, String> subEntityMapTuple;
private Entry<String, String> subEntityMapTuple;
private final List<String> subEntityAttributes; private final List<String> subEntityAttributes;
private DistributionSetFields(final String fieldName) { DistributionSetFields(final String fieldName) {
this(fieldName, false, null, Collections.emptyList()); this(fieldName, null, Collections.emptyList());
} }
private DistributionSetFields(final String fieldName, final String... subEntityAttributes) { DistributionSetFields(final String fieldName, final String... subEntityAttributes) {
this(fieldName, false, null, Arrays.asList(subEntityAttributes)); this(fieldName, null, List.of(subEntityAttributes));
} }
private DistributionSetFields(final String fieldName, final Entry<String, String> subEntityMapTuple) { DistributionSetFields(final String fieldName, final Entry<String, String> subEntityMapTuple) {
this(fieldName, true, subEntityMapTuple, Collections.emptyList()); this(fieldName, subEntityMapTuple, Collections.emptyList());
} }
private DistributionSetFields(final String fieldName, final boolean mapField, DistributionSetFields(final String fieldName, final Entry<String, String> subEntityMapTuple, List<String> subEntityAttributes) {
final Entry<String, String> subEntityMapTuple, List<String> subEntityAttributes) {
this.fieldName = fieldName; this.fieldName = fieldName;
this.mapField = mapField;
this.subEntityMapTuple = subEntityMapTuple; this.subEntityMapTuple = subEntityMapTuple;
this.subEntityAttributes = subEntityAttributes; this.subEntityAttributes = subEntityAttributes;
} }
@Override
public List<String> getSubEntityAttributes() {
return Collections.unmodifiableList(subEntityAttributes);
}
@Override @Override
public Optional<Entry<String, String>> getSubEntityMapTuple() { public Optional<Entry<String, String>> getSubEntityMapTuple() {
return Optional.ofNullable(subEntityMapTuple); return Optional.ofNullable(subEntityMapTuple);
} }
}
@Override
public boolean isMap() {
return mapField;
}
@Override
public String getFieldName() {
return fieldName;
}
}

View File

@@ -9,37 +9,25 @@
*/ */
package org.eclipse.hawkbit.repository; package org.eclipse.hawkbit.repository;
import lombok.Getter;
/** /**
* Sort fields for DistributionSetMetadata. * Sort fields for DistributionSetMetadata.
*
*
*
*
*/ */
@Getter
public enum DistributionSetMetadataFields implements FieldNameProvider { public enum DistributionSetMetadataFields implements FieldNameProvider {
/** KEY("key"),
* The value field. VALUE("value");
*/
VALUE("value"),
/**
* The key field.
*/
KEY("key");
private final String fieldName; private final String fieldName;
private DistributionSetMetadataFields(final String fieldName) { DistributionSetMetadataFields(final String fieldName) {
this.fieldName = fieldName; this.fieldName = fieldName;
} }
@Override
public String getFieldName() {
return fieldName;
}
@Override @Override
public String identifierFieldName() { public String identifierFieldName() {
return KEY.getFieldName(); return KEY.getFieldName();
} }
} }

View File

@@ -9,62 +9,37 @@
*/ */
package org.eclipse.hawkbit.repository; package org.eclipse.hawkbit.repository;
import java.util.Arrays; import lombok.Getter;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
/** /**
* Describing the fields of the Tag model which can be used in the REST API e.g. * Describing the fields of the Tag model which can be used in the REST API e.g.
* for sorting etc. * for sorting etc.
* Additionally here were added fields for DistributionSet in order * Additionally, here were added fields for DistributionSet in order
* filtering over distribution set fields also. * filtering over distribution set fields also.
*/ */
@Getter
public enum DistributionSetTagFields implements FieldNameProvider { public enum DistributionSetTagFields implements FieldNameProvider {
/**
* The id field.
*/
ID(TagFields.ID.getFieldName()), ID(TagFields.ID.getFieldName()),
/**
* The name field.
*/
NAME(TagFields.NAME.getFieldName()), NAME(TagFields.NAME.getFieldName()),
/**
* The description field.
*/
DESCRIPTION(TagFields.DESCRIPTION.getFieldName()), DESCRIPTION(TagFields.DESCRIPTION.getFieldName()),
/**
* The controllerId field.
*/
COLOUR(TagFields.COLOUR.getFieldName()), COLOUR(TagFields.COLOUR.getFieldName()),
/**
* Distribution set fields
*/
DISTRIBUTIONSET("assignedToDistributionSet", DISTRIBUTIONSET("assignedToDistributionSet",
DistributionSetFields.ID.getFieldName(), DistributionSetFields.NAME.getFieldName()); DistributionSetFields.ID.getFieldName(), DistributionSetFields.NAME.getFieldName());
private final String fieldName; private final String fieldName;
private final List<String> subEntityAttributes; private final List<String> subEntityAttributes;
private DistributionSetTagFields(final String fieldName) { DistributionSetTagFields(final String fieldName) {
this.fieldName = fieldName; this.fieldName = fieldName;
this.subEntityAttributes = Collections.emptyList(); this.subEntityAttributes = Collections.emptyList();
} }
private DistributionSetTagFields(final String fieldName, final String... subEntityAttributes) { DistributionSetTagFields(final String fieldName, final String... subEntityAttributes) {
this.fieldName = fieldName; this.fieldName = fieldName;
this.subEntityAttributes = Arrays.asList(subEntityAttributes); this.subEntityAttributes = List.of(subEntityAttributes);
}
@Override
public List<String> getSubEntityAttributes() {
return Collections.unmodifiableList(subEntityAttributes);
}
@Override
public String getFieldName() {
return fieldName;
} }
} }

View File

@@ -9,42 +9,23 @@
*/ */
package org.eclipse.hawkbit.repository; package org.eclipse.hawkbit.repository;
import lombok.Getter;
/** /**
* Describing the fields of the DistributionSetType model which can be used in * Describing the fields of the DistributionSetType model which can be used in
* the REST API e.g. for sorting etc. * the REST API e.g. for sorting etc.
*
*
*
*
*/ */
@Getter
public enum DistributionSetTypeFields implements FieldNameProvider { public enum DistributionSetTypeFields implements FieldNameProvider {
/**
* The name field.
*/
NAME("name"),
/**
* The description field.
*/
DESCRIPTION("description"),
/** ID("id"),
* The type key field.
*/
KEY("key"), KEY("key"),
NAME("name"),
/** DESCRIPTION("description");
* The id field.
*/
ID("id");
private final String fieldName; private final String fieldName;
private DistributionSetTypeFields(final String fieldName) { DistributionSetTypeFields(final String fieldName) {
this.fieldName = fieldName; this.fieldName = fieldName;
} }
@Override
public String getFieldName() {
return fieldName;
}
} }

View File

@@ -15,7 +15,7 @@ import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.Optional; import java.util.Optional;
import org.springframework.util.StringUtils; import org.springframework.util.ObjectUtils;
/** /**
* An interface for declaring the name of the field described in the database * An interface for declaring the name of the field described in the database
@@ -29,6 +29,7 @@ public interface FieldNameProvider {
* Separator for the sub attributes * Separator for the sub attributes
*/ */
String SUB_ATTRIBUTE_SEPARATOR = "."; String SUB_ATTRIBUTE_SEPARATOR = ".";
String SUB_ATTRIBUTE_SPLIT_REGEX = "\\" + SUB_ATTRIBUTE_SEPARATOR;
/** /**
* @return the string representation of the underlying persistence field * @return the string representation of the underlying persistence field
@@ -39,39 +40,36 @@ public interface FieldNameProvider {
/** /**
* Returns the sub attributes * Returns the sub attributes
* *
* @param propertyFieldName * @param propertyFieldName the given field
* the given field
* @return array consisting of sub attributes * @return array consisting of sub attributes
*/ */
default String[] getSubAttributes(final String propertyFieldName) { default String[] getSubAttributes(final String propertyFieldName) {
if (isMap()) { if (isMap()) {
final String[] subAttributes = propertyFieldName.split("\\" + SUB_ATTRIBUTE_SEPARATOR, 2); final String[] subAttributes = propertyFieldName.split(SUB_ATTRIBUTE_SPLIT_REGEX, 2);
// [0] fieldname |[1] keyname // [0] field name | [1] key name
final String mapKeyName = subAttributes.length == 2 ? subAttributes[1] : null; final String mapKeyName = subAttributes.length == 2 ? subAttributes[1] : null;
if (StringUtils.isEmpty(mapKeyName)) { if (ObjectUtils.isEmpty(mapKeyName)) {
return new String[] { getFieldName() }; return new String[] { getFieldName() };
} }
return new String[] { getFieldName(), mapKeyName }; return new String[] { getFieldName(), mapKeyName };
} }
return propertyFieldName.split("\\" + SUB_ATTRIBUTE_SEPARATOR); return propertyFieldName.split(SUB_ATTRIBUTE_SPLIT_REGEX);
} }
/** /**
* Contains the sub entity the given field. * Contains the sub entity the given field.
* *
* @param propertyField * @param propertyField the given field
* the given field
* @return <code>true</code> contains <code>false</code> contains not * @return <code>true</code> contains <code>false</code> contains not
*/ */
default boolean containsSubEntityAttribute(final String propertyField) { default boolean containsSubEntityAttribute(final String propertyField) {
final List<String> subEntityAttributes = getSubEntityAttributes(); final List<String> subEntityAttributes = getSubEntityAttributes();
if (subEntityAttributes.contains(propertyField)) { if (subEntityAttributes.contains(propertyField)) {
return true; return true;
} }
for (final String attribute : subEntityAttributes) {
final String[] graph = attribute.split("\\" + SUB_ATTRIBUTE_SEPARATOR);
for (final String attribute : subEntityAttributes) {
final String[] graph = attribute.split(SUB_ATTRIBUTE_SPLIT_REGEX);
for (final String subAttribute : graph) { for (final String subAttribute : graph) {
if (subAttribute.equalsIgnoreCase(propertyField)) { if (subAttribute.equalsIgnoreCase(propertyField)) {
return true; return true;
@@ -102,7 +100,7 @@ public interface FieldNameProvider {
* @return <code>true</code> is a map <code>false</code> is not a map * @return <code>true</code> is a map <code>false</code> is not a map
*/ */
default boolean isMap() { default boolean isMap() {
return false; return getSubEntityMapTuple().isPresent();
} }
/** /**
@@ -113,4 +111,4 @@ public interface FieldNameProvider {
default String identifierFieldName() { default String identifierFieldName() {
return "id"; return "id";
} }
} }

View File

@@ -13,25 +13,19 @@ package org.eclipse.hawkbit.repository;
* A value convert which converts given string based values into an object which * 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. * 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 * REST API to inside representation on database. E.g. mapping 'pending' or
* 'finished' values in rest queries to {@link TargetAction#isActive()} boolean * 'finished' values in rest queries to Action#isActive boolean
* value. * value.
*
*
*
* @param <T>
* the enum parameter
* *
* @param <T> the enum parameter
*/ */
public interface FieldValueConverter<T extends Enum<T>> { public interface FieldValueConverter<T extends Enum<T>> {
/** /**
* converts the given {@code value} into the representation to build a * Converts the given {@code value} into the representation to build a
* generic query. * generic query.
* *
* @param e * @param e the enum to build the value for
* the enum to build the value for * @param value the value in string representation
* @param value
* the value in string representation
* @return the converted object or {@code null} if conversation fails, if * @return the converted object or {@code null} if conversation fails, if
* given enum does not need to be converted the the unmodified * given enum does not need to be converted the the unmodified
* {@code value} is returned. * {@code value} is returned.
@@ -41,10 +35,8 @@ public interface FieldValueConverter<T extends Enum<T>> {
/** /**
* returns the possible values associated with the given enum type. * returns the possible values associated with the given enum type.
* *
* @param e * @param e the enum type to retrieve the possible values
* the enum type to retrieve the possible values
* @return the possible values for a specific enum or {@code null} * @return the possible values for a specific enum or {@code null}
*/ */
String[] possibleValues(final T e); String[] possibleValues(final T e);
}
}

View File

@@ -9,60 +9,35 @@
*/ */
package org.eclipse.hawkbit.repository; package org.eclipse.hawkbit.repository;
import java.util.Arrays; import lombok.Getter;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
/** /**
* Describing the fields of the Rollout model which can be used in the REST API * Describing the fields of the Rollout model which can be used in the REST API e.g. for sorting etc.
* e.g. for sorting etc.
*
*/ */
@Getter
public enum RolloutFields implements FieldNameProvider { public enum RolloutFields implements FieldNameProvider {
/**
* The name field.
*/
NAME("name"),
/**
* The description field.
*/
DESCRIPTION("description"),
/**
* The id field.
*/
ID("id"), ID("id"),
/** NAME("name"),
* The status field. DESCRIPTION("description"),
*/
STATUS("status"), STATUS("status"),
/**
* The Distribution set field.
*/
DISTRIBUTIONSET("distributionSet", DistributionSetFields.ID.getFieldName(), DISTRIBUTIONSET("distributionSet", DistributionSetFields.ID.getFieldName(),
DistributionSetFields.NAME.getFieldName(), DistributionSetFields.VERSION.getFieldName(), DistributionSetFields.NAME.getFieldName(), DistributionSetFields.VERSION.getFieldName(),
DistributionSetFields.TYPE.getFieldName()); DistributionSetFields.TYPE.getFieldName());
private final String fieldName; private final String fieldName;
private final List<String> subEntityAttributes; private final List<String> subEntityAttributes;
private RolloutFields(final String fieldName) { RolloutFields(final String fieldName) {
this.fieldName = fieldName; this.fieldName = fieldName;
this.subEntityAttributes = Collections.emptyList(); this.subEntityAttributes = Collections.emptyList();
} }
private RolloutFields(final String fieldName, final String... subEntityAttributes) { RolloutFields(final String fieldName, final String... subEntityAttributes) {
this.fieldName = fieldName; this.fieldName = fieldName;
this.subEntityAttributes = Arrays.asList(subEntityAttributes); this.subEntityAttributes = List.of(subEntityAttributes);
} }
}
@Override
public List<String> getSubEntityAttributes() {
return Collections.unmodifiableList(subEntityAttributes);
}
@Override
public String getFieldName() {
return fieldName;
}
}

View File

@@ -9,33 +9,21 @@
*/ */
package org.eclipse.hawkbit.repository; package org.eclipse.hawkbit.repository;
import lombok.Getter;
/** /**
* Describing the fields of the RolloutGroup model which can be used in the REST * Describing the fields of the RolloutGroup model which can be used in the REST API e.g. for sorting etc.
* API e.g. for sorting etc.
*
*/ */
@Getter
public enum RolloutGroupFields implements FieldNameProvider { public enum RolloutGroupFields implements FieldNameProvider {
/**
* The name field. ID("id"),
*/
NAME("name"), NAME("name"),
/** DESCRIPTION("description");
* The description field.
*/
DESCRIPTION("description"),
/**
* The id field.
*/
ID("id");
private final String fieldName; private final String fieldName;
private RolloutGroupFields(final String fieldName) { RolloutGroupFields(final String fieldName) {
this.fieldName = fieldName; this.fieldName = fieldName;
} }
@Override
public String getFieldName() {
return fieldName;
}
} }

View File

@@ -9,60 +9,34 @@
*/ */
package org.eclipse.hawkbit.repository; package org.eclipse.hawkbit.repository;
import lombok.Getter;
import java.util.AbstractMap.SimpleImmutableEntry; import java.util.AbstractMap.SimpleImmutableEntry;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.Optional; import java.util.Optional;
/** /**
* Describing the fields of the SoftwareModule model which can be used in the * Describing the fields of the SoftwareModule model which can be used in the REST API e.g. for sorting etc.
* REST API e.g. for sorting etc.
*
*
*
*
*/ */
@Getter
public enum SoftwareModuleFields implements FieldNameProvider { public enum SoftwareModuleFields implements FieldNameProvider {
/**
* The name field.
*/
NAME("name"),
/**
* The description field.
*/
DESCRIPTION("description"),
/**
* The description field.
*/
VERSION("version"),
/**
* The type field of the software module.
*/
TYPE("type.key"),
/**
* The id field.
*/
ID("id"), ID("id"),
/** TYPE("type.key"),
* The metadata. NAME("name"),
*/ DESCRIPTION("description"),
VERSION("version"),
METADATA("metadata", new SimpleImmutableEntry<>("key", "value")); METADATA("metadata", new SimpleImmutableEntry<>("key", "value"));
private final String fieldName; private final String fieldName;
private boolean mapField;
private Entry<String, String> subEntityMapTuple; private Entry<String, String> subEntityMapTuple;
private SoftwareModuleFields(final String fieldName) { SoftwareModuleFields(final String fieldName) {
this(fieldName, false, null); this(fieldName, null);
} }
private SoftwareModuleFields(final String fieldName, final Entry<String, String> subEntityMapTuple) { SoftwareModuleFields(final String fieldName, final Entry<String, String> subEntityMapTuple) {
this(fieldName, true, subEntityMapTuple);
}
private SoftwareModuleFields(final String fieldName, final boolean mapField,
final Entry<String, String> subEntityMapTuple) {
this.fieldName = fieldName; this.fieldName = fieldName;
this.mapField = mapField;
this.subEntityMapTuple = subEntityMapTuple; this.subEntityMapTuple = subEntityMapTuple;
} }
@@ -70,14 +44,4 @@ public enum SoftwareModuleFields implements FieldNameProvider {
public Optional<Entry<String, String>> getSubEntityMapTuple() { public Optional<Entry<String, String>> getSubEntityMapTuple() {
return Optional.ofNullable(subEntityMapTuple); return Optional.ofNullable(subEntityMapTuple);
} }
}
@Override
public boolean isMap() {
return mapField;
}
@Override
public String getFieldName() {
return fieldName;
}
}

View File

@@ -9,40 +9,24 @@
*/ */
package org.eclipse.hawkbit.repository; package org.eclipse.hawkbit.repository;
import lombok.Getter;
/** /**
* Sort fields for SoftwareModuleMetadata. * Sort fields for SoftwareModuleMetadata.
*
*
*
*
*/ */
@Getter
public enum SoftwareModuleMetadataFields implements FieldNameProvider { public enum SoftwareModuleMetadataFields implements FieldNameProvider {
/**
* The value field.
*/
VALUE("value"),
/**
* The key field.
*/
KEY("key"), KEY("key"),
VALUE("value"),
/**
* The target visible field.
*/
TARGETVISIBLE("targetVisible"); TARGETVISIBLE("targetVisible");
private final String fieldName; private final String fieldName;
private SoftwareModuleMetadataFields(final String fieldName) { SoftwareModuleMetadataFields(final String fieldName) {
this.fieldName = fieldName; this.fieldName = fieldName;
} }
@Override
public String getFieldName() {
return fieldName;
}
@Override @Override
public String identifierFieldName() { public String identifierFieldName() {
return KEY.getFieldName(); return KEY.getFieldName();

View File

@@ -9,44 +9,23 @@
*/ */
package org.eclipse.hawkbit.repository; package org.eclipse.hawkbit.repository;
import lombok.Getter;
/** /**
* Describing the fields of the SoftwareModuleType model which can be used in * Describing the fields of the SoftwareModuleType model which can be used in the REST API e.g. for sorting etc.
* the REST API e.g. for sorting etc.
*
*
*
*
*/ */
@Getter
public enum SoftwareModuleTypeFields implements FieldNameProvider { public enum SoftwareModuleTypeFields implements FieldNameProvider {
/**
* The name field.
*/
NAME("name"),
/**
* The description field.
*/
DESCRIPTION("description"),
/**
* The type key field.
*/
KEY("key"),
/**
* The id field.
*/
ID("id"), ID("id"),
/** KEY("key"),
* The max ds assignments field. NAME("name"),
*/ DESCRIPTION("description"),
MAXASSIGNMENTS("maxAssignments"); MAXASSIGNMENTS("maxAssignments");
private final String fieldName; private final String fieldName;
private SoftwareModuleTypeFields(final String fieldName) { SoftwareModuleTypeFields(final String fieldName) {
this.fieldName = fieldName; this.fieldName = fieldName;
} }
@Override
public String getFieldName() {
return fieldName;
}
} }

View File

@@ -9,38 +9,22 @@
*/ */
package org.eclipse.hawkbit.repository; package org.eclipse.hawkbit.repository;
/** import lombok.Getter;
* Describing the fields of the Tag model which can be used in the REST API e.g.
* for sorting etc.
*
*/
public enum TagFields implements FieldNameProvider {
/**
* The id field.
*/
ID("id"),
/** /**
* The name field. * Describing the fields of the Tag model which can be used in the REST API e.g. for sorting etc.
*/ */
@Getter
public enum TagFields implements FieldNameProvider {
ID("id"),
NAME("name"), NAME("name"),
/**
* The description field.
*/
DESCRIPTION("description"), DESCRIPTION("description"),
/**
* The controllerId field.
*/
COLOUR("colour"); COLOUR("colour");
private final String fieldName; private final String fieldName;
private TagFields(final String fieldName) { TagFields(final String fieldName) {
this.fieldName = fieldName; this.fieldName = fieldName;
} }
@Override
public String getFieldName() {
return fieldName;
}
} }

View File

@@ -9,8 +9,9 @@
*/ */
package org.eclipse.hawkbit.repository; package org.eclipse.hawkbit.repository;
import lombok.Getter;
import java.util.AbstractMap.SimpleImmutableEntry; import java.util.AbstractMap.SimpleImmutableEntry;
import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Map.Entry; import java.util.Map.Entry;
@@ -19,114 +20,48 @@ import java.util.Optional;
/** /**
* Describing the fields of the Target model which can be used in the REST API * Describing the fields of the Target model which can be used in the REST API
* e.g. for sorting etc. * e.g. for sorting etc.
*
*/ */
@Getter
public enum TargetFields implements FieldNameProvider { public enum TargetFields implements FieldNameProvider {
/**
* The controllerId field.
*/
ID("controllerId"), ID("controllerId"),
/**
* The name field.
*/
NAME("name"), NAME("name"),
/**
* The description field.
*/
DESCRIPTION("description"), DESCRIPTION("description"),
/**
* The createdAt field.
*/
CREATEDAT("createdAt"), CREATEDAT("createdAt"),
/**
* The createdAt field.
*/
LASTMODIFIEDAT("lastModifiedAt"), LASTMODIFIEDAT("lastModifiedAt"),
/**
* The controllerId field.
*/
CONTROLLERID("controllerId"), CONTROLLERID("controllerId"),
/**
* The updateStatus field.
*/
UPDATESTATUS("updateStatus"), UPDATESTATUS("updateStatus"),
/**
* The ip-address field.
*/
IPADDRESS("address"), IPADDRESS("address"),
ATTRIBUTE("controllerAttributes"),
/**
* The attribute map of target info.
*/
ATTRIBUTE("controllerAttributes", true),
/**
* distribution sets which is assigned to the target.
*/
ASSIGNEDDS("assignedDistributionSet", "name", "version"), ASSIGNEDDS("assignedDistributionSet", "name", "version"),
/**
* distribution sets which is installed on the target.
*/
INSTALLEDDS("installedDistributionSet", "name", "version"), INSTALLEDDS("installedDistributionSet", "name", "version"),
/**
* The tags field.
*/
TAG("tags.name"), TAG("tags.name"),
/**
* Last time the DDI or DMF client polled.
*/
LASTCONTROLLERREQUESTAT("lastTargetQuery"), LASTCONTROLLERREQUESTAT("lastTargetQuery"),
/**
* The metadata.
*/
METADATA("metadata", new SimpleImmutableEntry<>("key", "value")), METADATA("metadata", new SimpleImmutableEntry<>("key", "value")),
/**
* The target type.
*/
TARGETTYPE("targetType", TargetTypeFields.KEY.getFieldName(), TargetTypeFields.NAME.getFieldName()); TARGETTYPE("targetType", TargetTypeFields.KEY.getFieldName(), TargetTypeFields.NAME.getFieldName());
private final String fieldName; private final String fieldName;
private List<String> subEntityAttribues; private final List<String> subEntityAttributes;
private boolean mapField; private final Entry<String, String> subEntityMapTuple;
private Entry<String, String> subEntityMapTuple;
private TargetFields(final String fieldName) { TargetFields(final String fieldName) {
this(fieldName, false, Collections.emptyList(), null); this(fieldName, Collections.emptyList(), null);
} }
private TargetFields(final String fieldName, final boolean isMapField) { TargetFields(final String fieldName, final String... subEntityAttributes) {
this(fieldName, isMapField, Collections.emptyList(), null); this(fieldName, List.of(subEntityAttributes), null);
} }
private TargetFields(final String fieldName, final String... subEntityAttribues) { TargetFields(final String fieldName, final Entry<String, String> subEntityMapTuple) {
this(fieldName, false, Arrays.asList(subEntityAttribues), null); this(fieldName, Collections.emptyList(), subEntityMapTuple);
} }
private TargetFields(final String fieldName, final Entry<String, String> subEntityMapTuple) { TargetFields(final String fieldName, final List<String> subEntityAttributes, final Entry<String, String> subEntityMapTuple) {
this(fieldName, true, Collections.emptyList(), subEntityMapTuple);
}
private TargetFields(final String fieldName, final boolean mapField, final List<String> subEntityAttribues,
final Entry<String, String> subEntityMapTuple) {
this.fieldName = fieldName; this.fieldName = fieldName;
this.mapField = mapField; this.subEntityAttributes = subEntityAttributes;
this.subEntityAttribues = subEntityAttribues;
this.subEntityMapTuple = subEntityMapTuple; this.subEntityMapTuple = subEntityMapTuple;
} }
@Override
public List<String> getSubEntityAttributes() {
return subEntityAttribues;
}
@Override @Override
public Optional<Entry<String, String>> getSubEntityMapTuple() { public Optional<Entry<String, String>> getSubEntityMapTuple() {
return Optional.ofNullable(subEntityMapTuple); return Optional.ofNullable(subEntityMapTuple);
@@ -134,11 +69,6 @@ public enum TargetFields implements FieldNameProvider {
@Override @Override
public boolean isMap() { public boolean isMap() {
return mapField; return this == ATTRIBUTE || getSubEntityMapTuple().isPresent();
} }
}
@Override
public String getFieldName() {
return fieldName;
}
}

View File

@@ -9,55 +9,34 @@
*/ */
package org.eclipse.hawkbit.repository; package org.eclipse.hawkbit.repository;
import java.util.Arrays; import lombok.Getter;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
/** /**
* Describing the fields of the Target model which can be used in the REST API * Describing the fields of the Target model which can be used in the REST API e.g. for sorting etc.
* e.g. for sorting etc.
*
*/ */
@Getter
public enum TargetFilterQueryFields implements FieldNameProvider { public enum TargetFilterQueryFields implements FieldNameProvider {
/**
* The id field.
*/
ID("id"), ID("id"),
/**
* The name field.
*/
NAME("name"), NAME("name"),
/**
* Distribution set for auto-assignment.
*/
AUTOASSIGNDISTRIBUTIONSET("autoAssignDistributionSet", "name", "version"); AUTOASSIGNDISTRIBUTIONSET("autoAssignDistributionSet", "name", "version");
private final String fieldName; private final String fieldName;
private List<String> subEntityAttributes; private List<String> subEntityAttributes;
private TargetFilterQueryFields(final String fieldName) { TargetFilterQueryFields(final String fieldName) {
this(fieldName, Collections.emptyList()); this(fieldName, Collections.emptyList());
} }
private TargetFilterQueryFields(final String fieldName, final String... subEntityAttribues) { TargetFilterQueryFields(final String fieldName, final String... subEntityAttribues) {
this(fieldName, Arrays.asList(subEntityAttribues)); this(fieldName, List.of(subEntityAttribues));
} }
private TargetFilterQueryFields(final String fieldName, final List<String> subEntityAttribues) { TargetFilterQueryFields(final String fieldName, final List<String> subEntityAttribues) {
this.fieldName = fieldName; this.fieldName = fieldName;
this.subEntityAttributes = subEntityAttribues; this.subEntityAttributes = subEntityAttribues;
} }
@Override
public String getFieldName() {
return fieldName;
}
@Override
public List<String> getSubEntityAttributes() {
return subEntityAttributes;
}
} }

View File

@@ -9,32 +9,23 @@
*/ */
package org.eclipse.hawkbit.repository; package org.eclipse.hawkbit.repository;
import lombok.Getter;
/** /**
* Sort fields for TargetMetadata. * Sort fields for TargetMetadata.
*
*/ */
@Getter
public enum TargetMetadataFields implements FieldNameProvider { public enum TargetMetadataFields implements FieldNameProvider {
/** KEY("key"),
* The value field. VALUE("value");
*/
VALUE("value"),
/**
* The key field.
*/
KEY("key");
private final String fieldName; private final String fieldName;
private TargetMetadataFields(final String fieldName) { TargetMetadataFields(final String fieldName) {
this.fieldName = fieldName; this.fieldName = fieldName;
} }
@Override
public String getFieldName() {
return fieldName;
}
@Override @Override
public String identifierFieldName() { public String identifierFieldName() {
return KEY.getFieldName(); return KEY.getFieldName();

View File

@@ -9,29 +9,18 @@
*/ */
package org.eclipse.hawkbit.repository; package org.eclipse.hawkbit.repository;
/** import lombok.Getter;
* Describing the fields of the Tag model which can be used in the REST API e.g.
* for sorting etc.
* Additionally, here were added fields for Target in order
* filtering over target fields also.
*/
public enum TargetTagFields implements FieldNameProvider {
/**
* The id field.
*/
ID(TagFields.ID.getFieldName()),
/** /**
* The name field. * Describing the fields of the Tag model which can be used in the REST API e.g. for sorting etc.
*/ * Additionally, here were added fields for Target in order filtering over target fields also.
*/
@Getter
public enum TargetTagFields implements FieldNameProvider {
ID(TagFields.ID.getFieldName()),
NAME(TagFields.NAME.getFieldName()), NAME(TagFields.NAME.getFieldName()),
/**
* The description field.
*/
DESCRIPTION(TagFields.DESCRIPTION.getFieldName()), DESCRIPTION(TagFields.DESCRIPTION.getFieldName()),
/**
* The controllerId field.
*/
COLOUR(TagFields.COLOUR.getFieldName()); COLOUR(TagFields.COLOUR.getFieldName());
private final String fieldName; private final String fieldName;
@@ -39,9 +28,4 @@ public enum TargetTagFields implements FieldNameProvider {
TargetTagFields(final String fieldName) { TargetTagFields(final String fieldName) {
this.fieldName = fieldName; this.fieldName = fieldName;
} }
@Override
public String getFieldName() {
return fieldName;
}
} }

View File

@@ -9,37 +9,22 @@
*/ */
package org.eclipse.hawkbit.repository; package org.eclipse.hawkbit.repository;
/** import lombok.Getter;
* Describing the fields of the TargetType model which can be used in
* the REST API
*/
public enum TargetTypeFields implements FieldNameProvider {
/**
* The name field.
*/
KEY("key"),
/**
* The name field.
*/
NAME("name"),
/**
* The description field.
*/
DESCRIPTION("description"),
/** /**
* The id field. * Describing the fields of the TargetType model which can be used in the REST API
*/ */
ID("id"); @Getter
public enum TargetTypeFields implements FieldNameProvider {
ID("id"),
KEY("key"),
NAME("name"),
DESCRIPTION("description");
private final String fieldName; private final String fieldName;
TargetTypeFields(final String fieldName) { TargetTypeFields(final String fieldName) {
this.fieldName = fieldName; this.fieldName = fieldName;
} }
@Override
public String getFieldName() {
return fieldName;
}
} }

View File

@@ -12,19 +12,14 @@ package org.eclipse.hawkbit.repository.exception;
import org.eclipse.hawkbit.exception.AbstractServerRtException; import org.eclipse.hawkbit.exception.AbstractServerRtException;
import org.eclipse.hawkbit.exception.SpServerError; import org.eclipse.hawkbit.exception.SpServerError;
import java.io.Serial;
/** /**
* Exception used by the REST API in case of invalid field name in the rsql * Exception used by the REST API in case of invalid field name in the rsql search parameter.
* search parameter.
*
*
*
*
*/ */
public class RSQLParameterUnsupportedFieldException extends AbstractServerRtException { public class RSQLParameterUnsupportedFieldException extends AbstractServerRtException {
/** @Serial
*
*/
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
/** /**
@@ -35,12 +30,21 @@ public class RSQLParameterUnsupportedFieldException extends AbstractServerRtExce
super(SpServerError.SP_REST_RSQL_PARAM_INVALID_FIELD); super(SpServerError.SP_REST_RSQL_PARAM_INVALID_FIELD);
} }
/**
* Creates a new RSQLParameterUnsupportedFieldException with
* {@link SpServerError#SP_REST_RSQL_PARAM_INVALID_FIELD} error.
*
* @param message the message of the exception
*/
public RSQLParameterUnsupportedFieldException(final String message) {
super(message, SpServerError.SP_REST_RSQL_PARAM_INVALID_FIELD);
}
/** /**
* Creates a new RSQLParameterUnsupportedFieldException with * Creates a new RSQLParameterUnsupportedFieldException with
* {@link SpServerError#SP_REST_RSQL_PARAM_INVALID_FIELD} error. * {@link SpServerError#SP_REST_RSQL_PARAM_INVALID_FIELD} error.
* *
* @param cause * @param cause the cause (which is saved for later retrieval by the
* the cause (which is saved for later retrieval by the
* getCause() method). (A null value is permitted, and indicates * getCause() method). (A null value is permitted, and indicates
* that the cause is nonexistent or unknown.) * that the cause is nonexistent or unknown.)
*/ */
@@ -52,10 +56,8 @@ public class RSQLParameterUnsupportedFieldException extends AbstractServerRtExce
* Creates a new RSQLParameterUnsupportedFieldException with * Creates a new RSQLParameterUnsupportedFieldException with
* {@link SpServerError#SP_REST_RSQL_PARAM_INVALID_FIELD} error. * {@link SpServerError#SP_REST_RSQL_PARAM_INVALID_FIELD} error.
* *
* @param message * @param message the message of the exception
* the message of the exception * @param cause the cause (which is saved for later retrieval by the
* @param cause
* the cause (which is saved for later retrieval by the
* getCause() method). (A null value is permitted, and indicates * getCause() method). (A null value is permitted, and indicates
* that the cause is nonexistent or unknown.) * that the cause is nonexistent or unknown.)
*/ */

View File

@@ -31,11 +31,8 @@ public abstract class AbstractFieldNameRSQLVisitor<A extends Enum<A> & FieldName
} }
protected A getFieldEnumByName(final ComparisonNode node) { protected A getFieldEnumByName(final ComparisonNode node) {
String enumName = node.getSelector(); final String[] graph = node.getSelector().split(FieldNameProvider.SUB_ATTRIBUTE_SPLIT_REGEX);
final String[] graph = enumName.split("\\" + FieldNameProvider.SUB_ATTRIBUTE_SEPARATOR); final String enumName = graph.length == 0 ? node.getSelector() : graph[0];
if (graph.length != 0) {
enumName = graph[0];
}
log.debug("get field identifier by name {} of enum type {}", enumName, fieldNameProvider); log.debug("get field identifier by name {} of enum type {}", enumName, fieldNameProvider);
try { try {
return Enum.valueOf(fieldNameProvider, enumName.toUpperCase()); return Enum.valueOf(fieldNameProvider, enumName.toUpperCase());
@@ -45,25 +42,21 @@ public abstract class AbstractFieldNameRSQLVisitor<A extends Enum<A> & FieldName
} }
protected String getAndValidatePropertyFieldName(final A propertyEnum, final ComparisonNode node) { protected String getAndValidatePropertyFieldName(final A propertyEnum, final ComparisonNode node) {
final String[] subAttributes = propertyEnum.getSubAttributes(node.getSelector());
final String[] graph = propertyEnum.getSubAttributes(node.getSelector()); validateMapParameter(propertyEnum, node, subAttributes);
validateMapParameter(propertyEnum, node, graph);
// sub entity need minimum 1 dot // sub entity need minimum 1 dot
if (!propertyEnum.getSubEntityAttributes().isEmpty() && graph.length < 2) { if (!propertyEnum.getSubEntityAttributes().isEmpty() && subAttributes.length < 2) {
throw createRSQLParameterUnsupportedException(node, null); throw createRSQLParameterUnsupportedException(node, null);
} }
final StringBuilder fieldNameBuilder = new StringBuilder(propertyEnum.getFieldName()); final StringBuilder fieldNameBuilder = new StringBuilder(propertyEnum.getFieldName());
for (int i = 1; i < subAttributes.length; i++) {
for (int i = 1; i < graph.length; i++) { final String propertyField = getFormattedSubEntityAttribute(propertyEnum ,subAttributes[i]);
final String propertyField = getFormattedSubEntityAttribute(propertyEnum ,graph[i]);
fieldNameBuilder.append(FieldNameProvider.SUB_ATTRIBUTE_SEPARATOR).append(propertyField); fieldNameBuilder.append(FieldNameProvider.SUB_ATTRIBUTE_SEPARATOR).append(propertyField);
// the key of map is not in the graph // the key of map is not in the graph
if (propertyEnum.isMap() && graph.length == (i + 1)) { if (propertyEnum.isMap() && subAttributes.length == (i + 1)) {
continue; continue;
} }
@@ -75,30 +68,26 @@ public abstract class AbstractFieldNameRSQLVisitor<A extends Enum<A> & FieldName
return fieldNameBuilder.toString(); return fieldNameBuilder.toString();
} }
protected void validateMapParameter(final A propertyEnum, final ComparisonNode node, final String[] graph) { private void validateMapParameter(final A propertyEnum, final ComparisonNode node, final String[] subAttributes) {
if (!propertyEnum.isMap()) { if (!propertyEnum.isMap()) {
return; return;
} }
if (!propertyEnum.getSubEntityAttributes().isEmpty()) { if (!propertyEnum.getSubEntityAttributes().isEmpty()) {
throw new UnsupportedOperationException( throw new UnsupportedOperationException(
"Currently subentity attributes for maps are not supported, alternatively you could use the key/value tuple, defined by SimpleImmutableEntry class"); "Currently sub-entity attributes for maps are not supported, alternatively you could use the key/value tuple, defined by SimpleImmutableEntry class");
} }
// enum.key // enum.key
final int minAttributeForMap = 2; if (subAttributes.length != 2) {
if (graph.length != minAttributeForMap) { throw new RSQLParameterUnsupportedFieldException("The syntax of the given map search parameter field {" +
throw new RSQLParameterUnsupportedFieldException("The syntax of the given map search parameter field {" node.getSelector() + "} is wrong. Syntax is: <enum name>.<key name>");
+ node.getSelector() + "} is wrong. Syntax is: fieldname.keyname", new Exception());
} }
} }
/** /**
* @param node * @param node current processing node
* current processing node * @param rootException in case there is a cause otherwise {@code null}
* @param rootException
* in case there is a cause otherwise {@code null}
* @return Exception with prepared message extracted from the comparison node. * @return Exception with prepared message extracted from the comparison node.
*/ */
protected RSQLParameterUnsupportedFieldException createRSQLParameterUnsupportedException( protected RSQLParameterUnsupportedFieldException createRSQLParameterUnsupportedException(
@@ -110,20 +99,20 @@ public abstract class AbstractFieldNameRSQLVisitor<A extends Enum<A> & FieldName
} }
private String getFormattedSubEntityAttribute(final A propertyEnum, final String propertyField) { private String getFormattedSubEntityAttribute(final A propertyEnum, final String propertyField) {
return propertyEnum.getSubEntityAttributes().stream().filter(attr -> attr.equalsIgnoreCase(propertyField)) return propertyEnum.getSubEntityAttributes().stream()
.findFirst().orElse(propertyField); .filter(attr -> attr.equalsIgnoreCase(propertyField))
.findFirst().orElse(propertyField);
} }
private List<String> getExpectedFieldList() { private List<String> getExpectedFieldList() {
final List<String> expectedFieldList = Arrays.stream(fieldNameProvider.getEnumConstants()) final List<String> expectedFieldList = Arrays.stream(fieldNameProvider.getEnumConstants())
.filter(enumField -> enumField.getSubEntityAttributes().isEmpty()).map(enumField -> { .filter(enumField -> enumField.getSubEntityAttributes().isEmpty()).map(enumField -> {
final String enumFieldName = enumField.name().toLowerCase(); final String enumFieldName = enumField.name().toLowerCase();
if (enumField.isMap()) { if (enumField.isMap()) {
return enumFieldName + FieldNameProvider.SUB_ATTRIBUTE_SEPARATOR + "keyName"; return enumFieldName + FieldNameProvider.SUB_ATTRIBUTE_SEPARATOR + "keyName";
} else {
return enumFieldName;
} }
return enumFieldName;
}).collect(Collectors.toList()); }).collect(Collectors.toList());
final List<String> expectedSubFieldList = Arrays.stream(fieldNameProvider.getEnumConstants()) final List<String> expectedSubFieldList = Arrays.stream(fieldNameProvider.getEnumConstants())
@@ -131,11 +120,11 @@ public abstract class AbstractFieldNameRSQLVisitor<A extends Enum<A> & FieldName
final List<String> subEntity = enumField final List<String> subEntity = enumField
.getSubEntityAttributes().stream().map(fieldName -> enumField.name().toLowerCase() .getSubEntityAttributes().stream().map(fieldName -> enumField.name().toLowerCase()
+ FieldNameProvider.SUB_ATTRIBUTE_SEPARATOR + fieldName) + FieldNameProvider.SUB_ATTRIBUTE_SEPARATOR + fieldName)
.collect(Collectors.toList()); .toList();
return subEntity.stream(); return subEntity.stream();
}).collect(Collectors.toList()); }).toList();
expectedFieldList.addAll(expectedSubFieldList); expectedFieldList.addAll(expectedSubFieldList);
return expectedFieldList; return expectedFieldList;
} }
} }

View File

@@ -56,7 +56,6 @@ public class RsqlParserValidationOracle implements RsqlValidationOracle {
@Override @Override
public ValidationOracleContext suggest(final String rsqlQuery, final int cursorPosition) { public ValidationOracleContext suggest(final String rsqlQuery, final int cursorPosition) {
final List<SuggestToken> expectedTokens = new ArrayList<>(); final List<SuggestToken> expectedTokens = new ArrayList<>();
final ValidationOracleContext context = new ValidationOracleContext(); final ValidationOracleContext context = new ValidationOracleContext();
context.setSyntaxError(true); context.setSyntaxError(true);
@@ -92,8 +91,8 @@ public class RsqlParserValidationOracle implements RsqlValidationOracle {
final Collection<String> tokenImages = TokenDescription.getTokenImage(TokenDescription.LOGICAL_OP); final Collection<String> tokenImages = TokenDescription.getTokenImage(TokenDescription.LOGICAL_OP);
final List<SuggestToken> logicalOps = new ArrayList<>(tokenImages.size()); final List<SuggestToken> logicalOps = new ArrayList<>(tokenImages.size());
for (final String tokenImage : tokenImages) { for (final String tokenImage : tokenImages) {
logicalOps.add(new SuggestToken(currentQueryLength, currentQueryLength + tokenImage.length(), null, logicalOps.add(
tokenImage)); new SuggestToken(currentQueryLength, currentQueryLength + tokenImage.length(), null, tokenImage));
} }
return logicalOps; return logicalOps;
} }

View File

@@ -18,6 +18,7 @@ import java.util.stream.Collectors;
import org.eclipse.hawkbit.repository.TargetFields; import org.eclipse.hawkbit.repository.TargetFields;
import org.eclipse.hawkbit.repository.jpa.AbstractJpaIntegrationTest; import org.eclipse.hawkbit.repository.jpa.AbstractJpaIntegrationTest;
import org.eclipse.hawkbit.repository.rsql.RsqlValidationOracle; import org.eclipse.hawkbit.repository.rsql.RsqlValidationOracle;
import org.eclipse.hawkbit.repository.rsql.SuggestToken;
import org.eclipse.hawkbit.repository.rsql.ValidationOracleContext; import org.eclipse.hawkbit.repository.rsql.ValidationOracleContext;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@@ -36,7 +37,7 @@ public class RSQLParserValidationOracleTest extends AbstractJpaIntegrationTest {
private static final String[] OP_SUGGESTIONS = new String[] { "==", "!=", "=ge=", "=le=", "=gt=", "=lt=", "=in=", private static final String[] OP_SUGGESTIONS = new String[] { "==", "!=", "=ge=", "=le=", "=gt=", "=lt=", "=in=",
"=out=" }; "=out=" };
private static final String[] FIELD_SUGGESTIONS = Arrays.stream(TargetFields.values()) private static final String[] FIELD_SUGGESTIONS = Arrays.stream(TargetFields.values())
.map(field -> field.name().toLowerCase()).toArray(size -> new String[size]); .map(field -> field.name().toLowerCase()).toArray(String[]::new);
private static final String[] AND_OR_SUGGESTIONS = new String[] { "and", "or" }; private static final String[] AND_OR_SUGGESTIONS = new String[] { "and", "or" };
private static final String[] NAME_VERSION_SUGGESTIONS = new String[] { "name", "version" }; private static final String[] NAME_VERSION_SUGGESTIONS = new String[] { "name", "version" };
@@ -73,10 +74,9 @@ public class RSQLParserValidationOracleTest extends AbstractJpaIntegrationTest {
} }
private List<String> getSuggestions(final String rsqlQuery) { private List<String> getSuggestions(final String rsqlQuery) {
final ValidationOracleContext suggest = rsqlValidationOracle.suggest(rsqlQuery, -1); return rsqlValidationOracle
final List<String> currentSuggestions = suggest.getSuggestionContext().getSuggestions().stream() .suggest(rsqlQuery, -1).getSuggestionContext().getSuggestions().stream()
.map(suggestion -> suggestion.getSuggestion()).collect(Collectors.toList()); .map(SuggestToken::getSuggestion)
return currentSuggestions; .collect(Collectors.toList());
} }
}
}